mirror of https://github.com/adamdruppe/arsd.git
Fix cropInPlace()
This commit is contained in:
parent
6978d1f2dd
commit
fc346c3ec2
|
@ -375,13 +375,16 @@ struct SubPixmap {
|
||||||
Copies the pixel data – cropped to the subimage region –
|
Copies the pixel data – cropped to the subimage region –
|
||||||
into the target Pixmap.
|
into the target Pixmap.
|
||||||
|
|
||||||
Returns:
|
$(PITFALL
|
||||||
A size-adjusted shallow copy of the input Pixmap overwritten
|
Do not attempt to extract a subimage back into the source pixmap.
|
||||||
with the image data of the SubPixmap.
|
This will fail in cases where source and target regions overlap
|
||||||
|
and potentially crash the program.
|
||||||
|
)
|
||||||
|
|
||||||
$(PITFALL
|
$(PITFALL
|
||||||
While the returned Pixmap utilizes the buffer provided by the input,
|
While the returned Pixmap utilizes the buffer provided by the input,
|
||||||
the returned Pixmap might not exactly match the input.
|
the returned Pixmap might not exactly match the input.
|
||||||
|
The dimensions (width and height) and the length might have changed.
|
||||||
|
|
||||||
Always use the returned Pixmap structure.
|
Always use the returned Pixmap structure.
|
||||||
|
|
||||||
|
@ -393,6 +396,10 @@ struct SubPixmap {
|
||||||
pixmap = subPixmap.extractToPixmap(pixmap);
|
pixmap = subPixmap.extractToPixmap(pixmap);
|
||||||
---
|
---
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A size-adjusted shallow copy of the input Pixmap overwritten
|
||||||
|
with the image data of the SubPixmap.
|
||||||
+/
|
+/
|
||||||
Pixmap extractToPixmap(Pixmap target) @nogc const {
|
Pixmap extractToPixmap(Pixmap target) @nogc const {
|
||||||
// Length adjustment
|
// Length adjustment
|
||||||
|
@ -418,6 +425,19 @@ struct SubPixmap {
|
||||||
src.popFront();
|
src.popFront();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void extractToPixmapCopyPixelByPixelImpl(Pixmap target) @nogc const {
|
||||||
|
auto src = SubPixmapScanner(this);
|
||||||
|
auto dst = PixmapScannerRW(target);
|
||||||
|
|
||||||
|
foreach (dstLine; dst) {
|
||||||
|
const srcLine = src.front;
|
||||||
|
foreach (idx, ref px; dstLine) {
|
||||||
|
px = srcLine[idx];
|
||||||
|
}
|
||||||
|
src.popFront();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@safe pure nothrow @nogc:
|
@safe pure nothrow @nogc:
|
||||||
|
@ -1640,12 +1660,18 @@ Pixmap cropNew(const Pixmap source, Size targetSize, Point offset = Point(0, 0))
|
||||||
/++
|
/++
|
||||||
Crops an image and stores the result in the source buffer.
|
Crops an image and stores the result in the source buffer.
|
||||||
|
|
||||||
The source pixmap structure is passed by ref and gets with a size-adjusted
|
The source pixmap structure is passed by value.
|
||||||
structure using a slice of the same underlying memory.
|
A size-adjusted structure using a slice of the same underlying memory is
|
||||||
|
returned.
|
||||||
+/
|
+/
|
||||||
void cropInplace(ref Pixmap source, Size targetSize, Point offset = Point(0, 0)) @nogc {
|
Pixmap cropInPlace(Pixmap source, Size targetSize, Point offset = Point(0, 0)) @nogc {
|
||||||
|
Pixmap target = source;
|
||||||
|
target.width = targetSize.width;
|
||||||
|
target.data = target.data[0 .. targetSize.area];
|
||||||
|
|
||||||
auto src = const(SubPixmap)(source, targetSize, offset);
|
auto src = const(SubPixmap)(source, targetSize, offset);
|
||||||
source = src.extractToPixmap(source);
|
src.extractToPixmapCopyPixelByPixelImpl(target);
|
||||||
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
|
@ -1674,6 +1700,16 @@ void rotateClockwise(const Pixmap source, Pixmap target) @nogc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/++
|
||||||
|
Rotates an image by 90° clockwise.
|
||||||
|
Stores the result in a newly allocated Pixmap.
|
||||||
|
+/
|
||||||
|
Pixmap rotateClockwiseNew(const Pixmap source) {
|
||||||
|
auto target = Pixmap(Size(source.height, source.width));
|
||||||
|
source.rotateClockwise(target);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
@safe pure nothrow @nogc:
|
@safe pure nothrow @nogc:
|
||||||
|
|
||||||
// ==== Blending functions ====
|
// ==== Blending functions ====
|
||||||
|
|
Loading…
Reference in New Issue