#include <stdlib.h>#include <stdio.h>#include "OSGConfig.h"#include "OSGBaseFunctions.h"#include <iostream>#include <vector>#include <OSGLog.h>#include "OSGSGIImageFileType.h"Go to the source code of this file.
Namespaces | |
| namespace | osg |
Classes | |
| struct | ImageRec |
Defines | |
| #define | INT_MAX numeric_limits<int>::max() |
Functions | |
| static void | ConvertShort (unsigned short *array, long length) |
| static void | ConvertLong (unsigned *array, unsigned long length) |
| static bool | ImageOpen (ImageRec &image, std::istream &is) |
| static bool | ImageGetRow (ImageRec &image, unsigned char *buf, int y, int z, int stride) |
Variables | |
| static const UInt32 | zsize2pixelformat [] |
| static const Char8 * | suffixArray [] |
| #define INT_MAX numeric_limits<int>::max() |
Definition at line 60 of file OSGSGIImageFileType.cpp.
| static void ConvertShort | ( | unsigned short * | array, | |
| long | length | |||
| ) | [static] |
Definition at line 114 of file OSGSGIImageFileType.cpp.
Referenced by ImageOpen().
00115 { 00116 unsigned b1, b2; 00117 unsigned char *ptr; 00118 00119 ptr = (unsigned char *)array; 00120 while (length--) 00121 { 00122 b1 = *ptr++; 00123 b2 = *ptr++; 00124 *array++ = (b1 << 8) | (b2); 00125 } 00126 }
| static void ConvertLong | ( | unsigned * | array, | |
| unsigned long | length | |||
| ) | [static] |
Definition at line 129 of file OSGSGIImageFileType.cpp.
Referenced by ImageOpen().
00130 { 00131 unsigned long b1, b2, b3, b4; 00132 unsigned char *ptr; 00133 00134 ptr = (unsigned char *)array; 00135 while (length--) 00136 { 00137 b1 = *ptr++; 00138 b2 = *ptr++; 00139 b3 = *ptr++; 00140 b4 = *ptr++; 00141 *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); 00142 } 00143 }
| static bool ImageOpen | ( | ImageRec & | image, | |
| std::istream & | is | |||
| ) | [static] |
Definition at line 145 of file OSGSGIImageFileType.cpp.
References ConvertLong(), ConvertShort(), ImageRec::imagic, ImageRec::is, osg::osgIsBigEndian(), ImageRec::rowSize, ImageRec::rowStart, ImageRec::tmp, ImageRec::type, ImageRec::xsize, ImageRec::ysize, and ImageRec::zsize.
Referenced by osg::SGIImageFileType::read().
00146 { 00147 image.is = &is; 00148 00149 is.read(reinterpret_cast<char*>(&image), 12); 00150 if (is.gcount() != 12) 00151 return false; 00152 00153 bool swapFlag = !osgIsBigEndian(); 00154 if (swapFlag == true) 00155 ConvertShort(&image.imagic, 6); 00156 00157 if ((image.type & 0xFF00) == 0x0100) 00158 { 00159 is.ignore(512 - 12); 00160 if (is.gcount() != 512 - 12) 00161 return false; 00162 int n = image.ysize * image.zsize; 00163 int len = n * sizeof(unsigned); 00164 image.rowStart.resize(n); 00165 is.read(reinterpret_cast<char*>(&(image.rowStart.front())), len); 00166 if (is.gcount() != len) 00167 return false; 00168 image.rowSize.resize(n); 00169 is.read(reinterpret_cast<char*>(&(image.rowSize.front())), len); 00170 if (is.gcount() != len) 00171 return false; 00172 if (swapFlag == true) 00173 { 00174 ConvertLong(&(image.rowStart.front()), n); 00175 ConvertLong(&(image.rowSize.front()), n); 00176 } 00177 unsigned int maxSize = 0; 00178 for (int i = 0; i < n; ++i) 00179 if (image.rowSize[i] > maxSize) 00180 maxSize = image.rowSize[i]; 00181 image.tmp.resize(maxSize); 00182 } 00183 else 00184 image.tmp.resize(image.xsize); 00185 return true; 00186 }
| static bool ImageGetRow | ( | ImageRec & | image, | |
| unsigned char * | buf, | |||
| int | y, | |||
| int | z, | |||
| int | stride | |||
| ) | [static] |
Definition at line 188 of file OSGSGIImageFileType.cpp.
References ImageRec::is, ImageRec::rowSize, ImageRec::rowStart, ImageRec::tmp, ImageRec::type, ImageRec::xsize, and ImageRec::ysize.
Referenced by osg::SGIImageFileType::read().
00189 { 00190 unsigned char *iPtr = &(image.tmp.front()); 00191 unsigned char *oPtr = buf; 00192 if ((image.type & 0xFF00) == 0x0100) 00193 { 00194 unsigned int row = y + z * image.ysize; 00195 image.is->seekg(image.rowStart[row], std::ios::beg); 00196 long len = image.rowSize[row]; 00197 image.is->read(reinterpret_cast<char*>(iPtr), len); 00198 if (image.is->gcount() != len) 00199 return false; 00200 00201 int npix = image.xsize; 00202 while (len > 0) 00203 { 00204 --len; 00205 unsigned char pixel = *iPtr++; 00206 int count = pixel & 0x7F; 00207 if (count == 0) 00208 break; 00209 if (npix < count) 00210 return false; 00211 npix -= count; 00212 if (pixel & 0x80) 00213 { 00214 if (len < count) 00215 return false; 00216 len -= count; 00217 while (count--) 00218 { 00219 *oPtr = *iPtr++; 00220 oPtr += stride; 00221 } 00222 } 00223 else 00224 { 00225 if (len < 1) 00226 return false; 00227 --len; 00228 pixel = *iPtr++; 00229 while (count--) 00230 { 00231 *oPtr = pixel; 00232 oPtr += stride; 00233 } 00234 } 00235 } 00236 } 00237 else 00238 { 00239 image.is->seekg(512 + (y + z * image.ysize) * image.xsize, std::ios::beg); 00240 image.is->read(reinterpret_cast<char*>(iPtr), image.xsize); 00241 if (image.is->gcount() != image.xsize) 00242 return false; 00243 int count = image.xsize; 00244 while (count--) 00245 { 00246 *oPtr = *iPtr++; 00247 oPtr += stride; 00248 } 00249 } 00250 return true; 00251 }
const UInt32 zsize2pixelformat[] [static] |
Initial value:
{
Image::OSG_L_PF,
Image::OSG_LA_PF,
Image::OSG_RGB_PF,
Image::OSG_RGBA_PF
}
Definition at line 253 of file OSGSGIImageFileType.cpp.
Referenced by osg::SGIImageFileType::read().
const Char8* suffixArray[] [static] |
Initial value:
{
"rgb", "rgba", "sgi", "bw"
}
Definition at line 266 of file OSGSGIImageFileType.cpp.
1.5.5