| 332 | |
| 333 | |
| 334 | object |
| 335 | ImageInputWrap::read_tiles (int xbegin, int xend, int ybegin, int yend, |
| 336 | int zbegin, int zend, int chbegin, int chend, |
| 337 | TypeDesc format) |
| 338 | { |
| 339 | // Allocate our own temp buffer and try to read the scanline into it. |
| 340 | // If the read fails, return None. |
| 341 | const ImageSpec &spec = m_input->spec(); |
| 342 | chend = clamp (chend, chbegin+1, spec.nchannels); |
| 343 | int nchans = chend - chbegin; |
| 344 | size_t size = (size_t) ((xend-xbegin) * (yend-ybegin) * |
| 345 | (zend-zbegin) * nchans * format.size()); |
| 346 | char *data = new char[size]; |
| 347 | if (!m_input->read_tiles (xbegin, xend, ybegin, yend, |
| 348 | zbegin, zend, chbegin, chend, format, data)) { |
| 349 | delete [] data; // never mind |
| 350 | return object(handle<>(Py_None)); |
| 351 | } |
| 352 | |
| 353 | object array = C_array_to_Python_array (data, format, size); |
| 354 | |
| 355 | // clean up and return the array handle |
| 356 | delete [] data; |
| 357 | return array; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | object |