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