LockPalette()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

LockPalette()

Post by Fou-Lu »

I've been playing with palettes and I noticed something strange. If I change all the colors of a palette, it can get slower, but if I change all the colors of a palette I'm not using, I can get the same effect faster.

note: my fps aren't that accurate, if someone wants to improve the code it would be great.

First example (using the same palette all the time):

Code: Select all

InitSprite()
InitPalette()
InitKeyboard()

OpenScreen(640,480,8,"")

CreateSprite(0,640,480)
StartDrawing(SpriteOutput(0))
For x=0 To 639
For y=0 To 479
Plot(x,y,Random(255))
Next y
Next x
StopDrawing()

CreatePalette(1)
CreatePalette(0)
DisplayPalette(0)

DisplaySprite(0,0,0):FlipBuffers():DisplaySprite(0,0,0)

Repeat

flow=(flow+1)&255
For n=0 To 255
SetPaletteColor(n,(flow+n)&255)
Next n

time=time+(ElapsedMilliseconds()-oldtime)
frame=frame+1
If time=>1000
framerate=frame:frame=0:time=0
EndIf
StartDrawing(ScreenOutput())
Locate(10,10):DrawText(Str(framerate))
StopDrawing()

ExamineKeyboard()
FlipBuffers()
oldtime=ElapsedMilliseconds()
Until KeyboardPushed(#pb_key_escape)
Second (swaping between two palettes)

Code: Select all

initsprite()
initpalette()
initkeyboard()

openscreen(640,480,8,"")

createsprite(0,640,480)
startdrawing(spriteoutput(0))
for x=0 to 639
for y=0 to 479
plot(x,y,random(255))
next y
next x
stopdrawing()

createpalette(1)
createpalette(0)
displaypalette(0)

Displaysprite(0,0,0):flipbuffers():Displaysprite(0,0,0)

repeat

palette=(palette+1)&1
usepalette(palette)
flow=(flow+1)&255
for n=0 to 255
setpalettecolor(n,(flow+n)&255)
next n
displaypalette(palette)

time=time+(ElapsedMilliseconds()-oldtime)
frame=frame+1
If time=>1000
framerate=frame:frame=0:time=0
EndIf
StartDrawing(ScreenOutput())
Locate(10,10):DrawText(Str(framerate))
StopDrawing()

examinekeyboard()
flipbuffers()
oldtime=ElapsedMilliseconds()
until keyboardpushed(#pb_key_escape)
Then I wondered, it would be possible to lock a palette, so that it wouldn't update its colors whenever you use SetPaletteColor() with the current palette:

LockPalette(#Palette)

...do all changes

UnlockPalette()

It would be very useful. :wink:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: LockPalette()

Post by va!n »

its all nice but i really think 256 color screen days are out! I would like to see stuff in 16 or 32 bit instead 256 colors only (else i can go and use my a1200 again ;-)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

And even, using a non displayed palette is the way to go then.
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

C'mon Fred it can't be that hard! My example works ok, but it seems a hack, and it's annoying. I know most people hate 256 color screen, but I like it! :oops:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Now I see, I didn't mention yet: My example with the two palettes doesn't work for any situation.

It gets faster if you change all 256 colors at once, but if you want to change, say, 16 colors, it will be slower because you need to copy the whole palette to the one you are not using and then change them again, which is slower than changing all 16 colors in the palette that is being displayed. :)

Please Fred, say you will at least think about that. LockPalette() would make it easier and faster to change palette colors. ChangeGamma() works like that, why not with the palettes? :wink:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
Post Reply