| 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.
 
 
 |