| 251 | |
| 252 | |
| 253 | object |
| 254 | ImageInputWrap::read_scanlines (int ybegin, int yend, int z, |
| 255 | int chbegin, int chend, TypeDesc format) |
| 256 | { |
| 257 | // Allocate our own temp buffer and try to read the scanline into it. |
| 258 | // If the read fails, return None. |
| 259 | ASSERT (m_input); |
| 260 | const ImageSpec &spec = m_input->spec(); |
| 261 | chend = clamp (chend, chbegin+1, spec.nchannels); |
| 262 | int nchans = chend - chbegin; |
| 263 | size_t size = (size_t) spec.width * (yend-ybegin) * nchans * format.size(); |
| 264 | char *data = new char[size]; |
| 265 | if (!m_input->read_scanlines (ybegin, yend, z, format, data)) { |
| 266 | delete [] data; // never mind |
| 267 | return object(handle<>(Py_None)); |
| 268 | } |
| 269 | |
| 270 | object array = C_array_to_Python_array (data, format, size); |
| 271 | |
| 272 | // clean up and return the array handle |
| 273 | delete [] data; |
| 274 | return array; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | object |