• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/png.c

Go to the documentation of this file.
00001 /*
00002  * PNG image format
00003  * Copyright (c) 2003 Fabrice Bellard
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 /* Mask to determine which y pixels are valid in a pass */
00028 const uint8_t ff_png_pass_ymask[NB_PASSES] = {
00029     0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55,
00030 };
00031 
00032 /* minimum x value */
00033 static const uint8_t ff_png_pass_xmin[NB_PASSES] = {
00034     0, 4, 0, 2, 0, 1, 0
00035 };
00036 
00037 /* x shift to get row width */
00038 static const uint8_t ff_png_pass_xshift[NB_PASSES] = {
00039     3, 3, 2, 2, 1, 1, 0
00040 };
00041 
00042 /* Mask to determine which pixels are valid in a pass */
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 /* compute the row size of an interleaved pass */
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 }
Generated on Fri Feb 1 2013 14:34:41 for FFmpeg by doxygen 1.7.1