source: trunk/src/opengl/glide/cvg/texus/rgt.c

Last change on this file was 6653, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 4.9 KB
Line 
1/* $Id: rgt.c,v 1.2 2001-09-05 14:30:46 bird Exp $ */
2
3/*
4** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
5** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
6** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
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
10** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
11** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
12**
13** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
14** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
15** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
16** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
17** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
18** THE UNITED STATES.
19**
20** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
21**
22** $Revision: 1.2 $
23** $Date: 2001-09-05 14:30:46 $
24**
25*/
26
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <math.h>
31
32#include "texusint.h"
33
34const FxU16 IMAGIC = 0x01DA;
35const FxU16 ITYPE_RLE = 0x01;
36const FxU16 ITYPE_NCC = 0x02;
37const FxU16 ITYPE_BGR = 0x04;
38const FxU16 ITYPE_RGT = 0x08;
39
40typedef struct _rgtHeader{
41 FxU16 magic;
42 FxU8 typeLo;
43 FxU8 typeHi;
44 FxU8 dimLo;
45 FxU8 dimHi;
46 FxU8 sizeXLo;
47 FxU8 sizeXHi;
48 FxU8 sizeYLo;
49 FxU8 sizeYHi;
50 FxU8 sizeZLo;
51 FxU8 sizeZHigh;
52} RgtHeader;
53
54
55
56static void swapShorts(unsigned short *array, long length)
57{
58 unsigned short s;
59 while (length--) {
60 s = *array;
61 *array++ = (s << 8) | (s>>8);
62 }
63}
64
65static void swapLongs(unsigned int *array, long length)
66{
67 unsigned int s;
68 while (length--) {
69 s = *array;
70 *array++ = (s << 24) | ((s >> 8)&0xFF00) |
71 ((s&0xFF00) << 8) | (s>>24);
72 }
73}
74
75// just swap RGB into BGR (leave MSB undefined)
76static void swapRGB(unsigned int *array, long length)
77{
78 unsigned int s;
79 while (length--) {
80 s = *array;
81 *array++ = (s << 16) | (s & 0xFF00) | (s>>16);
82 }
83}
84
85
86FxBool
87_txReadRGTHeader( FILE *stream, FxU32 cookie, TxMip *info)
88{
89 RgtHeader *rgtHeader = (RgtHeader *) info->pal;
90
91 rgtHeader->magic = (FxU16) cookie;
92 if ( stream == NULL ) {
93 txPanic("RGT file: Bad file handle.");
94 return FXFALSE;
95 }
96
97 if ( fread( &(rgtHeader->typeLo), 1, sizeof(RgtHeader)-2, stream ) != 10 ) {
98 txPanic("RGT file: Unexpected end of file.");
99 return FXFALSE;
100 }
101 if (rgtHeader->magic == IMAGIC) {
102 // Needs byte swapping; don't swap magic cookie.
103 swapShorts((FxU16 *) &(rgtHeader->typeLo), 5);
104 }
105
106
107 info->format = GR_TEXFMT_ARGB_8888;
108 info->width = rgtHeader->sizeXHi << 8 | rgtHeader->sizeXLo;
109 info->height = rgtHeader->sizeYHi << 8 | rgtHeader->sizeYLo;
110 info->depth = 1;
111 info->size = info->width * info->height * 4;
112 if( txVerbose )
113 {
114 printf("Magic: %.04x w = %d, h = %d, z = %d, typehi = %d, typelo = %d, swap=%d\n", rgtHeader->magic,
115 info->width, info->height, rgtHeader->sizeZLo, rgtHeader->typeHi, rgtHeader->typeLo, rgtHeader->magic == IMAGIC);
116 }
117 return FXTRUE;
118}
119
120// RGT is RGBA in memory (low byte to high byte), or ABGR in a register
121
122FxBool
123_txReadRGTData( FILE *stream, TxMip *info)
124{
125 RgtHeader *rgtHeader = (RgtHeader *) info->pal;
126 FxU16 type = (rgtHeader->typeHi);
127 FxU16 swap = (rgtHeader->magic == IMAGIC);
128 int x, y;
129
130 if ( stream == NULL ) {
131 txPanic("RGT file: Bad file handle.");
132 return FXFALSE;
133 }
134 if (type & ITYPE_NCC) {
135 txPanic("RGT file: RGT NCC files not supported.");
136 return FXFALSE;
137 }
138 if (type & ITYPE_RLE) {
139 txPanic("RGT file: RGT RLE files not supported.");
140 return FXFALSE;
141 }
142
143 // load rgt, rgt's are bottom up
144 for ( y = 0; y < info->height; y++ ) {
145 FxU32 *data32;
146 int r, g, b, a;
147
148 data32 = (FxU32 *) info->data[0];
149 data32 += info->width * (info->height -1 - y);
150
151 // Read scanline worth of data.
152 for (x=0; x < info->width; x++) {
153 /* Read b, g, r, a from disk.*/
154 r = getc( stream );
155 g = getc( stream );
156 b = getc( stream );
157 a = getc( stream );
158
159 if ( a == EOF ) {
160 txPanic("RGT file: Unexpected End of File.");
161 return FXFALSE;
162 }
163 data32[x] = (a << 24) | (r << 16) | (g << 8) | b;
164 }
165
166#if 1
167 if (swap) {
168 swapRGB((unsigned int *)data32, (long)info->width);
169 }
170#endif
171
172#if 0
173 if (type & ITYPE_BGR) {
174 /* Swap just blue & red channels */
175 swapRGB(data32, info->width);
176 }
177#endif
178 }
179 return FXTRUE;
180}
Note: See TracBrowser for help on using the repository browser.