BBS: Inland Empire Archive Date: 12-27-92 (06:19) Number: 242 From: RICH GELDREICH Refer#: NONE To: ALL Recvd: NO Subj: Bload Compressor/1 Conf: (2) Quik_Bas
I'll get directly to the point: if you use BSAVE and BLOAD to compress SCREEN 13 images, then this program should be a great help. The purpose of this program is to compress SCREEN 13 (320x200x256) images to a BLOAD'able file. To decompress the file, you call a VERY FAST assembly language decompressor that quickly sets the palette and writes the image to the screen. It used to be small, until I documented it... Ooops. 'Page 1 of ENCODE13.BAS begins here. 'SCREEN 13 (320x200x256) Screen Compressor (SP1.BAS) 'Public Domain By Rich Geldreich, December 26, 1992 'Anyone may use this program in anything they want, as long as the 'original author(me, duh) is given credit where credit is due... 'Thanks. I'd appreciate a little cash on the side if you make any 'money off a product that uses this program... :-) If you make any 'neat modifications/optimizations to this program or the ASM decoder, 'I would really like to seem them! 'Description: ' This simple SCREEN 13 compression program uses an LZ77 variant 'to compress SCREEN 13 images. A FAST assembly subroutine is used to 'decompress the image back to the screen. The compression should 'always beat PCX, and should come fairly close or beat out GIF under 'most cases. ' ' The assembly decompressor's speed is several magnitudes faster 'than the quickest GIF decoder I've seen, VPIC 5.1. (Look how simple 'it is and you'll know why!) BTW- The output stage of this program 'was optimized for decoding speed, not for compression. Several 'optimizations could be added to increase this program's compression 'performance, such as entropy encoding on the distance & length 'tokens(which would slow the decoder down immensely), increasing the 'sizes of the sliding dictionary and look ahead buffers, and further 'optimizing the non-greedy aspect of this LZ77 implementation to 'choose the best character/match combinations to store in the output 'stream. ' ' The assembly subroutine is for 286's and above, only. This 'program does NOT work under QuickBASIC, only PDS and VB/DOS because 'of the use of BYVAL. ' ' Any questions, cash/and or death threats call me at '(609)-742-8752 2:30pm - 11:30pm eastern time or send a self 'addressed stamped evelope (SASE) to: ' ' Rich Geldreich ' 410 Market St. ' Gloucester City, NJ 08030 ' 'Possible uses of this program: Use a GIF or PCX converter(or SHELL 'out to VPIC) to display the image you want to use in your 'application on SCREEN 13. Then encode the image with this program. 'You can then instantly recall the image using the fast Decom13 'assembly language subroutine. DEFINT A-Z 'Declaration for the assembly decompressor. If the area of memory 'passed does not start with "RG", the compressed image's signature, 'then this routine will just return without doing anything. This 'prevents your machine from hanging when you pass it a bum pointer. DECLARE SUB Decom13 (BYVAL InSegment, BYVAL InOffset) CONST True = -1, False = 0 'A larger buffer size would surely increase compression. CONST BufferSize = 4096, HashSize = 4096 CONST Null = BufferSize, Threshold = 2, MaxMatch = 273 CONST MaxCompares = 300 'Controls compression ratio vs. speed 'Arrays for LZ77 style compression with multiple linked lists DIM SHARED RingBuffer((BufferSize + MaxMatch - 1) - 1) DIM SHARED NextCell((BufferSize + HashSize + 1) - 1) DIM SHARED LastCell((BufferSize + HashSize + 1) - 1) 'Temp. holding buffer for compression tokens DIM SHARED CodeBuffer(16 * 3 - 1) 'Misc. stuff DIM SHARED DoneFlag, xp, yp, xl, yl, xh, yh DIM SHARED Match.Length, Match.Position, Match.Distance DIM SHARED IOBuffer$, IOPointer DIM SHARED CodePointer, CodeCounter, OrMask AS LONG, BitAccum AS LONG SCREEN 13 '**COMPRESSION EXAMPLE** RANDOMIZE TIMER FOR a = 1 TO 100 'draw us some garbage x = RND * 319: y = RND * 199: c = RND * 255 CIRCLE (x, y), RND * 60, c: PAINT (x, y), RND * 255, c NEXT FOR a = 1 TO 200: LINE -(RND * 319, RND * 199), RND * 255: NEXT Compress13 "coolfile.bci" 'compress the screen to coolfile.bci '**DECOMPRESSION EXAMPLE** 'Allocate 64,000 bytes for a worst case scenario, decrease this of 'course to match the image's compressed size in bytes... 'Continued on page 2 --- MsgToss 2.0b * Origin: Computer Co-Op - Voorhees, NJ | Ted Hare (1:266/29)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET