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

The value in the coordinates list cannot exceed 32767. #84

Open
zhanbao2000 opened this issue Jul 7, 2022 · 1 comment
Open

The value in the coordinates list cannot exceed 32767. #84

zhanbao2000 opened this issue Jul 7, 2022 · 1 comment

Comments

@zhanbao2000
Copy link

zhanbao2000 commented Jul 7, 2022

In my project, I need to draw an image with a large size. But when I used the line method, I found that some lines could not be drawn. After testing, I found that if the value of coordinate of a point in the list of coordinates (both horizontal and vertical) exceeds 32767, then the line method will not draw the line, while Pillow does.

I have used the following code for testing.

from aggdraw import Draw, Pen
from PIL import Image, ImageDraw

im = Image.new('RGB', (40000, 1000), 'white')

# No problem when using Pillow, which draws a horizontal bar up to 40000 pixels long.
draw = ImageDraw.Draw(im)
draw.line((0, 250, 40000, 250), fill='red', width=500)

# This line cannot be drawn unless I change this value to 32767 or less.
draw2 = Draw(im)
pen = Pen(color=(0, 0, 255), width=500)
draw2.line((0, 750, 32768, 750), pen)
draw2.flush()

im.show()

In addition, this problem occurs in other methods that require a list of coordinates to be entered (such as path).

  • Windows 10
  • Python: 3.10
  • Pillow: 9.1.1
  • aggdraw: 1.3.15
@djhoese
Copy link
Member

djhoese commented Jul 7, 2022

So 32767 is the maximum value of a 16-bit signed integer. As far as I can tell all the path information for creating a line is stored in this class from the agg C++ library:

https://github.com/pytroll/aggdraw/blob/maint/1.3/agg2/include/agg_path_storage.h

As far as I can tell this class uses unsigned which is a 16-bit unsigned integer and it only does that for number of vertices (as far as I can tell) not the value of the vertex coordinates. So I'm not really sure where the 16-bit limit is happening.

Either way, I'm afraid that unless this can be tracked down to something in aggdraw.cxx, this is likely a major limitation of the agg C++ library and would require essentially rewriting portions of agg. I can't say for sure what would need to be changed as I haven't tracked down where this limit is happening. Note that the current version of agg in the main branch is newer than the version in the maint/1.3 branch and main has not had a public release yet.

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