00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <iostream>
00049
00050 #include <OSGLog.h>
00051
00052 #include "OSGMTDImageFileType.h"
00053
00054 OSG_USING_NAMESPACE
00055
00056
00068
00069
00070
00071
00072
00073 static const Char8 *suffixArray[] =
00074 {
00075 "mtd","opensg","opensgImage"
00076 };
00077
00078 MTDImageFileType MTDImageFileType::_the("image/x-mtd",
00079 suffixArray, sizeof(suffixArray),
00080 OSG_READ_SUPPORTED |
00081 OSG_WRITE_SUPPORTED );
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00097 MTDImageFileType& MTDImageFileType::the (void)
00098 {
00099 return _the;
00100 }
00101
00102
00103
00104
00105
00106
00111 bool MTDImageFileType::read (ImagePtr &image, std::istream &in, const std::string &mimetype)
00112 {
00113 bool retCode = false;
00114 Head head;
00115 void *headData = static_cast<void*>(&head);
00116 unsigned dataSize, headSize = sizeof(Head);
00117
00118 if ( in.read(static_cast<char *>(headData),
00119 headSize) && head.netToHost() &&
00120 image->set ( Image::PixelFormat(head.pixelFormat),
00121 head.width, head.height, head.depth, head.mipmapCount,
00122 head.frameCount, float(head.frameDelay) / 1000.0, 0,
00123 ( head.dataType ? Image::Type(head.dataType) :
00124 Image::OSG_UINT8_IMAGEDATA ),
00125 true, head.sideCount) &&
00126 (dataSize = image->getSize()) &&
00127 in.read(reinterpret_cast<char *>(image->editData()), dataSize ))
00128 retCode = true;
00129 else
00130 retCode = false;
00131
00132 return retCode;
00133 }
00134
00135
00140 bool MTDImageFileType::write (const ImagePtr &image, std::ostream &out, const std::string &mimetype)
00141 {
00142 bool retCode = false;
00143
00144 Head head;
00145 const void *headData = static_cast<void*>(&head);
00146 unsigned dataSize = image->getSize(), headSize = sizeof(Head);
00147
00148 head.pixelFormat = image->getPixelFormat();
00149 head.width = image->getWidth();
00150 head.height = image->getHeight();
00151 head.depth = image->getDepth();
00152 head.mipmapCount = image->getMipMapCount();
00153 head.frameCount = image->getFrameCount();
00154 head.frameDelay = short(image->getFrameDelay() * 1000.0);
00155 head.sideCount = image->getSideCount();
00156 head.dataType = image->getDataType();
00157 head.hostToNet();
00158
00159 if ( out.write(static_cast<const char *>(headData), headSize) &&
00160 dataSize && out.write(reinterpret_cast<const char *>(image->getData()), dataSize) )
00161 retCode = true;
00162 else
00163 retCode = false;
00164
00165 return retCode;
00166 }
00167
00168
00169
00174 UInt64 MTDImageFileType::restoreData( ImagePtr &image,
00175 const UChar8 *buffer,
00176 Int32 OSG_CHECK_ARG(memSize) )
00177 {
00178 image->setData(buffer);
00179
00180 return image->getSize();
00181 }
00182
00183
00188 UInt64 MTDImageFileType::storeData(const ImagePtr &image,
00189 UChar8 *buffer,
00190 Int32 OSG_CHECK_ARG(memSize))
00191 {
00192 unsigned dataSize = image->getSize();
00193 const UChar8 *src = image->getData();
00194
00195 if ( dataSize && src && buffer )
00196 memcpy( buffer, src, dataSize);
00197
00198 return dataSize;
00199 }
00200
00201
00202
00206 MTDImageFileType::MTDImageFileType ( const Char8 *mimeType,
00207 const Char8 *suffixArray[],
00208 UInt16 suffixByteCount,
00209 UInt32 flags )
00210 : ImageFileType ( mimeType, suffixArray, suffixByteCount, flags )
00211 {}
00212
00213
00217 MTDImageFileType::~MTDImageFileType (void ) {}