7 #define OPENIMAGEIO_IMAGEBUF_H
12 # pragma warning(disable : 4251)
330 bool make_writable(
bool keep_cache_type =
false);
334 bool make_writeable(
bool keep_cache_type =
false);
416 bool read(
int subimage = 0,
int miplevel = 0,
bool force =
false,
419 void* progress_callback_data =
nullptr);
438 bool read(
int subimage,
int miplevel,
int chbegin,
int chend,
bool force,
440 void* progress_callback_data =
nullptr);
514 void* progress_callback_data =
nullptr)
const;
516 #ifndef DOXYGEN_SHOULD_SKIP_THIS
518 OIIO_DEPRECATED(
"use other write() that takes the dtype argument (1.9)")
521 void* progress_callback_data =
nullptr)
const
523 return write(filename, TypeUnknown, fileformat, progress_callback,
524 progress_callback_data);
526 #endif // DOXYGEN_SHOULD_SKIP_THIS
599 void* progress_callback_data =
nullptr)
const;
677 float getchannel(
int x,
int y,
int z,
int c,
678 WrapMode wrap = WrapBlack)
const;
696 void getpixel(
int x,
int y,
int z,
float* pixel,
int maxchannels = 1000,
697 WrapMode wrap = WrapBlack)
const;
700 void getpixel(
int x,
int y,
float* pixel,
int maxchannels = 1000)
const
702 getpixel(x, y, 0, pixel, maxchannels);
720 void interppixel(
float x,
float y,
float* pixel,
721 WrapMode wrap = WrapBlack)
const;
729 void interppixel_NDC(
float s,
float t,
float* pixel,
730 WrapMode wrap = WrapBlack)
const;
732 #ifndef DOXYGEN_SHOULD_SKIP_THIS
735 void interppixel_NDC_full(
float s,
float t,
float* pixel,
736 WrapMode wrap = WrapBlack) const;
740 void interppixel_bicubic(
float x,
float y,
float* pixel,
741 WrapMode wrap = WrapBlack)
const;
746 void interppixel_bicubic_NDC(
float s,
float t,
float* pixel,
747 WrapMode wrap = WrapBlack)
const;
755 setpixel(x, y, 0, pixel);
763 setpixel(x, y, z, pixel.
data(),
int(pixel.
size()));
778 void setpixel(
int x,
int y,
const float* pixel,
int maxchannels = 1000)
780 setpixel(x, y, 0, pixel, maxchannels);
786 void setpixel(
int x,
int y,
int z,
const float* pixel,
787 int maxchannels = 1000);
792 void setpixel(
int i,
const float* pixel,
int maxchannels = 1000);
828 bool initialized()
const;
864 bool has_thumbnail()
const;
869 std::shared_ptr<ImageBuf> get_thumbnail()
const;
874 void set_thumbnail(
const ImageBuf& thumb);
878 void clear_thumbnail();
893 int subimage()
const;
898 int nsubimages()
const;
904 int miplevel()
const;
910 int nmiplevels()
const;
914 int nchannels()
const;
943 int orientation()
const;
946 void set_orientation(
int orient);
950 int oriented_width()
const;
951 int oriented_height()
const;
952 int oriented_x()
const;
953 int oriented_y()
const;
954 int oriented_full_width()
const;
955 int oriented_full_height()
const;
956 int oriented_full_x()
const;
957 int oriented_full_y()
const;
963 void set_origin(
int x,
int y,
int z = 0);
972 void set_full(
int xbegin,
int xend,
int ybegin,
int yend,
int zbegin,
979 ROI roi_full()
const;
987 bool contains_roi(
ROI roi)
const;
989 bool pixels_valid(
void)
const;
1003 void* localpixels();
1004 const void* localpixels()
const;
1019 bool contiguous()
const;
1023 bool cachedpixels()
const;
1031 const void* pixeladdr(
int x,
int y,
int z = 0,
int ch = 0)
const;
1032 void* pixeladdr(
int x,
int y,
int z = 0,
int ch = 0);
1036 int pixelindex(
int x,
int y,
int z,
bool check_range =
false)
const;
1049 void threads(
int n)
const;
1052 int threads()
const;
1066 template<
typename... Args>
1075 template<
typename... Args>
1085 template<
typename... Args>
1087 const Args&...
args)
const
1094 template<
typename... Args>
1096 void fmterror(const
char* fmt, const Args&...
args)
const
1124 int deep_samples(
int x,
int y,
int z = 0)
const;
1132 const void* deep_pixel_ptr(
int x,
int y,
int z,
int c,
int s = 0)
const;
1138 float deep_value(
int x,
int y,
int z,
int c,
int s)
const;
1144 uint32_t deep_value_uint(
int x,
int y,
int z,
int c,
int s)
const;
1149 void set_deep_samples(
int x,
int y,
int z,
int nsamples);
1153 void deep_insert_samples(
int x,
int y,
int z,
int samplepos,
int nsamples);
1157 void deep_erase_samples(
int x,
int y,
int z,
int samplepos,
int nsamples);
1162 void set_deep_value(
int x,
int y,
int z,
int c,
int s,
float value);
1167 void set_deep_value(
int x,
int y,
int z,
int c,
int s, uint32_t
value);
1171 bool copy_deep_pixel(
int x,
int y,
int z,
const ImageBuf&
src,
int srcx,
1172 int srcy,
int srcz);
1203 m_rng_xbegin = roi.
xbegin;
1204 m_rng_xend = roi.
xend;
1205 m_rng_ybegin = roi.
ybegin;
1206 m_rng_yend = roi.
yend;
1207 m_rng_zbegin = roi.
zbegin;
1208 m_rng_zend = roi.
zend;
1217 int yend,
int zbegin,
int zend,
WrapMode wrap)
1221 m_rng_xbegin = xbegin;
1223 m_rng_ybegin = ybegin;
1225 m_rng_zbegin = zbegin;
1231 , m_rng_xbegin(i.m_rng_xbegin)
1232 , m_rng_xend(i.m_rng_xend)
1233 , m_rng_ybegin(i.m_rng_ybegin)
1234 , m_rng_yend(i.m_rng_yend)
1235 , m_rng_zbegin(i.m_rng_zbegin)
1236 , m_rng_zend(i.m_rng_zend)
1237 , m_proxydata(i.m_proxydata)
1269 int x()
const {
return m_x; }
1272 int y()
const {
return m_y; }
1275 int z()
const {
return m_z; }
1282 bool valid(
int x_,
int y_,
int z_ = 0)
const
1284 return (x_ >= m_rng_xbegin && x_ < m_rng_xend && y_ >= m_rng_ybegin
1285 && y_ < m_rng_yend && z_ >= m_rng_zbegin
1286 && z_ < m_rng_zend);
1291 bool exists(
int x_,
int y_,
int z_ = 0)
const
1293 return (x_ >= m_img_xbegin && x_ < m_img_xend && y_ >= m_img_ybegin
1294 && y_ < m_img_yend && z_ >= m_img_zbegin
1295 && z_ < m_img_zend);
1309 return (m_valid ==
false && m_x == m_rng_xbegin
1310 && m_y == m_rng_ybegin && m_z == m_rng_zend);
1321 void pos(
int x_,
int y_,
int z_ = 0)
1323 if (x_ == m_x + 1 && x_ < m_rng_xend && y_ == m_y && z_ == m_z
1324 && m_valid && m_exists) {
1333 bool v = valid(x_, y_, z_);
1334 bool e =
exists(x_, y_, z_);
1335 if (m_localpixels) {
1337 m_proxydata = (
char*)m_ib->pixeladdr(x_, y_, z_);
1342 if (m_wrap == WrapBlack) {
1343 m_proxydata = (
char*)m_ib->blackpixel();
1345 if (m_ib->do_wrap(x_, y_, z_, m_wrap))
1346 m_proxydata = (
char*)m_ib->pixeladdr(x_, y_, z_);
1348 m_proxydata = (
char*)m_ib->blackpixel();
1355 m_proxydata = (
char*)m_ib->retile(x_, y_, z_, m_tile,
1356 m_tilexbegin, m_tileybegin,
1357 m_tilezbegin, m_tilexend, e,
1370 if (++m_x < m_rng_xend) {
1381 if (++m_y >= m_rng_yend) {
1383 if (++m_z >= m_rng_zend) {
1398 return ROI(m_rng_xbegin, m_rng_xend, m_rng_ybegin, m_rng_yend,
1399 m_rng_zbegin, m_rng_zend, 0, m_ib->nchannels());
1405 void rerange(
int xbegin,
int xend,
int ybegin,
int yend,
int zbegin,
1406 int zend,
WrapMode wrap = WrapDefault)
1411 m_wrap = (wrap == WrapDefault ? WrapBlack : wrap);
1412 m_rng_xbegin = xbegin;
1414 m_rng_ybegin = ybegin;
1416 m_rng_zbegin = zbegin;
1418 pos(xbegin, ybegin, zbegin);
1423 friend class ImageBufImpl;
1425 bool m_valid =
false, m_exists =
false;
1426 bool m_deep =
false;
1427 bool m_localpixels =
false;
1429 int m_img_xbegin, m_img_xend, m_img_ybegin, m_img_yend, m_img_zbegin,
1432 int m_rng_xbegin, m_rng_xend, m_rng_ybegin, m_rng_yend, m_rng_zbegin,
1435 pvt::ImageCacheTile* m_tile =
nullptr;
1440 char* m_proxydata =
nullptr;
1449 m_localpixels = (m_ib->localpixels() !=
nullptr);
1450 m_img_xbegin = spec.x;
1451 m_img_xend = spec.x + spec.width;
1452 m_img_ybegin = spec.y;
1453 m_img_yend = spec.y + spec.height;
1454 m_img_zbegin = spec.z;
1455 m_img_zend = spec.z + spec.depth;
1456 m_nchannels = spec.nchannels;
1458 m_pixel_stride = m_ib->pixel_stride();
1462 m_wrap = (wrap == WrapDefault ? WrapBlack : wrap);
1469 m_rng_xbegin = m_img_xbegin;
1470 m_rng_xend = m_img_xend;
1471 m_rng_ybegin = m_img_ybegin;
1472 m_rng_yend = m_img_yend;
1473 m_rng_zbegin = m_img_zbegin;
1474 m_rng_zend = m_img_zend;
1484 m_proxydata += m_pixel_stride;
1485 if (m_localpixels) {
1489 if (m_wrap == WrapBlack) {
1490 m_proxydata = (
char*)m_ib->blackpixel();
1492 int x = m_x,
y = m_y,
z = m_z;
1493 if (m_ib->do_wrap(x, y, z, m_wrap))
1494 m_proxydata = (
char*)m_ib->pixeladdr(x, y, z);
1496 m_proxydata = (
char*)m_ib->blackpixel();
1499 }
else if (m_deep) {
1500 m_proxydata =
nullptr;
1503 bool e = m_x < m_img_xend;
1506 m_proxydata = (
char*)m_ib->retile(m_x, m_y, m_z, m_tile,
1509 m_tilezbegin, m_tilexend,
1528 if (!m_localpixels) {
1529 const_cast<ImageBuf*
>(m_ib)->make_writable(
true);
1532 m_proxydata =
nullptr;
1561 template<
typename BUFT,
typename USERT =
float>
1570 pos(m_rng_xbegin, m_rng_ybegin, m_rng_zbegin);
1571 if (m_rng_xbegin == m_rng_xend || m_rng_ybegin == m_rng_yend
1572 || m_rng_zbegin == m_rng_zend)
1589 pos(m_rng_xbegin, m_rng_ybegin, m_rng_zbegin);
1590 if (m_rng_xbegin == m_rng_xend || m_rng_ybegin == m_rng_yend
1591 || m_rng_zbegin == m_rng_zend)
1597 int zbegin = 0,
int zend = 1,
WrapMode wrap = WrapDefault)
1598 :
IteratorBase(ib, xbegin, xend, ybegin, yend, zbegin, zend, wrap)
1601 pos(m_rng_xbegin, m_rng_ybegin, m_rng_zbegin);
1602 if (m_rng_xbegin == m_rng_xend || m_rng_ybegin == m_rng_yend
1603 || m_rng_zbegin == m_rng_zend)
1656 return const_cast<ImageBuf*
>(m_ib)->set_deep_samples(m_x, m_y, m_z,
1663 return convert_type<float, USERT>(
1664 m_ib->deep_value(m_x, m_y, m_z, c, s));
1668 return m_ib->deep_value_uint(m_x, m_y, m_z, c, s);
1675 return const_cast<ImageBuf*
>(m_ib)->set_deep_value(m_x, m_y, m_z, c,
1680 return const_cast<ImageBuf*
>(m_ib)->set_deep_value(m_x, m_y, m_z, c,
1688 template<
typename BUFT,
typename USERT =
float>
1696 pos(m_rng_xbegin, m_rng_ybegin, m_rng_zbegin);
1697 if (m_rng_xbegin == m_rng_xend || m_rng_ybegin == m_rng_yend
1698 || m_rng_zbegin == m_rng_zend)
1714 pos(m_rng_xbegin, m_rng_ybegin, m_rng_zbegin);
1715 if (m_rng_xbegin == m_rng_xend || m_rng_ybegin == m_rng_yend
1716 || m_rng_zbegin == m_rng_zend)
1722 int yend,
int zbegin = 0,
int zend = 1,
1724 :
IteratorBase(ib, xbegin, xend, ybegin, yend, zbegin, zend, wrap)
1726 pos(m_rng_xbegin, m_rng_ybegin, m_rng_zbegin);
1727 if (m_rng_xbegin == m_rng_xend || m_rng_ybegin == m_rng_yend
1728 || m_rng_zbegin == m_rng_zend)
1765 const void*
rawptr()
const {
return m_proxydata; }
1770 return convert_type<float, USERT>(
1771 m_ib->deep_value(m_x, m_y, m_z, c, s));
1775 return m_ib->deep_value_uint(m_x, m_y, m_z, c, s);
1782 static void impl_deleter(ImageBufImpl*);
1783 std::unique_ptr<ImageBufImpl, decltype(&impl_deleter)>
m_impl;
1788 const void* retile(
int x,
int y,
int z, pvt::ImageCacheTile*& tile,
1789 int& tilexbegin,
int& tileybegin,
int& tilezbegin,
1790 int& tilexend,
bool exists,
1791 WrapMode wrap = WrapDefault)
const;
1793 const void* blackpixel()
const;
1799 bool do_wrap(
int&
x,
int&
y,
int&
z,
WrapMode wrap)
const;
GLuint GLsizei const GLchar * message
OIIO_API std::string geterror(bool clear=true)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
OIIO_API bool has_error()
Is there a pending global error message waiting to be retrieved?
uint32_t deep_value_uint(int c, int s) const
IteratorBase(const ImageBuf &ib, WrapMode wrap)
GT_API const UT_StringHolder filename
void swap(ImageBuf &other)
Swap the entire contents with another ImageBuf.
void setpixel(int i, cspan< float > pixel)
ConstIterator(const ImageBuf &ib, const ROI &roi, WrapMode wrap=WrapDefault)
Construct read-only iteration region from ImageBuf and ROI.
void getpixel(int x, int y, float *pixel, int maxchannels=1000) const
OIIO_API void set_roi(ImageSpec &spec, const ROI &newroi)
getFileOption("OpenEXR:storage") storage
void pos(int x_, int y_, int z_=0)
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
std::string format(const Str &fmt, Args &&...args)
GLsizei const GLchar *const * string
OIIO_FORMAT_DEPRECATED void error(const char *fmt, const Args &...args) const
GLdouble GLdouble GLdouble z
Iterator(ImageBuf &ib, const ROI &roi, WrapMode wrap=WrapDefault)
Construct read-write iteration region from ImageBuf and ROI.
USERT operator[](int i) const
void init_ib(WrapMode wrap)
DataArrayProxy< BUFT, USERT > & operator*()
bool valid(int x_, int y_, int z_=0) const
void rerange(int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, WrapMode wrap=WrapDefault)
ROI range() const
Return the iteration range.
void set_deep_value(int c, int s, float value)
std::unique_ptr< ImageBufImpl, decltype(&impl_deleter)> m_impl
const void * rawptr() const
Tto convert(const Tfrom &source)
**But if you need a result
OIIO_API ROI get_roi(const ImageSpec &spec)
Return pixel data window for this ImageSpec as a ROI.
ConstIterator(const ImageBuf &ib, int x_, int y_, int z_=0, WrapMode wrap=WrapDefault)
void setpixel(int x, int y, const float *pixel, int maxchannels=1000)
basic_string_view< char > string_view
GLint GLsizei GLsizei height
void setpixel(int x, int y, cspan< float > pixel)
const IteratorBase & assign_base(const IteratorBase &i)
OIIO_API ROI get_roi_full(const ImageSpec &spec)
Return full/display window for this ImageSpec as a ROI.
bool(* ProgressCallback)(void *opaque_data, float portion_done)
IteratorBase(const ImageBuf &ib, int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, WrapMode wrap)
constexpr bool defined() const noexcept
Is a region defined?
void errorf(const char *fmt, const Args &...args) const
GLint GLint GLsizei GLint GLenum format
bool valid() const
Is the current location within the designated iteration range?
const ConstIterator & operator=(const ConstIterator &i)
constexpr size_type size() const noexcept
OIIO_UTIL_API bool exists(string_view path) noexcept
GLuint const GLchar * name
ConstDataArrayProxy< BUFT, USERT > & operator*() const
IteratorBase(const ImageBuf &ib, const ROI &roi, WrapMode wrap)
Construct valid iteration region from ImageBuf and ROI.
Iterator(ImageBuf &ib, int x, int y, int z=0, WrapMode wrap=WrapDefault)
GA_API const UT_StringHolder orient
void errorfmt(const char *fmt, const Args &...args) const
OIIO_FORCEINLINE void operator++()
void set_deep_value(int c, int s, uint32_t value)
Iterator(ImageBuf &ib, WrapMode wrap=WrapDefault)
ConstIterator(const ImageBuf &ib, WrapMode wrap=WrapDefault)
GLint GLint GLsizei GLsizei GLsizei depth
IteratorBase(const IteratorBase &i)
bool exists(int x_, int y_, int z_=0) const
SIM_API const UT_StringHolder force
const stride_t AutoStride
int deep_samples() const
Retrieve the number of deep data samples at this pixel.
USERT operator[](int i) const
LeafData & operator=(const LeafData &)=delete
ConstIterator(const ImageBuf &ib, int xbegin, int xend, int ybegin, int yend, int zbegin=0, int zend=1, WrapMode wrap=WrapDefault)
Iterator(ImageBuf &ib, int xbegin, int xend, int ybegin, int yend, int zbegin=0, int zend=1, WrapMode wrap=WrapDefault)
USERT deep_value(int c, int s) const
Retrieve the deep data value of sample s of channel c.
**If you just want to fire and args
OIIO_FORCEINLINE void pos_xincr()
USERT deep_value(int c, int s) const
Retrieve the deep data value of sample s of channel c.
#define OIIO_FORMAT_DEPRECATED
uint32_t deep_value_uint(int c, int s) const
bool done() const
Are we finished iterating over the region?
const Iterator & operator=(const Iterator &i)
void set_deep_samples(int n)
#define OIIO_NAMESPACE_END
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
ConstIterator(const ConstIterator &i)
WrapMode wrap() const
Return the wrap mode.
ImageBuf OIIO_API zero(ROI roi, int nthreads=0)
constexpr pointer data() const noexcept
DataProxy< BUFT, USERT > operator[](int i)
OIIO_API void set_roi_full(ImageSpec &spec, const ROI &newroi)
void setpixel(int x, int y, int z, cspan< float > pixel)
#define OIIO_NAMESPACE_BEGIN