|
!'マスク画像(2値画像)を使用して、自由形(任意形)変換をします
OPTION BASE 0
FILE GETNAME F$,"BMP,JPG,GIF,PNGファイル|*.BMP;*.JPG;*.GIF;*.PNG"
CALL PICTURELOAD(F$,XSIZE,YSIZE) !'入力画像(XSIZE*YSIZE)
DIM M(0 TO XSIZE-1,0 TO YSIZE-1)
ASK PIXEL ARRAY (0,0) M
FILE GETNAME F$,"マスク用画像|*.BMP;*.JPG;*.GIF;*.PNG" !'黒か黒以外
CALL PICTURELOAD(F$,XXSIZE,YYSIZE) !'マスク画像(XXSIZE*YYSIZE)
DIM MASK(0 TO XXSIZE-1,0 TO YYSIZE-1)
ASK PIXEL ARRAY (0,0) MASK
!'INPUT PROMPT "出力画像サイズ XSIZE,YSIZE=":OXSIZE,OYSIZE
LET OXSIZE=XSIZE !'出力画像サイズ(OXSIZE*OYSIZE)
LET OYSIZE=YSIZE
DIM XR(OYSIZE),YR(OXSIZE),YA(OXSIZE)
CALL GINIT(OXSIZE,OYSIZE)
FOR Y=0 TO OYSIZE-1 !'マスク画像表示
FOR X=0 TO OXSIZE-1
LET C=MASK(INT(X*XXSIZE/OXSIZE),INT(Y*YYSIZE/OYSIZE))
CALL RGB(C,RR,GG,BB)
IF RR<>0 OR GG<>0 OR BB<>0 THEN CALL PSET(X,Y,255,255,255) !'黒以外なら白色へ(2値化)
NEXT X
NEXT Y
FOR Y=0 TO OYSIZE-1 !'縮小率計算
FOR X=0 TO OXSIZE-1
CALL GETPOINT(X,Y,RR,GG,BB)
IF RR=255 AND GG=255 AND BB=255 THEN !'白ならカウント
LET XR(Y)=XR(Y)+1
LET YR(X)=YR(X)+1
END IF
NEXT X
NEXT Y
FOR X=0 TO OXSIZE-1 !'ライン毎に比率計算
LET YR(X)=YR(X)/OYSIZE
NEXT X
FOR Y=0 TO OYSIZE-1
LET XR(Y)=XR(Y)/OXSIZE
NEXT Y
FOR Y=0 TO OYSIZE-1
LET XA=0
FOR X=0 TO OXSIZE-1
CALL GETPOINT(X,Y,RR,GG,BB)
IF RR=255 AND GG=255 AND BB=255 THEN
LET XX=XA/XR(Y)*XSIZE/OXSIZE
LET YY=YA(X)/YR(X)*YSIZE/OYSIZE
LET XA=XA+1
LET YA(X)=YA(X)+1
LET C=M(INT(XX),INT(YY))
CALL RGB(C,RR,GG,BB)
CALL PSET(X,Y,RR,GG,BB)
END IF
NEXT X
NEXT Y
END
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
EXTERNAL SUB GETPOINT(X,Y,R,G,B)
ASK PIXEL VALUE(X,Y) C
CALL RGB(C,R,G,B)
END SUB
EXTERNAL SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
SET COLOR MODE "NATIVE"
CLEAR
SET POINT STYLE 1
SET WINDOW 0,XSIZE-1,YSIZE-1,0
CALL BOXFULL(0,0,XSIZE-1,YSIZE-1,0,0,0)
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)
SET COLOR MODE "NATIVE"
CLEAR
SET POINT STYLE 1
IF N$="" THEN STOP
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 BOXFULL(X0,Y0,X1,Y1,R,G,B)
SET COLOR COLORINDEX(R/255,G/255,B/255)
PLOT AREA:X0,Y0;X1,Y0;X1,Y1;X0,Y1;X0,Y0
END SUB
|
|