add 'fill_image' script function, rename 'offset' combine mode to 'lightmap'

This commit is contained in:
GenevensiS
2026-04-12 07:30:11 +02:00
parent d49cfda407
commit fa3f2e950d
7 changed files with 191 additions and 135 deletions
+14
View File
@@ -0,0 +1,14 @@
Function: fill_image
DOC_MSE_VERSION: since 2.6.0
--Usage--
> fill_image(input: image, color: color)
Fill an image with a single color, but keep the alpha channel unchanged.
--Parameters--
! Parameter Type Description
| @input@ [[type:image]] Image to fill.
| @color@ [[type:color]] Color to fill with.
+1
View File
@@ -86,6 +86,7 @@ These functions are built into the program, other [[type:function]]s can be defi
| [[fun:set_mask]] Set the transparancy mask of an image. | [[fun:set_mask]] Set the transparancy mask of an image.
| [[fun:set_alpha]] Change the transparency of an image. | [[fun:set_alpha]] Change the transparency of an image.
| [[fun:set_combine]] Change how the image should be combined with the background. | [[fun:set_combine]] Change how the image should be combined with the background.
| [[fun:fill_image]] Fill an image with a single color.
| [[fun:saturate_image]] Saturate/desaturate an image. | [[fun:saturate_image]] Saturate/desaturate an image.
| [[fun:brighten_image]] Brighten/darken an image. | [[fun:brighten_image]] Brighten/darken an image.
| [[fun:invert_image]] Invert the colors of an image. | [[fun:invert_image]] Invert the colors of an image.
+16 -10
View File
@@ -42,7 +42,8 @@ String combine_to_string(const ImageCombine& combine) {
case COMBINE_OR: return "or"; case COMBINE_OR: return "or";
case COMBINE_XOR: return "xor"; case COMBINE_XOR: return "xor";
case COMBINE_SHADOW: return "shadow"; case COMBINE_SHADOW: return "shadow";
case COMBINE_OFFSET: return "offset"; case COMBINE_LIGHTMAP_ABSOLUTE: return "lightmap absolute";
case COMBINE_LIGHTMAP_RELATIVE: return "lightmap relative";
case COMBINE_SYMMETRIC_OVERLAY: return "symmetric overlay"; case COMBINE_SYMMETRIC_OVERLAY: return "symmetric overlay";
case COMBINE_BRIGHTNESS_TO_ALPHA: return "brightness to alpha"; case COMBINE_BRIGHTNESS_TO_ALPHA: return "brightness to alpha";
case COMBINE_DARKNESS_TO_ALPHA: return "darkness to alpha"; case COMBINE_DARKNESS_TO_ALPHA: return "darkness to alpha";
@@ -175,7 +176,8 @@ IMPLEMENT_REFLECTION_ENUM(ImageCombine) {
VALUE_N("or", COMBINE_OR); VALUE_N("or", COMBINE_OR);
VALUE_N("xor", COMBINE_XOR); VALUE_N("xor", COMBINE_XOR);
VALUE_N("shadow", COMBINE_SHADOW); VALUE_N("shadow", COMBINE_SHADOW);
VALUE_N("offset", COMBINE_OFFSET); VALUE_N("lightmap absolute", COMBINE_LIGHTMAP_ABSOLUTE);
VALUE_N("lightmap relative", COMBINE_LIGHTMAP_RELATIVE);
VALUE_N("symmetric overlay", COMBINE_SYMMETRIC_OVERLAY); VALUE_N("symmetric overlay", COMBINE_SYMMETRIC_OVERLAY);
VALUE_N("brightness to alpha", COMBINE_BRIGHTNESS_TO_ALPHA); VALUE_N("brightness to alpha", COMBINE_BRIGHTNESS_TO_ALPHA);
VALUE_N("darkness to alpha", COMBINE_DARKNESS_TO_ALPHA); VALUE_N("darkness to alpha", COMBINE_DARKNESS_TO_ALPHA);
@@ -308,12 +310,12 @@ COMBINE_FUN(COMBINE_LIGHTEN, max(a, b))
COMBINE_FUN(COMBINE_COLOR_DODGE, b == 255 ? 255 : top(a * 255 / (255 - b))) COMBINE_FUN(COMBINE_COLOR_DODGE, b == 255 ? 255 : top(a * 255 / (255 - b)))
COMBINE_FUN(COMBINE_COLOR_BURN, b == 0 ? 0 : bot(255 - (255-a) * 255 / b)) COMBINE_FUN(COMBINE_COLOR_BURN, b == 0 ? 0 : bot(255 - (255-a) * 255 / b))
COMBINE_FUN(COMBINE_SCREEN, 255 - (((255 - a) * (255 - b)) / 255)) COMBINE_FUN(COMBINE_SCREEN, 255 - (((255 - a) * (255 - b)) / 255))
COMBINE_FUN(COMBINE_OVERLAY, a < 128 COMBINE_FUN(COMBINE_OVERLAY, a < 128 ?
? (a * b) >> 7 (a * b) >> 7 :
: 255 - (((255 - a) * (255 - b)) >> 7)) 255 - (((255 - a) * (255 - b)) >> 7))
COMBINE_FUN(COMBINE_HARD_LIGHT, b < 128 COMBINE_FUN(COMBINE_HARD_LIGHT, b < 128 ?
? (a * b) >> 7 (a * b) >> 7 :
: 255 - (((255 - a) * (255 - b)) >> 7)) 255 - (((255 - a) * (255 - b)) >> 7))
COMBINE_FUN(COMBINE_SOFT_LIGHT, b) COMBINE_FUN(COMBINE_SOFT_LIGHT, b)
COMBINE_FUN(COMBINE_REFLECT, b == 255 ? 255 : top(a * a / (255 - b))) COMBINE_FUN(COMBINE_REFLECT, b == 255 ? 255 : top(a * a / (255 - b)))
COMBINE_FUN(COMBINE_GLOW, a == 255 ? 255 : top(b * b / (255 - a))) COMBINE_FUN(COMBINE_GLOW, a == 255 ? 255 : top(b * b / (255 - a)))
@@ -323,7 +325,10 @@ COMBINE_FUN(COMBINE_AND, a & b)
COMBINE_FUN(COMBINE_OR, a | b) COMBINE_FUN(COMBINE_OR, a | b)
COMBINE_FUN(COMBINE_XOR, a ^ b) COMBINE_FUN(COMBINE_XOR, a ^ b)
COMBINE_FUN(COMBINE_SHADOW, (b * a * a) / (255 * 255)) COMBINE_FUN(COMBINE_SHADOW, (b * a * a) / (255 * 255))
COMBINE_FUN(COMBINE_OFFSET, col(a + b - 128)) COMBINE_FUN(COMBINE_LIGHTMAP_ABSOLUTE, col(a + b - 128))
COMBINE_FUN(COMBINE_LIGHTMAP_RELATIVE, b < 128 ?
a * b / 128 :
a + (255 - a) * (b - 128) / 128)
COMBINE_FUN(COMBINE_SYMMETRIC_OVERLAY, (Combine<COMBINE_OVERLAY>::f(a, b) + Combine<COMBINE_OVERLAY>::f(b, a)) / 2) COMBINE_FUN(COMBINE_SYMMETRIC_OVERLAY, (Combine<COMBINE_OVERLAY>::f(a, b) + Combine<COMBINE_OVERLAY>::f(b, a)) / 2)
COMBINE_FUN(COMBINE_BRIGHTNESS_TO_ALPHA, ((255 - a) * a + a * b) / 255) COMBINE_FUN(COMBINE_BRIGHTNESS_TO_ALPHA, ((255 - a) * a + a * b) / 255)
COMBINE_FUN(COMBINE_DARKNESS_TO_ALPHA, (255 * a + (255 - a) * b) / 255) COMBINE_FUN(COMBINE_DARKNESS_TO_ALPHA, (255 * a + (255 - a) * b) / 255)
@@ -480,7 +485,8 @@ void combine_image(Image& a, const Image& b, ImageCombine combine) {
DISPATCH(COMBINE_OR); DISPATCH(COMBINE_OR);
DISPATCH(COMBINE_XOR); DISPATCH(COMBINE_XOR);
DISPATCH(COMBINE_SHADOW); DISPATCH(COMBINE_SHADOW);
DISPATCH(COMBINE_OFFSET); DISPATCH(COMBINE_LIGHTMAP_ABSOLUTE);
DISPATCH(COMBINE_LIGHTMAP_RELATIVE);
DISPATCH(COMBINE_SYMMETRIC_OVERLAY); DISPATCH(COMBINE_SYMMETRIC_OVERLAY);
DISPATCH(COMBINE_BRIGHTNESS_TO_ALPHA); DISPATCH(COMBINE_BRIGHTNESS_TO_ALPHA);
DISPATCH(COMBINE_DARKNESS_TO_ALPHA); DISPATCH(COMBINE_DARKNESS_TO_ALPHA);
+13
View File
@@ -188,6 +188,19 @@ bool SetCombineImage::operator == (const GeneratedImage& that) const {
&& image_combine == that2->image_combine; && image_combine == that2->image_combine;
} }
// ----------------------------------------------------------------------------- : FillImage
Image FillImage::generate(const Options& opt) {
Image img = image->generate(opt);
fill_image(img, color);
return img;
}
bool FillImage::operator == (const GeneratedImage& that) const {
const FillImage* that2 = dynamic_cast<const FillImage*>(&that);
return that2 && *image == *that2->image
&& color == that2->color;
}
// ----------------------------------------------------------------------------- : SaturateImage // ----------------------------------------------------------------------------- : SaturateImage
Image SaturateImage::generate(const Options& opt) { Image SaturateImage::generate(const Options& opt) {
+14
View File
@@ -189,6 +189,20 @@ private:
ImageCombine image_combine; ImageCombine image_combine;
}; };
// ----------------------------------------------------------------------------- : FillImage
/// Fill an image with a given color, without touching the alpha channel
class FillImage : public SimpleFilterImage {
public:
inline FillImage(const GeneratedImageP& image, Color color)
: SimpleFilterImage(image), color(color)
{}
Image generate(const Options& opt) override;
bool operator == (const GeneratedImage& that) const override;
private:
Color color;
};
// ----------------------------------------------------------------------------- : SaturateImage // ----------------------------------------------------------------------------- : SaturateImage
/// Saturate/desaturate an image /// Saturate/desaturate an image
+2 -1
View File
@@ -144,7 +144,8 @@ enum ImageCombine
, COMBINE_OR , COMBINE_OR
, COMBINE_XOR , COMBINE_XOR
, COMBINE_SHADOW , COMBINE_SHADOW
, COMBINE_OFFSET , COMBINE_LIGHTMAP_ABSOLUTE
, COMBINE_LIGHTMAP_RELATIVE
, COMBINE_SYMMETRIC_OVERLAY , COMBINE_SYMMETRIC_OVERLAY
, COMBINE_BRIGHTNESS_TO_ALPHA , COMBINE_BRIGHTNESS_TO_ALPHA
, COMBINE_DARKNESS_TO_ALPHA , COMBINE_DARKNESS_TO_ALPHA
+7
View File
@@ -162,6 +162,12 @@ SCRIPT_FUNCTION(set_combine) {
return make_intrusive<SetCombineImage>(input, image_combine); return make_intrusive<SetCombineImage>(input, image_combine);
} }
SCRIPT_FUNCTION(fill_image) {
SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(Color, color);
return make_intrusive<FillImage>(input,color);
}
SCRIPT_FUNCTION(saturate) { SCRIPT_FUNCTION(saturate) {
SCRIPT_PARAM_C(GeneratedImageP, input); SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM(double, amount); SCRIPT_PARAM(double, amount);
@@ -349,6 +355,7 @@ void init_script_image_functions(Context& ctx) {
ctx.setVariable(_("set_mask"), script_set_mask); ctx.setVariable(_("set_mask"), script_set_mask);
ctx.setVariable(_("set_alpha"), script_set_alpha); ctx.setVariable(_("set_alpha"), script_set_alpha);
ctx.setVariable(_("set_combine"), script_set_combine); ctx.setVariable(_("set_combine"), script_set_combine);
ctx.setVariable(_("fill_image"), script_fill_image);
ctx.setVariable(_("saturate"), script_saturate); ctx.setVariable(_("saturate"), script_saturate);
ctx.setVariable(_("saturate_image"), script_saturate); ctx.setVariable(_("saturate_image"), script_saturate);
ctx.setVariable(_("brighten_image"), script_brighten_image); ctx.setVariable(_("brighten_image"), script_brighten_image);