Skip to content

gdImageRotateInterpolated() converts the source image to truecolor #320

Closed

Description

@cmb69

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

Activity

  1. pierrejoye commented on Aug 15, 2021

    @pierrejoye
    Contributor

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

  2. cmb69 commented on Aug 16, 2021

    @cmb69
    MemberAuthor

    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.

  3. reopened this on Aug 16, 2021
  4. self-assigned this
    on Aug 16, 2021
  5. pierrejoye commented on Aug 16, 2021

    @pierrejoye
    Contributor

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

  6. cmb69 commented on Aug 16, 2021

    @cmb69
    MemberAuthor

    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).

  7. pierrejoye commented on Aug 16, 2021

    @pierrejoye
    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 *).

  8. cmb69 commented on Aug 16, 2021

    @cmb69
    MemberAuthor

    That's fine for me as well. :)

  9. removed their assignment
    on Aug 16, 2021
  10. self-assigned this
    on Aug 25, 2021
  11. added this to the GD 2.3.3 milestone on Aug 25, 2021
  12. added a commit that references this issue on Sep 1, 2021
    4a0d7d8
  13. pierrejoye commented on Sep 1, 2021

    @pierrejoye
    Contributor

    PR done, please check :)

  14. added a commit that references this issue on Sep 2, 2021
    cb4ec5a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions