Skip to content

Commit 0eaebb0

Browse files
authored
Add convert command (#1099)
For converting ktx v1 files. Fixes formatting error in encode man page (doxygen).
1 parent 964acdc commit 0eaebb0

File tree

14 files changed

+365
-36
lines changed

14 files changed

+365
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Javascript wrapper for Basis Universal formats. For use with KTX parsers written
3939
[`interface/java_binding`](https://github.com/KhronosGroup/KTX-Software/tree/main/interface/java_binding)
4040
- *ktx* - a generic command line tool for managing KTX2 files with subcommands.[`tools/ktx`](https://github.com/KhronosGroup/KTX-Software/tree/main/tools/ktx)
4141
- *ktx compare* - Compare two KTX2 files
42+
- *ktx convert* - Convert other texture file types to KTX2
4243
- *ktx create* - Create a KTX2 file from various input files
4344
- *ktx deflate* - Deflate a KTX2 file with zstd or ZLIB
4445
- *ktx extract* - Export selected images from a KTX2 file

cmake/docs.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function( CreateDocTools )
166166
tools.doc
167167
tools/ktx/ktx_main.cpp
168168
tools/ktx/command_compare.cpp
169+
tools/ktx/command_convert.cpp
169170
tools/ktx/command_create.cpp
170171
tools/ktx/command_deflate.cpp
171172
tools/ktx/command_encode.cpp

external/dfdutils/.gitrepo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[subrepo]
77
remote = https://github.com/KhronosGroup/dfdutils.git
88
branch = main
9-
commit = 854792a6ced4cb7cce64f26bf297bf7ea294a9b6
10-
parent = 928612a718eaaf0a47e8ae6e5b74b13ac16637b1
9+
commit = c802c1b6849d05d1f23d1cdc3c0569c8dd3663f6
10+
parent = 5a07bc6f8eb95b6ea5b636903b335947d4684cef
1111
method = merge
12-
cmdver = 0.4.3
12+
cmdver = 0.4.9

tests/cts

Submodule cts updated 80 files

tools/ktx/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_executable(ktxtools
77
command.cpp
88
command.h
99
command_compare.cpp
10+
command_convert.cpp
1011
command_create.cpp
1112
command_deflate.cpp
1213
command_encode.cpp
@@ -30,6 +31,8 @@ add_executable(ktxtools
3031
validate.cpp
3132
validate.h
3233
validation_messages.h
34+
# Until the API is public
35+
${PROJECT_SOURCE_DIR}/lib/src/glformat_str.c
3336
)
3437

3538
create_version_header(tools/ktx ktxtools)

tools/ktx/command.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ OutputStream::OutputStream(const std::string& filepath, Reporter& report) :
162162
}
163163

164164
OutputStream::~OutputStream() {
165-
if (file != stdout)
165+
if (file != stdout) {
166166
fclose(file);
167+
if (removeAtDestruct) std::filesystem::remove(DecodeUTF8Path(filepath).c_str());
168+
}
167169
}
168170

169171
void OutputStream::write(const char* data, std::size_t size, Reporter& report) {

tools/ktx/command.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ struct OptionsSingleIn {
262262
}
263263
};
264264

265+
template<bool OUTPUT_FILE_OPTIONAL = false>
265266
struct OptionsSingleInSingleOut {
266267
std::string inputFilepath;
267268
std::string outputFilepath;
@@ -285,7 +286,7 @@ struct OptionsSingleInSingleOut {
285286
if (args.count("stdin") + args.count("input-file") > 1)
286287
report.fatal_usage("Conflicting options: Only one can be specified from <input-file> and --stdin.");
287288

288-
if (args.count("stdout") + args.count("output-file") == 0)
289+
if (args.count("stdout") + args.count("output-file") == 0 && !OUTPUT_FILE_OPTIONAL)
289290
report.fatal_usage("Missing output file. Either <output-file> or --stdout must be specified.");
290291
if (args.count("stdout") + args.count("output-file") > 1)
291292
report.fatal_usage("Conflicting options: Only one can be specified from <output-file> and --stdout.");
@@ -297,7 +298,7 @@ struct OptionsSingleInSingleOut {
297298

298299
if (args.count("stdout"))
299300
outputFilepath = "-";
300-
else
301+
else if (args.count("output-file"))
301302
outputFilepath = args["output-file"].as<std::string>();
302303
}
303304
};
@@ -383,8 +384,10 @@ class InputStream {
383384

384385
/// Helper to handle stdout and fstream uniformly
385386
class OutputStream {
387+
protected:
386388
std::string filepath;
387389
FILE* file;
390+
bool removeAtDestruct = false;
388391
// std::ostream* activeStream = nullptr;
389392
// std::ofstream file; // Unused for stdin/stdout
390393

@@ -396,6 +399,9 @@ class OutputStream {
396399
return filepath;
397400
}
398401

402+
bool isStdout() { return (file == stdout); }
403+
void flush() { fflush(file); }
404+
void removeOnDestruct() { removeAtDestruct = true; }
399405
void writeKTX2(ktxTexture* texture, Reporter& report);
400406
void write(const char* data, std::size_t size, Reporter& report);
401407
};

0 commit comments

Comments
 (0)