Skip to content

Commit

Permalink
#28 2/3 implementing GmicImage(numpy.ndarray) eased constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
myselfhimself committed Aug 24, 2020
1 parent bb21e3d commit dd50724
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions gmicpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ PyGmicImage_from_numpy_array(PyObject *cls, PyObject *args, PyObject *kwargs)
PyObject *ndarray_shape_tuple = NULL;
unsigned int _width = 1, _height = 1, _depth = 1, _spectrum = 1;
PyObject *numpy_module = NULL;
PyObject *new_gmic_image = NULL;
PyObject *ndarray_data_bytesObj = NULL;
T *ndarray_data_bytesObj_ptr = NULL;
char const *keywords[] = {"numpy_array", "deinterleave", "_gmicimagetofill", NULL};
Expand Down Expand Up @@ -534,11 +533,14 @@ PyGmicImage_from_numpy_array(PyObject *cls, PyObject *args, PyObject *kwargs)
Py_None, // This empty _data buffer will be regenerated by the
// GmicImage constructor as a zero-filled bytes object
_width, _height, _depth, _spectrum);
} else {
((PyGmicImage*)py_gmicimage_to_fill)->_gmic_image.assign(_width, _height, _depth, _spectrum);
}

ndarray_data_bytesObj =
PyObject_CallMethod(ndarray_as_3d_unsqueezed_view, "tobytes", NULL);
ndarray_data_bytesObj_ptr = (T *)PyBytes_AsString(ndarray_data_bytesObj);
PyObject_Print(py_gmicimage_to_fill, stderr, 0);

// no deinterleaving
if (!PyObject_IsTrue(py_arg_deinterleave)) {
Expand Down Expand Up @@ -580,7 +582,7 @@ PyGmicImage_from_numpy_array(PyObject *cls, PyObject *args, PyObject *kwargs)
Py_DECREF(ndarray_type);
Py_DECREF(numpy_module);

return new_gmic_image;
return py_gmicimage_to_fill;
}

#endif
Expand Down Expand Up @@ -721,10 +723,11 @@ PyGmicImage_init(PyGmicImage *self, PyObject *args, PyObject *kwargs)
}
}

// Importing numpy.ndarray shape and import buffer without any deinterleaving
// Library users should use the GmicImage.from_numpy_array class method to tell about any (de)interleaving
// Importing numpy.ndarray shape and import buffer without any prior deinterleaving pass
// Library users should use the GmicImage.from_numpy_array class method instead to be able to tune (de)interleaving
if (bytesObj_is_ndarray) {
if(!PyGmicImage_from_numpy_array(PyObject_GetAttrString((PyObject*)self, (const char*)"__class__"), Py_BuildValue((const char*)"(O)", bytesObj), NULL)) {
if(!PyGmicImage_from_numpy_array(PyObject_GetAttrString((PyObject*)self, (const char*)"__class__"), Py_BuildValue((const char*)"(NNN)", bytesObj, Py_False, self), NULL)) {
PyErr_Format(GmicException, "delegated from_numpy_array used as co-constructor returned NULL");
return -1;
}
}
Expand Down

0 comments on commit dd50724

Please sign in to comment.