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

ImageInterpolationMode not working with GdipDrawImageRectRect #730

Open
jhergens opened this issue Dec 6, 2021 · 1 comment
Open

ImageInterpolationMode not working with GdipDrawImageRectRect #730

jhergens opened this issue Dec 6, 2021 · 1 comment

Comments

@jhergens
Copy link

jhergens commented Dec 6, 2021

Setting Graphics.ImageInterpolationMode has no effect.

The following code:

var target = new Bitmap(100, 100);
using (var g = Graphics.FromImage(target))
{
    g.Clear(Color.Red);
    g.PixelOffsetMode = PixelOffsetMode.Half;            
    g.InterpolationMode = InterpolationMode.NearestNeighbor;

    var bmp = new Bitmap(2, 2);
    bmp.SetPixel(0, 0, Color.Black);
    bmp.SetPixel(0, 1, Color.White);
    bmp.SetPixel(1, 0, Color.White);
    bmp.SetPixel(1, 1, Color.Black);

    var destRect = new RectangleF(20, 20, 60, 60);
    var srcRect = new RectangleF(0, 0, 2, 2);

    g.DrawImage(bmp, destRect, srcRect, GraphicsUnit.Pixel);
}

Renders like this:
checkers

It is expect to render like this:
checkers_expected

We are building libgdiplus from main.

The problem seems to be at the end of GdipDrawImageRectRect. It creates two surfaces, and sets an interpolation for the first of them. I can't see that that surface is used for anything. Seems to be dead code? For the second surface no interpolation filter is set. The commented out line fixes the issue:

gdip_bitmap_ensure_surface (preprocessed_image);

filter = cairo_pattern_create_for_surface (preprocessed_image->surface);
cairo_pattern_set_filter (filter, gdip_get_cairo_filter (graphics->interpolation));

cairo_matrix_translate (&mat, srcx, srcy);

if (!gdip_near_zero(srcwidth - dstwidth) || !gdip_near_zero(srcheight - dstheight))
    cairo_matrix_scale (&mat, srcwidth / dstwidth, srcheight / dstheight);

cairo_matrix_translate (&mat, -dstx, -dsty);

pattern = cairo_pattern_create_for_surface (preprocessed_image->surface);
// cairo_pattern_set_filter (pattern, gdip_get_cairo_filter (graphics->interpolation));
cairo_pattern_set_matrix (pattern, &mat);
@TalicZealot
Copy link

Experiencing the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants