remove aarch64 for neon check
[platform/upstream/libpng.git] / pngread.c
index 8fa7d9f..e951446 100644 (file)
--- a/pngread.c
+++ b/pngread.c
@@ -161,6 +161,9 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
 
       else if (chunk_name == png_IDAT)
       {
+#ifdef PNG_READ_APNG_SUPPORTED
+         png_have_info(png_ptr, info_ptr);
+#endif
          png_ptr->idat_size = length;
          break;
       }
@@ -255,6 +258,17 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
          png_handle_iTXt(png_ptr, info_ptr, length);
 #endif
 
+#ifdef PNG_READ_APNG_SUPPORTED
+      else if (chunk_name == png_acTL)
+         png_handle_acTL(png_ptr, info_ptr, length);
+
+      else if (chunk_name == png_fcTL)
+         png_handle_fcTL(png_ptr, info_ptr, length);
+
+      else if (chunk_name == png_fdAT)
+         png_handle_fdAT(png_ptr, info_ptr, length);
+#endif
+
       else
          png_handle_unknown(png_ptr, info_ptr, length,
              PNG_HANDLE_CHUNK_AS_DEFAULT);
@@ -262,6 +276,72 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
 }
 #endif /* SEQUENTIAL_READ */
 
+#ifdef PNG_READ_APNG_SUPPORTED
+void PNGAPI
+png_read_frame_head(png_structp png_ptr, png_infop info_ptr)
+{
+    png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */
+
+    png_debug(0, "Reading frame head");
+
+    if (!(png_ptr->mode & PNG_HAVE_acTL))
+        png_error(png_ptr, "attempt to png_read_frame_head() but "
+                           "no acTL present");
+
+    /* do nothing for the main IDAT */
+    if (png_ptr->num_frames_read == 0)
+        return;
+
+    png_read_reset(png_ptr);
+    png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
+    png_ptr->mode &= ~PNG_HAVE_fcTL;
+
+    have_chunk_after_DAT = 0;
+    for (;;)
+    {
+        png_uint_32 length = png_read_chunk_header(png_ptr);
+
+        if (png_ptr->chunk_name == png_IDAT)
+        {
+            /* discard trailing IDATs for the first frame */
+            if (have_chunk_after_DAT || png_ptr->num_frames_read > 1)
+                png_error(png_ptr, "png_read_frame_head(): out of place IDAT");
+            png_crc_finish(png_ptr, length);
+        }
+
+        else if (png_ptr->chunk_name == png_fcTL)
+        {
+            png_handle_fcTL(png_ptr, info_ptr, length);
+            have_chunk_after_DAT = 1;
+        }
+
+        else if (png_ptr->chunk_name == png_fdAT)
+        {
+            png_ensure_sequence_number(png_ptr, length);
+
+            /* discard trailing fdATs for frames other than the first */
+            if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1)
+                png_crc_finish(png_ptr, length - 4);
+            else if(png_ptr->mode & PNG_HAVE_fcTL)
+            {
+                png_ptr->idat_size = length - 4;
+                png_ptr->mode |= PNG_HAVE_IDAT;
+
+                break;
+            }
+            else
+                png_error(png_ptr, "png_read_frame_head(): out of place fdAT");
+        }
+        else
+        {
+            png_warning(png_ptr, "Skipped (ignored) a chunk "
+                                 "between APNG chunks");
+            png_crc_finish(png_ptr, length);
+        }
+    }
+}
+#endif /* PNG_READ_APNG_SUPPORTED */
+
 /* Optional call to update the users info_ptr structure */
 void PNGAPI
 png_read_update_info(png_structrp png_ptr, png_inforp info_ptr)
@@ -755,6 +835,130 @@ png_read_image(png_structrp png_ptr, png_bytepp image)
       }
    }
 }
+
+#ifdef __TIZEN__
+void PNGAPI
+png_read_image_with_pick_color(png_structp png_ptr, png_bytepp image, PngPickColor *pickcolor)
+{
+   png_uint_32 i, image_height;
+   int pass, j;
+   png_uint_32 /*k = 0,*/ image_bpp = 0, image_width;
+   png_bytepp rp;
+   //png_bytep rc;
+   unsigned int npixels;
+       int perc_enable_y1, perc_enable_y2;
+   png_debug(1, "in png_read_image");
+
+   if (png_ptr == NULL || pickcolor == NULL)
+      return;
+
+#ifdef PNG_READ_INTERLACING_SUPPORTED
+   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
+   {
+      pass = png_set_interlace_handling(png_ptr);
+      /* And make sure transforms are initialized. */
+      png_start_read_image(png_ptr);
+   }
+   else
+   {
+      if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE))
+      {
+         /* Caller called png_start_read_image or png_read_update_info without
+          * first turning on the PNG_INTERLACE transform.  We can fix this here,
+          * but the caller should do it!
+          */
+         png_warning(png_ptr, "Interlace handling should be turned on when "
+            "using png_read_image");
+         /* Make sure this is set correctly */
+         png_ptr->num_rows = png_ptr->height;
+      }
+
+      /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in
+       * the above error case.
+       */
+      pass = png_set_interlace_handling(png_ptr);
+   }
+#else
+   if (png_ptr->interlaced)
+      png_error(png_ptr,
+          "Cannot read interlaced image -- interlace handler disabled");
+
+   pass = 1;
+#endif
+
+   image_height=png_ptr->height;
+   image_bpp=png_ptr->rowbytes;
+   image_width=png_ptr->width;
+   png_ptr->user_chunk_ptr = pickcolor;
+
+   if(pickcolor->perc < 0)
+   {
+       png_error(png_ptr, "ColorPick percentage is negative");
+       return;
+   }
+   if( (pickcolor->region < PNG_COLORPICK_TOP) || (pickcolor->region > PNG_COLORPICK_BOTTOM))
+   {
+       png_error(png_ptr, "ColorPick Region is out of bound");
+       return;
+   }
+   if(pickcolor->region == PNG_COLORPICK_TOP)
+   {
+       perc_enable_y1 = 0;
+       perc_enable_y2 = (pickcolor->perc*image_height/100) - 1;
+   }
+   else if(pickcolor->region == PNG_COLORPICK_MIDDLE)
+   {
+       perc_enable_y1 = (image_height/2) - (((pickcolor->perc/2)*image_height)/100);
+       perc_enable_y2 = perc_enable_y1 + ((pickcolor->perc*image_height)/100) - 1;
+   }
+   else
+   {
+       perc_enable_y1 = (image_height) - ( pickcolor->perc * image_height / 100  );
+       perc_enable_y2 = image_height - 1;
+   }
+
+   for (j = 0; j < pass; j++)
+   {
+      rp = image;
+      for (i = 0; i < image_height; i++)
+      {
+         pickcolor->enable = 0;
+         if( pickcolor->perc > 0 )
+         {
+            if( (int)i >= perc_enable_y1 && (int)i <= perc_enable_y2)
+            {
+               pickcolor->enable = 1;
+            }
+         }
+         else
+         {
+            if( ((int)i >= pickcolor->y1) && ((int)i <= pickcolor->y2) )
+            {
+               pickcolor->enable = 1;
+            }
+         }
+         png_read_row(png_ptr, *rp, NULL);
+         rp++;
+      }
+   }
+
+
+   if(pickcolor->perc > 0)
+   {
+      npixels = (pickcolor->perc*image_height*image_width)/100;
+   }
+   else
+   {
+      npixels = (pickcolor->x2-pickcolor->x1+1)*(pickcolor->y2-pickcolor->y1+1);
+   }
+   if(npixels > 0)
+   {
+      pickcolor->sumR = pickcolor->sumR/npixels;
+      pickcolor->sumG = pickcolor->sumG/npixels;
+      pickcolor->sumB = pickcolor->sumB/npixels;
+   }
+}
+#endif /* __TIZEN__ */
 #endif /* SEQUENTIAL_READ */
 
 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
@@ -3765,13 +3969,13 @@ png_image_read_direct(png_voidp argument)
          mode = PNG_ALPHA_PNG;
          output_gamma = PNG_DEFAULT_sRGB;
       }
-      
+
       if ((change & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0)
       {
          mode = PNG_ALPHA_OPTIMIZED;
          change &= ~PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
       }
-      
+
       /* If 'do_local_background' is set check for the presence of gamma
        * correction; this is part of the work-round for the libpng bug
        * described above.