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