1 {
2 Vampyre Imaging Library
3 by Marek Mauder
4 http://imaginglib.sourceforge.net
6 The contents of this file are used with permission, subject to the Mozilla
7 Public License Version 1.1 (the "License"); you may not use this file except
8 in compliance with the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/MPL-1.1.html
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
13 the specific language governing rights and limitations under the License.
15 Alternatively, the contents of this file may be used under the terms of the
16 GNU Lesser General Public License (the "LGPL License"), in which case the
17 provisions of the LGPL License are applicable instead of those above.
18 If you wish to allow use of your version of this file only under the terms
19 of the LGPL License and not to allow others to use your version of this file
20 under the MPL, indicate your decision by deleting the provisions above and
21 replace them with the notice and other provisions required by the LGPL
22 License. If you do not delete the provisions above, a recipient may use
23 your version of this file under either the MPL or the LGPL License.
25 For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
26 }
28 { This unit contains image format loader/saver for Radiance HDR/RGBE images.}
31 {$I ImagingOptions.inc}
33 interface
35 uses
38 type
39 { Radiance is a suite of tools for performing lighting simulation. It's
40 development started in 1985 and it pioneered the concept of
41 high dynamic range imaging. Radiance defined an image format for storing
42 HDR images, now described as RGBE image format. Since it was the first
43 HDR image format, this format is supported by many other software packages.
45 Radiance image file consists of three sections: a header, resolution string,
46 followed by the pixel data. Each pixel is stored as 4 bytes, one byte
47 mantissa for each r, g, b and a shared one byte exponent.
48 The pixel data may be stored uncompressed or using run length encoding.
50 Imaging translates RGBE pixels to original float values and stores them
51 in ifR32G32B32F data format. It can read both compressed and uncompressed
52 files, and saves files as compressed.}
54 protected
62 public
66 implementation
68 uses
71 const
76 type
92 const
99 resourcestring
104 { THdrFileFormat }
107 begin
118 var
123 const
125 var
131 begin
136 repeat
138 Exit;
142 Exit;
145 Continue;
147 Continue;
152 begin
153 // Data format parsing
159 else
160 Exit;
164 begin
171 begin
178 begin
182 Exit;
185 Exit;
200 var
202 begin
204 begin
209 end
210 else
211 begin
219 var
226 begin
234 begin
237 begin
240 begin
244 end
245 else
246 begin
255 begin
263 var
269 begin
283 begin
286 else
290 begin
297 begin
301 // Read header, allocate new image and, then read and convert the pixels
310 // Flip/mirror the image as needed (height < 0 is default top-down)
321 const
325 var
331 begin
335 WriteLine(IO, Handle, AnsiString(Format(SSizeFmt, [ImageToSave.Height, ImageToSave.Width])), LineEnd);
338 procedure EncodeRgbe(const Src: TColor96FPRec; var DestR, DestG, DestB, DestE: Byte); {$IFDEF USE_INLINE}inline;{$ENDIF}
339 var
342 begin
350 begin
355 end
356 else
357 begin
368 const
370 var
373 begin
376 begin
381 begin
385 while (BeginRun + RunCount < Width) and (RunCount < 127) and (Line[BeginRun] = Line[BeginRun + RunCount]) do
389 begin
396 begin
404 begin
414 var
419 begin
421 // Save using RLE, each component is compressed separately
425 begin
428 // Identify line as using "new" RLE scheme (separate components)
436 begin
446 begin
449 // Makes image to save compatible with Jpeg saving capabilities
452 try
453 // Save header
454 SaveHeader;
455 // Save uncompressed pixels
456 SavePixels;
457 finally
465 begin
470 var
473 begin
476 begin
484 initialization
487 {
488 File Notes:
490 -- 0.77.1 ---------------------------------------------------
491 - Added RLE compression to saving.
492 - Added image saving.
493 - Unit created with initial stuff (loading only).
495 }