1 /*---------------------------------------------------------------------*
2 Project: tc library
3 File: TCVerify.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: TCVerify.cpp,v $
16 Revision 1.1 2006/02/17 09:01:53 mitu
17 1st version
18
19
20 3 4/11/01 3:08p John
21 Updated header copyrights and pathname.
22
23 2 3/17/00 1:19p Mikepc
24 change tc to use indices numbered from 0.
25
26 1 12/03/99 3:45p Ryan
27
28 3 10/08/99 2:45p Mikepc
29 update for tplConv portability: altered data structures, replaced
30 references to 'read tga code' with ' *fileFn, removed redundant
31 functions. Changed some file conversion paths.
32
33 2 9/16/99 8:47p Mikepc
34 updated code for auto-palette generation
35
36 1 9/02/99 10:57a Mikepc
37 contains code for VerifyLists() ( formerly in convert.cpp ) that checks
38 list contents against each other and against real files
39
40 $NoKeywords: $
41
42 -----------------------------------------------------------------------*/
43
44 #include <stdio.h>
45
46 #include <charPipeline/tc/TCCommon.h>
47
48 #include "TCVerify.h"
49 #include "TCPaletteList.h"
50 #include "TCImageList.h"
51 #include "TCSrcImageList.h"
52 #include "TCTextureList.h"
53
54 /*>*******************************(*)*******************************<*/
55 static void TCSortListsByIndex ( void );
56
57 /*>*******************************(*)*******************************<*/
58 // compare SiHead, ImHead, PlHead, TxHead lists to ensure that all index
59 // references are valid
60 /*>*******************************(*)*******************************<*/
TCVerifyLists(void)61 void TCVerifyLists ( void )
62 {
63 TCSrcImage* siPtr = SiHead;
64 TCImage* imPtr = ImHead;
65 TCPalette* plPtr = PlHead;
66 TCTexture* txPtr = TxHead;
67 FILE* fp;
68
69
70 // sort each of SiHead, ImHead, PlHead, TxHead in ascending order
71 TCSortListsByIndex();
72
73 // verify that each source image exists
74 // note: extensions will be checked when files are opened for conversion
75 while( siPtr )
76 {
77 if( (fp = fopen( siPtr->fileName, "rb" )) == NULL )
78 {
79 TCErrorMsg( "TCVerifyLists: unable to open file %s for read\n", siPtr->fileName );
80 return;
81 }
82 fclose( fp );
83 siPtr = siPtr->next;
84 }
85
86 // verify that each image has a corresponding source image
87 while( imPtr )
88 {
89 // find the source image corresponding to the color index
90 // color layer is mandatory
91 if( (siPtr = TCFindSrcImageByIndex( imPtr->colorSrcImage )) == NULL )
92 {
93 TCErrorMsg( "TCVerifyLists: no matching source image for image %d color layer\n", imPtr->index );
94 return;
95 }
96
97 // alpha layer is optional
98 if( imPtr->alphaSrcImage != TC_UNUSED )
99 {
100 if( (siPtr = TCFindSrcImageByIndex( imPtr->alphaSrcImage )) == NULL )
101 {
102 TCErrorMsg( "TCVerifyLists: no matching source image for image %d alpha layer\n", imPtr->index );
103 return;
104 }
105 }
106
107 imPtr = imPtr->next;
108
109 } // end while( imPtr )
110
111
112 // verify each palette
113 while( plPtr )
114 {
115 // find the source image corresponding to the palette image index
116 if( (siPtr = TCFindSrcImageByIndex( plPtr->srcImage )) == NULL )
117 {
118 TCErrorMsg( "TCVerifyLists: no matching source image for palette %d srcImage\n", plPtr->index);
119 return;
120 }
121 plPtr = plPtr->next;
122
123 } // end while( plPtr )
124
125
126 // verify each texture
127 txPtr = TxHead;
128 while( txPtr )
129 {
130 // texture->image is mandatory
131 if( (imPtr = TCFindImageByIndex( txPtr->image )) == NULL )
132 {
133 TCErrorMsg( "TCVerifyLists: no matching image for texture %d\n", txPtr->index);
134 return;
135 }
136
137 // palette is optional
138 if( txPtr->palette != TC_UNUSED )
139 {
140 if( (plPtr = TCFindPaletteByIndex( txPtr->palette )) == NULL )
141 {
142 TCErrorMsg( "TCVerifyLists: no matching palette for texture %d\n", txPtr->index);
143 return;
144 }
145 }
146
147 txPtr = txPtr->next;
148 } // end while( txPtr )
149 }
150
151 /*>*******************************(*)*******************************<*/
152 // sort SiHead, ImHead, PlHead, TxHead into ascending order
153 /*>*******************************(*)*******************************<*/
TCSortListsByIndex(void)154 static void TCSortListsByIndex ( void )
155 {
156 TCSortSrcImageByIndex();
157 TCSortImageByIndex();
158 TCSortPaletteByIndex();
159 TCSortTextureByIndex();
160 }
161
162 /*>*******************************(*)*******************************<*/
163