You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gdImageRotateInterpolated() converts the source image to truecolor #320
If a palette image is passed to gdImageRotateInterpolated() it is converted to truecolor. That is at the very least unexpected, because gdImageRotateInterpolated() is supposed to return a modified result, but not to change the source image.
Test Program
#include <stdio.h>
#include <assert.h>
#include <gd.h>
int main()
{
gdImagePtr src, dst;
int black;
src = gdImageCreate(10, 10);
black = gdImageColorAllocate(src, 0, 0, 0);
printf("src is truecolor: %d\n", gdImageTrueColor(src));
dst = gdImageRotateInterpolated(src, 30.0, black);
assert(dst != NULL);
printf("src is truecolor: %d\n", gdImageTrueColor(src));
}
This is not about the output (or the internal calculation), but rather the fact that the source image is converted to true-color. This might have better been solved by only supporting true-color images in the first place (and failing for palette images), but we cannot change that anymore. However, we should document that this conversion is happening.
Solution would be simple: just create a copy of the src image before converting to palette. I'm not sure whether it's worth it. Users can do that themselves if they need to retain the source image (often there is no need to).
The fix is:
gdImageClone ion line 1885
gdImagePaletteToTrueColor(clone)
back_src = src;
src = clone;
At this stage I would like to go with the "fix" rather than making it non obvious. If the src changes, the parameter should be ** at the very least (to make it clear and not const *).
Activity
pierrejoye commentedon Aug 15, 2021
All interpolation converts to TC yes. It makes thing too complicated with palette while massively reducing the quality.
cmb69 commentedon Aug 16, 2021
This is not about the output (or the internal calculation), but rather the fact that the source image is converted to true-color. This might have better been solved by only supporting true-color images in the first place (and failing for palette images), but we cannot change that anymore. However, we should document that this conversion is happening.
pierrejoye commentedon Aug 16, 2021
oh, the original image is converted? sorry I misread. That should not happen. I will look into it.
cmb69 commentedon Aug 16, 2021
libgd/src/gd_interpolation.c
Lines 1882 to 1887 in 9af6d12
Solution would be simple: just create a copy of the src image before converting to palette. I'm not sure whether it's worth it. Users can do that themselves if they need to retain the source image (often there is no need to).
pierrejoye commentedon Aug 16, 2021
It is needed to be converted anyway.
The fix is:
gdImageClone ion line 1885
gdImagePaletteToTrueColor(clone)
back_src = src;
src = clone;
At this stage I would like to go with the "fix" rather than making it non obvious. If the src changes, the parameter should be ** at the very least (to make it clear and not const *).
cmb69 commentedon Aug 16, 2021
That's fine for me as well. :)
Fix #320, should not convert the source to palette
pierrejoye commentedon Sep 1, 2021
PR done, please check :)
Merge pull request #748 from libgd/bug/320
Fix fix for libgd#320
Fix fix for libgd#320
Fix fix for #320 (#929)