forked from BinomialLLC/basis_universal
-
Notifications
You must be signed in to change notification settings - Fork 3
/
basisu_tool.cpp
5325 lines (4401 loc) · 188 KB
/
basisu_tool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// basisu_tool.cpp
// Copyright (C) 2019-2024 Binomial LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#if _MSC_VER
// For sprintf(), strcpy()
#define _CRT_SECURE_NO_WARNINGS (1)
#endif
#include "transcoder/basisu.h"
#include "transcoder/basisu_transcoder_internal.h"
#include "encoder/basisu_enc.h"
#include "encoder/basisu_etc.h"
#include "encoder/basisu_gpu_texture.h"
#include "encoder/basisu_frontend.h"
#include "encoder/basisu_backend.h"
#include "encoder/basisu_comp.h"
#include "transcoder/basisu_transcoder.h"
#include "encoder/basisu_ssim.h"
#include "encoder/basisu_opencl.h"
#define MINIZ_HEADER_FILE_ONLY
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
#include "encoder/basisu_miniz.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
// Set BASISU_CATCH_EXCEPTIONS if you want exceptions to crash the app, otherwise main() catches them.
#ifndef BASISU_CATCH_EXCEPTIONS
#define BASISU_CATCH_EXCEPTIONS 0
#endif
using namespace basisu;
using namespace buminiz;
#define BASISU_TOOL_VERSION "1.50.0"
// Define to lower the -test and -test_hdr tolerances
//#define USE_TIGHTER_TEST_TOLERANCES
// Only enable to verify SAN is working.
//#define FORCE_SAN_FAILURE
enum tool_mode
{
cDefault,
cCompress,
cValidate,
cInfo,
cUnpack,
cCompare,
cHDRCompare,
cVersion,
cBench,
cCompSize,
cTestLDR,
cTestHDR,
cCLBench,
cSplitImage,
cCombineImages,
cTonemapImage
};
static void print_usage()
{
printf("\nUsage: basisu filename [filename ...] <options>\n");
puts("\n"
"The default mode is compression of one or more .PNG/.BMP/.TGA/.JPG/.QOI/.DDS/.EXR/.HDR files to a LDR or HDR .KTX2 file. Alternate modes:\n"
" -unpack: Use transcoder to unpack a .basis/.KTX2 file to one or more .KTX/.PNG files\n"
" -validate: Validate and display information about a .basis/.KTX2 file\n"
" -info: Display high-level information about a .basis/.KTX2 file\n"
" -compare: Compare two LDR PNG/BMP/TGA/JPG/QOI images specified with -file, output PSNR and SSIM statistics and RGB/A delta images\n"
" -compare_hdr: Compare two HDR .EXR/.HDR images specified with -file, output PSNR statistics and RGB delta images\n"
" -tonemap: Tonemap an HDR or EXR image to PNG at multiple exposures, use -file to specify filename\n"
" -version: Print version and exit\n"
"\n"
"Notes:\n"
"\nUnless an explicit mode is specified, if one or more files have the .basis or .KTX2 extension this tool defaults to unpack mode.\n"
"\nBy default, the compressor assumes the input is in the sRGB colorspace (like photos/albedo textures).\n"
"If the input is NOT sRGB (like a normal map), be sure to specify -linear for less artifacts. Depending on the content type, some experimentation may be needed.\n"
"\n"
"The TinyEXR library is used to read .EXR images. This library does not support all .EXR compression methods. For unsupported images, you can use ImageMagick to convert them to uncompressed .EXR.\n"
"\n"
"For .DDS source files: Mipmapped or not mipmapped 2D textures (but not cubemaps) are supported. Only uncompressed 32-bit RGBA/BGRA, half float RGBA, or float RGBA .DDS files are supported. In -tex_array mode, if a .DDS file is specified, all source files must be in .DDS format.\n"
"\n"
"Filenames prefixed with a @ symbol are read as filename listing files. Listing text files specify which actual filenames to process (one filename per line).\n"
"\n"
"Options:\n"
" -hdr: Encode input as UASTC HDR (automatic if any input file has the .EXR or .HDR extension, or if any .DDS file is HDR).\n"
" -fastest: Set UASTC LDR and HDR to fastest but lowest quality encoding mode (same as -uastc_level 0)\n"
" -slower: Set UASTC LDR and HDR to slower but a higher quality encoding mode (same as -uastc_level 3)\n"
" -opencl: Enable OpenCL usage (currently only accelerates ETC1S encoding)\n"
" -opencl_serialize: Serialize all calls to the OpenCL driver (to work around buggy drivers, only useful with -parallel)\n"
" -parallel: Compress multiple textures simumtanously (one per thread), instead of one at a time. Compatible with OpenCL mode. This is much faster, but in OpenCL mode the driver is pushed harder, and the CLI output will be jumbled.\n"
" -ktx2: Write .KTX2 files (the default). By default, UASTC LDR/HDR files will be compressed using Zstandard unless -ktx2_no_zstandard is specified.\n"
" -basis: Write .basis files instead of .KTX2 files (the previous default).\n"
" -file filename.png/bmp/tga/jpg/qoi: Input image filename, multiple images are OK, use -file X for each input filename (prefixing input filenames with -file is optional)\n"
" -alpha_file filename.png/bmp/tga/jpg/qoi: Input alpha image filename, multiple images are OK, use -file X for each input filename (must be paired with -file), images converted to REC709 grayscale and used as input alpha\n"
" -multifile_printf: printf() format strint to use to compose multiple filenames\n"
" -multifile_first: The index of the first file to process, default is 0 (must specify -multifile_printf and -multifile_num)\n"
" -multifile_num: The total number of files to process.\n"
" -q X: Set ETC1S quality level, 1-255, default is 128, lower=better compression/lower quality/faster, higher=less compression/higher quality/slower, default is 128. For even higher quality, use -max_endpoints/-max_selectors.\n"
" -linear: Use linear colorspace metrics (instead of the default sRGB or scaled RGB for HDR), and by default linear (not sRGB) mipmap filtering.\n"
" -output_file filename: Output .basis/.KTX2 filename\n"
" -output_path: Output .basis/.KTX2 files to specified directory.\n"
" -debug or -verbose: Enable codec debug print to stdout (slightly slower).\n"
" -debug_images: Enable codec debug images (much slower).\n"
" -stats: Compute and display image quality metrics (slightly to much slower).\n"
" -tex_type <2d, 2darray, 3d, video, cubemap>: Set Basis file header's texture type field. Cubemap arrays require multiples of 6 images, in X+, X-, Y+, Y-, Z+, Z- order, each image must be the same resolutions.\n"
" 2d=arbitrary 2D images, 2darray=2D array, 3D=volume texture slices, video=video frames, cubemap=array of faces. For 2darray/3d/cubemaps/video, each source image's dimensions and # of mipmap levels must be the same.\n"
" For video, the .basis file will be written with the first frame being an I-Frame, and subsequent frames being P-Frames (using conditional replenishment). Playback must always occur in order from first to last image.\n"
" -cubemap: same as -tex_type cubemap\n"
" -individual: Process input images individually and output multiple .basis/.KTX2 files (not as a texture array - this is now the default as of v1.16)\n"
" -tex_array: Process input images as a single texture array and write a single .basis/.KTX2 file (the former default before v1.16)\n"
" -comp_level X: Set ETC1S encoding speed vs. quality tradeoff. Range is 0-6, default is 1. Higher values=MUCH slower, but slightly higher quality. Higher levels intended for videos. Use -q first!\n"
" -fuzz_testing: Use with -validate: Disables CRC16 validation of file contents before transcoding\n"
"\nUASTC options:\n"
" -uastc: Enable UASTC LDR texture mode, instead of the default ETC1S mode. Significantly higher texture quality, but larger files. (Note that UASTC .basis files must be losslessly compressed by the user.)\n"
" -uastc_level: Set UASTC LDR/HDR encoding level. LDR Range is [0,4], default is 2, higher=slower but higher quality. 0=fastest/lowest quality, 3=slowest practical option, 4=impractically slow/highest achievable quality\n"
" UASTC HDR range is [0,4] - higher=slower but higher quality. HDR default=1.\n"
" -uastc_rdo_l X: Enable UASTC LDR RDO post-processing and set UASTC RDO quality scalar (lambda) to X. Lower values=higher quality/larger LZ\n"
" compressed files, higher values=lower quality/smaller LZ compressed files. Good range to try is [.25-10].\n"
" Note: Previous versons used the -uastc_rdo_q option, which was removed because the RDO algorithm was changed.\n"
" -uastc_rdo_d X: Set UASTC LDR RDO dictionary size in bytes. Default is 4096, max is 65536. Lower values=faster, but less compression.\n"
" -uastc_rdo_b X: Set UASTC LDR RDO max smooth block error scale. Range is [1,300]. Default is 10.0, 1.0=disabled. Larger values suppress more artifacts (and allocate more bits) on smooth blocks.\n"
" -uastc_rdo_s X: Set UASTC LDR RDO max smooth block standard deviation. Range is [.01,65536]. Default is 18.0. Larger values expand the range of blocks considered smooth.\n"
" -uastc_rdo_f: Don't favor simpler UASTC LDR modes in RDO mode.\n"
" -uastc_rdo_m: Disable RDO multithreading (slightly higher compression, deterministic).\n"
"\n"
"HDR specific options:\n"
" -uastc_level X: Sets the UASTC HDR compressor's level. Valid range is [0,4] - higher=slower but higher quality. HDR default=1.\n"
" Level 0=fastest/lowest quality, 3=highest practical setting, 4=exhaustive\n"
" -hdr_ldr_no_srgb_to_linear: If specified, LDR images will NOT be converted to normalized linear light (via a sRGB->Linear conversion) before compressing as HDR.\n"
" -hdr_uber_mode: Allow the encoder to try varying the selectors more for slightly higher quality. This may negatively impact BC6H quality, however.\n"
" -hdr_favor_astc: By default the HDR encoder tries to strike a balance or even slightly favor BC6H quality. If this option is specified, ASTC HDR quality is favored instead.\n"
"\n"
"More options:\n"
" -test: Run an automated LDR ETC1S/UASTC encoding and transcoding test. Returns EXIT_FAILURE if any failures\n"
" -test_hdr: Run an automated UASTC HDR encoding and transcoding test. Returns EXIT_FAILURE if any failures\n"
" -test_dir: Optional directory of test files. Defaults to \"../test_files\".\n"
" -max_endpoints X: Manually set the max number of color endpoint clusters from 1-16128, use instead of -q\n"
" -max_selectors X: Manually set the max number of color selector clusters from 1-16128, use instead of -q\n"
" -y_flip: Flip input images vertically before compression\n"
" -normal_map: Tunes codec parameters for better quality on normal maps (linear colorspace metrics, linear mipmap filtering, no selector RDO, no sRGB)\n"
" -no_alpha: Always output non-alpha basis files, even if one or more inputs has alpha\n"
" -force_alpha: Always output alpha basis files, even if no inputs has alpha\n"
" -separate_rg_to_color_alpha: Separate input R and G channels to RGB and A (for tangent space XY normal maps)\n"
" -swizzle rgba: Specify swizzle for the 4 input color channels using r, g, b and a (the -separate_rg_to_color_alpha flag is equivalent to rrrg)\n"
" -renorm: Renormalize each input image before any further processing/compression\n"
" -no_multithreading: Disable multithreading\n"
" -max_threads X: Use at most X threads total when multithreading is enabled (this includes the main thread)\n"
" -no_ktx: Disable KTX writing when unpacking (faster, less output files)\n"
" -ktx_only: Only write KTX files when unpacking (faster, less output files)\n"
" -write_out: Write 3dfx OUT files when unpacking FXT1 textures\n"
" -format_only: Only unpack the specified format, by its numeric code.\n"
" -etc1_only: Only unpack to ETC1, skipping the other texture formats during -unpack\n"
" -disable_hierarchical_endpoint_codebooks: Disable hierarchical endpoint codebook usage, slower but higher quality on some compression levels\n"
" -compare_ssim: Compute and display SSIM of image comparison (slow)\n"
" -compare_plot: Display histogram plots in -compare mode\n"
" -bench: UASTC benchmark mode, for development only\n"
" -resample X Y: Resample all input textures to XxY pixels using a box filter\n"
" -resample_factor X: Resample all input textures by scale factor X using a box filter\n"
" -no_sse: Forbid all SSE instruction set usage\n"
" -validate_etc1s: Validate internal ETC1S compressor's data structures during compression (slower, intended for development).\n"
" -ktx2_animdata_duration X: Set KTX2animData duration field to integer value X (only valid/useful for -tex_type video, default is 1)\n"
" -ktx2_animdata_timescale X: Set KTX2animData timescale field to integer value X (only valid/useful for -tex_type video, default is 15)\n"
" -ktx2_animdata_loopcount X: Set KTX2animData loopcount field to integer value X (only valid/useful for -tex_type video, default is 0)\n"
" -framerate X: Set framerate in .basis header to X/frames sec.\n"
" -ktx2_no_zstandard: Don't compress UASTC texture data using Zstandard -- store it uncompressed instead.\n"
" -ktx2_zstandard_level X: Set ZStandard compression level to X (see Zstandard documentation, default level is 6)\n"
"\n"
"Mipmap generation options:\n"
" -mipmap: Generate mipmaps for each source image\n"
" -mip_srgb: Convert image to linear before filtering, then back to sRGB\n"
" -mip_linear: Keep image in linear light during mipmap filtering (i.e. do not convert to/from sRGB for filtering purposes)\n"
" -mip_scale X: Set mipmap filter kernel's scale, lower=sharper, higher=more blurry, default is 1.0\n"
" -mip_filter X: Set mipmap filter kernel, default is kaiser, filters: box, tent, bell, blackman, catmullrom, mitchell, etc.\n"
" -mip_renorm: Renormalize normal map to unit length vectors after filtering\n"
" -mip_clamp: Use clamp addressing on borders, instead of wrapping\n"
" -mip_fast: Use faster mipmap generation (resample from previous mip, not always first/largest mip level). The default (as of 1/2021)\n"
" -mip_slow: Always resample each mipmap level starting from the largest mipmap. Higher quality, but slower. Opposite of -mip_fast. Was the prior default before 1/2021.\n"
" -mip_smallest X: Set smallest pixel dimension for generated mipmaps, default is 1 pixel\n"
"By default, textures will be converted from sRGB to linear light before mipmap filtering, then back to sRGB (for the RGB color channels) unless -linear is specified.\n"
"You can override this behavior with -mip_srgb/-mip_linear.\n"
"\n"
"Backend endpoint/selector RDO codec options:\n"
" -no_selector_rdo: Disable backend's selector rate distortion optimizations (slightly faster, less noisy output, but lower quality per output bit)\n"
" -selector_rdo_thresh X: Set selector RDO quality threshold, default is 1.25, lower is higher quality but less quality per output bit (try 1.0-3.0)\n"
" -no_endpoint_rdo: Disable backend's endpoint rate distortion optimizations (slightly faster, less noisy output, but lower quality per output bit)\n"
" -endpoint_rdo_thresh X: Set endpoint RDO quality threshold, default is 1.5, lower is higher quality but less quality per output bit (try 1.0-3.0)\n"
"\n"
"Set various fields in the Basis file header:\n"
" -userdata0 X: Set 32-bit userdata0 field in Basis file header to X (X is a signed 32-bit int)\n"
" -userdata1 X: Set 32-bit userdata1 field in Basis file header to X (X is a signed 32-bit int)\n"
"\n"
"Example LDR command lines:\n"
" basisu x.png : Compress sRGB image x.png to x.ktx2 using default settings (multiple filenames OK, use -tex_array if you want a tex array vs. multiple output files)\n"
" basisu -basis x.qoi : Compress sRGB image x.qoi to x.basis (supports 24-bit or 32-bit .QOI files)\n"
" basisu x.ktx2 : Unpack x.basis to PNG/KTX files (multiple filenames OK)\n"
" basisu x.basis : Unpack x.basis to PNG/KTX files (multiple filenames OK)\n"
" basisu -uastc x.png -uastc_rdo_l 2.0 -ktx2 -stats : Compress to a UASTC .KTX2 file with RDO (rate distortion optimization) to reduce .KTX2 compressed file size\n"
" basisu -file x.png -mipmap -y_flip : Compress a mipmapped x.ktx2 file from an sRGB image named x.png, Y flip each source image\n"
" basisu -validate -file x.basis : Validate x.basis (check header, check file CRC's, attempt to transcode all slices)\n"
" basisu -unpack -file x.basis : Validates, transcodes and unpacks x.basis to mipmapped .KTX and RGB/A .PNG files (transcodes to all supported GPU texture formats)\n"
" basisu -q 255 -file x.png -mipmap -debug -stats : Compress sRGB x.png to x.ktx2 at quality level 255 with compressor debug output/statistics\n"
" basisu -linear -max_endpoints 16128 -max_selectors 16128 -file x.png : Compress non-sRGB x.png to x.ktx2 using the largest supported manually specified codebook sizes\n"
" basisu -basis -comp_level 2 -max_selectors 8192 -max_endpoints 8192 -tex_type video -framerate 20 -multifile_printf \"x%02u.png\" -multifile_first 1 -multifile_count 20 : Compress a 20 sRGB source image video sequence (x01.png, x02.png, x03.png, etc.) to x01.basis\n"
"\n"
"Example HDR command lines:\n"
" basisu x.exr : Compress a HDR .EXR image to a UASTC HDR .KTX2 file.\n"
" basisu x.hdr -uastc_level 0 : Compress a HDR .hdr image to a UASTC HDR .KTX2 file, fastest encoding but lowest quality\n"
" basisu -hdr x.png : Compress a LDR .PNG image to UASTC HDR (image is converted from sRGB to linear light first, use -hdr_ldr_no_srgb_to_linear to disable)\n"
" basisu x.hdr -uastc_level 3 : Compress a HDR .hdr image to UASTC HDR at higher quality (-uastc_level 4 is highest quality, but very slow encoding)\n"
" basisu x.hdr -uastc_level 3 -mipmap -basis -stats -debug -debug_images : Compress a HDR .hdr image to a UASTC HDR, .basis output file, at higher quality, generate mipmaps, output statistics and debug information, and write tone mapped debug images\n"
" basisu x.hdr -stats -hdr_favor_astc -hdr_uber_mode -uastc_level 4 : Highest achievable ASTC HDR quality (very slow encoding, BC6H quality is traded off)\n"
"\n"
"Video notes: For video use, it's recommended to encode on a machine with many cores. Use -comp_level 2 or higher for better codebook\n"
"generation, specify very large codebooks using -max_endpoints and -max_selectors, and reduce the default endpoint RDO threshold\n"
"(-endpoint_rdo_thresh) to around 1.25. Videos may have mipmaps and alpha channels. Videos must always be played back by the transcoder\n"
"in first to last image order.\n"
"Video files currently use I-Frames on the first image, and P-Frames using conditional replenishment on subsequent frames.\n"
"\nETC1S Compression level (-comp_level X) details. This controls the ETC1S speed vs. quality trandeoff. (Use -q to control the quality vs. compressed size tradeoff.):\n"
" Level 0: Fastest, but has marginal quality and can be brittle on complex images. Avg. Y dB: 35.45\n"
" Level 1: Hierarchical codebook searching, faster ETC1S encoding. 36.87 dB, ~1.4x slower vs. level 0. (This is the default setting.)\n"
" Level 2: Use this or higher for video. Hierarchical codebook searching. 36.87 dB, ~1.4x slower vs. level 0. (This is the v1.12's default setting.)\n"
" Level 3: Full codebook searching. 37.13 dB, ~1.8x slower vs. level 0. (Equivalent the the initial release's default settings.)\n"
" Level 4: Hierarchical codebook searching, codebook k-means iterations. 37.15 dB, ~4x slower vs. level 0\n"
" Level 5: Full codebook searching, codebook k-means iterations. 37.41 dB, ~5.5x slower vs. level 0.\n"
" Level 6: Full codebook searching, twice as many codebook k-means iterations, best ETC1 endpoint opt. 37.43 dB, ~12x slower vs. level 0\n"
);
}
static bool load_listing_file(const std::string &f, basisu::vector<std::string> &filenames)
{
std::string filename(f);
filename.erase(0, 1);
FILE *pFile = nullptr;
#ifdef _WIN32
fopen_s(&pFile, filename.c_str(), "r");
#else
pFile = fopen(filename.c_str(), "r");
#endif
if (!pFile)
{
error_printf("Failed opening listing file: \"%s\"\n", filename.c_str());
return false;
}
uint32_t total_filenames = 0;
for ( ; ; )
{
char buf[3072];
buf[0] = '\0';
char *p = fgets(buf, sizeof(buf), pFile);
if (!p)
{
if (ferror(pFile))
{
error_printf("Failed reading from listing file: \"%s\"\n", filename.c_str());
fclose(pFile);
return false;
}
else
break;
}
std::string read_filename(p);
while (read_filename.size())
{
if (read_filename[0] == ' ')
read_filename.erase(0, 1);
else
break;
}
while (read_filename.size())
{
const char c = read_filename.back();
if ((c == ' ') || (c == '\n') || (c == '\r'))
read_filename.erase(read_filename.size() - 1, 1);
else
break;
}
if (read_filename.size())
{
filenames.push_back(read_filename);
total_filenames++;
}
}
fclose(pFile);
printf("Successfully read %u filenames(s) from listing file \"%s\"\n", total_filenames, filename.c_str());
return true;
}
class command_line_params
{
BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(command_line_params);
public:
command_line_params() :
m_mode(cDefault),
m_ktx2_mode(true),
m_ktx2_zstandard(true),
m_ktx2_zstandard_level(6),
m_ktx2_animdata_duration(1),
m_ktx2_animdata_timescale(15),
m_ktx2_animdata_loopcount(0),
m_format_only(-1),
m_multifile_first(0),
m_multifile_num(0),
m_max_threads(1024), // surely this is high enough
m_individual(true),
m_no_ktx(false),
m_ktx_only(false),
m_write_out(false),
m_etc1_only(false),
m_fuzz_testing(false),
m_compare_ssim(false),
m_compare_plot(false),
m_parallel_compression(false)
{
m_comp_params.m_compression_level = basisu::maximum<int>(0, BASISU_DEFAULT_COMPRESSION_LEVEL - 1);
m_comp_params.m_uastc_hdr_options.set_quality_level(astc_hdr_codec_options::cDefaultLevel);
m_test_file_dir = "../test_files";
}
bool parse(int arg_c, const char **arg_v)
{
int arg_index = 1;
while (arg_index < arg_c)
{
const char *pArg = arg_v[arg_index];
const int num_remaining_args = arg_c - (arg_index + 1);
int arg_count = 1;
#define REMAINING_ARGS_CHECK(n) if (num_remaining_args < (n)) { error_printf("Error: Expected %u values to follow %s!\n", n, pArg); return false; }
if ((strcasecmp(pArg, "-help") == 0) || (strcasecmp(pArg, "--help") == 0))
{
print_usage();
exit(EXIT_SUCCESS);
}
else if (strcasecmp(pArg, "-ktx2") == 0)
{
m_ktx2_mode = true;
}
else if (strcasecmp(pArg, "-basis") == 0)
{
m_ktx2_mode = false;
}
else if (strcasecmp(pArg, "-ktx2_no_zstandard") == 0)
{
m_ktx2_zstandard = false;
}
else if (strcasecmp(pArg, "-ktx2_zstandard_level") == 0)
{
REMAINING_ARGS_CHECK(1);
m_ktx2_zstandard_level = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-ktx2_animdata_duration") == 0)
{
REMAINING_ARGS_CHECK(1);
m_ktx2_animdata_duration = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-ktx2_animdata_timescale") == 0)
{
REMAINING_ARGS_CHECK(1);
m_ktx2_animdata_timescale = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-ktx2_animdata_loopcount") == 0)
{
REMAINING_ARGS_CHECK(1);
m_ktx2_animdata_loopcount = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-ldr") == 0)
{
}
else if (strcasecmp(pArg, "-compress") == 0)
m_mode = cCompress;
else if (strcasecmp(pArg, "-compare") == 0)
m_mode = cCompare;
else if ((strcasecmp(pArg, "-hdr_compare") == 0) || (strcasecmp(pArg, "-compare_hdr") == 0))
m_mode = cHDRCompare;
else if (strcasecmp(pArg, "-split") == 0)
m_mode = cSplitImage;
else if (strcasecmp(pArg, "-combine") == 0)
m_mode = cCombineImages;
else if (strcasecmp(pArg, "-tonemap") == 0)
m_mode = cTonemapImage;
else if (strcasecmp(pArg, "-unpack") == 0)
m_mode = cUnpack;
else if (strcasecmp(pArg, "-validate") == 0)
m_mode = cValidate;
else if (strcasecmp(pArg, "-info") == 0)
m_mode = cInfo;
else if ((strcasecmp(pArg, "-version") == 0) || (strcasecmp(pArg, "--version") == 0))
m_mode = cVersion;
else if (strcasecmp(pArg, "-compare_ssim") == 0)
m_compare_ssim = true;
else if (strcasecmp(pArg, "-compare_plot") == 0)
m_compare_plot = true;
else if (strcasecmp(pArg, "-bench") == 0)
m_mode = cBench;
else if (strcasecmp(pArg, "-comp_size") == 0)
m_mode = cCompSize;
else if (strcasecmp(pArg, "-hdr_ldr_no_srgb_to_linear") == 0)
m_comp_params.m_hdr_ldr_srgb_to_linear_conversion = false;
else if (strcasecmp(pArg, "-hdr_uber_mode") == 0)
m_comp_params.m_uastc_hdr_options.m_allow_uber_mode = true;
else if (strcasecmp(pArg, "-hdr_favor_astc") == 0)
m_comp_params.m_hdr_favor_astc = true;
else if ((strcasecmp(pArg, "-test") == 0) || (strcasecmp(pArg, "-test_ldr") == 0))
m_mode = cTestLDR;
else if (strcasecmp(pArg, "-test_hdr") == 0)
m_mode = cTestHDR;
else if (strcasecmp(pArg, "-clbench") == 0)
m_mode = cCLBench;
else if (strcasecmp(pArg, "-test_dir") == 0)
{
REMAINING_ARGS_CHECK(1);
m_test_file_dir = std::string(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-no_sse") == 0)
{
#if BASISU_SUPPORT_SSE
g_cpu_supports_sse41 = false;
#endif
}
else if (strcasecmp(pArg, "-no_status_output") == 0)
{
m_comp_params.m_status_output = false;
}
else if (strcasecmp(pArg, "-file") == 0)
{
REMAINING_ARGS_CHECK(1);
m_input_filenames.push_back(std::string(arg_v[arg_index + 1]));
arg_count++;
}
else if (strcasecmp(pArg, "-alpha_file") == 0)
{
REMAINING_ARGS_CHECK(1);
m_input_alpha_filenames.push_back(std::string(arg_v[arg_index + 1]));
arg_count++;
}
else if (strcasecmp(pArg, "-multifile_printf") == 0)
{
REMAINING_ARGS_CHECK(1);
m_multifile_printf = std::string(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-multifile_first") == 0)
{
REMAINING_ARGS_CHECK(1);
m_multifile_first = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-multifile_num") == 0)
{
REMAINING_ARGS_CHECK(1);
m_multifile_num = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-uastc") == 0)
m_comp_params.m_uastc = true;
else if (strcasecmp(pArg, "-fastest") == 0)
{
m_comp_params.m_pack_uastc_flags &= ~cPackUASTCLevelMask;
m_comp_params.m_pack_uastc_flags |= cPackUASTCLevelFastest;
m_comp_params.m_uastc_hdr_options.set_quality_level(0);
}
else if (strcasecmp(pArg, "-slower") == 0)
{
m_comp_params.m_pack_uastc_flags &= ~cPackUASTCLevelMask;
m_comp_params.m_pack_uastc_flags |= cPackUASTCLevelSlower;
m_comp_params.m_uastc_hdr_options.set_quality_level(3);
}
else if (strcasecmp(pArg, "-uastc_level") == 0)
{
REMAINING_ARGS_CHECK(1);
int uastc_level = atoi(arg_v[arg_index + 1]);
uastc_level = clamp<int>(uastc_level, 0, TOTAL_PACK_UASTC_LEVELS - 1);
static_assert(TOTAL_PACK_UASTC_LEVELS == 5, "TOTAL_PACK_UASTC_LEVELS==5");
static const uint32_t s_level_flags[TOTAL_PACK_UASTC_LEVELS] = { cPackUASTCLevelFastest, cPackUASTCLevelFaster, cPackUASTCLevelDefault, cPackUASTCLevelSlower, cPackUASTCLevelVerySlow };
m_comp_params.m_pack_uastc_flags &= ~cPackUASTCLevelMask;
m_comp_params.m_pack_uastc_flags |= s_level_flags[uastc_level];
m_comp_params.m_uastc_hdr_options.set_quality_level(uastc_level);
arg_count++;
}
else if (strcasecmp(pArg, "-resample") == 0)
{
REMAINING_ARGS_CHECK(2);
m_comp_params.m_resample_width = atoi(arg_v[arg_index + 1]);
m_comp_params.m_resample_height = atoi(arg_v[arg_index + 2]);
arg_count += 2;
}
else if (strcasecmp(pArg, "-resample_factor") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_resample_factor = (float)atof(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-uastc_rdo_l") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_rdo_uastc_quality_scalar = (float)atof(arg_v[arg_index + 1]);
m_comp_params.m_rdo_uastc = true;
arg_count++;
}
else if (strcasecmp(pArg, "-uastc_rdo_d") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_rdo_uastc_dict_size = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-uastc_rdo_b") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_rdo_uastc_max_smooth_block_error_scale = (float)atof(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-uastc_rdo_s") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_rdo_uastc_smooth_block_max_std_dev = (float)atof(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-uastc_rdo_f") == 0)
m_comp_params.m_rdo_uastc_favor_simpler_modes_in_rdo_mode = false;
else if (strcasecmp(pArg, "-uastc_rdo_m") == 0)
m_comp_params.m_rdo_uastc_multithreading = false;
else if (strcasecmp(pArg, "-linear") == 0)
m_comp_params.m_perceptual = false;
else if (strcasecmp(pArg, "-srgb") == 0)
m_comp_params.m_perceptual = true;
else if (strcasecmp(pArg, "-q") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_quality_level = clamp<int>(atoi(arg_v[arg_index + 1]), BASISU_QUALITY_MIN, BASISU_QUALITY_MAX);
arg_count++;
}
else if (strcasecmp(pArg, "-output_file") == 0)
{
REMAINING_ARGS_CHECK(1);
m_output_filename = arg_v[arg_index + 1];
arg_count++;
}
else if (strcasecmp(pArg, "-output_path") == 0)
{
REMAINING_ARGS_CHECK(1);
m_output_path = arg_v[arg_index + 1];
arg_count++;
}
else if ((strcasecmp(pArg, "-debug") == 0) || (strcasecmp(pArg, "-verbose") == 0))
{
m_comp_params.m_debug = true;
enable_debug_printf(true);
}
else if (strcasecmp(pArg, "-validate_etc1s") == 0)
{
m_comp_params.m_validate_etc1s = true;
}
else if (strcasecmp(pArg, "-validate_output") == 0)
{
m_comp_params.m_validate_output_data = true;
}
else if (strcasecmp(pArg, "-debug_images") == 0)
m_comp_params.m_debug_images = true;
else if (strcasecmp(pArg, "-stats") == 0)
m_comp_params.m_compute_stats = true;
else if (strcasecmp(pArg, "-gen_global_codebooks") == 0)
{
// TODO
}
else if (strcasecmp(pArg, "-use_global_codebooks") == 0)
{
REMAINING_ARGS_CHECK(1);
m_etc1s_use_global_codebooks_file = arg_v[arg_index + 1];
arg_count++;
}
else if (strcasecmp(pArg, "-comp_level") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_compression_level = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-max_endpoints") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_max_endpoint_clusters = clamp<int>(atoi(arg_v[arg_index + 1]), 1, BASISU_MAX_ENDPOINT_CLUSTERS);
arg_count++;
}
else if (strcasecmp(pArg, "-max_selectors") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_max_selector_clusters = clamp<int>(atoi(arg_v[arg_index + 1]), 1, BASISU_MAX_SELECTOR_CLUSTERS);
arg_count++;
}
else if (strcasecmp(pArg, "-y_flip") == 0)
m_comp_params.m_y_flip = true;
else if (strcasecmp(pArg, "-normal_map") == 0)
{
m_comp_params.m_perceptual = false;
m_comp_params.m_mip_srgb = false;
m_comp_params.m_no_selector_rdo = true;
m_comp_params.m_no_endpoint_rdo = true;
}
else if (strcasecmp(pArg, "-no_alpha") == 0)
m_comp_params.m_check_for_alpha = false;
else if (strcasecmp(pArg, "-force_alpha") == 0)
m_comp_params.m_force_alpha = true;
else if ((strcasecmp(pArg, "-separate_rg_to_color_alpha") == 0) ||
(strcasecmp(pArg, "-seperate_rg_to_color_alpha") == 0)) // was mispelled for a while - whoops!
{
m_comp_params.m_swizzle[0] = 0;
m_comp_params.m_swizzle[1] = 0;
m_comp_params.m_swizzle[2] = 0;
m_comp_params.m_swizzle[3] = 1;
}
else if (strcasecmp(pArg, "-swizzle") == 0)
{
REMAINING_ARGS_CHECK(1);
const char *swizzle = arg_v[arg_index + 1];
if (strlen(swizzle) != 4)
{
error_printf("Swizzle requires exactly 4 characters\n");
return false;
}
for (int i=0; i<4; ++i)
{
if (swizzle[i] == 'r')
m_comp_params.m_swizzle[i] = 0;
else if (swizzle[i] == 'g')
m_comp_params.m_swizzle[i] = 1;
else if (swizzle[i] == 'b')
m_comp_params.m_swizzle[i] = 2;
else if (swizzle[i] == 'a')
m_comp_params.m_swizzle[i] = 3;
else
{
error_printf("Swizzle must be one of [rgba]");
return false;
}
}
arg_count++;
}
else if (strcasecmp(pArg, "-renorm") == 0)
m_comp_params.m_renormalize = true;
else if ((strcasecmp(pArg, "-no_multithreading") == 0) || (strcasecmp(pArg, "-no_threading") == 0))
{
m_comp_params.m_multithreading = false;
}
else if (strcasecmp(pArg, "-parallel") == 0)
{
m_parallel_compression = true;
}
else if (strcasecmp(pArg, "-max_threads") == 0)
{
REMAINING_ARGS_CHECK(1);
m_max_threads = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-mipmap") == 0)
m_comp_params.m_mip_gen = true;
else if (strcasecmp(pArg, "-no_ktx") == 0)
m_no_ktx = true;
else if (strcasecmp(pArg, "-ktx_only") == 0)
m_ktx_only = true;
else if (strcasecmp(pArg, "-write_out") == 0)
m_write_out = true;
else if (strcasecmp(pArg, "-format_only") == 0)
{
REMAINING_ARGS_CHECK(1);
m_format_only = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-etc1_only") == 0)
{
m_etc1_only = true;
m_format_only = (int)basist::transcoder_texture_format::cTFETC1_RGB;
}
else if (strcasecmp(pArg, "-disable_hierarchical_endpoint_codebooks") == 0)
m_comp_params.m_disable_hierarchical_endpoint_codebooks = true;
else if (strcasecmp(pArg, "-hdr") == 0)
{
m_comp_params.m_hdr = true;
m_comp_params.m_uastc = true;
}
else if (strcasecmp(pArg, "-opencl") == 0)
{
m_comp_params.m_use_opencl = true;
}
else if (strcasecmp(pArg, "-opencl_serialize") == 0)
{
}
else if (strcasecmp(pArg, "-mip_scale") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_mip_scale = (float)atof(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-mip_filter") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_mip_filter = arg_v[arg_index + 1];
// TODO: Check filter
arg_count++;
}
else if (strcasecmp(pArg, "-mip_renorm") == 0)
m_comp_params.m_mip_renormalize = true;
else if (strcasecmp(pArg, "-mip_clamp") == 0)
m_comp_params.m_mip_wrapping = false;
else if (strcasecmp(pArg, "-mip_fast") == 0)
m_comp_params.m_mip_fast = true;
else if (strcasecmp(pArg, "-mip_slow") == 0)
m_comp_params.m_mip_fast = false;
else if (strcasecmp(pArg, "-mip_smallest") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_mip_smallest_dimension = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-mip_srgb") == 0)
m_comp_params.m_mip_srgb = true;
else if (strcasecmp(pArg, "-mip_linear") == 0)
m_comp_params.m_mip_srgb = false;
else if (strcasecmp(pArg, "-no_selector_rdo") == 0)
m_comp_params.m_no_selector_rdo = true;
else if (strcasecmp(pArg, "-selector_rdo_thresh") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_selector_rdo_thresh = (float)atof(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-no_endpoint_rdo") == 0)
m_comp_params.m_no_endpoint_rdo = true;
else if (strcasecmp(pArg, "-endpoint_rdo_thresh") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_endpoint_rdo_thresh = (float)atof(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-userdata0") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_userdata0 = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-userdata1") == 0)
{
REMAINING_ARGS_CHECK(1);
m_comp_params.m_userdata1 = atoi(arg_v[arg_index + 1]);
arg_count++;
}
else if (strcasecmp(pArg, "-framerate") == 0)
{
REMAINING_ARGS_CHECK(1);
double fps = atof(arg_v[arg_index + 1]);
double us_per_frame = 0;
if (fps > 0)
us_per_frame = 1000000.0f / fps;
m_comp_params.m_us_per_frame = clamp<int>(static_cast<int>(us_per_frame + .5f), 0, basist::cBASISMaxUSPerFrame);
arg_count++;
}
else if (strcasecmp(pArg, "-cubemap") == 0)
{
m_comp_params.m_tex_type = basist::cBASISTexTypeCubemapArray;
m_individual = false;
}
else if (strcasecmp(pArg, "-tex_type") == 0)
{
REMAINING_ARGS_CHECK(1);
const char* pType = arg_v[arg_index + 1];
if (strcasecmp(pType, "2d") == 0)
m_comp_params.m_tex_type = basist::cBASISTexType2D;
else if (strcasecmp(pType, "2darray") == 0)
{
m_comp_params.m_tex_type = basist::cBASISTexType2DArray;
m_individual = false;
}
else if (strcasecmp(pType, "3d") == 0)
{
m_comp_params.m_tex_type = basist::cBASISTexTypeVolume;
m_individual = false;
}
else if (strcasecmp(pType, "cubemap") == 0)
{
m_comp_params.m_tex_type = basist::cBASISTexTypeCubemapArray;
m_individual = false;
}
else if (strcasecmp(pType, "video") == 0)
{
m_comp_params.m_tex_type = basist::cBASISTexTypeVideoFrames;
m_individual = false;
}
else
{
error_printf("Invalid texture type: %s\n", pType);
return false;
}
arg_count++;
}
else if (strcasecmp(pArg, "-individual") == 0)
m_individual = true;
else if ((strcasecmp(pArg, "-tex_array") == 0) || (strcasecmp(pArg, "-texarray") == 0))
m_individual = false;
else if (strcasecmp(pArg, "-fuzz_testing") == 0)
m_fuzz_testing = true;
else if (strcasecmp(pArg, "-csv_file") == 0)
{
REMAINING_ARGS_CHECK(1);
m_csv_file = arg_v[arg_index + 1];
m_comp_params.m_compute_stats = true;
arg_count++;
}
else if (pArg[0] == '-')
{
error_printf("Unrecognized command line option: %s\n", pArg);
return false;
}
else
{
// Let's assume it's a source filename, so globbing works
//error_printf("Unrecognized command line option: %s\n", pArg);
m_input_filenames.push_back(pArg);
}
arg_index += arg_count;
}
if (m_comp_params.m_quality_level != -1)
{
m_comp_params.m_max_endpoint_clusters = 0;
m_comp_params.m_max_selector_clusters = 0;
}
else if ((!m_comp_params.m_max_endpoint_clusters) || (!m_comp_params.m_max_selector_clusters))
{
m_comp_params.m_max_endpoint_clusters = 0;
m_comp_params.m_max_selector_clusters = 0;
m_comp_params.m_quality_level = 128;
}
if (!m_comp_params.m_mip_srgb.was_changed())
{
// They didn't specify what colorspace to do mipmap filtering in, so choose sRGB if they've specified that the texture is sRGB.
if (m_comp_params.m_perceptual)
m_comp_params.m_mip_srgb = true;
else
m_comp_params.m_mip_srgb = false;
}
return true;
}
bool process_listing_files()
{
basisu::vector<std::string> new_input_filenames;
for (uint32_t i = 0; i < m_input_filenames.size(); i++)
{
if (m_input_filenames[i][0] == '@')
{
if (!load_listing_file(m_input_filenames[i], new_input_filenames))
return false;
}
else
new_input_filenames.push_back(m_input_filenames[i]);
}
new_input_filenames.swap(m_input_filenames);
basisu::vector<std::string> new_input_alpha_filenames;
for (uint32_t i = 0; i < m_input_alpha_filenames.size(); i++)
{
if (m_input_alpha_filenames[i][0] == '@')
{
if (!load_listing_file(m_input_alpha_filenames[i], new_input_alpha_filenames))
return false;
}
else
new_input_alpha_filenames.push_back(m_input_alpha_filenames[i]);
}
new_input_alpha_filenames.swap(m_input_alpha_filenames);
return true;
}
basis_compressor_params m_comp_params;
tool_mode m_mode;
bool m_ktx2_mode;
bool m_ktx2_zstandard;
int m_ktx2_zstandard_level;
uint32_t m_ktx2_animdata_duration;
uint32_t m_ktx2_animdata_timescale;
uint32_t m_ktx2_animdata_loopcount;
basisu::vector<std::string> m_input_filenames;
basisu::vector<std::string> m_input_alpha_filenames;
std::string m_output_filename;
std::string m_output_path;
int m_format_only;
std::string m_multifile_printf;
uint32_t m_multifile_first;
uint32_t m_multifile_num;
std::string m_csv_file;
std::string m_etc1s_use_global_codebooks_file;
std::string m_test_file_dir;
uint32_t m_max_threads;
bool m_individual;
bool m_no_ktx;
bool m_ktx_only;
bool m_write_out;
bool m_etc1_only;
bool m_fuzz_testing;
bool m_compare_ssim;
bool m_compare_plot;
bool m_parallel_compression;
};
static bool expand_multifile(command_line_params &opts)
{
if (!opts.m_multifile_printf.size())
return true;
if (!opts.m_multifile_num)
{
error_printf("-multifile_printf specified, but not -multifile_num\n");
return false;
}
std::string fmt(opts.m_multifile_printf);
// Workaround for MSVC debugger issues. Questionable to leave in here.
size_t x = fmt.find_first_of('!');
if (x != std::string::npos)
fmt[x] = '%';
if (string_find_right(fmt, '%') == -1)
{
error_printf("Must include C-style printf() format character '%%' in -multifile_printf string\n");
return false;
}
for (uint32_t i = opts.m_multifile_first; i < opts.m_multifile_first + opts.m_multifile_num; i++)
{
char buf[1024];
#ifdef _WIN32
sprintf_s(buf, sizeof(buf), fmt.c_str(), i);
#else
snprintf(buf, sizeof(buf), fmt.c_str(), i);
#endif
if (buf[0])
opts.m_input_filenames.push_back(buf);