------------ PyImageNew ------------ Object creation function, equivalent to the Python __new__() method. The generic handler creates a new instance using the tp_alloc field.
| 1136 | // The generic handler creates a new instance using the tp_alloc field. |
| 1137 | // |
| 1138 | static PyObject * |
| 1139 | PyImageNew(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 1140 | { |
| 1141 | static char *keywords[] = {"file_name", "scale_factor", NULL}; |
| 1142 | auto api = PyUtilApiFunction("|sO!", PyRunTimeErr, "imaging.Image"); |
| 1143 | char* fileNameArg = nullptr; |
| 1144 | PyObject* scaleObj = nullptr; |
| 1145 | |
| 1146 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, api.format, keywords, &fileNameArg, &PyFloat_Type, &scaleObj)) { |
| 1147 | return api.argsError(); |
| 1148 | } |
| 1149 | |
| 1150 | std::cout << "[PyImageNew] PyImageNew " << std::endl; |
| 1151 | auto self = (PyImage*)type->tp_alloc(type, 0); |
| 1152 | if (self != NULL) { |
| 1153 | self->id = 1; |
| 1154 | } |
| 1155 | |
| 1156 | if (fileNameArg != nullptr) { |
| 1157 | std::cout << "[PyImageNew] fileNameArg: " << fileNameArg << std::endl; |
| 1158 | self->image_node = ReadFile(std::string(fileNameArg)); |
| 1159 | self->image_data = dynamic_cast<mitk::Image*>(self->image_node->GetData()); |
| 1160 | } |
| 1161 | |
| 1162 | // Process 'scale' argument. |
| 1163 | if (scaleObj != nullptr) { |
| 1164 | double scale = PyFloat_AsDouble(scaleObj); |
| 1165 | if (PyErr_Occurred()) { |
| 1166 | return nullptr; |
| 1167 | } |
| 1168 | |
| 1169 | if (scale <= 0.0) { |
| 1170 | api.error("The 'scale ' argument must be >= 0.0."); |
| 1171 | return nullptr; |
| 1172 | } |
| 1173 | |
| 1174 | std::cout << "[PyImageNew] Scale image: " << scale << std::endl; |
| 1175 | ScaleImage(self, scale); |
| 1176 | } |
| 1177 | |
| 1178 | return (PyObject*)self; |
| 1179 | } |
| 1180 | |
| 1181 | //---------------- |
| 1182 | // PyImageDealloc |
nothing calls this directly
no test coverage detected