Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I make my GFX-Routine faster? (GFXlib)
#1
Hi,

I've got a Picture, saved in a String, just as a 8-Bit-Bitmap without the header. So 1 Byte stands for one colour.

In QuickBASIC I've used ASM instead, but how can I make this routine faster in FreeBASIC?
Code:
'Putdat$ = The Picture
'px, py = Picture-Position
'endX, endY = Picture-Sizes


dIM framebuffer AS BYTE PTR
   framebuffer = SCREENPTR


   SCREENLOCK
      for y=0 to endY-1
         for x=0 to endX-1
            c=c+1
            f=asc(mid$(putdat$, c, 1))
            if f<>CurrentFilterColor and y+py>CurrentScreenY1-1 and x+px>CurrentScreenX1-1 and y+py<CurrentScreenY2+1 and x+px<CurrentScreenX2+1 then POKE framebuffer + ((py+y) * CurrentScreenWidth) + x+px, f
         next x
      next y
   SCREENUNLOCK

As I'm using POKE, I have to control on my own if the pixel is outside of the Screen or of the current VIEW-area.

I'm using the GFX-lib and I'd be very happy if anyone could help me.

Mecki
he dogs bark, but the caravan keeps moving.
Reply
#2
dude your using a string and string munipulation of cource it going to be slow.

dump the string storage and simple allocate the memorey you want in byte's

i.e. callocate()

load your picture into your newly allocated chunk on memorey and then simple use a byte pointer to the block on memorey and use indexing.

alot less overhead.

also when you poke the data to the screen use an integer i'm gussing your in 8bit color mode so if you poke with intergers you basicly moving 4 pixels at a time
Reply
#3
You can use inline ASM in FB.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#4
Hi ShadowWolf..

..sounds good! - But I've never worked with pointers Sad

Could you perhaps give me some example code?
he dogs bark, but the caravan keeps moving.
Reply
#5
Look in this thread...

http://forum.qbasicnews.com/viewtopic.php?t=8666

It was enough to teach me... and that's really something! :lol:
Reply
#6
Ah yes! It workes much faster now.

But there's another problem: It seems that I have to REDIM my pixel-array or sth., as my program needs more and more RAM during the runtime. (That image-routine is called several times a second)

PS: ..but I already use REDIM
he dogs bark, but the caravan keeps moving.
Reply
#7
Yeah, MID$ is slow, as it returns another string, that must be allocated all the time - the string descriptor too.

I added ASC( s$, pos ) now, and also string indexing (s$[pos]), but you will have to wait for the next reelease, as the current sources can't be built by old versions -- anyways, using byte arrays is the way to go.
Reply
#8
Wow, thaaank you v3cz0r! Great, great great :bounce:
he dogs bark, but the caravan keeps moving.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)