Splitted Load_PNG to allow usage by Load_ICO

Introduces Load_PNG_Sub()
some .ico contain PNG images
This commit is contained in:
Thomas Bernard 2018-01-17 10:13:03 +01:00
parent c2486ed629
commit 37a5a0a85c

View File

@ -63,6 +63,10 @@
#include "pages.h"
#include "windows.h" // Best_color()
#ifndef __no_pnglib__
static void Load_PNG_Sub(T_IO_Context * context, FILE * file);
#endif
//////////////////////////////////// IMG ////////////////////////////////////
// -- Tester si un fichier est au format IMG --------------------------------
@ -4151,33 +4155,12 @@ int PNG_read_unknown_chunk(png_structp ptr, png_unknown_chunkp chunk)
}
png_bytep * Row_pointers;
// -- Lire un fichier au format PNG -----------------------------------------
void Load_PNG(T_IO_Context * context)
static void Load_PNG_Sub(T_IO_Context * context, FILE * file)
{
FILE *file; // Fichier du fichier
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
byte png_header[8];
byte row_pointers_allocated;
png_bytep trans;
int num_trans;
png_color_16p trans_values;
png_structp png_ptr;
png_infop info_ptr;
Get_full_filename(filename, context->File_name, context->File_directory);
File_error=0;
if ((file=fopen(filename, "rb")))
{
// Load header (8 first bytes)
if (Read_bytes(file,png_header,8))
{
// Do we recognize a png file signature ?
if ( !png_sig_cmp(png_header, 0, 8))
{
// Prepare internal PNG loader
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr)
@ -4270,6 +4253,11 @@ void Load_PNG(T_IO_Context * context)
int x,y;
png_colorp palette;
int num_palette;
png_bytep * Row_pointers = NULL;
byte row_pointers_allocated = 0;
int num_trans;
png_bytep trans;
png_color_16p trans_values;
// 16-bit images
if (bit_depth == 16)
@ -4462,7 +4450,27 @@ void Load_PNG(T_IO_Context * context)
File_error=1;
}
}
/*Close_lecture();*/
void Load_PNG(T_IO_Context * context)
{
FILE *file; // Fichier du fichier
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
byte png_header[8];
Get_full_filename(filename, context->File_name, context->File_directory);
File_error=0;
if ((file=fopen(filename, "rb")))
{
// Load header (8 first bytes)
if (Read_bytes(file,png_header,8))
{
// Do we recognize a png file signature ?
if ( !png_sig_cmp(png_header, 0, 8))
Load_PNG_Sub(context, file);
else
File_error=2;
}
else // Lecture header impossible: Error ne modifiant pas l'image
File_error=1;
@ -4483,6 +4491,7 @@ void Save_PNG(T_IO_Context * context)
png_infop info_ptr;
png_unknown_chunk crng_chunk;
byte cycle_data[16*6]; // Storage for color-cycling data, referenced by crng_chunk
static png_bytep * Row_pointers;
Get_full_filename(filename, context->File_name, context->File_directory);
File_error=0;