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