Refactor invert() to match other image manip functions

This commit is contained in:
Elias Batek 2024-10-13 17:52:57 +02:00
parent 75f77176d7
commit c21d14664c
1 changed files with 27 additions and 1 deletions

View File

@ -2087,6 +2087,13 @@ Pixel invert(const Pixel color) @nogc {
);
}
private void invertTo(const Pixmap source, Pixmap target) @trusted @nogc {
debug assert(source.length == target.length);
foreach (idx, ref px; target.data) {
px = invert(source.data.ptr[idx]);
}
}
/++
Inverts all colors to produce a $(B negative image).
@ -2094,12 +2101,31 @@ Pixel invert(const Pixel color) @nogc {
Develops a positive image when applied to a negative one.
)
+/
void invert(Pixmap pixmap) @nogc {
Pixmap invert(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.invertCalcDims());
source.invertTo(target);
return target;
}
/// ditto
Pixmap invertNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.invertCalcDims());
source.invertTo(target);
return target;
}
/// ditto
void invertInPlace(Pixmap pixmap) @nogc {
foreach (ref px; pixmap.data) {
px = invert(px);
}
}
/// ditto
PixmapBlueprint invertCalcDims(const Pixmap source) @nogc {
return PixmapBlueprint.fromPixmap(source);
}
/++
Crops an image and stores the result in the provided target Pixmap.