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
00043 const uint8_t ff_png_pass_mask[NB_PASSES] = {
00044 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff,
00045 };
00046
00047 void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size)
00048 {
00049 if(items >= UINT_MAX / size)
00050 return NULL;
00051 return av_malloc(items * size);
00052 }
00053
00054 void ff_png_zfree(void *opaque, void *ptr)
00055 {
00056 av_free(ptr);
00057 }
00058
00059 int ff_png_get_nb_channels(int color_type)
00060 {
00061 int channels;
00062 channels = 1;
00063 if ((color_type & (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)) ==
00064 PNG_COLOR_MASK_COLOR)
00065 channels = 3;
00066 if (color_type & PNG_COLOR_MASK_ALPHA)
00067 channels++;
00068 return channels;
00069 }
00070
00071
00072 int ff_png_pass_row_size(int pass, int bits_per_pixel, int width)
00073 {
00074 int shift, xmin, pass_width;
00075
00076 xmin = ff_png_pass_xmin[pass];
00077 if (width <= xmin)
00078 return 0;
00079 shift = ff_png_pass_xshift[pass];
00080 pass_width = (width - xmin + (1 << shift) - 1) >> shift;
00081 return (pass_width * bits_per_pixel + 7) >> 3;
00082 }