PPM,PGMファイル
FILE GETNAME F$, "BMP,JPG,GIFファイル|*.BMP;*.JPG;*.GIF" IF F$="" THEN STOP CALL PICTURELOAD(F$,XSIZE,YSIZE) INPUT PROMPT "SAVE FILENAME(.PPM)=":N$ INPUT PROMPT "MODE ASCII(0) or BINARY(1) ":MODE CALL PPMSAVE(MODE,N$,0,0,XSIZE-1,YSIZE-1) END
EXTERNAL SUB PPMSAVE(MODE,F$,XS,YS,XE,YE) OPTION CHARACTER BYTE IF F$="" THEN STOP IF POS(F$,".")=0 THEN LET F$=F$ & ".PPM" LET XSIZE=XE-XS+1 LET YSIZE=YE-YS+1 OPEN #1:NAME F$ SELECT CASE MODE CASE 0 PRINT #1:"P3";CHR$(10); PRINT #1:XSIZE;YSIZE;CHR$(10); PRINT #1:"255";CHR$(10); FOR Y=YS TO YE FOR X=XS TO XE CALL GETPOINT(X,Y,R,G,B) PRINT #1:R;G;B; NEXT X PRINT #1:CHR$(10); NEXT Y CASE 1 PRINT #1:"P6";CHR$(10); PRINT #1:XSIZE;YSIZE;CHR$(10); PRINT #1:"255";CHR$(10); FOR Y=YS TO YE FOR X=XS TO XE CALL GETPOINT(X,Y,R,G,B) PRINT #1:CHR$(R);CHR$(G);CHR$(B); NEXT X NEXT Y END SELECT CLOSE #1 END SUB
EXTERNAL SUB PGMSAVE(MODE,F$,XS,YS,XE,YE) OPTION CHARACTER BYTE IF F$="" THEN STOP IF POS(F$,".")=0 THEN LET F$=F$ & ".PGM" LET XSIZE=XE-XS+1 LET YSIZE=YE-YS+1 OPEN #1:NAME F$ SELECT CASE MODE CASE 0 PRINT #1:"P2";CHR$(10); PRINT #1:XSIZE;YSIZE;CHR$(10); PRINT #1:"255";CHR$(10); FOR Y=YS TO YE FOR X=XS TO XE CALL GETPOINT(X,Y,R,G,B) LET GR = (151 * B + 77 * G + 28 * R) / 256 CALL PSET(X,Y,GR,GR,GR) PRINT #1:GR; NEXT X PRINT #1:CHR$(10); NEXT Y CASE 1 PRINT #1:"P5";CHR$(10); PRINT #1:XSIZE;YSIZE;CHR$(10); PRINT #1:"255";CHR$(10); FOR Y=YS TO YE FOR X=XS TO XE CALL GETPOINT(X,Y,R,G,B) LET GR = (151 * B + 77 * G + 28 * R) / 256 CALL PSET(X,Y,GR,GR,GR) PRINT #1:CHR$(GR); NEXT X NEXT Y END SELECT CLOSE #1 END SUB
EXTERNAL SUB PSET(X,Y,R,G,B) SET COLOR COLORINDEX(R/255,G/255,B/255) PLOT POINTS: X , Y END SUB
EXTERNAL SUB PICTURELOAD(N$,XSIZE,YSIZE) CLEAR SET COLOR MODE "NATIVE" SET POINT STYLE 1 GLOAD N$ LET XSIZE=PIXELX(1)+1 LET YSIZE=PIXELY(1)+1 SET BITMAP SIZE XSIZE,YSIZE SET WINDOW 0,XSIZE-1,YSIZE-1,0 END SUB
EXTERNAL SUB GETPOINT(X,Y,R,G,B) ASK PIXEL VALUE (X,Y) C CALL RGB(C,R,G,B) END SUB
EXTERNAL SUB RGB(X,R,G,B) LET B=MOD(INT(X/65536),256) LET G=MOD(INT(X/256),256) LET R=MOD(X,256) END SUB
|