Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect pointer math in SpriteContentsInterpolationMixin #2185

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,29 @@ void apply(int x, int y, SpriteContents.AnimatorImpl arg) {
long ppSrcPixel = NativeImageHelper.getPointerRGBA(src);
long ppDstPixel = NativeImageHelper.getPointerRGBA(dst);

// Pointers to the pixel array for the current and next frame
long pRgba1 = ppSrcPixel + (curX + (long) curY * src.getWidth() * STRIDE);
long pRgba2 = ppSrcPixel + (nextX + (long) nextY * src.getWidth() * STRIDE);
for (int layerY = 0; layerY < height; layerY++) {
// Pointers to the pixel array for the current and next frame
long pRgba1 = ppSrcPixel + (curX + (long) (curY + layerY) * src.getWidth()) * STRIDE;
long pRgba2 = ppSrcPixel + (nextX + (long) (nextY + layerY) * src.getWidth()) * STRIDE;

for (int pixelIndex = 0, pixelCount = width * height; pixelIndex < pixelCount; pixelIndex++) {
int rgba1 = MemoryUtil.memGetInt(pRgba1);
int rgba2 = MemoryUtil.memGetInt(pRgba2);
for (int layerX = 0; layerX < width; layerX++) {
int rgba1 = MemoryUtil.memGetInt(pRgba1);
int rgba2 = MemoryUtil.memGetInt(pRgba2);

// Mix the RGB components and truncate the A component
int mixedRgb = ColorMixer.mix(rgba1, rgba2, mix) & 0x00FFFFFF;
// Mix the RGB components and truncate the A component
int mixedRgb = ColorMixer.mix(rgba1, rgba2, mix) & 0x00FFFFFF;

// Take the A component from the source pixel
int alpha = rgba1 & 0xFF000000;
// Take the A component from the source pixel
int alpha = rgba1 & 0xFF000000;

// Update the pixel within the interpolated frame using the combined RGB and A components
MemoryUtil.memPutInt(ppDstPixel, mixedRgb | alpha);
// Update the pixel within the interpolated frame using the combined RGB and A components
MemoryUtil.memPutInt(ppDstPixel, mixedRgb | alpha);

pRgba1 += STRIDE;
pRgba2 += STRIDE;
pRgba1 += STRIDE;
pRgba2 += STRIDE;

ppDstPixel += STRIDE;
ppDstPixel += STRIDE;
}
}
}

Expand Down
Loading