Skip to content

Commit 00d1d4a

Browse files
committed
Blend: note imIn1/imIn2/imOut can't alias each other
1 parent 84af3f5 commit 00d1d4a

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/libImaging/Blend.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,21 @@ ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha) {
5454
if (alpha >= 0 && alpha <= 1.0) {
5555
/* Interpolate between bands */
5656
for (y = 0; y < ysize; y++) {
57-
UINT8 *in1 = (UINT8 *)imIn1->image[y];
58-
UINT8 *in2 = (UINT8 *)imIn2->image[y];
59-
UINT8 *out = (UINT8 *)imOut->image[y];
57+
// restrict safe: imIn1 and imIn2 are read-only; imOut is a new allocation
58+
UINT8 *restrict in1 = (UINT8 *)imIn1->image[y];
59+
UINT8 *restrict in2 = (UINT8 *)imIn2->image[y];
60+
UINT8 *restrict out = (UINT8 *)imOut->image[y];
6061
for (x = 0; x < linesize; x++) {
6162
out[x] = (UINT8)((int)in1[x] + alpha * ((int)in2[x] - (int)in1[x]));
6263
}
6364
}
6465
} else {
6566
/* Extrapolation; must make sure to clip resulting values */
6667
for (y = 0; y < ysize; y++) {
67-
UINT8 *in1 = (UINT8 *)imIn1->image[y];
68-
UINT8 *in2 = (UINT8 *)imIn2->image[y];
69-
UINT8 *out = (UINT8 *)imOut->image[y];
68+
// restrict safe: imIn1 and imIn2 are read-only; imOut is a new allocation
69+
UINT8 *restrict in1 = (UINT8 *)imIn1->image[y];
70+
UINT8 *restrict in2 = (UINT8 *)imIn2->image[y];
71+
UINT8 *restrict out = (UINT8 *)imOut->image[y];
7072
for (x = 0; x < linesize; x++) {
7173
float temp = (float)((int)in1[x] + alpha * ((int)in2[x] - (int)in1[x]));
7274
if (temp <= 0.0) {

0 commit comments

Comments
 (0)