Changeset 6653 for trunk/src/opengl/glide/cvg/texus
- Timestamp:
- Sep 5, 2001, 4:31:14 PM (24 years ago)
- Location:
- trunk/src/opengl/glide/cvg/texus
- Files:
-
- 19 edited
-
3df.c (modified) (6 diffs)
-
clamp.c (modified) (7 diffs)
-
dequant.c (modified) (10 diffs)
-
diffuse.c (modified) (17 diffs)
-
gldutil.c (modified) (5 diffs)
-
mipmap.c (modified) (3 diffs)
-
ncc.c (modified) (9 diffs)
-
nccnnet.c (modified) (21 diffs)
-
pal256.c (modified) (19 diffs)
-
ppm.c (modified) (5 diffs)
-
quantize.c (modified) (23 diffs)
-
read.c (modified) (10 diffs)
-
resample.c (modified) (9 diffs)
-
rgt.c (modified) (11 diffs)
-
texuslib.c (modified) (25 diffs)
-
tga.c (modified) (12 diffs)
-
util.c (modified) (12 diffs)
-
view.c (modified) (2 diffs)
-
write.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/glide/cvg/texus/3df.c
r2888 r6653 1 /* $Id: 3df.c,v 1.2 2001-09-05 14:30:43 bird Exp $ */ 1 2 /* 2 3 * THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 * PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 * TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 * INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 * DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 * THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 * INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 * DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 * THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 * EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 * FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 * FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 11 * 11 12 * USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO … … 25 26 /*************************************** 3df files ****************************/ 26 27 /* Read word, msb first */ 27 static FxBool 28 static FxBool 28 29 _txRead16 (FILE *stream, FxU16* data) 29 30 { … … 36 37 37 38 /* Read long word, msb first */ 38 static FxBool 39 static FxBool 39 40 _txRead32 (FILE *stream, FxU32* data) 40 41 { … … 53 54 54 55 /* Read NCC table */ 55 static FxBool 56 static FxBool 56 57 _txRead3DFNCCTable (FILE* stream, FxI32* ncc_table) 57 58 { … … 87 88 } 88 89 89 static FxBool 90 static FxBool 90 91 _txRead3DFPalTable (FILE* stream, FxI32* pal) 91 92 { … … 114 115 if (fscanf (stream, "f v%6s", version) != 1) return FXFALSE; 115 116 116 /* 117 /* 117 118 * skip comments 118 119 */ -
trunk/src/opengl/glide/cvg/texus/clamp.c
r2888 r6653 1 /* $Id: clamp.c,v 1.2 2001-09-05 14:30:44 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:37:58$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:44 $ 23 24 */ 24 25 … … 37 38 if( txVerbose ) 38 39 { 39 printf( "clamping from %dx%d to %dx%d\n", 40 printf( "clamping from %dx%d to %dx%d\n", 40 41 ix, iy, ox, oy ); 41 42 } … … 76 77 if ((srcMip->data[0] == NULL) || (dstMip->data[0] == NULL)) 77 78 txPanic("txImageClamp: Null buffer\n"); 78 79 79 80 sw = srcMip->width; 80 81 sh = srcMip->height; … … 82 83 dh = dstMip->height; 83 84 84 for( i = 0; i < srcMip->depth; i++ ) 85 for( i = 0; i < srcMip->depth; i++ ) 85 86 { 86 87 if( !dstMip->data[i] ) … … 103 104 } 104 105 } 105 106 -
trunk/src/opengl/glide/cvg/texus/dequant.c
r2888 r6653 1 /* $Id: dequant.c,v 1.2 2001-09-05 14:30:44 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:37:58$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:44 $ 23 24 */ 24 25 … … 30 31 #include "texusint.h" 31 32 32 /* 33 /* 33 34 * Pn_8 = convert n bits (n <= 6) to 8 bits by replicating the msb's of input 34 35 * into the lsb's of the output. … … 94 95 95 96 /* 16 bit pixels */ 96 static FxU32 97 static FxU32 97 98 _txPixArgb8332to8888(FxU16 c8332) 98 99 { 99 100 FxU32 a, r, g, b; 100 a = (c8332 >> 8); 101 a = (c8332 >> 8); 101 102 r = P3_8[(c8332 >> 5) & 0x7]; 102 103 g = P3_8[(c8332 >> 2) & 0x7]; … … 233 234 in += n; 234 235 while (n--) { 235 in--; 236 in--; 236 237 *--out = (pal[(*in) & 0xff] & 0x00ffffff) | ((*in & 0xFF00) << 16); 237 238 } … … 302 303 in += n; 303 304 304 while (n--) *--out = *--in; 305 while (n--) *--out = *--in; 305 306 } 306 307 … … 314 315 for( i = 0; i < n; i++ ) 315 316 { 316 out[i] = 317 ( ( ( FxU32 )0xff ) << 24 ) | 317 out[i] = 318 ( ( ( FxU32 )0xff ) << 24 ) | 318 319 ( ( ( FxU32 )in[i*3] )<< 16 ) | 319 320 ( ( ( FxU32 )in[i*3+1] )<< 8 ) | … … 322 323 } 323 324 324 void 325 void 325 326 txMipDequantize(TxMip *txMip, TxMip *pxMip) 326 327 { … … 344 345 printf(" %dx%d", w, h); fflush(stdout); 345 346 } 346 347 347 348 switch(pxMip->format) { 348 case GR_TEXFMT_RGB_332: _txImgDequantizeRGB332(dst, src, w, h); 349 break; 350 case GR_TEXFMT_YIQ_422: _txImgDequantizeYIQ422(dst, src, w, h, 349 case GR_TEXFMT_RGB_332: _txImgDequantizeRGB332(dst, src, w, h); 350 break; 351 case GR_TEXFMT_YIQ_422: _txImgDequantizeYIQ422(dst, src, w, h, 351 352 (long *)pxMip->pal); break; 352 case GR_TEXFMT_A_8: _txImgDequantizeA8(dst, src, w, h); 353 break; 354 case GR_TEXFMT_I_8: _txImgDequantizeI8(dst, src, w, h); 355 break; 356 case GR_TEXFMT_AI_44: _txImgDequantizeAI44(dst, src, w, h); 357 break; 358 case GR_TEXFMT_P_8: _txImgDequantizeP8(dst, src, w, h, 353 case GR_TEXFMT_A_8: _txImgDequantizeA8(dst, src, w, h); 354 break; 355 case GR_TEXFMT_I_8: _txImgDequantizeI8(dst, src, w, h); 356 break; 357 case GR_TEXFMT_AI_44: _txImgDequantizeAI44(dst, src, w, h); 358 break; 359 case GR_TEXFMT_P_8: _txImgDequantizeP8(dst, src, w, h, 359 360 pxMip->pal); break; 360 361 361 case GR_TEXFMT_ARGB_8332: _txImgDequantizeARGB8332(dst, src, w, h); 362 break; 363 case GR_TEXFMT_AYIQ_8422: _txImgDequantizeAYIQ8422(dst, src, w, h, 362 case GR_TEXFMT_ARGB_8332: _txImgDequantizeARGB8332(dst, src, w, h); 363 break; 364 case GR_TEXFMT_AYIQ_8422: _txImgDequantizeAYIQ8422(dst, src, w, h, 364 365 (long *)pxMip->pal); break; 365 case GR_TEXFMT_RGB_565: _txImgDequantizeRGB565(dst, src, w, h); 366 break; 367 case GR_TEXFMT_ARGB_1555: _txImgDequantizeARGB1555(dst, src, w, h); 368 break; 369 case GR_TEXFMT_ARGB_4444: _txImgDequantizeARGB4444(dst, src, w, h); 370 break; 371 case GR_TEXFMT_AI_88: _txImgDequantizeAI88(dst, src, w, h); 372 break; 373 case GR_TEXFMT_AP_88: _txImgDequantizeAP88(dst, src, w, h, 366 case GR_TEXFMT_RGB_565: _txImgDequantizeRGB565(dst, src, w, h); 367 break; 368 case GR_TEXFMT_ARGB_1555: _txImgDequantizeARGB1555(dst, src, w, h); 369 break; 370 case GR_TEXFMT_ARGB_4444: _txImgDequantizeARGB4444(dst, src, w, h); 371 break; 372 case GR_TEXFMT_AI_88: _txImgDequantizeAI88(dst, src, w, h); 373 break; 374 case GR_TEXFMT_AP_88: _txImgDequantizeAP88(dst, src, w, h, 374 375 pxMip->pal); break; 375 case GR_TEXFMT_ARGB_8888: _txImgDequantizeARGB8888(dst, src, w, h); 376 break; 377 case GR_TEXFMT_RGB_888: _txImgDequantizeRGB888(dst, src, w, h); 378 break; 379 380 default: 376 case GR_TEXFMT_ARGB_8888: _txImgDequantizeARGB8888(dst, src, w, h); 377 break; 378 case GR_TEXFMT_RGB_888: _txImgDequantizeRGB888(dst, src, w, h); 379 break; 380 381 default: 381 382 break; 382 383 } -
trunk/src/opengl/glide/cvg/texus/diffuse.c
r2888 r6653 1 /* $Id: diffuse.c,v 1.2 2001-09-05 14:30:44 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:37:58$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:44 $ 23 24 */ 24 25 … … 39 40 FxU8 bestR[256], bestG[256], bestB[256]; 40 41 41 static int 42 static int 42 43 _txAscendingR(const void *a, const void *b) 43 44 { … … 46 47 47 48 48 static int 49 static int 49 50 _txAscendingG(const void *a, const void *b) 50 51 { … … 53 54 54 55 55 static int 56 static int 56 57 _txAscendingB(const void *a, const void *b) 57 58 { … … 78 79 79 80 #if 0 80 for (i=0; i<ncolors; i++) 81 printf("[%3d] = R%.08x G%.08x B%.08x\n", 81 for (i=0; i<ncolors; i++) 82 printf("[%3d] = R%.08x G%.08x B%.08x\n", 82 83 i, sortR[i], sortG[i], sortB[i]); 83 84 #endif 84 85 85 86 86 87 for (i=0; i<256; i++) { 87 88 … … 129 130 persist = 0; 130 131 for (i=bestR[r]; i>=0; i--) { 131 d = DISTANCE(r, g, b, 132 d = DISTANCE(r, g, b, 132 133 ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff)); 133 134 if (d < mindist) { mindist = d; minpos = (pal[i] >> 24) & 0xff; } … … 138 139 persist = 0; 139 140 for (i=bestR[r]+1; i < nsorted; i++) { 140 d = DISTANCE(r, g, b, 141 d = DISTANCE(r, g, b, 141 142 ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff)); 142 143 if (d < mindist) { mindist = d; minpos = (pal[i] >> 24) & 0xff; } … … 149 150 persist = 0; 150 151 for (i=bestG[g]; i>=0; i--) { 151 d = DISTANCE(r, g, b, 152 d = DISTANCE(r, g, b, 152 153 ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff)); 153 154 if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; } … … 158 159 persist = 0; 159 160 for (i=bestG[g]+1; i < nsorted; i++) { 160 d = DISTANCE(r, g, b, 161 d = DISTANCE(r, g, b, 161 162 ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff)); 162 163 if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; } … … 168 169 persist = 0; 169 170 for (i=bestB[b]; i>=0; i--) { 170 d = DISTANCE(r, g, b, 171 d = DISTANCE(r, g, b, 171 172 ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff)); 172 173 if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; } … … 177 178 persist = 0; 178 179 for (i=bestB[b]+1; i < nsorted; i++) { 179 d = DISTANCE(r, g, b, 180 d = DISTANCE(r, g, b, 180 181 ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff)); 181 182 if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; } … … 221 222 ib += qb + ErrB[x]; 222 223 223 qr = ir; // quantized pixel values. 224 qr = ir; // quantized pixel values. 224 225 qg = ig; // qR is error from pixel to left, errR is 225 226 qb = ib; // error from pixel to the top & top left. … … 245 246 qb = ib - qb; 246 247 247 // 3/8 (=0.375) to the EAST, 3/8 to the SOUTH, 248 // 3/8 (=0.375) to the EAST, 3/8 to the SOUTH, 248 249 // 1/4 (0.25) to the SOUTH-EAST. 249 250 ErrR[x] = ((x == 0) ? 0 : ErrR[x]) + ((int) (qr * 0.375f)); … … 279 280 printf("EDiffusion:..."); fflush(stdout); 280 281 } 281 282 282 283 #if FAST_DIFFUSION 283 284 _txMakeRange(palette, ncolors); … … 289 290 290 291 for (i=0; i<txMip->depth; i++) { 291 _txToDiffuseIndex(pxMip->data[i], pixsize, palette, ncolors, 292 _txToDiffuseIndex(pxMip->data[i], pixsize, palette, ncolors, 292 293 txMip->data[i], w, h); 293 294 if (w > 1) w >>= 1; -
trunk/src/opengl/glide/cvg/texus/gldutil.c
r2888 r6653 1 /* $Id: gldutil.c,v 1.2 2001-09-05 14:30:45 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:37:59$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:45 $ 23 24 */ 24 25 … … 35 36 /* 36 37 * Allocate memory via Glide for a texture. 37 * Assumes that the passed image is already quantized to 38 * Assumes that the passed image is already quantized to 38 39 * the format that you want to download. 39 40 */ … … 325 326 ncc_table.yRGB[i] = ( FxU8 )texture->pal[i]; 326 327 } 327 328 328 329 for( i = 0; i < 4; i++ ) 329 330 { -
trunk/src/opengl/glide/cvg/texus/mipmap.c
r2888 r6653 1 /* $Id: mipmap.c,v 1.2 2001-09-05 14:30:45 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:37:59$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:45 $ 23 24 */ 24 25 -
trunk/src/opengl/glide/cvg/texus/ncc.c
r2888 r6653 1 /* $Id: ncc.c,v 1.2 2001-09-05 14:30:45 bird Exp $ */ 1 2 /* 2 3 ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 ** 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 12 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 12 13 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 14 15 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 15 16 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 16 ** THE UNITED STATES. 17 ** 17 ** THE UNITED STATES. 18 ** 18 19 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 19 20 ** 20 ** $Revision: 1. 1$21 ** $Date: 200 0-02-25 00:37:59$21 ** $Revision: 1.2 $ 22 ** $Date: 2001-09-05 14:30:45 $ 22 23 */ 23 24 … … 29 30 #include "texusint.h" 30 31 31 static int 32 dithmat[4][4] = { 0, 8, 2, 10, 33 12, 4, 14, 6, 34 3, 11, 1, 9, 32 static int 33 dithmat[4][4] = { 0, 8, 2, 10, 34 12, 4, 14, 6, 35 3, 11, 1, 9, 35 36 15, 7, 13, 5 }; 36 37 … … 45 46 _txPixQuantize_YIQ422 (unsigned long argb, int x, int y, int w) 46 47 { 47 int r, g, b; 48 int r, g, b; 48 49 int iy, ii, iq; 49 50 … … 125 126 126 127 static void 127 _txImgNcc(char *odata, unsigned long *idata, int w, int h, int format, 128 _txImgNcc(char *odata, unsigned long *idata, int w, int h, int format, 128 129 int dither) 129 130 { … … 153 154 154 155 RGB values can be converted to YIQ using the equation: 155 156 156 157 Y = 0.30F * R + 0.59F * G + 0.11F * B; 157 158 I = 0.60F * R - 0.28F * G - 0.32F * B; 158 159 Q = 0.21F * R - 0.52F * G + 0.31F * B; 159 160 160 Assuming that each of the RGB components are in the range 0..255, 161 Assuming that each of the RGB components are in the range 0..255, 161 162 Y ranges from (0 .. 255) 162 163 I ranges from (-0.60 * 255 .. 0.60 * 255) i.e, (-153 to 153) … … 166 167 167 168 168 static void 169 static void 169 170 _txMipNccStatTable(TxMip *txMip) 170 171 { 171 172 int i, w, h; 172 173 173 for (i=0; i<256; i++) 174 for (i=0; i<256; i++) 174 175 ncc.yhist[i] = ncc.ihist[i] = ncc.qhist[i] = 0; 175 176 ncc.npixels = 0; … … 250 251 251 252 252 void 253 void 253 254 txMipNcc(TxMip *pxMip, TxMip *txMip, int format, FxU32 dither, FxU32 compression) 254 255 { … … 256 257 257 258 switch (compression & TX_COMPRESSION_MASK) { 258 case TX_COMPRESSION_HEURISTIC: 259 case TX_COMPRESSION_HEURISTIC: 259 260 _txMipNccStatTable(txMip); 260 261 for (i=0; i< 16; i++) pxMip->pal[ 0 + i] = ncc.y[i]; -
trunk/src/opengl/glide/cvg/texus/nccnnet.c
r2888 r6653 1 /* $Id: nccnnet.c,v 1.2 2001-09-05 14:30:45 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:37:59$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:45 $ 23 24 */ 24 25 #include <stdio.h> … … 33 34 * ARGB8888 format and produces an optimal YAB table, and an 8 bit image 34 35 * in YAB format that best represents the original image. A very detailed 35 * explanation of the algorithm is available in 36 * explanation of the algorithm is available in 36 37 * /tdfx/engr/devel/sst1/docs/yab.doc. The summary follows. 37 38 * 38 * Neural net algorithms first determine a "representative sample" of the 39 * Neural net algorithms first determine a "representative sample" of the 39 40 * input image. This representative sample is repeatedly run through the net 40 41 * during the network learning stage, and the neural net "learns" which colors 41 42 * are important and which ones are not. It's quite possible to feed every 42 43 * pixel in the original image repeatedly into the neural net 43 * to make it learn; however, this can be extremely time consuming. 44 * to make it learn; however, this can be extremely time consuming. 44 45 * 45 46 * So, we prefer to make a representative sample of colors for the input image. … … 48 49 * colors (just like for the 8-bit palettized case) works quite well, and 49 50 * so we first quantize to 8 bit palette, and use the palette as the sample 50 * colors to feed the neural network. This also makes using 256-palette 51 * colors to feed the neural network. This also makes using 256-palette 51 52 * textures very easy. 52 53 * 53 54 * After the "representative colors" are determined, we train the neural net, 54 * and obtain the optimal YAB table. Each sample color in the palette, 55 * which was originally in ARGB8888 format is now replaced with IRGB8888, 56 * where the RGB is the same as before, but the alpha channel is replaced 57 * with an 8 bit number I which is the YAB index corresponding to this 58 * representative color. 55 * and obtain the optimal YAB table. Each sample color in the palette, 56 * which was originally in ARGB8888 format is now replaced with IRGB8888, 57 * where the RGB is the same as before, but the alpha channel is replaced 58 * with an 8 bit number I which is the YAB index corresponding to this 59 * representative color. 59 60 * 60 61 * So now it's possible to translate the original image into an 8 bit image … … 65 66 * In the process of converting the original image to the YAB format, we could 66 67 * optionally dither the image. Ordered dithering doesn't quite work, so we 67 * use error-diffusion dithering. 68 * use error-diffusion dithering. 68 69 * 69 70 * I've found that there are three speed bottlenecks to overcome. The first 70 71 * time consuming operation is the computation of representative image colors. 71 * 256 color quantization is used for this part. The second bottleneck is the 72 * training of the neural net algorithm itself, and I've optimized this as 72 * 256 color quantization is used for this part. The second bottleneck is the 73 * training of the neural net algorithm itself, and I've optimized this as 73 74 * much as possible. The third bottleneck is the translation of the original 74 75 * image into the 8 bit YAB indexed image; this still needs work, especially … … 79 80 80 81 /****************************************************************************** 81 * 82 * 82 83 * The hardcore neural net stuff begins here. 83 84 * … … 117 118 _nn_modifyNeurons(long ir, long ig, long ib) 118 119 { 119 int i; 120 int i; 120 121 int d0, d1; // closest & next closest distance to input 121 122 int p0, p1; // index into the 256 color table. … … 138 139 139 140 d = DISTANCE(n->r, n->g, n->b, ir, ig, ib); 140 if (d < d0) { 141 if (d < d0) { 141 142 d1 = d0; d0 = d; 142 143 p1 = p0; p0 = i; … … 145 146 d1 = d; 146 147 p1 = i; 147 } 148 } 148 149 } 149 150 … … 183 184 pb = N[p0].pb; 184 185 py->r += (dr >> 2) + (dg >> 1) + (db >> 2); CLAMP_PLUS(py->r); 185 pa->r += (dr >> 2) ; CLAMP_BOTH(pa->r); 186 pa->r += (dr >> 2) ; CLAMP_BOTH(pa->r); 186 187 pa->g += (dg >> 2) ; CLAMP_BOTH(pa->g); 187 188 pa->b += (db >> 2) ; CLAMP_BOTH(pa->b); … … 258 259 259 260 static int order[256]; 260 static int 261 static int 261 262 _nn_randomOrder(const void *a, const void *b) 262 263 { … … 275 276 276 277 _nn_initTables(); 277 /* 278 /* 278 279 * Select a number which is relatively prime to nsamples. 279 280 */ … … 295 296 FxU32 *pRGB; 296 297 297 // We present the samples randomly to the network. 298 // We present the samples randomly to the network. 298 299 // _nn_modify_neurons() makes the neurons learn 299 300 // errR, errG, errB, errMax are computed in _nn_modifyNeurons(), as … … 308 309 309 310 if (errMax < bstMax) { 310 /* 311 /* 311 312 * A lower total error than before, take a Snapshot 312 313 * … … 344 345 bstB = errB; 345 346 #if 0 346 printf("%8d%, dry=%8d, eMax=%8x eMax=%3d%3d%3d eAvg=%3d%3d%3d\n", 347 iterations, drySpells, errMax, 348 errG, errR, errB, 347 printf("%8d%, dry=%8d, eMax=%8x eMax=%3d%3d%3d eAvg=%3d%3d%3d\n", 348 iterations, drySpells, errMax, 349 errG, errR, errB, 349 350 totG/nsamples, totR/nsamples, totB/nsamples 350 351 ); … … 356 357 } 357 358 358 if (errMax == 0) { 359 // printf("******Exact Solution in %d iterations\n", iterations); 360 // _nn_Dump(); 359 if (errMax == 0) { 360 // printf("******Exact Solution in %d iterations\n", iterations); 361 // _nn_Dump(); 361 362 break; 362 363 } 363 364 } 364 365 365 /* 366 /* 366 367 * At this point YAB has the YAB table, samples has input palette, 367 368 * Replace MSB of samples with index to be used with YAB table. … … 393 394 394 395 395 /* 396 * Get a 256 color palette, to be used as samples 396 /* 397 * Get a 256 color palette, to be used as samples 397 398 * Incidentally, convert src 32 bit image to dst 8 bit indexed image, 398 399 * with indices referring to the 256 color palette. … … 403 404 printf("NCC Neural nets..."); fflush(stdout); 404 405 } 405 pxMip->format = (format == GR_TEXFMT_YIQ_422) ? GR_TEXFMT_P_8 : 406 pxMip->format = (format == GR_TEXFMT_YIQ_422) ? GR_TEXFMT_P_8 : 406 407 GR_TEXFMT_AP_88; 407 408 ncolors = txMipPal256(pxMip, txMip, pxMip->format, 0, 0); … … 413 414 if( txVerbose ) 414 415 { 415 printf("eMax=(%3d%3d%3d)...eAvg=(%3d%3d%3d)\n", 416 errG, errR, errB, 416 printf("eMax=(%3d%3d%3d)...eAvg=(%3d%3d%3d)\n", 417 errG, errR, errB, 417 418 totG/ncolors, totR/ncolors, totB/ncolors 418 419 ); … … 423 424 /* 424 425 * At this point, we can lose the 256 color palette, and replace it with 425 * the 256 color palette generated from the YAB table. This will be 426 * the 256 color palette generated from the YAB table. This will be 426 427 * useful for error diffusion dithering. 427 428 */ 428 429 txYABtoPal256((long *)pxMip->pal, (long *)yabTable); 429 430 txDiffuseIndex(pxMip, txMip, pixsize, pxMip->pal, 256); 430 } 431 } 431 432 else { 432 433 -
trunk/src/opengl/glide/cvg/texus/pal256.c
r2888 r6653 1 /* $Id: pal256.c,v 1.2 2001-09-05 14:30:45 bird Exp $ */ 1 2 /* 2 3 * This software is copyrighted as noted below. It may be freely copied, 3 * modified, and redistributed, provided that the copyright notice is 4 * modified, and redistributed, provided that the copyright notice is 4 5 * preserved on all copies. 5 * 6 * 6 7 * There is no warranty or other guarantee of fitness for this software, 7 8 * it is provided solely "as is". Bug reports or fixes may be sent … … 9 10 * 10 11 * You may not include this software in a program or other software product 11 * without supplying the source, or without informing the end-user that the 12 * without supplying the source, or without informing the end-user that the 12 13 * source is available for no extra charge. 13 14 * … … 72 73 * Readability constants. 73 74 */ 74 #define REDI 0 75 #define REDI 0 75 76 #define GREENI 1 76 #define BLUEI 2 77 #define BLUEI 2 77 78 #define TRUE 1 78 79 #define FALSE 0 … … 111 112 * Perform variance-based color quantization on a 24-bit image. 112 113 */ 113 int 114 int 114 115 txMipPal256(TxMip *pxMip, TxMip *txMip, int format, FxU32 dither, FxU32 compression) 115 116 { … … 117 118 int i; /* Counter */ 118 119 int OutColors; /* # of entries computed */ 119 int Colormax; /* quantized full-intensity */ 120 int Colormax; /* quantized full-intensity */ 120 121 float Cfactor; /* Conversion factor */ 121 122 #if 0 … … 131 132 Cfactor = (float)FULLINTENSITY / Colormax; 132 133 133 Boxes = _Boxes; 134 Boxes = _Boxes; 134 135 #if 0 135 136 Histogram = (ulong *) txMalloc(ColormaxI*ColormaxI*ColormaxI * sizeof(long)); … … 157 158 158 159 OutColors = CutBoxes(Boxes, MAXCOLORS); 159 160 160 161 /* 161 162 * We now know the set of representative colors. We now … … 180 181 pxMip->pal[i] = (r<<16) | (g << 8) | b; 181 182 } 182 ComputeRGBMap(Boxes, OutColors, rgbmap); 183 ComputeRGBMap(Boxes, OutColors, rgbmap); 183 184 184 185 /* … … 218 219 *dst++ = rgbmap[index]; 219 220 } else { 220 *(FxU16 *)dst = (rgbmap[index]) | 221 *(FxU16 *)dst = (rgbmap[index]) | 221 222 ((argb >> 16) & 0xFF00); 222 223 dst+= 2; … … 253 254 * We compute both the histogram and the proj. frequencies of 254 255 * the first box at the same time to save a pass through the 255 * entire image. 256 * entire image. 256 257 */ 257 258 258 259 for (i = 0; i < npixels; i++) { 259 260 rr = (uchar) (((*pixels >> 16) & 0xff) >> (8-NBITS)); … … 266 267 Histogram[(((rr<<NBITS)|gg)<<NBITS)|bb]++; 267 268 } 268 269 269 270 } 270 271 … … 273 274 */ 274 275 static int 275 CutBoxes(Box *boxes, int colors) 276 CutBoxes(Box *boxes, int colors) 276 277 { 277 278 int curbox; … … 363 364 * Find 'optimal' cutpoint along each of the red, green and blue 364 365 * axes. Sum the variances of the two boxes which would result 365 * by making each cut and store the resultant boxes for 366 * by making each cut and store the resultant boxes for 366 367 * (possible) later use. 367 368 */ … … 461 462 bzero(box1->freq[0], ColormaxI * sizeof(ulong)); 462 463 bzero(box1->freq[1], ColormaxI * sizeof(ulong)); 463 bzero(box1->freq[2], ColormaxI * sizeof(ulong)); 464 bzero(box1->freq[2], ColormaxI * sizeof(ulong)); 464 465 465 466 for (r = box1->low[0]; r < box1->high[0]; r++) { … … 507 508 { 508 509 int r, g, b; 509 510 510 511 for (r = box->low[REDI]; r < box->high[REDI]; r++) { 511 512 for (g = box->low[GREENI]; g < box->high[GREENI]; g++) { 512 513 for (b = box->low[BLUEI]; b < box->high[BLUEI]; b++) { 513 514 int index; 514 515 515 516 index = (((r<<NBITS)|g)<<NBITS)|b; 516 517 rgbmap[index]=(char)boxnum; … … 528 529 int min_index; 529 530 long r, g, b; 530 531 531 532 min_dist = 256 * 256 + 256 * 256 + 256 * 256; 532 533 min_index = -1; … … 573 574 unsigned long index; 574 575 unsigned long r_index, g_index, b_index; 575 576 576 577 r_index = ( ( ( unsigned long )src[i*4+2] ) >> ( 8 - INVERSE_PAL_R_BITS ) ); 577 578 g_index = ( ( ( unsigned long )src[i*4+1] ) >> ( 8 - INVERSE_PAL_G_BITS ) ); 578 579 b_index = ( ( ( unsigned long )src[i*4+0] ) >> ( 8 - INVERSE_PAL_B_BITS ) ); 579 index = 580 index = 580 581 ( r_index << ( INVERSE_PAL_G_BITS + INVERSE_PAL_B_BITS ) ) | 581 582 ( g_index << INVERSE_PAL_B_BITS ) | … … 618 619 static FxU32 last_pal[256]; 619 620 static FxBool been_here = FXFALSE; 620 621 621 622 w = outputMip->width; 622 623 h = outputMip->height; … … 632 633 } 633 634 634 for( i = 0; i < trueColorMip->depth; i++ ) 635 for( i = 0; i < trueColorMip->depth; i++ ) 635 636 { 636 637 _txImgTrueToFixedPal( outputMip->data[i], trueColorMip->data[i], pal, -
trunk/src/opengl/glide/cvg/texus/ppm.c
r2888 r6653 1 /* $Id: ppm.c,v 1.2 2001-09-05 14:30:46 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:38:00$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:46 $ 23 24 ** 24 25 */ … … 32 33 33 34 34 FxBool 35 FxBool 35 36 _txReadPPMHeader( FILE *stream, FxU32 cookie, TxMip *info) 36 { 37 { 37 38 char buffer[256]; 38 39 FxU32 state = 1; 39 40 FxBool done = FXFALSE; 40 41 41 42 if ( stream == NULL ) { 42 txPanic("PPM file: Bad file handle.");43 return FXFALSE;43 txPanic("PPM file: Bad file handle."); 44 return FXFALSE; 44 45 } 45 46 46 47 while( !done && fgets( buffer, 256, stream ) ) { 47 char *token; 48 49 if ( buffer[0] == '#' ) continue; 50 for (token = strtok( buffer, " \t\n\r" ); token != NULL; 51 token = strtok( NULL, " \t\n\r" )) { 52 switch( state ) { 53 case 1: // Width 54 info->width = atoi( token ); 55 state++; 56 break; 48 char *token; 57 49 58 case 2: // height 59 info->height = atoi( token ); 60 state++; 61 break; 50 if ( buffer[0] == '#' ) continue; 51 for (token = strtok( buffer, " \t\n\r" ); token != NULL; 52 token = strtok( NULL, " \t\n\r" )) { 53 switch( state ) { 54 case 1: // Width 55 info->width = atoi( token ); 56 state++; 57 break; 62 58 63 case 3: // Color Depth 64 info->format = atoi( token ); 65 if ( info->format != 255 ) { 66 txPanic("Unsupported PPM format: max != 255\n"); 67 return FXFALSE; 68 } 69 state++; 70 done = FXTRUE; 71 break; 59 case 2: // height 60 info->height = atoi( token ); 61 state++; 62 break; 72 63 73 default: 74 txPanic("PPM file: parse error\n"); 75 return FXFALSE; 76 break; 77 } 78 } 64 case 3: // Color Depth 65 info->format = atoi( token ); 66 if ( info->format != 255 ) { 67 txPanic("Unsupported PPM format: max != 255\n"); 68 return FXFALSE; 69 } 70 state++; 71 done = FXTRUE; 72 break; 73 74 default: 75 txPanic("PPM file: parse error\n"); 76 return FXFALSE; 77 break; 78 } 79 79 } 80 80 } 81 81 82 if ( state < 4 ) { 82 txPanic("PPM file: Read error before end of header.");83 return FXFALSE;83 txPanic("PPM file: Read error before end of header."); 84 return FXFALSE; 84 85 } 85 86 info->depth = 1; … … 89 90 } 90 91 91 FxBool 92 _txReadPPMData( FILE *stream, TxMip *info) 93 { 92 FxBool 93 _txReadPPMData( FILE *stream, TxMip *info) 94 { 94 95 FxU32 numPixels; 95 96 FxU32 *data32 = info->data[0]; 96 97 97 98 numPixels = info->width * info->height; 98 99 99 100 if ( stream == NULL ) { 100 txPanic("PPM file: Bad file handle.");101 return FXFALSE;101 txPanic("PPM file: Bad file handle."); 102 return FXFALSE; 102 103 } 103 104 104 105 // Read in image data 105 106 while (numPixels--) { 106 int r, g, b;107 int r, g, b; 107 108 108 r = getc( stream );109 g = getc( stream );110 b = getc( stream );111 if ( b == EOF ) {112 txPanic("PPM file: Unexpected End of File.");113 return FXFALSE;114 }115 *data32++ = (0xFF << 24) | (r << 16) | (g << 8) | b;109 r = getc( stream ); 110 g = getc( stream ); 111 b = getc( stream ); 112 if ( b == EOF ) { 113 txPanic("PPM file: Unexpected End of File."); 114 return FXFALSE; 115 } 116 *data32++ = (0xFF << 24) | (r << 16) | (g << 8) | b; 116 117 } 117 118 return FXTRUE; -
trunk/src/opengl/glide/cvg/texus/quantize.c
r2888 r6653 1 /* $Id: quantize.c,v 1.2 2001-09-05 14:30:46 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:38:00$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:46 $ 23 24 */ 24 25 … … 30 31 #include "texusint.h" 31 32 32 static int 33 dithmat[4][4] = { 0, 8, 2, 10, 34 12, 4, 14, 6, 35 3, 11, 1, 9, 33 static int 34 dithmat[4][4] = { 0, 8, 2, 10, 35 12, 4, 14, 6, 36 3, 11, 1, 9, 36 37 15, 7, 13, 5 }; 37 38 38 39 // for error diffusion. 39 static int errR[MAX_TEXWIDTH], errG[MAX_TEXWIDTH], errB[MAX_TEXWIDTH]; 40 static int errR[MAX_TEXWIDTH], errG[MAX_TEXWIDTH], errB[MAX_TEXWIDTH]; 40 41 41 42 static int … … 54 55 int n, t; 55 56 56 n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d; 57 n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d; 57 58 t = (n>>4)<<5; 58 n = (int) (((argb >> 8) & 0xFF) * 0x70/255.0f + 0.5f) + d; 59 n = (int) (((argb >> 8) & 0xFF) * 0x70/255.0f + 0.5f) + d; 59 60 t |= (n>>4)<<2; 60 n = (int) (((argb ) & 0xFF) * 0x30/255.0f + 0.5f) + d; 61 n = (int) (((argb ) & 0xFF) * 0x30/255.0f + 0.5f) + d; 61 62 t |= (n>>4)<<0; 62 63 return t & 0xFF; … … 82 83 ib += errB[x] + qb; 83 84 84 qr = ir; // quantized pixel values. 85 qr = ir; // quantized pixel values. 85 86 qg = ig; // qR is error from pixel to left, errR is 86 87 qb = ib; // error from pixel to the top & top left. … … 157 158 158 159 159 n = (int) (n * 0xF0/255.0f + 0.5f) + d; 160 n = (int) (n * 0xF0/255.0f + 0.5f) + d; 160 161 t = (n>>4); 161 162 t |= (int) ((argb>>24) & 0xF0); … … 215 216 int n, t; 216 217 217 n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d; 218 n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d; 218 219 t = (n>>4)<<5; 219 n = (int) (((argb >> 8) & 0xFF) * 0x70/255.0f + 0.5f) + d; 220 n = (int) (((argb >> 8) & 0xFF) * 0x70/255.0f + 0.5f) + d; 220 221 t |= (n>>4)<<2; 221 n = (int) (((argb ) & 0xFF) * 0x30/255.0f + 0.5f) + d; 222 n = (int) (((argb ) & 0xFF) * 0x30/255.0f + 0.5f) + d; 222 223 t |= (n>>4)<<0; 223 224 t |= ((argb >> 16) & 0xFF00); … … 252 253 int n, t; 253 254 254 n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 255 n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 255 256 t = (n>>4)<<11; 256 n = (int) (((argb >> 8) & 0xFF) * 0x3F0/255.0f + 0.5f) + d; 257 n = (int) (((argb >> 8) & 0xFF) * 0x3F0/255.0f + 0.5f) + d; 257 258 t |= (n>>4)<<5; 258 n = (int) (((argb ) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 259 n = (int) (((argb ) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 259 260 t |= (n>>4)<<0; 260 261 return t & 0xFFFF; … … 279 280 ib += errB[x] + qb; 280 281 281 qr = ir; // quantized pixel values. 282 qr = ir; // quantized pixel values. 282 283 qg = ig; // qR is error from pixel to left, errR is 283 284 qb = ib; // error from pixel to the top & top left. … … 324 325 ((argb >> 9) & 0x7C00) | 325 326 ((argb >> 6) & 0x03E0) | 326 ((argb >> 3) & 0x001F) | 327 ((argb >> 3) & 0x001F) | 327 328 ((argb >> 24) ? 0x8000 : 0) ); 328 329 } … … 334 335 int n, t; 335 336 336 n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 337 n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 337 338 t = (n>>4)<<10; 338 n = (int) (((argb >> 8) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 339 n = (int) (((argb >> 8) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 339 340 t |= (n>>4)<<5; 340 n = (int) (((argb ) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 341 n = (int) (((argb ) & 0xFF) * 0x1F0/255.0f + 0.5f) + d; 341 342 t |= (n>>4)<<0; 342 343 t |= ((argb >> 24) ? 0x8000 : 0); … … 361 362 ib += errB[x] + qb; 362 363 363 qr = ir; // quantized pixel values. 364 qr = ir; // quantized pixel values. 364 365 qg = ig; // qR is error from pixel to left, errR is 365 366 qb = ib; // error from pixel to the top & top left. … … 407 408 ((argb >> 12) & 0x0F00) | 408 409 ((argb >> 8) & 0x00F0) | 409 ((argb >> 4) & 0x000F) | 410 ((argb >> 4) & 0x000F) | 410 411 ((argb >> 16) & 0xF000) ); 411 412 } … … 417 418 int n, t; 418 419 419 n = (int) (((argb >> 16) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 420 n = (int) (((argb >> 16) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 420 421 t = (n>>4)<<8; 421 n = (int) (((argb >> 8) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 422 n = (int) (((argb >> 8) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 422 423 t |= (n>>4)<<4; 423 n = (int) (((argb ) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 424 n = (int) (((argb ) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 424 425 t |= (n>>4)<<0; 425 426 t |= (argb >> 16) & 0xF000; … … 444 445 ib += errB[x] + qb; 445 446 446 qr = ir; // quantized pixel values. 447 qr = ir; // quantized pixel values. 447 448 qg = ig; // qR is error from pixel to left, errR is 448 449 qb = ib; // error from pixel to the top & top left. … … 511 512 512 513 switch(format) { 513 case GR_TEXFMT_RGB_332: quantizer = _txPixQuantize_RGB332_DErr; 514 break; 515 case GR_TEXFMT_A_8: quantizer = _txPixQuantize_A8; 514 case GR_TEXFMT_RGB_332: quantizer = _txPixQuantize_RGB332_DErr; 515 break; 516 case GR_TEXFMT_A_8: quantizer = _txPixQuantize_A8; 516 517 break; 517 518 case GR_TEXFMT_I_8: quantizer = _txPixQuantize_I8; … … 521 522 case GR_TEXFMT_ARGB_8332: quantizer = _txPixQuantize_ARGB8332_DErr; 522 523 break; 523 case GR_TEXFMT_RGB_565: quantizer = _txPixQuantize_RGB565_DErr; 524 case GR_TEXFMT_RGB_565: quantizer = _txPixQuantize_RGB565_DErr; 524 525 break; 525 526 case GR_TEXFMT_ARGB_1555: quantizer = _txPixQuantize_ARGB1555_DErr; … … 535 536 536 537 switch(format) { 537 case GR_TEXFMT_RGB_332: quantizer = _txPixQuantize_RGB332_D4x4; 538 break; 539 case GR_TEXFMT_A_8: quantizer = _txPixQuantize_A8; 540 break; 541 case GR_TEXFMT_I_8: quantizer = _txPixQuantize_I8; 542 break; 543 case GR_TEXFMT_AI_44: quantizer = _txPixQuantize_AI44_D4x4; 544 break; 545 546 case GR_TEXFMT_ARGB_8332: quantizer = _txPixQuantize_ARGB8332_D4x4; 547 break; 548 case GR_TEXFMT_RGB_565: quantizer = _txPixQuantize_RGB565_D4x4; 549 break; 550 case GR_TEXFMT_ARGB_1555: quantizer = _txPixQuantize_ARGB1555_D4x4; 551 break; 552 case GR_TEXFMT_ARGB_4444: quantizer = _txPixQuantize_ARGB4444_D4x4; 553 break; 554 case GR_TEXFMT_AI_88: quantizer = _txPixQuantize_AI88; 555 break; 556 557 default: txPanic("Bad case in txQuantize()\n"); 538 case GR_TEXFMT_RGB_332: quantizer = _txPixQuantize_RGB332_D4x4; 539 break; 540 case GR_TEXFMT_A_8: quantizer = _txPixQuantize_A8; 541 break; 542 case GR_TEXFMT_I_8: quantizer = _txPixQuantize_I8; 543 break; 544 case GR_TEXFMT_AI_44: quantizer = _txPixQuantize_AI44_D4x4; 545 break; 546 547 case GR_TEXFMT_ARGB_8332: quantizer = _txPixQuantize_ARGB8332_D4x4; 548 break; 549 case GR_TEXFMT_RGB_565: quantizer = _txPixQuantize_RGB565_D4x4; 550 break; 551 case GR_TEXFMT_ARGB_1555: quantizer = _txPixQuantize_ARGB1555_D4x4; 552 break; 553 case GR_TEXFMT_ARGB_4444: quantizer = _txPixQuantize_ARGB4444_D4x4; 554 break; 555 case GR_TEXFMT_AI_88: quantizer = _txPixQuantize_AI88; 556 break; 557 558 default: txPanic("Bad case in txQuantize()\n"); 558 559 break; 559 560 } … … 561 562 562 563 switch(format) { 563 case GR_TEXFMT_RGB_332: quantizer = _txPixQuantize_RGB332; 564 break; 565 case GR_TEXFMT_A_8: quantizer = _txPixQuantize_A8; 566 break; 567 case GR_TEXFMT_I_8: quantizer = _txPixQuantize_I8; 568 break; 569 case GR_TEXFMT_AI_44: quantizer = _txPixQuantize_AI44; 570 break; 571 572 case GR_TEXFMT_ARGB_8332: quantizer = _txPixQuantize_ARGB8332; 573 break; 574 case GR_TEXFMT_RGB_565: quantizer = _txPixQuantize_RGB565; 575 break; 576 case GR_TEXFMT_ARGB_1555: quantizer = _txPixQuantize_ARGB1555; 577 break; 578 case GR_TEXFMT_ARGB_4444: quantizer = _txPixQuantize_ARGB4444; 579 break; 580 case GR_TEXFMT_AI_88: quantizer = _txPixQuantize_AI88; 581 break; 582 583 default: txPanic("Bad case in txQuantize()\n"); 564 case GR_TEXFMT_RGB_332: quantizer = _txPixQuantize_RGB332; 565 break; 566 case GR_TEXFMT_A_8: quantizer = _txPixQuantize_A8; 567 break; 568 case GR_TEXFMT_I_8: quantizer = _txPixQuantize_I8; 569 break; 570 case GR_TEXFMT_AI_44: quantizer = _txPixQuantize_AI44; 571 break; 572 573 case GR_TEXFMT_ARGB_8332: quantizer = _txPixQuantize_ARGB8332; 574 break; 575 case GR_TEXFMT_RGB_565: quantizer = _txPixQuantize_RGB565; 576 break; 577 case GR_TEXFMT_ARGB_1555: quantizer = _txPixQuantize_ARGB1555; 578 break; 579 case GR_TEXFMT_ARGB_4444: quantizer = _txPixQuantize_ARGB4444; 580 break; 581 case GR_TEXFMT_AI_88: quantizer = _txPixQuantize_AI88; 582 break; 583 584 default: txPanic("Bad case in txQuantize()\n"); 584 585 break; 585 586 } … … 614 615 * quality levels in each of the compression cases. 615 616 */ 616 void 617 void 617 618 txMipQuantize(TxMip *pxMip, TxMip *txMip, int format, FxU32 dither, FxU32 compression) 618 619 { … … 636 637 return; 637 638 638 case GR_TEXFMT_ARGB_8888: 639 case GR_TEXFMT_ARGB_8888: 639 640 // Copy source to destination, and be done. 640 641 if( txVerbose ) … … 651 652 652 653 // Normal cases 653 case GR_TEXFMT_A_8: 654 case GR_TEXFMT_I_8: 655 case GR_TEXFMT_AI_44: 654 case GR_TEXFMT_A_8: 655 case GR_TEXFMT_I_8: 656 case GR_TEXFMT_AI_44: 656 657 case GR_TEXFMT_RGB_332: 657 case GR_TEXFMT_RGB_565: 658 case GR_TEXFMT_ARGB_8332: 659 case GR_TEXFMT_ARGB_1555: 658 case GR_TEXFMT_RGB_565: 659 case GR_TEXFMT_ARGB_8332: 660 case GR_TEXFMT_ARGB_1555: 660 661 case GR_TEXFMT_ARGB_4444: 661 662 case GR_TEXFMT_AI_88: -
trunk/src/opengl/glide/cvg/texus/read.c
r2888 r6653 1 /* $Id: read.c,v 1.2 2001-09-05 14:30:46 bird Exp $ */ 1 2 /* 2 3 ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 ** 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 12 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 12 13 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 14 15 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 15 16 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 16 ** THE UNITED STATES. 17 ** 17 ** THE UNITED STATES. 18 ** 18 19 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 19 20 ** 20 ** $Revision: 1. 1$21 ** $Date: 200 0-02-25 00:38:00$21 ** $Revision: 1.2 $ 22 ** $Date: 2001-09-05 14:30:46 $ 22 23 */ 23 24 … … 38 39 #define TX_UNK 0x200 // TGA is unknown from cookie signature. 39 40 40 int 41 int 41 42 _txReadHeader( FILE *stream, TxMip *info ) 42 43 { … … 86 87 } 87 88 88 static FxBool 89 static FxBool 89 90 _txReadData( FILE *stream, int fformat, TxMip *info ) 90 91 { … … 109 110 110 111 file = fopen(filename, "rb"); 111 if( file == NULL ) 112 if( file == NULL ) 112 113 { 113 114 fprintf( stderr,"Error: can't open input file %s\n", filename ); 114 115 exit(2); 115 116 } 116 117 117 118 retval = txMipReadFromFP( txMip, filename, file, prefFormat ); 118 119 fclose(file); … … 128 129 129 130 if ((prefFormat != GR_TEXFMT_ARGB_8888) && 130 (prefFormat != GR_TEXFMT_ANY)) 131 (prefFormat != GR_TEXFMT_ANY)) 131 132 { 132 133 txPanic("txMipRead: bad preferred format."); … … 143 144 fprintf(stderr,"Loading image file "); 144 145 145 fprintf (stderr,"%s (%dw x %dh x %d Bpp x %d mips) .. ", debug_filename, 146 fprintf (stderr,"%s (%dw x %dh x %d Bpp x %d mips) .. ", debug_filename, 146 147 txMip->width,txMip->height, GR_TEXFMT_SIZE(txMip->format), txMip->depth); 147 148 } 148 149 149 150 /* 150 * Allocate memory requested in data[0]; 151 * Allocate memory requested in data[0]; 151 152 */ 152 153 … … 159 160 continue; 160 161 } 161 txMip->data[i] = (FxU8*)txMip->data[i-1] + 162 txMip->data[i] = (FxU8*)txMip->data[i-1] + 162 163 w * h * GR_TEXFMT_SIZE(txMip->format); 163 164 if (w > 1) w >>= 1; … … 166 167 167 168 if( txVerbose ) { 168 fprintf( stderr, "mip-> format: %d width: %d height: %d depth: %d size: %d\n",169 txMip->format, txMip->width, txMip->height, txMip->depth,170 txMip->size );171 fflush( stderr );169 fprintf( stderr, "mip-> format: %d width: %d height: %d depth: %d size: %d\n", 170 txMip->format, txMip->width, txMip->height, txMip->depth, 171 txMip->size ); 172 fflush( stderr ); 172 173 } 173 174 … … 195 196 if( txVerbose ) 196 197 { 197 fprintf(stderr, "Dequantizing Input from %s to argb8888.\n", 198 fprintf(stderr, "Dequantizing Input from %s to argb8888.\n", 198 199 Format_Name[txMip->format]); 199 200 } -
trunk/src/opengl/glide/cvg/texus/resample.c
r2888 r6653 1 /* $Id: resample.c,v 1.2 2001-09-05 14:30:46 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:38:00$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:46 $ 23 24 */ 24 25 … … 38 39 * total of ox * ix fragments, same as before. 39 40 * Initialize an accumulator to 0. Add the first input pixel, multiplied by ox 40 * the number of fragments per input pixel. Keep track of the number of 41 * the number of fragments per input pixel. Keep track of the number of 41 42 * fragments in the accumulator; when this is >= ix, (the number of fragments 42 * it takes to make an output pixel), multiply the accumulator by 43 * it takes to make an output pixel), multiply the accumulator by 43 44 */ 44 45 … … 65 66 int oa, or, og, ob; 66 67 67 // Yes, we have (possibly more than) enough to generate an output 68 // pixel. Of the nf new fragments, use up enough to generate an 68 // Yes, we have (possibly more than) enough to generate an output 69 // pixel. Of the nf new fragments, use up enough to generate an 69 70 // output pixel. 70 71 71 72 ef = ix - accf; // the excessive # of fragments. 72 73 73 // printf("New: accf = %3d, nf = %3d, ef = %3d, ix = %3d, ox = %3d\n", 74 // printf("New: accf = %3d, nf = %3d, ef = %3d, ix = %3d, ox = %3d\n", 74 75 // accf, nf, ef, ix, ox); 75 76 … … 94 95 95 96 *out++ = (oa << 24) | (or << 16) | (og << 8) | ob; 96 // printf("Output pixel %4d: %.02x %.02x %.02x %.02x\n", 97 // printf("Output pixel %4d: %.02x %.02x %.02x %.02x\n", 97 98 // o, oa, or, og, ob); 98 99 o++; … … 124 125 125 126 static void 126 _txImgResample(FxU32 *out, int ox, int oy, 127 _txImgResample(FxU32 *out, int ox, int oy, 127 128 const FxU32 *in, int ix, int iy) 128 129 { … … 147 148 int ef; 148 149 149 // Yes, we have (possibly more than) enough to generate an output 150 // pixel. Of the nf new fragments, use up enough to generate an 150 // Yes, we have (possibly more than) enough to generate an output 151 // pixel. Of the nf new fragments, use up enough to generate an 151 152 // output pixel. 152 153 … … 243 244 printf("Resampling to %dx%d: ", destMip->width, destMip->height); 244 245 245 246 246 247 sw = srcMip->width; 247 248 sh = srcMip->height; -
trunk/src/opengl/glide/cvg/texus/rgt.c
r2888 r6653 1 /* $Id: rgt.c,v 1.2 2001-09-05 14:30:46 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:38:00$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:46 $ 23 24 ** 24 25 */ … … 36 37 const FxU16 ITYPE_BGR = 0x04; 37 38 const FxU16 ITYPE_RGT = 0x08; 38 39 39 40 typedef struct _rgtHeader{ 40 41 FxU16 magic; … … 67 68 while (length--) { 68 69 s = *array; 69 *array++ = (s << 24) | ((s >> 8)&0xFF00) | 70 *array++ = (s << 24) | ((s >> 8)&0xFF00) | 70 71 ((s&0xFF00) << 8) | (s>>24); 71 72 } … … 83 84 84 85 85 FxBool 86 FxBool 86 87 _txReadRGTHeader( FILE *stream, FxU32 cookie, TxMip *info) 87 88 { … … 93 94 return FXFALSE; 94 95 } 95 96 96 97 if ( fread( &(rgtHeader->typeLo), 1, sizeof(RgtHeader)-2, stream ) != 10 ) { 97 98 txPanic("RGT file: Unexpected end of file."); … … 104 105 105 106 106 info->format = GR_TEXFMT_ARGB_8888; 107 info->format = GR_TEXFMT_ARGB_8888; 107 108 info->width = rgtHeader->sizeXHi << 8 | rgtHeader->sizeXLo; 108 109 info->height = rgtHeader->sizeYHi << 8 | rgtHeader->sizeYLo; … … 111 112 if( txVerbose ) 112 113 { 113 printf("Magic: %.04x w = %d, h = %d, z = %d, typehi = %d, typelo = %d, swap=%d\n", rgtHeader->magic, 114 printf("Magic: %.04x w = %d, h = %d, z = %d, typehi = %d, typelo = %d, swap=%d\n", rgtHeader->magic, 114 115 info->width, info->height, rgtHeader->sizeZLo, rgtHeader->typeHi, rgtHeader->typeLo, rgtHeader->magic == IMAGIC); 115 116 } … … 119 120 // RGT is RGBA in memory (low byte to high byte), or ABGR in a register 120 121 121 FxBool 122 FxBool 122 123 _txReadRGTData( FILE *stream, TxMip *info) 123 124 { 124 125 RgtHeader *rgtHeader = (RgtHeader *) info->pal; 125 126 FxU16 type = (rgtHeader->typeHi); 126 FxU16 swap = (rgtHeader->magic == IMAGIC); 127 FxU16 swap = (rgtHeader->magic == IMAGIC); 127 128 int x, y; 128 129 129 130 if ( stream == NULL ) { 130 131 txPanic("RGT file: Bad file handle."); … … 139 140 return FXFALSE; 140 141 } 141 142 142 143 // load rgt, rgt's are bottom up 143 144 for ( y = 0; y < info->height; y++ ) { -
trunk/src/opengl/glide/cvg/texus/texuslib.c
r2888 r6653 1 /* $Id: texuslib.c,v 1.2 2001-09-05 14:30:47 bird Exp $ */ 1 2 /* 2 3 ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 ** 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 12 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 12 13 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 14 15 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 15 16 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 16 ** THE UNITED STATES. 17 ** 17 ** THE UNITED STATES. 18 ** 18 19 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 19 20 ** 20 ** $Id: texuslib.c,v 1. 1 2000-02-25 00:38:01 sandervlExp $21 ** $Id: texuslib.c,v 1.2 2001-09-05 14:30:47 bird Exp $ 21 22 */ 22 23 #include <string.h> … … 59 60 60 61 /* size in texels */ 61 static FxU32 _grMipMapHostSize[4][16] = 62 static FxU32 _grMipMapHostSize[4][16] = 62 63 { 63 64 { /* 1:1 aspect ratio */ … … 71 72 4, /* 7 : 2x2 */ 72 73 1, /* 8 : 1x1 */ 73 }, 74 }, 74 75 { /* 2:1 aspect ratio */ 75 76 32768, /* 0 : 256x128 */ … … 82 83 2, /* 7 : 2x1 */ 83 84 1, /* 8 : 1x1 */ 84 }, 85 }, 85 86 { /* 4:1 aspect ratio */ 86 87 16384, /* 0 : 256x64 */ … … 129 130 #else 130 131 _grMipMapHostSize[_gr_aspect_index_table[aspect]] [lod] << (format>=GR_TEXFMT_16BIT); 131 #endif 132 #endif 132 133 } 133 134 return memRequired ; … … 296 297 } 297 298 298 void txNccToPal( FxU32 *pal, const GuNccTable *ncc_table ) 299 void txNccToPal( FxU32 *pal, const GuNccTable *ncc_table ) 299 300 { 300 301 int i, j; … … 304 305 pal[i] = ncc_table->yRGB[i]; 305 306 } 306 307 307 308 for( i = 0; i < 4; i++ ) 308 309 { … … 322 323 ncc_table->yRGB[i] = ( FxU8 )pal[i]; 323 324 } 324 325 325 326 for( i = 0; i < 4; i++ ) 326 327 { … … 331 332 } 332 333 } 333 334 334 335 /* 335 336 ** pack the table Y entries … … 338 339 { 339 340 FxU32 packedvalue; 340 341 341 342 packedvalue = ( ( FxU32 )( ncc_table->yRGB[i*4+0] & 0xff ) ); 342 343 packedvalue |= ( ( FxU32 )( ncc_table->yRGB[i*4+1] & 0xff ) ) << 8; … … 346 347 ncc_table->packed_data[i] = packedvalue; 347 348 } 348 349 349 350 /* 350 351 ** pack the table I entries … … 353 354 { 354 355 FxU32 packedvalue; 355 356 356 357 packedvalue = ( ( FxU32 )( ncc_table->iRGB[i][0] & 0x1ff ) ) << 18; 357 358 packedvalue |= ( ( FxU32 )( ncc_table->iRGB[i][1] & 0x1ff ) ) << 9; 358 359 359 360 packedvalue |= ( ( FxU32 )( ncc_table->iRGB[i][2] & 0x1ff ) ) << 0; 360 361 361 362 ncc_table->packed_data[i+4] = packedvalue; 362 363 } 363 364 364 365 /* 365 366 ** pack the table Q entries … … 368 369 { 369 370 FxU32 packedvalue; 370 371 371 372 packedvalue = ( ( FxU32 )( ncc_table->qRGB[i][0] & 0x1ff ) ) << 18; 372 373 packedvalue |= ( ( FxU32 )( ncc_table->qRGB[i][1] & 0x1ff ) ) << 9;; 373 374 packedvalue |= ( ( FxU32 )( ncc_table->qRGB[i][2] & 0x1ff ) ) << 0; 374 375 375 376 ncc_table->packed_data[i+8] = packedvalue; 376 377 } 377 378 } 378 379 379 size_t txInit3dfInfoFromFile( FILE *file, 380 size_t txInit3dfInfoFromFile( FILE *file, 380 381 Gu3dfInfo *info, GrTextureFormat_t destFormat, 381 382 int *destWidth, int *destHeight, … … 415 416 416 417 /* 417 * Set the file offset back to where it was when we entered this 418 * Set the file offset back to where it was when we entered this 418 419 * function. 419 420 */ 420 421 fseek( file, file_start_position, SEEK_SET ); 421 422 422 423 /* 423 424 * Return the memory required for this texture. … … 452 453 *destHeight = txCeilPow2( *destHeight ); 453 454 } 454 455 455 456 /* 456 457 * Make sure the dimensions are in range. … … 520 521 */ 521 522 info->header.format = destFormat; 522 523 523 524 info->mem_required = txTexCalcMemRequired( info->header.small_lod, 524 525 info->header.large_lod, … … 534 535 535 536 536 FxBool txConvertFromFile( FILE *file, Gu3dfInfo *info, 537 FxBool txConvertFromFile( FILE *file, Gu3dfInfo *info, 537 538 FxU32 flags, const void *palNcc ) 538 539 { … … 540 541 FxBool retval; 541 542 TxMip txMip; 542 543 543 544 /* 544 545 * Save the current position of the input file so that we can … … 609 610 610 611 /* 611 * Set to one level only since we only want to dequant the first 612 * Set to one level only since we only want to dequant the first 612 613 * level. 613 614 */ … … 620 621 621 622 /* 622 * We realy have more than one level, so. . . 623 * We realy have more than one level, so. . . 623 624 */ 624 625 #ifdef GLIDE3 … … 633 634 634 635 /* 635 * Resample the true color version of the input image to 636 * Resample the true color version of the input image to 636 637 * the passed in size. . . . this should be a valid 637 638 * size for the hardware to handle. … … 653 654 #endif 654 655 } 655 656 656 657 657 658 #if 0 658 659 if( _heapchk() != _HEAPOK ) … … 691 692 txMipSetMipPointers( &outputMip ); 692 693 #endif 693 694 694 695 if( ( flags & TX_TARGET_PALNCC_MASK ) == TX_TARGET_PALNCC_SOURCE ) 695 696 { 696 txMipTrueToFixedPal( &outputMip, &trueColorMip, palNcc, 697 txMipTrueToFixedPal( &outputMip, &trueColorMip, palNcc, 697 698 flags & TX_FIXED_PAL_QUANT_MASK ); 698 699 } 699 700 else 700 701 { 701 txMipQuantize( &outputMip, &trueColorMip, outputMip.format, 702 txMipQuantize( &outputMip, &trueColorMip, outputMip.format, 702 703 flags & TX_DITHER_MASK, flags & TX_COMPRESSION_MASK ); 703 704 } … … 710 711 txPalToNcc( &info->table.nccTable, outputMip.pal ); 711 712 } 712 713 713 714 if( info->header.format == GR_TEXFMT_P_8 || info->header.format == GR_TEXFMT_AP_88 ) 714 715 { -
trunk/src/opengl/glide/cvg/texus/tga.c
r2888 r6653 1 /* $Id: tga.c,v 1.2 2001-09-05 14:30:47 bird Exp $ */ 1 2 /* 2 3 ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 ** 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 12 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 12 13 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 14 15 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 15 16 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 16 ** THE UNITED STATES. 17 ** 17 ** THE UNITED STATES. 18 ** 18 19 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 19 20 ** 20 ** $Revision: 1. 1$21 ** $Date: 200 0-02-25 00:38:01$21 ** $Revision: 1.2 $ 22 ** $Date: 2001-09-05 14:30:47 $ 22 23 */ 23 24 … … 52 53 53 54 /* Definitions for image types. */ 54 #define TGA_NULL 055 #define TGA_CMAP 156 #define TGA_TRUE 257 #define TGA_MONO 358 #define TGA_CMAP_RLE 959 #define TGA_TRUE_RLE 1060 #define TGA_MONO_RLE 1155 #define TGA_NULL 0 56 #define TGA_CMAP 1 57 #define TGA_TRUE 2 58 #define TGA_MONO 3 59 #define TGA_CMAP_RLE 9 60 #define TGA_TRUE_RLE 10 61 #define TGA_MONO_RLE 11 61 62 62 63 FxBool 63 64 _txReadTGAHeader( FILE *stream, FxU32 cookie, TxMip *info) 64 65 { 65 TgaHeader *tgaHeader = (TgaHeader *) info->pal;66 int i;67 68 // Fill up rest of the TGA header. 69 if ( fread( &(tgaHeader->ImgType), 1, sizeof(TgaHeader)-2, stream ) != 70 sizeof(TgaHeader)-2) {71 txPanic("Unexpected end of file.");72 return FXFALSE;73 } 74 tgaHeader->IDLength = (FxU8) ((cookie >> 8) & 0xFF);66 TgaHeader *tgaHeader = (TgaHeader *) info->pal; 67 int i; 68 69 // Fill up rest of the TGA header. 70 if ( fread( &(tgaHeader->ImgType), 1, sizeof(TgaHeader)-2, stream ) != 71 sizeof(TgaHeader)-2) { 72 txPanic("Unexpected end of file."); 73 return FXFALSE; 74 } 75 tgaHeader->IDLength = (FxU8) ((cookie >> 8) & 0xFF); 75 76 tgaHeader->CMapType = (FxU8) ((cookie ) & 0xFF); 76 77 77 78 // Optionally, skip the image id fields. 78 79 for (i= (tgaHeader->IDLength) & 0xFF; i; i--) { 79 intc;80 81 if ((c = getc(stream)) == EOF) {82 txPanic("Unexpected EOF.");83 return FXFALSE;84 }80 int c; 81 82 if ((c = getc(stream)) == EOF) { 83 txPanic("Unexpected EOF."); 84 return FXFALSE; 85 } 85 86 } 86 87 … … 91 92 92 93 if ((info->width <= 0) || (info->height <= 0)) { 93 txError("TGA Image: width or height is 0.");94 return FXFALSE;94 txError("TGA Image: width or height is 0."); 95 return FXFALSE; 95 96 } 96 97 97 98 switch(tgaHeader->ImgType) { 98 99 case TGA_MONO: 99 case TGA_MONO_RLE: // True color image.100 if (tgaHeader->PixelDepth != 8) {101 txError("TGA Image: Mono image is not 8 bits/pixel.");102 return FXFALSE;103 }104 info->format = GR_TEXFMT_I_8;105 break;100 case TGA_MONO_RLE: // True color image. 101 if (tgaHeader->PixelDepth != 8) { 102 txError("TGA Image: Mono image is not 8 bits/pixel."); 103 return FXFALSE; 104 } 105 info->format = GR_TEXFMT_I_8; 106 break; 106 107 107 108 case TGA_TRUE: 108 109 case TGA_TRUE_RLE: 109 switch (tgaHeader->PixelDepth ) {110 case 15:111 case 16:112 info->format = GR_TEXFMT_ARGB_1555; break;113 case 24:114 case 32:115 info->format = GR_TEXFMT_ARGB_8888; break;116 default:117 txError("TGA Image: True color image is not 24/32 bits/pixel.");118 return FXFALSE;119 break;120 }121 break;122 110 switch (tgaHeader->PixelDepth ) { 111 case 15: 112 case 16: 113 info->format = GR_TEXFMT_ARGB_1555; break; 114 case 24: 115 case 32: 116 info->format = GR_TEXFMT_ARGB_8888; break; 117 default: 118 txError("TGA Image: True color image is not 24/32 bits/pixel."); 119 return FXFALSE; 120 break; 121 } 122 break; 123 123 124 case TGA_CMAP: 124 case TGA_CMAP_RLE: // Color mapped image.125 if ( tgaHeader->CMapType != 1 ) {126 txError("TGA Image: Color-mapped TGA image has no palette");127 return FXFALSE;128 }129 if (((tgaHeader->CMapLengthLo + tgaHeader->CMapLengthHi * 256L)130 +(tgaHeader->CMapStartLo + tgaHeader->CMapStartHi * 256L)) > 256){131 txError("TGA Image: Color-mapped image has > 256 colors");132 return FXFALSE;133 }134 info->format = GR_TEXFMT_P_8;135 break;125 case TGA_CMAP_RLE: // Color mapped image. 126 if ( tgaHeader->CMapType != 1 ) { 127 txError("TGA Image: Color-mapped TGA image has no palette"); 128 return FXFALSE; 129 } 130 if (((tgaHeader->CMapLengthLo + tgaHeader->CMapLengthHi * 256L) 131 +(tgaHeader->CMapStartLo + tgaHeader->CMapStartHi * 256L)) > 256){ 132 txError("TGA Image: Color-mapped image has > 256 colors"); 133 return FXFALSE; 134 } 135 info->format = GR_TEXFMT_P_8; 136 break; 136 137 137 138 default: 138 txError("TGA Image: unsupported format");139 return FXFALSE;139 txError("TGA Image: unsupported format"); 140 return FXFALSE; 140 141 } 141 142 info->size = info->width*info->height*GR_TEXFMT_SIZE(info->format); … … 147 148 _txReadTGAColorMap(FILE *stream, const TgaHeader *tgaHeader, FxU32 *palette) 148 149 { 149 int cmapStart;150 int cmapLength;151 int cmapDepth;152 int i;150 int cmapStart; 151 int cmapLength; 152 int cmapDepth; 153 int i; 153 154 154 155 cmapStart = tgaHeader->CMapStartLo; … … 160 161 cmapDepth = tgaHeader->CMapDepth; 161 162 162 if (tgaHeader->CMapType == 0) return FXTRUE; // no colormap.163 if (tgaHeader->CMapType == 0) return FXTRUE; // no colormap. 163 164 164 165 /* Validate some parameters */ 165 166 if (cmapStart < 0) { 166 txError("TGA Image: Bad Color Map start value.");167 return FXFALSE;168 } 169 170 cmapDepth = (cmapDepth + 1) >> 3; // to bytes.167 txError("TGA Image: Bad Color Map start value."); 168 return FXFALSE; 169 } 170 171 cmapDepth = (cmapDepth + 1) >> 3; // to bytes. 171 172 if ((cmapDepth <= 0) || (cmapDepth > 4)) { 172 txError("TGA Image: Bad Color Map depth.");173 return FXFALSE;173 txError("TGA Image: Bad Color Map depth."); 174 return FXFALSE; 174 175 } 175 176 176 177 // May have to skip the color map. 177 if ((tgaHeader->ImgType != TGA_CMAP) && 178 (tgaHeader->ImgType != TGA_CMAP_RLE)) {179 /* True color, yet there is a palette, this is OK, just skip. */180 181 cmapLength *= cmapDepth;182 while (cmapLength--) {183 intc;184 185 c = getc(stream);186 if (c == EOF) {187 txError("TGA Image: Unexpected EOF reading Color Map.");188 return FXFALSE;189 }190 }191 return FXTRUE;192 } 193 194 // This is a real palette that's going to be used. 178 if ((tgaHeader->ImgType != TGA_CMAP) && 179 (tgaHeader->ImgType != TGA_CMAP_RLE)) { 180 /* True color, yet there is a palette, this is OK, just skip. */ 181 182 cmapLength *= cmapDepth; 183 while (cmapLength--) { 184 int c; 185 186 c = getc(stream); 187 if (c == EOF) { 188 txError("TGA Image: Unexpected EOF reading Color Map."); 189 return FXFALSE; 190 } 191 } 192 return FXTRUE; 193 } 194 195 // This is a real palette that's going to be used. 195 196 196 197 // Verify that it's not too large. 197 198 if ((cmapStart + cmapLength) > 256) { 198 txError("TGA Image: Color Map > 256 entries.");199 return FXFALSE;199 txError("TGA Image: Color Map > 256 entries."); 200 return FXFALSE; 200 201 } 201 202 202 203 203 204 // printf("cmapdepth = %d, start = %d, length = %d\n", cmapDepth, 204 // cmapStart, cmapLength);205 // cmapStart, cmapLength); 205 206 for (i=0; i<256; i++) { 206 intr, g, b, a;207 208 if ((i < cmapStart) || (i >= (cmapStart + cmapLength))) {209 palette[i] = 0;210 // printf("Skipping palette entry %d\n", i);211 continue;212 }213 214 // Read this colormap entry.215 switch (cmapDepth) {216 case 1:// 8 bpp217 r = getc(stream);218 if (r == EOF) {219 txError("TGA Image: Unexpected End of File.");220 return FXFALSE;221 }222 r &= 0xFF;223 palette[i] = (r << 24) | (r << 16) | (r << 8) | (r);224 break;225 226 case 2:// 15, 16 bpp.227 228 b = getc(stream);229 r = getc(stream);230 if ((r == EOF) || (b == EOF)) {231 txError("TGA Image: Unexpected End of File.");232 return FXFALSE;233 }234 r &= 0xFF;235 b &= 0xFF;236 g = ((r & 0x3) << 6) + ((b & 0xE0) >> 2);237 r = (r & 0x7C) << 1;238 b = (b & 0x1F) << 3;239 240 palette[i] = (r << 16) | (g << 8) | (b) | 0xFF000000L;241 break;242 243 case 3:244 case 4:245 b = getc(stream);246 g = getc(stream);247 r = getc(stream);248 a = (cmapDepth == 4) ? getc(stream) : 0x0FF;249 250 if ((r == EOF) || (g == EOF) || (b == EOF) | (a == EOF)) {251 txError("TGA Image: Unexpected End of File.");252 return FXFALSE;253 }254 palette[i] = (a << 24) | (r << 16) | (g << 8) | b;255 // printf("Setting palette %3d to %.08x\n", i, palette[i]);256 break;257 258 default:259 txError("TGA Image: Bad Color Map depth.");260 return FXFALSE;261 }207 int r, g, b, a; 208 209 if ((i < cmapStart) || (i >= (cmapStart + cmapLength))) { 210 palette[i] = 0; 211 // printf("Skipping palette entry %d\n", i); 212 continue; 213 } 214 215 // Read this colormap entry. 216 switch (cmapDepth) { 217 case 1: // 8 bpp 218 r = getc(stream); 219 if (r == EOF) { 220 txError("TGA Image: Unexpected End of File."); 221 return FXFALSE; 222 } 223 r &= 0xFF; 224 palette[i] = (r << 24) | (r << 16) | (r << 8) | (r); 225 break; 226 227 case 2: // 15, 16 bpp. 228 229 b = getc(stream); 230 r = getc(stream); 231 if ((r == EOF) || (b == EOF)) { 232 txError("TGA Image: Unexpected End of File."); 233 return FXFALSE; 234 } 235 r &= 0xFF; 236 b &= 0xFF; 237 g = ((r & 0x3) << 6) + ((b & 0xE0) >> 2); 238 r = (r & 0x7C) << 1; 239 b = (b & 0x1F) << 3; 240 241 palette[i] = (r << 16) | (g << 8) | (b) | 0xFF000000L; 242 break; 243 244 case 3: 245 case 4: 246 b = getc(stream); 247 g = getc(stream); 248 r = getc(stream); 249 a = (cmapDepth == 4) ? getc(stream) : 0x0FF; 250 251 if ((r == EOF) || (g == EOF) || (b == EOF) | (a == EOF)) { 252 txError("TGA Image: Unexpected End of File."); 253 return FXFALSE; 254 } 255 palette[i] = (a << 24) | (r << 16) | (g << 8) | b; 256 // printf("Setting palette %3d to %.08x\n", i, palette[i]); 257 break; 258 259 default: 260 txError("TGA Image: Bad Color Map depth."); 261 return FXFALSE; 262 } 262 263 } 263 264 return FXTRUE; 264 265 } 265 266 266 static int tgaRLE, tgaRLEflag, tgaRLEcount, tgaRLEsav[4];267 268 static FxBool267 static int tgaRLE, tgaRLEflag, tgaRLEcount, tgaRLEsav[4]; 268 269 static FxBool 269 270 _txReadTGARLEPixel( FILE *stream, FxU8 *data, int pixsize) 270 271 { 271 int c, i;272 int c, i; 272 273 273 274 // Run length encoded data Only 274 275 if (tgaRLEcount == 0) { 275 // Need to restart the run.276 if ( (tgaRLEcount = c = getc( stream )) == EOF) {277 txError("TGA Image: Unexpected End of File.");278 return FXFALSE;279 }280 tgaRLEflag = tgaRLEcount & 0x80;281 tgaRLEcount = (tgaRLEcount & 0x7F) + 1;282 283 if (tgaRLEflag) {284 // Replicated color, read the color to be replicated 285 for (i=0; i<pixsize; i++) {286 if ( (c = getc( stream )) == EOF) {287 txError("TGA Image: Unexpected End of File\n");288 return FXFALSE;289 }290 tgaRLEsav[i] = (FxU8) c;291 }292 }276 // Need to restart the run. 277 if ( (tgaRLEcount = c = getc( stream )) == EOF) { 278 txError("TGA Image: Unexpected End of File."); 279 return FXFALSE; 280 } 281 tgaRLEflag = tgaRLEcount & 0x80; 282 tgaRLEcount = (tgaRLEcount & 0x7F) + 1; 283 284 if (tgaRLEflag) { 285 // Replicated color, read the color to be replicated 286 for (i=0; i<pixsize; i++) { 287 if ( (c = getc( stream )) == EOF) { 288 txError("TGA Image: Unexpected End of File\n"); 289 return FXFALSE; 290 } 291 tgaRLEsav[i] = (FxU8) c; 292 } 293 } 293 294 } 294 295 … … 296 297 tgaRLEcount--; 297 298 if (tgaRLEflag) { 298 // deliver from saved data.299 for (i=0; i<pixsize; i++) *data++ = (FxU8) tgaRLEsav[i];299 // deliver from saved data. 300 for (i=0; i<pixsize; i++) *data++ = (FxU8) tgaRLEsav[i]; 300 301 } else { 301 for (i=0; i<pixsize; i++) {302 if ( (c = getc( stream )) == EOF) {303 txError("TGA Image: Unexpected End of File\n");304 return FXFALSE;305 }306 *data++ = (FxU8) c;307 }302 for (i=0; i<pixsize; i++) { 303 if ( (c = getc( stream )) == EOF) { 304 txError("TGA Image: Unexpected End of File\n"); 305 return FXFALSE; 306 } 307 *data++ = (FxU8) c; 308 } 308 309 } 309 310 return FXTRUE; … … 314 315 { 315 316 if (tgaRLE == 0) { 316 if ( fread( data, 1, w * pixsize, stream) != (FxU32)(w * pixsize)) {317 txError("TGA Image: Unexpected End of File\n");318 return FXFALSE;319 }320 return FXTRUE;317 if ( fread( data, 1, w * pixsize, stream) != (FxU32)(w * pixsize)) { 318 txError("TGA Image: Unexpected End of File\n"); 319 return FXFALSE; 320 } 321 return FXTRUE; 321 322 } 322 323 323 324 // Otherwise, RLE data. 324 325 while (w--) { 325 if (!_txReadTGARLEPixel( stream, data, pixsize)) {326 return FXFALSE;327 }328 data += pixsize;326 if (!_txReadTGARLEPixel( stream, data, pixsize)) { 327 return FXFALSE; 328 } 329 data += pixsize; 329 330 } 330 331 return FXTRUE; … … 334 335 _txReadTGAData( FILE *stream, TxMip *info) 335 336 { 336 TgaHeader *tgaHeader = (TgaHeader *) info->pal;337 int i, stride;338 int bpp;// bytesPerPixel339 FxU8* data;340 long BigEndian = 0xff000000;337 TgaHeader *tgaHeader = (TgaHeader *) info->pal; 338 int i, stride; 339 int bpp; // bytesPerPixel 340 FxU8* data; 341 long BigEndian = 0xff000000; 341 342 342 343 // printf("TxREAD TGA DATA\n"); … … 346 347 347 348 switch (tgaHeader->ImgType) { 348 case TGA_MONO: tgaRLE = 0; info->format = GR_TEXFMT_I_8; break;349 case TGA_MONO_RLE: tgaRLE = 1; info->format = GR_TEXFMT_I_8; break;350 351 case TGA_TRUE: tgaRLE = 0; info->format = (bpp == 2) ?352 GR_TEXFMT_ARGB_1555 : GR_TEXFMT_ARGB_8888; break;353 case TGA_TRUE_RLE: tgaRLE = 1; info->format = (bpp == 2) ?354 GR_TEXFMT_ARGB_1555 : GR_TEXFMT_ARGB_8888; break;355 356 case TGA_CMAP: tgaRLE = 0; info->format = GR_TEXFMT_P_8; break;357 case TGA_CMAP_RLE: tgaRLE = 1; info->format = GR_TEXFMT_P_8; break;349 case TGA_MONO: tgaRLE = 0; info->format = GR_TEXFMT_I_8; break; 350 case TGA_MONO_RLE: tgaRLE = 1; info->format = GR_TEXFMT_I_8; break; 351 352 case TGA_TRUE: tgaRLE = 0; info->format = (bpp == 2) ? 353 GR_TEXFMT_ARGB_1555 : GR_TEXFMT_ARGB_8888; break; 354 case TGA_TRUE_RLE: tgaRLE = 1; info->format = (bpp == 2) ? 355 GR_TEXFMT_ARGB_1555 : GR_TEXFMT_ARGB_8888; break; 356 357 case TGA_CMAP: tgaRLE = 0; info->format = GR_TEXFMT_P_8; break; 358 case TGA_CMAP_RLE: tgaRLE = 1; info->format = GR_TEXFMT_P_8; break; 358 359 } 359 360 … … 363 364 data = info->data[0]; 364 365 if ((tgaHeader->ImageDescriptor & 0x20) == 0) { 365 // Origin is lower left366 data = data + (info->height-1) * stride;367 stride = -stride;366 // Origin is lower left 367 data = data + (info->height-1) * stride; 368 stride = -stride; 368 369 } 369 370 370 371 /* If there's a colormap, read it now. */ 371 if (!_txReadTGAColorMap(stream, tgaHeader, (FxU32 *) &(info->pal[0]))) 372 return FXFALSE;372 if (!_txReadTGAColorMap(stream, tgaHeader, (FxU32 *) &(info->pal[0]))) 373 return FXFALSE; 373 374 // printf("read in color map\n"); 374 375 375 376 /* Read in all the data */ 376 377 for ( i = 0; i < info->height; i++) { 377 if (!_txReadTGASpan( stream, data, info->width, bpp)) {378 txError("TGA Image: Unexpected end of file.");379 return FXFALSE;380 }381 data += stride;378 if (!_txReadTGASpan( stream, data, info->width, bpp)) { 379 txError("TGA Image: Unexpected end of file."); 380 return FXFALSE; 381 } 382 data += stride; 382 383 } 383 384 … … 390 391 // printf("Repacking\n"); 391 392 if (bpp == 3) { 392 intnpixels = info->width * info->height;393 FxU8*src = ((FxU8 *) info->data[0]) + (npixels - 1) * 3;394 FxU8*dst = ((FxU8 *) info->data[0]) + (npixels - 1) * 4;395 396 while (npixels--) {397 dst[3] = 0xFF;398 dst[2] = src[2];399 dst[1] = src[1];400 dst[0] = src[0];401 dst -= 4;402 src -= 3;403 }393 int npixels = info->width * info->height; 394 FxU8 *src = ((FxU8 *) info->data[0]) + (npixels - 1) * 3; 395 FxU8 *dst = ((FxU8 *) info->data[0]) + (npixels - 1) * 4; 396 397 while (npixels--) { 398 dst[3] = 0xFF; 399 dst[2] = src[2]; 400 dst[1] = src[1]; 401 dst[0] = src[0]; 402 dst -= 4; 403 src -= 3; 404 } 404 405 } 405 406 // printf("Done\n"); 406 407 if (*(FxU8 *)&BigEndian) { 407 /* Repack 16bpp and 32bpp cases */408 /* Repack 16bpp and 32bpp cases */ 408 409 if (bpp == 2) { 409 intnpixels = info->width * info->height;410 FxU16*src = (FxU16 *) info->data[0];411 412 while (npixels--) {413 *src = (*src << 8) | ((*src >> 8) & 0xff);410 int npixels = info->width * info->height; 411 FxU16 *src = (FxU16 *) info->data[0]; 412 413 while (npixels--) { 414 *src = (*src << 8) | ((*src >> 8) & 0xff); 414 415 src++; 415 }416 } 416 417 } 417 418 if ((bpp == 3) || (bpp == 4)) { 418 intnpixels = info->width * info->height;419 FxU32*src = (FxU32 *) info->data[0];420 421 while (npixels--) {422 *src = (((*src ) & 0xff) << 24)|423 (((*src >> 8) & 0xff) << 16)|424 (((*src >> 16) & 0xff) << 8)|425 (((*src >> 24) & 0xff) );419 int npixels = info->width * info->height; 420 FxU32 *src = (FxU32 *) info->data[0]; 421 422 while (npixels--) { 423 *src = (((*src ) & 0xff) << 24)| 424 (((*src >> 8) & 0xff) << 16)| 425 (((*src >> 16) & 0xff) << 8)| 426 (((*src >> 24) & 0xff) ); 426 427 src++; 427 }428 } 428 429 } 429 430 } -
trunk/src/opengl/glide/cvg/texus/util.c
r2888 r6653 1 /* $Id: util.c,v 1.2 2001-09-05 14:30:47 bird Exp $ */ 1 2 2 3 /* … … 4 5 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 5 6 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 7 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 8 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 9 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 9 10 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 12 ** 12 13 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 13 14 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 15 16 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 16 17 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 17 ** THE UNITED STATES. 18 ** 18 ** THE UNITED STATES. 19 ** 19 20 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 20 21 ** 21 ** $Revision: 1. 1$22 ** $Date: 200 0-02-25 00:38:01$22 ** $Revision: 1.2 $ 23 ** $Date: 2001-09-05 14:30:47 $ 23 24 */ 24 25 … … 33 34 34 35 char *Format_Name[] = { 35 "rgb332", // GR_TEXFMT_RGB_332 36 "rgb332", // GR_TEXFMT_RGB_332 36 37 "yiq", // GR_TEXFMT_YIQ_422 37 38 "a8", // GR_TEXFMT_ALPHA_8 … … 136 137 txYABtoPal256(long *palette, const long* yabTable) 137 138 { 138 // Convert YAB table to a 256 color palette 139 // Convert YAB table to a 256 color palette 139 140 // Assume yabTable[] has first 16Y's, 12 A's, 12 B's 140 141 … … 268 269 txNearestColor(long ir, long ig, long ib, const FxU32 *pal, int ncolors) 269 270 { 270 int i, d; 271 int i, d; 271 272 int mindist, minpos; // closest distance to input 272 273 … … 274 275 txPanic("Bad explode\n"); 275 276 276 mindist = DISTANCE((*pal>>16)&0xff, (*pal>>8)&0xff, (*pal)&0xff, 277 mindist = DISTANCE((*pal>>16)&0xff, (*pal>>8)&0xff, (*pal)&0xff, 277 278 ir, ig, ib); 278 279 minpos = 0; … … 281 282 /* Find closest color */ 282 283 for (i=1; i<ncolors; i++, pal ++) { 283 d = DISTANCE((*pal>>16)&0xff, (*pal>>8)&0xff, (*pal)&0xff, 284 d = DISTANCE((*pal>>16)&0xff, (*pal>>8)&0xff, (*pal)&0xff, 284 285 ir, ig, ib); 285 286 if (d < mindist) { mindist = d; minpos = i; } … … 327 328 328 329 void 329 txRectCopy(FxU8 *dst, int dstStride, const FxU8 *src, int srcStride, 330 txRectCopy(FxU8 *dst, int dstStride, const FxU8 *src, int srcStride, 330 331 int width, int height) 331 332 { … … 414 415 { 415 416 /* Strip the pathname and leave us with filename.ext */ 416 char *s; 417 char *s; 417 418 const char *p, *slash; 418 419 … … 428 429 for (s = basename; *s; s++); 429 430 430 // Walk backwards; replace any . with 0 431 // Walk backwards; replace any . with 0 431 432 while (--s >= basename) { 432 433 if (*s == '.') {*s = 0; break;} … … 463 464 } 464 465 465 if (ext) 466 if (ext) 466 467 while (*ext) *extname++ = *ext++; 467 468 468 469 *extname = 0; 469 470 } -
trunk/src/opengl/glide/cvg/texus/view.c
r2888 r6653 1 /* $Id: view.c,v 1.2 2001-09-05 14:30:47 bird Exp $ */ 1 2 /* 2 3 ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 ** 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 12 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 12 13 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 14 15 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 15 16 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 16 ** THE UNITED STATES. 17 ** 17 ** THE UNITED STATES. 18 ** 18 19 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 19 20 ** 20 ** $Revision: 1. 1$21 ** $Date: 200 0-02-25 00:38:02$21 ** $Revision: 1.2 $ 22 ** $Date: 2001-09-05 14:30:47 $ 22 23 */ 23 24 -
trunk/src/opengl/glide/cvg/texus/write.c
r2888 r6653 1 /* $Id: write.c,v 1.2 2001-09-05 14:30:48 bird Exp $ */ 1 2 /* 2 3 ** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY 3 4 ** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT 4 5 ** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX 5 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 6 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 7 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 6 ** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 7 ** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 8 ** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 8 9 ** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A 9 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 10 ** 10 ** FULL TEXT OF THE NON-WARRANTY PROVISIONS. 11 ** 11 12 ** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO 12 13 ** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN … … 14 15 ** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR 15 16 ** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF 16 ** THE UNITED STATES. 17 ** 17 ** THE UNITED STATES. 18 ** 18 19 ** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED 19 20 */ … … 30 31 */ 31 32 static char *Version = "1.1"; 32 static char* aspect_names[] = { "8 1", "4 1", "2 1", "1 1", 33 static char* aspect_names[] = { "8 1", "4 1", "2 1", "1 1", 33 34 "1 2", "1 4", "1 8" }; 34 35 35 36 /*************************************** tga files ****************************/ 36 /* 37 /* 37 38 * Write a tga file from an ARGB8888 mipmap. 38 39 */ 39 static FxBool 40 static FxBool 40 41 txWriteTGA( FILE *stream, TxMip *txMip) 41 42 { … … 73 74 return FXFALSE; 74 75 } 75 76 76 77 outW = txMip->width; 77 78 outH = txMip->height; 78 79 if (txMip->depth > 1) outW += outW/2; 79 80 80 81 tgaHeader.IDLength = 0; 81 82 tgaHeader.ColorMapType = 0; … … 96 97 tgaHeader.PixelDepth = 32; 97 98 tgaHeader.ImageDescriptor = 0x20; // image always right side up. 98 99 99 100 100 101 if ( fwrite( &tgaHeader, 1, 18, stream ) != 18 ) { … … 110 111 111 112 /* Copy level 0 into malloc'd area */ 112 txRectCopy( data, outW * 4, txMip->data[0], txMip->width * 4, 113 txRectCopy( data, outW * 4, txMip->data[0], txMip->width * 4, 113 114 txMip->width * 4, txMip->height); 114 115 … … 116 117 117 118 /* Copy the rest of the levels to the right of level 0 */ 118 w = txMip->width; 119 h = txMip->height; 119 w = txMip->width; 120 h = txMip->height; 120 121 for (i=1; i< txMip->depth; i++) { 121 122 // printf("Copying: level = %d\n", i); … … 129 130 data32 = (FxU32 *) data; 130 131 for (i=outW*outH; i; i--) { 131 putc(((*data32 ) & 0xff) , stream); 132 putc(((*data32 >> 8) & 0xff) , stream); 133 putc(((*data32 >> 16) & 0xff) , stream); 134 putc(((*data32 >> 24) & 0xff) , stream); 132 putc(((*data32 ) & 0xff) , stream); 133 putc(((*data32 >> 8) & 0xff) , stream); 134 putc(((*data32 >> 16) & 0xff) , stream); 135 putc(((*data32 >> 24) & 0xff) , stream); 135 136 data32++; 136 137 } … … 142 143 /* Write word, msb first */ 143 144 144 static FxBool 145 static FxBool 145 146 _txWrite16 (FILE *stream, FxU16 data) 146 147 { … … 155 156 /* Write long word, msb first */ 156 157 157 static FxBool 158 static FxBool 158 159 _txWrite32 (FILE *stream, FxU32 data) 159 160 { … … 169 170 170 171 /* Write NCC table */ 171 static FxBool 172 static FxBool 172 173 _txWrite3dfNCCTable (FILE *stream, FxU32 *yab) 173 174 { … … 177 178 if (!_txWrite16 (stream, (FxU16) (yab[i] & 0x00ff))) return FXFALSE; 178 179 179 for (i = 0; i < 12; i++) 180 for (i = 0; i < 12; i++) 180 181 if (!_txWrite16 (stream, (FxU16) (yab[16+i] & 0xffff))) return FXFALSE; 181 182 182 for (i = 0; i < 12; i++) 183 for (i = 0; i < 12; i++) 183 184 if (!_txWrite16 (stream, (FxU16) (yab[28+i] & 0xffff))) return FXFALSE; 184 185 … … 197 198 } 198 199 199 static FxBool 200 static FxBool 200 201 txWrite3df (FILE *stream, TxMip *txMip) 201 202 { … … 213 214 214 215 // printf("Writing header...\n"); 215 if (EOF == fprintf (stream, 216 if (EOF == fprintf (stream, 216 217 "3df v%s\n%s\nlod range: %d %d\naspect ratio: %s\n", 217 Version, 218 Version, 218 219 Format_Name[txMip->format], 219 220 small_lod, … … 226 227 (txMip->format == GR_TEXFMT_AYIQ_8422)) { 227 228 if (!_txWrite3dfNCCTable (stream, txMip->pal)) return FXFALSE; 228 } 229 } 229 230 230 231 else if ((txMip->format == GR_TEXFMT_P_8) || 231 232 (txMip->format == GR_TEXFMT_AP_88)) { 232 233 if (!_txWrite3dfPalTable (stream, txMip->pal)) return FXFALSE; 233 } 234 } 234 235 235 236 … … 289 290 if( txVerbose ) 290 291 { 291 printf("Writing file \"%s\" (format: %s)\n", 292 printf("Writing file \"%s\" (format: %s)\n", 292 293 filename, Format_Name[txMip->format]); 293 294 } … … 380 381 break; 381 382 case TX_WRITE_TGA: 382 if( mip.format == GR_TEXFMT_YIQ_422 || 383 if( mip.format == GR_TEXFMT_YIQ_422 || 383 384 mip.format == GR_TEXFMT_AYIQ_8422 ) 384 385 {
Note:
See TracChangeset
for help on using the changeset viewer.
