画像イコライザー

 投稿者:しばっち  投稿日:2020年 5月24日(日)14時34分14秒
  画像に対してグラフィックイコライザー風な(DCT係数を0~2倍します)処理を
行います。
スライドバーを動かした後、グラフィックウィンドゥ内をマウスでクリックしてください。


OPTION BASE 0
DIM R(16,16),G(16,16),B(16,16)
FILE GETNAME N$,"BMP,JPG,GIF,PNGファイル|*.BMP;*.JPG;*.GIF;*.PNG"
CALL PICTURELOAD(N$,XSIZE,YSIZE)
DIM M(XSIZE-1,YSIZE-1),MM(XSIZE-1,YSIZE-1),V(16)
LET SW=0 !' 0 OR 1
LET BAND=8 !' 8 OR 16
ASK PIXEL ARRAY(0,0) M
LOCATE VALUE NOWAIT(1),RANGE -8 TO 8,AT 0:L
LOCATE VALUE NOWAIT(2),RANGE -8 TO 8,AT 0:H1
LOCATE VALUE NOWAIT(3),RANGE -8 TO 8,AT 0:H2
LOCATE VALUE NOWAIT(4),RANGE -8 TO 8,AT 0:H3
LOCATE VALUE NOWAIT(5),RANGE -8 TO 8,AT 0:H4
LOCATE VALUE NOWAIT(6),RANGE -8 TO 8,AT 0:H5
LOCATE VALUE NOWAIT(7),RANGE -8 TO 8,AT 0:H6
LOCATE VALUE NOWAIT(8),RANGE -8 TO 8,AT 0:H7
IF BAND=16 THEN
   LOCATE VALUE NOWAIT(9),RANGE -8 TO 8,AT 0:H8
   LOCATE VALUE NOWAIT(10),RANGE -8 TO 8,AT 0:H9
   LOCATE VALUE NOWAIT(11),RANGE -8 TO 8,AT 0:H10
   LOCATE VALUE NOWAIT(12),RANGE -8 TO 8,AT 0:H11
   LOCATE VALUE NOWAIT(13),RANGE -8 TO 8,AT 0:H12
   LOCATE VALUE NOWAIT(14),RANGE -8 TO 8,AT 0:H13
   LOCATE VALUE NOWAIT(15),RANGE -8 TO 8,AT 0:H14
   LOCATE VALUE NOWAIT(16),RANGE -8 TO 8,AT 0:H15
END IF
DO
   DO  !'ウェイト。マウスでウィンドゥ内をクリックする。
      IF GetKeyState(32)<0 OR GetKeyState(13)<0 OR GetKeyState(27)<0 THEN STOP
      MOUSE POLL X,Y,LL,RR
      LOCATE VALUE NOWAIT(1):L
      LOCATE VALUE NOWAIT(2):H1
      LOCATE VALUE NOWAIT(3):H2
      LOCATE VALUE NOWAIT(4):H3
      LOCATE VALUE NOWAIT(5):H4
      LOCATE VALUE NOWAIT(6):H5
      LOCATE VALUE NOWAIT(7):H6
      LOCATE VALUE NOWAIT(8):H7
      IF BAND=16 THEN
         LOCATE VALUE NOWAIT(9):H8
         LOCATE VALUE NOWAIT(10):H9
         LOCATE VALUE NOWAIT(11):H10
         LOCATE VALUE NOWAIT(12):H11
         LOCATE VALUE NOWAIT(13):H12
         LOCATE VALUE NOWAIT(14):H13
         LOCATE VALUE NOWAIT(15):H14
         LOCATE VALUE NOWAIT(16):H15
      END IF
   LOOP WHILE LL=0 AND RR=0
   CLEAR
   LET V(0)=L
   LET V(1)=H1
   LET V(2)=H2
   LET V(3)=H3
   LET V(4)=H4
   LET V(5)=H5
   LET V(6)=H6
   LET V(7)=H7
   LET V(8)=H8
   LET V(9)=H9
   LET V(10)=H10
   LET V(11)=H11
   LET V(12)=H12
   LET V(13)=H13
   LET V(14)=H14
   LET V(15)=H15
   SET TEXT HEIGHT YSIZE/10
   SET COLOR COLORINDEX(0,0,0)
   SET TEXT BACKGROUND "OPAQUE"
   SET TEXT JUSTIFY "CENTER" , "TOP"
   PLOT TEXT ,AT XSIZE/2,YSIZE/2 :"処理中"
   FOR Y=0 TO YSIZE-1 STEP BAND
      SET TEXT JUSTIFY "LEFT" , "TOP"
      PLOT TEXT ,AT 0,0 :USING$("###.#",Y/(YSIZE-1)*100)&"%"
      FOR X=0 TO XSIZE-1 STEP BAND
         FOR J=SW TO BAND-1+SW
            FOR I=SW TO BAND-1+SW
               IF X+I-SW<=XSIZE-1 AND Y+J-SW<=YSIZE-1 THEN
                  LET CC=M(X+I-SW,Y+J-SW)
               ELSE
                  LET CC=0
               END IF
               CALL RGB(CC,R(I,J),G(I,J),B(I,J))
            NEXT I
         NEXT J
         IF SW=0 THEN
            CALL DCT(R,BAND)
            CALL DCT(G,BAND)
            CALL DCT(B,BAND)
         ELSEIF SW=1 THEN
            CALL DST(R,BAND)
            CALL DST(G,BAND)
            CALL DST(B,BAND)
         END IF
         FOR I=SW TO BAND-1+SW
            FOR J=SW TO BAND-1+SW
               LET R(I,J)=R(I,J)*(8+V(I))/8*(V(J)+8)/8 !'係数を掛ける。縦横で最大4倍する
               LET G(I,J)=G(I,J)*(8+V(I))/8*(V(J)+8)/8
               LET B(I,J)=B(I,J)*(8+V(I))/8*(V(J)+8)/8
            NEXT J
         NEXT I
         IF SW=0 THEN
            CALL IDCT(R,BAND)
            CALL IDCT(G,BAND)
            CALL IDCT(B,BAND)
         ELSEIF SW=1 THEN
            CALL IDST(R,BAND)
            CALL IDST(G,BAND)
            CALL IDST(B,BAND)
         END IF
         FOR J=SW TO BAND-1+SW
            FOR I=SW TO BAND-1+SW
               IF B(I,J)<0 THEN LET B(I,J)=0
               IF G(I,J)<0 THEN LET G(I,J)=0
               IF R(I,J)<0 THEN LET R(I,J)=0
               IF B(I,J)>255 THEN LET B(I,J)=255
               IF G(I,J)>255 THEN LET G(I,J)=255
               IF R(I,J)>255 THEN LET R(I,J)=255
               IF X+I-SW<=XSIZE-1 AND Y+J-SW<=YSIZE-1 THEN LET MM(X+I-SW,Y+J-SW)=SETRGB(INT(R(I,J)),INT(G(I,J)),INT(B(I,J)))
            NEXT I
         NEXT J
      NEXT X
   NEXT Y
   MAT PLOT CELLS , IN 0,0; XSIZE-1,YSIZE-1:MM
LOOP
END

EXTERNAL FUNCTION C(X,N)
IF X=0 OR X=N THEN LET C=SQR(.5) ELSE LET C=1
END FUNCTION

EXTERNAL SUB DCT(S(,),N)
OPTION BASE 0
DIM X(N),Y(N)
FOR J=0 TO N-1
   FOR I=0 TO N-1
      LET X(I)=S(I,J)
   NEXT I
   CALL DCT2(X,N,Y)
   FOR I=0 TO N-1
      LET S(I,J)=Y(I)
   NEXT I
NEXT J
FOR J=0 TO N-1
   FOR I=0 TO N-1
      LET X(I)=S(J,I)
   NEXT I
   CALL DCT2(X,N,Y)
   FOR I=0 TO N-1
      LET S(J,I)=Y(I)
   NEXT I
NEXT J
END SUB

EXTERNAL SUB DCT2(A(),N,B())
FOR I=0 TO N-1
   LET S=0
   FOR K=0 TO N-1
      LET S=S+A(K)*COS((2*K+1)*I*PI/2/N)
   NEXT K
   LET B(I)=S*SQR(2/N)*C(I,N)
NEXT I
END SUB

EXTERNAL SUB DCT3(A(),N,B())
FOR I=0 TO N-1
   LET S=0
   FOR K=0 TO N-1
      LET S=S+C(K,N)*A(K)*COS((2*I+1)*K*PI/2/N)
   NEXT K
   LET B(I)=INT(S*SQR(2/N)+.5)
NEXT I
END SUB

EXTERNAL SUB IDCT(S(,),N)
OPTION BASE 0
DIM X(N),Y(N)
FOR J=0 TO N-1
   FOR I=0 TO N-1
      LET X(I)=S(I,J)
   NEXT I
   CALL DCT3(X,N,Y)
   FOR I=0 TO N-1
      LET S(I,J)=Y(I)
   NEXT I
NEXT J
FOR J=0 TO N-1
   FOR I=0 TO N-1
      LET X(I)=S(J,I)
   NEXT I
   CALL DCT3(X,N,Y)
   FOR I=0 TO N-1
      LET S(J,I)=Y(I)
   NEXT I
NEXT J
END SUB

EXTERNAL SUB DST(S(,),N)
OPTION BASE 0
DIM X(N),Y(N)
FOR J=1 TO N
   FOR I=1 TO N
      LET X(I)=S(I,J)
   NEXT I
   CALL DST2(X,N,Y)
   FOR I=1 TO N
      LET S(I,J)=Y(I)
   NEXT I
NEXT J
FOR J=1 TO N
   FOR I=1 TO N
      LET X(I)=S(J,I)
   NEXT I
   CALL DST2(X,N,Y)
   FOR I=1 TO N
      LET S(J,I)=Y(I)
   NEXT I
NEXT J
END SUB

EXTERNAL SUB DST2(A(),N,B())
FOR K=1 TO N
   LET S=0
   FOR I=1 TO N
      LET S=S+A(I)*SIN((2*I-1)*K*PI/2/N)
   NEXT I
   LET B(K)=S*SQR(2/N)*C(K,N)
NEXT K
END SUB

EXTERNAL SUB DST3(A(),N,B())
FOR K=1 TO N
   LET S=0
   FOR I=1 TO N
      LET S=S+C(I,N)*A(I)*SIN((2*K-1)*I*PI/2/N)
   NEXT I
   LET B(K)=INT(S*SQR(2/N)+.5)
NEXT K
END SUB

EXTERNAL SUB IDST(S(,),N)
OPTION BASE 0
DIM X(N),Y(N)
FOR J=1 TO N
   FOR I=1 TO N
      LET X(I)=S(I,J)
   NEXT I
   CALL DST3(X,N,Y)
   FOR I=1 TO N
      LET S(I,J)=Y(I)
   NEXT I
NEXT J
FOR J=1 TO N
   FOR I=1 TO N
      LET X(I)=S(J,I)
   NEXT I
   CALL DST3(X,N,Y)
   FOR I=1 TO N
      LET S(J,I)=Y(I)
   NEXT I
NEXT J
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

EXTERNAL FUNCTION SETRGB(R,G,B)
LET R=MIN(255,MAX(R,0))
LET G=MAX(0,MIN(G,255))
LET B=MAX(0,MIN(B,255))
LET SETRGB=B*65536+G*256+R
END FUNCTION

EXTERNAL SUB PICTURELOAD(N$,XSIZE,YSIZE)
CLEAR
SET COLOR MODE "NATIVE"
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
 

戻る