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

Skip to content

Commit 64b3b06

Browse files
committed
Fix for libpng-1.4 compatibility
svn path=/branches/v0_99_maint/; revision=8116
1 parent c492ff8 commit 64b3b06

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/_png.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ Py::Object _png_module::write_png(const Py::Tuple& args)
130130
png_init_io(png_ptr, fp);
131131
} else {
132132
png_set_write_fn(png_ptr, (void*)py_fileobj.ptr(),
133-
&write_png_data, &flush_png_data);
133+
&write_png_data, &flush_png_data);
134134
}
135135
png_set_IHDR(png_ptr, info_ptr,
136-
width, height, 8,
137-
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
138-
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
136+
width, height, 8,
137+
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
138+
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
139139

140140
// Save the dpi of the image in the file
141141
if (args.size() == 5) {
@@ -181,7 +181,7 @@ _png_module::read_png(const Py::Tuple& args) {
181181
args.verify_length(1);
182182
std::string fname = Py::String(args[0]);
183183

184-
png_byte header[8]; // 8 is the maximum size that can be checked
184+
png_byte header[8]; // 8 is the maximum size that can be checked
185185

186186
FILE *fp = fopen(fname.c_str(), "rb");
187187
if (!fp)
@@ -272,25 +272,29 @@ _png_module::read_png(const Py::Tuple& args) {
272272

273273
for (png_uint_32 y = 0; y < height; y++) {
274274
png_byte* row = row_pointers[y];
275-
for (png_uint_32 x = 0; x < width; x++) {
276-
size_t offset = y*A->strides[0] + x*A->strides[1];
277-
if (bit_depth == 16) {
278-
png_uint_16* ptr = &reinterpret_cast<png_uint_16*> (row)[x * dimensions[2]];
275+
for (png_uint_32 x = 0; x < width; x++) {
276+
size_t offset = y*A->strides[0] + x*A->strides[1];
277+
if (bit_depth == 16) {
278+
png_uint_16* ptr = &reinterpret_cast<png_uint_16*> (row)[x * dimensions[2]];
279279
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++)
280-
*(float*)(A->data + offset + p*A->strides[2]) = (float)(ptr[p]) / max_value;
281-
} else {
282-
png_byte* ptr = &(row[x * dimensions[2]]);
283-
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++)
284-
{
285-
*(float*)(A->data + offset + p*A->strides[2]) = (float)(ptr[p]) / max_value;
286-
}
287-
}
280+
*(float*)(A->data + offset + p*A->strides[2]) = (float)(ptr[p]) / max_value;
281+
} else {
282+
png_byte* ptr = &(row[x * dimensions[2]]);
283+
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++)
284+
{
285+
*(float*)(A->data + offset + p*A->strides[2]) = (float)(ptr[p]) / max_value;
286+
}
287+
}
288288
}
289289
}
290290

291291
//free the png memory
292292
png_read_end(png_ptr, info_ptr);
293+
#ifndef png_infopp_NULL
294+
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
295+
#else
293296
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
297+
#endif
294298
fclose(fp);
295299
for (row = 0; row < height; row++)
296300
delete [] row_pointers[row];

0 commit comments

Comments
 (0)