]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake2/qdata_heretic2/pics.c
Merge branch 'master' into divVerent/farplanedist-sky-fix
[xonotic/netradiant.git] / tools / quake2 / qdata_heretic2 / pics.c
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22
23 #include "qdata.h"
24
25 byte            *byteimage, *lbmpalette;
26 int byteimagewidth, byteimageheight;
27
28 qboolean TrueColorImage;
29 unsigned        *longimage;
30 int longimagewidth, longimageheight;
31
32 char pic_prefix[1024];
33 extern char        *g_outputDir;
34
35 /*
36    ===============
37    Cmd_Pic
38    ===============
39  */
40
41 void Cmd_Pic( void ){
42         int xl,yl,xh,yh,w,h;
43         byte            *dest, *source;
44         int flags, value, contents;
45         char lumpname[128];
46         char animname[128];
47         byte buffer[256 * 256];
48         unsigned bufferl[256 * 256];
49         char filename[1024];
50         unsigned        *destl, *sourcel;
51         int linedelta, x, y;
52         int size;
53         miptex_t        *qtex;
54         miptex32_t      *qtex32;
55         float scale_x, scale_y;
56
57         GetScriptToken( false );
58         strcpy( lumpname, token );
59
60         GetScriptToken( false );
61         xl = atoi( token );
62         GetScriptToken( false );
63         yl = atoi( token );
64         GetScriptToken( false );
65         w = atoi( token );
66         GetScriptToken( false );
67         h = atoi( token );
68
69         total_x += w;
70         total_y += h;
71         total_textures++;
72
73         if ( ( w & 7 ) || ( h & 7 ) ) {
74                 Error( "line %i: miptex sizes must be multiples of 8", scriptline );
75         }
76
77         flags = 0;
78         contents = 0;
79         value = 0;
80
81         animname[0] = 0;
82
83         scale_x = scale_y = 0.5;
84
85         if ( TrueColorImage ) {
86                 sprintf( filename, "%spics/%s/%s.m32", g_outputDir, pic_prefix, lumpname );
87                 if ( g_release ) {
88                         return; // textures are only released by $maps
89
90                 }
91                 xh = xl + w;
92                 yh = yl + h;
93
94                 if ( xl >= longimagewidth || xh > longimagewidth ||
95                          yl >= longimageheight || yh > longimageheight ) {
96                         Error( "line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,longimagewidth,longimageheight );
97                 }
98
99                 sourcel = longimage + ( yl * longimagewidth ) + xl;
100                 destl = bufferl;
101                 linedelta = ( longimagewidth - w );
102
103                 for ( y = yl ; y < yh ; y++ )
104                 {
105                         for ( x = xl ; x < xh ; x++ )
106                         {
107                                 *destl++ = *sourcel++;  // RGBA
108                         }
109                         sourcel += linedelta;
110                 }
111
112                 qtex32 = CreateMip32( bufferl, w, h, &size, false );
113
114                 qtex32->flags |= LittleLong( flags );
115                 qtex32->contents = contents;
116                 qtex32->value = value;
117                 qtex32->scale_x = scale_x;
118                 qtex32->scale_y = scale_y;
119                 sprintf( qtex32->name, "%s/%s", pic_prefix, lumpname );
120                 if ( animname[0] ) {
121                         sprintf( qtex32->animname, "%s/%s", pic_prefix, animname );
122                 }
123
124                 //
125                 // write it out
126                 //
127                 printf( "writing %s\n", filename );
128                 SaveFile( filename, (byte *)qtex32, size );
129
130                 free( qtex32 );
131         }
132         else
133         {
134                 sprintf( filename, "%spics/%s/%s.m8", g_outputDir, pic_prefix, lumpname );
135                 if ( g_release ) {
136                         return; // textures are only released by $maps
137
138                 }
139                 xh = xl + w;
140                 yh = yl + h;
141
142                 if ( xl >= byteimagewidth || xh > byteimagewidth ||
143                          yl >= byteimageheight || yh > byteimageheight ) {
144                         Error( "line %i: bad clip dimmensions (%d,%d) (%d,%d) > image (%d,%d)", scriptline, xl,yl,w,h,byteimagewidth,byteimageheight );
145                 }
146
147                 source = byteimage + yl * byteimagewidth + xl;
148                 dest = buffer;
149                 linedelta = byteimagewidth - w;
150
151                 for ( y = yl ; y < yh ; y++ )
152                 {
153                         for ( x = xl ; x < xh ; x++ )
154                         {
155                                 *dest++ = *source++;
156                         }
157                         source += linedelta;
158                 }
159
160                 qtex = CreateMip( buffer, w, h, lbmpalette, &size, false );
161
162                 qtex->flags = flags;
163                 qtex->contents = contents;
164                 qtex->value = value;
165                 sprintf( qtex->name, "%s/%s", pic_prefix, lumpname );
166                 if ( animname[0] ) {
167                         sprintf( qtex->animname, "%s/%s", pic_prefix, animname );
168                 }
169
170                 //
171                 // write it out
172                 //
173                 printf( "writing %s\n", filename );
174                 SaveFile( filename, (byte *)qtex, size );
175
176                 free( qtex );
177         }
178 }
179
180
181 /*
182    ===============
183    Cmd_picdir
184    ===============
185  */
186 void Cmd_Picdir( void ){
187         char filename[1024];
188
189         GetScriptToken( false );
190         strcpy( pic_prefix, token );
191         // create the directory if needed
192         sprintf( filename, "%sPics", g_outputDir );
193         Q_mkdir( filename );
194         sprintf( filename, "%sPics/%s", g_outputDir, pic_prefix );
195         Q_mkdir( filename );
196 }