The QBasic Forum      Other Subforums, Links and Downloads
 
  << Previous Topic | Next Topic >>Return to Index  

Run length encoding for saving black and white images

August 11 2009 at 6:02 PM
Anon  (no login)

Can use PRINT and INPUT instead of PUT and GET if you prefer. Also, you can modify it to decode to an array instead of to the screen if you want to, though it would probably be more efficient to just decode to the screen and GET it to an array.

DEFINT A-Z
SUB SAVEIMG(X1, Y1, X2, Y2, file$)
OPEN file$ FOR BINARY AS #1
c=0:count=0
FOR y = Y1 to Y2
FOR x = X1 to X2
IF POINT(x,y) <> c THEN PUT #1, , count: c = c XOR 1 ELSE count = count + 1
NEXT
NEXT
CLOSE #1
END SUB

SUB LOADIMG(X1, Y1, X2, Y2, file$)
OPEN file$ FOR BINARY AS #1
c=0:count=0
FOR y = Y1 to Y2
FOR x = X1 to X2
IF count=0 THEN GET #1, ,count: c = c XOR 1 ELSE PSET(x,y): count=count-1
NEXT
NEXT
END IF


 
 Respond to this message   
AuthorReply

(Login burger2227)
R

Using GET eliminates RLE compression of data

August 12 2009, 12:13 AM 

You could compress the data in an array and even BSAVE it, but then you have to redraw the image some way. My compression requires the same thing.




 
 Respond to this message   
Current Topic - Run length encoding for saving black and white images
  << Previous Topic | Next Topic >>Return to Index  

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums