Blitz+ 2D Alpha Blend

Community Forums/Showcase/Blitz+ 2D Alpha Blend

Snarty(Posted 2004) [#1]
Hi all,

Coded this little thing today. For those who do not have the latest B+ an Exe is included in the zip. Alpha routine is written in C++ and is a dual alpha-channel/alpha-fade command. Alpha channel side needs some finishing touches and will be used with the FreeImage lib.

Anyhow, fps feed-back is what I'm looking for, so grab the zip from...
Alpha Blitz Test

PS: Not really intended for full on real-time effects


Perturbatio(Posted 2004) [#2]
I get 31 fps


Snarty(Posted 2004) [#3]
Cheers for that Perurbatio.

Other results can be found here: BC Results Thread


Baley(Posted 2004) [#4]
It does 12 FPS on my Celeron@1000 laptop (slow machine). Did you try to code the Alpha routine in Blitz directly ? Is it much slower than C++ DLL ?


Snarty(Posted 2004) [#5]
The original was B+ direct, I managed to get a max of 7fps on my machine (15-16fps for c++). So found more than 50% extra speed. Which, is quite a bit. Though, I have some more playing to do yet, and hope to get this faster still.


Baley(Posted 2004) [#6]
I wanted to convert the alpha16() function found in a DLL to Blitz code. Here it is the original C function:

BBDECL int BBCALL alpha16(short buffer1[], int width1, int height1, int pitch1, short buffer2[], int width2, int height2, int pitch2, short buffer3[], int px, int py, int mode, int alpha1)
{
  int alpha2=255-alpha1;
  int offset1;
  int offset2;
  int x;
  int y;

  int rgb1;
  int r1;
  int g1;
  int b1;

  int rgb2;
  int r2;
  int g2;
  int b2;

  int r3;
  int g3;
  int b3;

  int startx=0;
  int starty=0;
  int endx=width2-1;
  int endy=height2-1;

  if (px<0) startx=0-px;
  if (py<0) starty=0-py;
  if (px+width2>width1) endx=width1-px;
  if (py+height2>height1) endy=height1-py;

  pitch1=pitch1/2;
  pitch2=pitch2/2;


  for(y=starty; y<=endy; y++)
  {
    offset1=(y+py)*pitch1+(startx+px)-1;
    offset2=y*pitch2+startx-1;

    for(x=startx; x<=endx; x++)
    {
      offset1++;
      offset2++;

      rgb1=buffer1[offset1];
      r1=((rgb1 >> 11) & 31);
      g1=((rgb1 >> 5) & 63);
      b1=(rgb1 & 31);

      rgb2=buffer2[offset2];
      r2=((rgb2 >> 11) & 31);
      g2=((rgb2 >> 5) & 63);
      b2=(rgb2 & 31);

      r3=(r1*alpha1)/255 + (r2*alpha2)/255;
      g3=(g1*alpha1)/255 + (g2*alpha2)/255;
      b3=(b1*alpha1)/255 + (b2*alpha2)/255;

      if (mode==1)
        buffer3[offset1]=(r3 << 11) + (g3 << 5) + b3;
      else
        buffer3[offset2]=(r3 << 11) + (g3 << 5) + b3;
    };
  };

  return 1;
}


I've translated it to Blitz code, but it doesn't work properly. Do you know what's wrong with this ?

Function balpha16(buffer1,width1,height1,pitch1,buffer2,width2,height2,pitch2,buffer3,px,py,mode,alpha1)
;BBDECL Int BBCALL alpha16(short buffer1[], Int width1, Int height1, Int pitch1, short buffer2[], Int width2, Int height2, Int pitch2, short buffer3[], Int px, Int py, Int mode, Int alpha1)
 alpha2=255-alpha1
 startx=0
 starty=0
 endx=width2-1
 endy=height2-1

 If px<0 Then startx=0-px
 If py<0 Then starty=0-py
 If px+width2>width1 Then endx=width1-px
 If py+height2>height1 Then endy=height1-py

 pitch1=pitch1/2
 pitch2=pitch2/2

 For y=starty To endy

  offset1=(y+py)*pitch1+(startx+px)-1
  offset2=y*pitch2+startx-1

  For x=startx To endx

   offset1=offset1+1
   offset2=offset2+1

   rgb1=PeekShort(buffer1,offset1)
   ;rgb1=buffer1[offset1]

   r1=((rgb1 Shr 11) And 31)
   g1=((rgb1 Shr 5) And 63);
   b1=(rgb1 And 31)

   rgb2=PeekShort(buffer2,offset2)
   ;rgb2=buffer2[offset2];

   r2=((rgb2 Shr 11) And 31)
   g2=((rgb2 Shr 5) And 63)
   b2=(rgb2 And 31)

   r3=(r1*alpha1)/255 + (r2*alpha2)/255
   g3=(g1*alpha1)/255 + (g2*alpha2)/255
   b3=(b1*alpha1)/255 + (b2*alpha2)/255

   If mode=1
    PokeShort(buffer3,offset1,(r3 Shl 11) + (g3 Shl 5) + b3)
    ;buffer3[offset1]=(r3 << 11) + (g3 << 5) + b3;
   Else
    PokeShort(buffer3,offset2,(r3 Shl 11) + (g3 Shl 5) + b3)
    ;buffer3[offset2]=(r3 << 11) + (g3 << 5) + b3;
   EndIf
  Next
 Next

 Return 1
End Function


Thanks for any hint.


Snarty(Posted 2004) [#7]
At a rough guess, it's trying to read/write 565 from an 888 or 8888 buffer. So, you'll need to account for the bit depth change.

I'll have a closer look when I get a few minutes spare.


MrCredo(Posted 2004) [#8]
ah this is my DLL-Source...
but ist should be slow, if you convert this to blitz-code...
DLL ist faster...


Baley(Posted 2004) [#9]
I know, but I wanted to try it in plain Blitz and then in assembly code directly in Blitz.


Snarty(Posted 2004) [#10]
Ok, I have had a play with the function and managed to squeeze another 2fps out of my system.

I have uploaded the new version, so feel free to see if you have gained some speed on your systems.


Filax(Posted 2004) [#11]
I get 54 FPS with Athlon XP 2600 + GEForce 4 TI + WinXP Pro


pantsonhead.com(Posted 2004) [#12]
I get around 36FPS on Intel 2.6/WinXP Pro/RadeonIGP 345M/320MB RAM

BUT when I drag the screenshot off-screen it shoots up to around 76FPS


Jim Teeuwen(Posted 2004) [#13]
14fps here.
spec listed below.


moOch(Posted 2005) [#14]
i get 76 fps :D

PC: Pentium IV, 3.0 Ghz; Geforce 6800 256MB; 1024MB RAM

:)
mfg moOch
(old nickname in title...)


EOF(Posted 2005) [#15]
74FPS on a P4 3Ghz, ATI X600Pro 256Mb system.


Perturbatio(Posted 2005) [#16]
(Posted 1 year ago)


Steve Elliott(Posted 2005) [#17]
LOL - time to lock the thread.


Rck(Posted 2005) [#18]
lock it, its resurfacing, ahhh