with-pixel seems very slow

14 views
Skip to first unread message

Adrien 'Pied Axioplase'

unread,
Dec 31, 2015, 1:18:28 PM12/31/15
to Lispbuilder
Hi,

I'm entertaining the idea of writing a tool to generate pictures using genetic algorithms. Right now, I've implemented a naive hill-climbing algorithm, and my program does the following:
- Load a picture into a target surface
- Loop
-- Generate N candidate pictures from the current best one
-- Render each in a temporary surface
-- Compare pixel-wise the temporary surface wit the target surface to assign a score
-- Blit and display the temporary surface with the best score

What I call a candidate picture is in fact just a list of filled polygons.

I was initially using something like
(with-pixels ((target (fp target-surface))
             
(temp (fp temporary-surface)))
 
(loop for y below height
   sum
(loop for x below width
         sum
(score-pixel target temp x y))))
but it was waaay too slow.
Because the target picture never changes, I decided to read it once, and to store the R, G, and B values directly into a array of dimension (heigth width 3). Yet, the program is still very slow.
I'm wondering whether there's a faster way for me to access the pixels's RGB values of the surface... I'm even considering rendering the surface, saving as an image on disk, and reading the RGB values of the image through another library...

Maybe SDL is not the right tool at all? I used it because I wanted to have access to draw-filled-polygon, and didn't want to reimplement is myself... But I guess I could do everything in memory using no graphic libabry except for rendering at the end...

Cheers,

P!
Reply all
Reply to author
Forward
0 new messages