info-mac@utcsrgv.UUCP (info-mac) (06/22/84)
Date: Tue, 19 Jun 84 15:44 PST From: John Palevich <uw-beaver!palevich%atari.csnet@csnet-relay.arpa> To: info-mac%sumex-aim@csnet-relay.arpa Subject: MacPaint Picture Enlarger Here is a program I wrote the other day. It enlarges any MacPaint compatible picture file into four files, each of which contains one quarter of the original image, doubled in size. These quarters may be printed out, using MacPaint, and pasted together to form a large picture that is twice as high and twice as large as the original. Or, each quarter can be enlarged, producing sixteen pictures which can be cut and pasted to form a very large picture which is four times as wide, and four times as long as the original. Of course, the enlarged pictures have larger pixels, but the results are quite striking, as well as practical for group presentations, posters, etc.. The four output files are named <input file name>+0 thru <input file name>+3. This program is written in Microsoft Basic, and, as a result, runs slowly. It contains code taken from MacTEP 1.8?, (C) 1984 Brothers Associates, which is used to get and set file types. Information about the internal structure of MacPaint files comes from Inside Macintosh. The internal representation of compressed pixels is undocumented, but look at the code to see what I think the representation is.... If you're enlarging screen dumps, note that only the first two files contain information, so you can break the program after it starts to process line 360. Jack Palevich 5 DEFINT A-Z 7 GOSUB 20000:REM Initialize machine language subroutines 10 DIM PIXBUF(143),DBYTE(16),PARAMLIST(39) 20 CALL TEXTFONT(1):CALL TEXTSIZE(12) 30 CLS:PRINT"MacPaint Picture Enlarger" 35 PRINT " ";CHR$(169);"1984 John Howard Palevich" 37 PRINT"Converts input MacPaint file into four output MacPaint files." 40 PRINT:PRINT"File to enlarge"; 50 INPUT IFN$ 55 F$=IFN$:GOSUB 10000:IF LEFT$(TYPEAPPL$,4)="PNTG" THEN 60 57 PRINT"That's not a MacPaint file.":GOTO 40 60 RESTORE 90 65 FOR I = 0 TO 15 70 READ D:DBYTE(I)=D 80 NEXT I 90 DATA &h00,&h03,&h0c,&h0f 92 DATA &h30,&h33,&h3c,&h3f 94 DATA &hc0,&hc3,&hcc,&hcf 96 DATA &hf0,&hf3,&hfc,&hff 100 OPEN IFN$ FOR INPUT AS #1 110 REM Skip the first 512 bytes of the MacPaint file 120 FOR I = 0 TO 3: A$=INPUT$(128,#1):NEXT I 130 OPEN IFN$+"0" FOR OUTPUT AS #2 140 OPEN IFN$+"1" FOR OUTPUT AS #3 150 N$=CHR$(0):FOR I = 1 TO 7:N$=N$+N$:NEXT I:REM fill n$ with 128 nulls 155 REM Write MacPaint Header to output files 160 FOR M = 0 TO 3: PRINT #2,N$;:PRINT #3,N$;:NEXT M 200 FOR I = 0 TO 719:REM for each scan line 205 PI=0 206 PRINT "Procesing line ";I; 210 COUNT=ASC(INPUT$(1,#1)) 220 IF COUNT >= 128 THEN 300 230 REM 0..127 -> COUNT+1 bytes of raw data 240 A$=INPUT$(COUNT+1,#1) 250 FOR J = 0 TO COUNT 260 PIXBUF(PI+J) = ASC(MID$(A$,J+1,1)) 270 NEXT J 280 PI=PI+COUNT+1 290 GOTO 400 300 REM 128..255 -> 256-COUNT repeats of the next byte 310 N = 256-COUNT 320 B=ASC(INPUT$(1,#1)) 330 FOR J = 0 TO N 340 PIXBUF(PI+J)=B 350 NEXT J 360 PI = PI + N + 1 400 REM See if the pixel buffer is filled up yet 410 IF PI < 72 THEN 210 500 REM Pixbuf(0..PI-1) now has the picture. (PI == 72) 505 IF PI <> 72 THEN PRINT"Woops, illegal file format.":END 510 FOR J = 71 TO 0 STEP -1 520 H=INT(PIXBUF(J)/16):L=PIXBUF(J)-16*H 530 PIXBUF(2*J+1)=DBYTE(L):PIXBUF(2*J)=DBYTE(H) 540 NEXT J 600 REM Compact the Pixels. 610 PI=0:GOSUB 2000:PRINT #2,OP$;OP$;:PRINT"[";LEN(OP$);","; 620 PI=72:GOSUB 2000:PRINT #3,OP$;OP$;:PRINT LEN(OP$);"]" 630 IF I <> 360 THEN 1000 640 REM We've filled up one set of files. Open the next set. 645 CLOSE#2:CLOSE#3 650 OPEN IFN$+"2" FOR OUTPUT AS #2 660 OPEN IFN$+"3" FOR OUTPUT AS #3 665 REM Write MacPaint Header to output files 670 FOR M = 0 TO 3: PRINT #2,N$;:PRINT #3,N$;:NEXT M 1000 NEXT I 1010 CLOSE#2:CLOSE#3:CLOSE#1 1020 PRINT"Done Processing." 1200 REM Change file type to MacPaint 1210 TYPEAPPL$="PNTGMPNT":REM MacPaint Painting code 1220 F$=IFN$+"0":GOSUB 11000:F$=IFN$+"1":GOSUB 11000 1230 F$=IFN$+"2":GOSUB 11000:F$=IFN$+"3":GOSUB 11000 1900 PRINT"Done." 1999 END 2000 REM Pixbuf(pi..pi+71) -> op$ 2010 OP$="":K=PI:Z=PI+71 2020 REM Duplicate bytes? 2030 IF K > Z THEN RETURN:REM We're done. 2035 IF K=Z THEN 2200 2040 IF PIXBUF(K)<>PIXBUF(K+1) THEN 2200 2050 REM See how many repeated bytes 2060 K2 = K+1 2070 IF K2>Z THEN 2100 2080 IF PIXBUF(K)=PIXBUF(K2) THEN K2=K2+1:GOTO 2070 2100 REM pixbuf(k..k2-1) is a repeat count 2110 OP$ = OP$+CHR$(257-(K2-K))+CHR$(PIXBUF(K)) 2120 K = K2:GOTO 2030 2200 REM See how many random bytes there are: 2210 K2=K+1:IF K = Z THEN 2300 2220 IF K2 >= Z-1 THEN K2=Z+1:GOTO 2300 2230 IF PIXBUF(K2)<>PIXBUF(K2+2) THEN K2=K2+2:GOTO 2220 2240 IF PIXBUF(K2) <> PIXBUF(K2+1) THEN K2=K2+1:GOTO 2220 2300 REM pixbuf(k..k2-1) is random 2310 OP$=OP$+CHR$(K2-K-1) 2320 FOR K3 = K TO K2-1 2330 OP$=OP$+CHR$(PIXBUF(K3)) 2340 NEXT K3 2350 K=K2 2360 GOTO 2030 10000 REM Subroutine to get type and application of a file 10010 REM 10015 FP!=0:PARAM!=0:I=0:FL=0:GETFILEINFO!=0:TYPEAPPL$="" 10020 FL=LEN(F$) 10030 F$=CHR$(FL)+F$ 10035 FP!=VARPTR(F$):PARAM!=VARPTR(PARAMLIST(0)) 10037 GETFILEINFO!=VARPTR(GETFILEINFOCODE(0)) 10040 FOR I = 0 TO 79:POKE PARAM!+I,0:NEXT I 10050 POKE PARAM!+19,PEEK(FP!+2) 10060 POKE PARAM!+20,PEEK(FP!+3) 10070 POKE PARAM!+21,PEEK(FP!+4) 10080 CALL GETFILEINFO!(PARAM!) 10090 FOR I = 0 TO 7 10100 TYPEAPPL$=TYPEAPPL$+CHR$(PEEK(PARAM!+32+I)) 10110 NEXT I 10120 RETURN 11000 REM Subroutine to set type and application of a file 11010 REM 11015 FP!=0:PARAM!=0:I=0:FL=0:GETFILEINFO!=0:SETFILEINFO!=0 11020 FL=LEN(F$) 11030 F$=CHR$(FL)+F$ 11035 FP!=VARPTR(F$):PARAM!=VARPTR(PARAMLIST(0)) 11037 GETFILEINFO!=VARPTR(GETFILEINFOCODE(0)) 11038 SETFILEINFO!=VARPTR(SETFILEINFOCODE(0)) 11040 FOR I = 0 TO 79:POKE PARAM!+I,0:NEXT I 11050 POKE PARAM!+19,PEEK(FP!+2) 11060 POKE PARAM!+20,PEEK(FP!+3) 11070 POKE PARAM!+21,PEEK(FP!+4) 11080 CALL GETFILEINFO!(PARAM!) 11090 FOR I = 0 TO 7 11100 POKE PARAM!+32+I, ASC(MID$(TYPEAPPL$,I+1,1)) 11110 NEXT I 11120 CALL SETFILEINFO!(PARAM!) 11130 RETURN 20000 REM Set up GetFileInfo ROM call 20010 REM From MacTEP 1.81, (c) 1984 Brothers Associates 20015 PRINT"Initializing."; 20020 DIM GETFILEINFOCODE(25) 20030 RESTORE 20100 20040 I = 0 20050 READ A:GETFILEINFOCODE(I)=A 20060 I=I+1 20070 IF A<> -1 THEN 20050 20080 REM 20090 REM 20100 REM Machine Language code to invoke GetFileInfo ROM function 20110 REM 20120 DATA &h4e56, &hfff8, &h48ee, &h0101, &hfff8, &h206e, &h0008, &ha00c 20130 DATA &h4cee, &h0101, &hfff8, &h4e5e, &h4e75 20140 DATA -1 20150 REM 20160 REM 20200 REM Set up the SetFileInfo ROM call 20210 REM 20215 PRINT"."; 20220 DIM SETFILEINFOCODE(25) 20230 RESTORE 20300 20240 I=0 20250 READ A:SETFILEINFOCODE(I)=A 20260 I=I+1 20270 IF A<>-1 THEN 20250 20280 REM 20290 REM 20300 REM Machine language code to invoke SetFileInfo ROM 20310 REM 20320 DATA &h4e56, &hfff8, &h48ee, &h0101, &hfff8, &h206e, &h0008, &ha00d 20330 DATA &h4cee, &h0101, &hfff8, &h4e5e, &h4e75 20340 DATA -1 20350 REM 20355 PRINT"." 20360 RETURN