mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Updated libpng to current version.
This commit is contained in:
parent
bd2a951314
commit
ca7007613d
1 changed files with 286 additions and 287 deletions
|
@ -15,19 +15,19 @@
|
|||
|
||||
// =============================================================================
|
||||
|
||||
static void user_read_fn (png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
static void user_read_fn(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_size_t check;
|
||||
|
||||
// Read() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
// instead of an int, which is what Read() actually returns.
|
||||
check = (png_size_t)((File*)png_ptr->io_ptr)->Read (data, length);
|
||||
check = (png_size_t)((File*)png_get_io_ptr(png_ptr))->Read(data, length);
|
||||
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Read Error");
|
||||
}
|
||||
|
||||
bool Image::LoadPNG (File& file)
|
||||
bool Image::LoadPNG(File& file)
|
||||
{
|
||||
unsigned char sig[8], red, green, blue;
|
||||
unsigned char *image_data = NULL;
|
||||
|
@ -44,9 +44,9 @@ bool Image::LoadPNG (File& file)
|
|||
int image_channels;
|
||||
double gamma;
|
||||
|
||||
FreeData ();
|
||||
FreeData();
|
||||
|
||||
file.Read (sig, 8);
|
||||
file.Read(sig, 8);
|
||||
if (!png_check_sig(sig, 8))
|
||||
return false; // bad signature
|
||||
|
||||
|
@ -61,21 +61,20 @@ bool Image::LoadPNG (File& file)
|
|||
return false; // out of memory
|
||||
}
|
||||
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
png_set_read_fn(png_ptr, (void *)&file, user_read_fn);
|
||||
// png_init_io(png_ptr, f);
|
||||
png_set_read_fn(png_ptr, (void*)&file, user_read_fn);
|
||||
// png_init_io(png_ptr, f);
|
||||
png_set_sig_bytes(png_ptr, 8); // we already read the 8 signature bytes
|
||||
|
||||
png_read_info(png_ptr, info_ptr); // read all PNG info up to image data
|
||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
NULL, NULL, NULL);
|
||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
|
||||
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return false;
|
||||
|
@ -85,7 +84,7 @@ bool Image::LoadPNG (File& file)
|
|||
{
|
||||
png_get_bKGD(png_ptr, info_ptr, &pBackground);
|
||||
|
||||
if (setjmp (png_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return false;
|
||||
|
@ -117,7 +116,7 @@ bool Image::LoadPNG (File& file)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (setjmp (png_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return false;
|
||||
|
@ -259,23 +258,23 @@ bool Image::LoadPNG (File& file)
|
|||
|
||||
// =============================================================================
|
||||
|
||||
static void user_write_fn (png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
static void user_write_fn(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
|
||||
check = ((File*)png_ptr->io_ptr)->Write (data, length);
|
||||
check = ((File*)png_get_io_ptr(png_ptr))->Write(data, length);
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
}
|
||||
|
||||
static void user_flush_fn (png_structp png_ptr)
|
||||
static void user_flush_fn(png_structp png_ptr)
|
||||
{
|
||||
((File*)png_ptr->io_ptr)->Flush ();
|
||||
((File*)png_get_io_ptr(png_ptr))->Flush();
|
||||
}
|
||||
|
||||
bool Image::SavePNG (File& file, bool transparent, bool interlaced, unsigned char* background) const
|
||||
bool Image::SavePNG(File& file, bool transparent, bool interlaced, unsigned char* background) const
|
||||
{
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
|
@ -295,16 +294,16 @@ bool Image::SavePNG (File& file, bool transparent, bool interlaced, unsigned cha
|
|||
return false;
|
||||
}
|
||||
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
// png_init_io(png_ptr, fp);
|
||||
png_set_write_fn (png_ptr, &file, user_write_fn, user_flush_fn);
|
||||
// png_init_io(png_ptr, fp);
|
||||
png_set_write_fn(png_ptr, &file, user_write_fn, user_flush_fn);
|
||||
|
||||
png_set_IHDR (png_ptr, info_ptr, m_nWidth, m_nHeight, 8,
|
||||
png_set_IHDR(png_ptr, info_ptr, m_nWidth, m_nHeight, 8,
|
||||
transparent ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB,
|
||||
interlaced ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
|
@ -334,7 +333,7 @@ bool Image::SavePNG (File& file, bool transparent, bool interlaced, unsigned cha
|
|||
if (transparent)
|
||||
{
|
||||
unsigned char *buf, *src, *dst, alpha;
|
||||
dst = buf = (unsigned char*)malloc (m_nWidth*m_nHeight*4);
|
||||
dst = buf = (unsigned char*)malloc(m_nWidth*m_nHeight*4);
|
||||
src = m_pData;
|
||||
|
||||
for (i = 0; i < m_nWidth*m_nHeight; i++)
|
||||
|
|
Loading…
Reference in a new issue