mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-04 13:47:04 -04:00
Added Propeng's tsoscan, and removed old files from libpng and zlib
This commit is contained in:
parent
1f7061d98a
commit
67fa76c747
10 changed files with 985 additions and 1 deletions
136
Tools/iff2html/image.c
Normal file
136
Tools/iff2html/image.c
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
iff2html - iff web page description generator
|
||||
image.c - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
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 <stdio.h>
|
||||
#include <iff/iff.h>
|
||||
#include <bmp/read_bmp.h>
|
||||
#include <setjmp.h>
|
||||
#include <libpng/png.h>
|
||||
|
||||
int WritePNG(const char * OutName, const IFFChunk * ChunkData, 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;
|
||||
|
||||
if(ChunkData){
|
||||
/* BMP_ or FBMP chunk */
|
||||
bmpheader_t BMPHeader;
|
||||
|
||||
if(!bmp_read_header(&BMPHeader, ChunkData->Data, ChunkData->Size - 76))
|
||||
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;
|
||||
|
||||
row_pointers = malloc(Image.Height * sizeof(png_bytep));
|
||||
if(row_pointers == NULL){
|
||||
free(Image.Data);
|
||||
return 0;
|
||||
}
|
||||
for(i=0; i<Image.Height; i++)
|
||||
row_pointers[i] = Image.Data + (Image.Height-i-1)*Image.Width*3;
|
||||
}else{
|
||||
/* SPR# or SPR2 sprite */
|
||||
Image.Width = Sprite->Width;
|
||||
Image.Height = Sprite->Height;
|
||||
Image.Data = Sprite->BGRA32Data;
|
||||
}
|
||||
|
||||
row_pointers = malloc(Image.Height * sizeof(png_bytep));
|
||||
if(row_pointers == NULL){
|
||||
if(ChunkData) free(Image.Data);
|
||||
return 0;
|
||||
}
|
||||
for(i=0; i<Image.Height; i++)
|
||||
row_pointers[i] = Image.Data + (Image.Height-i-1)*Image.Width*((ChunkData)?3:4);
|
||||
|
||||
/****
|
||||
** PNG handling
|
||||
*/
|
||||
|
||||
/* Initialization */
|
||||
hFile = fopen(OutName, "wb");
|
||||
if(hFile == NULL){
|
||||
free(row_pointers);
|
||||
if(ChunkData) free(Image.Data);
|
||||
return 0;
|
||||
}
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if(png_ptr == NULL){
|
||||
fclose(hFile);
|
||||
free(row_pointers);
|
||||
if(ChunkData) free(Image.Data);
|
||||
return 0;
|
||||
}
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if(info_ptr == NULL){
|
||||
png_destroy_write_struct(&png_ptr, NULL);
|
||||
fclose(hFile);
|
||||
free(row_pointers);
|
||||
if(ChunkData) free(Image.Data);
|
||||
return 0;
|
||||
}
|
||||
if(setjmp(png_jmpbuf(png_ptr))){
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
fclose(hFile);
|
||||
free(row_pointers);
|
||||
if(ChunkData) free(Image.Data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, hFile);
|
||||
|
||||
png_set_filter(png_ptr, 0, PNG_ALL_FILTERS);
|
||||
png_set_compression_level(png_ptr, 9);
|
||||
png_set_compression_mem_level(png_ptr, 9);
|
||||
png_set_compression_window_bits(png_ptr, 15);
|
||||
png_set_compression_buffer_size(png_ptr, 32768);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, Image.Width, Image.Height, 8, ChunkData ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
png_set_rows(png_ptr, info_ptr, row_pointers);
|
||||
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR, NULL);
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
fclose(hFile);
|
||||
free(row_pointers);
|
||||
|
||||
if(ChunkData){
|
||||
free(Image.Data);
|
||||
*Width = Image.Width;
|
||||
*Height = Image.Height;
|
||||
}
|
||||
return 1;
|
||||
}
|
19
Tools/iff2html/image.h
Normal file
19
Tools/iff2html/image.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
iff2html - iff web page description generator
|
||||
image.h - Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
int WritePNG(const char * OutName, const IFFChunk * ChunkData, const IFFSprite * Sprite, size_t * Width, size_t * Height);
|
Loading…
Add table
Add a link
Reference in a new issue