⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pngrutil.c

📁 Linux下的基于X11的图形开发环境。
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifndef PNG_NO_POINTER_INDEXING   for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)   {      png_byte buf[3];      png_crc_read(png_ptr, buf, 3);      pal_ptr->red = buf[0];      pal_ptr->green = buf[1];      pal_ptr->blue = buf[2];   }#else   for (i = 0; i < num; i++)   {      png_byte buf[3];      png_crc_read(png_ptr, buf, 3);      /* don't depend upon png_color being any order */      palette[i].red = buf[0];      palette[i].green = buf[1];      palette[i].blue = buf[2];   }#endif   /* If we actually NEED the PLTE chunk (ie for a paletted image), we do      whatever the normal CRC configuration tells us.  However, if we      have an RGB image, the PLTE can be considered ancillary, so      we will act as though it is. */#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)#endif   {      png_crc_finish(png_ptr, 0);   }#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)   else if (png_crc_error(png_ptr))  /* Only if we have a CRC error */   {      /* If we don't want to use the data from an ancillary chunk,         we have two options: an error abort, or a warning and we         ignore the data in this chunk (which should be OK, since         it's considered ancillary for a RGB or RGBA image). */      if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))      {         if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)         {            png_chunk_error(png_ptr, "CRC error");         }         else         {            png_chunk_warning(png_ptr, "CRC error");            return;         }      }      /* Otherwise, we (optionally) emit a warning and use the chunk. */      else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))      {         png_chunk_warning(png_ptr, "CRC error");      }   }#endif   png_set_PLTE(png_ptr, info_ptr, palette, num);#if defined(PNG_READ_tRNS_SUPPORTED)   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)   {      if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))      {         if (png_ptr->num_trans > (png_uint_16)num)         {            png_warning(png_ptr, "Truncating incorrect tRNS chunk length");            png_ptr->num_trans = (png_uint_16)num;         }         if (info_ptr->num_trans > (png_uint_16)num)         {            png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");            info_ptr->num_trans = (png_uint_16)num;         }      }   }#endif}void /* PRIVATE */png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){   png_debug(1, "in png_handle_IEND\n");   if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))   {      png_error(png_ptr, "No image in file");      info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */   }   png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);   if (length != 0)   {      png_warning(png_ptr, "Incorrect IEND chunk length");   }   png_crc_finish(png_ptr, length);}#if defined(PNG_READ_gAMA_SUPPORTED)void /* PRIVATE */png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){   png_fixed_point igamma;#ifdef PNG_FLOATING_POINT_SUPPORTED   float file_gamma;#endif   png_byte buf[4];   png_debug(1, "in png_handle_gAMA\n");   if (!(png_ptr->mode & PNG_HAVE_IHDR))      png_error(png_ptr, "Missing IHDR before gAMA");   else if (png_ptr->mode & PNG_HAVE_IDAT)   {      png_warning(png_ptr, "Invalid gAMA after IDAT");      png_crc_finish(png_ptr, length);      return;   }   else if (png_ptr->mode & PNG_HAVE_PLTE)      /* Should be an error, but we can cope with it */      png_warning(png_ptr, "Out of place gAMA chunk");   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)#if defined(PNG_READ_sRGB_SUPPORTED)      && !(info_ptr->valid & PNG_INFO_sRGB)#endif      )   {      png_warning(png_ptr, "Duplicate gAMA chunk");      png_crc_finish(png_ptr, length);      return;   }   if (length != 4)   {      png_warning(png_ptr, "Incorrect gAMA chunk length");      png_crc_finish(png_ptr, length);      return;   }   png_crc_read(png_ptr, buf, 4);   if (png_crc_finish(png_ptr, 0))      return;   igamma = (png_fixed_point)png_get_uint_32(buf);   /* check for zero gamma */   if (igamma == 0)      {         png_warning(png_ptr,           "Ignoring gAMA chunk with gamma=0");         return;      }#if defined(PNG_READ_sRGB_SUPPORTED)   if (info_ptr->valid & PNG_INFO_sRGB)      if(igamma < 45000L || igamma > 46000L)      {         png_warning(png_ptr,           "Ignoring incorrect gAMA value when sRGB is also present");#ifndef PNG_NO_CONSOLE_IO         fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);#endif         return;      }#endif /* PNG_READ_sRGB_SUPPORTED */#ifdef PNG_FLOATING_POINT_SUPPORTED   file_gamma = (float)igamma / (float)100000.0;#  ifdef PNG_READ_GAMMA_SUPPORTED     png_ptr->gamma = file_gamma;#  endif     png_set_gAMA(png_ptr, info_ptr, file_gamma);#endif#ifdef PNG_FIXED_POINT_SUPPORTED   png_set_gAMA_fixed(png_ptr, info_ptr, igamma);#endif}#endif#if defined(PNG_READ_sBIT_SUPPORTED)void /* PRIVATE */png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){   png_size_t truelen;   png_byte buf[4];   png_debug(1, "in png_handle_sBIT\n");   buf[0] = buf[1] = buf[2] = buf[3] = 0;   if (!(png_ptr->mode & PNG_HAVE_IHDR))      png_error(png_ptr, "Missing IHDR before sBIT");   else if (png_ptr->mode & PNG_HAVE_IDAT)   {      png_warning(png_ptr, "Invalid sBIT after IDAT");      png_crc_finish(png_ptr, length);      return;   }   else if (png_ptr->mode & PNG_HAVE_PLTE)   {      /* Should be an error, but we can cope with it */      png_warning(png_ptr, "Out of place sBIT chunk");   }   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))   {      png_warning(png_ptr, "Duplicate sBIT chunk");      png_crc_finish(png_ptr, length);      return;   }   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)      truelen = 3;   else      truelen = (png_size_t)png_ptr->channels;   if (length != truelen)   {      png_warning(png_ptr, "Incorrect sBIT chunk length");      png_crc_finish(png_ptr, length);      return;   }   png_crc_read(png_ptr, buf, truelen);   if (png_crc_finish(png_ptr, 0))      return;   if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)   {      png_ptr->sig_bit.red = buf[0];      png_ptr->sig_bit.green = buf[1];      png_ptr->sig_bit.blue = buf[2];      png_ptr->sig_bit.alpha = buf[3];   }   else   {      png_ptr->sig_bit.gray = buf[0];      png_ptr->sig_bit.red = buf[0];      png_ptr->sig_bit.green = buf[0];      png_ptr->sig_bit.blue = buf[0];      png_ptr->sig_bit.alpha = buf[1];   }   png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));}#endif#if defined(PNG_READ_cHRM_SUPPORTED)void /* PRIVATE */png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){   png_byte buf[4];#ifdef PNG_FLOATING_POINT_SUPPORTED   float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;#endif   png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,      int_y_green, int_x_blue, int_y_blue;   png_uint_32 uint_x, uint_y;   png_debug(1, "in png_handle_cHRM\n");   if (!(png_ptr->mode & PNG_HAVE_IHDR))      png_error(png_ptr, "Missing IHDR before cHRM");   else if (png_ptr->mode & PNG_HAVE_IDAT)   {      png_warning(png_ptr, "Invalid cHRM after IDAT");      png_crc_finish(png_ptr, length);      return;   }   else if (png_ptr->mode & PNG_HAVE_PLTE)      /* Should be an error, but we can cope with it */      png_warning(png_ptr, "Missing PLTE before cHRM");   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)#if defined(PNG_READ_sRGB_SUPPORTED)      && !(info_ptr->valid & PNG_INFO_sRGB)#endif      )   {      png_warning(png_ptr, "Duplicate cHRM chunk");      png_crc_finish(png_ptr, length);      return;   }   if (length != 32)   {      png_warning(png_ptr, "Incorrect cHRM chunk length");      png_crc_finish(png_ptr, length);      return;   }   png_crc_read(png_ptr, buf, 4);   uint_x = png_get_uint_32(buf);   png_crc_read(png_ptr, buf, 4);   uint_y = png_get_uint_32(buf);   if (uint_x > 80000L || uint_y > 80000L ||      uint_x + uint_y > 100000L)   {      png_warning(png_ptr, "Invalid cHRM white point");      png_crc_finish(png_ptr, 24);      return;   }   int_x_white = (png_fixed_point)uint_x;   int_y_white = (png_fixed_point)uint_y;   png_crc_read(png_ptr, buf, 4);   uint_x = png_get_uint_32(buf);   png_crc_read(png_ptr, buf, 4);   uint_y = png_get_uint_32(buf);   if (uint_x > 80000L || uint_y > 80000L ||      uint_x + uint_y > 100000L)   {      png_warning(png_ptr, "Invalid cHRM red point");      png_crc_finish(png_ptr, 16);      return;   }   int_x_red = (png_fixed_point)uint_x;   int_y_red = (png_fixed_point)uint_y;   png_crc_read(png_ptr, buf, 4);   uint_x = png_get_uint_32(buf);   png_crc_read(png_ptr, buf, 4);   uint_y = png_get_uint_32(buf);   if (uint_x > 80000L || uint_y > 80000L ||      uint_x + uint_y > 100000L)   {      png_warning(png_ptr, "Invalid cHRM green point");      png_crc_finish(png_ptr, 8);      return;   }   int_x_green = (png_fixed_point)uint_x;   int_y_green = (png_fixed_point)uint_y;   png_crc_read(png_ptr, buf, 4);   uint_x = png_get_uint_32(buf);   png_crc_read(png_ptr, buf, 4);   uint_y = png_get_uint_32(buf);   if (uint_x > 80000L || uint_y > 80000L ||      uint_x + uint_y > 100000L)   {      png_warning(png_ptr, "Invalid cHRM blue point");      png_crc_finish(png_ptr, 0);      return;   }   int_x_blue = (png_fixed_point)uint_x;   int_y_blue = (png_fixed_point)uint_y;#ifdef PNG_FLOATING_POINT_SUPPORTED   white_x = (float)int_x_white / (float)100000.0;   white_y = (float)int_y_white / (float)100000.0;   red_x   = (float)int_x_red   / (float)100000.0;   red_y   = (float)int_y_red   / (float)100000.0;   green_x = (float)int_x_green / (float)100000.0;   green_y = (float)int_y_green / (float)100000.0;   blue_x  = (float)int_x_blue  / (float)100000.0;   blue_y  = (float)int_y_blue  / (float)100000.0;#endif#if defined(PNG_READ_sRGB_SUPPORTED)   if (info_ptr->valid & PNG_INFO_sRGB)      {      if (abs(int_x_white - 31270L) > 1000 ||          abs(int_y_white - 32900L) > 1000 ||          abs(int_x_red   - 64000L) > 1000 ||          abs(int_y_red   - 33000L) > 1000 ||          abs(int_x_green - 30000L) > 1000 ||          abs(int_y_green - 60000L) > 1000 ||          abs(int_x_blue  - 15000L) > 1000 ||          abs(int_y_blue  -  6000L) > 1000)         {            png_warning(png_ptr,              "Ignoring incorrect cHRM value when sRGB is also present");#ifndef PNG_NO_CONSOLE_IO#ifdef PNG_FLOATING_POINT_SUPPORTED            fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",               white_x, white_y, red_x, red_y);            fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",               green_x, green_y, blue_x, blue_y);#else            fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",               int_x_white, int_y_white, int_x_red, int_y_red);            fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",               int_x_green, int_y_green, int_x_blue, int_y_blue);#endif#endif /* PNG_NO_CONSOLE_IO */         }         png_crc_finish(png_ptr, 0);         return;      }#endif /* PNG_READ_sRGB_SUPPORTED */#ifdef PNG_FLOATING_POINT_SUPPORTED   png_set_cHRM(png_ptr, info_ptr,      white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);#endif#ifdef PNG_FIXED_POINT_SUPPORTED   png_set_cHRM_fixed(png_ptr, info_ptr,      int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,      int_y_green, int_x_blue, int_y_blue);#endif   if (png_crc_finish(png_ptr, 0))      return;}#endif#if defined(PNG_READ_sRGB_SUPPORTED)void /* PRIVATE */png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){   int intent;   png_byte buf[1];   png_debug(1, "in png_handle_sRGB\n");   if (!(png_ptr->mode & PNG_HAVE_IHDR))      png_error(png_ptr, "Missing IHDR before sRGB");   else if (png_ptr->mode & PNG_HAVE_IDAT)   {      png_warning(png_ptr, "Invalid sRGB after IDAT");      png_crc_finish(png_ptr, length);      return;   }   else if (png_ptr->mode & PNG_HAVE_PLTE)      /* Should be an error, but we can cope with it */      png_warning(png_ptr, "Out of place sRGB chunk");   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))   {      png_warning(png_ptr, "Duplicate sRGB chunk");      png_crc_finish(png_ptr, length);      return;   }   if (length != 1)   {      png_warning(png_ptr, "Incorrect sRGB chunk length");      png_crc_finish(png_ptr, length);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -