all: use mach-basisu via github.com/hexops/mach-basisu

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2023-07-02 11:47:27 -07:00
parent 6794b4b91b
commit d1404e782f
24 changed files with 15 additions and 1408 deletions

View file

@ -52,7 +52,6 @@ push_subrepo() {
rm -rf staging-clean/ staging/
git clone https://github.com/hexops/mach staging-clean
push_subrepo 'basisu'
push_subrepo 'core'
push_subrepo 'freetype'
push_subrepo 'glfw'

4
.gitmodules vendored
View file

@ -15,7 +15,3 @@
[submodule "glfw/upstream"]
path = libs/glfw/upstream
url = https://github.com/hexops-graveyard/glfw
[submodule "basisu/upstream"]
path = libs/basisu/upstream
url = https://github.com/hexops-graveyard/basisu

View file

@ -3,7 +3,6 @@ const builtin = @import("builtin");
const system_sdk = @import("libs/glfw/system_sdk.zig");
const glfw = @import("libs/glfw/build.zig");
const freetype = @import("libs/freetype/build.zig");
const basisu = @import("libs/basisu/build.zig");
pub const gpu_dawn = @import("libs/gpu-dawn/sdk.zig").Sdk(.{
.glfw_include_dir = sdkPath("/libs/glfw/upstream/glfw/include"),
.system_sdk = system_sdk,
@ -33,6 +32,10 @@ pub fn module(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig
.target = target,
.optimize = optimize,
});
const mach_basisu = b.dependency("mach_basisu", .{
.target = target,
.optimize = optimize,
});
_module = b.createModule(.{
.source_file = .{ .path = sdkPath("/src/main.zig") },
@ -41,6 +44,7 @@ pub fn module(b: *std.Build, optimize: std.builtin.OptimizeMode, target: std.zig
.{ .name = "ecs", .module = mach_ecs.module("mach-ecs") },
.{ .name = "earcut", .module = mach_earcut.module("mach-earcut") },
.{ .name = "sysaudio", .module = sysaudio.module(b, optimize, target) },
.{ .name = "basisu", .module = mach_basisu.module("mach-basisu") },
},
});
return _module.?;
@ -82,18 +86,15 @@ pub fn build(b: *std.Build) !void {
const all_tests_step = b.step("test", "Run library tests");
const core_test_step = b.step("test-core", "Run Core library tests");
const freetype_test_step = b.step("test-freetype", "Run Freetype library tests");
const basisu_test_step = b.step("test-basisu", "Run Basis-Universal library tests");
const sysaudio_test_step = b.step("test-sysaudio", "Run sysaudio library tests");
const mach_test_step = b.step("test-mach", "Run Engine library tests");
core_test_step.dependOn(&(try core.testStep(b, optimize, target)).step);
freetype_test_step.dependOn(&freetype.testStep(b, optimize, target).step);
basisu_test_step.dependOn(&basisu.testStep(b, optimize, target).step);
sysaudio_test_step.dependOn(&sysaudio.testStep(b, optimize, target).step);
mach_test_step.dependOn(&testStep(b, optimize, target).step);
all_tests_step.dependOn(core_test_step);
all_tests_step.dependOn(basisu_test_step);
all_tests_step.dependOn(freetype_test_step);
all_tests_step.dependOn(sysaudio_test_step);
all_tests_step.dependOn(mach_test_step);
@ -196,6 +197,12 @@ pub const App = struct {
try app.core.link(options.core);
sysaudio.link(app.b, app.step, options.sysaudio);
if (app.use_freetype) |_| freetype.link(app.b, app.step, options.freetype);
const mach_basisu = app.b.dependency("mach_basisu", .{
.target = app.step.target,
.optimize = app.step.optimize,
});
app.step.linkLibrary(mach_basisu.artifact("mach-basisu"));
}
pub fn install(app: *const App) void {

View file

@ -22,5 +22,9 @@
.url = "https://github.com/hexops/mach-model3d/archive/499c0120d1ff678ab2b260e3be37af3e4b51e568.tar.gz",
.hash = "122098dff45c8bf49479688e2f0cb30903b1d5175c576782b53234dafa1f8be3f3d6",
},
.mach_basisu = .{
.url = "https://github.com/hexops/mach-basisu/archive/831de64fe2d7933d6418440f8558444ca32eeca5.tar.gz",
.hash = "1220ead8a15f606d6f0f853fe401460dfe18811e3d5d1aa7e808be825e44f17f0dc3",
},
},
}

View file

@ -1,2 +0,0 @@
* text=auto eol=lf
upstream/** linguist-vendored

View file

@ -1 +0,0 @@
github: slimsag

View file

@ -1,5 +0,0 @@
Please send your change to [the main repository](https://github.com/hexops/mach/tree/main/libs/basisu) instead, sorry for the trouble!
This helps us avoid some complex merge conflicts we run into when changes are made to both repositories and history needs to be reconciled. Keeping PRs in just that repository enables us to use `git subtree` to trivially keep the two repositories in sync.
Once your PR is merged over there, it'll automatically sync to this repository.

View file

@ -1,44 +0,0 @@
name: CI
on:
- push
- pull_request
jobs:
x86_64-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
sudo apt install xz-utils
sudo sh -c 'wget -c https://ziglang.org/builds/zig-linux-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: x86_64-linux -> aarch64-macos
run: zig build -Dtarget=aarch64-macos
- name: test
run: |
zig build test
x86_64-windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://ziglang.org/builds/zig-windows-x86_64-0.11.0-dev.3883+7166407d8.zip" -OutFile "C:\zig.zip"
cd C:\
7z x zig.zip
Add-Content $env:GITHUB_PATH "C:\zig-windows-x86_64-0.11.0-dev.3883+7166407d8\"
- name: test
run: zig build test
x86_64-macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Zig
run: |
brew install xz
sudo sh -c 'wget -c https://ziglang.org/builds/zig-macos-x86_64-0.11.0-dev.3883+7166407d8.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin'
- name: test
run: zig build test

View file

@ -1,18 +0,0 @@
# This file is for zig-specific build artifacts.
# If you have OS-specific or editor-specific files to ignore,
# such as *.swp or .DS_Store, put those in your global
# ~/.gitignore and put this in your ~/.gitconfig:
#
# [core]
# excludesfile = ~/.gitignore
#
# Cheers!
# -andrewrk
zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/

View file

@ -1,3 +0,0 @@
[submodule "upstream"]
path = upstream
url = https://github.com/hexops-graveyard/basisu

View file

@ -1,13 +0,0 @@
Copyright 2021, Hexops Contributors (given via the Git commit history).
All documentation, image, sound, font, and 2D/3D model files are CC-BY-4.0 licensed unless
otherwise noted. You may get a copy of this license at https://creativecommons.org/licenses/by/4.0
Files in a directory with a separate LICENSE file may contain files under different license terms,
described within that LICENSE file.
All other files are licensed under the Apache License, Version 2.0 (see LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
or the MIT license (see LICENSE-MIT or http://opensource.org/licenses/MIT), at your option.
All files in the project without exclusions may not be copied, modified, or distributed except
according to the terms above.

View file

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View file

@ -1,25 +0,0 @@
Copyright (c) 2021 Hexops Contributors (given via the Git commit history).
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View file

@ -1,46 +0,0 @@
# mach/basisu - basis universal (supercompressed textures) for Zig
This repository is a separate copy of the same library in the [main Mach repository](https://github.com/hexops/mach), and is automatically kept in sync, so that anyone can use this library in their own project if they like!
## Experimental
This is an _experimental_ Mach library, according to our [stability guarantees](https://machengine.org/next/docs/libs/):
> Experimental libraries may have their APIs change without much notice, and you may have to look at recent changes in order to update your code.
[Why this library is not declared stable yet](https://machengine.org/next/docs/libs/experimental/#basisu)
## Getting started
### Adding dependency
In a `libs` subdirectory of the root of your project:
```sh
git clone https://github.com/hexops/mach-basisu
```
Then in your `build.zig` add:
```zig
...
const basisu = @import("libs/mach-basisu/build.zig");
pub fn build(b: *Build) void {
...
exe.addModule("basisu", basisu.module(b));
basisu.link(b, exe, .{});
}
```
## Join the community
Join the Mach community [on Discord](https://discord.gg/XNG3NZgCqp) to discuss this project, ask questions, get help, etc.
## Issues
Issues are tracked in the [main Mach repository](https://github.com/hexops/mach/issues?q=is%3Aissue+is%3Aopen+label%3Abasisu).
## Contributing
Contributions are very welcome. Pull requests must be sent to [the main repository](https://github.com/hexops/mach/tree/main/libs/basisu) to avoid some complex merge conflicts we'd get by accepting contributions in both repositories. Once the changes are merged there, they'll get sync'd to this repository automatically.

View file

@ -1,156 +0,0 @@
const std = @import("std");
const Build = std.Build;
const basisu_root = sdkPath("/upstream/basisu");
var _module: ?*std.build.Module = null;
pub fn module(b: *std.Build) *std.build.Module {
if (_module) |m| return m;
_module = b.createModule(.{
.source = .{
.path = "src/main.zig",
},
});
return _module.?;
}
pub const Options = struct {
encoder: ?EncoderOptions,
transcoder: ?TranscoderOptions,
};
pub const EncoderOptions = struct {
install_libs: bool = false,
};
pub const TranscoderOptions = struct {
install_libs: bool = false,
};
pub fn build(b: *Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&testStep(b, optimize, target).step);
}
pub fn testStep(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.RunStep {
const main_tests = b.addTest(.{
.name = "basisu-tests",
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
.target = target,
.optimize = optimize,
});
main_tests.main_pkg_path = sdkPath("/");
link(b, main_tests, target, optimize, .{
.encoder = .{},
.transcoder = .{},
});
b.installArtifact(main_tests);
return b.addRunArtifact(main_tests);
}
pub fn link(b: *Build, step: *std.build.CompileStep, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) void {
if (options.encoder) |encoder_options| {
step.linkLibrary(buildEncoder(b, target, optimize, encoder_options));
step.addCSourceFile(sdkPath("/src/encoder/wrapper.cpp"), &.{});
step.addIncludePath(basisu_root ++ "/encoder");
}
if (options.transcoder) |transcoder_options| {
step.linkLibrary(buildTranscoder(b, target, optimize, transcoder_options));
step.addCSourceFile(sdkPath("/src/transcoder/wrapper.cpp"), &.{});
step.addIncludePath(basisu_root ++ "/transcoder");
}
}
pub fn buildEncoder(b: *Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: EncoderOptions) *std.build.CompileStep {
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
const encoder = b.addStaticLibrary(.{
.name = "basisu-encoder",
.target = target,
.optimize = optimize,
});
encoder.linkLibCpp();
encoder.addCSourceFiles(
encoder_sources,
&.{},
);
encoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0");
encoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0");
if (options.install_libs)
b.installArtifact(encoder);
return encoder;
}
pub fn buildTranscoder(b: *Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: TranscoderOptions) *std.build.CompileStep {
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
const transcoder = b.addStaticLibrary(.{
.name = "basisu-transcoder",
.target = target,
.optimize = optimize,
});
transcoder.linkLibCpp();
transcoder.addCSourceFiles(transcoder_sources, &.{
"-Wno-deprecated-builtins",
"-Wno-deprecated-declarations",
"-Wno-array-bounds",
});
transcoder.defineCMacro("BASISU_FORCE_DEVEL_MESSAGES", "0");
transcoder.defineCMacro("BASISD_SUPPORT_KTX2_ZSTD", "0");
if (options.install_libs)
b.installArtifact(transcoder);
return transcoder;
}
fn ensureDependencySubmodule(allocator: std.mem.Allocator, path: []const u8) !void {
if (std.process.getEnvVarOwned(allocator, "NO_ENSURE_SUBMODULES")) |no_ensure_submodules| {
defer allocator.free(no_ensure_submodules);
if (std.mem.eql(u8, no_ensure_submodules, "true")) return;
} else |_| {}
var child = std.ChildProcess.init(&.{ "git", "submodule", "update", "--init", path }, allocator);
child.cwd = sdkPath("/");
child.stderr = std.io.getStdErr();
child.stdout = std.io.getStdOut();
_ = try child.spawnAndWait();
}
fn sdkPath(comptime suffix: []const u8) []const u8 {
if (suffix[0] != '/') @compileError("suffix must be an absolute path");
return comptime blk: {
const root_dir = std.fs.path.dirname(@src().file) orelse ".";
break :blk root_dir ++ suffix;
};
}
const transcoder_sources = &[_][]const u8{
basisu_root ++ "/transcoder/basisu_transcoder.cpp",
};
const encoder_sources = &[_][]const u8{
basisu_root ++ "/encoder/basisu_backend.cpp",
basisu_root ++ "/encoder/basisu_basis_file.cpp",
basisu_root ++ "/encoder/basisu_bc7enc.cpp",
basisu_root ++ "/encoder/basisu_comp.cpp",
basisu_root ++ "/encoder/basisu_enc.cpp",
basisu_root ++ "/encoder/basisu_etc.cpp",
basisu_root ++ "/encoder/basisu_frontend.cpp",
basisu_root ++ "/encoder/basisu_gpu_texture.cpp",
basisu_root ++ "/encoder/basisu_kernels_sse.cpp",
basisu_root ++ "/encoder/basisu_opencl.cpp",
basisu_root ++ "/encoder/basisu_pvrtc1_4.cpp",
basisu_root ++ "/encoder/basisu_resample_filters.cpp",
basisu_root ++ "/encoder/basisu_resampler.cpp",
basisu_root ++ "/encoder/basisu_ssim.cpp",
basisu_root ++ "/encoder/basisu_uastc_enc.cpp",
basisu_root ++ "/encoder/jpgd.cpp",
basisu_root ++ "/encoder/pvpngreader.cpp",
};

View file

@ -1,225 +0,0 @@
const std = @import("std");
const b = @import("encoder/binding.zig");
const BasisTextureFormat = @import("main.zig").BasisTextureFormat;
const testing = std.testing;
/// Must be called before encoding anything
pub fn init_encoder() void {
b.basisu_encoder_init();
}
pub const Compressor = struct {
pub const Error = error{
InitializationFailed,
ValidationFailed,
EncodingUASTCFailed,
CannotReadSourceImages,
FrontendFault,
FrontendExtractionFailed,
BackendFault,
CannotCreateBasisFile,
CannotWriteOutput,
UASTCRDOPostProcessFailed,
CannotCreateKTX2File,
};
handle: *b.Compressor,
pub fn init(params: CompressorParams) error{Unknown}!Compressor {
return Compressor{
.handle = if (b.compressor_init(params.handle)) |v| v else return error.Unknown,
};
}
pub fn deinit(self: Compressor) void {
b.compressor_deinit(self.handle);
}
pub fn process(self: Compressor) Error!void {
return switch (b.compressor_process(self.handle)) {
0 => {},
1 => error.InitializationFailed,
2 => error.CannotReadSourceImages,
3 => error.ValidationFailed,
4 => error.EncodingUASTCFailed,
5 => error.FrontendFault,
6 => error.FrontendExtractionFailed,
7 => error.BackendFault,
8 => error.CannotCreateBasisFile,
9 => error.UASTCRDOPostProcessFailed,
10 => error.CannotCreateKTX2File,
else => unreachable,
};
}
/// output will be freed with `Compressor.deinit`
pub fn output(self: Compressor) []const u8 {
return b.compressor_get_output(self.handle)[0..b.compressor_get_output_size(self.handle)];
}
pub fn outputBitsPerTexel(self: Compressor) f64 {
return b.compressor_get_output_bits_per_texel(self.handle);
}
pub fn anyImageHasAlpha(self: Compressor) bool {
return b.compressor_get_any_source_image_has_alpha(self.handle);
}
};
pub const CompressorParams = struct {
handle: *b.CompressorParams,
pub fn init(threads_count: u32) CompressorParams {
const h = CompressorParams{ .handle = b.compressor_params_init() };
h.setStatusOutput(false);
b.compressor_params_set_thread_count(h.handle, threads_count);
return h;
}
pub fn deinit(self: CompressorParams) void {
b.compressor_params_deinit(self.handle);
}
pub fn clear(self: CompressorParams) void {
b.compressor_params_clear(self.handle);
}
pub fn setStatusOutput(self: CompressorParams, enable_output: bool) void {
b.compressor_params_set_status_output(self.handle, enable_output);
}
/// `level` ranges from [1, 255]
pub fn setQualityLevel(self: CompressorParams, level: u8) void {
b.compressor_params_set_quality_level(self.handle, level);
}
pub fn getPackUASTCFlags(self: CompressorParams) PackUASTCFlags {
return @as(PackUASTCFlags, @bitCast(b.compressor_params_get_pack_uastc_flags(self.handle)));
}
pub fn setPackUASTCFlags(self: CompressorParams, flags: PackUASTCFlags) void {
b.compressor_params_set_pack_uastc_flags(self.handle, @as(u32, @bitCast(flags)));
}
pub fn setBasisFormat(self: CompressorParams, format: BasisTextureFormat) void {
b.compressor_params_set_uastc(self.handle, switch (format) {
.etc1s => false,
.uastc4x4 => true,
});
}
pub fn setColorSpace(self: CompressorParams, color_space: ColorSpace) void {
b.compressor_params_set_perceptual(self.handle, switch (color_space) {
.linear => false,
.srgb => true,
});
}
pub fn setMipColorSpace(self: CompressorParams, color_space: ColorSpace) void {
b.compressor_params_set_mip_srgb(self.handle, switch (color_space) {
.linear => false,
.srgb => true,
});
}
/// Disable selector RDO, for faster compression but larger files.
/// Enabled by default
pub fn setSelectorRDO(self: CompressorParams, enable: bool) void {
b.compressor_params_set_no_selector_rdo(self.handle, !enable);
}
/// Enabled by default
pub fn setEndpointRDO(self: CompressorParams, enable: bool) void {
b.compressor_params_set_no_endpoint_rdo(self.handle, !enable);
}
pub fn setRDO_UASTC(self: CompressorParams, enable: bool) void {
b.compressor_params_set_rdo_uastc(self.handle, enable);
}
pub fn setRDO_UASTCQualityScalar(self: CompressorParams, quality: f32) void {
b.compressor_params_set_rdo_uastc_quality_scalar(self.handle, quality);
}
pub fn setGenerateMipMaps(self: CompressorParams, enable: bool) void {
b.compressor_params_set_generate_mipmaps(self.handle, enable);
}
pub fn setMipSmallestDimension(self: CompressorParams, smallest_dimension: i32) void {
b.compressor_params_set_mip_smallest_dimension(self.handle, smallest_dimension);
}
/// Resizes sources list and creates a new Image in case index is out of bounds
pub fn getImageSource(self: CompressorParams, index: u32) Image {
return .{ .handle = b.compressor_params_get_or_create_source_image(self.handle, index) };
}
pub fn resizeImageSource(self: CompressorParams, new_size: u32) void {
b.compressor_params_resize_source_image_list(self.handle, new_size);
}
pub fn clearImageSource(self: CompressorParams) void {
b.compressor_params_clear_source_image_list(self.handle);
}
};
pub const Image = struct {
handle: *b.Image,
pub fn fill(self: Image, data: []const u8, w: u32, h: u32, channels: u3) void {
b.compressor_image_fill(self.handle, data.ptr, w, h, channels);
}
pub fn resize(self: Image, w: u32, h: u32, p: ?u32) void {
b.compressor_image_resize(self.handle, w, h, p orelse std.math.maxInt(u32));
}
pub fn width(self: Image) u32 {
return b.compressor_image_get_width(self.handle);
}
pub fn height(self: Image) u32 {
return b.compressor_image_get_height(self.handle);
}
pub fn pitch(self: Image) u32 {
return b.compressor_image_get_pitch(self.handle);
}
pub fn totalPixels(self: Image) u32 {
return b.compressor_image_get_total_pixels(self.handle);
}
pub fn blockWidth(self: Image, w: u32) u32 {
return (self.width() + (w - 1)) / w;
}
pub fn blockHeight(self: Image, h: u32) u32 {
return (self.height() + (h - 1)) / h;
}
pub fn totalBlocks(self: Image, w: u32, h: u32) u32 {
return self.blockWidth(w) * self.blockHeight(h);
}
};
pub const PackUASTCFlags = packed struct(u32) {
fastest: bool = false,
faster: bool = false,
default: bool = false,
slower: bool = false,
verySlow: bool = false,
favor_uastc_error: bool = false,
favor_bc7_error: bool = false,
_padding: u1 = 0,
etc1_faster_hints: bool = false,
etc1_fastest_hints: bool = false,
etc1_disable_flip_and_individual: bool = false,
favor_simpler_modes: bool = false,
_padding0: u20 = 0,
};
pub const ColorSpace = enum {
linear,
srgb,
};

View file

@ -1,42 +0,0 @@
pub const Compressor = opaque {};
pub const CompressorParams = opaque {};
pub const Image = opaque {};
pub extern fn basisu_encoder_init() void;
pub extern fn compressor_params_init() *CompressorParams;
pub extern fn compressor_params_deinit(*CompressorParams) void;
pub extern fn compressor_params_clear(*CompressorParams) void;
pub extern fn compressor_params_set_status_output(*CompressorParams, bool) void;
pub extern fn compressor_params_set_thread_count(*CompressorParams, u32) void;
pub extern fn compressor_params_set_quality_level(*CompressorParams, c_int) void;
pub extern fn compressor_params_get_pack_uastc_flags(*CompressorParams) u32;
pub extern fn compressor_params_set_pack_uastc_flags(*CompressorParams, u32) void;
pub extern fn compressor_params_set_uastc(*CompressorParams, bool) void;
pub extern fn compressor_params_set_perceptual(*CompressorParams, bool) void;
pub extern fn compressor_params_set_mip_srgb(*CompressorParams, bool) void;
pub extern fn compressor_params_set_no_selector_rdo(*CompressorParams, bool) void;
pub extern fn compressor_params_set_no_endpoint_rdo(*CompressorParams, bool) void;
pub extern fn compressor_params_set_rdo_uastc(*CompressorParams, bool) void;
pub extern fn compressor_params_set_rdo_uastc_quality_scalar(*CompressorParams, f32) void;
pub extern fn compressor_params_set_generate_mipmaps(*CompressorParams, bool) void;
pub extern fn compressor_params_set_mip_smallest_dimension(*CompressorParams, c_int) void;
pub extern fn compressor_params_get_or_create_source_image(*CompressorParams, u32) *Image;
pub extern fn compressor_params_resize_source_image_list(*CompressorParams, usize) void;
pub extern fn compressor_params_clear_source_image_list(*CompressorParams) void;
pub extern fn compressor_image_fill(*Image, [*]const u8, u32, u32, u32) void;
pub extern fn compressor_image_resize(*Image, u32, u32, u32) void;
pub extern fn compressor_image_get_width(*Image) u32;
pub extern fn compressor_image_get_height(*Image) u32;
pub extern fn compressor_image_get_pitch(*Image) u32;
pub extern fn compressor_image_get_total_pixels(*Image) u32;
pub extern fn compressor_init(*CompressorParams) ?*Compressor;
pub extern fn compressor_deinit(*Compressor) void;
pub extern fn compressor_process(*Compressor) u32;
pub extern fn compressor_get_output(*Compressor) [*]const u8;
pub extern fn compressor_get_output_size(*Compressor) u32;
pub extern fn compressor_get_output_bits_per_texel(*Compressor) f64;
pub extern fn compressor_get_any_source_image_has_alpha(*Compressor) bool;

View file

@ -1,176 +0,0 @@
#include <basisu_comp.h>
#include <basisu_enc.h>
#include <cstdbool>
#include <cstdint>
extern "C" {
void basisu_encoder_init() { basisu::basisu_encoder_init(); }
basisu::basis_compressor_params *compressor_params_init() {
return new basisu::basis_compressor_params();
};
void compressor_params_deinit(basisu::basis_compressor_params *params) {
delete params;
}
void compressor_params_clear(basisu::basis_compressor_params *params) {
params->clear();
}
void compressor_params_set_status_output(
basisu::basis_compressor_params *params, bool status_output) {
params->m_status_output = status_output;
}
void compressor_params_set_thread_count(basisu::basis_compressor_params *params,
uint32_t thread_count) {
params->m_pJob_pool = new basisu::job_pool(thread_count);
}
void compressor_params_set_quality_level(
basisu::basis_compressor_params *params, uint8_t quality_level) {
params->m_quality_level = quality_level;
}
uint32_t compressor_params_get_pack_uastc_flags(
basisu::basis_compressor_params *params) {
return params->m_pack_uastc_flags;
}
void compressor_params_set_pack_uastc_flags(
basisu::basis_compressor_params *params, uint32_t pack_uastc_flags) {
params->m_pack_uastc_flags = pack_uastc_flags;
}
void compressor_params_set_uastc(basisu::basis_compressor_params *params,
bool is_uastc) {
params->m_uastc = is_uastc;
}
void compressor_params_set_perceptual(basisu::basis_compressor_params *params,
bool perceptual) {
params->m_perceptual = perceptual;
}
void compressor_params_set_mip_srgb(basisu::basis_compressor_params *params,
bool mip_srgb) {
params->m_mip_srgb = mip_srgb;
}
void compressor_params_set_no_selector_rdo(
basisu::basis_compressor_params *params, bool no_selector_rdo) {
params->m_no_selector_rdo = no_selector_rdo;
}
void compressor_params_set_no_endpoint_rdo(
basisu::basis_compressor_params *params, bool no_endpoint_rdo) {
params->m_no_endpoint_rdo = no_endpoint_rdo;
}
void compressor_params_set_rdo_uastc(basisu::basis_compressor_params *params,
bool rdo_uastc) {
params->m_rdo_uastc = rdo_uastc;
}
void compressor_params_set_generate_mipmaps(
basisu::basis_compressor_params *params, bool generate_mipmaps) {
params->m_mip_gen = generate_mipmaps;
}
void compressor_params_set_rdo_uastc_quality_scalar(
basisu::basis_compressor_params *params, float rdo_uastc_quality_scalar) {
params->m_rdo_uastc_quality_scalar = rdo_uastc_quality_scalar;
}
void compressor_params_set_mip_smallest_dimension(
basisu::basis_compressor_params *params, int mip_smallest_dimension) {
params->m_mip_smallest_dimension = mip_smallest_dimension;
}
basisu::image *compressor_params_get_or_create_source_image(
basisu::basis_compressor_params *params, uint32_t index) {
if (params->m_source_images.size() < index + 1) {
params->m_source_images.resize(index + 1);
}
return &params->m_source_images[index];
}
void compressor_params_resize_source_image_list(
basisu::basis_compressor_params *params, size_t size) {
params->m_source_images.resize(size);
}
void compressor_params_clear_source_image_list(
basisu::basis_compressor_params *params) {
params->clear();
}
///
void compressor_image_fill(basisu::image *image, const uint8_t *pData,
uint32_t width, uint32_t height, uint32_t comps) {
image->init(pData, width, height, comps);
}
void compressor_image_resize(basisu::image *image, uint32_t w, uint32_t h,
uint32_t p) {
image->resize(w, h, p);
}
uint32_t compressor_image_get_width(basisu::image *image) {
return image->get_width();
}
uint32_t compressor_image_get_height(basisu::image *image) {
return image->get_height();
}
uint32_t compressor_image_get_pitch(basisu::image *image) {
return image->get_pitch();
}
uint32_t compressor_image_get_total_pixels(basisu::image *image) {
return image->get_total_pixels();
}
///
basisu::basis_compressor *
compressor_init(basisu::basis_compressor_params *params) {
auto comp = new basisu::basis_compressor();
if (comp->init(*params))
return comp;
else
return nullptr;
}
void compressor_deinit(basisu::basis_compressor *compressor) {
delete compressor;
}
basisu::basis_compressor::error_code
compressor_process(basisu::basis_compressor *compressor) {
return compressor->process();
}
const uint8_t *compressor_get_output(basisu::basis_compressor *compressor) {
return compressor->get_output_basis_file().data();
}
uint32_t
compressor_get_output_size(const basisu::basis_compressor *compressor) {
return compressor->get_basis_file_size();
}
double compressor_get_output_bits_per_texel(
const basisu::basis_compressor *compressor) {
return compressor->get_basis_bits_per_texel();
}
bool compressor_get_any_source_image_has_alpha(
const basisu::basis_compressor *compressor) {
return compressor->get_any_source_image_has_alpha();
}
}

View file

@ -1,45 +0,0 @@
pub usingnamespace @import("encoder.zig");
pub usingnamespace @import("transcoder.zig");
pub const BasisTextureFormat = enum(u1) {
etc1s = 0,
uastc4x4 = 1,
};
// Test
const t = @import("transcoder.zig");
const e = @import("encoder.zig");
const testing = @import("std").testing;
test "reference decls" {
testing.refAllDeclsRecursive(t);
testing.refAllDeclsRecursive(e);
}
test "encode/transcode" {
// Encode
e.init_encoder();
const params = e.CompressorParams.init(1);
params.setGenerateMipMaps(true);
params.setBasisFormat(.uastc4x4);
params.setPackUASTCFlags(.{ .fastest = true });
defer params.deinit();
const image = params.getImageSource(0);
image.fill(@embedFile("../test/ziggy.png"), 379, 316, 4);
const comp = try e.Compressor.init(params);
try comp.process();
// Transcode
t.init_transcoder();
const trans = try t.Transcoder.init(comp.output());
defer trans.deinit();
var out_buf = try testing.allocator.alloc(u8, try trans.calcTranscodedSize(0, 0, .astc_4x4_rgba));
defer testing.allocator.free(out_buf);
try trans.transcode(out_buf, 0, 0, .astc_4x4_rgba, .{});
}

View file

@ -1,204 +0,0 @@
const std = @import("std");
const b = @import("transcoder/binding.zig");
const BasisTextureFormat = @import("main.zig").BasisTextureFormat;
const testing = std.testing;
/// Must be called before a `.basis` file can be transcoded.
/// NOTE: this function *isn't* thread safe.
pub fn init_transcoder() void {
b.basisu_transcoder_init();
}
/// Returns true if the specified format was enabled at compile time.
pub fn isFormatEnabled(self: BasisTextureFormat, transcoder_format: Transcoder.TextureFormat) bool {
return b.transcoder_is_format_supported(@intFromEnum(self), @intFromEnum(transcoder_format));
}
pub const Transcoder = struct {
handle: *b.BasisFile,
pub fn init(src: []const u8) error{Unknown}!Transcoder {
const h = b.transcoder_init(src.ptr, @as(u32, @intCast(src.len)));
return if (!b.transcoder_start_transcoding(h))
error.Unknown
else
.{ .handle = h };
}
pub fn deinit(self: Transcoder) void {
if (!b.transcoder_stop_transcoding(self.handle))
unreachable;
b.transcoder_deinit(self.handle);
}
/// Returns the total number of images in the basis file (always 1 or more).
/// Note that the number of mipmap levels for each image may differ, and that images may have different resolutions.
pub fn getImageCount(self: Transcoder) u32 {
return b.transcoder_get_images_count(self.handle);
}
/// Returns the number of mipmap levels in an image.
pub fn getImageLevelCount(self: Transcoder, image_index: u32) u32 {
return b.transcoder_get_levels_count(self.handle, image_index);
}
/// Returns basic information about an image.
/// Note that orig_width/orig_height may not be a multiple of 4.
pub fn getImageLevelDescriptor(self: Transcoder, image_index: u32, level_index: u32) error{OutOfBoundsLevelIndex}!ImageLevelDescriptor {
var desc: ImageLevelDescriptor = undefined;
return if (b.transcoder_get_image_level_desc(
self.handle,
image_index,
level_index,
&desc.original_width,
&desc.original_height,
&desc.block_count,
))
desc
else
error.OutOfBoundsLevelIndex;
}
/// Returns the bytes neeeded to store output.
pub fn calcTranscodedSize(self: Transcoder, image_index: u32, level_index: u32, format: TextureFormat) error{OutOfBoundsLevelIndex}!u32 {
var size: u32 = undefined;
return if (b.transcoder_get_image_transcoded_size(self.handle, image_index, level_index, @intFromEnum(format), &size))
size
else
error.OutOfBoundsLevelIndex;
}
pub const TranscodeParams = struct {
decode_flags: DecodeFlags = .{},
/// Output row pitch in blocks or pixels.
/// Should be at least the image level's total_blocks (num_blocks_x * num_blocks_y),
/// or the total number of output pixels if fmt==cTFRGBA32.
output_row_pitch: ?u32 = null,
/// Output rows in pixels
/// Ignored unless fmt is uncompressed (cRGBA32, etc.).
/// The total number of output rows in the output buffer. If 0,
/// the transcoder assumes the slice's orig_height (NOT num_blocks_y * 4).
output_rows: ?u32 = null,
};
/// Decodes a single mipmap level from the .basis file to any of the supported output texture formats.
/// Currently, to decode to PVRTC1 the basis texture's dimensions in pixels must be a power of 2,
/// due to PVRTC1 format requirements.
/// NOTE:
/// - `transcoder_init()` must have been called first to initialize
/// the transcoder lookup tables before calling this function.
/// - This method assumes the output texture buffer is readable.
/// In some cases to handle alpha, the transcoder will write temporary data
/// to the output texture in a first pass, which will be read in a second pass.
pub fn transcode(
self: Transcoder,
out_buf: []u8,
image_index: u32,
level_index: u32,
format: TextureFormat,
params: TranscodeParams,
) error{Unknown}!void {
if (!b.transcoder_transcode(
self.handle,
out_buf.ptr,
@as(u32, @intCast(out_buf.len)),
image_index,
level_index,
@intFromEnum(format),
@as(u32, @bitCast(params.decode_flags)),
params.output_row_pitch orelse 0,
params.output_rows orelse 0,
)) return error.Unknown;
}
pub const ImageLevelDescriptor = struct {
original_width: u32,
original_height: u32,
block_count: u32,
};
pub const DecodeFlags = packed struct(u32) {
_padding: u1 = 0,
pvrtc_decode_to_next_pow_2: bool = false,
transcode_alpha_data_to_opaque_formats: bool = false,
bc1_forbid_three_color_blocks: bool = false,
output_has_alpha_indices: bool = false,
high_quality: bool = false,
_padding0: u26 = 0,
};
pub const TextureFormat = enum(u5) {
etc1_rgb = 0,
etc2_rgba = 1,
bc1_rgb = 2,
bc3_rgba = 3,
bc4_r = 4,
bc5_rg = 5,
bc7_rgba = 6,
bc7_alt = 7,
pvrtc1_4_rgb = 8,
pvrtc1_4_rgba = 9,
astc_4x4_rgba = 10,
atc_rgb = 11,
atc_rgba = 12,
rgba32 = 13,
rgb565 = 14,
bgr565 = 15,
rgba4444 = 16,
fxt1_rgb = 17,
pvrtc2_4_rgb = 18,
pvrtc2_4_rgba = 19,
etc2_eac_r11 = 20,
etc2_eac_rg11 = 21,
pub fn isEnabled(
self: TextureFormat,
basis_texture_format: BasisTextureFormat,
) bool {
return isFormatEnabled(basis_texture_format, self);
}
pub fn bytesPerBlockOrPixel(self: TextureFormat) u5 {
return switch (self) {
.rgb565, .bgr565, .rgba4444 => return 2,
.rgba32 => return 4,
.etc1_rgb, .bc1_rgb, .bc4_r, .pvrtc1_4_rgb, .pvrtc1_4_rgba, .atc_rgb, .pvrtc2_4_rgb, .pvrtc2_4_rgba, .etc2_eac_r11 => 8,
.bc7_rgba, .bc7_alt, .etc2_rgba, .bc3_rgba, .bc5_rg, .astc_4x4_rgba, .atc_rgba, .fxt1_rgb, .etc2_eac_rg11 => return 16,
};
}
};
pub const BlockFormat = enum(u5) {
etc1 = 0,
etc2_rgba = 1,
bc1 = 2,
bc3 = 3,
bc4 = 4,
bc5 = 5,
pvrtc1_4_rgb = 6,
pvrtc1_4_rgba = 7,
bc7 = 8,
bc7_m5_color = 9,
bc7_m5_alpha = 10,
etc2_eac_a8 = 11,
astc_4x4 = 12,
atc_rgb = 13,
atc_rgba_interpolated_alpha = 14,
fxt1_rgb = 15,
pvrtc2_4_rgb = 16,
pvrtc2_4_rgba = 17,
etc2_eac_r11 = 18,
etc2_eac_rg11 = 19,
indices = 20,
rgb32 = 21,
rgba32 = 23,
a32 = 24,
rgb565 = 25,
bgr565 = 26,
rgba4444_color = 27,
rgba4444_alpha = 28,
rgba4444_color_opaque = 29,
rgba4444 = 30,
uastc_4x4 = 31,
};
};

View file

@ -1,38 +0,0 @@
pub const BasisFile = opaque {};
pub extern fn basisu_transcoder_init() void;
pub extern fn transcoder_is_format_supported(tex_type: u32, fmt: u32) bool;
pub extern fn transcoder_init([*]const u8, u32) *BasisFile;
pub extern fn transcoder_deinit(*BasisFile) void;
pub extern fn transcoder_get_images_count(*BasisFile) u32;
pub extern fn transcoder_get_levels_count(*BasisFile, image_index: u32) u32;
pub extern fn transcoder_get_image_level_desc(
*BasisFile,
image_index: u32,
level_index: u32,
orig_width: *u32,
orig_height: *u32,
total_block: *u32,
) bool;
pub extern fn transcoder_get_image_transcoded_size(
*BasisFile,
image_index: u32,
level_index: u32,
format: u32,
size: *u32,
) bool;
pub extern fn transcoder_start_transcoding(*BasisFile) bool;
pub extern fn transcoder_stop_transcoding(*BasisFile) bool;
pub extern fn transcoder_transcode(
*BasisFile,
out: [*]const u8,
out_size: u32,
image_index: u32,
level_index: u32,
format: u32,
decode_flags: u32,
output_row_pitch_in_blocks_or_pixels: u32,
output_rows_in_pixels: u32,
) bool;

View file

@ -1,153 +0,0 @@
#include <basisu_transcoder.h>
#include <cstdbool>
#include <cstdint>
extern "C" {
void basisu_transcoder_init();
bool transcoder_is_format_supported(uint32_t tex_type, uint32_t fmt);
void *transcoder_init(void *src, uint32_t src_size);
void transcoder_deinit(void *h);
uint32_t transcoder_get_images_count(void *h);
uint32_t transcoder_get_levels_count(void *h, uint32_t image_index);
bool transcoder_get_image_level_desc(void *h, uint32_t image_index,
uint32_t level_index, uint32_t &orig_width,
uint32_t &orig_height,
uint32_t &block_count);
bool transcoder_get_image_transcoded_size(void *h, uint32_t image_index,
uint32_t level_index, uint32_t format,
uint32_t &size);
bool transcoder_start_transcoding(void *h);
bool transcoder_stop_transcoding(void *h);
bool transcoder_transcode(void *h, void *out, uint32_t out_size,
uint32_t image_index, uint32_t level_index,
uint32_t format, uint32_t decode_flags,
uint32_t output_row_pitch_in_blocks_or_pixels,
uint32_t output_rows_in_pixels);
}
void basisu_transcoder_init() { basist::basisu_transcoder_init(); }
#define MAGIC 0xDEADBEE1
struct basis_file {
int m_magic;
basist::basisu_transcoder m_transcoder;
void *m_pFile;
uint32_t m_file_size;
basis_file() : m_transcoder() {}
};
// transcoder_texture_format, basis_tex_format
bool transcoder_is_format_supported(uint32_t tex_type, uint32_t fmt) {
return basist::basis_is_format_supported(
(basist::transcoder_texture_format)tex_type,
(basist::basis_tex_format)fmt);
}
// !null - success
// null - validation failure
void *transcoder_init(void *src, uint32_t src_size) {
auto f = new basis_file;
f->m_pFile = src;
f->m_file_size = src_size;
if (!f->m_transcoder.validate_header(f->m_pFile, f->m_file_size)) {
delete f;
return nullptr;
}
f->m_magic = MAGIC;
return f;
}
void transcoder_deinit(void *h) {
auto f = static_cast<basis_file *>(h);
delete f;
}
uint32_t transcoder_get_images_count(void *h) {
auto f = static_cast<basis_file *>(h);
return f->m_transcoder.get_total_images(f->m_pFile, f->m_file_size);
}
uint32_t transcoder_get_levels_count(void *h, uint32_t image_index) {
auto f = static_cast<basis_file *>(h);
return f->m_transcoder.get_total_image_levels(f->m_pFile, f->m_file_size,
image_index);
}
// true - success
// false - OutOfBoundsLevelIndex
bool transcoder_get_image_level_desc(void *h, uint32_t image_index,
uint32_t level_index, uint32_t &orig_width,
uint32_t &orig_height,
uint32_t &block_count) {
auto f = static_cast<basis_file *>(h);
return f->m_transcoder.get_image_level_desc(
f->m_pFile, f->m_file_size, image_index, level_index, orig_width,
orig_height, block_count);
}
// true - success
// false - OutOfBoundsLevelIndex
bool transcoder_get_image_transcoded_size(void *h, uint32_t image_index,
uint32_t level_index, uint32_t format,
uint32_t &size) {
auto f = static_cast<basis_file *>(h);
uint32_t orig_width, orig_height, total_blocks;
if (!f->m_transcoder.get_image_level_desc(
f->m_pFile, f->m_file_size, image_index, level_index, orig_width,
orig_height, total_blocks))
return false;
uint8_t bytes_per_block_or_pixel = basis_get_bytes_per_block_or_pixel(
(basist::transcoder_texture_format)format);
if (basis_transcoder_format_is_uncompressed(
(basist::transcoder_texture_format)format)) {
size = orig_width * orig_height * bytes_per_block_or_pixel;
} else {
size = total_blocks * bytes_per_block_or_pixel;
}
return true;
}
// true - success
// false - unknown
bool transcoder_start_transcoding(void *h) {
auto f = static_cast<basis_file *>(h);
return f->m_transcoder.start_transcoding(f->m_pFile, f->m_file_size);
}
// true - success
// false - unknown
bool transcoder_stop_transcoding(void *h) {
auto f = static_cast<basis_file *>(h);
return f->m_transcoder.stop_transcoding();
}
// true - success
// false - unknown
bool transcoder_transcode(void *h, void *out, uint32_t out_size,
uint32_t image_index, uint32_t level_index,
uint32_t format, uint32_t decode_flags,
uint32_t output_row_pitch_in_blocks_or_pixels,
uint32_t output_rows_in_pixels) {
auto f = static_cast<basis_file *>(h);
uint32_t bytes_per_block = basis_get_bytes_per_block_or_pixel(
(basist::transcoder_texture_format)format);
return f->m_transcoder.transcode_image_level(
f->m_pFile, f->m_file_size, image_index, level_index, out,
out_size / bytes_per_block, (basist::transcoder_texture_format)format,
decode_flags, output_row_pitch_in_blocks_or_pixels, nullptr,
output_rows_in_pixels);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

@ -1 +0,0 @@
Subproject commit d55a3f9f06adf9cc8c31f58e894d947cc6026da5