File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -369,8 +369,6 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
369369 } else {
370370 dimensions[2 ] = 1 ; // Greyscale images
371371 }
372- // For gray, return an x by y array, not an x by y by 1
373- num_dims = (png_get_color_type (png_ptr, info_ptr) & PNG_COLOR_MASK_COLOR) ? 3 : 2 ;
374372
375373 if (float_result) {
376374 double max_value = (1 << bit_depth) - 1 ;
@@ -431,6 +429,16 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
431429 // free the png memory
432430 png_read_end (png_ptr, info_ptr);
433431
432+ // For gray, return an x by y array, not an x by y by 1
433+ num_dims = (png_get_color_type (png_ptr, info_ptr) & PNG_COLOR_MASK_COLOR) ? 3 : 2 ;
434+
435+ if (num_dims == 2 ) {
436+ PyArray_Dims dims = {dimensions, 2 };
437+ PyObject *reshaped = PyArray_Newshape ((PyArrayObject *)result, &dims, NPY_CORDER);
438+ Py_DECREF (result);
439+ result = reshaped;
440+ }
441+
434442exit:
435443 if (png_ptr && info_ptr) {
436444#ifndef png_infopp_NULL
You can’t perform that action at this time.
0 commit comments