info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
png_set_IHDR(png_structp png_ptr, png_infop info_ptr,   png_uint_32 width, png_uint_32 height, int bit_depth,   int color_type, int interlace_type, int compression_type,   int filter_type){   int rowbytes_per_pixel;   png_debug1(1, "in %s storage function\n", "IHDR");   if (png_ptr == NULL || info_ptr == NULL)      return;   /* check for width and height valid values */   if (width == 0 || height == 0)      png_error(png_ptr, "Image width or height is zero in IHDR");   if (width > PNG_MAX_UINT || height > PNG_MAX_UINT)      png_error(png_ptr, "Invalid image size in IHDR");   /* check other values */   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&      bit_depth != 8 && bit_depth != 16)      png_error(png_ptr, "Invalid bit depth in IHDR");   if (color_type < 0 || color_type == 1 ||      color_type == 5 || color_type > 6)      png_error(png_ptr, "Invalid color type in IHDR");   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||       ((color_type == PNG_COLOR_TYPE_RGB ||         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))      png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");   if (interlace_type >= PNG_INTERLACE_LAST)      png_error(png_ptr, "Unknown interlace method in IHDR");   if (compression_type != PNG_COMPRESSION_TYPE_BASE)      png_error(png_ptr, "Unknown compression method in IHDR");#if defined(PNG_MNG_FEATURES_SUPPORTED)   /* Accept filter_method 64 (intrapixel differencing) only if    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and    * 2. Libpng did not read a PNG signature (this filter_method is only    *    used in PNG datastreams that are embedded in MNG datastreams) and    * 3. The application called png_permit_mng_features with a mask that    *    included PNG_FLAG_MNG_FILTER_64 and    * 4. The filter_method is 64 and    * 5. The color_type is RGB or RGBA    */   if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");   if(filter_type != PNG_FILTER_TYPE_BASE)   {     if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&        (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&        ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&        (color_type == PNG_COLOR_TYPE_RGB ||          color_type == PNG_COLOR_TYPE_RGB_ALPHA)))        png_error(png_ptr, "Unknown filter method in IHDR");     if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)        png_warning(png_ptr, "Invalid filter method in IHDR");   }#else   if(filter_type != PNG_FILTER_TYPE_BASE)      png_error(png_ptr, "Unknown filter method in IHDR");#endif   info_ptr->width = width;   info_ptr->height = height;   info_ptr->bit_depth = (png_byte)bit_depth;   info_ptr->color_type =(png_byte) color_type;   info_ptr->compression_type = (png_byte)compression_type;   info_ptr->filter_type = (png_byte)filter_type;   info_ptr->interlace_type = (png_byte)interlace_type;   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)      info_ptr->channels = 1;   else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)      info_ptr->channels = 3;   else      info_ptr->channels = 1;   if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)      info_ptr->channels++;   info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);   /* check for overflow */   rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;   if ( width > PNG_MAX_UINT/rowbytes_per_pixel - 64)   {      png_warning(png_ptr,         "Width too large to process image data; rowbytes will overflow.");      info_ptr->rowbytes = (png_size_t)0;   }   else      info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;}