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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1075 - (hide annotations)
Sun Jan 12 20:13:41 2014 UTC (6 years ago) by dbug
File size: 12246 byte(s)
PictConv 0.016
- New option to skip the conversion if the target file is more recent than the source file (-u)
- New option to enable/disable information about what happens (-v)

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

  ViewVC Help
Powered by ViewVC 1.1.26