Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45c4667

Browse files
efiringmdboom
authored andcommitted
Support libpng versions 1.2 through 1.5.x.
Direct access to the info_ptr is no longer allowed; png_get_* functions have been available at least since 1.2.x. Conflicts: CHANGELOG
1 parent 6ab7b18 commit 45c4667

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
not responding to the c kwarg. The symbols have no
2020
face area, so only the edgecolor is visible. - EF
2121

22+
2011-02-27 Support libpng version 1.5.x; suggestion by Michael
23+
Albert. Changed installation specification to a
24+
minimum of libpng version 1.2. - EF
25+
26+
2011-02-20 clabel accepts a callable as an fmt kwarg; modified
27+
patch by Daniel Hyams. - EF
28+
2229
2011-02-07 Quick workaround for dviread bug #3175113 - JKS
2330

2431
2011-01-04 Tag 1.0.1 for release at r8896

doc/users/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ libraries themselves.
138138
array support for python (`download
139139
<http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103>`__)
140140

141-
libpng 1.1 (or later)
141+
libpng 1.2 (or later)
142142
library for loading and saving :term:`PNG` files (`download
143143
<http://www.libpng.org/pub/png/libpng.html>`__). libpng requires
144144
zlib. If you are a windows user, you can ignore this since we

src/_png.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,18 @@ _png_module::read_png(const Py::Tuple& args)
350350
png_set_sig_bytes(png_ptr, 8);
351351
png_read_info(png_ptr, info_ptr);
352352

353-
png_uint_32 width = info_ptr->width;
354-
png_uint_32 height = info_ptr->height;
353+
png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
354+
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
355355

356-
int bit_depth = info_ptr->bit_depth;
356+
int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
357357

358358
// Unpack 1, 2, and 4-bit images
359359
if (bit_depth < 8)
360360
png_set_packing(png_ptr);
361361

362362
// If sig bits are set, shift data
363363
png_color_8p sig_bit;
364-
if ((info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) &&
364+
if ((png_get_color_type(png_ptr, info_ptr) != PNG_COLOR_TYPE_PALETTE) &&
365365
png_get_sBIT(png_ptr, info_ptr, &sig_bit))
366366
{
367367
png_set_shift(png_ptr, sig_bit);
@@ -374,13 +374,13 @@ _png_module::read_png(const Py::Tuple& args)
374374
}
375375

376376
// Convert palletes to full RGB
377-
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
377+
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE)
378378
{
379379
png_set_palette_to_rgb(png_ptr);
380380
}
381381

382382
// If there's an alpha channel convert gray to RGB
383-
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
383+
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
384384
{
385385
png_set_gray_to_rgb(png_ptr);
386386
}
@@ -408,11 +408,11 @@ _png_module::read_png(const Py::Tuple& args)
408408
npy_intp dimensions[3];
409409
dimensions[0] = height; //numrows
410410
dimensions[1] = width; //numcols
411-
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
411+
if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA)
412412
{
413413
dimensions[2] = 4; //RGBA images
414414
}
415-
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
415+
else if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_COLOR)
416416
{
417417
dimensions[2] = 3; //RGB images
418418
}
@@ -421,7 +421,8 @@ _png_module::read_png(const Py::Tuple& args)
421421
dimensions[2] = 1; //Greyscale images
422422
}
423423
//For gray, return an x by y array, not an x by y by 1
424-
int num_dims = (info_ptr->color_type & PNG_COLOR_MASK_COLOR) ? 3 : 2;
424+
int num_dims = (png_get_color_type(png_ptr, info_ptr)
425+
& PNG_COLOR_MASK_COLOR) ? 3 : 2;
425426

426427
double max_value = (1 << ((bit_depth < 8) ? 8 : bit_depth)) - 1;
427428
PyArrayObject *A = (PyArrayObject *) PyArray_SimpleNew(

0 commit comments

Comments
 (0)