Hi again,
I was curious to see if I would be able to make small images to be used for paintbrushes in a paint program that I have in mind. It's straight forward to make an image with a 2D painter, but wanted to try to dynamically make all kinds of "paint brushes", so that I do not have hundreds of brush images to clutter the place.
Background:
I wrote a little program that uses SPRITE2MEM and MEM2SPRITE just to see how things would work, since the documentation warns that GETPIXEL can be very slow. The program uses a linear-move (linear-swap without comparing) concept to play around with the pixels. It's a very crude program, but it's the speed of the program that has me a little concerned. The idea is to use a paintbrush image and mix it with a different image on another "screen/buffer" in order to get all sorts of fun filter brush effects.
// --------------------------------- //
// Project: spritememToy
// --------------------------------- //
LOCAL pxl%[]
LOCAL res
LOCAL w
LOCAL h
LOCAL x
LOCAL y
LOCAL sw
LOCAL sh
LOCAL barrel%
LOCAL i
LOCAL offs1, offs2
LOADSPRITE "prettyImage.png",0
GETSPRITESIZE 0,w,h
GETSCREENSIZE sw,sh
res = SPRITE2MEM(pxl%[], 0)
WHILE 1
FOR y = 0 TO h-1
FOR i = 0 TO w-1
offs1 = (w/2 + i) + (y*h)
offs2 = (w/2 + i+1) +(y*h)
barrel% = pxl%[offs1]
pxl%[offs1] = pxl%[offs2]
pxl%[offs2] = barrel%
NEXT
MEM2SPRITE (pxl%[], 0, w, h)
NEXT
DRAWSPRITE 0, sw/2-w/2, sh/2-h/2
PRINT w+" "+h, 10,10
SHOWSCREEN
WEND
Question:
There are nothing wrong with the MEM functions, but they may be too slow for what I have in mind. Are MEM functions the fastest way to manipulate pixels in an image, or is there a faster way? I could go the INLINE route, but then it moves out of the realm of what I want to teach the kids in my computer lessons. I hope there is a solution, else I may have to leave out this fun little exercise in my course.
My program itself may also be the problem, and it is perhaps just too crude for the mission.
Edit: I've included the image I used for my tests.
[attachment deleted by admin]