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

kimgio

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

kimgio

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

kimgio

Skip menu "kimgio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kimgio by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |