Coder Social home page Coder Social logo

Blank output image (v1.3) about aggdraw HOT 12 CLOSED

pytroll avatar pytroll commented on June 2, 2024
Blank output image (v1.3)

from aggdraw.

Comments (12)

djhoese avatar djhoese commented on June 2, 2024

What version of python and what operating system? Thanks.

from aggdraw.

bhbr avatar bhbr commented on June 2, 2024

python 2.7.14 on macOS Sierra

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

With the old version of aggdraw is this what the result looked like for you (this is Python 3.6, OSX High Sierra):

image

from aggdraw.

bhbr avatar bhbr commented on June 2, 2024

Yes.
I'll see if the issue persists with Python 3. If not, all the more reason to migrate

from aggdraw.

bhbr avatar bhbr commented on June 2, 2024

The bug does not appear with Python 3.6.

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

What if you don't use any alpha (RGB instead of RGBA) when running it in python 2? I've been told by more experienced users (I just maintain the code) that aggdraw has always had less than ideal handling of alpha.

from aggdraw.

bhbr avatar bhbr commented on June 2, 2024

Without alpha (I presume you mean making the array MxNx3 and mode = "RGB") the bug appears with both Python 2 and 3.

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

@bhbr I'm just now reviewing this code and I'm a little confused by what is happening. The way you are creating a Draw object, flushing it, then using the original pixel_array to make a new image, is this advertised/accepted behavior for aggdraw? Is the expectation that pixel_array will get written to in-place through the Image object? Or am I looking at this too early in the morning and misunderstanding something?

from aggdraw.

burlito avatar burlito commented on June 2, 2024

Hi,

I just hit on this bug while trying https://github.com/3b1b/manim. I bisected library and it looks like it's because of commit 1832993, I did also try your reproducer with and without commit and it seems to be hitting same thing.

I hope it helped.

from aggdraw.

burlito avatar burlito commented on June 2, 2024

So what I think is happening is:

in static agg::rgba8 getcolor(PyObject* color, int opacity) https://github.com/pytroll/aggdraw/blob/master/aggdraw.cxx#L896

in if statement PyBytes_Check(color) was changed to PyUnicode_Check(color) which is false in situations where PyBytes_Check was true.

next even if you skip that PyObject* ascii_color = PyUnicode_AsASCIIString(color); will always give you NULL.

I don't think PyUnicode_Check and PyUnicode_AsASCIIString are used corectly in that file

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

Awesome @burlito thanks for the help. I agree it looks like I screwed up the python 2 support. There should be a second else if statement to check for the bytes.

For your second point, what do you mean PyUnicode_AsASCIIString will always return NULL? In both python 2 and 3 that should convert a unicode object to an ascii string if it can be converted (https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsASCIIString). As mentioned the code should have another if statement for bytes and then run PyBytes_AsString(color). You are right that the PyUnicode_AsASCIIString will always return NULL for a bytes object (if it doesn't crash), but that function shouldn't be called in that case.

I'll see if I can find time to test this later.

from aggdraw.

djhoese avatar djhoese commented on June 2, 2024

I have this fixed locally, but it seems a test is failing on python 2 now and I can't get it to pass even after removing my changes. This should be fun.

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.