Splitted Load_PNG to allow usage by Load_ICO
Introduces Load_PNG_Sub() some .ico contain PNG images
This commit is contained in:
parent
c2486ed629
commit
37a5a0a85c
@ -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)
|
||||
@ -4297,13 +4285,13 @@ void Load_PNG(T_IO_Context * context)
|
||||
// Map low bpp greyscales to full 8bit (0-255 range)
|
||||
if (bit_depth < 8)
|
||||
{
|
||||
#if (PNG_LIBPNG_VER_MAJOR <= 1) && (PNG_LIBPNG_VER_MINOR < 4)
|
||||
#if (PNG_LIBPNG_VER_MAJOR <= 1) && (PNG_LIBPNG_VER_MINOR < 4)
|
||||
// Works well with png 1.2.8, but deprecated in 1.4 ...
|
||||
png_set_gray_1_2_4_to_8(png_ptr);
|
||||
#else
|
||||
#else
|
||||
// ...where this seems to replace it:
|
||||
png_set_expand_gray_1_2_4_to_8(png_ptr);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create greyscale palette
|
||||
@ -4461,8 +4449,28 @@ void Load_PNG(T_IO_Context * context)
|
||||
else
|
||||
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user