• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kimgio
 

kimgio

  • kimgio
exr.cpp
1
11#include "config.h"
12
13#ifdef HAVE_EXR
14
15#include <ImfRgbaFile.h>
16#include <ImfStandardAttributes.h>
17#include <ImathBox.h>
18#include <ImfInputFile.h>
19#include <ImfBoxAttribute.h>
20#include <ImfChannelListAttribute.h>
21#include <ImfCompressionAttribute.h>
22#include <ImfFloatAttribute.h>
23#include <ImfIntAttribute.h>
24#include <ImfLineOrderAttribute.h>
25#include <ImfStringAttribute.h>
26#include <ImfVecAttribute.h>
27#include <ImfArray.h>
28#include <ImfConvert.h>
29
30#include <iostream>
31
32#include <stdlib.h>
33
34#include <kurl.h>
35#include <tdeprocess.h>
36#include <tdelocale.h>
37#include <kgenericfactory.h>
38#include <kdebug.h>
39
40#include <tqimage.h>
41#include <tqcstring.h>
42#include <tqfile.h>
43#include <tqdatetime.h>
44#include <tqdict.h>
45#include <tqvalidator.h>
46#include <tqcolor.h>
47
48#include "exr.h"
49
50using namespace Imf;
51
52/* this does a conversion from the ILM Half (equal to Nvidia Half)
53 * format into the normal 32 bit pixel format. Process is from the
54 * ILM code.
55 */
56TQRgb RgbaToQrgba(struct Rgba imagePixel)
57{
58 float r,g,b,a;
59
60 // 1) Compensate for fogging by subtracting defog
61 // from the raw pixel values.
62 // Response: We work with defog of 0.0, so this is a no-op
63
64 // 2) Multiply the defogged pixel values by
65 // 2^(exposure + 2.47393).
66 // Response: We work with exposure of 0.0.
67 // (2^2.47393) is 5.55555
68 r = imagePixel.r * 5.55555;
69 g = imagePixel.g * 5.55555;
70 b = imagePixel.b * 5.55555;
71 a = imagePixel.a * 5.55555;
72
73 // 3) Values, which are now 1.0, are called "middle gray".
74 // If defog and exposure are both set to 0.0, then
75 // middle gray corresponds to a raw pixel value of 0.18.
76 // In step 6, middle gray values will be mapped to an
77 // intensity 3.5 f-stops below the display's maximum
78 // intensity.
79 // Response: no apparent content.
80
81 // 4) Apply a knee function. The knee function has two
82 // parameters, kneeLow and kneeHigh. Pixel values
83 // below 2^kneeLow are not changed by the knee
84 // function. Pixel values above kneeLow are lowered
85 // according to a logarithmic curve, such that the
86 // value 2^kneeHigh is mapped to 2^3.5 (in step 6,
87 // this value will be mapped to the the display's
88 // maximum intensity).
89 // Response: kneeLow = 0.0 (2^0.0 => 1); kneeHigh = 5.0 (2^5 =>32)
90 if (r > 1.0)
91 r = 1.0 + Imath::Math<float>::log ((r-1.0) * 0.184874 + 1) / 0.184874;
92 if (g > 1.0)
93 g = 1.0 + Imath::Math<float>::log ((g-1.0) * 0.184874 + 1) / 0.184874;
94 if (b > 1.0)
95 b = 1.0 + Imath::Math<float>::log ((b-1.0) * 0.184874 + 1) / 0.184874;
96 if (a > 1.0)
97 a = 1.0 + Imath::Math<float>::log ((a-1.0) * 0.184874 + 1) / 0.184874;
98//
99// 5) Gamma-correct the pixel values, assuming that the
100// screen's gamma is 0.4545 (or 1/2.2).
101 r = Imath::Math<float>::pow (r, 0.4545);
102 g = Imath::Math<float>::pow (g, 0.4545);
103 b = Imath::Math<float>::pow (b, 0.4545);
104 a = Imath::Math<float>::pow (a, 0.4545);
105
106// 6) Scale the values such that pixels middle gray
107// pixels are mapped to 84.66 (or 3.5 f-stops below
108// the display's maximum intensity).
109//
110// 7) Clamp the values to [0, 255].
111 return tqRgba( char (Imath::clamp ( r * 84.66f, 0.f, 255.f ) ),
112 char (Imath::clamp ( g * 84.66f, 0.f, 255.f ) ),
113 char (Imath::clamp ( b * 84.66f, 0.f, 255.f ) ),
114 char (Imath::clamp ( a * 84.66f, 0.f, 255.f ) ) );
115}
116
117TDE_EXPORT void kimgio_exr_read( TQImageIO *io )
118{
119 try
120 {
121 int width, height;
122
123 // This won't work if io is not TQFile !
124 RgbaInputFile file (TQFile::encodeName(io->fileName()));
125 Imath::Box2i dw = file.dataWindow();
126
127 width = dw.max.x - dw.min.x + 1;
128 height = dw.max.y - dw.min.y + 1;
129
130 Array2D<Rgba> pixels;
131 pixels.resizeErase (height, width);
132
133 file.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
134 file.readPixels (dw.min.y, dw.max.y);
135
136 TQImage image(width, height, 32, 0, TQImage::BigEndian);
137 if( image.isNull())
138 return;
139
140 // somehow copy pixels into image
141 for ( int y=0; y < height; y++ ) {
142 for ( int x=0; x < width; x++ ) {
143 // copy pixels(x,y) into image(x,y)
144 image.setPixel( x, y, RgbaToQrgba( pixels[y][x] ) );
145 }
146 }
147
148 io->setImage( image );
149 io->setStatus( 0 );
150 }
151 catch (const std::exception &exc)
152 {
153 kdDebug(399) << exc.what() << endl;
154 return;
155 }
156}
157
158
159TDE_EXPORT void kimgio_exr_write(TQImageIO *)
160{
161 // TODO: stub
162}
163
164
165#endif

kimgio

Skip menu "kimgio"
  • Main Page
  • File List
  • Related Pages

kimgio

Skip menu "kimgio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kimgio by doxygen 1.9.4
This website is maintained by Timothy Pearson.