Go to the source code of this file.
Compounds | |
struct | tgaInfo |
Enumerations | |
enum | { TGA_ERROR_FILE_OPEN, TGA_ERROR_READING_FILE, TGA_ERROR_INDEXED_COLOR, TGA_ERROR_MEMORY, TGA_ERROR_COMPRESSED_FILE, TGA_OK } |
Functions | |
int | tgaSave (char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData) |
int | tgaSaveSeries (char *filename, short int width, short int height, unsigned char pixelDepth, unsigned char *imageData) |
|
Definition at line 6 of file tga.h.
00007 { 00008 TGA_ERROR_FILE_OPEN, 00009 TGA_ERROR_READING_FILE, 00010 TGA_ERROR_INDEXED_COLOR, 00011 TGA_ERROR_MEMORY, 00012 TGA_ERROR_COMPRESSED_FILE, 00013 TGA_OK 00014 }; |
|
Definition at line 205 of file tga.cpp. Referenced by CreateLightmaps(), and tgaSaveSeries().
00209 { 00210 00211 unsigned char cGarbage = 0, type,mode,aux; 00212 short int iGarbage = 0; 00213 int i; 00214 FILE *file; 00215 00216 // open file and check for errors 00217 file = fopen(filename, "wb"); 00218 if (file == NULL) { 00219 return(TGA_ERROR_FILE_OPEN); 00220 } 00221 00222 // compute image type: 2 for RGB(A), 3 for greyscale 00223 mode = (unsigned char)(pixelDepth / 8); 00224 if ((pixelDepth == 24) || (pixelDepth == 32)) 00225 type = 2; 00226 else 00227 type = 3; 00228 00229 // write the header 00230 fwrite(&cGarbage, sizeof(unsigned char), 1, file); 00231 fwrite(&cGarbage, sizeof(unsigned char), 1, file); 00232 00233 fwrite(&type, sizeof(unsigned char), 1, file); 00234 00235 fwrite(&iGarbage, sizeof(short int), 1, file); 00236 fwrite(&iGarbage, sizeof(short int), 1, file); 00237 fwrite(&cGarbage, sizeof(unsigned char), 1, file); 00238 fwrite(&iGarbage, sizeof(short int), 1, file); 00239 fwrite(&iGarbage, sizeof(short int), 1, file); 00240 00241 fwrite(&width, sizeof(short int), 1, file); 00242 fwrite(&height, sizeof(short int), 1, file); 00243 fwrite(&pixelDepth, sizeof(unsigned char), 1, file); 00244 00245 fwrite(&cGarbage, sizeof(unsigned char), 1, file); 00246 00247 // convert the image data from RGB(a) to BGR(A) 00248 if (mode >= 3) 00249 for (i=0; i < width * height * mode ; i+= mode) { 00250 aux = imageData[i]; 00251 imageData[i] = imageData[i+2]; 00252 imageData[i+2] = aux; 00253 } 00254 00255 // save the image data 00256 fwrite(imageData, sizeof(unsigned char), 00257 width * height * mode, file); 00258 fclose(file); 00259 // release the memory 00260 // free(imageData); 00261 00262 return(TGA_OK); 00263 } |
|
Definition at line 266 of file tga.cpp. References savedImages, and tgaSave(). Referenced by tgaGrabScreenSeries().
00270 { 00271 00272 char *newFilename; 00273 int status; 00274 00275 // compute the new filename by adding the 00276 // series number and the extension 00277 newFilename = (char *)malloc(sizeof(char) * strlen(filename)+8); 00278 00279 sprintf(newFilename,"%s%d.tga",filename,savedImages); 00280 00281 // save the image 00282 status = tgaSave(newFilename,width,height,pixelDepth,imageData); 00283 00284 //increase the counter 00285 savedImages++; 00286 return(status); 00287 } |