473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fast 2D Raster Rendering with GUI

Hi All. I've been formulating in my head a simple image editor. I
actually started prototyping is some time ago in Java, but am liking
Python more and more. My editor will be nowhere near the level of Gimp/
Photoshop, but I do need fast pixel level control and display. For
instance, that means no automatic anti-aliasing and that I will be
implementing my own line drawing algorithms.

I've got the high level architectual aspects of my program down, but
am stuck on what graphics API to use. I want a canvas area of
adjustable size which users can draw on with as little lag as
possible. The canvas area will be composed of layers (i.e. I require
an alpha channel) and I need to be able to zoom in and out of it (zoom
levels will be at fixed intervals, so this can be simulated if need
be.)

I started looking at PyGame but realize that I need to integrate a GUI
into the whole thing (or integrate the image into the GUI rather) and
I didn't see a straightforward way to do that. Of course, I don't even
know if PyGame is the right API for the job anyways :P

Any thoughts or ideas that could help me get started? Thanks!
Mar 18 '08 #1
7 3660
On Mar 18, 4:36 am, dave <man...@gmail.comwrote:
Hi All. I've been formulating in my head a simple image editor. I
actually started prototyping is some time ago in Java, but am liking
Python more and more. My editor will be nowhere near the level of Gimp/
Photoshop, but I do need fast pixel level control and display. For
instance, that means no automatic anti-aliasing and that I will be
implementing my own line drawing algorithms.

I've got the high level architectual aspects of my program down, but
am stuck on what graphics API to use. I want a canvas area of
adjustable size which users can draw on with as little lag as
possible. The canvas area will be composed of layers (i.e. I require
an alpha channel) and I need to be able to zoom in and out of it (zoom
levels will be at fixed intervals, so this can be simulated if need
be.)

I started looking at PyGame but realize that I need to integrate a GUI
into the whole thing (or integrate the image into the GUI rather) and
I didn't see a straightforward way to do that. Of course, I don't even
know if PyGame is the right API for the job anyways :P

Any thoughts or ideas that could help me get started? Thanks!
Look at the PIL source code for reference and implement your own C
extensions for drawing and image manipulation. Or write your app on
top of PIL. Any GUI toolkit will work if you find the low-level access
to their image memory buffers. PyGame is for multimedia applications,
you probably need Tkinter, Qt, wx or GTK.

And as long as you need such low-level things as custom drawing and
anti-aliasing your API is plain old C malloc's, free's and raw memory
addresses.

--
Ivan
Mar 18 '08 #2
Hello Dave,
Hi All. I've been formulating in my head a simple image editor. I
actually started prototyping is some time ago in Java, but am liking
Python more and more. My editor will be nowhere near the level of Gimp/
Photoshop, but I do need fast pixel level control and display. For
instance, that means no automatic anti-aliasing and that I will be
implementing my own line drawing algorithms.

I've got the high level architectual aspects of my program down, but
am stuck on what graphics API to use. I want a canvas area of
adjustable size which users can draw on with as little lag as
possible. The canvas area will be composed of layers (i.e. I require
an alpha channel) and I need to be able to zoom in and out of it (zoom
levels will be at fixed intervals, so this can be simulated if need
be.)

I started looking at PyGame but realize that I need to integrate a GUI
into the whole thing (or integrate the image *into the GUI rather) and
I didn't see a straightforward way to do that. Of course, I don't even
know if PyGame is the right API for the job anyways :P

Any thoughts or ideas that could help me get started? Thanks!
Apart from PIL, some other options are:
1. Most GUI frameworks (wxPython, PyQT, ...) give you a canvas object
you can draw on
2. A bit of an overkill, but you can use PyOpenGL
3. ImageMagick bindings? (http://www.imagemagick.org/script/api.php)

HTH,
--
Miki <mi*********@gmail.com>
http://pythonwise.blogspot.com
Mar 18 '08 #3
Chris Mellon <ar*****@gmail.comwrote:
>OpenGL is totally unsuitable if the goal is to implement your own
pixel-level raster drawing.
Unfornately, any solution involving Python is likely to be unsuitable
if your goal is to set individual pixels one-by-one, and GDI would be no
better than OpenGL here. The overhead of calling some sort of putpixel()
function over and over will domininate everything else.

Ross Ridge

--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rr****@csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
Mar 18 '08 #4
First I want to say thank you all for your timely replies. This is all
good food for thought. I've been programming more many years, but fast
graphics rendering is new territory for me.

I'm hoping to fine something like a buffer_blit, where I can set all
the pixels to change using basic operators, blit them all at once to a
pixel buffer, then swap the visible buffer. Ideally it will only
change the region of the pixel buffer that needs changing.

Because I want layers, I would like to take advantage wherever
possible of the available hardware features. I.E. ideally I am hoping
that the layers can be textures in memory that get composited in
hardware onto the screen. Maybe this is wishful thinking though?

I'm also thinking that maybe I can reduce the number of active layers
from N down to 3 - the active layer, the layers below it, and the
layers above it. Obviously only the active layer needs any sort of
sprite-like animations and it on this layer than response time is most
important. Having to layer the top layers ontop of it may also play a
factor but, as I suggested, I can merge them all together in one time
and then use the merged result to layer on top of the active layer.

I'm a little nervous about going the C/C++ route. It's been a few
years since I used them, I'm new to Python, and jumping into coding
Python extensions with C/C++ is not particularly palatable (though
I'll do it if I have to.)
Any GUI toolkit will work if you find the low-level access
to their image memory buffers.
That's another new step for me. Any ideas where to start? Thanks!
Mar 18 '08 #5
On Mar 19, 2:33 am, dave <man...@gmail.comwrote:
First I want to say thank you all for your timely replies. This is all
good food for thought. I've been programming more many years, but fast
graphics rendering is new territory for me.

I'm hoping to fine something like a buffer_blit, where I can set all
the pixels to change using basic operators, blit them all at once to a
pixel buffer, then swap the visible buffer. Ideally it will only
change the region of the pixel buffer that needs changing.

Because I want layers, I would like to take advantage wherever
possible of the available hardware features. I.E. ideally I am hoping
that the layers can be textures in memory that get composited in
hardware onto the screen. Maybe this is wishful thinking though?

I'm also thinking that maybe I can reduce the number of active layers
from N down to 3 - the active layer, the layers below it, and the
layers above it. Obviously only the active layer needs any sort of
sprite-like animations and it on this layer than response time is most
important. Having to layer the top layers ontop of it may also play a
factor but, as I suggested, I can merge them all together in one time
and then use the merged result to layer on top of the active layer.

I'm a little nervous about going the C/C++ route. It's been a few
years since I used them, I'm new to Python, and jumping into coding
Python extensions with C/C++ is not particularly palatable (though
I'll do it if I have to.)
Any GUI toolkit will work if you find the low-level access
to their image memory buffers.

That's another new step for me. Any ideas where to start? Thanks!
Some reading on fast 2d graphics:
chapters 35-42 from
http://www.byte.com/abrash/

and a lot of great stuff here:
http://tog.acm.org/GraphicsGems/
Mar 18 '08 #6
That's another new step for me. Any ideas where to start?

http://docs.python.org/ext/simpleExample.html

And look into the source of existing extensions. PIL and PyCairo are
the best in your situation.

Mar 18 '08 #7
On Mar 18, 6:51 pm, Ivan Illarionov <ivan.illario...@gmail.comwrote:
That's another new step for me. Any ideas where to start?

http://docs.python.org/ext/simpleExample.html

And look into the source of existing extensions. PIL and PyCairo are
the best in your situation.
You shouldn't be afraid of doing raster graphics in Python; you'll
just need to be familiar with Numpy. You can easily compose layers,
mask out operations to only happen on one channel, etc., and code it
all up in Python while getting C-level speed. The gotcha, if you use
PIL, is that you're going to have to use tostring() and fromstring()
to get the array data back and forth between numpy and PIL. An
alternative is to use openGL, as others have suggested, and blit into
a texture. If you use pyglet, for instance, you can use Andrew
Straw's pygarrayimage module to convert a numpy array directly into a
texture.

I wouldn't recommend Cairo for doing pixel-level ops, since it is a
vector graphics library.
-Peter
Mar 19 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tole | last post by:
hi all, i've got a selcetbox (multiple) which is filled by javascript. only problem is that i have aprox 1000 options to add to that select, and that adding lasts for 5-6 seconds. Even...
7
by: Maxim Shemanarev | last post by:
I'd like to announce my project called Anti-Grain Geometry. http://www.antigrain.com Anti-Grain Geometry (AGG) is an Open Source, free of charge graphic library, written in industrially standard...
1
by: John Tempest | last post by:
Please help. I got no response to my previous query "?Using raster fonts as graphics in dotNet?" posted on 7th July. The principal question remains: How can I (if I can at all) select a raster...
4
by: Nick K. | last post by:
Is there any native ,Net assemblies or open C# source code that can perform vector to raster conversion?
7
by: Dennis Benzinger | last post by:
Hi! Does anybody know of a SVG rendering library for Python? Bye, Dennis
2
by: Spotnick | last post by:
I have no idea why, but since I'm trying to recreate my website using ASP.NET 2.0 I've encountered so many performance issues that I'm about to give up and continue using v1.1 Seriously, how can...
6
dmjpro
by: dmjpro | last post by:
frnds .. i understand that why AJAX is introduced in web-technology and also i am very interested in AJAX..... but one question stil knocking me ... why AJAX is fast than normal request??? ...
4
by: alarock | last post by:
hi, I have performed some drawing using Vector image,DrawRectangle etc... and then i converted to raster Image(bitmap) i found in the zoomed raster image(bitmap) the outer...
7
by: VC | last post by:
Hi I'm working on a web site with hard programming in Javascript. ?This web based application is intended to be used by bank workers who types very fast. The problem is: sometimes they type...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.