Skip to content

Commit 23bced5

Browse files
committed
feat: Reorder, rename to NICE, fix casing
1 parent 4662344 commit 23bced5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/vtfpp/ImageConversion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ enum class ResizeFilter {
375375

376376
// User-defined
377377
KAISER = 100,
378-
LANCZOS3 = 101,
378+
/// Valve NICE filtering, equivalent to Lanczos-3
379+
NICE = 101,
379380
};
380381

381382
enum class ResizeMethod {

src/vtfpp/ImageConversion.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,22 +1942,22 @@ std::vector<std::byte> ImageConversion::resizeImageData(std::span<const std::byt
19421942
stbir_set_filter_callbacks(&resize, KAISER_FILTER, KAISER_SUPPORT, KAISER_FILTER, KAISER_SUPPORT);
19431943
break;
19441944
}
1945-
case ResizeFilter::LANCZOS3: {
1945+
case ResizeFilter::NICE: {
19461946
static constexpr auto SINC = [](const float x) -> float {
19471947
if (x == 0.f) return 1.f;
19481948
const float a = x * math::pi_f32;
19491949
return sinf(a) / a;
19501950
};
1951-
// Normally you would max(1, inv_scale), but stb is weird and immediately un-scales the result when downsampling.
1952-
// See stb_image_resize2.h L2977
1953-
static constexpr auto LANCZOS3_SUPPORT = [](float inv_scale, void*) -> float {
1954-
return inv_scale * 3.f;
1955-
};
1956-
static constexpr auto LANCZOS3_FILTER = [](float x, float inv_scale, void*) -> float {
1951+
static constexpr auto NICE_FILTER = [](float x, float invScale, void*) -> float {
19571952
if (x >= 3.f || x <= -3.f) return 0.f;
19581953
return SINC(x) * SINC(x / 3.f);
19591954
};
1960-
stbir_set_filter_callbacks(&resize, LANCZOS3_FILTER, LANCZOS3_SUPPORT, LANCZOS3_FILTER, LANCZOS3_SUPPORT);
1955+
// Normally you would max(1, invScale), but stb is weird and immediately un-scales the result when downsampling.
1956+
// See stb_image_resize2.h L2977
1957+
static constexpr auto NICE_SUPPORT = [](float invScale, void*) -> float {
1958+
return invScale * 3.f;
1959+
};
1960+
stbir_set_filter_callbacks(&resize, NICE_FILTER, NICE_SUPPORT, NICE_FILTER, NICE_SUPPORT);
19611961
break;
19621962
}
19631963
}

0 commit comments

Comments
 (0)