row_bytes = ((png_ptr->iwidth * (png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
png_read_start_row(png_structp png_ptr){#ifdef PNG_USE_LOCAL_ARRAYS   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */   /* start of interlace block */   const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};   /* offset to next interlace block */   const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};   /* start of interlace block in the y direction */   const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};   /* offset to next interlace block in the y direction */   const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};#endif   int max_pixel_depth;   png_uint_32 row_bytes;   png_debug(1, "in png_read_start_row\n");   png_ptr->zstream.avail_in = 0;   png_init_read_transformations(png_ptr);   if (png_ptr->interlaced)   {      if (!(png_ptr->transformations & PNG_INTERLACE))         png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -            png_pass_ystart[0]) / png_pass_yinc[0];      else         png_ptr->num_rows = png_ptr->height;      png_ptr->iwidth = (png_ptr->width +         png_pass_inc[png_ptr->pass] - 1 -         png_pass_start[png_ptr->pass]) /         png_pass_inc[png_ptr->pass];         row_bytes = ((png_ptr->iwidth *            (png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;         png_ptr->irowbytes = (png_size_t)row_bytes;         if((png_uint_32)png_ptr->irowbytes != row_bytes)            png_error(png_ptr, "Rowbytes overflow in png_read_start_row");   }   else   {      png_ptr->num_rows = png_ptr->height;      png_ptr->iwidth = png_ptr->width;      png_ptr->irowbytes = png_ptr->rowbytes + 1;   }   max_pixel_depth = png_ptr->pixel_depth;#if defined(PNG_READ_PACK_SUPPORTED)   if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)      max_pixel_depth = 8;#endif#if defined(PNG_READ_EXPAND_SUPPORTED)   if (png_ptr->transformations & PNG_EXPAND)   {      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)      {         if (png_ptr->num_trans)            max_pixel_depth = 32;         else            max_pixel_depth = 24;      }      else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)      {         if (max_pixel_depth < 8)            max_pixel_depth = 8;         if (png_ptr->num_trans)            max_pixel_depth *= 2;      }      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)      {         if (png_ptr->num_trans)         {            max_pixel_depth *= 4;            max_pixel_depth /= 3;         }      }   }#endif#if defined(PNG_READ_FILLER_SUPPORTED)   if (png_ptr->transformations & (PNG_FILLER))   {      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)         max_pixel_depth = 32;      else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)      {         if (max_pixel_depth <= 8)            max_pixel_depth = 16;         else            max_pixel_depth = 32;      }      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)      {         if (max_pixel_depth <= 32)            max_pixel_depth = 32;         else            max_pixel_depth = 64;      }   }#endif#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)   if (png_ptr->transformations & PNG_GRAY_TO_RGB)   {      if (#if defined(PNG_READ_EXPAND_SUPPORTED)        (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||#endif#if defined(PNG_READ_FILLER_SUPPORTED)        (png_ptr->transformations & (PNG_FILLER)) ||#endif        png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)      {         if (max_pixel_depth <= 16)            max_pixel_depth = 32;         else            max_pixel_depth = 64;      }      else      {         if (max_pixel_depth <= 8)           {             if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)               max_pixel_depth = 32;             else               max_pixel_depth = 24;           }         else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)            max_pixel_depth = 64;         else            max_pixel_depth = 48;      }   }#endif#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)   if(png_ptr->transformations & PNG_USER_TRANSFORM)     {       int user_pixel_depth=png_ptr->user_transform_depth*         png_ptr->user_transform_channels;       if(user_pixel_depth > max_pixel_depth)         max_pixel_depth=user_pixel_depth;     }#endif   /* align the width on the next larger 8 pixels.  Mainly used      for interlacing */   row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));   /* calculate the maximum bytes needed, adding a byte and a pixel      for safety's sake */   row_bytes = ((row_bytes * (png_uint_32)max_pixel_depth + 7) >> 3) +      1 + ((max_pixel_depth + 7) >> 3);#ifdef PNG_MAX_MALLOC_64K   if (row_bytes > (png_uint_32)65536L)      png_error(png_ptr, "This image requires a row greater than 64KB");#endif   png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);   png_ptr->row_buf = png_ptr->big_row_buf+32;#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD)   png_ptr->row_buf_size = row_bytes;#endif#ifdef PNG_MAX_MALLOC_64K   if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)      png_error(png_ptr, "This image requires a row greater than 64KB");#endif   png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(      png_ptr->rowbytes + 1));   png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);   png_debug1(3, "width = %lu,\n", png_ptr->width);   png_debug1(3, "height = %lu,\n", png_ptr->height);   png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);   png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);   png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);   png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);   png_ptr->flags |= PNG_FLAG_ROW_INIT;}