scaling functions now warn instead of crashing with negative scales
This commit is contained in:
parent
de3d099d51
commit
95f6babd5e
@ -6,12 +6,15 @@
|
|||||||
#include "StarImage.hpp"
|
#include "StarImage.hpp"
|
||||||
#include "StarStringView.hpp"
|
#include "StarStringView.hpp"
|
||||||
#include "StarEncode.hpp"
|
#include "StarEncode.hpp"
|
||||||
//#include "StarTime.hpp"
|
#include "StarLogging.hpp"
|
||||||
//#include "StarLogging.hpp"
|
|
||||||
|
|
||||||
namespace Star {
|
namespace Star {
|
||||||
|
|
||||||
Image scaleNearest(Image const& srcImage, Vec2F const& scale) {
|
Image scaleNearest(Image const& srcImage, Vec2F scale) {
|
||||||
|
if (scale[0] < 0.0f || scale[1] < 0.0f) {
|
||||||
|
Logger::warn("Negative scale in scaleNearest({})", scale);
|
||||||
|
scale = scale.piecewiseMax(Vec2F::filled(0.f));
|
||||||
|
}
|
||||||
Vec2U srcSize = srcImage.size();
|
Vec2U srcSize = srcImage.size();
|
||||||
Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
|
Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
|
||||||
destSize[0] = max(destSize[0], 1u);
|
destSize[0] = max(destSize[0], 1u);
|
||||||
@ -26,7 +29,11 @@ Image scaleNearest(Image const& srcImage, Vec2F const& scale) {
|
|||||||
return destImage;
|
return destImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image scaleBilinear(Image const& srcImage, Vec2F const& scale) {
|
Image scaleBilinear(Image const& srcImage, Vec2F scale) {
|
||||||
|
if (scale[0] < 0.0f || scale[1] < 0.0f) {
|
||||||
|
Logger::warn("Negative scale in scaleBilinear({})", scale);
|
||||||
|
scale = scale.piecewiseMax(Vec2F::filled(0.f));
|
||||||
|
}
|
||||||
Vec2U srcSize = srcImage.size();
|
Vec2U srcSize = srcImage.size();
|
||||||
Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
|
Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
|
||||||
destSize[0] = max(destSize[0], 1u);
|
destSize[0] = max(destSize[0], 1u);
|
||||||
@ -50,7 +57,11 @@ Image scaleBilinear(Image const& srcImage, Vec2F const& scale) {
|
|||||||
return destImage;
|
return destImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image scaleBicubic(Image const& srcImage, Vec2F const& scale) {
|
Image scaleBicubic(Image const& srcImage, Vec2F scale) {
|
||||||
|
if (scale[0] < 0.0f || scale[1] < 0.0f) {
|
||||||
|
Logger::warn("Negative scale in scaleBicubic({})", scale);
|
||||||
|
scale = scale.piecewiseMax(Vec2F::filled(0.f));
|
||||||
|
}
|
||||||
Vec2U srcSize = srcImage.size();
|
Vec2U srcSize = srcImage.size();
|
||||||
Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
|
Vec2U destSize = Vec2U::round(vmult(Vec2F(srcSize), scale));
|
||||||
destSize[0] = max(destSize[0], 1u);
|
destSize[0] = max(destSize[0], 1u);
|
||||||
|
@ -10,9 +10,9 @@ STAR_CLASS(Image);
|
|||||||
|
|
||||||
STAR_EXCEPTION(ImageOperationException, StarException);
|
STAR_EXCEPTION(ImageOperationException, StarException);
|
||||||
|
|
||||||
Image scaleNearest(Image const& srcImage, Vec2F const& scale);
|
Image scaleNearest(Image const& srcImage, Vec2F scale);
|
||||||
Image scaleBilinear(Image const& srcImage, Vec2F const& scale);
|
Image scaleBilinear(Image const& srcImage, Vec2F scale);
|
||||||
Image scaleBicubic(Image const& srcImage, Vec2F const& scale);
|
Image scaleBicubic(Image const& srcImage, Vec2F scale);
|
||||||
|
|
||||||
StringList colorDirectivesFromConfig(JsonArray const& directives);
|
StringList colorDirectivesFromConfig(JsonArray const& directives);
|
||||||
String paletteSwapDirectivesFromConfig(Json const& swaps);
|
String paletteSwapDirectivesFromConfig(Json const& swaps);
|
||||||
|
Loading…
Reference in New Issue
Block a user