Ignore:
Timestamp:
Sep 5, 2001, 4:31:14 PM (24 years ago)
Author:
bird
Message:

Added $Id:$ keyword.

Location:
trunk/src/opengl/glide/cvg/texus
Files:
19 edited

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 $ */
    12/*
    23 * THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34 * PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45 * 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
    89 * 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.
    1011 *
    1112 * USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
     
    2526/*************************************** 3df files ****************************/
    2627/* Read word, msb first */
    27 static FxBool 
     28static FxBool
    2829_txRead16 (FILE *stream, FxU16* data)
    2930{
     
    3637
    3738/* Read long word, msb first */
    38 static FxBool 
     39static FxBool
    3940_txRead32 (FILE *stream, FxU32* data)
    4041{
     
    5354
    5455/* Read NCC table */
    55 static FxBool 
     56static FxBool
    5657_txRead3DFNCCTable (FILE* stream, FxI32* ncc_table)
    5758{
     
    8788}
    8889
    89 static FxBool 
     90static FxBool
    9091_txRead3DFPalTable (FILE* stream, FxI32* pal)
    9192{
     
    114115    if (fscanf (stream, "f v%6s", version) != 1) return FXFALSE;
    115116
    116     /* 
     117    /*
    117118     * skip comments
    118119     */
  • 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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:37:58 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:44 $
    2324*/
    2425
     
    3738  if( txVerbose )
    3839    {
    39       printf( "clamping from %dx%d to %dx%d\n", 
     40      printf( "clamping from %dx%d to %dx%d\n",
    4041              ix, iy, ox, oy );
    4142    }
     
    7677  if ((srcMip->data[0] == NULL) || (dstMip->data[0] == NULL))
    7778    txPanic("txImageClamp: Null buffer\n");
    78  
     79
    7980  sw = srcMip->width;
    8081  sh = srcMip->height;
     
    8283  dh = dstMip->height;
    8384
    84   for( i = 0; i < srcMip->depth; i++ ) 
     85  for( i = 0; i < srcMip->depth; i++ )
    8586    {
    8687      if( !dstMip->data[i] )
     
    103104    }
    104105}
    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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:37:58 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:44 $
    2324*/
    2425
     
    3031#include "texusint.h"
    3132
    32 /* 
     33/*
    3334 * Pn_8 = convert n bits (n <= 6) to 8 bits by replicating the msb's of input
    3435 * into the lsb's of the output.
     
    9495
    9596/* 16 bit pixels */
    96 static FxU32 
     97static FxU32
    9798_txPixArgb8332to8888(FxU16 c8332)
    9899{
    99100    FxU32       a, r, g, b;
    100     a =      (c8332 >>  8);     
     101    a =      (c8332 >>  8);
    101102    r = P3_8[(c8332 >>  5) & 0x7];
    102103    g = P3_8[(c8332 >>  2) & 0x7];
     
    233234    in  += n;
    234235    while (n--) {
    235         in--; 
     236        in--;
    236237        *--out = (pal[(*in) & 0xff] & 0x00ffffff) | ((*in & 0xFF00) << 16);
    237238    }
     
    302303    in  += n;
    303304
    304     while (n--) *--out = *--in; 
     305    while (n--) *--out = *--in;
    305306}
    306307
     
    314315    for( i = 0; i < n; i++ )
    315316      {
    316         out[i] = 
    317           ( ( ( FxU32 )0xff ) << 24 ) | 
     317        out[i] =
     318          ( ( ( FxU32 )0xff ) << 24 ) |
    318319          ( ( ( FxU32 )in[i*3] )<< 16 ) |
    319320          ( ( ( FxU32 )in[i*3+1] )<< 8 ) |
     
    322323}
    323324
    324 void   
     325void
    325326txMipDequantize(TxMip *txMip, TxMip *pxMip)
    326327{
     
    344345            printf(" %dx%d", w, h); fflush(stdout);
    345346          }
    346            
     347
    347348        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,
    351352                                                                        (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,
    359360                                                                        pxMip->pal); break;
    360361
    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,
    364365                                                                        (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,
    374375                                                                        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:
    381382                                                                break;
    382383        }
  • 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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:37:58 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:44 $
    2324*/
    2425
     
    3940FxU8    bestR[256], bestG[256], bestB[256];
    4041
    41 static int 
     42static int
    4243_txAscendingR(const void *a, const void *b)
    4344{
     
    4647
    4748
    48 static int 
     49static int
    4950_txAscendingG(const void *a, const void *b)
    5051{
     
    5354
    5455
    55 static int 
     56static int
    5657_txAscendingB(const void *a, const void *b)
    5758{
     
    7879
    7980#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",
    8283            i, sortR[i], sortG[i], sortB[i]);
    8384#endif
    8485
    85  
     86
    8687    for (i=0; i<256; i++) {
    8788
     
    129130    persist = 0;
    130131    for (i=bestR[r]; i>=0; i--) {
    131         d = DISTANCE(r, g, b, 
     132        d = DISTANCE(r, g, b,
    132133            ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff));
    133134        if (d < mindist) { mindist = d; minpos = (pal[i] >> 24) & 0xff; }
     
    138139    persist = 0;
    139140    for (i=bestR[r]+1; i < nsorted; i++) {
    140         d = DISTANCE(r, g, b, 
     141        d = DISTANCE(r, g, b,
    141142            ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff));
    142143        if (d < mindist) { mindist = d; minpos = (pal[i] >> 24) & 0xff; }
     
    149150    persist = 0;
    150151    for (i=bestG[g]; i>=0; i--) {
    151         d = DISTANCE(r, g, b, 
     152        d = DISTANCE(r, g, b,
    152153            ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff));
    153154        if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; }
     
    158159    persist = 0;
    159160    for (i=bestG[g]+1; i < nsorted; i++) {
    160         d = DISTANCE(r, g, b, 
     161        d = DISTANCE(r, g, b,
    161162            ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff));
    162163        if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; }
     
    168169    persist = 0;
    169170    for (i=bestB[b]; i>=0; i--) {
    170         d = DISTANCE(r, g, b, 
     171        d = DISTANCE(r, g, b,
    171172            ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff));
    172173        if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; }
     
    177178    persist = 0;
    178179    for (i=bestB[b]+1; i < nsorted; i++) {
    179         d = DISTANCE(r, g, b, 
     180        d = DISTANCE(r, g, b,
    180181            ((pal[i] >> 16) & 0xff), ((pal[i] >> 8) & 0xff), ((pal[i]) & 0xff));
    181182        if (d < mindist) { mindist = d; minpos = (pal[i]>>24) & 0xff; }
     
    221222            ib += qb + ErrB[x];
    222223
    223             qr = ir;    // quantized pixel values. 
     224            qr = ir;    // quantized pixel values.
    224225            qg = ig;    // qR is error from pixel to left, errR is
    225226            qb = ib;    // error from pixel to the top & top left.
     
    245246            qb = ib - qb;
    246247
    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,
    248249            // 1/4 (0.25) to the SOUTH-EAST.
    249250            ErrR[x]  = ((x == 0) ? 0 : ErrR[x]) + ((int) (qr * 0.375f));
     
    279280        printf("EDiffusion:..."); fflush(stdout);
    280281      }
    281        
     282
    282283#if     FAST_DIFFUSION
    283284    _txMakeRange(palette, ncolors);
     
    289290
    290291    for (i=0; i<txMip->depth; i++) {
    291         _txToDiffuseIndex(pxMip->data[i], pixsize, palette, ncolors, 
     292        _txToDiffuseIndex(pxMip->data[i], pixsize, palette, ncolors,
    292293            txMip->data[i], w, h);
    293294            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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:37:59 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:45 $
    2324*/
    2425
     
    3536/*
    3637 * 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
    3839 * the format that you want to download.
    3940 */
     
    325326          ncc_table.yRGB[i] = ( FxU8 )texture->pal[i];
    326327        }
    327      
     328
    328329      for( i = 0; i < 4; i++ )
    329330        {
  • 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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:37:59 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:45 $
    2324*/
    2425
  • 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 $ */
    12/*
    23** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45** 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
    89** 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**
    1112** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1213** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1415** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1516** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    16 ** THE UNITED STATES. 
    17 ** 
     17** THE UNITED STATES.
     18**
    1819** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    1920**
    20 ** $Revision: 1.1 $
    21 ** $Date: 2000-02-25 00:37:59 $
     21** $Revision: 1.2 $
     22** $Date: 2001-09-05 14:30:45 $
    2223*/
    2324
     
    2930#include "texusint.h"
    3031
    31 static int 
    32 dithmat[4][4] = {       0,  8,  2, 10, 
    33                            12,  4, 14,  6, 
    34                             3, 11,  1,  9, 
     32static int
     33dithmat[4][4] = {       0,  8,  2, 10,
     34                           12,  4, 14,  6,
     35                            3, 11,  1,  9,
    3536                           15,  7, 13,  5 };
    3637
     
    4546_txPixQuantize_YIQ422 (unsigned long argb, int x, int y, int w)
    4647{
    47     int         r, g, b; 
     48    int         r, g, b;
    4849    int         iy, ii, iq;
    4950
     
    125126
    126127static 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,
    128129    int dither)
    129130{
     
    153154
    154155   RGB values can be converted to YIQ using the equation:
    155  
     156
    156157   Y = 0.30F * R + 0.59F * G + 0.11F * B;
    157158   I = 0.60F * R - 0.28F * G - 0.32F * B;
    158159   Q = 0.21F * R - 0.52F * G + 0.31F * B;
    159160
    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,
    161162   Y ranges from (0 .. 255)
    162163   I ranges from (-0.60 * 255 .. 0.60 * 255) i.e, (-153 to 153)
     
    166167
    167168
    168 static void     
     169static void
    169170_txMipNccStatTable(TxMip *txMip)
    170171{
    171172    int i, w, h;
    172173
    173     for (i=0; i<256; i++) 
     174    for (i=0; i<256; i++)
    174175        ncc.yhist[i] = ncc.ihist[i] = ncc.qhist[i] = 0;
    175176    ncc.npixels = 0;
     
    250251
    251252
    252 void   
     253void
    253254txMipNcc(TxMip *pxMip, TxMip *txMip, int format, FxU32 dither, FxU32 compression)
    254255{
     
    256257
    257258    switch (compression & TX_COMPRESSION_MASK) {
    258     case        TX_COMPRESSION_HEURISTIC:                               
     259    case        TX_COMPRESSION_HEURISTIC:
    259260                _txMipNccStatTable(txMip);
    260261                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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:37:59 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:45 $
    2324*/
    2425#include <stdio.h>
     
    3334 * ARGB8888 format and produces an optimal YAB table, and an 8 bit image
    3435 * 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
    3637 * /tdfx/engr/devel/sst1/docs/yab.doc. The summary follows.
    3738 *
    38  * Neural net algorithms first determine a "representative sample" of the 
     39 * Neural net algorithms first determine a "representative sample" of the
    3940 * input image. This representative sample is repeatedly run through the net
    4041 * during the network learning stage, and the neural net "learns" which colors
    4142 * are important and which ones are not. It's quite possible to feed every
    4243 * 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.
    4445 *
    4546 * So, we prefer to make a representative sample of colors for the input image.
     
    4849 * colors (just like for the 8-bit palettized case) works quite well, and
    4950 * 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
    5152 * textures very easy.
    5253 *
    5354 * 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.
    5960 *
    6061 * So now it's possible to translate the original image into an 8 bit image
     
    6566 * In the process of converting the original image to the YAB format, we could
    6667 * optionally dither the image. Ordered dithering doesn't quite work, so we
    67  * use error-diffusion dithering. 
     68 * use error-diffusion dithering.
    6869 *
    6970 * I've found that there are three speed bottlenecks to overcome. The first
    7071 * 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
    7374 * much as possible. The third bottleneck is the translation of the original
    7475 * image into the 8 bit YAB indexed image; this still needs work, especially
     
    7980
    8081/******************************************************************************
    81  * 
     82 *
    8283 * The hardcore neural net stuff begins here.
    8384 *
     
    117118_nn_modifyNeurons(long ir, long ig, long ib)
    118119{
    119     int         i; 
     120    int         i;
    120121    int         d0, d1;                         // closest & next closest distance to input
    121122    int         p0, p1;                         // index into the 256 color table.
     
    138139
    139140        d = DISTANCE(n->r, n->g, n->b, ir, ig, ib);
    140         if (d < d0) { 
     141        if (d < d0) {
    141142                d1 = d0; d0 = d;
    142143                p1 = p0; p0 = i;
     
    145146                d1 = d;
    146147                p1 = i;
    147         } 
     148        }
    148149    }
    149150
     
    183184    pb = N[p0].pb;
    184185    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);
    186187    pa->g += (dg >> 2) ; CLAMP_BOTH(pa->g);
    187188    pa->b += (db >> 2) ; CLAMP_BOTH(pa->b);
     
    258259
    259260static  int order[256];
    260 static int 
     261static int
    261262_nn_randomOrder(const void *a, const void *b)
    262263{
     
    275276
    276277    _nn_initTables();
    277     /* 
     278    /*
    278279     * Select a number which is relatively prime to nsamples.
    279280     */
     
    295296                FxU32   *pRGB;
    296297
    297                 // We present the samples randomly to the network. 
     298                // We present the samples randomly to the network.
    298299                // _nn_modify_neurons() makes the neurons learn
    299300                // errR, errG, errB, errMax are computed in _nn_modifyNeurons(), as
     
    308309
    309310        if (errMax < bstMax) {
    310                 /* 
     311                /*
    311312                 * A lower total error than before, take a Snapshot
    312313                 *
     
    344345                bstB   = errB;
    345346#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,
    349350                   totG/nsamples, totR/nsamples, totB/nsamples
    350351                );
     
    356357        }
    357358
    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();
    361362                break;
    362363        }
    363364    }
    364365
    365     /* 
     366    /*
    366367     * At this point YAB has the YAB table, samples has input palette,
    367368     * Replace MSB of samples with index to be used with YAB table.
     
    393394
    394395
    395     /* 
    396      * Get a 256 color palette, to be used as samples 
     396    /*
     397     * Get a 256 color palette, to be used as samples
    397398     * Incidentally, convert src 32 bit image to dst 8 bit indexed image,
    398399     * with indices referring to the 256 color palette.
     
    403404        printf("NCC Neural nets..."); fflush(stdout);
    404405      }
    405     pxMip->format = (format == GR_TEXFMT_YIQ_422) ? GR_TEXFMT_P_8 : 
     406    pxMip->format = (format == GR_TEXFMT_YIQ_422) ? GR_TEXFMT_P_8 :
    406407        GR_TEXFMT_AP_88;
    407408    ncolors = txMipPal256(pxMip, txMip, pxMip->format, 0, 0);
     
    413414    if( txVerbose )
    414415      {
    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,
    417418               totG/ncolors, totR/ncolors, totB/ncolors
    418419               );
     
    423424        /*
    424425         * 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
    426427         * useful for error diffusion dithering.
    427428         */
    428429        txYABtoPal256((long *)pxMip->pal, (long *)yabTable);
    429430        txDiffuseIndex(pxMip, txMip, pixsize, pxMip->pal, 256);
    430     } 
     431    }
    431432    else {
    432433
  • 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 $ */
    12/*
    23 * 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
    45 * preserved on all copies.
    5  * 
     6 *
    67 * There is no warranty or other guarantee of fitness for this software,
    78 * it is provided solely "as is".  Bug reports or fixes may be sent
     
    910 *
    1011 * 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
    1213 * source is available for no extra charge.
    1314 *
     
    7273 * Readability constants.
    7374 */
    74 #define REDI            0       
     75#define REDI            0
    7576#define GREENI          1
    76 #define BLUEI           2       
     77#define BLUEI           2
    7778#define TRUE            1
    7879#define FALSE           0
     
    111112 * Perform variance-based color quantization on a 24-bit image.
    112113 */
    113 int     
     114int
    114115txMipPal256(TxMip *pxMip, TxMip *txMip, int format, FxU32 dither, FxU32 compression)
    115116{
     
    117118    int         i;                              /* Counter */
    118119    int         OutColors;              /* # of entries computed */
    119     int         Colormax;               /* quantized full-intensity */ 
     120    int         Colormax;               /* quantized full-intensity */
    120121    float       Cfactor;                /* Conversion factor */
    121122#if 0
     
    131132    Cfactor = (float)FULLINTENSITY / Colormax;
    132133
    133     Boxes = _Boxes;     
     134    Boxes = _Boxes;
    134135#if 0
    135136    Histogram = (ulong *) txMalloc(ColormaxI*ColormaxI*ColormaxI * sizeof(long));
     
    157158
    158159    OutColors = CutBoxes(Boxes, MAXCOLORS);
    159    
     160
    160161    /*
    161162     * We now know the set of representative colors.  We now
     
    180181        pxMip->pal[i] = (r<<16) | (g << 8) | b;
    181182    }
    182     ComputeRGBMap(Boxes, OutColors, rgbmap); 
     183    ComputeRGBMap(Boxes, OutColors, rgbmap);
    183184
    184185    /*
     
    218219                                *dst++ = rgbmap[index];
    219220                        } else {
    220                                 *(FxU16 *)dst = (rgbmap[index]) | 
     221                                *(FxU16 *)dst = (rgbmap[index]) |
    221222                                                ((argb >> 16) & 0xFF00);
    222223                                dst+= 2;
     
    253254     * We compute both the histogram and the proj. frequencies of
    254255     * the first box at the same time to save a pass through the
    255      * entire image. 
     256     * entire image.
    256257     */
    257    
     258
    258259    for (i = 0; i < npixels; i++) {
    259260        rr = (uchar) (((*pixels >> 16) & 0xff) >> (8-NBITS));
     
    266267        Histogram[(((rr<<NBITS)|gg)<<NBITS)|bb]++;
    267268    }
    268        
     269
    269270}
    270271
     
    273274 */
    274275static int
    275 CutBoxes(Box *boxes, int colors) 
     276CutBoxes(Box *boxes, int colors)
    276277{
    277278    int curbox;
     
    363364     * Find 'optimal' cutpoint along each of the red, green and blue
    364365     * 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
    366367     * (possible) later use.
    367368     */
     
    461462    bzero(box1->freq[0], ColormaxI * sizeof(ulong));
    462463    bzero(box1->freq[1], ColormaxI * sizeof(ulong));
    463     bzero(box1->freq[2], ColormaxI * sizeof(ulong)); 
     464    bzero(box1->freq[2], ColormaxI * sizeof(ulong));
    464465
    465466    for (r = box1->low[0]; r < box1->high[0]; r++) {
     
    507508{
    508509    int r, g, b;
    509    
     510
    510511    for (r = box->low[REDI]; r < box->high[REDI]; r++) {
    511512        for (g = box->low[GREENI]; g < box->high[GREENI]; g++) {
    512513                for (b = box->low[BLUEI]; b < box->high[BLUEI]; b++) {
    513514                        int     index;
    514                        
     515
    515516                        index = (((r<<NBITS)|g)<<NBITS)|b;
    516517                        rgbmap[index]=(char)boxnum;
     
    528529  int min_index;
    529530  long r, g, b;
    530  
     531
    531532  min_dist = 256 * 256 + 256 * 256 + 256 * 256;
    532533  min_index = -1;
     
    573574          unsigned long index;
    574575          unsigned long r_index, g_index, b_index;
    575          
     576
    576577          r_index = ( ( ( unsigned long )src[i*4+2] ) >> ( 8 - INVERSE_PAL_R_BITS ) );
    577578          g_index = ( ( ( unsigned long )src[i*4+1] ) >> ( 8 - INVERSE_PAL_G_BITS ) );
    578579          b_index = ( ( ( unsigned long )src[i*4+0] ) >> ( 8 - INVERSE_PAL_B_BITS ) );
    579           index = 
     580          index =
    580581            ( r_index << ( INVERSE_PAL_G_BITS + INVERSE_PAL_B_BITS ) ) |
    581582            ( g_index << INVERSE_PAL_B_BITS ) |
     
    618619  static          FxU32 last_pal[256];
    619620  static          FxBool been_here = FXFALSE;
    620  
     621
    621622  w = outputMip->width;
    622623  h = outputMip->height;
     
    632633    }
    633634
    634   for( i = 0; i < trueColorMip->depth; i++ ) 
     635  for( i = 0; i < trueColorMip->depth; i++ )
    635636    {
    636637      _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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:38:00 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:46 $
    2324**
    2425*/
     
    3233
    3334
    34 FxBool 
     35FxBool
    3536_txReadPPMHeader( FILE *stream, FxU32 cookie, TxMip *info)
    36 { 
     37{
    3738    char buffer[256];
    3839    FxU32 state = 1;
    3940    FxBool done = FXFALSE;
    40    
     41
    4142    if ( stream == NULL ) {
    42         txPanic("PPM file: Bad file handle.");
    43         return FXFALSE;
     43    txPanic("PPM file: Bad file handle.");
     44    return FXFALSE;
    4445    }
    45    
     46
    4647    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;
    5749
    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;
    6258
    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;
    7263
    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        }
    7979    }
    80    
     80    }
     81
    8182    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;
    8485    }
    8586    info->depth = 1;
     
    8990}
    9091
    91 FxBool 
    92 _txReadPPMData( FILE *stream, TxMip *info) 
    93 { 
     92FxBool
     93_txReadPPMData( FILE *stream, TxMip *info)
     94{
    9495    FxU32 numPixels;
    9596    FxU32 *data32 = info->data[0];
    96    
     97
    9798    numPixels = info->width * info->height;
    9899
    99100    if ( stream == NULL ) {
    100         txPanic("PPM file: Bad file handle.");
    101         return FXFALSE;
     101    txPanic("PPM file: Bad file handle.");
     102    return FXFALSE;
    102103    }
    103    
     104
    104105    // Read in image data
    105106    while (numPixels--) {
    106         int r, g, b;
     107    int r, g, b;
    107108
    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;
    116117    }
    117118    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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:38:00 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:46 $
    2324*/
    2425
     
    3031#include "texusint.h"
    3132
    32 static int 
    33 dithmat[4][4] = {       0,  8,  2, 10, 
    34                            12,  4, 14,  6, 
    35                             3, 11,  1,  9, 
     33static int
     34dithmat[4][4] = {       0,  8,  2, 10,
     35                           12,  4, 14,  6,
     36                            3, 11,  1,  9,
    3637                           15,  7, 13,  5 };
    3738
    3839// for error diffusion.
    39 static int      errR[MAX_TEXWIDTH], errG[MAX_TEXWIDTH], errB[MAX_TEXWIDTH];     
     40static int      errR[MAX_TEXWIDTH], errG[MAX_TEXWIDTH], errB[MAX_TEXWIDTH];
    4041
    4142static int
     
    5455    int n, t;
    5556
    56     n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d; 
     57    n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d;
    5758    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;
    5960    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;
    6162    t |= (n>>4)<<0;
    6263    return t & 0xFF;
     
    8283    ib += errB[x] + qb;
    8384
    84     qr = ir;            // quantized pixel values. 
     85    qr = ir;            // quantized pixel values.
    8586    qg = ig;            // qR is error from pixel to left, errR is
    8687    qb = ib;            // error from pixel to the top & top left.
     
    157158
    158159
    159     n = (int) (n * 0xF0/255.0f + 0.5f) + d;     
     160    n = (int) (n * 0xF0/255.0f + 0.5f) + d;
    160161    t = (n>>4);
    161162    t |= (int)  ((argb>>24) & 0xF0);
     
    215216    int n, t;
    216217
    217     n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d; 
     218    n = (int) (((argb >> 16) & 0xFF) * 0x70/255.0f + 0.5f) + d;
    218219    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;
    220221    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;
    222223    t |= (n>>4)<<0;
    223224    t |= ((argb >> 16) & 0xFF00);
     
    252253    int n, t;
    253254
    254     n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d;       
     255    n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d;
    255256    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;
    257258    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;
    259260    t |= (n>>4)<<0;
    260261    return t & 0xFFFF;
     
    279280    ib += errB[x] + qb;
    280281
    281     qr = ir;            // quantized pixel values. 
     282    qr = ir;            // quantized pixel values.
    282283    qg = ig;            // qR is error from pixel to left, errR is
    283284    qb = ib;            // error from pixel to the top & top left.
     
    324325                    ((argb >> 9) & 0x7C00) |
    325326                        ((argb >> 6) & 0x03E0) |
    326                         ((argb >> 3) & 0x001F) |       
     327                        ((argb >> 3) & 0x001F) |
    327328                        ((argb >> 24) ? 0x8000 : 0)     );
    328329}
     
    334335    int n, t;
    335336
    336     n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d;       
     337    n = (int) (((argb >> 16) & 0xFF) * 0x1F0/255.0f + 0.5f) + d;
    337338    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;
    339340    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;
    341342    t |= (n>>4)<<0;
    342343    t |= ((argb >> 24) ? 0x8000 : 0);
     
    361362    ib += errB[x] + qb;
    362363
    363     qr = ir;            // quantized pixel values. 
     364    qr = ir;            // quantized pixel values.
    364365    qg = ig;            // qR is error from pixel to left, errR is
    365366    qb = ib;            // error from pixel to the top & top left.
     
    407408                    ((argb >> 12) & 0x0F00) |
    408409                        ((argb >>  8) & 0x00F0) |
    409                         ((argb >>  4) & 0x000F) |       
     410                        ((argb >>  4) & 0x000F) |
    410411                        ((argb >> 16) & 0xF000) );
    411412}
     
    417418    int n, t;
    418419
    419     n = (int) (((argb >> 16) & 0xFF) * 0xF0/255.0f + 0.5f) + d; 
     420    n = (int) (((argb >> 16) & 0xFF) * 0xF0/255.0f + 0.5f) + d;
    420421    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;
    422423    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;
    424425    t |= (n>>4)<<0;
    425426    t |= (argb >> 16) & 0xF000;
     
    444445    ib += errB[x] + qb;
    445446
    446     qr = ir;            // quantized pixel values. 
     447    qr = ir;            // quantized pixel values.
    447448    qg = ig;            // qR is error from pixel to left, errR is
    448449    qb = ib;            // error from pixel to the top & top left.
     
    511512
    512513        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;
    516517                                                                break;
    517518        case GR_TEXFMT_I_8:                     quantizer = _txPixQuantize_I8;
     
    521522        case GR_TEXFMT_ARGB_8332:       quantizer = _txPixQuantize_ARGB8332_DErr;
    522523                                                                break;
    523         case GR_TEXFMT_RGB_565:         quantizer = _txPixQuantize_RGB565_DErr; 
     524        case GR_TEXFMT_RGB_565:         quantizer = _txPixQuantize_RGB565_DErr;
    524525                                                                break;
    525526        case GR_TEXFMT_ARGB_1555:       quantizer =     _txPixQuantize_ARGB1555_DErr;
     
    535536
    536537        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");
    558559                                                                break;
    559560        }
     
    561562
    562563        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");
    584585                                                                break;
    585586        }
     
    614615 * quality levels in each of the compression cases.
    615616 */
    616 void   
     617void
    617618txMipQuantize(TxMip *pxMip, TxMip *txMip, int format, FxU32 dither, FxU32 compression)
    618619{
     
    636637                return;
    637638
    638     case GR_TEXFMT_ARGB_8888: 
     639    case GR_TEXFMT_ARGB_8888:
    639640                // Copy source to destination, and be done.
    640641                if( txVerbose )
     
    651652
    652653    // 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:
    656657    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:
    660661    case GR_TEXFMT_ARGB_4444:
    661662    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 $ */
    12/*
    23** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45** 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
    89** 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**
    1112** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1213** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1415** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1516** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    16 ** THE UNITED STATES. 
    17 ** 
     17** THE UNITED STATES.
     18**
    1819** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    1920**
    20 ** $Revision: 1.1 $
    21 ** $Date: 2000-02-25 00:38:00 $
     21** $Revision: 1.2 $
     22** $Date: 2001-09-05 14:30:46 $
    2223*/
    2324
     
    3839#define TX_UNK  0x200   // TGA is unknown from cookie signature.
    3940
    40 int 
     41int
    4142_txReadHeader( FILE *stream, TxMip *info )
    4243{
     
    8687}
    8788
    88 static FxBool 
     89static FxBool
    8990_txReadData( FILE *stream, int fformat, TxMip *info )
    9091{
     
    109110
    110111  file = fopen(filename, "rb");
    111   if( file == NULL ) 
     112  if( file == NULL )
    112113    {
    113114      fprintf( stderr,"Error: can't open input file %s\n", filename );
    114115      exit(2);
    115116    }
    116  
     117
    117118  retval = txMipReadFromFP( txMip, filename, file, prefFormat );
    118119  fclose(file);
     
    128129
    129130        if ((prefFormat != GR_TEXFMT_ARGB_8888) &&
    130             (prefFormat != GR_TEXFMT_ANY)) 
     131            (prefFormat != GR_TEXFMT_ANY))
    131132          {
    132133            txPanic("txMipRead: bad preferred format.");
     
    143144            fprintf(stderr,"Loading image file ");
    144145
    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,
    146147                     txMip->width,txMip->height, GR_TEXFMT_SIZE(txMip->format), txMip->depth);
    147148          }
    148149
    149150        /*
    150          * Allocate memory requested in data[0]; 
     151         * Allocate memory requested in data[0];
    151152         */
    152153
     
    159160                        continue;
    160161                }
    161                 txMip->data[i] = (FxU8*)txMip->data[i-1] + 
     162                txMip->data[i] = (FxU8*)txMip->data[i-1] +
    162163                        w * h * GR_TEXFMT_SIZE(txMip->format);
    163164                if (w > 1) w >>= 1;
     
    166167
    167168        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 );
    172173        }
    173174
     
    195196        if( txVerbose )
    196197          {
    197             fprintf(stderr, "Dequantizing Input from %s to argb8888.\n", 
     198            fprintf(stderr, "Dequantizing Input from %s to argb8888.\n",
    198199                   Format_Name[txMip->format]);
    199200          }
  • 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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:38:00 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:46 $
    2324*/
    2425
     
    3839 * total of ox * ix fragments, same as before.
    3940 * 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
    4142 * 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
    4344 */
    4445
     
    6566        int    oa, or, og, ob;
    6667
    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
    6970        // output pixel.
    7071
    7172        ef = ix - accf;         // the excessive # of fragments.
    7273
    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",
    7475    //  accf, nf, ef, ix, ox);
    7576
     
    9495
    9596        *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",
    9798           //  o, oa, or, og, ob);
    9899        o++;
     
    124125
    125126static void
    126 _txImgResample(FxU32 *out, int ox, int oy, 
     127_txImgResample(FxU32 *out, int ox, int oy,
    127128               const FxU32 *in, int ix, int iy)
    128129{
     
    147148        int          ef;
    148149
    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
    151152        // output pixel.
    152153
     
    243244          printf("Resampling to %dx%d: ", destMip->width, destMip->height);
    244245
    245        
     246
    246247        sw = srcMip->width;
    247248        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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:38:00 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:46 $
    2324**
    2425*/
     
    3637const FxU16 ITYPE_BGR      = 0x04;
    3738const FxU16 ITYPE_RGT      = 0x08;
    38    
     39
    3940typedef struct _rgtHeader{
    4041    FxU16 magic;
     
    6768    while (length--) {
    6869        s = *array;
    69         *array++ = (s << 24) | ((s >> 8)&0xFF00) | 
     70        *array++ = (s << 24) | ((s >> 8)&0xFF00) |
    7071                        ((s&0xFF00) << 8) | (s>>24);
    7172    }
     
    8384
    8485
    85 FxBool 
     86FxBool
    8687_txReadRGTHeader( FILE *stream, FxU32 cookie, TxMip *info)
    8788{
     
    9394        return FXFALSE;
    9495    }
    95    
     96
    9697    if ( fread( &(rgtHeader->typeLo), 1, sizeof(RgtHeader)-2, stream ) != 10 ) {
    9798        txPanic("RGT file: Unexpected end of file.");
     
    104105
    105106
    106     info->format = GR_TEXFMT_ARGB_8888; 
     107    info->format = GR_TEXFMT_ARGB_8888;
    107108    info->width = rgtHeader->sizeXHi << 8 | rgtHeader->sizeXLo;
    108109    info->height = rgtHeader->sizeYHi << 8 | rgtHeader->sizeYLo;
     
    111112    if( txVerbose )
    112113      {
    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,
    114115               info->width, info->height, rgtHeader->sizeZLo, rgtHeader->typeHi, rgtHeader->typeLo, rgtHeader->magic == IMAGIC);
    115116      }
     
    119120// RGT is RGBA in memory (low byte to high byte), or ABGR in a register
    120121
    121 FxBool 
     122FxBool
    122123_txReadRGTData( FILE *stream, TxMip *info)
    123124{
    124125    RgtHeader   *rgtHeader = (RgtHeader *) info->pal;
    125126    FxU16 type = (rgtHeader->typeHi);
    126     FxU16 swap = (rgtHeader->magic == IMAGIC); 
     127    FxU16 swap = (rgtHeader->magic == IMAGIC);
    127128    int   x, y;
    128    
     129
    129130    if ( stream == NULL ) {
    130131        txPanic("RGT file: Bad file handle.");
     
    139140        return FXFALSE;
    140141    }
    141    
     142
    142143    // load rgt, rgt's are bottom up
    143144    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 $ */
    12/*
    23** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45** 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
    89** 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**
    1112** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1213** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1415** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1516** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    16 ** THE UNITED STATES. 
    17 ** 
     17** THE UNITED STATES.
     18**
    1819** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    1920**
    20 ** $Id: texuslib.c,v 1.1 2000-02-25 00:38:01 sandervl Exp $
     21** $Id: texuslib.c,v 1.2 2001-09-05 14:30:47 bird Exp $
    2122*/
    2223#include <string.h>
     
    5960
    6061/* size in texels  */
    61 static FxU32 _grMipMapHostSize[4][16] = 
     62static FxU32 _grMipMapHostSize[4][16] =
    6263{
    6364    {   /* 1:1 aspect ratio */
     
    7172            4, /* 7 :   2x2    */
    7273            1, /* 8 :   1x1    */
    73     }, 
     74    },
    7475    {   /* 2:1 aspect ratio */
    7576        32768, /* 0 : 256x128  */
     
    8283            2, /* 7 :   2x1    */
    8384            1, /* 8 :   1x1    */
    84     }, 
     85    },
    8586    {   /* 4:1 aspect ratio */
    8687        16384, /* 0 : 256x64   */
     
    129130#else
    130131           _grMipMapHostSize[_gr_aspect_index_table[aspect]] [lod] << (format>=GR_TEXFMT_16BIT);
    131 #endif 
     132#endif
    132133    }
    133134    return memRequired ;
     
    296297}
    297298
    298 void txNccToPal( FxU32 *pal, const GuNccTable *ncc_table ) 
     299void txNccToPal( FxU32 *pal, const GuNccTable *ncc_table )
    299300{
    300301  int i, j;
     
    304305      pal[i] = ncc_table->yRGB[i];
    305306    }
    306      
     307
    307308  for( i = 0; i < 4; i++ )
    308309    {
     
    322323      ncc_table->yRGB[i] = ( FxU8 )pal[i];
    323324    }
    324      
     325
    325326  for( i = 0; i < 4; i++ )
    326327    {
     
    331332        }
    332333    }
    333  
     334
    334335  /*
    335336  ** pack the table Y entries
     
    338339    {
    339340      FxU32 packedvalue;
    340      
     341
    341342      packedvalue  = ( ( FxU32 )( ncc_table->yRGB[i*4+0] & 0xff ) );
    342343      packedvalue |= ( ( FxU32 )( ncc_table->yRGB[i*4+1] & 0xff ) ) << 8;
     
    346347      ncc_table->packed_data[i] = packedvalue;
    347348    }
    348  
     349
    349350  /*
    350351  ** pack the table I entries
     
    353354    {
    354355      FxU32 packedvalue;
    355      
     356
    356357      packedvalue  = ( ( FxU32 )( ncc_table->iRGB[i][0] & 0x1ff ) ) << 18;
    357358      packedvalue |= ( ( FxU32 )( ncc_table->iRGB[i][1] & 0x1ff ) ) << 9;
    358359
    359360      packedvalue |= ( ( FxU32 )( ncc_table->iRGB[i][2] & 0x1ff ) ) << 0;
    360      
     361
    361362      ncc_table->packed_data[i+4] = packedvalue;
    362363    }
    363  
     364
    364365  /*
    365366  ** pack the table Q entries
     
    368369    {
    369370      FxU32 packedvalue;
    370      
     371
    371372      packedvalue  = ( ( FxU32 )( ncc_table->qRGB[i][0] & 0x1ff ) ) << 18;
    372373      packedvalue |= ( ( FxU32 )( ncc_table->qRGB[i][1] & 0x1ff ) ) << 9;;
    373374      packedvalue |= ( ( FxU32 )( ncc_table->qRGB[i][2] & 0x1ff ) ) << 0;
    374      
     375
    375376      ncc_table->packed_data[i+8] = packedvalue;
    376377    }
    377378}
    378379
    379 size_t txInit3dfInfoFromFile( FILE *file, 
     380size_t txInit3dfInfoFromFile( FILE *file,
    380381                              Gu3dfInfo *info, GrTextureFormat_t destFormat,
    381382                              int *destWidth, int *destHeight,
     
    415416
    416417  /*
    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
    418419   * function.
    419420   */
    420421  fseek( file, file_start_position, SEEK_SET );
    421  
     422
    422423  /*
    423424   * Return the memory required for this texture.
     
    452453          *destHeight = txCeilPow2( *destHeight );
    453454        }
    454      
     455
    455456      /*
    456457       * Make sure the dimensions are in range.
     
    520521   */
    521522  info->header.format   = destFormat;
    522  
     523
    523524  info->mem_required = txTexCalcMemRequired( info->header.small_lod,
    524525                                             info->header.large_lod,
     
    534535
    535536
    536 FxBool txConvertFromFile( FILE *file, Gu3dfInfo *info, 
     537FxBool txConvertFromFile( FILE *file, Gu3dfInfo *info,
    537538                          FxU32 flags, const void *palNcc )
    538539{
     
    540541  FxBool retval;
    541542  TxMip txMip;
    542  
     543
    543544  /*
    544545   * Save the current position of the input file so that we can
     
    609610
    610611  /*
    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
    612613   * level.
    613614   */
     
    620621
    621622  /*
    622    * We realy have more than one level, so. . . 
     623   * We realy have more than one level, so. . .
    623624   */
    624625#ifdef GLIDE3
     
    633634
    634635  /*
    635    * Resample the true color version of the input image to 
     636   * Resample the true color version of the input image to
    636637   * the passed in size. . . . this should be a valid
    637638   * size for the hardware to handle.
     
    653654#endif
    654655    }
    655    
    656  
     656
     657
    657658#if 0
    658659  if( _heapchk() != _HEAPOK )
     
    691692  txMipSetMipPointers( &outputMip );
    692693#endif
    693  
     694
    694695  if( ( flags & TX_TARGET_PALNCC_MASK ) == TX_TARGET_PALNCC_SOURCE )
    695696    {
    696       txMipTrueToFixedPal( &outputMip, &trueColorMip, palNcc, 
     697      txMipTrueToFixedPal( &outputMip, &trueColorMip, palNcc,
    697698                           flags & TX_FIXED_PAL_QUANT_MASK );
    698699    }
    699700  else
    700701    {
    701       txMipQuantize( &outputMip, &trueColorMip, outputMip.format, 
     702      txMipQuantize( &outputMip, &trueColorMip, outputMip.format,
    702703                     flags & TX_DITHER_MASK, flags & TX_COMPRESSION_MASK );
    703704    }
     
    710711      txPalToNcc( &info->table.nccTable, outputMip.pal );
    711712    }
    712  
     713
    713714  if( info->header.format == GR_TEXFMT_P_8 || info->header.format == GR_TEXFMT_AP_88 )
    714715    {
  • 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 $ */
    12/*
    23** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45** 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
    89** 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**
    1112** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1213** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1415** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1516** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    16 ** THE UNITED STATES. 
    17 ** 
     17** THE UNITED STATES.
     18**
    1819** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    1920**
    20 ** $Revision: 1.1 $
    21 ** $Date: 2000-02-25 00:38:01 $
     21** $Revision: 1.2 $
     22** $Date: 2001-09-05 14:30:47 $
    2223*/
    2324
     
    5253
    5354/* Definitions for image types. */
    54 #define TGA_NULL        0
    55 #define TGA_CMAP        1
    56 #define TGA_TRUE        2
    57 #define TGA_MONO        3
    58 #define TGA_CMAP_RLE    9
    59 #define TGA_TRUE_RLE    10
    60 #define TGA_MONO_RLE    11
     55#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
    6162
    6263FxBool
    6364_txReadTGAHeader( FILE *stream, FxU32 cookie, TxMip *info)
    6465{
    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);
    7576    tgaHeader->CMapType = (FxU8) ((cookie      ) & 0xFF);
    7677
    7778    // Optionally, skip the image id fields.
    7879    for (i= (tgaHeader->IDLength) & 0xFF; i; i--) {
    79         int     c;
    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        }
    8586    }
    8687
     
    9192
    9293    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;
    9596    }
    9697
    9798    switch(tgaHeader->ImgType) {
    9899    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;
    106107
    107108    case TGA_TRUE:
    108109    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
    123124    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;
    136137
    137138    default:
    138         txError("TGA Image: unsupported format");
    139         return  FXFALSE;
     139        txError("TGA Image: unsupported format");
     140        return  FXFALSE;
    140141    }
    141142    info->size = info->width*info->height*GR_TEXFMT_SIZE(info->format);
     
    147148_txReadTGAColorMap(FILE *stream, const TgaHeader *tgaHeader, FxU32 *palette)
    148149{
    149     int         cmapStart;
    150     int         cmapLength;
    151     int         cmapDepth;
    152     int         i;
     150    int     cmapStart;
     151    int     cmapLength;
     152    int     cmapDepth;
     153    int     i;
    153154
    154155    cmapStart   = tgaHeader->CMapStartLo;
     
    160161    cmapDepth   = tgaHeader->CMapDepth;
    161162
    162     if (tgaHeader->CMapType == 0) return FXTRUE;                // no colormap.
     163    if (tgaHeader->CMapType == 0) return FXTRUE;        // no colormap.
    163164
    164165    /* Validate some parameters */
    165166    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.
    171172    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;
    174175    }
    175176
    176177    // 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                 int             c;
    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.
    195196
    196197    // Verify that it's not too large.
    197198    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;
    200201    }
    201202
    202203
    203204    // printf("cmapdepth = %d, start = %d, length = %d\n", cmapDepth,
    204     //  cmapStart, cmapLength);
     205    //  cmapStart, cmapLength);
    205206    for (i=0; i<256; i++) {
    206         int     r, 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 bpp
    217                 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        }
    262263    }
    263264    return FXTRUE;
    264265}
    265266
    266 static  int     tgaRLE, tgaRLEflag, tgaRLEcount, tgaRLEsav[4];
    267 
    268 static  FxBool
     267static  int tgaRLE, tgaRLEflag, tgaRLEcount, tgaRLEsav[4];
     268
     269static  FxBool
    269270_txReadTGARLEPixel( FILE *stream, FxU8 *data, int pixsize)
    270271{
    271     int         c, i;
     272    int     c, i;
    272273
    273274    // Run length encoded data Only
    274275    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        }
    293294    }
    294295
     
    296297    tgaRLEcount--;
    297298    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];
    300301    } 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        }
    308309    }
    309310    return FXTRUE;
     
    314315{
    315316    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;
    321322    }
    322323
    323324    // Otherwise, RLE data.
    324325    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;
    329330    }
    330331    return FXTRUE;
     
    334335_txReadTGAData( FILE *stream, TxMip *info)
    335336{
    336     TgaHeader   *tgaHeader = (TgaHeader *) info->pal;
    337     int         i, stride;
    338     int         bpp;                    // bytesPerPixel
    339     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;
    341342
    342343    // printf("TxREAD TGA DATA\n");
     
    346347
    347348    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;
    358359    }
    359360
     
    363364    data   =  info->data[0];
    364365    if ((tgaHeader->ImageDescriptor & 0x20) == 0) {
    365         // Origin is lower left
    366         data   = data + (info->height-1) * stride;
    367         stride = -stride;
     366        // Origin is lower left
     367        data   = data + (info->height-1) * stride;
     368        stride = -stride;
    368369    }
    369370
    370371    /* 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;
    373374    // printf("read in color map\n");
    374375
    375376    /* Read in all the data */
    376377    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;
    382383    }
    383384
     
    390391    // printf("Repacking\n");
    391392    if (bpp == 3) {
    392         int             npixels = 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        }
    404405    }
    405406    // printf("Done\n");
    406407    if (*(FxU8 *)&BigEndian) {
    407         /* Repack 16bpp and 32bpp cases */
     408    /* Repack 16bpp and 32bpp cases */
    408409        if (bpp == 2) {
    409             int         npixels = 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);
    414415                src++;
    415             }
     416            }
    416417        }
    417418        if ((bpp == 3) || (bpp == 4)) {
    418             int         npixels = 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)       );
    426427                src++;
    427             }
     428            }
    428429        }
    429430    }
  • 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 $ */
    12
    23/*
     
    45** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    56** 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
    910** 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**
    1213** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1314** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1516** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1617** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    17 ** THE UNITED STATES. 
    18 ** 
     18** THE UNITED STATES.
     19**
    1920** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    2021**
    21 ** $Revision: 1.1 $
    22 ** $Date: 2000-02-25 00:38:01 $
     22** $Revision: 1.2 $
     23** $Date: 2001-09-05 14:30:47 $
    2324*/
    2425
     
    3334
    3435char *Format_Name[] = {
    35          "rgb332",                              // GR_TEXFMT_RGB_332 
     36         "rgb332",                              // GR_TEXFMT_RGB_332
    3637         "yiq",                                 // GR_TEXFMT_YIQ_422
    3738         "a8",                                  // GR_TEXFMT_ALPHA_8
     
    136137txYABtoPal256(long *palette, const long* yabTable)
    137138{
    138         // Convert YAB table to a 256 color palette 
     139        // Convert YAB table to a 256 color palette
    139140        // Assume yabTable[] has first 16Y's, 12 A's, 12 B's
    140141
     
    268269txNearestColor(long ir, long ig, long ib, const FxU32 *pal, int ncolors)
    269270{
    270         int             i, d; 
     271        int             i, d;
    271272        int             mindist, minpos;                // closest distance to input
    272273
     
    274275                txPanic("Bad explode\n");
    275276
    276         mindist = DISTANCE((*pal>>16)&0xff, (*pal>>8)&0xff, (*pal)&0xff, 
     277        mindist = DISTANCE((*pal>>16)&0xff, (*pal>>8)&0xff, (*pal)&0xff,
    277278                ir, ig, ib);
    278279        minpos  = 0;
     
    281282        /* Find closest color */
    282283        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,
    284285                        ir, ig, ib);
    285286                if (d < mindist) { mindist = d; minpos = i; }
     
    327328
    328329void
    329 txRectCopy(FxU8 *dst, int dstStride, const FxU8 *src, int srcStride, 
     330txRectCopy(FxU8 *dst, int dstStride, const FxU8 *src, int srcStride,
    330331        int width, int height)
    331332{
     
    414415{
    415416        /* Strip the pathname and leave us with filename.ext */
    416         char    *s; 
     417        char    *s;
    417418        const   char *p, *slash;
    418419
     
    428429        for (s = basename; *s; s++);
    429430
    430         // Walk backwards; replace any . with 0 
     431        // Walk backwards; replace any . with 0
    431432        while (--s >= basename) {
    432433                if (*s == '.') {*s = 0; break;}
     
    463464        }
    464465
    465         if (ext) 
     466        if (ext)
    466467            while (*ext)  *extname++ = *ext++;
    467        
     468
    468469        *extname = 0;
    469470}
  • 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 $ */
    12/*
    23** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45** 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
    89** 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**
    1112** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1213** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1415** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1516** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    16 ** THE UNITED STATES. 
    17 ** 
     17** THE UNITED STATES.
     18**
    1819** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    1920**
    20 ** $Revision: 1.1 $
    21 ** $Date: 2000-02-25 00:38:02 $
     21** $Revision: 1.2 $
     22** $Date: 2001-09-05 14:30:47 $
    2223*/
    2324
  • 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 $ */
    12/*
    23** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
    34** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
    45** 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
    89** 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**
    1112** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
    1213** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
     
    1415** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
    1516** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
    16 ** THE UNITED STATES. 
    17 ** 
     17** THE UNITED STATES.
     18**
    1819** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
    1920*/
     
    3031 */
    3132static  char *Version = "1.1";
    32 static char* aspect_names[] = { "8 1", "4 1", "2 1", "1 1", 
     33static char* aspect_names[] = { "8 1", "4 1", "2 1", "1 1",
    3334                                                        "1 2", "1 4", "1 8" };
    3435
    3536/*************************************** tga files ****************************/
    36 /* 
     37/*
    3738 * Write a tga file from an ARGB8888 mipmap.
    3839 */
    39 static FxBool 
     40static FxBool
    4041txWriteTGA( FILE *stream, TxMip *txMip)
    4142{
     
    7374        return FXFALSE;
    7475    }
    75    
     76
    7677    outW = txMip->width;
    7778    outH = txMip->height;
    7879    if (txMip->depth > 1) outW += outW/2;
    79    
     80
    8081    tgaHeader.IDLength         = 0;
    8182    tgaHeader.ColorMapType     = 0;
     
    9697    tgaHeader.PixelDepth       = 32;
    9798    tgaHeader.ImageDescriptor  = 0x20;          // image always right side up.
    98        
     99
    99100
    100101    if ( fwrite( &tgaHeader, 1, 18, stream ) != 18 ) {
     
    110111
    111112    /* 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,
    113114        txMip->width * 4, txMip->height);
    114115
     
    116117
    117118    /* 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;
    120121    for (i=1; i< txMip->depth; i++) {
    121122        // printf("Copying: level = %d\n", i);
     
    129130    data32 = (FxU32 *) data;
    130131    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);
    135136        data32++;
    136137    }
     
    142143/* Write word, msb first */
    143144
    144 static FxBool 
     145static FxBool
    145146_txWrite16 (FILE *stream, FxU16 data)
    146147{
     
    155156/* Write long word, msb first */
    156157
    157 static FxBool 
     158static FxBool
    158159_txWrite32 (FILE *stream, FxU32 data)
    159160{
     
    169170
    170171/* Write NCC table */
    171 static FxBool 
     172static FxBool
    172173_txWrite3dfNCCTable (FILE *stream, FxU32 *yab)
    173174{
     
    177178        if (!_txWrite16 (stream, (FxU16) (yab[i] & 0x00ff))) return FXFALSE;
    178179
    179     for (i = 0; i < 12; i++) 
     180    for (i = 0; i < 12; i++)
    180181        if (!_txWrite16 (stream, (FxU16) (yab[16+i] & 0xffff))) return FXFALSE;
    181182
    182     for (i = 0; i < 12; i++) 
     183    for (i = 0; i < 12; i++)
    183184        if (!_txWrite16 (stream, (FxU16) (yab[28+i] & 0xffff))) return FXFALSE;
    184185
     
    197198}
    198199
    199 static FxBool 
     200static FxBool
    200201txWrite3df (FILE *stream, TxMip *txMip)
    201202{
     
    213214
    214215    // printf("Writing header...\n");
    215     if (EOF == fprintf (stream, 
     216    if (EOF == fprintf (stream,
    216217        "3df v%s\n%s\nlod range: %d %d\naspect ratio: %s\n",
    217         Version, 
     218        Version,
    218219        Format_Name[txMip->format],
    219220        small_lod,
     
    226227        (txMip->format == GR_TEXFMT_AYIQ_8422)) {
    227228                if (!_txWrite3dfNCCTable (stream, txMip->pal)) return FXFALSE;
    228     } 
     229    }
    229230
    230231    else if ((txMip->format == GR_TEXFMT_P_8) ||
    231232        (txMip->format == GR_TEXFMT_AP_88)) {
    232233                if (!_txWrite3dfPalTable (stream, txMip->pal)) return FXFALSE;
    233     } 
     234    }
    234235
    235236
     
    289290        if( txVerbose )
    290291          {
    291             printf("Writing file \"%s\" (format: %s)\n", 
     292            printf("Writing file \"%s\" (format: %s)\n",
    292293                   filename, Format_Name[txMip->format]);
    293294          }
     
    380381      break;
    381382    case TX_WRITE_TGA:
    382       if( mip.format == GR_TEXFMT_YIQ_422 || 
     383      if( mip.format == GR_TEXFMT_YIQ_422 ||
    383384          mip.format == GR_TEXFMT_AYIQ_8422 )
    384385        {
Note: See TracChangeset for help on using the changeset viewer.