'=========================================================================== ' Subject: SAVE SCREEN 12 AS 4BIT BMP V0.2 Date: 04-23-99 (18:32) ' Author: Yousuf Philips Code: QB, QBasic, PDS ' Origin: philipz@emirates.net.ae Packet: GRAPHICS.ABC '=========================================================================== '''''''''''''''''''''''''''''''''''''''''''' ' Program : Save Screen 12 as 4-BIT BMP ' ' Name : SAVE4BIT Version 0.2 ' ' Programmer : Yousuf Philips ' ' Company : Y P I ' ' Updated On : 17th of Jan. 1998 ' ' Email - [philipz85@hotmail.com] ' ' [http://members.xoom.com/Philipz/] ' '''''''''''''''''''''''''''''''''''''''''''' '/* Do not edit this file if you distribute it. */' '/* (c) Copyrighted by YPI in 1998 | All Rights Reserved | Public Domain */' '/* The SAVE4BIT SUB is able to save any portion of screen 12 as a 4-BIT */' '/* Windows BMP file. */' '/* */' '/* What's New - */' '/* * 4-BIT saving was corrected. */' '/* [Thanks for the notification of the error, Joran.] */' '/* If you use any of this code in your program then you must credit YPI, */' '/* it would be appreciated if you sent us a copy of your program also. */' TYPE BMPHeader ValidID AS STRING * 2 '/* Must be 'BM' SizeOfFile AS LONG '/* Size of entire file in bytes Reserved AS LONG '/* Four empty bytes OffsetOfBitMap AS LONG '/* The location in the file where the ' bitmap is located END TYPE TYPE WindowsBMPInfoHeader SizeOfHeader AS LONG '/* Size of Information Header ' 40 - Windows | 12 - OS/2 1.x | 64 OS/2 2.x Widthz AS LONG '/* Width of image in pixels Heightz AS LONG '/* Height of image in pixels Planes AS INTEGER '/* Number of Planes. Must be '1' BitsPerPixel AS INTEGER '/* Number of bits per pixel ' Possible values are 1,4,8,16,24,32 CompressMethod AS LONG '/* Compression Method ' 0 - Uncompressed ' 1 - 8 Bit RLE Compression ' 2 - 4 Bit RLE Compression ImageSizeInBytes AS LONG '/* Size of image in bytes HorizontalResol AS LONG '/* Horizontal Resolution VerticalResol AS LONG '/* Vertical Resolution ColorsUsed AS LONG '/* Number of Colors used | 0 - All Used ImportantColors AS LONG '/* Number of Important Colors END TYPE DECLARE SUB SAVE4BIT (FileName$, MinX%, MinY%, MaxX%, MaxY%) '/* FileName$ - The filename of the file that the saved screen is to be put*/' '/* MinX - The starting x position */' '/* MinY - The starting y position */' '/* MaxX - The ending x position */' '/* MaxY - The ending y position */' SCREEN 0: SCREEN 12 FOR Circles = 1 TO 100 CIRCLE (RND * 640, RND * 480), RND * 200, RND * 16 NEXT Circles PRINT "Created By YPI (c) 1998" t = TIMER CALL SAVE4BIT("4bit.bmp", 0, 0, 639, 479) PRINT " Time Taken To Save Screen -"; TIMER - t DEFINT A-Z SUB SAVE4BIT (FileName$, MinX, MinY, MaxX, MaxY) OPEN FileName$ FOR BINARY AS #255 IF LOF(255) <> 0 THEN CLOSE KILL FileName$ OPEN FileName$ FOR BINARY AS #255 END IF ImageWidth = (MaxX - MinX) + 1: ImageHeight = (MaxY - MinY) + 1 DIM BMPHeader AS BMPHeader DIM WindowsBMPInfoHeader AS WindowsBMPInfoHeader PUT #255, , BMPHeader WindowsBMPInfoHeader.SizeOfHeader = 40 WindowsBMPInfoHeader.Widthz = ImageWidth WindowsBMPInfoHeader.Heightz = ImageHeight WindowsBMPInfoHeader.Planes = 1 WindowsBMPInfoHeader.BitsPerPixel = 4 WindowsBMPInfoHeader.CompressMethod = 0 WindowsBMPInfoHeader.ColorsUsed = 16 WindowsBMPInfoHeader.ImportantColors = 16 PUT #255, , WindowsBMPInfoHeader SCREEN 12 FOR Colors = 0 TO 15 OUT &H3C7, Colors AllColorz$ = AllColorz$ + CHR$(INP(&H3C9) * 4) + CHR$(INP(&H3C9) * 4) + CHR$(INP(&H3C9) * 4) + CHR$(0) NEXT Colors PUT #255, , AllColorz$: AllColorz$ = "" IF (WindowsBMPInfoHeader.Widthz MOD 2) = 1 THEN WindowsBMPInfoHeader.Widthz = WindowsBMPInfoHeader.Widthz + 1 END IF IF (4 - ((WindowsBMPInfoHeader.Widthz MOD 8) \ 2)) <> 4 THEN Padding$ = SPACE$((4 - ((WindowsBMPInfoHeader.Widthz MOD 8) \ 2))) END IF FOR Loops = MaxY TO MinY STEP -1 Bytez$ = "" FOR Lips = MinX TO MaxX STEP 2 Byte = POINT(Lips, Loops) * 16 Byte = Byte + POINT(Lips + 1, Loops) Bytez$ = Bytez$ + CHR$(Byte) NEXT Lips LINE (MinX, Loops)-(MaxX, Loops), 0 PUT #255, , Bytez$ PUT #255, , Padding$ NEXT Loops BMPHeader.ValidID = "BM" BMPHeader.SizeOfFile = LOF(255) BMPHeader.OffsetOfBitMap = 118 PUT #255, 1, BMPHeader CLOSE #255 END SUB