| 887 | |
| 888 | |
| 889 | bool |
| 890 | ImageBuf::write (ImageOutput *out, |
| 891 | ProgressCallback progress_callback, |
| 892 | void *progress_callback_data) const |
| 893 | { |
| 894 | stride_t as = AutoStride; |
| 895 | bool ok = true; |
| 896 | const ImageBufImpl *impl = this->impl(); |
| 897 | impl->validate_pixels (); |
| 898 | const ImageSpec &m_spec (impl->m_spec); |
| 899 | if (impl->m_localpixels) { |
| 900 | // In-core pixel buffer for the whole image |
| 901 | ok = out->write_image (m_spec.format, impl->m_localpixels, as, as, as, |
| 902 | progress_callback, progress_callback_data); |
| 903 | } else if (deep()) { |
| 904 | // Deep image record |
| 905 | ok = out->write_deep_image (impl->m_deepdata); |
| 906 | } else { |
| 907 | // Backed by ImageCache |
| 908 | boost::scoped_array<char> tmp (new char [m_spec.image_bytes()]); |
| 909 | get_pixels (xbegin(), xend(), ybegin(), yend(), zbegin(), zend(), |
| 910 | m_spec.format, &tmp[0]); |
| 911 | ok = out->write_image (m_spec.format, &tmp[0], as, as, as, |
| 912 | progress_callback, progress_callback_data); |
| 913 | // FIXME -- not good for huge images. Instead, we should read |
| 914 | // little bits at a time (scanline or tile blocks). |
| 915 | } |
| 916 | if (! ok) |
| 917 | error ("%s", out->geterror ()); |
| 918 | return ok; |
| 919 | } |
| 920 | |
| 921 | |
| 922 | |