Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/3rdparty/openexr/IlmImf/ImfCRgbaFile.cpp
16337 views
1
///////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
4
// Digital Ltd. LLC
5
//
6
// All rights reserved.
7
//
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
10
// met:
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
16
// distribution.
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
//
33
///////////////////////////////////////////////////////////////////////////
34
35
36
//-----------------------------------------------------------------------------
37
//
38
// C interface to C++ classes Imf::RgbaOutputFile and Imf::RgbaInputFile
39
//
40
//-----------------------------------------------------------------------------
41
42
43
#include <ImfCRgbaFile.h>
44
#include <ImfRgbaFile.h>
45
#include <ImfTiledRgbaFile.h>
46
#include <ImfIntAttribute.h>
47
#include <ImfFloatAttribute.h>
48
#include <ImfDoubleAttribute.h>
49
#include <ImfStringAttribute.h>
50
#include <ImfBoxAttribute.h>
51
#include <ImfVecAttribute.h>
52
#include <ImfMatrixAttribute.h>
53
#include <ImfChannelList.h>
54
#include <ImfLut.h>
55
#include "half.h"
56
#include <string.h>
57
58
using Imath::Box2i;
59
using Imath::Box2f;
60
using Imath::V2i;
61
using Imath::V2f;
62
using Imath::V3i;
63
using Imath::V3f;
64
using Imath::M33f;
65
using Imath::M44f;
66
67
68
namespace {
69
70
71
const int MAX_ERR_LENGTH = 1024;
72
char errorMessage[MAX_ERR_LENGTH];
73
74
75
void
76
setErrorMessage (const std::exception &e)
77
{
78
strncpy (errorMessage, e.what(), MAX_ERR_LENGTH - 1);
79
errorMessage[MAX_ERR_LENGTH - 1] = 0;
80
}
81
82
83
inline Imf::Header *
84
header (ImfHeader *hdr)
85
{
86
return (Imf::Header *)(hdr);
87
}
88
89
90
inline const Imf::Header *
91
header (const ImfHeader *hdr)
92
{
93
return (const Imf::Header *)(hdr);
94
}
95
96
97
inline Imf::RgbaOutputFile *
98
outfile (ImfOutputFile *out)
99
{
100
return (Imf::RgbaOutputFile *) out;
101
}
102
103
104
inline const Imf::RgbaOutputFile *
105
outfile (const ImfOutputFile *out)
106
{
107
return (const Imf::RgbaOutputFile *) out;
108
}
109
110
111
inline Imf::TiledRgbaOutputFile *
112
outfile (ImfTiledOutputFile *out)
113
{
114
return (Imf::TiledRgbaOutputFile *) out;
115
}
116
117
118
inline const Imf::TiledRgbaOutputFile *
119
outfile (const ImfTiledOutputFile *out)
120
{
121
return (const Imf::TiledRgbaOutputFile *) out;
122
}
123
124
125
inline Imf::RgbaInputFile *
126
infile (ImfInputFile *in)
127
{
128
return (Imf::RgbaInputFile *) in;
129
}
130
131
132
inline const Imf::RgbaInputFile *
133
infile (const ImfInputFile *in)
134
{
135
return (const Imf::RgbaInputFile *) in;
136
}
137
138
139
inline Imf::TiledRgbaInputFile *
140
infile (ImfTiledInputFile *in)
141
{
142
return (Imf::TiledRgbaInputFile *) in;
143
}
144
145
146
inline const Imf::TiledRgbaInputFile *
147
infile (const ImfTiledInputFile *in)
148
{
149
return (const Imf::TiledRgbaInputFile *) in;
150
}
151
152
153
} // namespace
154
155
156
void
157
ImfFloatToHalf (float f, ImfHalf *h)
158
{
159
*h = half(f).bits();
160
}
161
162
163
void
164
ImfFloatToHalfArray (int n, const float f[/*n*/], ImfHalf h[/*n*/])
165
{
166
for (int i = 0; i < n; ++i)
167
h[i] = half(f[i]).bits();
168
}
169
170
171
float
172
ImfHalfToFloat (ImfHalf h)
173
{
174
return float (*((half *)&h));
175
}
176
177
178
void
179
ImfHalfToFloatArray (int n, const ImfHalf h[/*n*/], float f[/*n*/])
180
{
181
for (int i = 0; i < n; ++i)
182
f[i] = float (*((half *)(h + i)));
183
}
184
185
186
ImfHeader *
187
ImfNewHeader (void)
188
{
189
try
190
{
191
return (ImfHeader *) new Imf::Header;
192
}
193
catch (const std::exception &e)
194
{
195
setErrorMessage (e);
196
return 0;
197
}
198
}
199
200
201
void
202
ImfDeleteHeader (ImfHeader *hdr)
203
{
204
delete header (hdr);
205
}
206
207
208
ImfHeader *
209
ImfCopyHeader (const ImfHeader *hdr)
210
{
211
try
212
{
213
return (ImfHeader *) new Imf::Header (*header (hdr));
214
}
215
catch (const std::exception &e)
216
{
217
setErrorMessage (e);
218
return 0;
219
}
220
}
221
222
223
void
224
ImfHeaderSetDisplayWindow (ImfHeader *hdr,
225
int xMin, int yMin,
226
int xMax, int yMax)
227
{
228
header(hdr)->displayWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));
229
}
230
231
232
void
233
ImfHeaderDisplayWindow (const ImfHeader *hdr,
234
int *xMin, int *yMin,
235
int *xMax, int *yMax)
236
{
237
const Box2i dw = header(hdr)->displayWindow();
238
*xMin = dw.min.x;
239
*yMin = dw.min.y;
240
*xMax = dw.max.x;
241
*yMax = dw.max.y;
242
}
243
244
245
void
246
ImfHeaderSetDataWindow (ImfHeader *hdr,
247
int xMin, int yMin,
248
int xMax, int yMax)
249
{
250
header(hdr)->dataWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));
251
}
252
253
254
void
255
ImfHeaderDataWindow (const ImfHeader *hdr,
256
int *xMin, int *yMin,
257
int *xMax, int *yMax)
258
{
259
const Box2i dw = header(hdr)->dataWindow();
260
*xMin = dw.min.x;
261
*yMin = dw.min.y;
262
*xMax = dw.max.x;
263
*yMax = dw.max.y;
264
}
265
266
267
void
268
ImfHeaderSetPixelAspectRatio (ImfHeader *hdr, float pixelAspectRatio)
269
{
270
header(hdr)->pixelAspectRatio() = pixelAspectRatio;
271
}
272
273
274
float
275
ImfHeaderPixelAspectRatio (const ImfHeader *hdr)
276
{
277
return header(hdr)->pixelAspectRatio();
278
}
279
280
281
void
282
ImfHeaderSetScreenWindowCenter (ImfHeader *hdr, float x, float y)
283
{
284
header(hdr)->screenWindowCenter() = V2f (x, y);
285
}
286
287
288
void
289
ImfHeaderScreenWindowCenter (const ImfHeader *hdr, float *x, float *y)
290
{
291
const V2i &swc = header(hdr)->screenWindowCenter();
292
*x = swc.x;
293
*y = swc.y;
294
}
295
296
297
void
298
ImfHeaderSetScreenWindowWidth (ImfHeader *hdr, float width)
299
{
300
header(hdr)->screenWindowWidth() = width;
301
}
302
303
304
float
305
ImfHeaderScreenWindowWidth (const ImfHeader *hdr)
306
{
307
return header(hdr)->screenWindowWidth();
308
}
309
310
311
void
312
ImfHeaderSetLineOrder (ImfHeader *hdr, int lineOrder)
313
{
314
header(hdr)->lineOrder() = Imf::LineOrder (lineOrder);
315
}
316
317
318
int
319
ImfHeaderLineOrder (const ImfHeader *hdr)
320
{
321
return header(hdr)->lineOrder();
322
}
323
324
325
void
326
ImfHeaderSetCompression (ImfHeader *hdr, int compression)
327
{
328
header(hdr)->compression() = Imf::Compression (compression);
329
}
330
331
332
int
333
ImfHeaderCompression (const ImfHeader *hdr)
334
{
335
return header(hdr)->compression();
336
}
337
338
339
int
340
ImfHeaderSetIntAttribute (ImfHeader *hdr, const char name[], int value)
341
{
342
try
343
{
344
if (header(hdr)->find(name) == header(hdr)->end())
345
{
346
header(hdr)->insert (name, Imf::IntAttribute (value));
347
}
348
else
349
{
350
header(hdr)->typedAttribute<Imf::IntAttribute>(name).value() =
351
value;
352
}
353
354
return 1;
355
}
356
catch (const std::exception &e)
357
{
358
setErrorMessage (e);
359
return 0;
360
}
361
}
362
363
364
int
365
ImfHeaderIntAttribute (const ImfHeader *hdr, const char name[], int *value)
366
{
367
try
368
{
369
*value = header(hdr)->typedAttribute<Imf::IntAttribute>(name).value();
370
return 1;
371
}
372
catch (const std::exception &e)
373
{
374
setErrorMessage (e);
375
return 0;
376
}
377
}
378
379
380
int
381
ImfHeaderSetFloatAttribute (ImfHeader *hdr, const char name[], float value)
382
{
383
try
384
{
385
if (header(hdr)->find(name) == header(hdr)->end())
386
{
387
header(hdr)->insert (name, Imf::FloatAttribute (value));
388
}
389
else
390
{
391
header(hdr)->typedAttribute<Imf::FloatAttribute>(name).value() =
392
value;
393
}
394
395
return 1;
396
}
397
catch (const std::exception &e)
398
{
399
setErrorMessage (e);
400
return 0;
401
}
402
}
403
404
405
int
406
ImfHeaderSetDoubleAttribute (ImfHeader *hdr, const char name[], double value)
407
{
408
try
409
{
410
if (header(hdr)->find(name) == header(hdr)->end())
411
{
412
header(hdr)->insert (name, Imf::DoubleAttribute (value));
413
}
414
else
415
{
416
header(hdr)->typedAttribute<Imf::DoubleAttribute>(name).value() =
417
value;
418
}
419
420
return 1;
421
}
422
catch (const std::exception &e)
423
{
424
setErrorMessage (e);
425
return 0;
426
}
427
}
428
429
430
int
431
ImfHeaderFloatAttribute (const ImfHeader *hdr, const char name[], float *value)
432
{
433
try
434
{
435
*value = header(hdr)->typedAttribute<Imf::FloatAttribute>(name).value();
436
return 1;
437
}
438
catch (const std::exception &e)
439
{
440
setErrorMessage (e);
441
return 0;
442
}
443
}
444
445
446
int
447
ImfHeaderDoubleAttribute (const ImfHeader *hdr,
448
const char name[],
449
double *value)
450
{
451
try
452
{
453
*value = header(hdr)->
454
typedAttribute<Imf::DoubleAttribute>(name).value();
455
456
return 1;
457
}
458
catch (const std::exception &e)
459
{
460
setErrorMessage (e);
461
return 0;
462
}
463
}
464
465
466
int
467
ImfHeaderSetStringAttribute (ImfHeader *hdr,
468
const char name[],
469
const char value[])
470
{
471
try
472
{
473
if (header(hdr)->find(name) == header(hdr)->end())
474
{
475
header(hdr)->insert (name, Imf::StringAttribute (value));
476
}
477
else
478
{
479
header(hdr)->typedAttribute<Imf::StringAttribute>(name).value() =
480
value;
481
}
482
483
return 1;
484
}
485
catch (const std::exception &e)
486
{
487
setErrorMessage (e);
488
return 0;
489
}
490
}
491
492
493
int
494
ImfHeaderStringAttribute (const ImfHeader *hdr,
495
const char name[],
496
const char **value)
497
{
498
try
499
{
500
*value = header(hdr)->
501
typedAttribute<Imf::StringAttribute>(name).value().c_str();
502
503
return 1;
504
}
505
catch (const std::exception &e)
506
{
507
setErrorMessage (e);
508
return 0;
509
}
510
}
511
512
513
int
514
ImfHeaderSetBox2iAttribute (ImfHeader *hdr,
515
const char name[],
516
int xMin, int yMin,
517
int xMax, int yMax)
518
{
519
try
520
{
521
Box2i box (V2i (xMin, yMin), V2i (xMax, yMax));
522
523
if (header(hdr)->find(name) == header(hdr)->end())
524
{
525
header(hdr)->insert (name, Imf::Box2iAttribute (box));
526
}
527
else
528
{
529
header(hdr)->typedAttribute<Imf::Box2iAttribute>(name).value() =
530
box;
531
}
532
533
return 1;
534
}
535
catch (const std::exception &e)
536
{
537
setErrorMessage (e);
538
return 0;
539
}
540
}
541
542
543
int
544
ImfHeaderBox2iAttribute (const ImfHeader *hdr,
545
const char name[],
546
int *xMin, int *yMin,
547
int *xMax, int *yMax)
548
{
549
try
550
{
551
const Box2i &box =
552
header(hdr)->typedAttribute<Imf::Box2iAttribute>(name).value();
553
554
*xMin = box.min.x;
555
*yMin = box.min.y;
556
*xMax = box.max.x;
557
*yMax = box.max.y;
558
559
return 1;
560
}
561
catch (const std::exception &e)
562
{
563
setErrorMessage (e);
564
return 0;
565
}
566
}
567
568
569
int
570
ImfHeaderSetBox2fAttribute (ImfHeader *hdr,
571
const char name[],
572
float xMin, float yMin,
573
float xMax, float yMax)
574
{
575
try
576
{
577
Box2f box (V2f (xMin, yMin), V2f (xMax, yMax));
578
579
if (header(hdr)->find(name) == header(hdr)->end())
580
{
581
header(hdr)->insert (name, Imf::Box2fAttribute (box));
582
}
583
else
584
{
585
header(hdr)->typedAttribute<Imf::Box2fAttribute>(name).value() =
586
box;
587
}
588
589
return 1;
590
}
591
catch (const std::exception &e)
592
{
593
setErrorMessage (e);
594
return 0;
595
}
596
}
597
598
599
int
600
ImfHeaderBox2fAttribute (const ImfHeader *hdr,
601
const char name[],
602
float *xMin, float *yMin,
603
float *xMax, float *yMax)
604
{
605
try
606
{
607
const Box2f &box =
608
header(hdr)->typedAttribute<Imf::Box2fAttribute>(name).value();
609
610
*xMin = box.min.x;
611
*yMin = box.min.y;
612
*xMax = box.max.x;
613
*yMax = box.max.y;
614
615
return 1;
616
}
617
catch (const std::exception &e)
618
{
619
setErrorMessage (e);
620
return 0;
621
}
622
}
623
624
625
int
626
ImfHeaderSetV2iAttribute (ImfHeader *hdr,
627
const char name[],
628
int x, int y)
629
{
630
try
631
{
632
V2i v (x, y);
633
634
if (header(hdr)->find(name) == header(hdr)->end())
635
header(hdr)->insert (name, Imf::V2iAttribute (v));
636
else
637
header(hdr)->typedAttribute<Imf::V2iAttribute>(name).value() = v;
638
639
return 1;
640
}
641
catch (const std::exception &e)
642
{
643
setErrorMessage (e);
644
return 0;
645
}
646
}
647
648
649
int
650
ImfHeaderV2iAttribute (const ImfHeader *hdr,
651
const char name[],
652
int *x, int *y)
653
{
654
try
655
{
656
const V2i &v =
657
header(hdr)->typedAttribute<Imf::V2iAttribute>(name).value();
658
659
*x = v.x;
660
*y = v.y;
661
662
return 1;
663
}
664
catch (const std::exception &e)
665
{
666
setErrorMessage (e);
667
return 0;
668
}
669
}
670
671
672
int
673
ImfHeaderSetV2fAttribute (ImfHeader *hdr,
674
const char name[],
675
float x, float y)
676
{
677
try
678
{
679
V2f v (x, y);
680
681
if (header(hdr)->find(name) == header(hdr)->end())
682
header(hdr)->insert (name, Imf::V2fAttribute (v));
683
else
684
header(hdr)->typedAttribute<Imf::V2fAttribute>(name).value() = v;
685
686
return 1;
687
}
688
catch (const std::exception &e)
689
{
690
setErrorMessage (e);
691
return 0;
692
}
693
}
694
695
696
int
697
ImfHeaderV2fAttribute (const ImfHeader *hdr,
698
const char name[],
699
float *x, float *y)
700
{
701
try
702
{
703
const V2f &v =
704
header(hdr)->typedAttribute<Imf::V2fAttribute>(name).value();
705
706
*x = v.x;
707
*y = v.y;
708
709
return 1;
710
}
711
catch (const std::exception &e)
712
{
713
setErrorMessage (e);
714
return 0;
715
}
716
}
717
718
719
int
720
ImfHeaderSetV3iAttribute (ImfHeader *hdr,
721
const char name[],
722
int x, int y, int z)
723
{
724
try
725
{
726
V3i v (x, y, z);
727
728
if (header(hdr)->find(name) == header(hdr)->end())
729
header(hdr)->insert (name, Imf::V3iAttribute (v));
730
else
731
header(hdr)->typedAttribute<Imf::V3iAttribute>(name).value() = v;
732
733
return 1;
734
}
735
catch (const std::exception &e)
736
{
737
setErrorMessage (e);
738
return 0;
739
}
740
}
741
742
743
int
744
ImfHeaderV3iAttribute (const ImfHeader *hdr,
745
const char name[],
746
int *x, int *y, int *z)
747
{
748
try
749
{
750
const V3i &v =
751
header(hdr)->typedAttribute<Imf::V3iAttribute>(name).value();
752
753
*x = v.x;
754
*y = v.y;
755
*z = v.z;
756
757
return 1;
758
}
759
catch (const std::exception &e)
760
{
761
setErrorMessage (e);
762
return 0;
763
}
764
}
765
766
767
int
768
ImfHeaderSetV3fAttribute (ImfHeader *hdr,
769
const char name[],
770
float x, float y, float z)
771
{
772
try
773
{
774
V3f v (x, y, z);
775
776
if (header(hdr)->find(name) == header(hdr)->end())
777
header(hdr)->insert (name, Imf::V3fAttribute (v));
778
else
779
header(hdr)->typedAttribute<Imf::V3fAttribute>(name).value() = v;
780
781
return 1;
782
}
783
catch (const std::exception &e)
784
{
785
setErrorMessage (e);
786
return 0;
787
}
788
}
789
790
791
int
792
ImfHeaderV3fAttribute (const ImfHeader *hdr,
793
const char name[],
794
float *x, float *y, float *z)
795
{
796
try
797
{
798
const V3f &v =
799
header(hdr)->typedAttribute<Imf::V3fAttribute>(name).value();
800
801
*x = v.x;
802
*y = v.y;
803
*z = v.z;
804
805
return 1;
806
}
807
catch (const std::exception &e)
808
{
809
setErrorMessage (e);
810
return 0;
811
}
812
}
813
814
815
int
816
ImfHeaderSetM33fAttribute (ImfHeader *hdr,
817
const char name[],
818
const float m[3][3])
819
{
820
try
821
{
822
M33f m3 (m);
823
824
if (header(hdr)->find(name) == header(hdr)->end())
825
header(hdr)->insert (name, Imf::M33fAttribute (m3));
826
else
827
header(hdr)->typedAttribute<Imf::M33fAttribute>(name).value() = m3;
828
829
return 1;
830
}
831
catch (const std::exception &e)
832
{
833
setErrorMessage (e);
834
return 0;
835
}
836
}
837
838
839
int
840
ImfHeaderM33fAttribute (const ImfHeader *hdr,
841
const char name[],
842
float m[3][3])
843
{
844
try
845
{
846
const M33f &m3 =
847
header(hdr)->typedAttribute<Imf::M33fAttribute>(name).value();
848
849
m[0][0] = m3[0][0];
850
m[0][1] = m3[0][1];
851
m[0][2] = m3[0][2];
852
853
m[1][0] = m3[1][0];
854
m[1][1] = m3[1][1];
855
m[1][2] = m3[1][2];
856
857
m[2][0] = m3[2][0];
858
m[2][1] = m3[2][1];
859
m[2][2] = m3[2][2];
860
861
return 1;
862
}
863
catch (const std::exception &e)
864
{
865
setErrorMessage (e);
866
return 0;
867
}
868
}
869
870
871
int
872
ImfHeaderSetM44fAttribute (ImfHeader *hdr,
873
const char name[],
874
const float m[4][4])
875
{
876
try
877
{
878
M44f m4 (m);
879
880
if (header(hdr)->find(name) == header(hdr)->end())
881
header(hdr)->insert (name, Imf::M44fAttribute (m4));
882
else
883
header(hdr)->typedAttribute<Imf::M44fAttribute>(name).value() = m4;
884
885
return 1;
886
}
887
catch (const std::exception &e)
888
{
889
setErrorMessage (e);
890
return 0;
891
}
892
}
893
894
895
int
896
ImfHeaderM44fAttribute (const ImfHeader *hdr,
897
const char name[],
898
float m[4][4])
899
{
900
try
901
{
902
const M44f &m4 =
903
header(hdr)->typedAttribute<Imf::M44fAttribute>(name).value();
904
905
m[0][0] = m4[0][0];
906
m[0][1] = m4[0][1];
907
m[0][2] = m4[0][2];
908
m[0][3] = m4[0][3];
909
910
m[1][0] = m4[1][0];
911
m[1][1] = m4[1][1];
912
m[1][2] = m4[1][2];
913
m[1][3] = m4[1][3];
914
915
m[2][0] = m4[2][0];
916
m[2][1] = m4[2][1];
917
m[2][2] = m4[2][2];
918
m[2][3] = m4[2][3];
919
920
m[3][0] = m4[3][0];
921
m[3][1] = m4[3][1];
922
m[3][2] = m4[3][2];
923
m[3][3] = m4[3][3];
924
925
return 1;
926
}
927
catch (const std::exception &e)
928
{
929
setErrorMessage (e);
930
return 0;
931
}
932
}
933
934
935
ImfOutputFile *
936
ImfOpenOutputFile (const char name[], const ImfHeader *hdr, int channels)
937
{
938
try
939
{
940
return (ImfOutputFile *) new Imf::RgbaOutputFile
941
(name, *header(hdr), Imf::RgbaChannels (channels));
942
}
943
catch (const std::exception &e)
944
{
945
setErrorMessage (e);
946
return 0;
947
}
948
}
949
950
951
int
952
ImfCloseOutputFile (ImfOutputFile *out)
953
{
954
try
955
{
956
delete outfile (out);
957
return 1;
958
}
959
catch (const std::exception &e)
960
{
961
setErrorMessage (e);
962
return 0;
963
}
964
}
965
966
967
int
968
ImfOutputSetFrameBuffer (ImfOutputFile *out,
969
const ImfRgba *base,
970
size_t xStride,
971
size_t yStride)
972
{
973
try
974
{
975
outfile(out)->setFrameBuffer ((Imf::Rgba *)base, xStride, yStride);
976
return 1;
977
}
978
catch (const std::exception &e)
979
{
980
setErrorMessage (e);
981
return 0;
982
}
983
}
984
985
986
int
987
ImfOutputWritePixels (ImfOutputFile *out, int numScanLines)
988
{
989
try
990
{
991
outfile(out)->writePixels (numScanLines);
992
return 1;
993
}
994
catch (const std::exception &e)
995
{
996
setErrorMessage (e);
997
return 0;
998
}
999
}
1000
1001
1002
int
1003
ImfOutputCurrentScanLine (const ImfOutputFile *out)
1004
{
1005
return outfile(out)->currentScanLine();
1006
}
1007
1008
1009
const ImfHeader *
1010
ImfOutputHeader (const ImfOutputFile *out)
1011
{
1012
return (const ImfHeader *) &outfile(out)->header();
1013
}
1014
1015
1016
int
1017
ImfOutputChannels (const ImfOutputFile *out)
1018
{
1019
return outfile(out)->channels();
1020
}
1021
1022
1023
ImfTiledOutputFile *
1024
ImfOpenTiledOutputFile (const char name[],
1025
const ImfHeader *hdr,
1026
int channels,
1027
int xSize, int ySize,
1028
int mode, int rmode)
1029
{
1030
try
1031
{
1032
return (ImfTiledOutputFile *) new Imf::TiledRgbaOutputFile
1033
(name, *header(hdr),
1034
Imf::RgbaChannels (channels),
1035
xSize, ySize,
1036
Imf::LevelMode (mode),
1037
Imf::LevelRoundingMode (rmode));
1038
}
1039
catch (const std::exception &e)
1040
{
1041
setErrorMessage (e);
1042
return 0;
1043
}
1044
}
1045
1046
1047
int
1048
ImfCloseTiledOutputFile (ImfTiledOutputFile *out)
1049
{
1050
try
1051
{
1052
delete outfile (out);
1053
return 1;
1054
}
1055
catch (const std::exception &e)
1056
{
1057
setErrorMessage (e);
1058
return 0;
1059
}
1060
}
1061
1062
1063
int
1064
ImfTiledOutputSetFrameBuffer (ImfTiledOutputFile *out,
1065
const ImfRgba *base,
1066
size_t xStride,
1067
size_t yStride)
1068
{
1069
try
1070
{
1071
outfile(out)->setFrameBuffer ((Imf::Rgba *)base, xStride, yStride);
1072
return 1;
1073
}
1074
catch (const std::exception &e)
1075
{
1076
setErrorMessage (e);
1077
return 0;
1078
}
1079
}
1080
1081
1082
int
1083
ImfTiledOutputWriteTile (ImfTiledOutputFile *out,
1084
int dx, int dy,
1085
int lx, int ly)
1086
{
1087
try
1088
{
1089
outfile(out)->writeTile (dx, dy, lx, ly);
1090
return 1;
1091
}
1092
catch (const std::exception &e)
1093
{
1094
setErrorMessage (e);
1095
return 0;
1096
}
1097
}
1098
1099
1100
int
1101
ImfTiledOutputWriteTiles (ImfTiledOutputFile *out,
1102
int dxMin, int dxMax,
1103
int dyMin, int dyMax,
1104
int lx, int ly)
1105
{
1106
try
1107
{
1108
outfile(out)->writeTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);
1109
return 1;
1110
}
1111
catch (const std::exception &e)
1112
{
1113
setErrorMessage (e);
1114
return 0;
1115
}
1116
}
1117
1118
1119
const ImfHeader *
1120
ImfTiledOutputHeader (const ImfTiledOutputFile *out)
1121
{
1122
return (const ImfHeader *) &outfile(out)->header();
1123
}
1124
1125
1126
int
1127
ImfTiledOutputChannels (const ImfTiledOutputFile *out)
1128
{
1129
return outfile(out)->channels();
1130
}
1131
1132
1133
int
1134
ImfTiledOutputTileXSize (const ImfTiledOutputFile *out)
1135
{
1136
return outfile(out)->tileXSize();
1137
}
1138
1139
1140
int
1141
ImfTiledOutputTileYSize (const ImfTiledOutputFile *out)
1142
{
1143
return outfile(out)->tileYSize();
1144
}
1145
1146
1147
int
1148
ImfTiledOutputLevelMode (const ImfTiledOutputFile *out)
1149
{
1150
return outfile(out)->levelMode();
1151
}
1152
1153
1154
int
1155
ImfTiledOutputLevelRoundingMode (const ImfTiledOutputFile *out)
1156
{
1157
return outfile(out)->levelRoundingMode();
1158
}
1159
1160
1161
ImfInputFile *
1162
ImfOpenInputFile (const char name[])
1163
{
1164
try
1165
{
1166
return (ImfInputFile *) new Imf::RgbaInputFile (name);
1167
}
1168
catch (const std::exception &e)
1169
{
1170
setErrorMessage (e);
1171
return 0;
1172
}
1173
}
1174
1175
1176
int
1177
ImfCloseInputFile (ImfInputFile *in)
1178
{
1179
try
1180
{
1181
delete infile (in);
1182
return 1;
1183
}
1184
catch (const std::exception &e)
1185
{
1186
setErrorMessage (e);
1187
return 0;
1188
}
1189
}
1190
1191
1192
int
1193
ImfInputSetFrameBuffer (ImfInputFile *in,
1194
ImfRgba *base,
1195
size_t xStride,
1196
size_t yStride)
1197
{
1198
try
1199
{
1200
infile(in)->setFrameBuffer ((Imf::Rgba *) base, xStride, yStride);
1201
return 1;
1202
}
1203
catch (const std::exception &e)
1204
{
1205
setErrorMessage (e);
1206
return 0;
1207
}
1208
}
1209
1210
1211
int
1212
ImfInputReadPixels (ImfInputFile *in, int scanLine1, int scanLine2)
1213
{
1214
try
1215
{
1216
infile(in)->readPixels (scanLine1, scanLine2);
1217
return 1;
1218
}
1219
catch (const std::exception &e)
1220
{
1221
setErrorMessage (e);
1222
return 0;
1223
}
1224
}
1225
1226
1227
const ImfHeader *
1228
ImfInputHeader (const ImfInputFile *in)
1229
{
1230
return (const ImfHeader *) &infile(in)->header();
1231
}
1232
1233
1234
int
1235
ImfInputChannels (const ImfInputFile *in)
1236
{
1237
return infile(in)->channels();
1238
}
1239
1240
1241
const char *
1242
ImfInputFileName (const ImfInputFile *in)
1243
{
1244
return infile(in)->fileName();
1245
}
1246
1247
1248
ImfTiledInputFile *
1249
ImfOpenTiledInputFile (const char name[])
1250
{
1251
try
1252
{
1253
return (ImfTiledInputFile *) new Imf::TiledRgbaInputFile (name);
1254
}
1255
catch (const std::exception &e)
1256
{
1257
setErrorMessage (e);
1258
return 0;
1259
}
1260
}
1261
1262
1263
int
1264
ImfCloseTiledInputFile (ImfTiledInputFile *in)
1265
{
1266
try
1267
{
1268
delete infile (in);
1269
return 1;
1270
}
1271
catch (const std::exception &e)
1272
{
1273
setErrorMessage (e);
1274
return 0;
1275
}
1276
}
1277
1278
1279
int
1280
ImfTiledInputSetFrameBuffer (ImfTiledInputFile *in,
1281
ImfRgba *base,
1282
size_t xStride,
1283
size_t yStride)
1284
{
1285
try
1286
{
1287
infile(in)->setFrameBuffer ((Imf::Rgba *) base, xStride, yStride);
1288
return 1;
1289
}
1290
catch (const std::exception &e)
1291
{
1292
setErrorMessage (e);
1293
return 0;
1294
}
1295
}
1296
1297
1298
int
1299
ImfTiledInputReadTile (ImfTiledInputFile *in,
1300
int dx, int dy,
1301
int lx, int ly)
1302
{
1303
try
1304
{
1305
infile(in)->readTile (dx, dy, lx, ly);
1306
return 1;
1307
}
1308
catch (const std::exception &e)
1309
{
1310
setErrorMessage (e);
1311
return 0;
1312
}
1313
}
1314
1315
1316
int
1317
ImfTiledInputReadTiles (ImfTiledInputFile *in,
1318
int dxMin, int dxMax,
1319
int dyMin, int dyMax,
1320
int lx, int ly)
1321
{
1322
try
1323
{
1324
infile(in)->readTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);
1325
return 1;
1326
}
1327
catch (const std::exception &e)
1328
{
1329
setErrorMessage (e);
1330
return 0;
1331
}
1332
}
1333
1334
1335
const ImfHeader *
1336
ImfTiledInputHeader (const ImfTiledInputFile *in)
1337
{
1338
return (const ImfHeader *) &infile(in)->header();
1339
}
1340
1341
1342
int
1343
ImfTiledInputChannels (const ImfTiledInputFile *in)
1344
{
1345
return infile(in)->channels();
1346
}
1347
1348
1349
const char *
1350
ImfTiledInputFileName (const ImfTiledInputFile *in)
1351
{
1352
return infile(in)->fileName();
1353
}
1354
1355
1356
int
1357
ImfTiledInputTileXSize (const ImfTiledInputFile *in)
1358
{
1359
return infile(in)->tileXSize();
1360
}
1361
1362
1363
int
1364
ImfTiledInputTileYSize (const ImfTiledInputFile *in)
1365
{
1366
return infile(in)->tileYSize();
1367
}
1368
1369
1370
int
1371
ImfTiledInputLevelMode (const ImfTiledInputFile *in)
1372
{
1373
return infile(in)->levelMode();
1374
}
1375
1376
1377
int
1378
ImfTiledInputLevelRoundingMode (const ImfTiledInputFile *in)
1379
{
1380
return infile(in)->levelRoundingMode();
1381
}
1382
1383
1384
ImfLut *
1385
ImfNewRound12logLut (int channels)
1386
{
1387
try
1388
{
1389
return (ImfLut *) new Imf::RgbaLut
1390
(Imf::round12log, Imf::RgbaChannels (channels));
1391
}
1392
catch (const std::exception &e)
1393
{
1394
setErrorMessage (e);
1395
return 0;
1396
}
1397
}
1398
1399
1400
ImfLut *
1401
ImfNewRoundNBitLut (unsigned int n, int channels)
1402
{
1403
try
1404
{
1405
return (ImfLut *) new Imf::RgbaLut
1406
(Imf::roundNBit (n), Imf::RgbaChannels (channels));
1407
}
1408
catch (const std::exception &e)
1409
{
1410
setErrorMessage (e);
1411
return 0;
1412
}
1413
}
1414
1415
1416
void
1417
ImfDeleteLut (ImfLut *lut)
1418
{
1419
delete (Imf::RgbaLut *) lut;
1420
}
1421
1422
1423
void
1424
ImfApplyLut (ImfLut *lut, ImfRgba *data, int nData, int stride)
1425
{
1426
((Imf::RgbaLut *)lut)->apply ((Imf::Rgba *)data, nData, stride);
1427
}
1428
1429
1430
const char *
1431
ImfErrorMessage ()
1432
{
1433
return errorMessage;
1434
}
1435
1436