1 /*---------------------------------------------------------------------*
2 Project: tc library
3 File: TCCreateTPL.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: TCCreateTPL.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 3 4/11/01 3:08p John
24 Updated header copyrights and pathname.
25
26 2 3/17/00 1:19p Mikepc
27 change tc to use indices numbered from 0.
28
29 1 12/03/99 3:45p Ryan
30
31 16 10/08/99 2:45p Mikepc
32 update for tplConv portability: altered data structures, replaced
33 references to 'read tga code' with ' *fileFn, removed redundant
34 functions. Changed some file conversion paths.
35
36 15 9/16/99 8:47p Mikepc
37 updated code for auto-palette generation
38
39 14 9/07/99 3:05p Mikepc
40 removed default directory restriction from ConvSi2Dds(). tga files can
41 now originate in any directory.
42
43 13 9/07/99 10:20a Mikepc
44 changed a couple of comments to improve clarity.
45
46 12 9/02/99 11:12a Mikepc
47 some code re-organization between files.
48 added code (verify.cpp) to invoke s3tc.exe from within tc program.
49 changed some routines to accommodate the new texture creation path.
50
51 11 8/26/99 4:59p Mikepc
52 renamed file extensions from .c to .cpp.
53 .cpp extension allows addition of namespace protection to remove
54 potential name collisions with tool code. Exceptions are CreateTplFile
55 and QuickConvert. These are extern "C" linked.
56
57 10 8/26/99 11:38a Mikepc
58
59 9 8/26/99 11:03a Mikepc
60 tplCon rewrite for efficient memory usage, batch file processing
61 ability.
62
63 $NoKeywords: $
64
65 -----------------------------------------------------------------------*/
66
67 #include <string.h>
68
69 #include <charPipeline/tc/TCCreateTPL.h>
70 #include <charPipeline/tc/TCCommon.h>
71
72 #include "TCScriptFile.h"
73 #include "TCVerify.h"
74 #include "TCImageList.h"
75 #include "TCPaletteList.h"
76 #include "TCTPLToolbox.h"
77 #include "TCMem.h"
78
79 #pragma warning(disable : 4996)
80
81 /*>*******************************(*)*******************************<*/
82 // wrapper function to perform the major .tpl creation steps
83 /*>*******************************(*)*******************************<*/
TCCreateTplFile(char * srcTxtFile,char * dstTplFile)84 void TCCreateTplFile( char* srcTxtFile, char* dstTplFile )
85 {
86 char* cPtr = NULL;
87 char* tmpTpl = NULL;
88 int len = 0;
89
90
91 // read a text file and generate SrcImage, Image, Palette and Texture lists
92 TCReadTplTxtFile( srcTxtFile );
93
94
95 // at this point, all source files have been opened once and header
96 // information extracted.
97 // SrcImage, Image, Palette and Texture lists have been created.
98
99
100 // do a 1st pass to verify list info.
101 // set image and palette base sizes from SrcImage list
102 TCVerifyLists();
103
104
105 // set image layer values from source files
106 // but dont fetch image data yet.
107 TCSetImageValues();
108
109
110 // create or copy palette data from source files,
111 // filling in each palette's PalEntry array
112 TCSetPalettes();
113
114
115 // compute all .tpl file, data block sizes; compute all offsets within each .tpl
116 // descriptor block. Information is stored within Image/Palette/Texture structures
117 // in ImHead, PlHead, TxHead lists
118 TCComputeTplSizes();
119
120
121 // check for a 3-letter extension; if none is present, append one
122
123 len = strlen( dstTplFile ) + 5; // large enough to add ".tpl" if needed
124 TCAssertMsg( (len), "TCCreateTplFile: empty string for .tpl file name\n" );
125
126 tmpTpl = (char*)TCMalloc( len );
127
128 strcpy( tmpTpl, dstTplFile );
129
130 cPtr = tmpTpl + strlen( tmpTpl ) - 4;
131
132 // no 3-letter extension
133 if( *cPtr != '.' )
134 {
135 cPtr += 4;
136 }
137
138 // append/overwrite a ".tpl" extension to the filename
139 strcpy( cPtr, ".tpl" );
140
141 // create the .tpl file
142 TCWriteTplFile( tmpTpl );
143
144
145 // free SrcImage, Image, Palette, Texture lists
146 // and all other allocated memory (includes tmpTpl)
147 TCFreeMem();
148
149 }
150
151 /*>*******************************(*)*******************************<*/
152
153