1 /*---------------------------------------------------------------------*
2 Project: tc library
3 File: TCSrcImageList.cpp
4
5 Copyright 1998-2001 Nintendo. All rights reserved.
6
7 These coded instructions, statements and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 Change History:
14
15 $Log: TCSrcImageList.cpp,v $
16 Revision 1.2 2008/05/23 04:26:10 iwai_yuma
17 Improved for handling of VC2005.
18
19 Revision 1.1 2006/02/17 09:01:53 mitu
20 1st version
21
22
23 4 4/11/01 3:08p John
24 Updated header copyrights and pathname.
25
26 3 8/10/00 6:03p Mikepc
27
28 2 3/17/00 1:19p Mikepc
29 change tc to use indices numbered from 0.
30
31 1 12/03/99 3:45p Ryan
32
33 11 10/08/99 2:45p Mikepc
34 update for tplConv portability: altered data structures, replaced
35 references to 'read tga code' with ' *fileFn, removed redundant
36 functions. Changed some file conversion paths.
37
38 10 10/01/99 12:20p Mikepc
39 Integrated s3.lib code to generate s3 textures 'on the fly' as direct
40 draw surfaces. Removed .dds file reading code. Changed CMP texture
41 generation 'order of operations' to- rgb layer->s3->CMPR format per
42 mipmap LOD.
43
44 9 9/16/99 8:47p Mikepc
45 updated code for auto-palette generation
46
47 8 9/02/99 11:12a Mikepc
48 some code re-organization between files.
49 added code (verify.cpp) to invoke s3tc.exe from within tc program.
50 changed some routines to accommodate the new texture creation path.
51
52 7 8/26/99 4:59p Mikepc
53 renamed file extensions from .c to .cpp.
54 .cpp extension allows addition of namespace protection to remove
55 potential name collisions with tool code. Exceptions are CreateTplFile
56 and QuickConvert. These are extern "C" linked.
57
58 6 8/26/99 11:38a Mikepc
59
60 5 8/26/99 11:03a Mikepc
61 tplCon rewrite for efficient memory usage, batch file processing
62 ability.
63
64 $NoKeywords: $
65
66 -----------------------------------------------------------------------*/
67
68 #include <string.h>
69
70 #include <charPipeline/tc/TCCommon.h>
71
72 #include "TCSrcImageList.h"
73 #include "TCMem.h"
74
75 #pragma warning(disable : 4996)
76
77 /********************************/
78 // internally managed global SrcImage linked list variables
79 TCSrcImage* SiHead = NULL;
80
81 /*>*******************************(*)*******************************<*/
82 static void TCSwapSrcImage ( TCSrcImage* src, TCSrcImage* dst );
83
84 /*>*******************************(*)*******************************<*/
85 // create a new source image; attach it to the tail of SiHead's list
86 /*>*******************************(*)*******************************<*/
TCNewSrcImage(void)87 TCSrcImage* TCNewSrcImage ( void )
88 {
89 TCSrcImage* newSi, *tail;
90
91
92 newSi = (TCSrcImage*)TCCalloc( 1, sizeof(TCSrcImage));
93
94 if( SiHead == NULL )
95 {
96 SiHead = newSi;
97 }
98 else
99 {
100 tail = SiHead;
101 while( tail->next )
102 {
103 tail = tail->next;
104 }
105
106 tail->next = newSi;
107 newSi->prev = tail;
108 newSi->next = NULL;
109 }
110
111 return newSi;
112 }
113
114 /*>*******************************(*)*******************************<*/
115 // sort indices from lowest to highest
116 // check for 0 index, missing indices, duplicate indices
117 /*>*******************************(*)*******************************<*/
TCSortSrcImageByIndex(void)118 void TCSortSrcImageByIndex ( void )
119 {
120 TCSrcImage* thisSi, *nextSi;
121
122
123 if( (SiHead == NULL) || (SiHead->next == NULL) )
124 {
125 return;
126 }
127
128 thisSi = SiHead;
129 while( thisSi->next )
130 {
131 nextSi = thisSi->next;
132
133 if( nextSi->index < thisSi->index )
134 {
135 // swap just the data, not the pointers
136 TCSwapSrcImage( thisSi, nextSi );
137
138 thisSi = SiHead;
139 continue;
140 }
141
142 thisSi = thisSi->next;
143 }
144 }
145
146 /*>*******************************(*)*******************************<*/
TCSwapSrcImage(TCSrcImage * src,TCSrcImage * dst)147 static void TCSwapSrcImage ( TCSrcImage* src, TCSrcImage* dst )
148 {
149 TCSrcImage siTmp;
150
151
152 strcpy( siTmp.fileName, src->fileName );
153 siTmp.index = src->index;
154
155 strcpy( src->fileName, dst->fileName );
156 src->index = dst->index;
157
158 strcpy( dst->fileName, siTmp.fileName );
159 dst->index = siTmp.index;
160 }
161
162 /*>*******************************(*)*******************************<*/
TCFindSrcImageByIndex(u32 index)163 TCSrcImage* TCFindSrcImageByIndex ( u32 index )
164 {
165 TCSrcImage* siTmp;
166
167
168 if( index == TC_UNUSED )
169 return NULL;
170
171 siTmp = SiHead;
172 while( siTmp )
173 {
174 if( siTmp->index == index )
175 {
176 return siTmp;
177 }
178 siTmp = siTmp->next;
179 }
180
181 TCErrorMsg( "TCFindSrcImageByIndex: source image %d is not part of source image list\n", index );
182 return NULL;
183 }
184
185 /*>*******************************(*)*******************************<*/
186 // given a file name, check for the existence of the file and determine
187 // its attributes.
188 // perform initial error checks
189 /*>*******************************(*)*******************************<*/
TCSetSrcImageFromFile(TCSrcImage * newSi,char * fileName,u32 index)190 void TCSetSrcImageFromFile ( TCSrcImage* newSi, char* fileName, u32 index )
191 {
192
193 TCAssertMsg( (newSi != NULL), "TCSetSrcImageFromFile: NULL TCSrcImage ptr\n" );
194 TCAssertMsg( (fileName != NULL), "TCSetSrcImageFromFile: NULL file name\n" );
195 TCAssertMsg( (*fileName != '\0'), "TCSetSrcImageFromFile: NULL file name\n" );
196
197
198 strcpy( newSi->fileName, fileName );
199 newSi->index = index;
200 }
201
202 /*>*******************************(*)*******************************<*/
203
204
205
206
207
208
209
210
211
212