Back to index

extremetuxracer  0.5beta
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions
pp::ReaderRGB Class Reference

#include <rgb_reader.h>

Inheritance diagram for pp::ReaderRGB:
Inheritance graph
[legend]
Collaboration diagram for pp::ReaderRGB:
Collaboration graph
[legend]

List of all members.

Classes

struct  ImageInfo

Public Member Functions

 ReaderRGB (const char *fileName)
 ~ReaderRGB ()
bool writeToFile (const char *fileName) const

Static Public Member Functions

static ImagereadFile (const char *fileName)

Public Attributes

unsigned short width
unsigned short height
unsigned char depth
unsigned char * data

Private Member Functions

ReaderRGB::ImageInfoImageOpen (const char *fileName)
void ImageGetRawData (ReaderRGB::ImageInfo *image, unsigned char *data)
void ImageGetRow (ReaderRGB::ImageInfo *image, unsigned char *buf, int y, int z)
void ImageClose (ReaderRGB::ImageInfo *image)

Detailed Description

Definition at line 29 of file rgb_reader.h.


Class Documentation

struct pp::ReaderRGB::ImageInfo

Definition at line 31 of file rgb_reader.h.

Class Members
unsigned long colorMap
unsigned short dim
FILE * file
unsigned short imagic
unsigned long max
unsigned long min
char name
unsigned long rleEnd
unsigned int * rowSize
unsigned int * rowStart
unsigned short sizeX
unsigned short sizeY
unsigned short sizeZ
unsigned char * tmp
unsigned short type
unsigned long wasteBytes

Constructor & Destructor Documentation

pp::ReaderRGB::ReaderRGB ( const char *  fileName)

Definition at line 37 of file rgb_reader.cpp.

{
       ImageInfo *image;
       //IMAGEInfo *final;
       int sx;

       image = ImageOpen(fileName);

       if ( image == NULL ) {
              return;
       }

       width=image->sizeX; 
       height= image->sizeY;
       depth= image->sizeZ;

  /* 
   * Round up so rows are long-word aligned 
   */
  sx = ( (image->sizeX) * (image->sizeZ) + 3) >> 2;

  data 
    = (unsigned char *)malloc( sx * image->sizeY * sizeof(unsigned int));

  if (data == NULL) 
    {
      fprintf(stderr, "Out of memory!\n");
      //winsys_exit(-1);
         return;
    }

  ImageGetRawData(image, data);
  ImageClose(image);
}

Here is the call graph for this function:


Member Function Documentation

void pp::ReaderRGB::ImageClose ( ReaderRGB::ImageInfo image) [private]

Definition at line 228 of file rgb_reader.cpp.

{
  int i;

  fclose(image->file);
  for ( i = 0 ; i <= image->sizeZ ; i++ )
    free(image->tmp[i]);
  free(image);
}

Here is the caller graph for this function:

void pp::ReaderRGB::ImageGetRawData ( ReaderRGB::ImageInfo image,
unsigned char *  data 
) [private]

Definition at line 148 of file rgb_reader.cpp.

{
  int i, j, k;
  int remain = 0;

  switch ( image->sizeZ )
    {
    case 1:
      remain = image->sizeX % 4;
      break;
    case 2:
      remain = image->sizeX % 2;
      break;
    case 3:
      remain = (image->sizeX * 3) & 0x3;
      if (remain)
       remain = 4 - remain;
      break;
    case 4:
      remain = 0;
      break;
    }

  for (i = 0; i < image->sizeY; i++) 
    {
      for ( k = 0; k < image->sizeZ ; k++ )
       ImageGetRow(image, image->tmp[k+1], i, k);
      for (j = 0; j < image->sizeX; j++) 
       for ( k = 1; k <= image->sizeZ ; k++ )
         *data++ = *(image->tmp[k] + j);
      data += remain;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::ReaderRGB::ImageGetRow ( ReaderRGB::ImageInfo image,
unsigned char *  buf,
int  y,
int  z 
) [private]

Definition at line 183 of file rgb_reader.cpp.

{
  unsigned char *iPtr, *oPtr, pixel;
  int count;

  if ((image->type & 0xFF00) == 0x0100)  /* RLE image */
    {
      fseek(image->file, image->rowStart[y+z*image->sizeY], SEEK_SET);
      fread(image->tmp[0], 1, (unsigned int)image->rowSize[y+z*image->sizeY],
           image->file);

      iPtr = image->tmp[0];
      oPtr = buf;
      while (1) 
       {
         pixel = *iPtr++;
         count = (int)(pixel & 0x7F);
         if (!count)
           return;
         if (pixel & 0x80) 
           {
             while (count--) 
              {
                *oPtr++ = *iPtr++;
              }
           } 
         else 
           {
             pixel = *iPtr++;
             while (count--) 
              {
                *oPtr++ = pixel;
              }
           }
       }
    }
  else /* verbatim image */
    {
      fseek(image->file, 512+(y*image->sizeX)+(z*image->sizeX*image->sizeY),
           SEEK_SET);
      fread(buf, 1, image->sizeX, image->file);
    }
}

Here is the caller graph for this function:

ReaderRGB::ImageInfo * pp::ReaderRGB::ImageOpen ( const char *  fileName) [private]

Definition at line 73 of file rgb_reader.cpp.

{
  ImageInfo *image;
  unsigned int *rowStart, *rowSize, ulTmp;
  int x, i;

  image = (ImageInfo *)malloc(sizeof(ImageInfo));
  if (image == NULL) 
    {
      fprintf(stderr, "Out of memory!\n");
      //winsys_exit(-1);
    }
  if ((image->file = fopen(fileName, "rb")) == NULL) 
    {
      free( image );
      return NULL;
    }
  /*
   *   Read the image header
   */
  fread(image, 1, 12, image->file);
  /*
   *   Check byte order
   */
  if (image->imagic == IMAGIC_SWAP) 
    {
      image->type = SWAP_SHORT_BYTES(image->type);
      image->dim = SWAP_SHORT_BYTES(image->dim);
      image->sizeX = SWAP_SHORT_BYTES(image->sizeX);
      image->sizeY = SWAP_SHORT_BYTES(image->sizeY);
      image->sizeZ = SWAP_SHORT_BYTES(image->sizeZ);
    }

  for ( i = 0 ; i <= image->sizeZ ; i++ )
    {
      image->tmp[i] = (unsigned char *)malloc(image->sizeX*256);
      if (image->tmp[i] == NULL ) 
       {
         fprintf(stderr, "Out of memory!\n");
         //winsys_exit(-1);
       }
    }

  if ((image->type & 0xFF00) == 0x0100) /* RLE image */
    {
      x = image->sizeY * image->sizeZ * sizeof(int);
      image->rowStart = (unsigned int *)malloc(x);
      image->rowSize = (unsigned int *)malloc(x);
      if (image->rowStart == NULL || image->rowSize == NULL) 
       {
         fprintf(stderr, "Out of memory!\n");
         //winsys_exit(-1);
       }
      image->rleEnd = 512 + (2 * x);
      fseek(image->file, 512, SEEK_SET);
      fread(image->rowStart, 1, x, image->file);
      fread(image->rowSize, 1, x, image->file);
      if (image->imagic == IMAGIC_SWAP) 
       {
         x /= sizeof(int);
         rowStart = image->rowStart;
         rowSize = image->rowSize;
         while (x--) 
           {
             ulTmp = *rowStart;
             *rowStart++ = SWAP_LONG_BYTES(ulTmp);
             ulTmp = *rowSize;
             *rowSize++ = SWAP_LONG_BYTES(ulTmp);
           }
       }
    }
  return image;
}

Here is the caller graph for this function:

Image * pp::Image::readFile ( const char *  fileName) [static, inherited]

Definition at line 54 of file image.cpp.

{
       int len = strlen(fileName);
       
       // PNG Image?
       if(!strcmp(fileName+len-3,"png")){
              Image* image=new ReaderPNG(fileName);
              
              // check if the image contains valid data
              if(image->data!=NULL){
                     return image;        
              } else {
                     delete image;
                     return NULL;
              }
       }else{
              // try it as rgb (should we check for this first?)
              Image* image=new ReaderRGB(fileName);
              return image;        
       }
}

Here is the caller graph for this function:

bool pp::Image::writeToFile ( const char *  fileName) const [inherited]

Definition at line 77 of file image.cpp.

{
       WriterPPM writer(fileName,*this);
       
       return true;
}

Here is the caller graph for this function:


Member Data Documentation

unsigned char* pp::Image::data [inherited]

Definition at line 32 of file image.h.

unsigned char pp::Image::depth [inherited]

Definition at line 31 of file image.h.

unsigned short pp::Image::height [inherited]

Definition at line 30 of file image.h.

unsigned short pp::Image::width [inherited]

Definition at line 30 of file image.h.


The documentation for this class was generated from the following files: