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 //-------------------------------
46 #include "OSGConfig.h"
53 #include "OSGMTDImageFileType.h"
55 static const OSG::Char8
*suffixArray
[] =
57 "mtd","opensg","opensgImage"
62 /*! \class MTDImageFileType
64 Image File Type to read/write and store/restore Image objects as
67 All the type specific code is included in the class. Does
68 not depend on external libs.
72 MTDImageFileType
MTDImageFileType::_the("image/x-mtd",
73 suffixArray
, sizeof(suffixArray
),
75 OSG_WRITE_SUPPORTED
));
77 //-------------------------------------------------------------------------
78 /*! Tries to fill the image object with the data read from
79 the given stream. Returns true on success.
82 bool MTDImageFileType::read( Image
*pImage
,
84 const std::string
&mimetype
)
88 void *headData
= static_cast<void*>(&head
);
89 unsigned dataSize
, headSize
= sizeof(Head
);
91 if(is
.read(static_cast<char *>(headData
), headSize
) &&
93 pImage
->set(Image::PixelFormat(head
.pixelFormat
),
99 float(head
.frameDelay
) / 1000.0,
102 Image::Type(head
.dataType
) : Image::OSG_UINT8_IMAGEDATA
),
105 (dataSize
= pImage
->getSize()) &&
106 is
.read(reinterpret_cast<char *>(pImage
->editData()), dataSize
) )
118 //-------------------------------------------------------------------------
120 Tries to write the image object to the given stream.
121 Returns true on success.
123 bool MTDImageFileType::write(const Image
*pImage
,
125 const std::string
&mimetype
)
127 bool retCode
= false;
131 const void *headData
= static_cast<void *>(&head
);
132 unsigned dataSize
= pImage
->getSize(), headSize
= sizeof(Head
);
134 head
.pixelFormat
= pImage
->getPixelFormat();
135 head
.width
= pImage
->getWidth();
136 head
.height
= pImage
->getHeight();
137 head
.depth
= pImage
->getDepth();
138 head
.mipmapCount
= pImage
->getMipMapCount();
139 head
.frameCount
= pImage
->getFrameCount();
140 head
.frameDelay
= short(pImage
->getFrameDelay() * 1000.0);
141 head
.sideCount
= pImage
->getSideCount();
142 head
.dataType
= pImage
->getDataType();
145 if(os
.write(static_cast<const char *>(headData
), headSize
) &&
147 os
.write(reinterpret_cast<const char *>(pImage
->getData()), dataSize
) )
160 //-------------------------------------------------------------------------
162 Tries to restore the image data from the given memblock.
163 Returns the amount of data read.
165 UInt64
MTDImageFileType::restoreData( Image
*pImage
,
166 const UChar8
*buffer
,
169 pImage
->setData(buffer
);
171 return pImage
->getSize();
174 //-------------------------------------------------------------------------
175 /*! Tries to store the image data to the given memblock.
176 Returns the amount of data written.
179 UInt64
MTDImageFileType::storeData(const Image
*pImage
,
183 unsigned dataSize
= pImage
->getSize();
184 const UChar8
*src
= pImage
->getData();
186 if(dataSize
&& src
&& buffer
)
187 memcpy(buffer
, src
, dataSize
);
193 //-------------------------------------------------------------------------
194 /*! Constructor used for the singleton object
197 MTDImageFileType::MTDImageFileType(const Char8
*mimeType
,
198 const Char8
*suffixArray
[],
199 UInt16 suffixByteCount
,
202 Inherited(mimeType
, suffixArray
, suffixByteCount
, flags
)
206 //-------------------------------------------------------------------------
210 MTDImageFileType::~MTDImageFileType(void)