PDA

Click to See Complete Forum and Search --> : Alphablending DLL


DamnedMoose
Dec 12th, 2001, 10:18 PM
...Hey all,

I've been experimenting with ASM in C++, but whenever I use it in my DLL, I can't call any of the functions in the DLL :P

Here's the source


#include <windows.h>

#ifndef _RWSTD_NO_NAMESPACE
using namespace std;
#endif

extern "C" {
INT CALLBACK _export ColorBlend(LONG BlendColor, HBITMAP BitmapHandle);
}

int LibMain()
{
return 1;
}

INT CALLBACK _export ColorBlend(LONG BlendColor, HBITMAP BitmapHandle)
{
BYTE rBit; BYTE gBit; BYTE bBit;
BYTE* Bits = NULL;

rBit = RedOf(BlendColor);
gBit = GreenOf(BlendColor);
bBit = BlueOf(BlendColor);

Bits = new BYTE[32*32*3];
GetBitmapBits(BitmapHandle, 32*32*3, Bits);

_asm
{
mov esi,Bits
mov ecx,32*32
mov ah,0
mov dh,0

@MixColors:
mov al,[esi]
mov dl,rBit
add ax,dx
sar ax,1
mov [esi],al

mov al,[esi+1]
mov dl,gBit
add ax,dx
sar ax,1
mov [esi+1],al

mov al,[esi+2]
mov dl,bBit
add ax,dx
sar ax,1
mov [esi+2],al

add esi,3
; add ecx,-1 - Taken out thanks to Kedaman's advice (i forgot loop auto-decreases ecx...
loop @MixColors
}

SetBitmapBits(BitmapHandle, 32*32*3, Bits);

delete(Bits);
return 1;
}


I also have a feeling the ASM is wrong (it should stop looping when ecx = 0...) Help please? :)

Oh, and RedOf, GreenOf, BlueOf functions I use:


BYTE RedOf(LONG inColor)
{
return (byte)(inColor & 255);
}


BYTE GreenOf(LONG inColor)
{
return (byte)((inColor >> 8) & 255);
}


BYTE BlueOf(LONG inColor)
{
return (byte)(inColor >> 16);
}


Thanks alot! Also, if any of the code is wrong for Alphablending a picture with BlendColor by 50%, please can someone correct it??

kedaman
Dec 12th, 2001, 10:39 PM
add ecx,-1
loop @MixColors

I think loop decrement ecx automatically, dunno though, never coded asm.

CornedBee
Dec 13th, 2001, 10:06 AM
Have you the extern "C" also in the header you include in your app?

parksie
Dec 13th, 2001, 11:07 AM
What's the deal with _export and LibMain? I thought both of those were obsolete?

CornedBee
Dec 14th, 2001, 06:44 AM
True. It is DllMain and _declspec(dllexport) now.

parksie
Dec 14th, 2001, 12:40 PM
From looking closer, it appears that _export is happily used by Borland, which is what they're using (further to the MSN conversation).

DllMain is definitely replacing LibMain, though...however __declspec(anything) is MSVC specific.

As a guide, if it has more than two preceding underscores, it's a compiler specific thing.