Debian Codegraph @

third_party/etc2comp/EtcTool/EtcTool.cpp

raw
1 /*
2 * Copyright 2015 The Etc2Comp Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifdef _WIN32
18 #define _CRT_SECURE_NO_WARNINGS (1)
19 #endif
20 /*
21 since this code will be used on a wide varity of platforms and configurations
22 its important to have some sort of sanity check for the amount of threads that can be used.
23 change this macro to suit your configuration. This will be the maximum amount of threads
24 that can be created.
25 */
26 #define MAX_JOBS 1024
27
28 #define RUN_MEM_TEST 0
29
30 #include "EtcConfig.h"
31
32 #include "Etc.h"
33 #include "EtcFilter.h"
34
35 #include "EtcTool.h"
36 #include "EtcSourceImage.h"
37 #include "EtcFile.h"
38 #include "EtcMath.h"
39 #include "EtcImage.h"
40 #include "EtcErrorMetric.h"
41 #include "EtcBlock4x4EncodingBits.h"
42
43 #include "EtcAnalysis.h"
44
45 #include <assert.h>
46 #include <stdlib.h>
47 #include <string.h>
48
49 using namespace Etc;
50
51 #if ETC_WINDOWS
52 const char *ETC_MKDIR_COMMAND = "mkdir";
53
54 int strcasecmp(const char *s1, const char *s2)
55 {
56 return _stricmp(s1, s2);
57 }
58 #else
59 const char *ETC_MKDIR_COMMAND = "mkdir -p";
60 #endif
61
62 #if RUN_MEM_TEST
63 #include "EtcMemTest.h"
64 #endif
65
66 class Commands
67 {
68 public:
69
70 static const unsigned int MIN_JOBS = 8;
71
72 Commands(void)
73 {
74 pstrSourceFilename = nullptr;
75 pstrOutputFilename = nullptr;
76 format = Image::Format::DEFAULT;
77 pstrAnalysisDirectory = nullptr;
78 uiComparisons = 0;
79 for (unsigned int uiComparison = 0; uiComparison < Analysis::MAX_COMPARISONS; uiComparison++)
80 {
81 apstrCompareFilename[uiComparison] = nullptr;
82 }
83 fEffort = ETCCOMP_DEFAULT_EFFORT_LEVEL;
84 //Rec. 709 or BT.709...the default
85 e_ErrMetric = ErrorMetric::BT709;
86 uiJobs = MIN_JOBS;
87
88 //these are ignored if they are < 0
89 i_hPixel = -1;
90 i_vPixel = -1;
91 verboseOutput = false;
92 boolNormalizeXYZ = false;
93 mipmaps = 1;
94 mipFilterFlags = Etc::FILTER_WRAP_NONE;
95 }
96
97 bool ProcessCommandLineArguments(int a_iArgs, const char *a_apstrArgs[]);
98 void PrintUsageMessage(void);
99 static void FixSlashes(char *a_pstr);
100
101 char *pstrSourceFilename;
102 char *pstrOutputFilename;
103
104 Image::Format format;
105 char *pstrAnalysisDirectory;
106 char *formatType;
107 unsigned int uiComparisons;
108 char *apstrCompareFilename[Analysis::MAX_COMPARISONS];
109 float fEffort;
110 ErrorMetric e_ErrMetric;
111 unsigned int uiJobs; // for threading
112 bool verboseOutput;
113 //when both of these are >= 0 then single block mode is on
114 int i_hPixel;
115 int i_vPixel;
116 bool boolNormalizeXYZ;
117 int mipmaps;
118 unsigned int mipFilterFlags;
119 };
120
121 #include "EtcFileHeader.h"
122
123 // ----------------------------------------------------------------------------------------------------
124 //
125 int main(int argc, const char * argv[])
126 {
127
128 static const bool USE_C_INTERFACE = false;
129
130 // this code tests for memory leaks
131 #if RUN_MEM_TEST
132 RunMemTest(true, 100);
133 printf("an extra line to see how the memory is free'd\n");
134 printf("all done!\n");
135 exit(0);
136 #endif
137
138 Commands commands;
139 bool boolPrintUsage = commands.ProcessCommandLineArguments(argc, argv);
140 if (boolPrintUsage)
141 {
142 commands.PrintUsageMessage();
143 exit(1);
144 }
145
146 if (commands.verboseOutput)
147 {
148 printf("SourceImage: %s\n", commands.pstrSourceFilename);
149 }
150 SourceImage sourceimage(commands.pstrSourceFilename, commands.i_hPixel, commands.i_vPixel);
151 if (commands.boolNormalizeXYZ)
152 {
153 sourceimage.NormalizeXYZ();
154 }
155
156 unsigned int uiSourceWidth = sourceimage.GetWidth();
157 unsigned int uiSourceHeight = sourceimage.GetHeight();
158
159 if(commands.mipmaps != 1)
160 {
161 int iEncodingTime_ms;
162
163 // Calculate the maximum number of possible mipmaps
164 {
165 int dim = (uiSourceWidth < uiSourceHeight)?uiSourceWidth:uiSourceHeight;
166 int maxMips = 0;
167 while(dim >= 1)
168 {
169 maxMips++;
170 dim >>= 1;
171 }
172 if( commands.mipmaps == 0 || commands.mipmaps > maxMips)
173 {
174 commands.mipmaps = maxMips;
175 }
176 }
177
178 Etc::RawImage *pMipmapImages = new Etc::RawImage[commands.mipmaps];
179
180 if (commands.verboseOutput)
181 {
182 printf("Encoding:\n");
183 printf(" effort = %.f\n", commands.fEffort);
184 printf(" encoding = %s\n", Image::EncodingFormatToString(commands.format));
185 printf(" error metric: %s\n", ErrorMetricToString(commands.e_ErrMetric));
186 }
187 Etc::EncodeMipmaps((float *)sourceimage.GetPixels(),
188 uiSourceWidth, uiSourceHeight,
189 commands.format,
190 commands.e_ErrMetric,
191 commands.fEffort,
192 commands.uiJobs,
193 MAX_JOBS,
194 commands.mipmaps,
195 commands.mipFilterFlags,
196 pMipmapImages,
197 &iEncodingTime_ms);
198 if (commands.verboseOutput)
199 {
200 printf(" encode time = %dms\n", iEncodingTime_ms);
201 printf("EncodedImage: %s\n", commands.pstrOutputFilename);
202 }
203 Etc::File etcfile(commands.pstrOutputFilename, Etc::File::Format::INFER_FROM_FILE_EXTENSION,
204 commands.format,
205 commands.mipmaps,
206 pMipmapImages,
207 uiSourceWidth, uiSourceHeight );
208 etcfile.Write();
209
210 delete [] pMipmapImages;
211 }
212 else if (USE_C_INTERFACE)
213 {
214 unsigned char *paucEncodingBits;
215 unsigned int uiEncodingBitsBytes;
216 unsigned int uiExtendedWidth;
217 unsigned int uiExtendedHeight;
218 int iEncodingTime_ms;
219
220 if (commands.verboseOutput)
221 {
222 printf("Encoding:\n");
223 printf(" effort = %.f\n", commands.fEffort);
224 printf(" encoding = %s\n", Image::EncodingFormatToString(commands.format));
225 printf(" error metric: %s\n", ErrorMetricToString(commands.e_ErrMetric));
226 }
227 Etc::Encode((float *)sourceimage.GetPixels(),
228 uiSourceWidth, uiSourceHeight,
229 commands.format,
230 commands.e_ErrMetric,
231 commands.fEffort,
232 commands.uiJobs,
233 MAX_JOBS,
234 &paucEncodingBits, &uiEncodingBitsBytes,
235 &uiExtendedWidth, &uiExtendedHeight,
236 &iEncodingTime_ms);
237 if (commands.verboseOutput)
238 {
239 printf(" encode time = %dms\n", iEncodingTime_ms);
240 printf("EncodedImage: %s\n", commands.pstrOutputFilename);
241 }
242 Etc::File etcfile(commands.pstrOutputFilename, Etc::File::Format::INFER_FROM_FILE_EXTENSION,
243 commands.format,
244 paucEncodingBits, uiEncodingBitsBytes,
245 uiSourceWidth, uiSourceHeight,
246 uiExtendedWidth, uiExtendedHeight);
247 etcfile.Write();
248 }
249 else
250 {
251 if (commands.verboseOutput)
252 {
253 printf("Encoding:\n");
254 printf(" effort = %.f%%\n", commands.fEffort);
255 printf(" encoding = %s\n", Image::EncodingFormatToString(commands.format));
256 printf(" error metric: %s\n", ErrorMetricToString(commands.e_ErrMetric));
257 }
258 Etc::Image image((float *)sourceimage.GetPixels(),
259 uiSourceWidth, uiSourceHeight,
260 commands.e_ErrMetric);
261 image.m_bVerboseOutput = commands.verboseOutput;
262 Etc::Image::EncodingStatus encStatus = Etc::Image::EncodingStatus::SUCCESS;
263
264 encStatus = image.Encode(commands.format, commands.e_ErrMetric, commands.fEffort, commands.uiJobs,MAX_JOBS);
265 if (commands.verboseOutput)
266 {
267 printf(" encode time = %dms\n", image.GetEncodingTimeMs());
268 printf("EncodedImage: %s\n", commands.pstrOutputFilename);
269 printf("status bitfield: %u\n", encStatus);
270 }
271 Etc::File etcfile(commands.pstrOutputFilename, Etc::File::Format::INFER_FROM_FILE_EXTENSION,
272 commands.format,
273 image.GetEncodingBits(), image.GetEncodingBitsBytes(),
274 image.GetSourceWidth(), image.GetSourceHeight(),
275 image.GetExtendedWidth(), image.GetExtendedHeight());
276
277 etcfile.Write();
278
279 if (commands.pstrAnalysisDirectory)
280 {
281 if (commands.verboseOutput)
282 {
283 printf("Analysis: %s\n", commands.pstrAnalysisDirectory);
284 }
285 Analysis analysis(&image, commands.pstrAnalysisDirectory);
286
287 for (unsigned int uiComparison = 0; uiComparison < commands.uiComparisons; uiComparison++)
288 {
289 analysis.Compare(commands.apstrCompareFilename[uiComparison], commands.i_hPixel, commands.i_vPixel);
290 }
291 }
292
293 }
294
295 return 0;
296 }
297
298 // ----------------------------------------------------------------------------------------------------
299 // return true if usage message should be printed
300 //
301 bool Commands::ProcessCommandLineArguments(int a_iArgs, const char *a_apstrArgs[])
302 {
303 static const bool DEBUG_PRINT = false;
304
305 if (a_iArgs == 1)
306 {
307 printf("Error: missing arguments\n");
308 return true;
309 }
310
311 for (int iArg = 1; iArg < a_iArgs; iArg++)
312 {
313 if (DEBUG_PRINT)
314 {
315 printf("%s: %u %s\n", a_apstrArgs[0], iArg, a_apstrArgs[iArg]);
316 }
317
318 if (strcmp(a_apstrArgs[iArg], "-analyze") == 0)
319 {
320 ++iArg;
321
322 if (iArg >= (a_iArgs))
323 {
324 printf("Error: missing folder parameter for -analyze\n");
325 return true;
326 }
327 else
328 {
329 pstrAnalysisDirectory = new char[strlen(a_apstrArgs[iArg]) + 1];
330 strcpy(pstrAnalysisDirectory, a_apstrArgs[iArg]);
331 FixSlashes(pstrAnalysisDirectory);
332 }
333 }
334 else if (strcmp(a_apstrArgs[iArg], "-argfile") == 0)
335 {
336 static const unsigned int MAX_LINE_CHARS = 1000;
337 static const unsigned int MAX_ARGFILE_ARGS = 100;
338
339 ++iArg;
340
341 if (iArg >= (a_iArgs))
342 {
343 printf("Error: missing file parameter for -argfile\n");
344 return true;
345 }
346 else
347 {
348 FILE *pfile = fopen(a_apstrArgs[iArg], "rt");
349 if (pfile == nullptr)
350 {
351 printf("Error: couldn't open argfile (%s)\n", a_apstrArgs[iArg]);
352 return true;
353 }
354
355 char **apstrArgs = new char *[MAX_ARGFILE_ARGS];
356 assert(apstrArgs);
357
358 // add null executable name
359 apstrArgs[0] = const_cast<char *>("");
360 int iArgs = 1;
361
362 // read in tokens
363 {
364 char *pcTokens = new char[MAX_LINE_CHARS + 1];
365 assert(pcTokens);
366 char *pcToken = nullptr;
367
368 // read in each line
369 while (fgets(pcTokens, MAX_LINE_CHARS, pfile))
370 {
371 // skip over lines with '#' in first char
372 if (pcTokens[0] == '#')
373 {
374 continue;
375 }
376
377 // abort remainder of argfile with '%' in first char
378 if (pcTokens[0] == '%')
379 {
380 break;
381 }
382 pcToken = strtok(pcTokens, " \n\r");
383
384 if (pcToken != nullptr)
385 {
386 apstrArgs[iArgs] = new char[strlen(pcToken) + 1];
387 strcpy(apstrArgs[iArgs], pcToken);
388 iArgs++;
389 }
390
391 while (pcToken != nullptr)
392 {
393 pcToken = strtok(nullptr, " \n");
394 if (pcToken != nullptr)
395 {
396 apstrArgs[iArgs] = new char[strlen(pcToken) + 1];
397 strcpy(apstrArgs[iArgs], pcToken);
398 iArgs++;
399 }
400 }
401 }
402
403 delete[] pcTokens;
404 }
405
406 fclose(pfile);
407
408 bool boolErrors = ProcessCommandLineArguments(iArgs, const_cast<const char **>(apstrArgs));
409
410 for (iArg = 1; iArg < iArgs; iArg++)
411 {
412 delete[] apstrArgs[iArg];
413 }
414 delete[] apstrArgs;
415
416 if (boolErrors)
417 {
418 return true;
419 }
420 }
421 }
422 //used for debugging...select a single block to encode
423 //supply the horiz and very pos of the block
424 else if (strcmp(a_apstrArgs[iArg], "-blockAtHV") == 0)
425 {
426 ++iArg;
427
428 //make sure we have two more args after -block
429 if (iArg + 1 >= (a_iArgs))
430 {
431 printf("Error: missing horiz and vert position of pixel for single block mode \n");
432 return true;
433 }
434 i_hPixel = atoi(a_apstrArgs[iArg]);
435 ++iArg;
436 i_vPixel = atoi(a_apstrArgs[iArg]);
437 }
438 else if (strcmp(a_apstrArgs[iArg], "-compare") == 0)
439 {
440 ++iArg;
441
442 if (iArg >= (a_iArgs))
443 {
444 printf("Error: missing comprison_image parameter for -compare\n");
445 return true;
446 }
447 else
448 {
449 if (uiComparisons >= Analysis::MAX_COMPARISONS)
450 {
451 printf("Error: too many comparisons\n");
452 return true;
453 }
454
455 char **ppstrCompareFilename = &apstrCompareFilename[uiComparisons++];
456
457 *ppstrCompareFilename = new char[strlen(a_apstrArgs[iArg]) + 1];
458 strcpy(*ppstrCompareFilename, a_apstrArgs[iArg]);
459 FixSlashes(*ppstrCompareFilename);
460 }
461 }
462 else if (strcmp(a_apstrArgs[iArg], "-effort") == 0)
463 {
464 ++iArg;
465
466 if (iArg >= (a_iArgs))
467 {
468 printf("Error: missing amount parameter for -effort\n");
469 return true;
470 }
471 else
472 {
473 float f;
474 int iScans = sscanf(a_apstrArgs[iArg], "%f", &f);
475
476 if (iScans != 1)
477 {
478 printf("Error: couldn't parse amount for -effort (%s)\n", a_apstrArgs[iArg]);
479 return true;
480 }
481 else
482 {
483 fEffort = f;
484 }
485 }
486 }
487 else if (strcmp(a_apstrArgs[iArg], "-errormetric") == 0)
488 {
489 ++iArg;
490
491 if (iArg >= (a_iArgs))
492 {
493 printf("Error: missing error metric type %s\n", a_apstrArgs[iArg]);
494 return true;
495 }
496 else
497 {
498 if (strcmp(a_apstrArgs[iArg], "rgba") == 0)
499 {
500 e_ErrMetric = ErrorMetric::RGBA;
501 }
502 else if (strcmp(a_apstrArgs[iArg], "rgbx") == 0)
503 {
504 e_ErrMetric = ErrorMetric::RGBX;
505 }
506 else if (strcmp(a_apstrArgs[iArg], "rec709") == 0)
507 {
508 e_ErrMetric = ErrorMetric::REC709;
509 }
510 else if (strcmp(a_apstrArgs[iArg], "numeric") == 0)
511 {
512 e_ErrMetric = ErrorMetric::NUMERIC;
513 }
514 else if (strcmp(a_apstrArgs[iArg], "normalxyz") == 0 ||
515 strcmp(a_apstrArgs[iArg], "normalXYZ") == 0)
516 {
517 e_ErrMetric = ErrorMetric::NORMALXYZ;
518 }
519 else
520 {
521 printf("unrecognized error metric (%s), using numeric\n", a_apstrArgs[iArg]);
522 e_ErrMetric = ErrorMetric::NUMERIC;
523 }
524 }
525 }
526 else if (strcmp(a_apstrArgs[iArg], "-format") == 0)
527 {
528 ++iArg;
529
530 if (iArg >= (a_iArgs))
531 {
532 printf("Error: missing etc_format parameter for -format\n");
533 return true;
534 }
535 else
536 {
537 formatType = new char[strlen(a_apstrArgs[iArg])+1];
538 strcpy(formatType,a_apstrArgs[iArg]);
539 if (strcmp(a_apstrArgs[iArg], "ETC1") == 0)
540 {
541 format = Image::Format::ETC1;
542 }
543 else if (strcmp(a_apstrArgs[iArg], "RGB8") == 0)
544 {
545 format = Image::Format::RGB8;
546 }
547 else if (strcmp(a_apstrArgs[iArg], "SRGB8") == 0)
548 {
549 format = Image::Format::SRGB8;
550 }
551 else if (strcmp(a_apstrArgs[iArg], "RGBA8") == 0)
552 {
553 format = Image::Format::RGBA8;
554 }
555 else if (strcmp(a_apstrArgs[iArg], "SRGBA8") == 0)
556 {
557 format = Image::Format::SRGBA8;
558 }
559 else if (strcmp(a_apstrArgs[iArg], "R11") == 0)
560 {
561 format = Image::Format::R11;
562 }
563 else if (strcmp(a_apstrArgs[iArg], "SIGNED_R11") == 0)
564 {
565 format = Image::Format::SIGNED_R11;
566 }
567 else if (strcmp(a_apstrArgs[iArg], "RG11") == 0)
568 {
569 format = Image::Format::RG11;
570 }
571 else if (strcmp(a_apstrArgs[iArg], "SIGNED_RG11") == 0)
572 {
573 format = Image::Format::SIGNED_RG11;
574 }
575 else if (strcmp(a_apstrArgs[iArg], "RGB8A1") == 0)
576 {
577 format = Image::Format::RGB8A1;
578 }
579 else if (strcmp(a_apstrArgs[iArg], "SRGB8A1") == 0)
580 {
581 format = Image::Format::SRGB8A1;
582 }
583 else
584 {
585 printf("Error: unknown etc_format parameter for -format\n");
586 format = Image::Format::UNKNOWN;
587 return true;
588 }
589 }
590 }
591 else if (strcmp(a_apstrArgs[iArg], "-help") == 0)
592 {
593 return true;
594 }
595 else if (strcmp(a_apstrArgs[iArg], "-j") == 0 ||
596 strcmp(a_apstrArgs[iArg], "-jobs") == 0)
597 {
598 ++iArg;
599
600 if (iArg >= (a_iArgs))
601 {
602 printf("Error: missing job count for %s\n", a_apstrArgs[iArg]);
603 return true;
604 }
605 else
606 {
607 unsigned int ui;
608 int iScans = sscanf(a_apstrArgs[iArg], "%u", &ui);
609
610 if (iScans != 1)
611 {
612 printf("Error: couldn't parse job count for %s (%s)\n", a_apstrArgs[iArg-1], a_apstrArgs[iArg]);
613 return true;
614 }
615 else
616 {
617 if (ui < MIN_JOBS)
618 {
619 ui = MIN_JOBS;
620 }
621
622 uiJobs = ui;
623 }
624 }
625 }
626 else if (strcmp(a_apstrArgs[iArg], "-normalizexyz") == 0 ||
627 strcmp(a_apstrArgs[iArg], "-normalizeXYZ") == 0)
628 {
629 boolNormalizeXYZ = true;
630 }
631 else if (strcmp(a_apstrArgs[iArg], "-output") == 0)
632 {
633 ++iArg;
634
635 if (iArg >= (a_iArgs))
636 {
637 printf("Error: missing encoded_image parameter for -output\n");
638 return true;
639 }
640 else
641 {
642 pstrOutputFilename = new char[strlen(a_apstrArgs[iArg]) + 1];
643 strcpy(pstrOutputFilename, a_apstrArgs[iArg]);
644 //take the output file name and extract the directory path so we can create the directory if nescacary
645 char *ptrOutputDir = nullptr;
646
647 FixSlashes(pstrOutputFilename);
648 for (int c = (int)strlen(pstrOutputFilename); c > 0; c--)
649 {
650 //find the last slash, to get the name of the directory
651 if (pstrOutputFilename[c] == ETC_PATH_SLASH)
652 {
653 c++;
654 ptrOutputDir = new char[c];
655 strncpy(ptrOutputDir, pstrOutputFilename, c);
656 ptrOutputDir[c] = '\0';
657 CreateNewDir(ptrOutputDir);
658 break;
659 }
660 }
661
662 if (ptrOutputDir == nullptr)
663 {
664 printf("couldnt find a place to put converted images\n");
665 exit(1);
666 }
667 }
668 }
669 else if (strcmp(a_apstrArgs[iArg], "-verbose") == 0 ||
670 strcmp(a_apstrArgs[iArg], "-v") == 0)
671 {
672 verboseOutput = true;
673 }
674 else if (strcmp(a_apstrArgs[iArg], "-mipmaps") == 0 ||
675 strcmp(a_apstrArgs[iArg], "-m") == 0)
676 {
677 ++iArg;
678
679 if (iArg >= (a_iArgs))
680 {
681 printf("Error: missing mipmap number parameter for -mipmaps\n");
682 return true;
683 }
684 else
685 {
686 unsigned int ui;
687 int result = sscanf(a_apstrArgs[iArg], "%u", &ui);
688 if (result == 1)
689 {
690 mipmaps = ui;
691 }
692 else
693 {
694 printf("Error: -mipmaps argument needs to be a number\n");
695 return true;
696 }
697 }
698 }
699 else if (strcmp(a_apstrArgs[iArg], "-mipwrap") == 0 ||
700 strcmp(a_apstrArgs[iArg], "-w") == 0)
701 {
702 ++iArg;
703
704 if (iArg >= (a_iArgs))
705 {
706 printf("Error: missing parameter for -mipwrap\n");
707 return true;
708 }
709 else
710 {
711 if ( 0 == strcmp(a_apstrArgs[iArg], "x") )
712 {
713 mipFilterFlags = Etc::FILTER_WRAP_X;
714 }
715 else if (0 == strcmp(a_apstrArgs[iArg], "y"))
716 {
717 mipFilterFlags = Etc::FILTER_WRAP_Y;
718 }
719 else if (0 == strcmp(a_apstrArgs[iArg], "xy"))
720 {
721 mipFilterFlags = Etc::FILTER_WRAP_X | Etc::FILTER_WRAP_Y;
722 }
723 }
724 }
725 else if (a_apstrArgs[iArg][0] == '-')
726 {
727 printf("Error: unknown option (%s)\n", a_apstrArgs[iArg]);
728 return true;
729 }
730 else if (a_apstrArgs[iArg][0] == '\r')
731 {
732 continue;
733 }
734 else
735 {
736 if (pstrSourceFilename != nullptr)
737 {
738 printf("Error: only support one source_image (%s)\n", a_apstrArgs[iArg]);
739 return true;
740 }
741
742 pstrSourceFilename = new char[strlen(a_apstrArgs[iArg])+1];
743 strcpy(pstrSourceFilename, a_apstrArgs[iArg]);
744 }
745 }
746
747 if (pstrSourceFilename == nullptr)
748 {
749 printf("Error: missing source_image\n");
750 return true;
751 }
752
753 if (pstrOutputFilename == nullptr)
754 {
755 printf("Error: missing -output encoded_image\n");
756 return true;
757 }
758
759 if (uiComparisons > 0 && pstrAnalysisDirectory == nullptr)
760 {
761 printf("Error: -compare is only valid with -analyze\n");
762 return true;
763 }
764
765 return false;
766 }
767
768 // ----------------------------------------------------------------------------------------------------
769 //
770 void Commands::FixSlashes(char *a_pstr)
771 {
772 while (*a_pstr)
773 {
774 if (*a_pstr == ETC_BAD_PATH_SLASH)
775 {
776 *a_pstr = ETC_PATH_SLASH;
777 }
778
779 a_pstr++;
780 }
781 }
782
783 // ----------------------------------------------------------------------------------------------------
784 // print usage message and exit
785 //
786 void Commands::PrintUsageMessage(void)
787 {
788 printf("Usage: etctool.exe source_image [options ...] -output <output_file>\n");
789 printf("Options:\n");
790 printf(" -analyze <analysis_folder>\n");
791 printf(" -argfile <arg_file> additional command line arguments\n");
792 printf(" -blockAtHV <H V> encodes a single block that contains the\n");
793 printf(" pixel specified by the H V coordinates\n");
794 printf(" -compare <comparison_image> compares source_image to comparison_image\n");
795 printf(" -effort <amount> number between 0 and 100\n");
796 printf(" -errormetric <error_metric> specify the error metric, the options are\n");
797 printf(" rgba, rgbx, rec709, numeric and normalxyz\n");
798 printf(" -format <etc_format> ETC1, RGB8, SRGB8, RGBA8, SRGB8, RGB8A1,\n");
799 printf(" SRGB8A1 or R11\n");
800 printf(" -help prints this message\n");
801 printf(" -jobs or -j <thread_count> specifies the number of threads (default=1)\n");
802 printf(" -normalizexyz normalize RGB to have a length of 1\n");
803 printf(" -verbose or -v shows status information during the encoding\n");
804 printf(" process\n");
805 printf(" -mipmaps or -m <mip_count> sets the maximum number of mipaps to generate (default=1)\n");
806 printf(" -mipwrap or -w <x|y|xy> sets the mipmap filter wrap mode (default=clamp)\n");
807 printf("\n");
808
809 exit(1);
810 }
811
812 // ----------------------------------------------------------------------------------------------------
813 //
814 void CreateNewDir(const char *path)
815 {
816 char strCommand[300];
817
818 #if ETC_WINDOWS
819 sprintf_s(strCommand, "if not exist %s %s %s", path, ETC_MKDIR_COMMAND, path);
820 #else
821 sprintf(strCommand, "%s %s", ETC_MKDIR_COMMAND, path);
822 #endif
823 int iResult = system(strCommand);
824 if (iResult != 0)
825 {
826 printf("Error: couldn't create directory (%s)\n", path);
827 exit(0);
828 }
829
830 }
831
832 // ----------------------------------------------------------------------------------------------------
833 //