/[projet1]/public/pc/tools/osdk/main/pictconv/sources/pictconv.cpp
Defence Force logotype

Contents of /public/pc/tools/osdk/main/pictconv/sources/pictconv.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1260 - (show annotations)
Sat Feb 14 20:26:49 2015 UTC (4 years, 7 months ago) by dbug
File size: 12313 byte(s)
PictConv 0.21
- Added support for 32bit picture, to handle things like masking/opacity in the picture formats
- The -a1 mode will generate bytes with null value for blocks of 6 pixels with transparent alpha values (only active in monochrome or AIC conversion modes)
- Added the -f7 conversion mode for Oric pictures using the AIC coloring method.

1 /*==============================================================================
2
3 PictConv
4
5 ==[Description]=================================================================
6
7 ==[History]=====================================================================
8
9 ==[ToDo]========================================================================
10
11 * Upgrade to a more recent version of FreeImage
12
13 ==============================================================================*/
14
15 #include <stdio.h>
16
17 #include "FreeImage.h"
18
19 #include "infos.h"
20
21 #include "common.h"
22
23 #include "defines.h"
24 #include "hires.h"
25 #include "image.h"
26
27 //#include <conio.h>
28
29 int RunUnitTests();
30
31
32 #define NB_ARG 2
33
34
35 int __cdecl main(int argc,char *argv[])
36 {
37 //
38 // Some initialization for the common library
39 //
40 SetApplicationParameters(
41 "PictConv",
42 TOOL_VERSION_MAJOR,
43 TOOL_VERSION_MINOR,
44 #ifdef _WIN32
45 "{ApplicationName} - Version {ApplicationVersion} - ("__DATE__" / "__TIME__") - This program is a part of the OSDK\r\n"
46 #else
47 "{ApplicationName} - Version {ApplicationVersion} - (Missing Date) - This program is a part of the OSDK\r\n"
48 #endif
49 "\r\n"
50 "Author:\r\n"
51 " (c) 2002-2015 Pointier Mickael \r\n"
52 "\r\n"
53 "Usage:\r\n"
54 " {ApplicationName} [switches] <source picture> <destination file>\r\n"
55 "\r\n"
56 "Switches:\r\n"
57 " -mn Machine\r\n"
58 " -m0 => Oric [default]\r\n"
59 " -m1 => Atari ST\r\n"
60 "\r\n"
61 " -fn Rendering format (machine dependent)\r\n"
62 " -Oric:\r\n"
63 " -f0 => to hires monochrom format [default]\r\n"
64 " -f0z => to hires monochrom format (do not set bit 6) *** Not working in this version ***\r\n"
65 " -f1 => precolored picture\r\n"
66 " -f2 => RVB conversion\r\n"
67 " -f3 => Twilight masks\r\n"
68 " -f4 => RB conversion\r\n"
69 " -f5 => CHAR generator\r\n"
70 " -f6 => Sam method (Img2Oric)\r\n"
71 " -f7 => AIC encoding\r\n"
72 " -Atari ST:\r\n"
73 " -f0 => Single palette format [default]\r\n"
74 " -f1 => Multi palette format\r\n"
75 "\r\n"
76 " -pn Palette management\r\n"
77 " -p0 => Generate a palette automatically [default]\r\n"
78 " -p1 => Last line of the picture contains the palette\r\n"
79 " -p2 => Last pixels of each line of the picture contains the palette\r\n"
80 "\r\n"
81 " -dn Dithering mode\r\n"
82 " -d0 => no dithering [default]\r\n"
83 " -d1 => alternate (01010101) dithering\r\n"
84 " -d2 => ordered dither\r\n"
85 " -d3 => riemersma\r\n"
86 "\r\n"
87 " -an Alpha mode\r\n"
88 " -a0 => no transparency [default]\r\n"
89 " -a1 => encode alpha as zeroes\r\n"
90 "\r\n"
91 " -on Output file format\r\n"
92 " -o0 => TAP (with a header that load in 0xa000)\r\n"
93 " -o1 => TAP (with a BASIC program that switch to HIRES then load)\r\n"
94 " -o2 => RAW data\r\n"
95 " -o3[label] => .C format with labels and .h for 'extern' declaration\r\n"
96 " -o4[label] => .S format with labels and .h for 'extern' declaration\r\n"
97 " -o5 => Picture format (PNG, BMP, ...)\r\n"
98 " -o6 => X+Y+RAW\r\n"
99 " -o7 => Palette followed by picture data\r\n"
100 " -o8[line:step] => .BAS format \r\n"
101 "\r\n"
102 " -tn Testing mode\r\n"
103 " -t0 => Testing disabled [default]\r\n"
104 " -t1 => Testing enabled\r\n"
105 "\r\n"
106 " -bn Block mode\r\n"
107 " -b0 => Block mode disabled [default]\r\n"
108 " -b1 => Block mode enabled\r\n"
109 "\r\n"
110 " -nn Defines the number of entries per line.\r\n"
111 " -n16 => Output 16 values each line\r\n"
112 " -n40 => Output 40 values each line\r\n"
113 "\r\n"
114 " -un Update check.\r\n"
115 " -u0 => Do not check if files are up to date [default]\r\n"
116 " -u1 => Perform a date check on the files and only update if needed\r\n"
117 "\r\n"
118 " -vn Verbosity.\r\n"
119 " -v0 => Silent [default]\r\n"
120 " -v1 => Shows information about what PictConv is doing\r\n"
121 );
122
123 #ifdef _DEBUG
124 int failureCount=RunUnitTests();
125 if (failureCount)
126 {
127 ShowError("UnitTests failed.");
128 }
129 #endif
130
131 DEVICE_FORMAT output_format=DEVICE_FORMAT_BASIC_TAPE;
132 //bool flag_basic_loader=true;
133 bool flag_testing = false;
134 bool flagUpdateTest = false;
135 bool flagVerbosity = false;
136
137 TextFileGenerator textFileGenerator;
138 textFileGenerator.SetLabel("_LabelPicture");
139 textFileGenerator.SetDataSize(1); // Byte format
140 textFileGenerator.SetEndianness(TextFileGenerator::_eEndianness_Little); // Little endian
141
142 int switchMachine=0; // Default 0=oric
143 int switchFormat=0;
144 int switchDither=0;
145 int switchPalette=0; // Default 0=automatically generate the palette
146 int switchBlock=0; // Default 0=no block mode (full picture)
147 int switchAlpha=0; // Default 0=no transparency
148
149 ArgumentParser argumentParser(argc,argv);
150
151 while (argumentParser.ProcessNextArgument())
152 {
153 if (argumentParser.IsSwitch("-f"))
154 {
155 switchFormat=argumentParser.GetIntegerValue(0);
156 }
157 else
158 if (argumentParser.IsSwitch("-m"))
159 {
160 //format: [-m]
161 // 0 => Oric
162 // 1 => Atari ST
163 switchMachine=argumentParser.GetIntegerValue(0);
164 }
165 else
166 if (argumentParser.IsSwitch("-b"))
167 {
168 //block mode: [-b]
169 // 0 => No blocs (simple picture)
170 // 1 => Blocks enabled
171 switchBlock=argumentParser.GetIntegerValue(0);
172 }
173 else
174 if (argumentParser.IsSwitch("-a"))
175 {
176 //alpha mode: [-a]
177 // 0 => No transparency
178 // 1 => Encode full transparent alpha as holes saved as zeroes. Or something like that at least.
179 switchAlpha=argumentParser.GetIntegerValue(0);
180 }
181 else
182 if (argumentParser.IsSwitch("-p"))
183 {
184 //format: [-m]
185 // 0 => Get the palette from the picture
186 // 1 => The last line of the picture contains the palette
187 // 2 => The last pixels of each line contains the palette for the line
188 switchPalette=argumentParser.GetIntegerValue(0);
189 }
190 else
191 if (argumentParser.IsSwitch("-n"))
192 {
193 //format: [-n]
194 textFileGenerator.SetValuesPerLine(argumentParser.GetIntegerValue(16));
195 }
196 else
197 if (argumentParser.IsSwitch("-d"))
198 {
199 //dithering: [-d]
200 // 0 => none
201 // 1 => alternate (01010101)
202 // 2 => ordered dither
203 // 3 => riemersma
204 // 4 => floyd steinberg
205 // 5 => alternate inversed (10101010)
206 switchDither=argumentParser.GetIntegerValue(0);
207 }
208 else
209 if (argumentParser.IsSwitch("-o"))
210 {
211 //output: [-o]
212 // 0 => TAP (with a header)
213 // => load adress (0xa000 by default for hires, 0xbb80 for text + 0xb400 for attributes))
214 // 1 => specify if we want a basic loader
215 // => load adress (0xa000 by default for hires, 0xbb80 for text + 0xb400 for attributes))
216 // 2 => Raw data
217 // 3 => .C format with labels and .h for "extern" declaration
218 // 4 => .S format with labels and .h for "extern" declaration
219 // 5 => Picture
220 // 6 => X+Y+RAW
221 // 7 => Raw picture + palette mode
222 // 8 => .BAS format with labels and .h for "extern" declaration
223 output_format=(DEVICE_FORMAT)argumentParser.GetIntegerValue(DEVICE_FORMAT_BASIC_TAPE);
224 switch (output_format)
225 {
226 case DEVICE_FORMAT_SOURCE_C:
227 textFileGenerator.SetFileType(TextFileGenerator::eLanguage_C);
228 if (*argumentParser.GetRemainingStuff())
229 {
230 // Keep this as a label value
231 textFileGenerator.SetLabel(argumentParser.GetRemainingStuff());
232 }
233 break;
234
235 case DEVICE_FORMAT_SOURCE_S:
236 textFileGenerator.SetFileType(TextFileGenerator::eLanguage_Assembler);
237 if (*argumentParser.GetRemainingStuff())
238 {
239 // Keep this as a label value
240 textFileGenerator.SetLabel(argumentParser.GetRemainingStuff());
241 }
242 break;
243
244 case DEVICE_FORMAT_SOURCE_BASIC:
245 textFileGenerator.SetFileType(TextFileGenerator::eLanguage_BASIC);
246 textFileGenerator.SetLabel("Generated by PictConv");
247 if (argumentParser.GetSeparator(":"))
248 {
249 textFileGenerator.SetLineNumber(argumentParser.GetIntegerValue(10));
250 if (argumentParser.GetSeparator(":"))
251 {
252 textFileGenerator.SetIncrementLineNumber(argumentParser.GetIntegerValue(10));
253 }
254 }
255 break;
256
257 case DEVICE_FORMAT_BASIC_TAPE:
258 case DEVICE_FORMAT_TAPE:
259 case DEVICE_FORMAT_RAWBUFFER:
260 case DEVICE_FORMAT_PICTURE:
261 case DEVICE_FORMAT_RAWBUFFER_WITH_XYHEADER:
262 case DEVICE_FORMAT_RAWBUFFER_WITH_PALETTE:
263 break;
264
265 default:
266 ShowError("Unknown format");
267 break;
268 }
269 }
270 else
271 if (argumentParser.IsSwitch("-t"))
272 {
273 //testing: [-t]
274 // 0 => disabled
275 // 1 => enabled
276 flag_testing=argumentParser.GetBooleanValue(true);
277 }
278 else
279 if (argumentParser.IsSwitch("-u"))
280 {
281 //testing: [-u]
282 // 0 => no update check
283 // 1 => do update check
284 flagUpdateTest=argumentParser.GetBooleanValue(true);
285 }
286 else
287 if (argumentParser.IsSwitch("-v"))
288 {
289 //testing: [-v]
290 // 0 => silent
291 // 1 => verbose
292 flagVerbosity=argumentParser.GetBooleanValue(true);
293 }
294 }
295
296 if (argumentParser.GetParameterCount()!=NB_ARG)
297 {
298 ShowError(0);
299 }
300
301 //
302 // Set and validate the parameters
303 // 0 => Oric
304 // 1 => Atari ST
305 //
306 PictureConverter* pictureConverter=PictureConverter::GetConverter((PictureConverter::MACHINE)switchMachine);
307 if (!pictureConverter)
308 {
309 ShowError("Can't create the required converter - Type is unknown");
310 }
311 PictureConverter& Hires(*pictureConverter);
312
313 Hires.SetDither((PictureConverter::DITHER)switchDither);
314 Hires.SetBlockMode((PictureConverter::BLOCKMODE)switchBlock);
315
316 if (!Hires.SetFormat(switchFormat))
317 {
318 ShowError("Invalid format (-f) for the selected machine (-m)");
319 }
320
321 if (!Hires.SetPaletteMode(switchPalette))
322 {
323 ShowError("Invalid palette mode (-p) for the selected machine (-m)");
324 }
325
326 if (!Hires.SetTransparencyMode(switchAlpha))
327 {
328 ShowError("Invalid alpha mode (-a) for the selected machine (-m)");
329 }
330
331
332 //
333 // Copy last parameters
334 //
335 std::string source_name=argumentParser.GetParameter(0);
336 std::string dest_name=argumentParser.GetParameter(1);
337
338 //
339 // Eventual time stamp check
340 //
341 if ( (!flagUpdateTest) || (flagUpdateTest && !IsUpToDate(source_name,dest_name)) )
342 {
343 //
344 // Initialize free image
345 //
346 FreeImage_Initialise();
347
348 //
349 // Try to load the source picture
350 //
351 ImageContainer sourceImage;
352 if (!sourceImage.LoadPicture(source_name))
353 {
354 ShowError("Could not load the source picture");
355 }
356
357 //
358 // Display informations about the picture
359 //
360 if (flagVerbosity)
361 {
362 printf("\r\n Name of the source picture: '%s'",source_name.c_str());
363 printf("\r\n Size: %dx%d",sourceImage.GetWidth(),sourceImage.GetHeight());
364 printf("\r\n BPP: %d",sourceImage.GetDpp());
365
366 int color_count=sourceImage.GetPaletteSize();
367 if (color_count)
368 {
369 // palletized
370 printf("\r\n Color count: %d",color_count);
371 }
372 else
373 {
374 // true color
375 printf("\r\n True color picture");
376 }
377 printf("\r\n");
378 }
379
380 //
381 // Convert to destination format
382 //
383 Hires.SetDebug(flag_testing);
384 if (!Hires.Convert(sourceImage))
385 {
386 ShowError("Conversion failed");
387 }
388
389 if (!Hires.Save(output_format,dest_name,textFileGenerator))
390 {
391 ShowError("Saving failed");
392 }
393
394 //
395 // Terminate free image
396 //
397 FreeImage_DeInitialise();
398 }
399
400 // getch();
401
402 return 0;
403 }
404

  ViewVC Help
Powered by ViewVC 1.1.26