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 |
Definition at line 44 of file mxjpeg.h.
| mx::mxJpeg::mxJpeg | ( | ) | [inline] |
| mx::mxJpeg::~mxJpeg | ( | ) | [inline] |
| void mx::mxJpeg::jpgClose | ( | ) |
jpgClose close image File
Definition at line 101 of file mxjpeg.cpp.
References data.
Referenced by mx::mxImage::loadIMG().
| bool mx::mxJpeg::jpgOpen | ( | FILE * | fptr | ) |
jpgOpen open image file
| fptr | file pointer for opened file |
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
| fileName | name of file to open |
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
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 }
unsigned char* mx::mxJpeg::data [protected] |
1.5.8