/* * This file is part of the Advance project. * * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Andrea Mazzoleni * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * In addition, as a special exception, Andrea Mazzoleni * gives permission to link the code of this program with * the MAME library (or with modified versions of MAME that use the * same license as MAME), and distribute linked combinations including * the two. You must obey the GNU General Public License in all * respects for all of the code used other than MAME. If you modify * this file, you may extend this exception to your version of the * file, but you are not obligated to do so. If you do not wish to * do so, delete this exception statement from your version. */ #include "portable.h" #include "pngdef.h" #include "rgb.h" #include "png.h" #include "mode.h" #include "endianrw.h" /** * Get the color definition of a PNG image. * \param bytes_per_pixel Size of the pixel. */ adv_color_def adv_png_color_def(unsigned bytes_per_pixel) { adv_color_def def; #ifdef USE_LSB if (bytes_per_pixel == 3 || bytes_per_pixel == 4) def = color_def_make_rgb_from_sizelenpos(bytes_per_pixel, 8, 0, 8, 8, 8, 16); else def = color_def_make(adv_color_type_palette); #else if (bytes_per_pixel == 3) def = color_def_make_rgb_from_sizelenpos(bytes_per_pixel, 8, 16, 8, 8, 8, 0); else if (bytes_per_pixel == 4) def = color_def_make_rgb_from_sizelenpos(bytes_per_pixel, 8, 24, 8, 16, 8, 8); else def = color_def_make(adv_color_type_palette); #endif return def; } /** * Check if a color def is supported by PNG format. */ adv_bool adv_png_color_def_is_valid(adv_color_def def) { unsigned pixel = color_def_bytes_per_pixel_get(def); return def == adv_png_color_def(pixel); } static adv_error png_write_raw_pal( unsigned pix_width, unsigned pix_height, unsigned pix_pixel, const unsigned char* pix_ptr, int pix_pixel_pitch, int pix_scanline_pitch, adv_color_rgb* rgb_ptr, unsigned rgb_max, adv_bool fast, adv_fz* f, unsigned* count ) { uint8 palette[3*256]; uint8* i_ptr; unsigned i_size; uint8* p; unsigned i, j; if (rgb_max > 256) goto err; for (i=0;i