mx::mxJpeg Class Reference

List of all members.

Public Member Functions

 mxJpeg ()
 ~mxJpeg ()
bool jpgOpen (string fileName)
bool jpgOpen (FILE *fptr)
void jpgClose ()
SDL_Surface * LoadJPG ()

Protected Attributes

unsigned char * data
int w
int h
int bytes


Detailed Description

class

Definition at line 44 of file mxjpeg.h.


Constructor & Destructor Documentation

mx::mxJpeg::mxJpeg (  )  [inline]

default constructor

Definition at line 48 of file mxjpeg.h.

References data.

00048                          {
00049                         data = 0;
00050                 }

mx::mxJpeg::~mxJpeg (  )  [inline]

destructor

Definition at line 52 of file mxjpeg.h.

References data.

00052                           {
00053                         if(data) delete [] data;
00054                         data = 0;
00055                 }


Member Function Documentation

void mx::mxJpeg::jpgClose (  ) 

jpgClose close image File

Definition at line 101 of file mxjpeg.cpp.

References data.

Referenced by mx::mxImage::loadIMG().

00101                               {
00102 
00103                 if(data) delete [] data;
00104                 data = 0;
00105         }

bool mx::mxJpeg::jpgOpen ( FILE *  fptr  ) 

jpgOpen open image file

Parameters:
fptr file pointer for opened file
Returns:
boolean value true for success false for failure

Definition at line 23 of file mxjpeg.cpp.

References data.

00023                                        {
00024 
00025 
00026                 jpeg_decompress_struct deInfo;
00027                 jpeg_error_mgr deErr;
00028 
00029                 deInfo.err = jpeg_std_error(&deErr);
00030                 jpeg_create_decompress(&deInfo);
00031                 jpeg_stdio_src(&deInfo, fptr);
00032                 jpeg_read_header(&deInfo, TRUE);
00033                 jpeg_start_decompress(&deInfo);
00034 
00035                 int width = deInfo.output_width, height = deInfo.output_height, depth = deInfo.num_components;
00036                 int output_lines = deInfo.output_height;
00037 
00038                 if(data != 0) delete [] data;
00039                 data = 0;
00040 
00041                 data = new unsigned char [ ( width * height ) * depth ];
00042                 JSAMPROW row_ptr[1];
00043 
00044                 row_ptr[0] = (unsigned char*) malloc(deInfo.output_width*deInfo.num_components);
00045 
00046                 unsigned int i = 0;
00047                 unsigned long location = 0;
00048 
00049                 while (deInfo.output_scanline < deInfo.image_height)
00050                 {
00051                     jpeg_read_scanlines(&deInfo, row_ptr, 1);
00052                         for(i = 0; i <deInfo.image_width*deInfo.num_components; i++)
00053                                 data[location++] = row_ptr[0][i];
00054                  }
00055 
00056                 jpeg_finish_decompress(&deInfo);
00057                 jpeg_destroy_decompress(&deInfo);
00058                 w = width, h = height, bytes = depth;
00059                 fclose(fptr);
00060                 free(row_ptr[0]);
00061 
00062                 return true;
00063         }

bool mx::mxJpeg::jpgOpen ( string  fileName  ) 

jpgOpen opens image file

Parameters:
fileName name of file to open
Returns:
boolean value true for success false for failure

Definition at line 65 of file mxjpeg.cpp.

Referenced by mx::mxImage::loadIMG().

00065                                             {
00066 
00067 
00068                 FILE *fptr = fopen(fileName.c_str(), "rb");
00069 
00070                 if(fptr == 0) return false;
00071 
00072                 return jpgOpen(fptr);
00073 
00074         }

SDL_Surface * mx::mxJpeg::LoadJPG (  ) 

LoadJPG loads a jpeg to a SDL_Surface call this function directly after jpgOpen and before jpgClose

Returns:
SDL_Surface *

Definition at line 77 of file mxjpeg.cpp.

References data.

Referenced by mx::mxImage::loadIMG().

00077                                      {
00078 
00079                 SDL_Surface *surf = CreateBuffer(w,h);
00080 
00081 
00082                 if(SDL_MUSTLOCK(surf)) SDL_LockSurface(surf);
00083 
00084 
00085                 unsigned int *pixels = (unsigned int*) surf->pixels;
00086                 unsigned int *buf = (unsigned int *) data;
00087                 unsigned int pos = 0;
00088                 unsigned char *dat = (unsigned char*) data;
00089 
00090                 while ( pos < (w*h) ) {
00091                         unsigned char *v = dat;
00092                         pixels[pos++] = SDL_MapRGB(surf->format, v[0], v[1], v[2]);
00093                         dat += bytes;
00094                 }
00095 
00096                 if(SDL_MUSTLOCK(surf)) SDL_UnlockSurface(surf);
00097 
00098                 return surf;
00099         }


Member Data Documentation

unsigned char* mx::mxJpeg::data [protected]

raw image data

Definition at line 75 of file mxjpeg.h.

Referenced by jpgClose(), jpgOpen(), LoadJPG(), mxJpeg(), and ~mxJpeg().


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

Generated on Wed Jun 10 14:52:02 2009 for libmx by  doxygen 1.5.8