/* iff2html - iff web page description generator image.c - Copyright (c) 2012 Niotso Project Author(s): Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include /* Used for libpng */ #include "opngreduc.h" int WritePNG(const char * OutName, const IFFChunk * ChunkData, int ZBuffer, const IFFSprite * Sprite, size_t * Width, size_t * Height){ FILE * hFile; png_structp png_ptr; png_infop info_ptr; png_bytep * row_pointers; unsigned i; struct { size_t Width; size_t Height; uint8_t * Data; } Image; /* We must swap from BGR to RGB; this cannot be done with libpng when you use ** opng_reduce_image due to the state that it leaves png_ptr in */ if(ChunkData){ /* BMP_ or FBMP chunk */ bmpheader_t BMPHeader; if(!bmp_read_header(&BMPHeader, ChunkData->Data, ChunkData->Size)) return 0; Image.Data = malloc(BMPHeader.DecompressedSize); if(Image.Data == NULL) return 0; if(!bmp_read_data(&BMPHeader, ChunkData->Data, Image.Data)){ free(Image.Data); return 0; } Image.Width = BMPHeader.biWidth; Image.Height = BMPHeader.biHeight; for(i=0; iWidth; Image.Height = Sprite->Height; Image.Data = (!ZBuffer) ? Sprite->BGRA32Data : Sprite->ZBuffer; if(!ZBuffer){ for(i=0; i