03-29-2005, 11:48 PM
I'v made a sub for copying a 320x240-16bit buffer to a 640x480-16bit screen. I want to use the 320x240x16 screen mode, but the mode is not supported any all computers, so I need a backup plan
I'v tried to optimize it, but its to slow. Can somebody help me speed it up?
This code is made for the sdl lib, but I havent changed it to work with gfxlib(wich I'm gonna use)
I'v tried to optimize it, but its to slow. Can somebody help me speed it up?
This code is made for the sdl lib, but I havent changed it to work with gfxlib(wich I'm gonna use)
Code:
'buffer and video are Dim'ed as SDL_Surface ptr'rs
sub xCopyBuffer
dim srcOfset as unsigned integer, srcPixel as ushort ptr
dim dstOfset1 as unsigned integer, dstOfset2 as unsigned integer
dim dstPixel as unsigned integer ptr
dim x as integer, y as integer, doublepixel as unsigned integer
srcOfset = 0
dstOfset1 = 0
dstOfset2 = video->pitch
SDL_LockSurface(video)
for y = 0 to 239
for x = 0 to 639 step 2
srcPixel = buffer->pixels + SrcOfset + x
doublepixel = *srcPixel
doublepixel = doublepixel shl 16
doublepixel = doublepixel or *srcPixel
dstPixel = video->pixels + DstOfset1 + (x*2)
*dstPixel = doublepixel
dstPixel = video->pixels + DstOfset2 + (x*2)
*dstPixel = doublepixel
next
srcOfset = srcOfset + buffer->pitch
dstOfset1 = dstOfset1 + (video->pitch*2)
dstOfset2 = dstOfset2 + (video->pitch*2)
next
SDL_UnlockSurface(video)
SDL_Updaterect Video,0,0,0,0
end sub