Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGSGIImageFileType.cpp File Reference

#include <stdlib.h>
#include <stdio.h>
#include "OSGConfig.h"
#include "OSGBaseFunctions.h"
#include <iostream>
#include <fstream>
#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 rgbatorgba (unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void bwtobw (unsigned char *b, unsigned char *l, int n)
static void latola (unsigned char *b, unsigned char *a, unsigned char *l, int n)
static void rgbtorgb (unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *l, int n)
static void ConvertShort (unsigned short *array, long length)
static void ConvertLong (unsigned *array, unsigned long length)
static ImageRecImageOpen (const char *fileName)
static void ImageClose (ImageRec *image)
static void ImageGetRow (ImageRec *image, unsigned char *buf, int y, int z)

Variables

static const Char8suffixArray []


Define Documentation

#define INT_MAX   numeric_limits<int>::max()
 

Definition at line 60 of file OSGSGIImageFileType.cpp.


Function Documentation

static void rgbatorgba unsigned char *  r,
unsigned char *  g,
unsigned char *  b,
unsigned char *  a,
unsigned char *  l,
int  n
[static]
 

Definition at line 91 of file OSGSGIImageFileType.cpp.

Referenced by osg::SGIImageFileType::read().

00093 {
00094     while(n--) 
00095     {
00096         l[0] = r[0];
00097         l[1] = g[0];
00098         l[2] = b[0];
00099         l[3] = a[0];
00100         l += 4; r++; g++; b++; a++;
00101     }
00102 }

static void bwtobw unsigned char *  b,
unsigned char *  l,
int  n
[static]
 

Definition at line 105 of file OSGSGIImageFileType.cpp.

Referenced by osg::SGIImageFileType::read().

00106 {
00107     memcpy( l, b, n );
00108 }

static void latola unsigned char *  b,
unsigned char *  a,
unsigned char *  l,
int  n
[static]
 

Definition at line 111 of file OSGSGIImageFileType.cpp.

Referenced by osg::SGIImageFileType::read().

00112 {
00113     while(n--) 
00114     {
00115         l[0] = *b;
00116         l[1] = *a;
00117         l += 2; b++; a++;
00118     }
00119 }

static void rgbtorgb unsigned char *  r,
unsigned char *  g,
unsigned char *  b,
unsigned char *  l,
int  n
[static]
 

Definition at line 122 of file OSGSGIImageFileType.cpp.

Referenced by osg::SGIImageFileType::read().

00124 {
00125     while(n--) 
00126     {
00127         l[0] = r[0];
00128         l[1] = g[0];
00129         l[2] = b[0];
00130         l += 3; r++; g++; b++;
00131     }
00132 }

static void ConvertShort unsigned short *  array,
long  length
[static]
 

Definition at line 159 of file OSGSGIImageFileType.cpp.

Referenced by ImageOpen().

00160 {
00161     unsigned b1, b2;
00162     unsigned char *ptr;
00163 
00164     ptr = (unsigned char *)array;
00165     while (length--) 
00166     {
00167         b1 = *ptr++;
00168         b2 = *ptr++;
00169         *array++ = (b1 << 8) | (b2);
00170     }
00171 }

static void ConvertLong unsigned *  array,
unsigned long  length
[static]
 

Definition at line 174 of file OSGSGIImageFileType.cpp.

Referenced by ImageOpen().

00175 {
00176     unsigned long b1, b2, b3, b4;
00177     unsigned char *ptr;
00178 
00179     ptr = (unsigned char *)array;
00180     while (length--) 
00181     {
00182         b1 = *ptr++;
00183         b2 = *ptr++;
00184         b3 = *ptr++;
00185         b4 = *ptr++;
00186         *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4);
00187     }
00188 }

static ImageRec* ImageOpen const char *  fileName  )  [static]
 

Definition at line 190 of file OSGSGIImageFileType.cpp.

References ConvertLong(), ConvertShort(), ImageRec::file, ImageRec::imagic, osg::osgIsBigEndian(), ImageRec::rleEnd, ImageRec::rowSize, ImageRec::rowStart, ImageRec::tmp, ImageRec::tmpB, ImageRec::tmpG, ImageRec::tmpR, ImageRec::type, ImageRec::xsize, ImageRec::ysize, and ImageRec::zsize.

Referenced by osg::SGIImageFileType::read().

00191 {
00192     ImageRec *image   = NULL;
00193     FILE     *pInFile = NULL;
00194 
00195     int swapFlag;
00196     int x;
00197 
00198     swapFlag = !osgIsBigEndian();
00199 
00200     if((pInFile = fopen(fileName, "rb")) == NULL) 
00201     {
00202         perror(fileName);
00203         return image;
00204     }
00205 
00206     image = (ImageRec *)malloc(sizeof(ImageRec));
00207 
00208     if (image == NULL) 
00209     {
00210         fprintf(stderr, "Out of memory!\n");
00211         exit(1);
00212     }
00213 
00214     image->file = pInFile;
00215 
00216     fread(image, 1, 12, image->file);
00217 
00218     if (swapFlag) 
00219     {
00220         ConvertShort(&image->imagic, 6);
00221     }
00222 
00223     image->tmp = (unsigned char *)malloc(image->xsize*256);
00224     image->tmpR = (unsigned char *)malloc(image->xsize*256);
00225     image->tmpG = (unsigned char *)malloc(image->xsize*256);
00226     image->tmpB = (unsigned char *)malloc(image->xsize*256);
00227     if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
00228     image->tmpB == NULL) 
00229     {
00230         fprintf(stderr, "Out of memory!\n");
00231         exit(1);
00232     }
00233 
00234     if ((image->type & 0xFF00) == 0x0100) 
00235     {
00236         x = image->ysize * image->zsize * sizeof(unsigned);
00237         image->rowStart = (unsigned *)malloc(x);
00238         image->rowSize = (int *)malloc(x);
00239         if (image->rowStart == NULL || image->rowSize == NULL) 
00240         {
00241             fprintf(stderr, "Out of memory!\n");
00242             exit(1);
00243         }
00244         image->rleEnd = 512 + (2 * x);
00245         fseek(image->file, 512, SEEK_SET);
00246         fread(image->rowStart, 1, x, image->file);
00247         fread(image->rowSize, 1, x, image->file);
00248         if (swapFlag) 
00249         {
00250             ConvertLong(image->rowStart, x/sizeof(unsigned));
00251             ConvertLong((unsigned *)image->rowSize, x/sizeof(int));
00252         }
00253     }
00254     else
00255     {
00256         image->rowStart = NULL;
00257         image->rowSize  = NULL;
00258     }
00259     return image;
00260 }

static void ImageClose ImageRec image  )  [static]
 

Definition at line 263 of file OSGSGIImageFileType.cpp.

References ImageRec::file, ImageRec::rowSize, ImageRec::rowStart, ImageRec::tmp, ImageRec::tmpB, ImageRec::tmpG, and ImageRec::tmpR.

Referenced by osg::SGIImageFileType::read().

00264 {
00265     fclose(image->file);
00266     free(image->tmp);
00267     free(image->tmpR);
00268     free(image->tmpG);
00269     free(image->tmpB);
00270     if(image->rowStart)
00271         free(image->rowStart);
00272     if(image->rowSize)
00273         free(image->rowSize);
00274     free(image);
00275 }

static void ImageGetRow ImageRec image,
unsigned char *  buf,
int  y,
int  z
[static]
 

Definition at line 278 of file OSGSGIImageFileType.cpp.

References ImageRec::file, ImageRec::rowSize, ImageRec::rowStart, ImageRec::tmp, ImageRec::type, ImageRec::xsize, and ImageRec::ysize.

Referenced by osg::SGIImageFileType::read().

00279 {
00280     unsigned char *iPtr, *oPtr, pixel;
00281     int count;
00282 
00283     if ((image->type & 0xFF00) == 0x0100) 
00284     {
00285         fseek(image->file, (long)image->rowStart[y+z*image->ysize], SEEK_SET);
00286         fread(image->tmp, 1, (unsigned int)image->rowSize[y+z*image->ysize],
00287               image->file);
00288 
00289         iPtr = image->tmp;
00290         oPtr = buf;
00291         for(;;)
00292         {
00293             pixel = *iPtr++;
00294             count = (int)(pixel & 0x7F);
00295             if (!count) 
00296             {
00297                 return;
00298             }
00299             if (pixel & 0x80) 
00300             {
00301                 while (count--) 
00302                 {
00303                     *oPtr++ = *iPtr++;
00304                 }
00305             } 
00306             else 
00307             {
00308                 pixel = *iPtr++;
00309                 while (count--) 
00310                 {
00311                     *oPtr++ = pixel;
00312                 }
00313             }
00314         }
00315     } 
00316     else 
00317     {
00318         fseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize),
00319               SEEK_SET);
00320         fread(buf, 1, image->xsize, image->file);
00321     }
00322 }


Variable Documentation

const Char8* suffixArray[] [static]
 

Initial value:

 
{
    "rgb", "rgba", "sgi", "bw"
}

Definition at line 329 of file OSGSGIImageFileType.cpp.


Generated on Thu Aug 25 04:12:22 2005 for OpenSG by  doxygen 1.4.3