*error = EVAS_LOAD_ERROR_GENERIC;
goto close_file;
}
- ie->w = (int) w32;
- ie->h = (int) h32;
+ if (ie->load_opts.scale_down_by > 1)
+ {
+ ie->w = (int) w32 / ie->load_opts.scale_down_by;
+ ie->h = (int) h32 / ie->load_opts.scale_down_by;
+ if ((ie->w < 1) || (ie->h < 1))
+ {
+ *error = EVAS_LOAD_ERROR_GENERIC;
+ goto close_file;
+ }
+ }
+ else
+ {
+ ie->w = (int) w32;
+ ie->h = (int) h32;
+ }
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) hasa = 1;
if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) hasa = 1;
if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) hasa = 1;
unsigned char buf[PNG_BYTES_TO_CHECK];
unsigned char **lines;
char hasa;
- int i;
+ int i, j;
+ int scale_ratio = 1, image_w = 0;
+ unsigned char *tmp_line;
+ DATA32 *src_ptr, *dst_ptr;
hasa = 0;
f = E_FOPEN(file, "rb");
png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32),
(png_uint_32 *) (&h32), &bit_depth, &color_type,
&interlace_type, NULL, NULL);
+ image_w = w32;
+ if (ie->load_opts.scale_down_by > 1)
+ {
+ scale_ratio = ie->load_opts.scale_down_by;
+ w32 /= scale_ratio;
+ h32 /= scale_ratio;
+ }
evas_cache_image_surface_alloc(ie, w32, h32);
surface = (unsigned char *) evas_cache_image_pixels(ie);
if (!surface)
png_set_bgr(png_ptr);
if (!hasa) png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
#endif
- lines = (unsigned char **) alloca(h * sizeof(unsigned char *));
- for (i = 0; i < h; i++)
- lines[i] = surface + (i * w * sizeof(DATA32));
- png_read_image(png_ptr, lines);
- png_read_end(png_ptr, info_ptr);
+ /* we read image line by line if scale down was set */
+ if (scale_ratio == 1)
+ {
+ lines = (unsigned char **) alloca(h * sizeof(unsigned char *));
+ for (i = 0; i < h; i++)
+ lines[i] = surface + (i * w * sizeof(DATA32));
+ png_read_image(png_ptr, lines);
+ png_read_end(png_ptr, info_ptr);
+ }
+ else
+ {
+ tmp_line = (unsigned char *) alloca(image_w * sizeof(DATA32));
+ dst_ptr = (DATA32 *)surface;
+ for (i = 0; i < h; i++)
+ {
+ png_read_row(png_ptr, tmp_line, NULL);
+ src_ptr = (DATA32 *)tmp_line;
+ for (j = 0; j < w; j++)
+ {
+ *dst_ptr = *src_ptr;
+ dst_ptr++;
+ src_ptr += scale_ratio;
+ }
+ for (j = 0; j < (scale_ratio - 1); j++)
+ {
+ png_read_row(png_ptr, tmp_line, NULL);
+ }
+ }
+ }
+
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
E_FCLOSE(f);
evas_common_image_premul(ie);