39 OIIO_NAMESPACE_ENTER {
42 typedef int (*CallbackFunction)(
int argc,
const char*argv[]);
45 typedef shared_ptr<ImageRec> ImageRecRef;
61 std::string full_command_line;
62 std::string printinfo_metamatch;
63 std::string printinfo_nometamatch;
66 TypeDesc output_dataformat;
67 std::map<std::string,std::string> output_channelformats;
68 int output_bitspersample;
70 int output_tilewidth, output_tileheight;
71 std::string output_compression;
73 std::string output_planarconfig;
74 bool output_adjust_time;
79 float diff_warnthresh;
80 float diff_warnpercent;
82 float diff_failthresh;
83 float diff_failpercent;
88 std::vector<ImageRecRef> image_stack;
93 Timer total_writetime;
94 double total_imagecache_readtime;
95 typedef std::map<std::string, double> TimingMap;
96 TimingMap function_times;
97 bool enable_function_timing;
101 void clear_options ();
104 void read (ImageRecRef img);
106 void read () {
if (curimg) read (curimg); }
111 bool postpone_callback (
int required_images, CallbackFunction func,
112 int argc,
const char *argv[]);
115 void process_pending ();
117 CallbackFunction pending_callback ()
const {
return m_pending_callback; }
118 const char *pending_callback_name ()
const {
return m_pending_argv[0]; }
120 void push (
const ImageRecRef &img) {
123 image_stack.push_back (curimg);
128 void push (ImageRec *newir) { push (ImageRecRef(newir)); }
131 ImageRecRef r = curimg;
132 if (image_stack.size()) {
134 curimg = image_stack.back ();
135 image_stack.resize (image_stack.size()-1);
138 curimg = ImageRecRef();
143 ImageRecRef top () {
return curimg; }
145 void error (
const std::string &command,
const std::string &explanation=
"");
148 CallbackFunction m_pending_callback;
150 const char *m_pending_argv[4];
154 typedef shared_ptr<ImageBuf> ImageBufRef;
159 int miplevels()
const {
return (
int) m_miplevels.size(); }
161 return miplevels() ? m_miplevels[0].get() : NULL;
164 return i < miplevels() ? m_miplevels[i].get() : NULL;
166 const ImageBuf * operator[] (
int i)
const {
167 return i < miplevels() ? m_miplevels[i].get() : NULL;
170 return i < miplevels() ? &m_specs[i] : NULL;
173 return i < miplevels() ? &m_specs[i] : NULL;
176 std::vector<ImageBufRef> m_miplevels;
177 std::vector<ImageSpec> m_specs;
178 friend class ImageRec;
185 ImageRec (
const std::string &name,
ImageCache *imagecache)
186 : m_name(name), m_elaborated(false),
187 m_metadata_modified(false), m_pixels_modified(false),
188 m_imagecache(imagecache)
198 ImageRec (
const std::string &name,
int nsubimages = 1,
199 const int *miplevels = NULL,
const ImageSpec *specs=NULL);
207 ImageRec (ImageRec &img,
int subimage_to_copy = -1,
208 int miplevel_to_copy = -1,
bool writable =
true,
209 bool copy_pixels =
true);
214 ImageRec (ImageBufRef img,
bool copy_pixels =
true);
217 ImageRec (
const std::string &name,
const ImageSpec &spec,
220 enum WinMerge { WinMergeUnion, WinMergeIntersection, WinMergeA, WinMergeB };
228 ImageRec (ImageRec &imgA, ImageRec &imgB,
int subimage_to_copy = -1,
229 WinMerge pixwin = WinMergeUnion,
230 WinMerge fullwin = WinMergeUnion,
231 TypeDesc pixeltype = TypeDesc::UNKNOWN);
234 int subimages()
const {
return (
int) m_subimages.size(); }
237 int miplevels (
int subimage=0)
const {
238 if (subimage >= subimages())
240 return m_subimages[subimage].miplevels();
244 SubimageRec& subimage (
int i) {
245 return m_subimages[i];
247 const SubimageRec& subimage (
int i)
const {
248 return m_subimages[i];
252 SubimageRec& operator[] (
int i) {
253 return m_subimages[i];
255 const SubimageRec& operator[] (
int i)
const {
256 return m_subimages[i];
259 std::string name ()
const {
return m_name; }
263 bool elaborated ()
const {
return m_elaborated; }
270 ImageBuf& operator() (
int subimg=0,
int mip=0) {
271 return *m_subimages[subimg][mip];
273 const ImageBuf& operator() (
int subimg=0,
int mip=0)
const {
274 return *m_subimages[subimg][mip];
277 ImageSpec * spec (
int subimg=0,
int mip=0) {
278 return subimg < subimages() ? m_subimages[subimg].spec(mip) : NULL;
280 const ImageSpec * spec (
int subimg=0,
int mip=0)
const {
281 return subimg < subimages() ? m_subimages[subimg].spec(mip) : NULL;
284 bool metadata_modified ()
const {
return m_metadata_modified; }
285 void metadata_modified (
bool mod) { m_metadata_modified = mod; }
286 bool pixels_modified ()
const {
return m_pixels_modified; }
287 void pixels_modified (
bool mod) { m_pixels_modified = mod; }
289 std::time_t time()
const {
return m_time; }
294 void update_spec_from_imagebuf (
int subimg=0,
int mip=0) {
295 *m_subimages[subimg].spec(mip) = m_subimages[subimg][mip]->spec();
302 bool m_metadata_modified;
303 bool m_pixels_modified;
304 std::vector<SubimageRec> m_subimages;
312 struct print_info_options {
319 std::string metamatch;
320 std::string nometamatch;
321 size_t namefieldlength;
323 print_info_options ()
324 : verbose(false), filenameprefix(false), sum(false), subimages(false),
325 compute_sha1(false), compute_stats(false), namefieldlength(20)
335 bool print_info (
const std::string &filename,
336 const print_info_options &opt,
337 long long &totalsize, std::string &error);
346 bool adjust_geometry (
int &w,
int &h,
int &x,
int &y,
const char *geom,
347 bool allow_scaling=
false);
354 bool set_attribute (ImageRecRef img,
const std::string &attribname,
355 TypeDesc type,
const std::string &value);
360 return (a.width == b.width && a.height == b.height &&
361 a.depth == b.depth && a.nchannels == b.nchannels);
369 DiffErrDifferentSize,
374 int do_action_diff (ImageRec &ir0, ImageRec &ir1, Oiiotool &options);
381 template<
class Action,
class Type>
382 bool apply_spec_mod (ImageRec &img, Action act,
const Type &t,
387 img.metadata_modified (
true);
388 for (
int s = 0, send = img.subimages(); s < send; ++s) {
389 for (
int m = 0, mend = img.miplevels(s); m < mend; ++m) {
390 ok &= act (*img.spec(s,m), t);
402 } OIIO_NAMESPACE_EXIT;