?? img_png.c
字號:
/* SDL_image: An example image loading library for use with SDL Copyright (C) 1997-2006 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Sam Lantinga slouken@libsdl.org*//* This is a PNG image file loading framework */#include <stdlib.h>#include <stdio.h>#include "SDL_image.h"#ifdef LOAD_PNG/*============================================================================= File: SDL_png.c Purpose: A PNG loader and saver for the SDL library Revision: Created by: Philippe Lavoie (2 November 1998) lavoie@zeus.genie.uottawa.ca Modified by: Copyright notice: Copyright (C) 1998 Philippe Lavoie This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Comments: The load and save routine are basically the ones you can find in the example.c file from the libpng distribution. Changes: 5/17/99 - Modified to use the new SDL data sources - Sam Lantinga=============================================================================*/#include "SDL_endian.h"#ifdef macintosh#define MACOS#endif#include <png.h>static struct { int loaded; void *handle; png_infop (*png_create_info_struct) (png_structp png_ptr); png_structp (*png_create_read_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn); void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr); png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method); png_voidp (*png_get_io_ptr) (png_structp png_ptr); png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values); png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag); void (*png_read_image) (png_structp png_ptr, png_bytepp image); void (*png_read_info) (png_structp png_ptr, png_infop info_ptr); void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr); void (*png_set_expand) (png_structp png_ptr); void (*png_set_gray_to_rgb) (png_structp png_ptr); void (*png_set_packing) (png_structp png_ptr); void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn); void (*png_set_strip_16) (png_structp png_ptr); int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check);} lib;#ifdef LOAD_PNG_DYNAMICint IMG_InitPNG(){ if ( lib.loaded == 0 ) { lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC); if ( lib.handle == NULL ) { return -1; } lib.png_create_info_struct = (png_infop (*) (png_structp)) SDL_LoadFunction(lib.handle, "png_create_info_struct"); if ( lib.png_create_info_struct == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_create_read_struct = (png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr)) SDL_LoadFunction(lib.handle, "png_create_read_struct"); if ( lib.png_create_read_struct == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_destroy_read_struct = (void (*) (png_structpp, png_infopp, png_infopp)) SDL_LoadFunction(lib.handle, "png_destroy_read_struct"); if ( lib.png_destroy_read_struct == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_get_IHDR = (png_uint_32 (*) (png_structp, png_infop, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *)) SDL_LoadFunction(lib.handle, "png_get_IHDR"); if ( lib.png_get_IHDR == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_get_io_ptr = (png_voidp (*) (png_structp)) SDL_LoadFunction(lib.handle, "png_get_io_ptr"); if ( lib.png_get_io_ptr == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_get_tRNS = (png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *)) SDL_LoadFunction(lib.handle, "png_get_tRNS"); if ( lib.png_get_tRNS == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_get_valid = (png_uint_32 (*) (png_structp, png_infop, png_uint_32)) SDL_LoadFunction(lib.handle, "png_get_valid"); if ( lib.png_get_valid == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_read_image = (void (*) (png_structp, png_bytepp)) SDL_LoadFunction(lib.handle, "png_read_image"); if ( lib.png_read_image == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_read_info = (void (*) (png_structp, png_infop)) SDL_LoadFunction(lib.handle, "png_read_info"); if ( lib.png_read_info == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_read_update_info = (void (*) (png_structp, png_infop)) SDL_LoadFunction(lib.handle, "png_read_update_info"); if ( lib.png_read_update_info == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_set_expand = (void (*) (png_structp)) SDL_LoadFunction(lib.handle, "png_set_expand"); if ( lib.png_set_expand == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_set_gray_to_rgb = (void (*) (png_structp)) SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb"); if ( lib.png_set_gray_to_rgb == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_set_packing = (void (*) (png_structp)) SDL_LoadFunction(lib.handle, "png_set_packing"); if ( lib.png_set_packing == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_set_read_fn = (void (*) (png_structp, png_voidp, png_rw_ptr)) SDL_LoadFunction(lib.handle, "png_set_read_fn"); if ( lib.png_set_read_fn == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_set_strip_16 = (void (*) (png_structp)) SDL_LoadFunction(lib.handle, "png_set_strip_16"); if ( lib.png_set_strip_16 == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_sig_cmp = (int (*) (png_bytep, png_size_t, png_size_t)) SDL_LoadFunction(lib.handle, "png_sig_cmp"); if ( lib.png_sig_cmp == NULL ) { SDL_UnloadObject(lib.handle); return -1; } } ++lib.loaded; return 0;}void IMG_QuitPNG(){ if ( lib.loaded == 0 ) { return; } if ( lib.loaded == 1 ) { SDL_UnloadObject(lib.handle); } --lib.loaded;}#elseint IMG_InitPNG(){ if ( lib.loaded == 0 ) { lib.png_create_info_struct = png_create_info_struct; lib.png_create_read_struct = png_create_read_struct; lib.png_destroy_read_struct = png_destroy_read_struct; lib.png_get_IHDR = png_get_IHDR; lib.png_get_io_ptr = png_get_io_ptr; lib.png_get_tRNS = png_get_tRNS; lib.png_get_valid = png_get_valid; lib.png_read_image = png_read_image; lib.png_read_info = png_read_info; lib.png_read_update_info = png_read_update_info; lib.png_set_expand = png_set_expand; lib.png_set_gray_to_rgb = png_set_gray_to_rgb; lib.png_set_packing = png_set_packing; lib.png_set_read_fn = png_set_read_fn; lib.png_set_strip_16 = png_set_strip_16; lib.png_sig_cmp = png_sig_cmp; } ++lib.loaded; return 0;}void IMG_QuitPNG(){ if ( lib.loaded == 0 ) { return; } if ( lib.loaded == 1 ) { } --lib.loaded;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -