00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avcodec.h"
00022 #include "png.h"
00023
00024
00025 const uint8_t ff_png_pass_ymask[NB_PASSES] = {
00026 0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55,
00027 };
00028
00029
00030 static const uint8_t ff_png_pass_xmin[NB_PASSES] = {
00031 0, 4, 0, 2, 0, 1, 0
00032 };
00033
00034
00035 static const uint8_t ff_png_pass_xshift[NB_PASSES] = {
00036 3, 3, 2, 2, 1, 1, 0
00037 };
00038
00039 void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
00040 {
00041 if(items >= UINT_MAX / size)
00042 return NULL;
00043 return av_malloc(items * size);
00044 }
00045
00046 void ff_png_zfree(void *opaque, void *ptr)
00047 {
00048 av_free(ptr);
00049 }
00050
00051 int ff_png_get_nb_channels(int color_type)
00052 {
00053 int channels;
00054 channels = 1;
00055 if ((color_type & (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)) ==
00056 PNG_COLOR_MASK_COLOR)
00057 channels = 3;
00058 if (color_type & PNG_COLOR_MASK_ALPHA)
00059 channels++;
00060 return channels;
00061 }
00062
00063
00064 int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
00065 {
00066 int shift, xmin, pass_width;
00067
00068 xmin = ff_png_pass_xmin[pass];
00069 if (width <= xmin)
00070 return 0;
00071 shift = ff_png_pass_xshift[pass];
00072 pass_width = (width - xmin + (1 << shift) - 1) >> shift;
00073 return (pass_width * bits_per_pixel + 7) >> 3;
00074 }