Hi all,
I had a concern about the Pyglet image module. Particularly, the
website claims that the development branch of Pyglet is compatible
with Python3... But from what I can see, ImageData.get_data() still
returns "a sequence of bytes, or str". But in Python3 a string is
unicode by default, so one character != one byte. Might it be better
to use the bytearray() type instead? I feel like bytearray() is
probably a better type for this than a string or list, anyway...
I also feel like returning "a sequence of bytes, or str" is hazardous,
since they have somewhat different semantics in any but the most
trivial case (iteration, basically). For instance, while playing
around preparing this post, I discovered the following bug (in the
latest stable, haven't tried tip):
>>> data1 = [1,2,3,4] * 10 * 10
>>> a = pyglet.image.ImageData(10, 10, 'RGBA', data1)
>>> a.get_data('RGBA', 4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/pyglet/image/__init__.py", line 701, in
get_data
return self._convert(format, pitch)
File "/usr/lib/pymodules/python2.7/pyglet/image/__init__.py", line 986, in
_convert
self._ensure_string_data()
File "/usr/lib/pymodules/python2.7/pyglet/image/__init__.py", line 1053, in
_ensure_string_data
memmove(buf, self._current_data, len(self._current_data))
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong type
This was with the latest stable version of pyglet rather than tip, but
is a demonstration of how conflating these types can balls things up,
even internally. Doing `a.set_data('RGBA', 4, data1)` followed by
`a.get_data('RGBA', 4)` works and returns the list, as you would
expect.
I have other issues with the image module... You can't blit_into()
anything but a texture, doing destination.blit_into(source) seems
confusing in terms of argument order, it'd be nice to be able to blit
scaled and rotated images (ie, sprites) into each other, I feel like
trying to shove everything under AbstractImage might not be a great
idea because the different types of images really are quite different
from each other... Generally, composing and manipulating images is
not as easy as it seems like it should be. But in the end those are
nitpicks, while the bytes-as-uniode-string is the only thing that's
really strictly speaking wrong. Pretty much every other part of
Pyglet I've touched has been excellent, so.
Thanks,
Simon
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.