00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00041
00042
00043 #ifndef OPENIMAGEIO_IMAGEIO_H
00044 #define OPENIMAGEIO_IMAGEIO_H
00045
00046 #include <vector>
00047 #include <string>
00048 #include <limits>
00049 #include <cmath>
00050
00051 #include "export.h"
00052 #include "typedesc.h"
00053 #include "paramlist.h"
00054
00055
00056
00057 #ifdef OPENIMAGEIO_NAMESPACE
00058 namespace OPENIMAGEIO_NAMESPACE {
00059 #endif
00060
00063 namespace OpenImageIO {
00064
00065
00066 #define OPENIMAGEIO_VERSION_STRING "0.7.0"
00067 #define OPENIMAGEIO_VERSION_MAJOR 0
00068 #define OPENIMAGEIO_VERSION_MINOR 7
00069 #define OPENIMAGEIO_VERSION_PATCH 0
00070 #define OPENIMAGEIO_VERSION (10000 * OPENIMAGEIO_VERSION_MAJOR + \
00071 100 * OPENIMAGEIO_VERSION_MINOR + \
00072 OPENIMAGEIO_VERSION_PATCH)
00073 #define OPENIMAGEIO_INTRO_STRING "OpenImageIO " OPENIMAGEIO_VERSION_STRING " http://www.openimageio.org"
00074
00075
00088 #define OPENIMAGEIO_PLUGIN_VERSION 10
00089
00092 #define IMAGEIO_VERSION OPENIMAGEIO_PLUGIN_VERSION
00093
00094
00095
00100 typedef ptrdiff_t stride_t;
00101
00102
00106 #if defined(LINUX64)
00107 typedef size_t imagesize_t;
00108 #else
00109 typedef unsigned long long imagesize_t;
00110 #endif
00111
00112
00113
00116 const stride_t AutoStride = std::numeric_limits<stride_t>::min();
00117
00118
00119
00125 typedef bool (*ProgressCallback)(void *opaque_data, float portion_done);
00126
00127
00128
00129 typedef ParamValue ImageIOParameter;
00130 typedef ParamValueList ImageIOParameterList;
00131
00132
00133
00134 class QuantizationSpec {
00135 public:
00136 int quant_black;
00137 int quant_white;
00138 int quant_min;
00139 int quant_max;
00140 float quant_dither;
00141
00144 QuantizationSpec (int _black, int _white, int _min, int _max, float _dither)
00145 : quant_black(_black), quant_white(_white),
00146 quant_min(_min), quant_max(_max), quant_dither(_dither)
00147 { }
00148
00151 QuantizationSpec (TypeDesc _type);
00152
00156 static QuantizationSpec quantize_default;
00157 };
00158
00159
00160
00163 class DLLPUBLIC ImageSpec {
00164 public:
00165 enum Linearity {
00166 UnknownLinearity = 0,
00167 Linear = 1,
00168 GammaCorrected = 2,
00169 sRGB = 3
00170 };
00171
00172 int x, y, z;
00173 int width;
00174 int height;
00175 int depth;
00176 int full_x;
00177 int full_y;
00178 int full_z;
00179 int full_width;
00180 int full_height;
00181 int full_depth;
00182 int tile_width;
00183 int tile_height;
00184 int tile_depth;
00185
00186 TypeDesc format;
00187
00188
00189 int nchannels;
00190 std::vector<std::string> channelnames;
00191
00192 int alpha_channel;
00193 int z_channel;
00194 Linearity linearity;
00195 float gamma;
00196
00197 int quant_black;
00198 int quant_white;
00199 int quant_min;
00200 int quant_max;
00201 float quant_dither;
00202
00212 ImageIOParameterList extra_attribs;
00213
00216 ImageSpec (TypeDesc format = TypeDesc::UNKNOWN);
00217
00220 ImageSpec (int xres, int yres, int nchans, TypeDesc fmt = TypeDesc::UINT8);
00221
00224 void set_format (TypeDesc fmt);
00225
00228 void default_channel_names ();
00229
00232 static TypeDesc format_from_quantize (int quant_black, int quant_white,
00233 int quant_min, int quant_max);
00234
00237 size_t channel_bytes() const { return format.size(); }
00238
00242 size_t pixel_bytes() const;
00243
00247 imagesize_t scanline_bytes() const;
00248
00252 imagesize_t tile_pixels() const;
00253
00257 imagesize_t tile_bytes() const;
00258
00262 imagesize_t image_pixels() const;
00263
00267 imagesize_t image_bytes() const;
00268
00274 bool size_t_safe() const {
00275 const imagesize_t big = std::numeric_limits<size_t>::max();
00276 return image_bytes() < big && scanline_bytes() < big &&
00277 tile_bytes() < big;
00278 }
00279
00283 static void auto_stride (stride_t &xstride, stride_t &ystride, stride_t &zstride,
00284 TypeDesc format,
00285 int nchannels, int width, int height) {
00286 if (xstride == AutoStride)
00287 xstride = nchannels * format.size();
00288 if (ystride == AutoStride)
00289 ystride = xstride * width;
00290 if (zstride == AutoStride)
00291 zstride = ystride * height;
00292 }
00293
00296 static void auto_stride (stride_t &xstride, TypeDesc format, int nchannels) {
00297 if (xstride == AutoStride)
00298 xstride = nchannels * format.size();
00299 }
00300
00303 void attribute (const std::string &name, TypeDesc type, const void *value);
00304
00307 void attribute (const std::string &name, unsigned int value) {
00308 attribute (name, TypeDesc::UINT, &value);
00309 }
00310
00313 void attribute (const std::string &name, int value) {
00314 attribute (name, TypeDesc::INT, &value);
00315 }
00316
00319 void attribute (const std::string &name, float value) {
00320 attribute (name, TypeDesc::FLOAT, &value);
00321 }
00322
00325 void attribute (const std::string &name, const char *value) {
00326 attribute (name, TypeDesc::STRING, &value);
00327 }
00328
00331 void attribute (const std::string &name, const std::string &value) {
00332 attribute (name, value.c_str());
00333 }
00334
00337 ImageIOParameter * find_attribute (const std::string &name,
00338 TypeDesc searchtype=TypeDesc::UNKNOWN,
00339 bool casesensitive=false);
00340 const ImageIOParameter *find_attribute (const std::string &name,
00341 TypeDesc searchtype=TypeDesc::UNKNOWN,
00342 bool casesensitive=false) const;
00343
00347 int get_int_attribute (const std::string &name, int defaultval=0) const;
00348
00352 float get_float_attribute (const std::string &name,
00353 float defaultval=0) const;
00354
00357 std::string get_string_attribute (const std::string &name,
00358 const std::string &defaultval = std::string()) const;
00359
00364 std::string metadata_val (const ImageIOParameter &p,
00365 bool human=false) const;
00366 };
00367
00368
00369
00370
00373 class DLLPUBLIC ImageInput {
00374 public:
00382 static ImageInput *create (const std::string &filename,
00383 const std::string &plugin_searchpath="");
00384
00385 ImageInput () { }
00386 virtual ~ImageInput () { }
00387
00390 virtual const char *format_name (void) const = 0;
00391
00397 virtual bool open (const std::string &name, ImageSpec &newspec) = 0;
00398
00404 virtual bool open (const std::string &name, ImageSpec &newspec,
00405 const ImageSpec &config) { return open(name,newspec); }
00406
00410 const ImageSpec &spec (void) const { return m_spec; }
00411
00414 virtual bool close () = 0;
00415
00419 virtual int current_subimage (void) const { return 0; }
00420
00429 virtual bool seek_subimage (int index, ImageSpec &newspec) {
00430 if (index == current_subimage()) {
00431 newspec = spec();
00432 return true;
00433 }
00434 return false;
00435 }
00436
00450 virtual bool read_scanline (int y, int z, TypeDesc format, void *data,
00451 stride_t xstride=AutoStride);
00452
00455 bool read_scanline (int y, int z, float *data) {
00456 return read_scanline (y, z, TypeDesc::FLOAT, data);
00457 }
00458
00475 virtual bool read_tile (int x, int y, int z, TypeDesc format,
00476 void *data, stride_t xstride=AutoStride,
00477 stride_t ystride=AutoStride, stride_t zstride=AutoStride);
00478
00481 bool read_tile (int x, int y, int z, float *data) {
00482 return read_tile (x, y, z, TypeDesc::FLOAT, data,
00483 AutoStride, AutoStride, AutoStride);
00484 }
00485
00498 virtual bool read_image (TypeDesc format, void *data,
00499 stride_t xstride=AutoStride,
00500 stride_t ystride=AutoStride,
00501 stride_t zstride=AutoStride,
00502 ProgressCallback progress_callback=NULL,
00503 void *progress_callback_data=NULL);
00504
00507 bool read_image (float *data) {
00508 return read_image (TypeDesc::FLOAT, data);
00509 }
00510
00516 virtual bool read_native_scanline (int y, int z, void *data) = 0;
00517
00524 virtual bool read_native_tile (int x, int y, int z, void *data) {
00525 return false;
00526 }
00527
00530 virtual int send_to_input (const char *format, ...);
00531 int send_to_client (const char *format, ...);
00532
00537 std::string geterror () const {
00538 std::string e = m_errmessage;
00539 m_errmessage.clear ();
00540 return e;
00541 }
00544 std::string error_message () const { return geterror (); }
00545
00546 protected:
00549 void error (const char *format, ...) OPENIMAGEIO_PRINTF_ARGS(2,3);
00550
00551 protected:
00552 ImageSpec m_spec;
00553
00554 private:
00555 mutable std::string m_errmessage;
00556 };
00557
00558
00559
00560
00563 class DLLPUBLIC ImageOutput {
00564 public:
00570 static ImageOutput *create (const std::string &filename,
00571 const std::string &plugin_searchpath="");
00572
00573 ImageOutput () { }
00574 virtual ~ImageOutput () { }
00575
00578 virtual const char *format_name (void) const = 0;
00579
00580
00581
00582
00611 virtual bool supports (const std::string &feature) const = 0;
00612
00619 virtual bool open (const std::string &name, const ImageSpec &newspec,
00620 bool append=false) = 0;
00621
00625 const ImageSpec &spec (void) const { return m_spec; }
00626
00630 virtual bool close () = 0;
00631
00642 virtual bool write_scanline (int y, int z, TypeDesc format,
00643 const void *data, stride_t xstride=AutoStride)
00644 { return false; }
00645
00659 virtual bool write_tile (int x, int y, int z, TypeDesc format,
00660 const void *data, stride_t xstride=AutoStride,
00661 stride_t ystride=AutoStride,
00662 stride_t zstride=AutoStride)
00663 { return false; }
00664
00679 virtual bool write_rectangle (int xmin, int xmax, int ymin, int ymax,
00680 int zmin, int zmax, TypeDesc format,
00681 const void *data, stride_t xstride=AutoStride,
00682 stride_t ystride=AutoStride,
00683 stride_t zstride=AutoStride)
00684 { return false; }
00685
00698 virtual bool write_image (TypeDesc format, const void *data,
00699 stride_t xstride=AutoStride,
00700 stride_t ystride=AutoStride,
00701 stride_t zstride=AutoStride,
00702 ProgressCallback progress_callback=NULL,
00703 void *progress_callback_data=NULL);
00704
00723 virtual bool copy_image (ImageInput *in);
00724
00727 virtual int send_to_output (const char *format, ...);
00728 int send_to_client (const char *format, ...);
00729
00734 std::string geterror () const {
00735 std::string e = m_errmessage;
00736 m_errmessage.clear ();
00737 return e;
00738 }
00741 std::string error_message () const { return geterror (); }
00742
00743 protected:
00746 void error (const char *format, ...) OPENIMAGEIO_PRINTF_ARGS(2,3);
00747
00756 const void *to_native_scanline (TypeDesc format,
00757 const void *data, stride_t xstride,
00758 std::vector<unsigned char> &scratch);
00759 const void *to_native_tile (TypeDesc format, const void *data,
00760 stride_t xstride, stride_t ystride,
00761 stride_t zstride,
00762 std::vector<unsigned char> &scratch);
00763 const void *to_native_rectangle (int xmin, int xmax, int ymin, int ymax,
00764 int zmin, int zmax,
00765 TypeDesc format, const void *data,
00766 stride_t xstride, stride_t ystride,
00767 stride_t zstride,
00768 std::vector<unsigned char> &scratch);
00769
00770 protected:
00771 ImageSpec m_spec;
00772
00773 private:
00774 mutable std::string m_errmessage;
00775 };
00776
00777
00778
00779
00780
00784 DLLPUBLIC int openimageio_version ();
00785
00789 DLLPUBLIC std::string geterror ();
00790
00793 inline std::string error_message () { return OpenImageIO::geterror (); }
00794
00797 DLLPUBLIC int quantize (float value, int quant_black, int quant_white,
00798 int quant_min, int quant_max, float quant_dither);
00799
00802 inline float exposure (float value, float gain, float invgamma)
00803 {
00804 if (invgamma != 1 && value >= 0)
00805 return powf (gain * value, invgamma);
00806
00807
00808 return gain * value;
00809 }
00810
00811
00816 DLLPUBLIC bool convert_types (TypeDesc src_type, const void *src,
00817 TypeDesc dst_type, void *to, int n,
00818 float gain=1, float gamma=1);
00819
00829 DLLPUBLIC bool convert_image (int nchannels, int width, int height, int depth,
00830 const void *src, TypeDesc src_type,
00831 stride_t src_xstride, stride_t src_ystride,
00832 stride_t src_zstride,
00833 void *dst, TypeDesc dst_type,
00834 stride_t dst_xstride, stride_t dst_ystride,
00835 stride_t dst_zstride,
00836 float gain=1, float gamma=1);
00837
00846 DLLPUBLIC bool decode_iptc_iim (const void *exif, int length, ImageSpec &spec);
00847
00854 DLLPUBLIC void encode_iptc_iim (const ImageSpec &spec, std::vector<char> &iptc);
00855
00861 DLLPUBLIC bool decode_xmp (const std::string &xml, ImageSpec &spec);
00862
00869 DLLPUBLIC std::string encode_xmp (const ImageSpec &spec, bool minimal=false);
00870
00871
00872 DLLPUBLIC void _ImageIO_force_link ();
00873
00876 typedef ImageSpec ImageIOFormatSpec;
00877
00878
00879 };
00880
00881
00882 #ifdef OPENIMAGEIO_NAMESPACE
00883 };
00884 using namespace OPENIMAGEIO_NAMESPACE;
00885 #endif
00886
00887 #endif // OPENIMAGEIO_IMAGEIO_H