#include "tr_local.h"
#include "../jpeg-6/jpeglib.h"
Include dependency graph for tr_image.c:

Go to the source code of this file.
Data Structures | |
| struct | BMPHeader_t |
| struct | my_destination_mgr |
| struct | textureMode_t |
Defines | |
| #define | DEFAULT_SIZE 16 |
| #define | DLIGHT_SIZE 16 |
| #define | FILE_HASH_SIZE 1024 |
| #define | FOG_S 256 |
| #define | FOG_T 32 |
| #define | JPEG_INTERNALS |
Typedefs | |
| typedef my_destination_mgr * | my_dest_ptr |
Functions | |
| char * | CommaParse (char **data_p) |
| boolean | empty_output_buffer (j_compress_ptr cinfo) |
| long | generateHashValue (const char *fname) |
| void | GL_TextureMode (const char *string) |
| void | init_destination (j_compress_ptr cinfo) |
| GLOBAL void | jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) |
| GLOBAL JDIMENSION | jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines) |
| void | jpegDest (j_compress_ptr cinfo, byte *outfile, int size) |
| void | LoadBMP (const char *name, byte **pic, int *width, int *height) |
| void | LoadJPG (const char *filename, unsigned char **pic, int *width, int *height) |
| void | LoadJPG (const char *name, byte **pic, int *width, int *height) |
| void | LoadPCX (const char *filename, byte **pic, byte **palette, int *width, int *height) |
| void | LoadPCX32 (const char *filename, byte **pic, int *width, int *height) |
| void | LoadTGA (const char *name, byte **pic, int *width, int *height) |
| void | R_BlendOverTexture (byte *data, int pixelCount, byte blend[4]) |
| void | R_CreateBuiltinImages (void) |
| void | R_CreateDefaultImage (void) |
| void | R_CreateDlightImage (void) |
| void | R_CreateFogImage (void) |
| image_t * | R_CreateImage (const char *name, const byte *pic, int width, int height, qboolean mipmap, qboolean allowPicmip, int glWrapClampMode) |
| void | R_DeleteTextures (void) |
| image_t * | R_FindImageFile (const char *name, qboolean mipmap, qboolean allowPicmip, int glWrapClampMode) |
| float | R_FogFactor (float s, float t) |
| void | R_GammaCorrect (byte *buffer, int bufSize) |
| skin_t * | R_GetSkinByHandle (qhandle_t hSkin) |
| void | R_ImageList_f (void) |
| void | R_InitFogTable (void) |
| void | R_InitImages (void) |
| void | R_InitSkins (void) |
| void | R_LightScaleTexture (unsigned *in, int inwidth, int inheight, qboolean only_gamma) |
| void | R_LoadImage (const char *name, byte **pic, int *width, int *height) |
| void | R_MipMap (byte *in, int width, int height) |
| void | R_MipMap2 (unsigned *in, int inWidth, int inHeight) |
| void | R_SetColorMappings (void) |
| void | R_SkinList_f (void) |
| int | R_SumOfUsedImages (void) |
| qhandle_t | RE_RegisterSkin (const char *name) |
| void | ResampleTexture (unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight) |
| void | SaveJPG (char *filename, int quality, int image_width, int image_height, unsigned char *image_buffer) |
| void | term_destination (j_compress_ptr cinfo) |
| void | Upload32 (unsigned *data, int width, int height, qboolean mipmap, qboolean picmip, qboolean lightMap, int *format, int *pUploadWidth, int *pUploadHeight) |
Variables | |
| qboolean | charSet |
| int | gl_filter_max = GL_LINEAR |
| int | gl_filter_min = GL_LINEAR_MIPMAP_NEAREST |
| int | hackSize |
| image_t * | hashTable [FILE_HASH_SIZE] |
| byte | mipBlendColors [16][4] |
| textureMode_t | modes [] |
| unsigned char | s_gammatable [256] |
| byte | s_intensitytable [256] |
|
|
Definition at line 2050 of file tr_image.c. Referenced by R_CreateBuiltinImages(), and R_CreateDefaultImage(). |
|
|
Definition at line 1919 of file tr_image.c. Referenced by R_CreateDlightImage(). |
|
|
Definition at line 47 of file tr_image.c. |
|
|
Definition at line 2007 of file tr_image.c. Referenced by R_CreateFogImage(). |
|
|
Definition at line 2008 of file tr_image.c. Referenced by R_CreateFogImage(). |
|
|
Definition at line 33 of file tr_image.c. |
|
|
Definition at line 1514 of file tr_image.c. |
|
|
Definition at line 2263 of file tr_image.c. References c, com_token, and data. Referenced by RE_RegisterSkin(). 02263 {
02264 int c = 0, len;
02265 char *data;
02266 static char com_token[MAX_TOKEN_CHARS];
02267
02268 data = *data_p;
02269 len = 0;
02270 com_token[0] = 0;
02271
02272 // make sure incoming data is valid
02273 if ( !data ) {
02274 *data_p = NULL;
02275 return com_token;
02276 }
02277
02278 while ( 1 ) {
02279 // skip whitespace
02280 while( (c = *data) <= ' ') {
02281 if( !c ) {
02282 break;
02283 }
02284 data++;
02285 }
02286
02287
02288 c = *data;
02289
02290 // skip double slash comments
02291 if ( c == '/' && data[1] == '/' )
02292 {
02293 while (*data && *data != '\n')
02294 data++;
02295 }
02296 // skip /* */ comments
02297 else if ( c=='/' && data[1] == '*' )
02298 {
02299 while ( *data && ( *data != '*' || data[1] != '/' ) )
02300 {
02301 data++;
02302 }
02303 if ( *data )
02304 {
02305 data += 2;
02306 }
02307 }
02308 else
02309 {
02310 break;
02311 }
02312 }
02313
02314 if ( c == 0 ) {
02315 return "";
02316 }
02317
02318 // handle quoted strings
02319 if (c == '\"')
02320 {
02321 data++;
02322 while (1)
02323 {
02324 c = *data++;
02325 if (c=='\"' || !c)
02326 {
02327 com_token[len] = 0;
02328 *data_p = ( char * ) data;
02329 return com_token;
02330 }
02331 if (len < MAX_TOKEN_CHARS)
02332 {
02333 com_token[len] = c;
02334 len++;
02335 }
02336 }
02337 }
02338
02339 // parse a regular word
02340 do
02341 {
02342 if (len < MAX_TOKEN_CHARS)
02343 {
02344 com_token[len] = c;
02345 len++;
02346 }
02347 data++;
02348 c = *data;
02349 } while (c>32 && c != ',' );
02350
02351 if (len == MAX_TOKEN_CHARS)
02352 {
02353 // Com_Printf ("Token exceeded %i chars, discarded.\n", MAX_TOKEN_CHARS);
02354 len = 0;
02355 }
02356 com_token[len] = 0;
02357
02358 *data_p = ( char * ) data;
02359 return com_token;
02360 }
|
|
|
Definition at line 1554 of file tr_image.c. References j_compress_ptr. 01555 {
01556 return TRUE;
01557 }
|
|
|
Definition at line 80 of file tr_image.c. References FILE_HASH_SIZE, i, and tolower(). 00080 {
00081 int i;
00082 long hash;
00083 char letter;
00084
00085 hash = 0;
00086 i = 0;
00087 while (fname[i] != '\0') {
00088 letter = tolower(fname[i]);
00089 if (letter =='.') break; // don't include extension
00090 if (letter =='\\') letter = '/'; // damn path names
00091 hash+=(long)(letter)*(i+119);
00092 i++;
00093 }
00094 hash &= (FILE_HASH_SIZE-1);
00095 return hash;
00096 }
|
Here is the call graph for this function:

|
|
Definition at line 103 of file tr_image.c. References GL_Bind(), gl_filter_max, gl_filter_min, glConfig, glconfig_t::hardwareType, i, image_t, trGlobals_t::images, textureMode_t::maximize, textureMode_t::minimize, image_s::mipmap, modes, name, trGlobals_t::numImages, PRINT_ALL, Q_stricmp(), qglTexParameterf, ri, string(), and tr. Referenced by GL_SetDefaultState(), and RE_BeginFrame(). 00103 {
00104 int i;
00105 image_t *glt;
00106
00107 for ( i=0 ; i< 6 ; i++ ) {
00108 if ( !Q_stricmp( modes[i].name, string ) ) {
00109 break;
00110 }
00111 }
00112
00113 // hack to prevent trilinear from being set on voodoo,
00114 // because their driver freaks...
00115 if ( i == 5 && glConfig.hardwareType == GLHW_3DFX_2D3D ) {
00116 ri.Printf( PRINT_ALL, "Refusing to set trilinear on a voodoo.\n" );
00117 i = 3;
00118 }
00119
00120
00121 if ( i == 6 ) {
00122 ri.Printf (PRINT_ALL, "bad filter name\n");
00123 return;
00124 }
00125
00126 gl_filter_min = modes[i].minimize;
00127 gl_filter_max = modes[i].maximize;
00128
00129 // change all the existing mipmap texture objects
00130 for ( i = 0 ; i < tr.numImages ; i++ ) {
00131 glt = tr.images[ i ];
00132 if ( glt->mipmap ) {
00133 GL_Bind (glt);
00134 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
00135 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
00136 }
00137 }
00138 }
|
Here is the call graph for this function:

|
|
Definition at line 1522 of file tr_image.c. References jpeg_compress_struct::dest, jpeg_destination_mgr::free_in_buffer, j_compress_ptr, my_dest_ptr, jpeg_destination_mgr::next_output_byte, my_destination_mgr::outfile, my_destination_mgr::pub, and my_destination_mgr::size. 01523 {
01524 my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
01525
01526 dest->pub.next_output_byte = dest->outfile;
01527 dest->pub.free_in_buffer = dest->size;
01528 }
|
|
||||||||||||
|
Definition at line 1576 of file tr_image.c. References CSTATE_RAW_OK, jpeg_compress_struct::dest, ERREXIT1, FALSE, j_common_ptr, j_compress_ptr, jinit_compress_master(), jpeg_suppress_tables(), jpeg_compress_struct::master, jpeg_compress_struct::next_scanline, and jpeg_compress_struct::raw_data_in. Referenced by SaveJPG(). 01577 {
01578 if (cinfo->global_state != CSTATE_START)
01579 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
01580
01581 if (write_all_tables)
01582 jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
01583
01584 /* (Re)initialize error mgr and destination modules */
01585 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
01586 (*cinfo->dest->init_destination) (cinfo);
01587 /* Perform master selection of active modules */
01588 jinit_compress_master(cinfo);
01589 /* Set up for the first pass */
01590 (*cinfo->master->prepare_for_pass) (cinfo);
01591 /* Ready for application to drive first pass through jpeg_write_scanlines
01592 * or jpeg_write_raw_data.
01593 */
01594 cinfo->next_scanline = 0;
01595 cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
01596 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 1615 of file tr_image.c. References jpeg_comp_master::call_pass_startup, ERREXIT1, jpeg_compress_struct::image_height, j_common_ptr, j_compress_ptr, JDIMENSION, JWRN_TOO_MUCH_DATA, jpeg_compress_struct::main, jpeg_compress_struct::master, jpeg_compress_struct::next_scanline, and WARNMS. Referenced by SaveJPG(). 01617 {
01618 JDIMENSION row_ctr, rows_left;
01619
01620 if (cinfo->global_state != CSTATE_SCANNING)
01621 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
01622 if (cinfo->next_scanline >= cinfo->image_height)
01623 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
01624
01625 /* Call progress monitor hook if present */
01626 if (cinfo->progress != NULL) {
01627 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
01628 cinfo->progress->pass_limit = (long) cinfo->image_height;
01629 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
01630 }
01631
01632 /* Give master control module another chance if this is first call to
01633 * jpeg_write_scanlines. This lets output of the frame/scan headers be
01634 * delayed so that application can write COM, etc, markers between
01635 * jpeg_start_compress and jpeg_write_scanlines.
01636 */
01637 if (cinfo->master->call_pass_startup)
01638 (*cinfo->master->pass_startup) (cinfo);
01639
01640 /* Ignore any extra scanlines at bottom of image. */
01641 rows_left = cinfo->image_height - cinfo->next_scanline;
01642 if (num_lines > rows_left)
01643 num_lines = rows_left;
01644
01645 row_ctr = 0;
01646 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
01647 cinfo->next_scanline += row_ctr;
01648 return row_ctr;
01649 }
|
|
||||||||||||||||
|
Definition at line 1676 of file tr_image.c. References byte, jpeg_compress_struct::dest, j_common_ptr, j_compress_ptr, my_dest_ptr, my_destination_mgr::outfile, my_destination_mgr::pub, and my_destination_mgr::size. Referenced by SaveJPG(). 01677 {
01678 my_dest_ptr dest;
01679
01680 /* The destination object is made permanent so that multiple JPEG images
01681 * can be written to the same file without re-executing jpeg_stdio_dest.
01682 * This makes it dangerous to use this manager and a different destination
01683 * manager serially with the same JPEG object, because their private object
01684 * sizes may be different. Caveat programmer.
01685 */
01686 if (cinfo->dest == NULL) { /* first time for this JPEG object? */
01687 cinfo->dest = (struct jpeg_destination_mgr *)
01688 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
01689 sizeof(my_destination_mgr));
01690 }
01691
01692 dest = (my_dest_ptr) cinfo->dest;
01693 dest->pub.init_destination = init_destination;
01694 dest->pub.empty_output_buffer = empty_output_buffer;
01695 dest->pub.term_destination = term_destination;
01696 dest->outfile = outfile;
01697 dest->size = size;
01698 }
|
|
||||||||||||||||||||
|
Definition at line 822 of file tr_image.c. References alpha, BMPHeader_t::bitmapDataOffset, BMPHeader_t::bitmapDataSize, BMPHeader_t::bitmapHeaderSize, BMPHeader_t::bitsPerPixel, blue, buffer, byte, BMPHeader_t::colors, Com_Memcpy(), BMPHeader_t::compression, ERR_DROP, BMPHeader_t::fileSize, refimport_t::FS_FreeFile, refimport_t::FS_ReadFile, green, height, BMPHeader_t::height, BMPHeader_t::hRes, BMPHeader_t::id, BMPHeader_t::importantColors, length(), LittleLong(), LittleShort(), refimport_t::Malloc, name, BMPHeader_t::palette, BMPHeader_t::planes, BMPHeader_t::reserved0, ri, rows, BMPHeader_t::vRes, width, and BMPHeader_t::width. 00823 {
00824 int columns, rows, numPixels;
00825 byte *pixbuf;
00826 int row, column;
00827 byte *buf_p;
00828 byte *buffer;
00829 int length;
00830 BMPHeader_t bmpHeader;
00831 byte *bmpRGBA;
00832
00833 *pic = NULL;
00834
00835 //
00836 // load the file
00837 //
00838 length = ri.FS_ReadFile( ( char * ) name, (void **)&buffer);
00839 if (!buffer) {
00840 return;
00841 }
00842
00843 buf_p = buffer;
00844
00845 bmpHeader.id[0] = *buf_p++;
00846 bmpHeader.id[1] = *buf_p++;
00847 bmpHeader.fileSize = LittleLong( * ( long * ) buf_p );
00848 buf_p += 4;
00849 bmpHeader.reserved0 = LittleLong( * ( long * ) buf_p );
00850 buf_p += 4;
00851 bmpHeader.bitmapDataOffset = LittleLong( * ( long * ) buf_p );
00852 buf_p += 4;
00853 bmpHeader.bitmapHeaderSize = LittleLong( * ( long * ) buf_p );
00854 buf_p += 4;
00855 bmpHeader.width = LittleLong( * ( long * ) buf_p );
00856 buf_p += 4;
00857 bmpHeader.height = LittleLong( * ( long * ) buf_p );
00858 buf_p += 4;
00859 bmpHeader.planes = LittleShort( * ( short * ) buf_p );
00860 buf_p += 2;
00861 bmpHeader.bitsPerPixel = LittleShort( * ( short * ) buf_p );
00862 buf_p += 2;
00863 bmpHeader.compression = LittleLong( * ( long * ) buf_p );
00864 buf_p += 4;
00865 bmpHeader.bitmapDataSize = LittleLong( * ( long * ) buf_p );
00866 buf_p += 4;
00867 bmpHeader.hRes = LittleLong( * ( long * ) buf_p );
00868 buf_p += 4;
00869 bmpHeader.vRes = LittleLong( * ( long * ) buf_p );
00870 buf_p += 4;
00871 bmpHeader.colors = LittleLong( * ( long * ) buf_p );
00872 buf_p += 4;
00873 bmpHeader.importantColors = LittleLong( * ( long * ) buf_p );
00874 buf_p += 4;
00875
00876 Com_Memcpy( bmpHeader.palette, buf_p, sizeof( bmpHeader.palette ) );
00877
00878 if ( bmpHeader.bitsPerPixel == 8 )
00879 buf_p += 1024;
00880
00881 if ( bmpHeader.id[0] != 'B' && bmpHeader.id[1] != 'M' )
00882 {
00883 ri.Error( ERR_DROP, "LoadBMP: only Windows-style BMP files supported (%s)\n", name );
00884 }
00885 if ( bmpHeader.fileSize != length )
00886 {
00887 ri.Error( ERR_DROP, "LoadBMP: header size does not match file size (%d vs. %d) (%s)\n", bmpHeader.fileSize, length, name );
00888 }
00889 if ( bmpHeader.compression != 0 )
00890 {
00891 ri.Error( ERR_DROP, "LoadBMP: only uncompressed BMP files supported (%s)\n", name );
00892 }
00893 if ( bmpHeader.bitsPerPixel < 8 )
00894 {
00895 ri.Error( ERR_DROP, "LoadBMP: monochrome and 4-bit BMP files not supported (%s)\n", name );
00896 }
00897
00898 columns = bmpHeader.width;
00899 rows = bmpHeader.height;
00900 if ( rows < 0 )
00901 rows = -rows;
00902 numPixels = columns * rows;
00903
00904 if ( width )
00905 *width = columns;
00906 if ( height )
00907 *height = rows;
00908
00909 bmpRGBA = ri.Malloc( numPixels * 4 );
00910 *pic = bmpRGBA;
00911
00912
00913 for ( row = rows-1; row >= 0; row-- )
00914 {
00915 pixbuf = bmpRGBA + row*columns*4;
00916
00917 for ( column = 0; column < columns; column++ )
00918 {
00919 unsigned char red, green, blue, alpha;
00920 int palIndex;
00921 unsigned short shortPixel;
00922
00923 switch ( bmpHeader.bitsPerPixel )
00924 {
00925 case 8:
00926 palIndex = *buf_p++;
00927 *pixbuf++ = bmpHeader.palette[palIndex][2];
00928 *pixbuf++ = bmpHeader.palette[palIndex][1];
00929 *pixbuf++ = bmpHeader.palette[palIndex][0];
00930 *pixbuf++ = 0xff;
00931 break;
00932 case 16:
00933 shortPixel = * ( unsigned short * ) pixbuf;
00934 pixbuf += 2;
00935 *pixbuf++ = ( shortPixel & ( 31 << 10 ) ) >> 7;
00936 *pixbuf++ = ( shortPixel & ( 31 << 5 ) ) >> 2;
00937 *pixbuf++ = ( shortPixel & ( 31 ) ) << 3;
00938 *pixbuf++ = 0xff;
00939 break;
00940
00941 case 24:
00942 blue = *buf_p++;
00943 green = *buf_p++;
00944 red = *buf_p++;
00945 *pixbuf++ = red;
00946 *pixbuf++ = green;
00947 *pixbuf++ = blue;
00948 *pixbuf++ = 255;
00949 break;
00950 case 32:
00951 blue = *buf_p++;
00952 green = *buf_p++;
00953 red = *buf_p++;
00954 alpha = *buf_p++;
00955 *pixbuf++ = red;
00956 *pixbuf++ = green;
00957 *pixbuf++ = blue;
00958 *pixbuf++ = alpha;
00959 break;
00960 default:
00961 ri.Error( ERR_DROP, "LoadBMP: illegal pixel_size '%d' in file '%s'\n", bmpHeader.bitsPerPixel, name );
00962 break;
00963 }
00964 }
00965 }
00966
00967 ri.FS_FreeFile( buffer );
00968
00969 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 1360 of file tr_image.c. References buffer, byte, refimport_t::FS_FreeFile, refimport_t::FS_ReadFile, height, i, j, jpeg_create_decompress(), jpeg_destroy_decompress(), jpeg_finish_decompress(), jpeg_read_header(), jpeg_read_scanlines(), jpeg_start_decompress(), jpeg_std_error(), jpeg_stdio_src(), JSAMPARRAY, refimport_t::Malloc, jpeg_decompress_struct::output_components, jpeg_decompress_struct::output_height, jpeg_decompress_struct::output_scanline, jpeg_decompress_struct::output_width, ri, TRUE, and width. 01360 {
01361 /* This struct contains the JPEG decompression parameters and pointers to
01362 * working space (which is allocated as needed by the JPEG library).
01363 */
01364 struct jpeg_decompress_struct cinfo;
01365 /* We use our private extension JPEG error handler.
01366 * Note that this struct must live as long as the main JPEG parameter
01367 * struct, to avoid dangling-pointer problems.
01368 */
01369 /* This struct represents a JPEG error handler. It is declared separately
01370 * because applications often want to supply a specialized error handler
01371 * (see the second half of this file for an example). But here we just
01372 * take the easy way out and use the standard error handler, which will
01373 * print a message on stderr and call exit() if compression fails.
01374 * Note that this struct must live as long as the main JPEG parameter
01375 * struct, to avoid dangling-pointer problems.
01376 */
01377 struct jpeg_error_mgr jerr;
01378 /* More stuff */
01379 JSAMPARRAY buffer; /* Output row buffer */
01380 int row_stride; /* physical row width in output buffer */
01381 unsigned char *out;
01382 byte *fbuffer;
01383 byte *bbuf;
01384
01385 /* In this example we want to open the input file before doing anything else,
01386 * so that the setjmp() error recovery below can assume the file is open.
01387 * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
01388 * requires it in order to read binary files.
01389 */
01390
01391 ri.FS_ReadFile ( ( char * ) filename, (void **)&fbuffer);
01392 if (!fbuffer) {
01393 return;
01394 }
01395
01396 /* Step 1: allocate and initialize JPEG decompression object */
01397
01398 /* We have to set up the error handler first, in case the initialization
01399 * step fails. (Unlikely, but it could happen if you are out of memory.)
01400 * This routine fills in the contents of struct jerr, and returns jerr's
01401 * address which we place into the link field in cinfo.
01402 */
01403 cinfo.err = jpeg_std_error(&jerr);
01404
01405 /* Now we can initialize the JPEG decompression object. */
01406 jpeg_create_decompress(&cinfo);
01407
01408 /* Step 2: specify data source (eg, a file) */
01409
01410 jpeg_stdio_src(&cinfo, fbuffer);
01411
01412 /* Step 3: read file parameters with jpeg_read_header() */
01413
01414 (void) jpeg_read_header(&cinfo, TRUE);
01415 /* We can ignore the return value from jpeg_read_header since
01416 * (a) suspension is not possible with the stdio data source, and
01417 * (b) we passed TRUE to reject a tables-only JPEG file as an error.
01418 * See libjpeg.doc for more info.
01419 */
01420
01421 /* Step 4: set parameters for decompression */
01422
01423 /* In this example, we don't need to change any of the defaults set by
01424 * jpeg_read_header(), so we do nothing here.
01425 */
01426
01427 /* Step 5: Start decompressor */
01428
01429 (void) jpeg_start_decompress(&cinfo);
01430 /* We can ignore the return value since suspension is not possible
01431 * with the stdio data source.
01432 */
01433
01434 /* We may need to do some setup of our own at this point before reading
01435 * the data. After jpeg_start_decompress() we have the correct scaled
01436 * output image dimensions available, as well as the output colormap
01437 * if we asked for color quantization.
01438 * In this example, we need to make an output work buffer of the right size.
01439 */
01440 /* JSAMPLEs per row in output buffer */
01441 row_stride = cinfo.output_width * cinfo.output_components;
01442
01443 out = ri.Malloc(cinfo.output_width*cinfo.output_height*cinfo.output_components);
01444
01445 *pic = out;
01446 *width = cinfo.output_width;
01447 *height = cinfo.output_height;
01448
01449 /* Step 6: while (scan lines remain to be read) */
01450 /* jpeg_read_scanlines(...); */
01451
01452 /* Here we use the library's state variable cinfo.output_scanline as the
01453 * loop counter, so that we don't have to keep track ourselves.
01454 */
01455 while (cinfo.output_scanline < cinfo.output_height) {
01456 /* jpeg_read_scanlines expects an array of pointers to scanlines.
01457 * Here the array is only one element long, but you could ask for
01458 * more than one scanline at a time if that's more convenient.
01459 */
01460 bbuf = ((out+(row_stride*cinfo.output_scanline)));
01461 buffer = &bbuf;
01462 (void) jpeg_read_scanlines(&cinfo, buffer, 1);
01463 }
01464
01465 // clear all the alphas to 255
01466 {
01467 int i, j;
01468 byte *buf;
01469
01470 buf = *pic;
01471
01472 j = cinfo.output_width * cinfo.output_height * 4;
01473 for ( i = 3 ; i < j ; i+=4 ) {
01474 buf[i] = 255;
01475 }
01476 }
01477
01478 /* Step 7: Finish decompression */
01479
01480 (void) jpeg_finish_decompress(&cinfo);
01481 /* We can ignore the return value since suspension is not possible
01482 * with the stdio data source.
01483 */
01484
01485 /* Step 8: Release JPEG decompression object */
01486
01487 /* This is an important step since it will release a good deal of memory. */
01488 jpeg_destroy_decompress(&cinfo);
01489
01490 /* After finish_decompress, we can close the input file.
01491 * Here we postpone it until after no more JPEG errors are possible,
01492 * so as to simplify the setjmp error logic above. (Actually, I don't
01493 * think that jpeg_destroy can do an error exit, but why assume anything...)
01494 */
01495 ri.FS_FreeFile (fbuffer);
01496
01497 /* At this point you may want to check to see whether any corrupt-data
01498 * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
01499 */
01500
01501 /* And we're done! */
01502 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
|
|
||||||||||||||||||||||||
|
Definition at line 986 of file tr_image.c. References pcx_t::bits_per_pixel, byte, Com_Memcpy(), pcx_t::data, pcx_t::encoding, refimport_t::Free, refimport_t::FS_FreeFile, refimport_t::FS_ReadFile, height, LittleShort(), refimport_t::Malloc, pcx_t::manufacturer, PRINT_ALL, PRINT_DEVELOPER, ri, pcx_t::version, width, x, pcx_t::xmax, y, and pcx_t::ymax. 00987 {
00988 byte *raw;
00989 pcx_t *pcx;
00990 int x, y;
00991 int len;
00992 int dataByte, runLength;
00993 byte *out, *pix;
00994 int xmax, ymax;
00995
00996 *pic = NULL;
00997 *palette = NULL;
00998
00999 //
01000 // load the file
01001 //
01002 len = ri.FS_ReadFile( ( char * ) filename, (void **)&raw);
01003 if (!raw) {
01004 return;
01005 }
01006
01007 //
01008 // parse the PCX file
01009 //
01010 pcx = (pcx_t *)raw;
01011 raw = &pcx->data;
01012
01013 xmax = LittleShort(pcx->xmax);
01014 ymax = LittleShort(pcx->ymax);
01015
01016 if (pcx->manufacturer != 0x0a
01017 || pcx->version != 5
01018 || pcx->encoding != 1
01019 || pcx->bits_per_pixel != 8
01020 || xmax >= 1024
01021 || ymax >= 1024)
01022 {
01023 ri.Printf (PRINT_ALL, "Bad pcx file %s (%i x %i) (%i x %i)\n", filename, xmax+1, ymax+1, pcx->xmax, pcx->ymax);
01024 return;
01025 }
01026
01027 out = ri.Malloc ( (ymax+1) * (xmax+1) );
01028
01029 *pic = out;
01030
01031 pix = out;
01032
01033 if (palette)
01034 {
01035 *palette = ri.Malloc(768);
01036 Com_Memcpy (*palette, (byte *)pcx + len - 768, 768);
01037 }
01038
01039 if (width)
01040 *width = xmax+1;
01041 if (height)
01042 *height = ymax+1;
01043 // FIXME: use bytes_per_line here?
01044
01045 for (y=0 ; y<=ymax ; y++, pix += xmax+1)
01046 {
01047 for (x=0 ; x<=xmax ; )
01048 {
01049 dataByte = *raw++;
01050
01051 if((dataByte & 0xC0) == 0xC0)
01052 {
01053 runLength = dataByte & 0x3F;
01054 dataByte = *raw++;
01055 }
01056 else
01057 runLength = 1;
01058
01059 while(runLength-- > 0)
01060 pix[x++] = dataByte;
01061 }
01062
01063 }
01064
01065 if ( raw - (byte *)pcx > len)
01066 {
01067 ri.Printf (PRINT_DEVELOPER, "PCX file %s was malformed", filename);
01068 ri.Free (*pic);
01069 *pic = NULL;
01070 }
01071
01072 ri.FS_FreeFile (pcx);
01073 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 1081 of file tr_image.c. References byte, c, refimport_t::Free, height, i, LoadPCX(), refimport_t::Malloc, p, ri, and width. 01081 {
01082 byte *palette;
01083 byte *pic8;
01084 int i, c, p;
01085 byte *pic32;
01086
01087 LoadPCX (filename, &pic8, &palette, width, height);
01088 if (!pic8) {
01089 *pic = NULL;
01090 return;
01091 }
01092
01093 c = (*width) * (*height);
01094 pic32 = *pic = ri.Malloc(4 * c );
01095 for (i = 0 ; i < c ; i++) {
01096 p = pic8[i];
01097 pic32[0] = palette[p*3];
01098 pic32[1] = palette[p*3 + 1];
01099 pic32[2] = palette[p*3 + 2];
01100 pic32[3] = 255;
01101 pic32 += 4;
01102 }
01103
01104 ri.Free (pic8);
01105 ri.Free (palette);
01106 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 1121 of file tr_image.c. References _TargaHeader::attributes, blue, buffer, byte, _TargaHeader::colormap_index, _TargaHeader::colormap_length, _TargaHeader::colormap_size, _TargaHeader::colormap_type, ERR_DROP, free(), refimport_t::FS_FreeFile, refimport_t::FS_ReadFile, green, height, _TargaHeader::height, _TargaHeader::id_length, _TargaHeader::image_type, j, LittleShort(), malloc(), refimport_t::Malloc, memcpy(), name, _TargaHeader::pixel_size, PRINT_WARNING, ri, rows, src, TargaHeader, width, _TargaHeader::width, _TargaHeader::x_origin, and _TargaHeader::y_origin. 01122 {
01123 int columns, rows, numPixels;
01124 byte *pixbuf;
01125 int row, column;
01126 byte *buf_p;
01127 byte *buffer;
01128 TargaHeader targa_header;
01129 byte *targa_rgba;
01130
01131 *pic = NULL;
01132
01133 //
01134 // load the file
01135 //
01136 ri.FS_ReadFile ( ( char * ) name, (void **)&buffer);
01137 if (!buffer) {
01138 return;
01139 }
01140
01141 buf_p = buffer;
01142
01143 targa_header.id_length = *buf_p++;
01144 targa_header.colormap_type = *buf_p++;
01145 targa_header.image_type = *buf_p++;
01146
01147 targa_header.colormap_index = LittleShort ( *(short *)buf_p );
01148 buf_p += 2;
01149 targa_header.colormap_length = LittleShort ( *(short *)buf_p );
01150 buf_p += 2;
01151 targa_header.colormap_size = *buf_p++;
01152 targa_header.x_origin = LittleShort ( *(short *)buf_p );
01153 buf_p += 2;
01154 targa_header.y_origin = LittleShort ( *(short *)buf_p );
01155 buf_p += 2;
01156 targa_header.width = LittleShort ( *(short *)buf_p );
01157 buf_p += 2;
01158 targa_header.height = LittleShort ( *(short *)buf_p );
01159 buf_p += 2;
01160 targa_header.pixel_size = *buf_p++;
01161 targa_header.attributes = *buf_p++;
01162
01163 if (targa_header.image_type!=2
01164 && targa_header.image_type!=10
01165 && targa_header.image_type != 3 )
01166 {
01167 ri.Error (ERR_DROP, "LoadTGA: Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported\n");
01168 }
01169
01170 if ( targa_header.colormap_type != 0 )
01171 {
01172 ri.Error( ERR_DROP, "LoadTGA: colormaps not supported\n" );
01173 }
01174
01175 if ( ( targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) && targa_header.image_type != 3 )
01176 {
01177 ri.Error (ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
01178 }
01179
01180 columns = targa_header.width;
01181 rows = targa_header.height;
01182 numPixels = columns * rows;
01183
01184 if (width)
01185 *width = columns;
01186 if (height)
01187 *height = rows;
01188
01189 targa_rgba = ri.Malloc (numPixels*4);
01190 *pic = targa_rgba;
01191
01192 if (targa_header.id_length != 0)
01193 buf_p += targa_header.id_length; // skip TARGA image comment
01194
01195 if ( targa_header.image_type==2 || targa_header.image_type == 3 )
01196 {
01197 // Uncompressed RGB or gray scale image
01198 for(row=rows-1; row>=0; row--)
01199 {
01200 pixbuf = targa_rgba + row*columns*4;
01201 for(column=0; column<columns; column++)
01202 {
01203 unsigned char red,green,blue,alphabyte;
01204 switch (targa_header.pixel_size)
01205 {
01206
01207 case 8:
01208 blue = *buf_p++;
01209 green = blue;
01210 red = blue;
01211 *pixbuf++ = red;
01212 *pixbuf++ = green;
01213 *pixbuf++ = blue;
01214 *pixbuf++ = 255;
01215 break;
01216
01217 case 24:
01218 blue = *buf_p++;
01219 green = *buf_p++;
01220 red = *buf_p++;
01221 *pixbuf++ = red;
01222 *pixbuf++ = green;
01223 *pixbuf++ = blue;
01224 *pixbuf++ = 255;
01225 break;
01226 case 32:
01227 blue = *buf_p++;
01228 green = *buf_p++;
01229 red = *buf_p++;
01230 alphabyte = *buf_p++;
01231 *pixbuf++ = red;
01232 *pixbuf++ = green;
01233 *pixbuf++ = blue;
01234 *pixbuf++ = alphabyte;
01235 break;
01236 default:
01237 ri.Error( ERR_DROP, "LoadTGA: illegal pixel_size '%d' in file '%s'\n", targa_header.pixel_size, name );
01238 break;
01239 }
01240 }
01241 }
01242 }
01243 else if (targa_header.image_type==10) { // Runlength encoded RGB images
01244 unsigned char red,green,blue,alphabyte,packetHeader,packetSize,j;
01245
01246 red = 0;
01247 green = 0;
01248 blue = 0;
01249 alphabyte = 0xff;
01250
01251 for(row=rows-1; row>=0; row--) {
01252 pixbuf = targa_rgba + row*columns*4;
01253 for(column=0; column<columns; ) {
01254 packetHeader= *buf_p++;
01255 packetSize = 1 + (packetHeader & 0x7f);
01256 if (packetHeader & 0x80) { // run-length packet
01257 switch (targa_header.pixel_size) {
01258 case 24:
01259 blue = *buf_p++;
01260 green = *buf_p++;
01261 red = *buf_p++;
01262 alphabyte = 255;
01263 break;
01264 case 32:
01265 blue = *buf_p++;
01266 green = *buf_p++;
01267 red = *buf_p++;
01268 alphabyte = *buf_p++;
01269 break;
01270 default:
01271 ri.Error( ERR_DROP, "LoadTGA: illegal pixel_size '%d' in file '%s'\n", targa_header.pixel_size, name );
01272 break;
01273 }
01274
01275 for(j=0;j<packetSize;j++) {
01276 *pixbuf++=red;
01277 *pixbuf++=green;
01278 *pixbuf++=blue;
01279 *pixbuf++=alphabyte;
01280 column++;
01281 if (column==columns) { // run spans across rows
01282 column=0;
01283 if (row>0)
01284 row--;
01285 else
01286 goto breakOut;
01287 pixbuf = targa_rgba + row*columns*4;
01288 }
01289 }
01290 }
01291 else { // non run-length packet
01292 for(j=0;j<packetSize;j++) {
01293 switch (targa_header.pixel_size) {
01294 case 24:
01295 blue = *buf_p++;
01296 green = *buf_p++;
01297 red = *buf_p++;
01298 *pixbuf++ = red;
01299 *pixbuf++ = green;
01300 *pixbuf++ = blue;
01301 *pixbuf++ = 255;
01302 break;
01303 case 32:
01304 blue = *buf_p++;
01305 green = *buf_p++;
01306 red = *buf_p++;
01307 |