Board index » delphi » bgi transparent putimage

bgi transparent putimage

Hey All,
 I am looking for a procedure that will do a transparent putimage in BGI's
VGA640*480*16color mode.  I know BGI sucks but it works for what i need
except for the putimage command.  I would appreciate it!  Thanks

Jeff Clement
cleme...@cadvision.com

 

Re:bgi transparent putimage


In <01bb3f4c.9f23ab80$680132cc@clements>, |\|\arauder <cleme...@cadvision.com> writes:

Quote
>Hey All,
> I am looking for a procedure that will do a transparent putimage in BGI's
>VGA640*480*16color mode.  I know BGI sucks but it works for what i need
>except for the putimage command.  I would appreciate it!  Thanks

>Jeff Clement
>cleme...@cadvision.com

This is actual a pain in the {*word*82}in 16 colour mode and I never optimized
it but here are three routines which you can reduce down, one converts
4 plane mode out to packed pixel mode (1 Byte 1 Pixel), a transparent
combine and then a packed pixel back to 4 plane

{=FourPlaneToPackedPixel=============================================
Converts an EGAVGA four plane image to a packed pixel image which is
used by almost all the image support routines in the other units. This
was done this way because I was not willing to compromise the speed
of the other routines just because someone wanted to run in EGAVGA
mode with it's horrible four plane mode.
01May96 LdB
=====================================================================}
PROCEDURE FourPlaneToPackedPixel (Var Source, Dest; Width, Height: Word);
ASSEMBLER;
ASM
   CLD;                                               { Bytes go forward }
   PUSH DS;
   LDS SI, Source;                                    { Image source }
   LES DI, Dest;                                      { Image dest }
   MOV CX, Width;                                     { Image width }
   SHR CX, 3;
   MOV DX, CX;                                        { Four plane width }
@@HeightLoop2:
   MOV AX, Height;                                    { Load height }
   OR AX, AX;
   JZ @@Exit2;                                        { have we finished }
   PUSH SI;
   MOV AH, 80H;
   MOV CX, Width;                                     { Image width }
@@Loop2:
   XOR AL, AL;
   MOV BX, SI;                                        { Initial position }
   TEST DS:[BX], AH;
   JZ @@GreyNotSet2;                                  { Check if grey set }
   OR AL, 08H;                                        { Set grey bit }
@@GreyNotSet2:
   ADD BX, DX;
   TEST DS:[BX], AH;                                  { Check if red set }
   JZ @@RedNotSet2;
   OR AL, 04H;                                        { Set red bit }
@@RedNotSet2:
   ADD BX, DX;
   TEST DS:[BX], AH;                                  { Check if green set }
   JZ @@GreenNotSet2;
   OR AL, 02H;                                        { Set green bit }
@@GreenNotSet2:
   ADD BX, DX;
   TEST DS:[BX], AH;                                  { Check if blue set }
   JZ @@BlueNotSet2;
   OR AL, 01;                                         { Set blue bit }
@@BlueNotSet2:
   SHR AH, 1;                                         { Shift bit }
   OR AH, AH;
   JNZ @@Okay2;
   MOV AH, 80H;                                       { Reload bit }
   INC SI;
@@Okay2:
   STOSB;                                             { Write pack pixel }
   LOOP @@Loop2;
   POP SI;
   MOV AX, DX;                                        { Load width }
   SHL AX, 2;
   ADD SI, AX;                                        { New address }
   DEC Height;
   JMP @@HeightLoop2;                                 { Reloop until done }
@@Exit2:
   POP DS;                                            { Recover segment }
END;

{=MakeTransparentImage===============================================
Copies the source image to the destination image with the rules that
any no zero byte in the source is transferred while any zero byte is
left the same in the destination. Used to mask mouse onto screen but
can be useful for more general sprite graphics routines. Both sources
are assumed to be in normal packed pixel arrays.
30Apr96 LdB
=====================================================================}
PROCEDURE MakeTransparentImage (Var Source, Dest; Count: Word); ASSEMBLER;
ASM
   CLD;                                               { Go forward }
   PUSH DS;
   LDS SI, Source;                                    { Load pointers }
   LES DI, Dest;
   MOV CX, Count;                                     { Load count }
@@Loop:
   LODSB;                                             { Load byte }
   OR AL, AL;
   JNZ @@NotClear;                                    { See if trans byte }
   MOV AL, ES:[DI];
@@NotClear:
   STOSB;                                             { Write the byte }
   LOOP @@Loop;
   POP DS;                                            { Recover register }
END;

{=PackedPixelToFourPlane=============================================
Converts a packed pixel image to an EGVGA four plane image for use
with putimage within EGAVGA.BGI. It is the callers responsiblity
to ensure that destination is large enough to accomodate the output
image data.
01May96 LdB
=====================================================================}
PROCEDURE PackedPixelToFourPlane (Var Source, Dest; Width, Height: Word);
ASSEMBLER;
ASM
   CLD;                                               { Bytes go forward }
   PUSH DS;
   LDS SI, Source;                                    { Image source }
   LES DI, Dest;                                      { Image dest }
   MOV CX, Width;                                     { Image width }
   SHR CX, 3;
   MOV DX, CX;                                        { Four plane width }
@@HeightLoop1:
   MOV AX, Height;                                    { Load height }
   OR AX, AX;
   JZ @@Exit1;                                         { have we finished }
   PUSH DI;
   XOR AX, AX;                                        { Clear each plane }
   MOV CX, Width;
{$IFDEF CPU386+}                                      { 386+ CPU CODE }
   MOV BX, CX;                                        { Transfer bytes }
   AND BX, 0003H;                                     { Cleave odd bytes }
   SHR CX, 2;                                         { Double word count }
   DB 66H; REPNZ STOSW;                               { Write double words }
   MOV CX, BX;                                        { Transfer odd bytes }
   REPNZ STOSB;                                       { Write odd bytes }
{$ELSE}                                               { 286 CPU CODE }
   SHR CX, 1;                                         { Word count }
   REPNZ STOSW;                                       { Write word data }
   ADC CX, CX;                                        { Calc odd byte }
   REPNZ STOSB;                                       { Write odd bytes }
{$ENDIF}
   POP DI;                                            { Reset DI }
   PUSH DI;
   MOV AH, 80H;
   MOV CX, Width;                                     { Image width }
@@Loop1:
   LODSB;                                             { Load image byte }
   MOV BX, DI;
   CMP AL, 8H;                                        { Check grey needed }
   JB @@GreyNotSet1;
   OR ES:[BX], AH;                                    { Set grey bit }
@@GreyNotSet1:
   AND AL, 07H;                                       { Clear bits }
   ADD BX, DX;
   CMP AL, 4H;                                        { Check red needed }
   JB @@RedNotSet1;
   OR ES:[BX], AH;                                    { Set red bit }
@@RedNotSet1:
   AND AL, 03H;                                       { Clear bits }
   ADD BX, DX;
   CMP AL, 2H;                                        { Check green needed }
   JB @@GreenNotSet1;
   OR ES:[BX], AH;                                    { Set green bit }
@@GreenNotSet1:
   AND AL, 1H;                                        { Clear bits }
   ADD BX, DX;
   CMP AL, 1H;                                        { Check blue needed }
   JB @@BlueNotSet1;
   OR ES:[BX], AH;                                    { Set blue bit }
@@BlueNotSet1:
   SHR AH, 1;                                         { Shift bit }
   OR AH, AH;
   JNZ @@Okay1;
   MOV AH, 80H;                                       { Reload bit }
   INC DI;
@@Okay1:
   LOOP @@Loop1;                                      { Loop byte times }
   POP DI;
   MOV AX, DX;                                        { Load width }
   SHL AX, 2;
   ADD DI, AX;                                        { New address }
   DEC Height;
   JMP @@HeightLoop1;
@@Exit1:
   POP DS;                                            { Recover segment }
END;

Re:bgi transparent putimage


Quote
||arauder wrote:

> Hey All,
>  I am looking for a procedure that will do a transparent putimage in BGI's
> VGA640*480*16color mode.  I know BGI sucks but it works for what i need
> except for the putimage command.  I would appreciate it!  Thanks

> Jeff Clement
> cleme...@cadvision.com

putimage in pascal will do what your looking for I believe.  If you use
the XOR_PUT image operator when you put the image on the screen.  I have
got the effect of a transparent mouse cursor.  It takes a little bit
more than just putting an image though, but this should give you the
idea.  If not let me know!

        ==>  PutImage( 0, 0, 100, 100, ^bitmap, XOR_PUT);
Where the ^bitmap is the pointer to the image your trying to put on the
screen.

Re:bgi transparent putimage


In <31992620.6...@gate.net>, Ben Stahlhood <ideag...@gate.net> writes:

Quote
>||arauder wrote:

>> Hey All,
>>  I am looking for a procedure that will do a transparent putimage in BGI's
>> VGA640*480*16color mode.  I know BGI sucks but it works for what i need
>> except for the putimage command.  I would appreciate it!  Thanks

>> Jeff Clement
>> cleme...@cadvision.com

>putimage in pascal will do what your looking for I believe.  If you use
>the XOR_PUT image operator when you put the image on the screen.  I have
>got the effect of a transparent mouse cursor.  It takes a little bit
>more than just putting an image though, but this should give you the
>idea.  If not let me know!

>    ==>  PutImage( 0, 0, 100, 100, ^bitmap, XOR_PUT);
>Where the ^bitmap is the pointer to the image your trying to put on the
>screen.

That wont work an XOR_PUT twice will remove itself from the screen replacing
the original but the colour on screen is problematic for instance

 Blue (1=0001 Binary ) XOR Yellow (14 =1110 Binary) =  White (15=1111 Binary)

Other Threads