Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarImageProcessing.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-12-28 13:07:51 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-12-28 13:07:51 +1100
commit6b49f382e3a9429e97bc47a9b3c18c3ca8feb65c (patch)
tree4f3afffbc25f60e0930bc651ef98f21f4a6ac719 /source/core/StarImageProcessing.cpp
parent9da08e898d9c666f655c7f901d0c67b17a746608 (diff)
move image scaling functions to their own unit, as -O2
Diffstat (limited to 'source/core/StarImageProcessing.cpp')
-rw-r--r--source/core/StarImageProcessing.cpp99
1 files changed, 1 insertions, 98 deletions
diff --git a/source/core/StarImageProcessing.cpp b/source/core/StarImageProcessing.cpp
index 96edc0b..1cfd847 100644
--- a/source/core/StarImageProcessing.cpp
+++ b/source/core/StarImageProcessing.cpp
@@ -1,4 +1,5 @@
#include "StarImageProcessing.hpp"
+#include "StarImageScaling.hpp"
#include "StarMatrix3.hpp"
#include "StarInterpolation.hpp"
#include "StarLexicalCast.hpp"
@@ -10,104 +11,6 @@
namespace Star {
-Image scaleNearest(Image const& srcImage, Vec2F const& scale) {
- Vec2U srcSize = srcImage.size();
- Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
- destSize[0] = max(destSize[0], 1u);
- destSize[1] = max(destSize[1], 1u);
-
- Image destImage(destSize, srcImage.pixelFormat());
-
- for (unsigned y = 0; y < destSize[1]; ++y) {
- for (unsigned x = 0; x < destSize[0]; ++x)
- destImage.set({x, y}, srcImage.clamp(Vec2I::round(vdiv(Vec2F(x, y), scale))));
- }
- return destImage;
-}
-
-#pragma GCC push_options
-#pragma GCC optimize("-fno-unsafe-math-optimizations", "-ffloat-store")
-Image scaleBilinear(Image const& srcImage, Vec2F const& scale) {
- Vec2U srcSize = srcImage.size();
- Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
- destSize[0] = max(destSize[0], 1u);
- destSize[1] = max(destSize[1], 1u);
-
- Image destImage(destSize, srcImage.pixelFormat());
-
- auto lerpVec = [](float const& offset, Vec4F f0, Vec4F f1) {
- return f0 * (1 - offset) + f1 * (offset);
- };
-
- for (unsigned y = 0; y < destSize[1]; ++y) {
- for (unsigned x = 0; x < destSize[0]; ++x) {
- auto pos = vdiv(Vec2F(x, y), scale);
- auto ipart = Vec2I::floor(pos);
- auto fpart = pos - Vec2F(ipart);
-
- auto result = lerpVec(fpart[1], lerpVec(fpart[0], Vec4F(srcImage.clamp(ipart[0], ipart[1])), Vec4F(srcImage.clamp(ipart[0] + 1, ipart[1]))), lerpVec(fpart[0],
- Vec4F(srcImage.clamp(ipart[0], ipart[1] + 1)), Vec4F(srcImage.clamp(ipart[0] + 1, ipart[1] + 1))));
-
- destImage.set({x, y}, Vec4B(result));
- }
- }
-
- return destImage;
-}
-
-Image scaleBicubic(Image const& srcImage, Vec2F const& scale) {
- Vec2U srcSize = srcImage.size();
- Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
- destSize[0] = max(destSize[0], 1u);
- destSize[1] = max(destSize[1], 1u);
-
- Image destImage(destSize, srcImage.pixelFormat());
-
- for (unsigned y = 0; y < destSize[1]; ++y) {
- for (unsigned x = 0; x < destSize[0]; ++x) {
- auto pos = vdiv(Vec2F(x, y), scale);
- auto ipart = Vec2I::floor(pos);
- auto fpart = pos - Vec2F(ipart);
-
- Vec4F a = cubic4(fpart[0],
- Vec4F(srcImage.clamp(ipart[0], ipart[1])),
- Vec4F(srcImage.clamp(ipart[0] + 1, ipart[1])),
- Vec4F(srcImage.clamp(ipart[0] + 2, ipart[1])),
- Vec4F(srcImage.clamp(ipart[0] + 3, ipart[1])));
-
- Vec4F b = cubic4(fpart[0],
- Vec4F(srcImage.clamp(ipart[0], ipart[1] + 1)),
- Vec4F(srcImage.clamp(ipart[0] + 1, ipart[1] + 1)),
- Vec4F(srcImage.clamp(ipart[0] + 2, ipart[1] + 1)),
- Vec4F(srcImage.clamp(ipart[0] + 3, ipart[1] + 1)));
-
- Vec4F c = cubic4(fpart[0],
- Vec4F(srcImage.clamp(ipart[0], ipart[1] + 2)),
- Vec4F(srcImage.clamp(ipart[0] + 1, ipart[1] + 2)),
- Vec4F(srcImage.clamp(ipart[0] + 2, ipart[1] + 2)),
- Vec4F(srcImage.clamp(ipart[0] + 3, ipart[1] + 2)));
-
- Vec4F d = cubic4(fpart[0],
- Vec4F(srcImage.clamp(ipart[0], ipart[1] + 3)),
- Vec4F(srcImage.clamp(ipart[0] + 1, ipart[1] + 3)),
- Vec4F(srcImage.clamp(ipart[0] + 2, ipart[1] + 3)),
- Vec4F(srcImage.clamp(ipart[0] + 3, ipart[1] + 3)));
-
- auto result = cubic4(fpart[1], a, b, c, d);
-
- destImage.set({x, y}, Vec4B(
- clamp(result[0], 0.0f, 255.0f),
- clamp(result[1], 0.0f, 255.0f),
- clamp(result[2], 0.0f, 255.0f),
- clamp(result[3], 0.0f, 255.0f)
- ));
- }
- }
-
- return destImage;
-}
-#pragma GCC pop_options
-
StringList colorDirectivesFromConfig(JsonArray const& directives) {
List<String> result;