1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //-------------------------------
41 //-------------------------------
48 #include "OSGConfig.h"
54 #include "OSGImageFileHandler.h"
55 #include "OSGPathHandler.h"
56 #include "OSGFileSystem.h"
57 #include "OSGImageFunctions.h"
59 #include "OSGCHDRImageFileType.h"
61 // Static Class Varible implementations:
62 static const OSG::Char8
*suffixArray
[] =
69 /*! \class HDRImageFileType
71 Image File Type to read/write and store/restore Image objects as
74 All the type specific code is included in the class. Does
75 not depend on external libs.
79 /*****************************
81 *****************************/
83 CHDRImageFileType
CHDRImageFileType::_the("chdr",
84 suffixArray
, sizeof(suffixArray
),
88 /*****************************
90 *****************************/
93 /********************************
95 *******************************/
98 /*******************************
100 *******************************/
102 //-------------------------------------------------------------------------
104 Tries to fill the image object with the data read from
105 the given input stream. Returns true on success.
108 bool CHDRImageFileType::read( Image
*image
,
110 const std::string
&mimetype
)
112 ImageUnrecPtr pTmpImage
= Image::create();
114 bool returnValue
= Inherited::read(pTmpImage
, is
, mimetype
);
116 if(returnValue
== false)
124 returnValue
= convertCrossToCubeMap(pTmpImage
,
132 //-------------------------------------------------------------------------
134 Tries to write the image object to the given output stream.
135 Returns true on success.
138 bool CHDRImageFileType::write(const Image
*image
,
140 const std::string
&mimetype
)
143 if(image
->getDataType() != Image::OSG_FLOAT32_IMAGEDATA
)
145 FWARNING(("HDRImageFileType::write: Image has non float data "
153 int width
= image
->getWidth();
154 int height
= image
->getHeight();
156 os
<< "#?RADIANCE" << std::endl
;
157 os
<< "# Written with OpenSG" << std::endl
;
158 os
<< "FORMAT=32-bit_rle_rgbe" << std::endl
;
159 os
<< "EXPOSURE=" << 1.0f
<< std::endl
<< std::endl
;
160 os
<< "-Y " << height
<< " +X " << width
<< std::endl
;
162 RGBE
*rgbe_scan
= new RGBE
[width
];
164 Real32
*data
= ((Real32
*)(image
->getData()));
167 for(int y
=height
-1;y
>=0;y
--)
170 &data
[y
* width
* 3],
186 //-------------------------------------------------------------------------
188 Tries to restore the image data from the given memblock.
189 Returns the amount of data read.
192 UInt64
CHDRImageFileType::restoreData( Image
*image
,
193 const UChar8
*buffer
,
196 image
->setData(buffer
);
198 return image
->getSize();
201 //-------------------------------------------------------------------------
203 Tries to store the image data to the given memblock.
204 Returns the amount of data written.
207 UInt64
CHDRImageFileType::storeData(const Image
*image
,
209 Int32
OSG_CHECK_ARG(memSize
)) const
211 UInt32 dataSize
= image
->getSize();
213 const UChar8
*src
= image
->getData();
215 if(dataSize
&& src
&& buffer
)
216 memcpy(buffer
, src
, dataSize
);
222 //-------------------------------------------------------------------------
224 Constructor used for the singleton object
227 CHDRImageFileType::CHDRImageFileType(const Char8
*mimeType
,
228 const Char8
*suffixArray
[],
229 UInt16 suffixByteCount
,
238 //-------------------------------------------------------------------------
243 CHDRImageFileType::~CHDRImageFileType(void)