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