Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Bitmaps

magamanmagaman Posts: 14Member
I would like to know the source code on how to call bitmaps images in a program and print it to the screen.



TMM

Comments

  • Phat NatPhat Nat Posts: 757Member
    : I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
    :
    :
    :
    : TMM
    :


    Just wrote about this. Try the link below:

    http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=302690&Setting=A9999F0001

    This shows for 8-bit, but the higher ones just don't have a palette usually (although they can I believe).
    Also, I posted a unit to show bitmaps here that I wrote. Not perfect, but a good start.

    http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=300751&Setting=A9999F0003

    Enjoy,
    Phat Nat

  • Phat NatPhat Nat Posts: 757Member
    : : I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
    : :
    : :
    : :
    : : TMM
    : :
    :
    :
    : Just wrote about this. Try the link below:
    :
    : http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=302690&Setting=A9999F0001
    :
    : This shows for 8-bit, but the higher ones just don't have a palette usually (although they can I believe).
    : Also, I posted a unit to show bitmaps here that I wrote. Not perfect, but a good start.
    :
    : http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=300751&Setting=A9999F0003
    :
    : Enjoy,
    : Phat Nat

    I was just writing a game that used my bitmap unit and it worked great until I loaded about 5 bitmaps, then it crashed/gave divide by zero errors & other unexpected results. Turns out I have a mistake in my unit (UNBELIEVABLE!). Anyways, if you're going to use it it has this fix:

    [code]

    With Info.BMPHeader Do
    If (Bits = 8) Then
    Begin
    [b]{ BlockRead(F, Colors[X], PalCount*4);}
    { This should be: }
    BlockRead(F, Colors[0], PalCount*4);
    [/b]

    For X := 0 to PalCount Do
    Begin
    If DoColors Then SetPal(X, Colors[X,3]*63 DIV 255, Colors[X,2]*63 DIV 255, Colors[X,1]*63 DIV 255);
    End;
    Reset(F,1);
    BlockRead(F, Junk, BitMapOffset);
    Z := (Width*Bits) SHR 3;
    While Z MOD(4) <> 0 Do Inc(Z);
    For Y := Height-1 downto 0 Do
    [/code]

    Nothing like loading data into a random spot in memory to crash a program ;)

    Enjoy,
    Phat Nat
  • magamanmagaman Posts: 14Member
    : : : I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
    : : :
    : : :
    : : :
    : : : TMM
    : : :
    : :
    : :
    : : Just wrote about this. Try the link below:
    : :
    : : http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=302690&Setting=A9999F0001
    : :
    : : This shows for 8-bit, but the higher ones just don't have a palette usually (although they can I believe).
    : : Also, I posted a unit to show bitmaps here that I wrote. Not perfect, but a good start.
    : :
    : : http://www.programmersheaven.com/c/msgboard/read.asp?Board=16&MsgID=300751&Setting=A9999F0003
    : :
    : : Enjoy,
    : : Phat Nat
    :
    : I was just writing a game that used my bitmap unit and it worked great until I loaded about 5 bitmaps, then it crashed/gave divide by zero errors & other unexpected results. Turns out I have a mistake in my unit (UNBELIEVABLE!). Anyways, if you're going to use it it has this fix:
    :
    : [code]
    :
    : With Info.BMPHeader Do
    : If (Bits = 8) Then
    : Begin
    : [b]{ BlockRead(F, Colors[X], PalCount*4);}
    : { This should be: }
    : BlockRead(F, Colors[0], PalCount*4);
    : [/b]
    :
    : For X := 0 to PalCount Do
    : Begin
    : If DoColors Then SetPal(X, Colors[X,3]*63 DIV 255, Colors[X,2]*63 DIV 255, Colors[X,1]*63 DIV 255);
    : End;
    : Reset(F,1);
    : BlockRead(F, Junk, BitMapOffset);
    : Z := (Width*Bits) SHR 3;
    : While Z MOD(4) <> 0 Do Inc(Z);
    : For Y := Height-1 downto 0 Do
    : [/code]
    :
    : Nothing like loading data into a random spot in memory to crash a program ;)
    :
    : Enjoy,
    : Phat Nat
    :
    thx
    and can u tell me like the commands to call the bitmaps in the program
    a demo program will be fine.
    thx

    TMM
  • Phat NatPhat Nat Posts: 757Member
    [b][red]This message was edited by Phat Nat at 2005-6-16 18:25:40[/red][/b][hr]
    : I would like to know the source code on how to call bitmaps images in a program and print it to the screen.
    :
    :
    :
    : TMM


    Well, since eyou have that figured out, I'm gonna post some Virtual Screen Routines. This will allow you up to 10 Virtual Screens (Although memory probably won't!). Usually you only need 1-3 anyways.
    Remember to Save the Code below as VSCREENS.PAS or change the unit name to match the file name.

    [code]
    UNIT VScreens;

    INTERFACE

    { Wait for the Monitor Beam to reach the top of the screen }
    PROCEDURE WaitRetrace;
    { Clears the Chosen Video Screen to the given color }
    PROCEDURE CLRVID(Where : Word;Color : Byte);
    { Tries to allocate "NumPages" Virtual Screens. Returns actual # allocated }
    FUNCTION GetVideoPages(NumPages : Byte) : Byte;
    { Used at the end of the program to free the Virtual Screen Memory }
    PROCEDURE DisposeVideoPages;
    { Copies the Video Page from "Source" to "Dest" }
    PROCEDURE CopyPage(Source,Dest : Word);

    TYPE
    VPage = Array[0..63999] Of Byte;
    VPagePtr = ^VPage;

    VAR
    VirScr : Array[1..10] Of VPagePtr;
    VAddr : Array[1..10] Of Word;

    IMPLEMENTATION

    VAR
    NumVidPages : Byte;

    PROCEDURE WaitRetrace; Assembler;
    ASM
    Mov dx,3DAh
    @l1:
    In al,dx
    And al,08h
    Jnz @l1
    @l2:
    In al,dx
    And al,08h
    Jz @l2
    END;

    PROCEDURE CLRVID; Assembler;
    ASM
    Mov Di, Where
    Mov Es, Di
    Xor Di, Di
    Mov Al, Color
    Mov Ah, Al
    Mov Cx, 32000
    REP STOSW
    END;

    FUNCTION GetVideoPages;
    Begin
    NumVidPages := 0;
    While (NumPages > 0) and (MaxAvail > 64000) Do
    Begin
    Inc(NumVidPages);
    Dec(NumPages);
    New(VirScr[NumVidPages]);
    VAddr[NumVidPages] := Seg(VirScr[NumVidPages]^);
    End;
    GetVideoPages := NumVidPages;
    End;

    PROCEDURE DisposeVideoPages;
    Begin
    While NumVidPages > 0 Do
    Begin
    Dispose(VirScr[NumVidPages]);
    Dec(NumVidPages);
    End;
    End;

    PROCEDURE CopyPage; Assembler;
    ASM
    Push Ds
    Cld
    Mov Si, Source
    Mov Ds, Si
    Xor Si, Si
    Mov Di, Dest
    Mov Es, Di
    Xor Di, Di
    Mov Cx, 32000
    @Transfer:
    LODSW
    STOSW
    Loop @Transfer
    Pop Ds
    END;

    Begin
    End.
    [/code]

    These are fairly fast routines for Virtual Screens. I've used them for a long time, so now you can enjoy too. Hmmm, just looking at my code, I think I could've made a faster CopyPage() Procedure. Here's a faster one (uses 32-bit copy instead of 16-bit copy):

    [code]
    PROCEDURE CopyPage; Assembler;
    ASM
    Push Ds
    Cld
    Mov Si, Source
    Mov Ds, Si
    Xor Si, Si
    Mov Di, Dest
    Mov Es, Di
    Xor Di, Di
    [b] Mov Cx, 16000[/b]
    @Transfer:
    [b] db $66[/b]
    LODSW
    [b] db $66[/b]
    STOSW
    Loop @Transfer
    Pop Ds
    END;
    [/code]

    >NOTE<
    Just ran a test. On my computer 60,000 VScreen Copies takes 7.9 sec with the first procedure and only 4.1 sec with the new one. sweet.
    >NOTE<


    A Simple program that uses them would look like this:
    [code]
    PROGRAM TestScreens;
    USES Crt, VScreens;

    CONST
    VGA = $A000;

    VAR
    X : Byte;

    PROCEDURE DrawBox(X,Y : Word; Size, Color : Byte; Where : Word);
    VAR
    X1,Y1 : Byte;
    Begin
    For Y1 := 0 to Size-1 Do
    For X1 := 0 to Size-1 Do
    Mem[Where:X+X1+(Y+Y1)*320] := Color
    End;

    Begin
    If GetVideoPages(1) <> 1 Then { Get Memory }
    Begin
    WriteLn('Not Enough Memory!');
    Halt;
    End;
    ASM
    Mov Ax, $13 { Get into Graphics 320x200x256 }
    Int $10
    END;

    { Draw a moving Box, no virtual Screens }
    { I am using 2 WaitRetrace, because otherwise it's too fast and You can't even see the box }
    Repeat
    WaitRetrace;
    ClrVid(VGA,0);
    WaitRetrace;
    DrawBox(X,0,10,12,VGA);
    Inc(X);
    Until Keypressed;
    While Keypressed Do Readkey;

    { Draw a moving Box, using a virtual Screen }
    Repeat
    ClrVid(VAddr[1],0);
    DrawBox(X,0,10,12,VAddr[1]);
    WaitRetrace;
    CopyPage(VAddr[1],VGA);
    Inc(X);
    Until Keypressed;
    While Keypressed Do Readkey;

    ASM
    Mov Ax, $3 { Return to Text Mode }
    Int $10
    END;
    DisposeVideoPages; { Release Memory }
    End.
    [/code]

    If you have any questions, just post them.

    Phat Nat



Sign In or Register to comment.