The read_image method is a bit different from the c++ interface. "function" is a function which takes a float, and the PyProgressCallback function is called automatically.
| 178 | // "function" is a function which takes a float, and the |
| 179 | // PyProgressCallback function is called automatically. |
| 180 | object |
| 181 | ImageInputWrap::read_image (TypeDesc format) |
| 182 | { |
| 183 | // Allocate our own temp buffer and try to read the image into it. |
| 184 | // If the read fails, return None. |
| 185 | const ImageSpec &spec = m_input->spec(); |
| 186 | size_t size = (size_t) spec.image_pixels() * spec.nchannels * format.size(); |
| 187 | char *data = new char[size]; |
| 188 | if (!m_input->read_image(format, data)) { |
| 189 | delete [] data; // never mind |
| 190 | return object(handle<>(Py_None)); |
| 191 | } |
| 192 | |
| 193 | object array = C_array_to_Python_array (data, format, size); |
| 194 | |
| 195 | // clean up and return the array handle |
| 196 | delete [] data; |
| 197 | return array; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | object |