📄 pngrutil.c
字号:
/* 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.alpha = buf[1]; } png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));}#endif#if defined(PNG_READ_cHRM_SUPPORTED)voidpng_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){ png_byte buf[4]; png_uint_32 val; float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; png_debug(1, "in png_handle_cHRM\n"); 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 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); val = png_get_uint_32(buf); white_x = (float)val / (float)100000.0; png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); white_y = (float)val / (float)100000.0; if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 || white_x + white_y > 1.0) { png_warning(png_ptr, "Invalid cHRM white point"); png_crc_finish(png_ptr, 24); return; } png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); red_x = (float)val / (float)100000.0; png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); red_y = (float)val / (float)100000.0; if (red_x < 0 || red_x > 0.8 || red_y < 0 || red_y > 0.8 || red_x + red_y > 1.0) { png_warning(png_ptr, "Invalid cHRM red point"); png_crc_finish(png_ptr, 16); return; } png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); green_x = (float)val / (float)100000.0; png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); green_y = (float)val / (float)100000.0; if (green_x < 0 || green_x > 0.8 || green_y < 0 || green_y > 0.8 || green_x + green_y > 1.0) { png_warning(png_ptr, "Invalid cHRM green point"); png_crc_finish(png_ptr, 8); return; } png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); blue_x = (float)val / (float)100000.0; png_crc_read(png_ptr, buf, 4); val = png_get_uint_32(buf); blue_y = (float)val / (float)100000.0; if (blue_x < (float)0 || blue_x > (float)0.8 || blue_y < (float)0 || blue_y > (float)0.8 || blue_x + blue_y > (float)1.0) { png_warning(png_ptr, "Invalid cHRM blue point"); png_crc_finish(png_ptr, 0); return; } if (png_crc_finish(png_ptr, 0)) return;#if defined(PNG_READ_sRGB_SUPPORTED) if (info_ptr->valid & PNG_INFO_sRGB) { if (fabs(white_x - (float).3127) > (float).001 || fabs(white_y - (float).3290) > (float).001 || fabs( red_x - (float).6400) > (float).001 || fabs( red_y - (float).3300) > (float).001 || fabs(green_x - (float).3000) > (float).001 || fabs(green_y - (float).6000) > (float).001 || fabs( blue_x - (float).1500) > (float).001 || fabs( blue_y - (float).0600) > (float).001) { png_warning(png_ptr, "Ignoring incorrect cHRM value when sRGB is also present");#ifndef PNG_NO_STDIO 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);#endif } return; }#endif /* PNG_READ_sRGB_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#if defined(PNG_READ_sRGB_SUPPORTED)voidpng_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); return; } png_crc_read(png_ptr, buf, 1); if (png_crc_finish(png_ptr, 0)) return; intent = buf[0]; /* check for bad intent */ if (intent >= PNG_sRGB_INTENT_LAST) { png_warning(png_ptr, "Unknown sRGB intent"); return; }#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) if ((info_ptr->valid & PNG_INFO_gAMA)) if((png_uint_32)(png_ptr->gamma*(float)100000.+.5) != (png_uint_32)45000L) { png_warning(png_ptr, "Ignoring incorrect gAMA value when sRGB is also present");#ifndef PNG_NO_STDIO fprintf(stderr,"gamma=%f\n",png_ptr->gamma);#endif }#endif /* PNG_READ_gAMA_SUPPORTED */#ifdef PNG_READ_cHRM_SUPPORTED if (info_ptr->valid & PNG_INFO_cHRM) if (fabs(info_ptr->x_white - (float).3127) > (float).001 || fabs(info_ptr->y_white - (float).3290) > (float).001 || fabs( info_ptr->x_red - (float).6400) > (float).001 || fabs( info_ptr->y_red - (float).3300) > (float).001 || fabs(info_ptr->x_green - (float).3000) > (float).001 || fabs(info_ptr->y_green - (float).6000) > (float).001 || fabs( info_ptr->x_blue - (float).1500) > (float).001 || fabs( info_ptr->y_blue - (float).0600) > (float).001) { png_warning(png_ptr, "Ignoring incorrect cHRM value when sRGB is also present"); }#endif /* PNG_READ_cHRM_SUPPORTED */ png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);}#endif /* PNG_READ_sRGB_SUPPORTED */#if defined(PNG_READ_tRNS_SUPPORTED)voidpng_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){ png_debug(1, "in png_handle_tRNS\n"); if (!(png_ptr->mode & PNG_HAVE_IHDR)) png_error(png_ptr, "Missing IHDR before tRNS"); else if (png_ptr->mode & PNG_HAVE_IDAT) { png_warning(png_ptr, "Invalid tRNS after IDAT"); png_crc_finish(png_ptr, length); return; } else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS) { png_warning(png_ptr, "Duplicate tRNS chunk"); png_crc_finish(png_ptr, length); return; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { if (!(png_ptr->mode & PNG_HAVE_PLTE)) { /* Should be an error, but we can cope with it */ png_warning(png_ptr, "Missing PLTE before tRNS"); } else if (length > png_ptr->num_palette) { png_warning(png_ptr, "Incorrect tRNS chunk length"); png_crc_finish(png_ptr, length); return; } if (length == 0) { png_warning(png_ptr, "Zero length tRNS chunk"); png_crc_finish(png_ptr, length); return; } png_ptr->trans = (png_bytep)png_malloc(png_ptr, length); png_ptr->flags |= PNG_FLAG_FREE_TRANS; png_crc_read(png_ptr, png_ptr->trans, (png_size_t)length); png_ptr->num_trans = (png_uint_16)length; } else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB) { png_byte buf[6]; if (length != 6) { png_warning(png_ptr, "Incorrect tRNS chunk length"); png_crc_finish(png_ptr, length); return; } png_crc_read(png_ptr, buf, (png_size_t)length); png_ptr->num_trans = 1; png_ptr->trans_values.red = png_get_uint_16(buf); png_ptr->trans_values.green = png_get_uint_16(buf + 2); png_ptr->trans_values.blue = png_get_uint_16(buf + 4); } else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY) { png_byte buf[6]; if (length != 2) { png_warning(png_ptr, "Incorrect tRNS chunk length"); png_crc_finish(png_ptr, length); return; } png_crc_read(png_ptr, buf, 2); png_ptr->num_trans = 1; png_ptr->trans_values.gray = png_get_uint_16(buf); } else { png_warning(png_ptr, "tRNS chunk not allowed with alpha channel"); png_crc_finish(png_ptr, length); return; } if (png_crc_finish(png_ptr, 0)) return; png_set_tRNS(png_ptr, info_ptr, png_ptr->trans, png_ptr->num_trans, &(png_ptr->trans_values));}#endif#if defined(PNG_READ_bKGD_SUPPORTED)voidpng_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){ png_size_t truelen; png_byte buf[6]; png_debug(1, "in png_handle_bKGD\n"); if (!(png_ptr->mode & PNG_HAVE_IHDR)) png_error(png_ptr, "Missing IHDR before bKGD"); else if (png_ptr->mode & PNG_HAVE_IDAT) { png_warning(png_ptr, "Invalid bKGD after IDAT"); png_crc_finish(png_ptr, length); return; } else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && !(png_ptr->mode & PNG_HAVE_PLTE)) { png_warning(png_ptr, "Missing PLTE before bKGD"); png_crc_finish(png_ptr, length); return; } else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD) { png_warning(png_ptr, "Duplicate bKGD chunk"); png_crc_finish(png_ptr, length); return; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) truelen = 1; else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) truelen = 6; else truelen = 2; if (length != truelen) { png_warning(png_ptr, "Incorrect bKGD chunk length"); png_crc_finish(png_ptr, length); return; } png_crc_read(png_ptr, buf, truelen); if (png_crc_finish(png_ptr, 0)) return; /* We convert the index value into RGB components so that we can allow * arbitrary RGB values for background when we have transparency, and * so it is easy to determine the RGB values of the background color * from the info_ptr struct. */ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { png_ptr->background.index = buf[0]; png_ptr->background.red = (png_uint_16)png_ptr->palette[buf[0]].red; png_ptr->background.green = (png_uint_16)png_ptr->palette[buf[0]].green; png_ptr->background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue; } else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */ { png_ptr->background.red = png_ptr->background.green = png_ptr->background.blue = png_ptr->background.gray = png_get_uint_16(buf); } else { png_ptr->background.red = png_get_uint_16(buf); png_ptr->background.green = png_get_uint_16(buf + 2); png_ptr->background.blue = png_get_uint_16(buf + 4); } png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));}#endif#if defined(PNG_READ_hIST_SUPPORTED)voidpng_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length){ int num, i; png_debug(1, "in png_handle_hIST\n"); if (!(png_ptr->mode & PNG_HAVE_IHDR)) png_error(png_ptr, "Missing IHDR before hIST"); else if (png_ptr->mode & PNG_HAVE_IDAT) { png_warning(png_ptr, "Invalid hIST after IDAT"); png_crc_finish(png_ptr, length); return; } else if (!(png_ptr->mode & PNG_HAVE_PLTE)) { png_warning(png_ptr, "Missing PLTE before hIST"); png_crc_finish(png_ptr, length); return; } else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST) { png_warning(png_ptr, "Duplicate hIST chunk"); png_crc_finish(png_ptr, length); return; } if (length != (png_uint_32)(2 * png_ptr->num_palette)) { png_warning(png_ptr, "Incorrect hIST chunk length");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -