@@ -249,6 +249,8 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
249249 png_uint_32 height = 0 ;
250250 int bit_depth;
251251
252+ // TODO: Remove direct calls to Numpy API here
253+
252254 if (PyBytes_Check (filein) || PyUnicode_Check (filein)) {
253255 if ((py_file = mpl_PyFile_OpenFile (filein, (char *)" rb" )) == NULL ) {
254256 goto exit;
@@ -381,18 +383,15 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
381383 for (png_uint_32 y = 0 ; y < height; y++) {
382384 png_byte *row = row_pointers[y];
383385 for (png_uint_32 x = 0 ; x < width; x++) {
384- size_t offset = y * A->strides [0 ] + x * A->strides [1 ];
385386 if (bit_depth == 16 ) {
386387 png_uint_16 *ptr = &reinterpret_cast <png_uint_16 *>(row)[x * dimensions[2 ]];
387388 for (png_uint_32 p = 0 ; p < (png_uint_32)dimensions[2 ]; p++) {
388- *(float *)(A->data + offset + p *A->strides [2 ]) =
389- (float )(ptr[p]) / max_value;
389+ *(float *)PyArray_GETPTR3 (A, y, x, p) = (float )(ptr[p]) / max_value;
390390 }
391391 } else {
392392 png_byte *ptr = &(row[x * dimensions[2 ]]);
393393 for (png_uint_32 p = 0 ; p < (png_uint_32)dimensions[2 ]; p++) {
394- *(float *)(A->data + offset + p *A->strides [2 ]) =
395- (float )(ptr[p]) / max_value;
394+ *(float *)PyArray_GETPTR3 (A, y, x, p) = (float )(ptr[p]) / max_value;
396395 }
397396 }
398397 }
@@ -414,28 +413,27 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
414413 for (png_uint_32 y = 0 ; y < height; y++) {
415414 png_byte *row = row_pointers[y];
416415 for (png_uint_32 x = 0 ; x < width; x++) {
417- size_t offset = y * A->strides [0 ] + x * A->strides [1 ];
418416 if (bit_depth == 16 ) {
419417 png_uint_16 *ptr = &reinterpret_cast <png_uint_16 *>(row)[x * dimensions[2 ]];
420418
421419 if (bit_depth == 16 ) {
422420 for (png_uint_32 p = 0 ; p < (png_uint_32)dimensions[2 ]; p++) {
423- *(png_uint_16 *)(A-> data + offset + p *A-> strides [ 2 ] ) = ptr[p];
421+ *(png_uint_16 *)PyArray_GETPTR3 (A, y, x, p ) = ptr[p];
424422 }
425423 } else {
426424 for (png_uint_32 p = 0 ; p < (png_uint_32)dimensions[2 ]; p++) {
427- *(png_byte *)(A-> data + offset + p *A-> strides [ 2 ] ) = ptr[p] >> 8 ;
425+ *(png_byte *)PyArray_GETPTR3 (A, y, x, p ) = ptr[p] >> 8 ;
428426 }
429427 }
430428 } else {
431429 png_byte *ptr = &(row[x * dimensions[2 ]]);
432430 if (bit_depth == 16 ) {
433431 for (png_uint_32 p = 0 ; p < (png_uint_32)dimensions[2 ]; p++) {
434- *(png_uint_16 *)(A-> data + offset + p *A-> strides [ 2 ] ) = ptr[p];
432+ *(png_uint_16 *)PyArray_GETPTR3 (A, y, x, p ) = ptr[p];
435433 }
436434 } else {
437435 for (png_uint_32 p = 0 ; p < (png_uint_32)dimensions[2 ]; p++) {
438- *(png_byte *)(A-> data + offset + p *A-> strides [ 2 ] ) = ptr[p];
436+ *(png_byte *)PyArray_GETPTR3 (A, y, x, p ) = ptr[p];
439437 }
440438 }
441439 }
0 commit comments