42 std::string
fit =
"stretch";
48 else if (
fit ==
"coord")
70 FILE* fp = std::fopen(
filename.c_str(),
"rb");
74 png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
77 png_infop info = png_create_info_struct(png);
85 png_read_info(png, info);
87 value.
png_width = png_get_image_width(png, info);
88 value.
png_height = png_get_image_height(png, info);
89 value.
color_type = png_get_color_type(png, info);
90 value.
bit_depth = png_get_bit_depth(png, info);
93 png_set_strip_16(png);
95 if (value.
color_type == PNG_COLOR_TYPE_PALETTE)
96 png_set_palette_to_rgb(png);
99 png_set_expand_gray_1_2_4_to_8(png);
101 if (png_get_valid(png, info, PNG_INFO_tRNS))
102 png_set_tRNS_to_alpha(png);
107 png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
109 if (value.
color_type == PNG_COLOR_TYPE_GRAY ||
110 value.
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
111 png_set_gray_to_rgb(png);
113 png_read_update_info(png, info);
119 value.
row_pointers[y] = (png_byte*)malloc(png_get_rowbytes(png, info));
126 png_destroy_read_struct(&png, &info, NULL);
163 std::array<Set::Scalar, 4> ret;
183 ximg(1) -= 0.5 - 0.5 / aspect_ratio;
184 ximg(1) *= aspect_ratio;
191 ximg(0) -= 0.5 - 0.5 / aspect_ratio;
192 ximg(0) *= aspect_ratio;
202 ximg(0) = std::min(ximg(0), 1.0); ximg(1) = std::min(ximg(1), 1.0);
203 ximg(0) = std::max(ximg(0), 0.0); ximg(1) = std::max(ximg(1), 0.0);
205 ximg(0) *= img_width;
206 ximg(1) *= img_height;
208 int I = (int)(ximg(0));
209 int J = (int)(ximg(1));
211 Set::Scalar x1 = I * img_dx, x2 = (I + 1) * img_dx;
212 Set::Scalar y1 = J * img_dy, y2 = (J + 1) * img_dy;
215 for (
int channel = 0; channel < 4; channel++)
233 fQ11 * (x2 - ximg(0)) * (y2 - ximg(1)) +
234 fQ21 * (ximg(0) - x1) * (y2 - ximg(1)) +
235 fQ12 * (x2 - ximg(0)) * (ximg(1) - y1) +
236 fQ22 * (ximg(0) - x1) * (ximg(1) - y1)) / (img_dx * img_dy);
246 ret[channel] = fQ11 + (fQ12 - fQ11) * (ximg(1) - y1);
255 ret[channel] = fQ11 + (fQ21 - fQ11) * (ximg(0) - x1);
272 return {NAN,NAN,NAN,NAN};