Coder Social home page Coder Social logo

Comments (5)

baryluk avatar baryluk commented on June 2, 2024

Update: Yes, it looks like sRGB issue, either with PIL, with aggdraw, or with the PNG writer in PIL.

I added this piece of code at the end:

from PIL.ImageCms import buildTransform, applyTransform
# SRGB_PROFILE = 'sRGB.icc'
SRGB_PROFILE = '/usr/share/color/icc/sRGB.icc'
LINEARIZED_PROFILE = 'linearized-sRGB.icc'
LINEARIZED_TO_SRGB = buildTransform(LINEARIZED_PROFILE, SRGB_PROFILE, 'RGB', 'RGB')
img = applyTransform(img, LINEARIZED_TO_SRGB)
img.save("dump2.png")

The color profile icc file I got from: python-pillow/Pillow#1604 (comment) based on this post: https://stackoverflow.com/questions/31300865/srgb-aware-image-resize-in-pillow/46613620#46613620

And the result looks much better:

dump2

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

Wow, nice examples. Thanks for reporting this.

Could you do a couple things for me?

  1. Could you make a simple example script that includes all the data (x/y locations) needs to reproduce an image that shows this problem? That way I can test it locally.

  2. Could you try this with installing from the current aggdraw master branch? You should be able to do pip install git+https://github.com/pytroll/aggdraw.git. Note that there are other issues we've discovered in the master branch that are being talked about in other issues/PRs so results may not be perfect.

I'm not sure there is much aggdraw, the python package, can do to resolve this unless it is specifically a bug of aggdraw improperly passing things between python and C. Aggdraw depends almost entirely on the antigrain (agg) C library. We keep a copy of it alongside aggdraw in this repository, but it is coming from another group. The reason I asked about you using the master branch is that we are working on switching to agg 2.4 (I think that's the version, can't remember offhand) which had a lot of changes done from the previous versions we used.

If the master branch gives you "better" results then this must be an agg C problem. If not, then it could still be an agg problem or a PIL problem as you've deduced already.

from aggdraw.

baryluk avatar baryluk commented on June 2, 2024

A full script to reproduce the issue in the attachment:

agg-lines-issue.tar.gz

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

I'm pretty swamped this month, but might have time to look at this this weekend. @baryluk Did you have time to try the master branch and compare it?

Edit: And of course, thank you for putting together this example code and images.

from aggdraw.

baryluk avatar baryluk commented on June 2, 2024

Tested the master branch at commit 6c1cf87 , and confirmed the code is using the locally compiled version.

Same results.

It looks the issue is that the PIL doesn't really understand color spaces, nor the image metadata carry this information. If the PIL supported 16-bit per channel, or multi channel f32 formats, that would be less of an issue.

I did modify aggdraw.cxx line 407 , in the method draw_adaptor::setantialias I did this:

    void setantialias(bool flag)
    {
        if (flag) {
            // rasterizer.gamma(agg::gamma_power(1.0/2.4));
            rasterizer.gamma(&agg::linear_to_sRGB);
        } else
            rasterizer.gamma(agg::gamma_threshold(0.5));
    };

Instead of using rasterizer.gamma(agg::gamma_linear());, and this works and fixes the issue.

from aggdraw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.