Rename "…To" image manipulation functions to "…Into"

This commit is contained in:
Elias Batek 2024-10-13 18:55:43 +02:00
parent ac7f4c9889
commit c23f7116c7
1 changed files with 29 additions and 27 deletions

View File

@ -2094,7 +2094,7 @@ Pixel decreaseOpacityF(const Pixel source, float opacityPercentage) @nogc {
// Dont get fooled by the name of this function. // Dont get fooled by the name of this function.
// Its called like that for consistency reasons. // Its called like that for consistency reasons.
private void decreaseOpacityTo(const Pixmap source, Pixmap target, ubyte opacityPercentage) @trusted @nogc { private void decreaseOpacityInto(const Pixmap source, Pixmap target, ubyte opacityPercentage) @trusted @nogc {
debug assert(source.data.length == target.data.length); debug assert(source.data.length == target.data.length);
foreach (idx, ref px; target.data) { foreach (idx, ref px; target.data) {
px = decreaseOpacity(source.data.ptr[idx], opacityPercentage); px = decreaseOpacity(source.data.ptr[idx], opacityPercentage);
@ -2112,14 +2112,14 @@ private void decreaseOpacityTo(const Pixmap source, Pixmap target, ubyte opacity
+/ +/
Pixmap decreaseOpacity(const Pixmap source, Pixmap target, ubyte opacityPercentage) @nogc { Pixmap decreaseOpacity(const Pixmap source, Pixmap target, ubyte opacityPercentage) @nogc {
target.adjustTo(source.decreaseOpacityCalcDims(opacityPercentage)); target.adjustTo(source.decreaseOpacityCalcDims(opacityPercentage));
source.decreaseOpacityTo(target, opacityPercentage); source.decreaseOpacityInto(target, opacityPercentage);
return target; return target;
} }
/// ditto /// ditto
Pixmap decreaseOpacityNew(const Pixmap source, ubyte opacityPercentage) { Pixmap decreaseOpacityNew(const Pixmap source, ubyte opacityPercentage) {
auto target = Pixmap.makeNew(source.decreaseOpacityCalcDims(opacityPercentage)); auto target = Pixmap.makeNew(source.decreaseOpacityCalcDims(opacityPercentage));
source.decreaseOpacityTo(target, opacityPercentage); source.decreaseOpacityInto(target, opacityPercentage);
return target; return target;
} }
@ -2175,7 +2175,7 @@ Pixel invert(const Pixel color) @nogc {
); );
} }
private void invertTo(const Pixmap source, Pixmap target) @trusted @nogc { private void invertInto(const Pixmap source, Pixmap target) @trusted @nogc {
debug assert(source.length == target.length); debug assert(source.length == target.length);
foreach (idx, ref px; target.data) { foreach (idx, ref px; target.data) {
px = invert(source.data.ptr[idx]); px = invert(source.data.ptr[idx]);
@ -2191,14 +2191,14 @@ private void invertTo(const Pixmap source, Pixmap target) @trusted @nogc {
+/ +/
Pixmap invert(const Pixmap source, Pixmap target) @nogc { Pixmap invert(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.invertCalcDims()); target.adjustTo(source.invertCalcDims());
source.invertTo(target); source.invertInto(target);
return target; return target;
} }
/// ditto /// ditto
Pixmap invertNew(const Pixmap source) { Pixmap invertNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.invertCalcDims()); auto target = Pixmap.makeNew(source.invertCalcDims());
source.invertTo(target); source.invertInto(target);
return target; return target;
} }
@ -2234,6 +2234,9 @@ void cropTo(const Pixmap source, Pixmap target, Point offset = Point(0, 0)) @nog
src.extractToPixmapCopyImpl(target); src.extractToPixmapCopyImpl(target);
} }
// consistency
private alias cropInto = cropTo;
/++ /++
Crops an image to the provided size with the requested offset. Crops an image to the provided size with the requested offset.
@ -2241,14 +2244,14 @@ void cropTo(const Pixmap source, Pixmap target, Point offset = Point(0, 0)) @nog
+/ +/
Pixmap crop(const Pixmap source, Pixmap target, Size cropToSize, Point offset = Point(0, 0)) @nogc { Pixmap crop(const Pixmap source, Pixmap target, Size cropToSize, Point offset = Point(0, 0)) @nogc {
target.adjustTo(source.cropCalcDims(cropToSize, offset)); target.adjustTo(source.cropCalcDims(cropToSize, offset));
cropTo(source, target, offset); cropInto(source, target, offset);
return target; return target;
} }
/// ditto /// ditto
Pixmap cropNew(const Pixmap source, Size cropToSize, Point offset = Point(0, 0)) { Pixmap cropNew(const Pixmap source, Size cropToSize, Point offset = Point(0, 0)) {
auto target = Pixmap.makeNew(cropToSize); auto target = Pixmap.makeNew(cropToSize);
cropTo(source, target, offset); cropInto(source, target, offset);
return target; return target;
} }
@ -2268,7 +2271,7 @@ PixmapBlueprint cropCalcDims(const Pixmap source, Size cropToSize, Point offset
return PixmapBlueprint.fromSize(cropToSize); return PixmapBlueprint.fromSize(cropToSize);
} }
private void transposeTo(const Pixmap source, Pixmap target) @nogc { private void transposeInto(const Pixmap source, Pixmap target) @nogc {
foreach (y; 0 .. target.width) { foreach (y; 0 .. target.width) {
foreach (x; 0 .. source.width) { foreach (x; 0 .. source.width) {
const idxSrc = linearOffset(Point(x, y), source.width); const idxSrc = linearOffset(Point(x, y), source.width);
@ -2291,14 +2294,14 @@ private void transposeTo(const Pixmap source, Pixmap target) @nogc {
+/ +/
Pixmap transpose(const Pixmap source, Pixmap target) @nogc { Pixmap transpose(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.transposeCalcDims()); target.adjustTo(source.transposeCalcDims());
source.transposeTo(target); source.transposeInto(target);
return target; return target;
} }
/// ditto /// ditto
Pixmap transposeNew(const Pixmap source) { Pixmap transposeNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.transposeCalcDims()); auto target = Pixmap.makeNew(source.transposeCalcDims());
source.transposeTo(target); source.transposeInto(target);
return target; return target;
} }
@ -2307,7 +2310,7 @@ PixmapBlueprint transposeCalcDims(const Pixmap source) @nogc {
return PixmapBlueprint(source.length, source.height); return PixmapBlueprint(source.length, source.height);
} }
private void rotateClockwiseTo(const Pixmap source, Pixmap target) @nogc { private void rotateClockwiseInto(const Pixmap source, Pixmap target) @nogc {
const area = source.data.length; const area = source.data.length;
const rowLength = source.size.height; const rowLength = source.size.height;
ptrdiff_t cursor = -1; ptrdiff_t cursor = -1;
@ -2334,14 +2337,14 @@ private void rotateClockwiseTo(const Pixmap source, Pixmap target) @nogc {
+/ +/
Pixmap rotateClockwise(const Pixmap source, Pixmap target) @nogc { Pixmap rotateClockwise(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.rotateClockwiseCalcDims()); target.adjustTo(source.rotateClockwiseCalcDims());
source.rotateClockwiseTo(target); source.rotateClockwiseInto(target);
return target; return target;
} }
/// ditto /// ditto
Pixmap rotateClockwiseNew(const Pixmap source) { Pixmap rotateClockwiseNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.rotateClockwiseCalcDims()); auto target = Pixmap.makeNew(source.rotateClockwiseCalcDims());
source.rotateClockwiseTo(target); source.rotateClockwiseInto(target);
return target; return target;
} }
@ -2350,7 +2353,7 @@ PixmapBlueprint rotateClockwiseCalcDims(const Pixmap source) @nogc {
return PixmapBlueprint(source.length, source.height); return PixmapBlueprint(source.length, source.height);
} }
private void rotateCounterClockwiseTo(const Pixmap source, Pixmap target) @nogc { private void rotateCounterClockwiseInto(const Pixmap source, Pixmap target) @nogc {
// TODO: can this be optimized? // TODO: can this be optimized?
target = transpose(source, target); target = transpose(source, target);
target.flipVerticallyInPlace(); target.flipVerticallyInPlace();
@ -2368,14 +2371,14 @@ private void rotateCounterClockwiseTo(const Pixmap source, Pixmap target) @nogc
+/ +/
Pixmap rotateCounterClockwise(const Pixmap source, Pixmap target) @nogc { Pixmap rotateCounterClockwise(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.rotateCounterClockwiseCalcDims()); target.adjustTo(source.rotateCounterClockwiseCalcDims());
source.rotateCounterClockwiseTo(target); source.rotateCounterClockwiseInto(target);
return target; return target;
} }
/// ditto /// ditto
Pixmap rotateCounterClockwiseNew(const Pixmap source) { Pixmap rotateCounterClockwiseNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.rotateCounterClockwiseCalcDims()); auto target = Pixmap.makeNew(source.rotateCounterClockwiseCalcDims());
source.rotateCounterClockwiseTo(target); source.rotateCounterClockwiseInto(target);
return target; return target;
} }
@ -2384,7 +2387,7 @@ PixmapBlueprint rotateCounterClockwiseCalcDims(const Pixmap source) @nogc {
return PixmapBlueprint(source.length, source.height); return PixmapBlueprint(source.length, source.height);
} }
private void rotate180degTo(const Pixmap source, Pixmap target) @nogc { private void rotate180degInto(const Pixmap source, Pixmap target) @nogc {
// Technically, this is implemented as flip vertical + flip horizontal. // Technically, this is implemented as flip vertical + flip horizontal.
auto src = PixmapScanner(source); auto src = PixmapScanner(source);
auto dst = PixmapScannerRW(target); auto dst = PixmapScannerRW(target);
@ -2411,14 +2414,14 @@ private void rotate180degTo(const Pixmap source, Pixmap target) @nogc {
+/ +/
Pixmap rotate180deg(const Pixmap source, Pixmap target) @nogc { Pixmap rotate180deg(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.rotate180degCalcDims()); target.adjustTo(source.rotate180degCalcDims());
source.rotate180degTo(target); source.rotate180degInto(target);
return target; return target;
} }
/// ditto /// ditto
Pixmap rotate180degNew(const Pixmap source) { Pixmap rotate180degNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.size); auto target = Pixmap.makeNew(source.size);
source.rotate180degTo(target); source.rotate180degInto(target);
return target; return target;
} }
@ -2455,7 +2458,7 @@ PixmapBlueprint rotate180degCalcDims(const Pixmap source) @nogc {
return PixmapBlueprint.fromPixmap(source); return PixmapBlueprint.fromPixmap(source);
} }
private void flipHorizontallyTo(const Pixmap source, Pixmap target) @nogc { private void flipHorizontallyInto(const Pixmap source, Pixmap target) @nogc {
auto src = PixmapScanner(source); auto src = PixmapScanner(source);
auto dst = PixmapScannerRW(target); auto dst = PixmapScannerRW(target);
@ -2481,14 +2484,14 @@ private void flipHorizontallyTo(const Pixmap source, Pixmap target) @nogc {
+/ +/
Pixmap flipHorizontally(const Pixmap source, Pixmap target) @nogc { Pixmap flipHorizontally(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.flipHorizontallyCalcDims()); target.adjustTo(source.flipHorizontallyCalcDims());
source.flipHorizontallyTo(target); source.flipHorizontallyInto(target);
return target; return target;
} }
/// ditto /// ditto
Pixmap flipHorizontallyNew(const Pixmap source) { Pixmap flipHorizontallyNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.size); auto target = Pixmap.makeNew(source.size);
source.flipHorizontallyTo(target); source.flipHorizontallyInto(target);
return target; return target;
} }
@ -2515,7 +2518,7 @@ PixmapBlueprint flipHorizontallyCalcDims(const Pixmap source) @nogc {
return PixmapBlueprint.fromPixmap(source); return PixmapBlueprint.fromPixmap(source);
} }
private void flipVerticallyTo(const Pixmap source, Pixmap target) @nogc { private void flipVerticallyInto(const Pixmap source, Pixmap target) @nogc {
auto src = PixmapScanner(source); auto src = PixmapScanner(source);
auto dst = PixmapScannerRW(target); auto dst = PixmapScannerRW(target);
@ -2537,15 +2540,14 @@ private void flipVerticallyTo(const Pixmap source, Pixmap target) @nogc {
+/ +/
Pixmap flipVertically(const Pixmap source, Pixmap target) @nogc { Pixmap flipVertically(const Pixmap source, Pixmap target) @nogc {
target.adjustTo(source.flipVerticallyCalcDims()); target.adjustTo(source.flipVerticallyCalcDims());
flipVerticallyInto(source, target);
flipVerticallyTo(source, target);
return target; return target;
} }
/// ditto /// ditto
Pixmap flipVerticallyNew(const Pixmap source) { Pixmap flipVerticallyNew(const Pixmap source) {
auto target = Pixmap.makeNew(source.flipVerticallyCalcDims()); auto target = Pixmap.makeNew(source.flipVerticallyCalcDims());
source.flipVerticallyTo(target); source.flipVerticallyInto(target);
return target; return target;
} }