2024-02-25 14:46:47 +00:00
|
|
|
#pragma once
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
#include "StarList.hpp"
|
|
|
|
#include "StarRect.hpp"
|
|
|
|
#include "StarJson.hpp"
|
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
STAR_CLASS(Image);
|
|
|
|
|
|
|
|
STAR_EXCEPTION(ImageOperationException, StarException);
|
|
|
|
|
|
|
|
Image scaleNearest(Image const& srcImage, Vec2F const& scale);
|
|
|
|
Image scaleBilinear(Image const& srcImage, Vec2F const& scale);
|
|
|
|
Image scaleBicubic(Image const& srcImage, Vec2F const& scale);
|
|
|
|
|
|
|
|
StringList colorDirectivesFromConfig(JsonArray const& directives);
|
|
|
|
String paletteSwapDirectivesFromConfig(Json const& swaps);
|
|
|
|
|
2023-06-26 17:38:57 +00:00
|
|
|
struct NullImageOperation {
|
2024-04-24 23:39:23 +00:00
|
|
|
bool unloaded = false;
|
2023-06-26 17:38:57 +00:00
|
|
|
};
|
|
|
|
|
2023-06-25 04:00:20 +00:00
|
|
|
struct ErrorImageOperation {
|
2024-04-24 23:39:23 +00:00
|
|
|
Variant<std::string, std::exception_ptr> cause;
|
2023-06-25 04:00:20 +00:00
|
|
|
};
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
struct HueShiftImageOperation {
|
|
|
|
// Specify hue shift angle as -360 to 360 rather than -1 to 1
|
|
|
|
static HueShiftImageOperation hueShiftDegrees(float degrees);
|
|
|
|
|
|
|
|
// value here is normalized to 1.0
|
|
|
|
float hueShiftAmount;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SaturationShiftImageOperation {
|
|
|
|
// Specify saturation shift as amount normalized to 100
|
|
|
|
static SaturationShiftImageOperation saturationShift100(float amount);
|
|
|
|
|
|
|
|
// value here is normalized to 1.0
|
|
|
|
float saturationShiftAmount;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BrightnessMultiplyImageOperation {
|
|
|
|
// Specify brightness multiply as amount where 0 means "no change" and 100
|
|
|
|
// means "x2" and -100 means "x0"
|
|
|
|
static BrightnessMultiplyImageOperation brightnessMultiply100(float amount);
|
|
|
|
|
|
|
|
float brightnessMultiply;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fades R G and B channels to the given color by the given amount, ignores A
|
|
|
|
struct FadeToColorImageOperation {
|
|
|
|
FadeToColorImageOperation(Vec3B color, float amount);
|
|
|
|
|
|
|
|
Vec3B color;
|
|
|
|
float amount;
|
|
|
|
|
|
|
|
Array<uint8_t, 256> rTable;
|
|
|
|
Array<uint8_t, 256> gTable;
|
|
|
|
Array<uint8_t, 256> bTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Applies two FadeToColor operations in alternating rows to produce a scanline effect
|
|
|
|
struct ScanLinesImageOperation {
|
|
|
|
FadeToColorImageOperation fade1;
|
|
|
|
FadeToColorImageOperation fade2;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Sets RGB values to the given color, and ignores the alpha channel
|
|
|
|
struct SetColorImageOperation {
|
|
|
|
Vec3B color;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef HashMap<Vec4B, Vec4B> ColorReplaceMap;
|
|
|
|
|
|
|
|
struct ColorReplaceImageOperation {
|
|
|
|
ColorReplaceMap colorReplaceMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AlphaMaskImageOperation {
|
|
|
|
enum MaskMode {
|
|
|
|
Additive,
|
|
|
|
Subtractive
|
|
|
|
};
|
|
|
|
|
|
|
|
MaskMode mode;
|
|
|
|
StringList maskImages;
|
|
|
|
Vec2I offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BlendImageOperation {
|
|
|
|
enum BlendMode {
|
|
|
|
Multiply,
|
|
|
|
Screen
|
|
|
|
};
|
|
|
|
|
|
|
|
BlendMode mode;
|
|
|
|
StringList blendImages;
|
|
|
|
Vec2I offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MultiplyImageOperation {
|
|
|
|
Vec4B color;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BorderImageOperation {
|
|
|
|
unsigned pixels;
|
|
|
|
Vec4B startColor;
|
|
|
|
Vec4B endColor;
|
|
|
|
bool outlineOnly;
|
2023-06-21 08:59:15 +00:00
|
|
|
bool includeTransparent;
|
2023-06-20 04:33:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ScaleImageOperation {
|
|
|
|
enum Mode {
|
|
|
|
Nearest,
|
|
|
|
Bilinear,
|
|
|
|
Bicubic
|
|
|
|
};
|
|
|
|
|
|
|
|
Mode mode;
|
|
|
|
Vec2F scale;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CropImageOperation {
|
|
|
|
RectI subset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FlipImageOperation {
|
|
|
|
enum Mode {
|
|
|
|
FlipX,
|
|
|
|
FlipY,
|
|
|
|
FlipXY
|
|
|
|
};
|
|
|
|
Mode mode;
|
|
|
|
};
|
|
|
|
|
2023-06-26 17:38:57 +00:00
|
|
|
typedef Variant<NullImageOperation, ErrorImageOperation, HueShiftImageOperation, SaturationShiftImageOperation, BrightnessMultiplyImageOperation, FadeToColorImageOperation,
|
2023-06-20 04:33:09 +00:00
|
|
|
ScanLinesImageOperation, SetColorImageOperation, ColorReplaceImageOperation, AlphaMaskImageOperation, BlendImageOperation,
|
|
|
|
MultiplyImageOperation, BorderImageOperation, ScaleImageOperation, CropImageOperation, FlipImageOperation> ImageOperation;
|
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
ImageOperation imageOperationFromString(StringView string);
|
2023-06-20 04:33:09 +00:00
|
|
|
String imageOperationToString(ImageOperation const& operation);
|
|
|
|
|
2023-06-25 15:42:18 +00:00
|
|
|
void parseImageOperations(StringView params, function<void(ImageOperation&&)> outputter);
|
2023-06-24 03:06:13 +00:00
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
// Each operation is assumed to be separated by '?', with parameters
|
|
|
|
// separated by ';' or '='
|
2023-06-25 15:42:18 +00:00
|
|
|
List<ImageOperation> parseImageOperations(StringView params);
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
// Each operation separated by '?', returns string with leading '?'
|
|
|
|
String printImageOperations(List<ImageOperation> const& operations);
|
|
|
|
|
2023-06-24 09:41:52 +00:00
|
|
|
void addImageOperationReferences(ImageOperation const& operation, StringList& out);
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
StringList imageOperationReferences(List<ImageOperation> const& operations);
|
|
|
|
|
|
|
|
typedef function<Image const*(String const& refName)> ImageReferenceCallback;
|
|
|
|
|
2023-06-24 03:06:13 +00:00
|
|
|
void processImageOperation(ImageOperation const& operation, Image& input, ImageReferenceCallback refCallback = {});
|
|
|
|
|
2023-06-20 04:33:09 +00:00
|
|
|
Image processImageOperations(List<ImageOperation> const& operations, Image input, ImageReferenceCallback refCallback = {});
|
|
|
|
|
|
|
|
}
|