diff options
author | Johny Mattsson <jmattsson@dius.com.au> | 2017-05-31 14:14:42 +1000 |
---|---|---|
committer | Johny Mattsson <jmattsson@dius.com.au> | 2017-05-31 14:14:42 +1000 |
commit | 4be8c4c1b2d3c3a840631ff99d441bb1db0ad88d (patch) | |
tree | 9bd620197261a54a4aea605a7b010a9cc0ba5b9c /src/loadpng.c | |
parent | 55e6f6890acddfd8b415db8f92ebb7ea1a2d4166 (diff) | |
download | qlprint-4be8c4c1b2d3c3a840631ff99d441bb1db0ad88d.tar.gz qlprint-4be8c4c1b2d3c3a840631ff99d441bb1db0ad88d.tar.xz qlprint-4be8c4c1b2d3c3a840631ff99d441bb1db0ad88d.zip |
Only request necessary transforms.
Diffstat (limited to 'src/loadpng.c')
-rw-r--r-- | src/loadpng.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/loadpng.c b/src/loadpng.c index c986ce2..fce5066 100644 --- a/src/loadpng.c +++ b/src/loadpng.c @@ -52,15 +52,20 @@ ql_raster_image_t *loadpng(const char *path) png_read_info(png_ptr, info_ptr); - png_set_strip_alpha(png_ptr); - png_set_rgb_to_gray_fixed(png_ptr, 1, -1, -1); // force into grayscale - png_set_expand_gray_1_2_4_to_8(png_ptr); // get us a known output format + png_uint_32 width, height; + int bit_depth, color_type; + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, + &color_type, NULL, NULL, NULL); + + if (color_type & PNG_COLOR_MASK_ALPHA) + png_set_strip_alpha(png_ptr); + if (color_type & (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)) + png_set_rgb_to_gray_fixed(png_ptr, 1, -1, -1); // force into grayscale + if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand_gray_1_2_4_to_8(png_ptr); // get us a known output format png_read_update_info(png_ptr, info_ptr); - png_uint_32 width = png_get_image_width(png_ptr, info_ptr); - png_uint_32 height = png_get_image_height(png_ptr, info_ptr); - png_bytepp row_ptrs = calloc(height, sizeof(png_bytep)); if (!row_ptrs) goto destroy_read_out; |