]> git.imager.perl.org - imager.git/blobdiff - ICO/imicon.c
move EXIF handling from the JPEG handler to core Imager
[imager.git] / ICO / imicon.c
index c132f68a9eb62c4143d174c52f171435b117426e..529610d72dbd955c88ab4522573553334bb6c8c7 100644 (file)
@@ -13,7 +13,7 @@ ico_push_error(int error) {
 
 static
 i_img *
-read_one_icon(ico_reader_t *file, int index, int masked) {
+read_one_icon(ico_reader_t *file, int index, int masked, int alpha_masked) {
   ico_image_t *image;
   int error;
   i_img *result;
@@ -25,7 +25,7 @@ read_one_icon(ico_reader_t *file, int index, int masked) {
     return NULL;
   }
 
-  if (masked) {
+  if (masked && (image->bit_count != 32 || alpha_masked)) {
     /* check to make sure we should do the masking, if the mask has
        nothing set we don't mask */
     int pos;
@@ -46,13 +46,15 @@ read_one_icon(ico_reader_t *file, int index, int masked) {
     i_color *line_buf;
     i_color *outp;
     ico_color_t *inp = image->image_data;
+    int channels = masked || image->bit_count == 32 ? 4 : 3;
 
-    if (!i_int_check_image_file_limits(image->width, image->height, 4, 1)) {
+    if (!i_int_check_image_file_limits(image->width, image->height, channels, 1)) {
       ico_image_release(image);
       return NULL;
     }
 
-    result = i_img_8_new(image->width, image->height, 4);
+    
+    result = i_img_8_new(image->width, image->height, channels);
     if (!result) {
       ico_image_release(image);
       return NULL;
@@ -193,7 +195,7 @@ read_one_icon(ico_reader_t *file, int index, int masked) {
 }
 
 i_img *
-i_readico_single(io_glue *ig, int index, int masked) {
+i_readico_single(io_glue *ig, int index, int masked, int alpha_masked) {
   ico_reader_t *file;
   i_img *result;
   int error;
@@ -209,14 +211,14 @@ i_readico_single(io_glue *ig, int index, int masked) {
 
   /* the index is range checked by msicon.c - don't duplicate it here */
 
-  result = read_one_icon(file, index, masked);
+  result = read_one_icon(file, index, masked, alpha_masked);
   ico_reader_close(file);
 
   return result;
 }
 
 i_img **
-i_readico_multi(io_glue *ig, int *count, int masked) {
+i_readico_multi(io_glue *ig, int *count, int masked, int alpha_masked) {
   ico_reader_t *file;
   int index;
   int error;
@@ -235,7 +237,7 @@ i_readico_multi(io_glue *ig, int *count, int masked) {
 
   *count = 0;
   for (index = 0; index < ico_image_count(file); ++index) {
-    i_img *im = read_one_icon(file, index, masked);
+    i_img *im = read_one_icon(file, index, masked, alpha_masked);
     if (!im)
       break;
 
@@ -254,7 +256,7 @@ i_readico_multi(io_glue *ig, int *count, int masked) {
 
 static int
 validate_image(i_img *im) {
-  if (im->xsize > 255 || im->ysize > 255) {
+  if (im->xsize > 256 || im->ysize > 256) {
     i_push_error(0, "image too large for ico file");
     return 0;
   }