8000 Support libpng versions 1.2 through 1.5.x. · radford/matplotlib@55ae1ec · GitHub
[go: up one dir, main page]

Skip to content

Commit 55ae1ec

Browse files
committed
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.
1 parent 25a06fb commit 55ae1ec

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2011-02-27 Support libpng version 1.5.x; suggestion by Michael
2+
Albert. Changed installation specification to a
3+
minimum of libpng version 1.2. - EF
4+
15
2011-02-20 clabel accepts a callable as an fmt kwarg; modified
26
patch by Daniel Hyams. - EF
37

doc/users/installing.rst

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

152-
libpng 1.1 (or later)
152+
libpng 1.2 (or later)
153153
library for loading and saving :term:`PNG` files (`download
154154
<http://www.libpng.org/pub/png/libpng.html>`__). libpng requires
155155
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
@@ -351,18 +351,18 @@ _png_module::read_png(const Py::Tuple& args)
351351
png_set_sig_bytes(png_ptr, 8);
352352
png_read_info(png_ptr, info_ptr);
353353

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

357-
int bit_depth = info_ptr->bit_depth;
357+
int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
358358

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

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

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

383383
// If there's an alpha channel convert gray to RGB
384-
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
384+
if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY_ALPHA)
385385
{
386386
png_set_gray_to_rgb(png_ptr);
387387
}
@@ -409,11 +409,11 @@ _png_module::read_png(const Py::Tuple& args)
409409
npy_intp dimensions[3];
410410
dimensions[0] = height; //numrows
411411
dimensions[1] = width; //numcols
412-
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
412+
if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA)
413413
{
414414
dimensions[2] = 4; //RGBA images
415415
}
416-
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
416+
else if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_COLOR)
417417
{
418418
dimensions[2] = 3; //RGB images
419419
}
@@ -422,7 +422,8 @@ _png_module::read_png(const Py::Tuple& args)
422422
dimensions[2] = 1; //Greyscale images
423423
}
424424
//For gray, return an x by y array, not an x by y by 1
425-
int num_dims = (info_ptr->color_type & PNG_COLOR_MASK_COLOR) ? 3 : 2;
425+
int num_dims = (png_get_color_type(png_ptr, info_ptr)
426+
& PNG_COLOR_MASK_COLOR) ? 3 : 2;
426427

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

0 commit comments

Comments
 (0)
0