Repository navigation
Conversation
|
@mmporong please, could you post some screenshots with before-after? not sure if I understand the issue it addresses... |
|
Sure, here are before/after images.
Test image: 8x5 pixels with a 1-pixel border in a different color on each side (blue top, green right, orange bottom, red left). All images are scaled 24x with 90 degrees. Left: master, middle: this PR, right: 180 degrees. Left: master, middle: this PR, right: 45 degrees. Left: master, right: this PR. On master the shape is half a pixel off center, so the blue and red borders are blended with the dark fill while the orange and green ones keep their full color. With this PR all four borders keep their color. Numeric check with an 8x5 image that has a different color in every pixel: at 90 degrees master has 8 transparent pixels, 40 of 40 pixels differ from Master is 3b12ba1 and this PR is e8f2398. The harness uses only CPU image functions (no window), and its source and the 1:1 PNGs are here: https://github.com/mmporong/raylib/tree/pr-6356-screenshots/pr-6356 |
|
@mmporong is rotation following other drawing functions rotation convention? |
|
Yes. This PR does not change the direction, only where the samples are taken (pixel centers instead of pixel corners). The sin/cos terms are the same as on master.
|
|
@mmporong sorry, I don't understand your answer if yes or no. please, could you reread my question and be more clear? provide 45deg rotation samples with the other functions using same image. |
|
Yes. Here is the same image rotated 45 degrees with each function: In all three results the blue top border ends up on the upper right. I also compared the pixels. Against Setup: 192x120 image, bilinear filter, 300x300 canvas, all three rotated around the canvas center, drawn with Mesa software OpenGL. |





ImageRotate()currently maps destination pixel corners back into the source image. At right angles this shifts the sampled pixels, sends edge coordinates outside the image, and leaves transparent pixels in the output. For example, rotating a 2x3 RGBA image by 180 degrees leaves four of its six pixels transparent.This change maps destination pixel centers to source pixel centers. It accepts coordinates within the source pixels' half-pixel extent, clamps interpolation at the image edge, and rounds interpolated channel values to the nearest integer.
The channel rounding is needed to recover exact source values at right angles when floating-point trigonometry produces values just below an integer. For non-right-angle interpolation, this can change a channel by at most one compared with the previous truncation.
I tested the change with distinct per-pixel RGBA values and hard-coded expected outputs for 2x3 and 3x3 images. The cases cover 0, 90, 180, 270, and -90 degrees, plus 360 degrees as an out-of-contract diagnostic. All cases preserve the expected dimensions and contain no unexpected transparent pixels.
Validation performed:
libraylib.a: 9/9 cases passedThe following headless reproducer links against the built static library. It rotates six unique RGBA8 pixels by 180 degrees and checks the complete output, including alpha:
I compiled it with a C99 compiler, the raylib
srcinclude directory, and the CMake Releaselibraylib.a. It exits with status 0 and does not initialize a window or graphics device.I did not run the Windows, macOS, WebAssembly, or Android builds. I also did not run GUI examples or GPU rendering tests; this change is in the CPU image manipulation path.