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 const uint8_t ff_pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
00025 const uint8_t ff_mngsig[8] = {138, 77, 78, 71, 13, 10, 26, 10};
00026
00027
00028 const uint8_t ff_png_pass_ymask[NB_PASSES] = {
00029 0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55,
00030 };
00031
00032
00033 static const uint8_t ff_png_pass_xmin[NB_PASSES] = {
00034 0, 4, 0, 2, 0, 1, 0
00035 };
00036
00037
00038 static const uint8_t ff_png_pass_xshift[NB_PASSES] = {
00039 3, 3, 2, 2, 1, 1, 0
00040 };
00041
00042 void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
00043 {
00044 if(items >= UINT_MAX / size)
00045 return NULL;
00046 return av_malloc(items * size);
00047 }
00048
00049 void ff_png_zfree(void *opaque, void *ptr)
00050 {
00051 av_free(ptr);
00052 }
00053
00054 int ff_png_get_nb_channels(int color_type)
00055 {
00056 int channels;
00057 channels = 1;
00058 if ((color_type & (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)) ==
00059 PNG_COLOR_MASK_COLOR)
00060 channels = 3;
00061 if (color_type & PNG_COLOR_MASK_ALPHA)
00062 channels++;
00063 return channels;
00064 }
00065
00066
00067 int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
00068 {
00069 int shift, xmin, pass_width;
00070
00071 xmin = ff_png_pass_xmin[pass];
00072 if (width <= xmin)
00073 return 0;
00074 shift = ff_png_pass_xshift[pass];
00075 pass_width = (width - xmin + (1 << shift) - 1) >> shift;
00076 return (pass_width * bits_per_pixel + 7) >> 3;
00077 }