18 #define OPENIMAGEIO_IMAGEIO_H
23 # pragma warning(disable : 4251)
75 namespace Filesystem {
113 : xbegin(xbegin), xend(xend), ybegin(ybegin), yend(yend),
149 return (
a.xbegin ==
b.xbegin &&
a.xend ==
b.xend &&
150 a.ybegin ==
b.ybegin &&
a.yend ==
b.yend &&
151 a.zbegin ==
b.zbegin &&
a.zend ==
b.zend &&
152 a.chbegin ==
b.chbegin &&
a.chend ==
b.chend);
156 return (
a.xbegin !=
b.xbegin ||
a.xend !=
b.xend ||
157 a.ybegin !=
b.ybegin ||
a.yend !=
b.yend ||
158 a.zbegin !=
b.zbegin ||
a.zend !=
b.zend ||
159 a.chbegin !=
b.chbegin ||
a.chend !=
b.chend);
163 constexpr
bool contains (
int x,
int y,
int z=0,
int ch=0) const noexcept {
170 return (other.xbegin >=
xbegin && other.xend <=
xend &&
171 other.ybegin >=
ybegin && other.yend <=
yend &&
172 other.zbegin >=
zbegin && other.zend <=
zend &&
189 return (
A.defined() &&
B.defined())
194 : (
A.defined() ?
A :
B);
199 return (
A.defined() &&
B.defined())
204 : (
A.defined() ?
A :
B);
351 void set_format (
TypeDesc fmt) noexcept;
362 void default_channel_names () noexcept;
367 size_t channel_bytes() const noexcept {
return format.size(); }
374 size_t channel_bytes (
int chan,
bool native=
false) const noexcept;
381 size_t pixel_bytes (
bool native=false) const noexcept;
388 size_t pixel_bytes (
int chbegin,
int chend,
bool native=false) const noexcept;
431 bool size_t_safe() const noexcept {
433 return image_bytes() < big && scanline_bytes() < big &&
444 xstride = nchannels * channelsize;
446 ystride = xstride *
width;
448 zstride = ystride *
height;
457 auto_stride (xstride, ystride, zstride,
format.size(),
465 xstride = nchannels *
format.size();
491 const char *
s = str.c_str();
511 bool casesensitive=
false);
521 bool casesensitive=
false);
524 bool casesensitive=
false)
const;
579 bool casesensitive=
false)
const;
586 bool casesensitive =
false)
const;
618 bool casesensitive =
false)
const;
659 SerialVerbose verbose = SerialDetailed)
const;
665 void from_xml (
const char *xml);
670 std::pair<string_view, int>
671 decode_compression_metadata(
string_view defaultcomp =
"",
672 int defaultqual = -1)
const;
678 int zbegin,
int zend) noexcept {
679 return (tile_width &&
680 ((xbegin-
x) % tile_width) == 0 &&
681 ((ybegin-
y) % tile_height) == 0 &&
682 ((zbegin-
z) % tile_depth) == 0 &&
683 (((xend-
x) % tile_width) == 0 || (xend-
x) ==
width) &&
684 (((yend-
y) % tile_height) == 0 || (yend-
y) ==
height) &&
685 (((zend-
z) % tile_depth) == 0 || (zend-
z) ==
depth));
691 return chan >= 0 && chan < (
int)channelformats.
size()
692 ? channelformats[chan] :
format;
698 return chan >= 0 && chan < (
int)channelnames.
size()
707 formats = channelformats;
708 if ((
int)formats.size() < nchannels)
709 formats.resize (nchannels,
format);
723 return ROI (full_x, full_x+full_width, full_y, full_y+full_height,
724 full_z, full_z+full_depth, 0, nchannels);
746 full_width =
r.width();
747 full_height =
r.height();
748 full_depth =
r.depth();
785 return nchannels == 0 &&
format == TypeUnknown;
811 return {
this, name };
815 return {
this, name };
944 ioproxy, plugin_searchpath);
966 virtual const char *format_name (
void)
const = 0;
1071 return open(name,newspec);
1076 return open(name,newspec);
1094 virtual ImageSpec spec (
int subimage,
int miplevel=0);
1104 virtual ImageSpec spec_dimensions (
int subimage,
int miplevel=0);
1132 virtual bool close () = 0;
1160 return subimage == current_subimage() && miplevel == current_miplevel();
1166 bool ok = seek_subimage (subimage, miplevel);
1176 return seek_subimage (subimage, 0 , newspec);
1247 return read_scanline (y, z, TypeFloat, data);
1283 virtual bool read_scanlines (
int subimage,
int miplevel,
1284 int ybegin,
int yend,
int z,
1285 int chbegin,
int chend,
1290 #ifndef OIIO_DOXYGEN
1295 bool read_scanlines (
int ybegin,
int yend,
int z,
1299 bool read_scanlines (
int ybegin,
int yend,
int z,
1300 int chbegin,
int chend,
1389 virtual bool read_tiles (
int subimage,
int miplevel,
int xbegin,
int xend,
1390 int ybegin,
int yend,
int zbegin,
int zend,
1395 #ifndef OIIO_DOXYGEN
1400 bool read_tiles (
int xbegin,
int xend,
int ybegin,
int yend,
1404 bool read_tiles (
int xbegin,
int xend,
int ybegin,
int yend,
1405 int zbegin,
int zend,
int chbegin,
int chend,
1444 virtual bool read_image (
int subimage,
int miplevel,
1445 int chbegin,
int chend,
1451 void *progress_callback_data=NULL);
1453 #ifndef OIIO_DOXYGEN
1463 void *progress_callback_data=NULL);
1464 virtual bool read_image (
int chbegin,
int chend,
1470 void *progress_callback_data=NULL);
1490 virtual bool read_native_deep_scanlines (
int subimage,
int miplevel,
1491 int ybegin,
int yend,
int z,
1492 int chbegin,
int chend,
1515 virtual bool read_native_deep_tiles (
int subimage,
int miplevel,
1516 int xbegin,
int xend,
1517 int ybegin,
int yend,
1518 int zbegin,
int zend,
1519 int chbegin,
int chend,
1531 virtual bool read_native_deep_image (
int subimage,
int miplevel,
1534 #ifndef OIIO_DOXYGEN
1537 int chbegin,
int chend,
DeepData &deepdata) {
1538 return read_native_deep_scanlines (current_subimage(), current_miplevel(),
1540 chbegin, chend, deepdata);
1543 int zbegin,
int zend,
int chbegin,
int chend,
1545 return read_native_deep_tiles (current_subimage(), current_miplevel(),
1546 xbegin, xend, ybegin, yend,
1547 zbegin, zend, chbegin, chend, deepdata);
1550 return read_native_deep_image (current_subimage(), current_miplevel(),
1589 virtual bool read_native_scanline (
int subimage,
int miplevel,
1590 int y,
int z,
void *
data) = 0;
1593 virtual bool read_native_scanlines (
int subimage,
int miplevel,
1594 int ybegin,
int yend,
int z,
1598 virtual bool read_native_scanlines (
int subimage,
int miplevel,
1599 int ybegin,
int yend,
int z,
1600 int chbegin,
int chend,
void *
data);
1606 virtual bool read_native_tile (
int subimage,
int miplevel,
1607 int x,
int y,
int z,
void *
data);
1616 virtual bool read_native_tiles (
int subimage,
int miplevel,
1617 int xbegin,
int xend,
int ybegin,
int yend,
1618 int zbegin,
int zend,
void *
data);
1628 virtual bool read_native_tiles (
int subimage,
int miplevel,
1629 int xbegin,
int xend,
int ybegin,
int yend,
1630 int zbegin,
int zend,
1631 int chbegin,
int chend,
void *
data);
1637 virtual int send_to_input (
const char *
format, ...);
1638 int send_to_client (
const char *
format, ...);
1646 return (ioproxy ==
nullptr);
1672 template<
typename... Args>
1681 template<
typename... Args>
1689 template<
typename... Args>
1697 template<
typename... Args>
1699 void fmterror(const
char* fmt, const Args&...
args)
const {
1714 void threads(
int n);
1718 int threads()
const;
1724 void unlock()
const;
1725 bool try_lock()
const;
1734 void*
operator new (
size_t size);
1735 void operator delete (
void *
ptr);
1750 static void impl_deleter(Impl*);
1751 std::unique_ptr<Impl, decltype(&impl_deleter)> m_impl;
1757 const std::
string& plugin_searchpath);
1811 const std::wstring& plugin_searchpath = {}) {
1817 static unique_ptr create (
const std::string &filename,
1823 static void destroy (ImageOutput *
x);
1828 virtual ~ImageOutput ();
1831 virtual const char *format_name (
void)
const = 0;
1967 enum OpenMode { Create, AppendSubimage, AppendMIPLevel };
1986 OpenMode
mode=Create) = 0;
2021 return open (filename, specs[0]);
2038 virtual bool close () = 0;
2113 virtual bool write_scanlines (
int ybegin,
int yend,
int z,
2178 virtual bool write_tiles (
int xbegin,
int xend,
int ybegin,
int yend,
2210 virtual bool write_rectangle (
int xbegin,
int xend,
int ybegin,
int yend,
2244 void *progress_callback_data=
nullptr);
2255 virtual bool write_deep_scanlines (
int ybegin,
int yend,
int z,
2278 virtual bool write_deep_tiles (
int xbegin,
int xend,
int ybegin,
int yend,
2279 int zbegin,
int zend,
2287 virtual bool write_deep_image (
const DeepData &deepdata);
2330 virtual int send_to_output (
const char *
format, ...);
2331 int send_to_client (
const char *
format, ...);
2339 return (ioproxy ==
nullptr);
2365 template<
typename... Args>
2374 template<
typename... Args>
2382 template<
typename... Args>
2390 template<
typename... Args>
2392 void fmterror(const
char* fmt, const Args&...
args)
const {
2408 void threads(
int n);
2412 int threads()
const;
2416 void*
operator new (
size_t size);
2417 void operator delete (
void *
ptr);
2421 typedef ImageOutput* (*Creator)();
2439 std::vector<unsigned char> &scratch,
2440 unsigned int dither=0,
2441 int yorigin=0,
int zorigin=0);
2445 std::vector<unsigned char> &scratch,
2446 unsigned int dither=0,
2447 int xorigin=0,
int yorigin=0,
int zorigin=0);
2448 const void *to_native_rectangle (
int xbegin,
int xend,
int ybegin,
int yend,
2449 int zbegin,
int zend,
2453 std::vector<unsigned char> &scratch,
2454 unsigned int dither=0,
2455 int xorigin=0,
int yorigin=0,
int zorigin=0);
2463 bool copy_to_image_buffer (
int xbegin,
int xend,
int ybegin,
int yend,
2487 static void impl_deleter(Impl*);
2488 std::unique_ptr<Impl, decltype(&impl_deleter)> m_impl;
2677 return attribute (name, TypeFloat, &val);
2681 const char *
s = val.
c_str();
2682 return attribute (name, TypeString, &s);
2786 return getattribute (name, TypeInt, &val) ? val : defaultval;
2793 return getattribute (name, TypeFloat, &val) ? val : defaultval;
2808 const char **input_extensions,
2810 const char **output_extensions,
2811 const char *lib_version);
2820 inline std::map<std::string, std::vector<std::string>>
2823 std::map<std::string, std::vector<std::string>> map;
2827 if (format_exts.size() != 2)
2880 return convert_image(nchannels, width, height, depth, src, src_type,
2881 src_xstride, src_ystride, src_zstride, dst, dst_type,
2882 dst_xstride, dst_ystride, dst_zstride);
2895 stride_t dst_zstride,
int nthreads=0);
2903 int ,
int ,
int nthreads=0)
2906 src, src_type, src_xstride, src_ystride, src_zstride,
2907 dst, dst_type, dst_xstride, dst_ystride, dst_zstride, nthreads);
2918 float ditheramplitude,
2919 int alpha_channel = -1,
int z_channel = -1,
2920 unsigned int ditherseed = 1,
2921 int chorigin=0,
int xorigin=0,
2922 int yorigin=0,
int zorigin=0);
2930 int chbegin,
int chend,
2933 int alpha_channel = -1,
int z_channel = -1);
2973 template<
typename T1,
typename... Args>
2980 template<
typename T1,
typename... Args>
2988 template<
typename T1,
typename... Args>
2996 template<
typename T1,
typename... Args>
int tile_width
tile width (0 for a non-tiled image)
int nchannels
number of image channels, e.g., 4 for RGBA
static void auto_stride(stride_t &xstride, TypeDesc format, int nchannels) noexcept
32-bit IEEE floating point values, (C/C++ float).
std::unique_ptr< ImageOutput > unique_ptr
unique_ptr to an ImageOutput.
GLuint GLsizei const GLchar * message
OIIO_API bool wrap_periodic_pow2(int &coord, int origin, int width)
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?
void set_roi(const ROI &r) noexcept
string_view channel_name(int chan) const
GT_API const UT_StringHolder filename
bool convert_types(TypeDesc src_type, const void *src, TypeDesc dst_type, void *dst, int n=1)
DEPRECATED(2.1): old name.
virtual bool open(const std::string &filename, int subimages OIIO_MAYBE_UNUSED, const ImageSpec *specs)
OIIO_UTIL_API std::vector< string_view > splitsv(string_view str, string_view sep="", int maxsplit=-1)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
ImageOutput *(* Creator)()
const ImageSpec & spec(void) const
constexpr imagesize_t npixels() const noexcept
Total number of pixels in the region.
bool undefined() const noexcept
std::string format(const Str &fmt, Args &&...args)
GLsizei const GLchar *const * string
constexpr bool contains(int x, int y, int z=0, int ch=0) const noexcept
Test if the coordinate is within the ROI.
friend constexpr bool operator==(const ROI &a, const ROI &b) noexcept
Test equality of two ROIs.
void get_channelformats(std::vector< TypeDesc > &formats) const
ROI roi_full() const noexcept
Return full/display window for this ImageSpec expressed as a ROI.
GLdouble GLdouble GLdouble z
GLboolean GLboolean GLboolean GLboolean a
static unique_ptr create(const std::wstring &filename, Filesystem::IOProxy *ioproxy=nullptr, const std::wstring &plugin_searchpath={})
OIIO_API bool wrap_periodic(int &coord, int origin, int width)
TypeDesc channelformat(int chan) const
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int depth
depth of pixel data, >1 indicates a "volume"
int full_height
height of the full (display) window
std::vector< std::string > channelnames
OIIO_API void declare_imageio_format(const std::string &format_name, ImageInput::Creator input_creator, const char **input_extensions, ImageOutput::Creator output_creator, const char **output_extensions, const char *lib_version)
void copy_dimensions(const ImageSpec &other)
void attribute(string_view name, int value)
Add an int attribute to extra_attribs.
int tile_height
tile height (0 for a non-tiled image)
static constexpr ROI All() noexcept
String-related utilities, all in namespace Strutil.
void attribute(string_view name, string_view value)
Add a string attribute to extra_attribs.
OIIO_FORMAT_DEPRECATED void error(const char *fmt, const Args &...args) const
friend std::ostream & operator<<(std::ostream &out, const ROI &roi)
Stream output of the range.
bool valid_tile_range(int xbegin, int xend, int ybegin, int yend, int zbegin, int zend) noexcept
std::map< std::string, std::vector< std::string > > get_extension_map()
OIIO_API void premult(int nchannels, int width, int height, int depth, int chbegin, int chend, TypeDesc datatype, void *data, stride_t xstride, stride_t ystride, stride_t zstride, int alpha_channel=-1, int z_channel=-1)
OIIO_API void add_dither(int nchannels, int width, int height, int depth, float *data, stride_t xstride, stride_t ystride, stride_t zstride, float ditheramplitude, int alpha_channel=-1, int z_channel=-1, unsigned int ditherseed=1, int chorigin=0, int xorigin=0, int yorigin=0, int zorigin=0)
basic_string_view< char > string_view
constexpr size_type size() const noexcept
OIIO_API bool wrap_black(int &coord, int origin, int width)
static void auto_stride(stride_t &xstride, stride_t &ystride, stride_t &zstride, TypeDesc format, int nchannels, int width, int height) noexcept
void errorfmt(const char *fmt, const Args &...args) const
GLint GLsizei GLsizei height
Wrappers and utilities for multithreading.
constexpr int height() const noexcept
Width.
constexpr ROI roi_intersection(const ROI &A, const ROI &B) noexcept
Intersection of two regions.
bool(* ProgressCallback)(void *opaque_data, float portion_done)
ImageSpec m_spec
format spec of the currently open image
void debugfmt(const char *fmt, const T1 &v1, const Args &...args)
debug output with std::format conventions.
constexpr bool defined() const noexcept
Is a region defined?
virtual bool set_ioproxy(Filesystem::IOProxy *ioproxy)
OIIO_API bool convert_image(int nchannels, int width, int height, int depth, const void *src, TypeDesc src_type, stride_t src_xstride, stride_t src_ystride, stride_t src_zstride, void *dst, TypeDesc dst_type, stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride)
constexpr int depth() const noexcept
void set_roi_full(const ROI &r) noexcept
OIIO_API bool parallel_convert_image(int nchannels, int width, int height, int depth, const void *src, TypeDesc src_type, stride_t src_xstride, stride_t src_ystride, stride_t src_zstride, void *dst, TypeDesc dst_type, stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride, int nthreads=0)
GLint GLint GLsizei GLint GLenum format
constexpr ROI roi_union(const ROI &A, const ROI &B) noexcept
Union of two regions, the smallest region containing both.
constexpr int nchannels() const noexcept
friend constexpr bool operator!=(const ROI &a, const ROI &b) noexcept
Test inequality of two ROIs.
void attribute(string_view name, unsigned int value)
Add an unsigned int attribute to extra_attribs.
int full_width
width of the full (display) window
OIIO_API void _ImageIO_force_link()
OIIO_API bool wrap_mirror(int &coord, int origin, int width)
GLuint const GLchar * name
OIIO_HOSTDEVICE size_t size() const noexcept
int full_y
origin of the full (display) window
void set_format(string_view fmt) noexcept
GLboolean GLboolean GLboolean b
float get_float_attribute(string_view name, float defaultval=0)
GLint GLint GLsizei GLsizei GLsizei depth
ROI roi() const noexcept
Return pixel data window for this ImageSpec expressed as a ROI.
virtual bool set_thumbnail(const ImageBuf &thumb)
ParamValue ImageIOParameter
int full_depth
depth of the full (display) window
OIIO_API void debug(string_view str)
OIIO_API bool wrap_clamp(int &coord, int origin, int width)
std::vector< TypeDesc > channelformats
int x
origin (upper left corner) of pixel data
OIIO_API bool is_imageio_format_name(string_view name)
Is name one of the known format names?
OIIO_API int openimageio_version()
OIIO_API bool getattribute(string_view name, TypeDesc type, void *val)
static void auto_stride(stride_t &xstride, stride_t &ystride, stride_t &zstride, stride_t channelsize, int nchannels, int width, int height) noexcept
constexpr int width() const noexcept
Height.
const stride_t AutoStride
int z
origin (upper left corner) of pixel data
ParamValueList extra_attribs
int full_z
origin of the full (display) window
int width
width of the pixel data window
bool(* wrap_impl)(int &coord, int origin, int width)
OIIO_UTIL_API std::vector< std::string > splits(string_view str, string_view sep="", int maxsplit=-1)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void fmtdebug(const char *fmt, const T1 &v1, const Args &...args)
constexpr bool contains(const ROI &other) const noexcept
Test if another ROI is entirely within our ROI.
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
**If you just want to fire and args
AttrDelegate< ImageSpec > operator[](string_view name)
ParamValueList ImageIOParameterList
#define OIIO_FORMAT_DEPRECATED
constexpr ROI(int xbegin, int xend, int ybegin, int yend, int zbegin=0, int zend=1, int chbegin=0, int chend=10000) noexcept
int height
height of the pixel data window
#define OIIO_NAMESPACE_END
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
const char * c_str() const
void debugf(const char *fmt, const T1 &v1, const Args &...args)
debug output with printf conventions.
AttrDelegate< const ImageSpec > operator[](string_view name) const
string_view get_string_attribute(string_view name, string_view defaultval=string_view())
bool open(const std::wstring &filename, const ImageSpec &newspec, OpenMode mode=Create)
Open an ImageOutput using a UTF-16 encoded wstring filename.
std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring &utf16str) noexcept
OIIO_API bool copy_image(int nchannels, int width, int height, int depth, const void *src, stride_t pixelsize, stride_t src_xstride, stride_t src_ystride, stride_t src_zstride, void *dst, stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride)
int get_int_attribute(string_view name, int defaultval=0)
const std::string & string() const noexcept
Return a C++ std::string representation of a ustring.
OIIO_API bool convert_pixel_values(TypeDesc src_type, const void *src, TypeDesc dst_type, void *dst, int n=1)
virtual int supports(string_view feature OIIO_MAYBE_UNUSED) const
void attribute(string_view name, float value)
Add a float attribute to extra_attribs.
void errorf(const char *fmt, const Args &...args) const
OpenMode
Modes passed to the open() call.
bool open(const std::wstring &filename, int subimages OIIO_MAYBE_UNUSED, const ImageSpec *specs)
Modes passed to the open() call.
int full_x
origin of the full (display) window
int y
origin (upper left corner) of pixel data
#define OIIO_NAMESPACE_BEGIN