モノクロBMPファイルを作る
OPTION BASE 0 PUBLIC NUMERIC XSIZE, M2(-1 TO 1,1),M(-2 TO 2,2) FILE GETNAME F$, "BMP,JPG,GIFファイル|*.BMP;*.JPG;*.GIF" IF F$="" THEN STOP CALL PICTURELOAD(F$,XSIZE,YSIZE) DIM BUF(XSIZE - 1, 2) INPUT PROMPT "MODE JARVIS(1) OR FLOYD(2) ": MD SELECT CASE MD CASE 1 RESTORE 10 FOR J = 0 TO 2 FOR I = -2 TO 2 READ M(I, J) NEXT I NEXT J CASE 2 RESTORE 20 FOR J = 0 TO 1 FOR I = -1 TO 1 READ M2(I, J) NEXT I NEXT J END SELECT FOR Y = 0 TO YSIZE - 1 FOR X = 0 TO XSIZE - 1 CALL GETPOINT(X,Y,R,G,B) LET V = (151 * B + 77 * G + 28 * R) / 256 SELECT CASE MD CASE 1 CALL ERRORDIFF(BUF,V,X,RV) IF RV<>0 THEN CALL PSET(X,Y,255,255,255) ELSE CALL PSET(X,Y,0,0,0) CASE 2 CALL ERRORDIFF2(BUF,V,X,RV) IF RV<>0 THEN CALL PSET(X,Y,255,255,255) ELSE CALL PSET(X,Y,0,0,0) END SELECT NEXT X NEXT Y 10 DATA 5,7,0,0,0 DATA 3,5,7,5,3 DATA 1,3,5,3,1 20 DATA 7,0,0 DATA 1,5,3 INPUT PROMPT "SAVE FILENAME(.BMP)=":F$ IF POS(F$,".")=0 THEN LET F$=F$ & ".BMP" CALL BMPMONOSAVE(F$,0,0,XSIZE-1,YSIZE-1) END EXTERNAL SUB ERRORDIFF (ERRBUF(,),LV,X,RV) LET S = 0 FOR J = 0 TO 2 FOR I = -2 TO 2 IF X + I >= 0 AND X + I <= XSIZE - 1 THEN LET S = S + ERRBUF(X + I, J) * M(I, J) NEXT I NEXT J LET S = (S + 24) / 48 IF S + LV > LEVEL THEN LET RV = 255 ELSE LET RV = 0 LET ERRBUF(X, 0) = S + LV - RV IF X = XSIZE - 1 THEN FOR XX = 0 TO XSIZE - 1 LET ERRBUF(XX, 2) = ERRBUF(XX, 1) LET ERRBUF(XX, 1) = ERRBUF(XX, 0) NEXT XX END IF END SUB EXTERNAL SUB ERRORDIFF2 (ERRBUF(,), LV, X,RV) LET S = 0 FOR J = 0 TO 1 FOR I = -1 TO 1 IF X + I >= 0 AND X + I <= XSIZE - 1 THEN LET S = S + ERRBUF(X + I, J) * M2(I, J) NEXT I NEXT J LET S = (S + 8) / 16 IF S + LV > LEVEL THEN LET RV = 255 ELSE LET RV = 0 LET ERRBUF(X, 0) = S + LV - RV IF X = XSIZE - 1 THEN FOR XX = 0 TO XSIZE - 1 SWAP ERRBUF(XX, 1), ERRBUF(XX, 0) NEXT XX END IF END SUB
|