Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ jobs:
arch: x64
spectre: true

- name: Install Dependencies [macOS]
if: matrix.os == 'macos-latest'
run: brew install ninja

- name: Install Dependencies [Linux]
if: matrix.os == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y ninja-build

- name: Configure CMake
run: cmake -G "Ninja" -B build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DSOURCEPP_BUILD_TESTS=ON

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ found on PyPI in the [sourcepp](https://pypi.org/project/sourcepp) package.
- `vpkpp`'s ORE parser is based on [reverse-engineering work](https://github.com/erysdren/narbacular-drop-tools) by [@erysdren](https://github.com/erysdren).
- `vpkpp`'s VPP parser was contributed by [@erysdren](https://github.com/erysdren).
- `vpkpp`'s WAD3 parser/writer was contributed by [@ozxybox](https://github.com/ozxybox).
- `vtfpp`'s NICE/Lanczos-3 resize filter support was contributed by [@koerismo](https://github.com/koerismo).
- `vtfpp`'s SHT parser/writer was contributed by [@Trico Everfire](https://github.com/Trico-Everfire).
- `vtfpp`'s VTF write support is loosely based on work by [@Trico Everfire](https://github.com/Trico-Everfire).
- `vtfpp`'s HDRI to cubemap conversion code is modified from the [HdriToCubemap](https://github.com/ivarout/HdriToCubemap) library by [@ivarout](https://github.com/ivarout).
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ found on PyPI in the [sourcepp](https://pypi.org/project/sourcepp) package.
- `vpkpp`'s ORE parser is based on [reverse-engineering work](https://github.com/erysdren/narbacular-drop-tools) by [@erysdren](https://github.com/erysdren).
- `vpkpp`'s VPP parser was contributed by [@erysdren](https://github.com/erysdren).
- `vpkpp`'s WAD3 parser/writer was contributed by [@ozxybox](https://github.com/ozxybox).
- `vtfpp`'s NICE/Lanczos-3 resize filter support was contributed by [@koerismo](https://github.com/koerismo).
- `vtfpp`'s SHT parser/writer was contributed by [@Trico Everfire](https://github.com/Trico-Everfire).
- `vtfpp`'s VTF write support is loosely based on work by [@Trico Everfire](https://github.com/Trico-Everfire).
- `vtfpp`'s HDRI to cubemap conversion code is modified from the [HdriToCubemap](https://github.com/ivarout/HdriToCubemap) library by [@ivarout](https://github.com/ivarout).
Expand Down
2 changes: 2 additions & 0 deletions include/vtfpp/ImageConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ enum class ResizeFilter {

// User-defined
KAISER = 100,
/// Valve NICE filtering, equivalent to Lanczos-3
NICE = 101,
};

enum class ResizeMethod {
Expand Down
1 change: 1 addition & 0 deletions lang/c/include/vtfppc/ImageConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef enum {
VTFPP_IMAGE_CONVERSION_RESIZE_FILTER_MITCHELL,
VTFPP_IMAGE_CONVERSION_RESIZE_FILTER_POINT_SAMPLE,
VTFPP_IMAGE_CONVERSION_RESIZE_FILTER_KAISER = 100,
VTFPP_IMAGE_CONVERSION_RESIZE_FILTER_NICE,
} vtfpp_image_conversion_resize_filter_e;

typedef enum {
Expand Down
1 change: 1 addition & 0 deletions lang/python/src/vtfpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void register_python(py::module_& m) {
.value("MITCHELL", ResizeFilter::MITCHELL)
.value("POINT_SAMPLE", ResizeFilter::POINT_SAMPLE)
.value("KAISER", ResizeFilter::KAISER)
.value("NICE", ResizeFilter::NICE)
.export_values();

py::enum_<ResizeMethod>(ImageConversion, "ResizeMethod")
Expand Down
18 changes: 18 additions & 0 deletions src/vtfpp/ImageConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,24 @@ std::vector<std::byte> ImageConversion::resizeImageData(std::span<const std::byt
stbir_set_filter_callbacks(&resize, KAISER_FILTER, KAISER_SUPPORT, KAISER_FILTER, KAISER_SUPPORT);
break;
}
case ResizeFilter::NICE: {
static constexpr auto SINC = [](float x) -> float {
if (x == 0.f) return 1.f;
const float a = x * math::pi_f32;
return sinf(a) / a;
};
static constexpr auto NICE_FILTER = [](float x, float, void*) -> float {
if (x >= 3.f || x <= -3.f) return 0.f;
return SINC(x) * SINC(x / 3.f);
};
// Normally you would max(1, invScale), but stb is weird and immediately un-scales the result when downsampling.
// See stb_image_resize2.h L2977 (stbir__get_filter_pixel_width)
static constexpr auto NICE_SUPPORT = [](float invScale, void*) -> float {
return invScale * 3.f;
};
stbir_set_filter_callbacks(&resize, NICE_FILTER, NICE_SUPPORT, NICE_FILTER, NICE_SUPPORT);
break;
}
}
stbir_resize_extended(&resize);
};
Expand Down