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

gdImageRotateInterpolated() converts the source image to truecolor #320

Closed
cmb69 opened this issue Oct 3, 2016 · 7 comments
Closed

gdImageRotateInterpolated() converts the source image to truecolor #320

cmb69 opened this issue Oct 3, 2016 · 7 comments
Assignees
Labels
Milestone

Comments

@cmb69
Copy link
Contributor

cmb69 commented Oct 3, 2016

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));
}

Expected Output

src is truecolor: 0
src is truecolor: 0

Actual Output

src is truecolor: 0
src is truecolor: 1
@pierrejoye
Copy link
Contributor

All interpolation converts to TC yes. It makes thing too complicated with palette while massively reducing the quality.

@cmb69
Copy link
Contributor Author

cmb69 commented 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.

@cmb69 cmb69 reopened this Aug 16, 2021
@cmb69 cmb69 self-assigned this Aug 16, 2021
@pierrejoye
Copy link
Contributor

oh, the original image is converted? sorry I misread. That should not happen. I will look into it.

@cmb69
Copy link
Contributor Author

cmb69 commented Aug 16, 2021

libgd/src/gd_interpolation.c

Lines 1882 to 1887 in 9af6d12

if (src->trueColor == 0) {
if (bgcolor < gdMaxColors) {
bgcolor = gdTrueColorAlpha(src->red[bgcolor], src->green[bgcolor], src->blue[bgcolor], src->alpha[bgcolor]);
}
gdImagePaletteToTrueColor(src);
}

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
Copy link
Contributor

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
Copy link
Contributor Author

cmb69 commented Aug 16, 2021

That's fine for me as well. :)

@cmb69 cmb69 removed their assignment Aug 16, 2021
@cmb69 cmb69 added bug and removed documentation labels Aug 16, 2021
@pierrejoye pierrejoye self-assigned this Aug 25, 2021
@pierrejoye pierrejoye added this to the GD 2.3.3 milestone Aug 25, 2021
@pierrejoye
Copy link
Contributor

PR done, please check :)

pierrejoye added a commit that referenced this issue Sep 2, 2021
Fix #320, should not convert the source to palette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants