You are here

Is there Python classes for Array of Pixels?

I'm looking for Python code to model a GIMP drawable as a 2D array of Pixels. Where Pixels have properties: color, isSelected, isTransparent. More object oriented than gimp.PixelRgn.

Does such a class exist already? If not, I will keep working on my prototype of it.

I dont know an answer to your question, but I am just curious what are you coding. Is it something unrelated to gimp? Or it will be python plugin for gimp?

Just my opinion - your array would allow 1-4 channels (or in fact third dimension), you must define if there will be some predefined types of images, like RGB (3 channels), RGBA (4 channels), or GREY(1 channel), GREYA(2 channels), or will you allow developer to ad hoc define 4 channels like YUVA or 3 channels image of HSL type.

Another question is color depth, or type of value for single channel - will it be guchar (0-255), or you will allow short int or float, whatever. Will the type be hardcoded (like now in gimp) or custom....

You are not probably going to programm new gimp from scratch, but I was doing it I would first answer these questions...

Thanks.

Yes, for GIMP plugins.

Most plugins don't need access to Pixels, but if you do, there is no model for it in PyGIMP. For example, PixelRgn[] returns a string, not a Pixel. A more abstract model is that a Pixel has a color, which is a sequence of integer values.

Your question points out the need: I want to abstract away the number of channels, and the fact that the alpha channel is tacked on the end (not what I consider a color) and so forth. Also, it would encapsulate that values were 8-bits (guchar for glib C programmers). When that changes, this class might need to be modified, but not plugins that use the class (ideally.)

It uses other's ideas about reading a PixelRgn into a Python array.array. Thats done for speed and simplicity, but speed is not the main issue. The issue is being able to quickly prototype a plugin (that does need pixel access) using an easier object model.

Subscribe to Comments for "Is there Python classes for Array of Pixels?"