• 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 "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 /* Mask to determine which y pixels are valid in a pass */
00029 const uint8_t ff_png_pass_ymask[NB_PASSES] = {
00030     0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55,
00031 };
00032 
00033 /* minimum x value */
00034 const uint8_t ff_png_pass_xmin[NB_PASSES] = {
00035     0, 4, 0, 2, 0, 1, 0
00036 };
00037 
00038 /* x shift to get row width */
00039 const uint8_t ff_png_pass_xshift[NB_PASSES] = {
00040     3, 3, 2, 2, 1, 1, 0
00041 };
00042 
00043 /* Mask to determine which pixels are valid in a pass */
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 /* compute the row size of an interleaved pass */
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 }

Generated on Fri Sep 16 2011 17:17:41 for FFmpeg by  doxygen 1.7.1