Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Antialiasing
#21
yes just had a full read through your code and i cant spot it. i'll take a closer look.

EDIT :

B Pixels all (1)

Quote: Pixels(1).B=TL AND &HFF
Pixels(2).B=TM AND &HFF
....
Pixels(8).B=BM AND &HFF
Pixels(9).B=BR AND &HFF

This bit all R
Quote: FOR I=1 TO 9
RetPixel.R=RetPixel.R+Pixels(I).R
RetPixel.G=RetPixel.G+Pixels(I).G
RetPixel.B=RetPixel.B+Pixels(I).B
NEXT
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply
#22
OMFG was I drunk or something...thanks yetifoot!
Fixed code. But ignore it, because Dave's is way better. Tongue
Code:
TYPE Pixel
    R AS INTEGER
    G AS INTEGER
    B AS INTEGER
END TYPE
DECLARE FUNCTION BlurPixel(INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER) AS Pixel
SCREENRES 300,200,24
RANDOMIZE TIMER
FOR I=1 TO 50
    CIRCLE (INT(RND*300),INT(RND*200)),INT(RND*15),RGB(INT(RND*255),INT(RND*255),INT(RND*255))
NEXT
SLEEP
DIM AS Pixel NewPixel
FOR X=100 TO 200
    FOR Y=50 TO 150
        TL=POINT(X-1,Y-1)
        TM=POINT(X,Y-1)
        TR=POINT(X+1,Y-1)
        ML=POINT(X-1,Y)
        MM=POINT(X,Y)
        MR=POINT(X+1,Y)
        BL=POINT(X-1,Y+1)
        BM=POINT(X,Y+1)
        BR=POINT(X+1,Y+1)
        NewPixel=BlurPixel(TL,TM,TR,ML,MM,MR,BL,BM,BR)
        PSET (X,Y),RGB(NewPixel.R,NewPixel.G,NewPixel.B)
    NEXT
NEXT
SLEEP
FUNCTION BlurPixel(TL AS INTEGER,TM AS INTEGER,TR AS INTEGER,ML AS INTEGER,MM AS INTEGER,MR AS INTEGER,BL AS INTEGER,BM AS INTEGER,BR AS INTEGER) AS Pixel
        DIM AS BYTE R,G,B
        DIM AS Pixel Pixels(1 TO 9),RetPixel
        DIM AS INTEGER I,RTotal,GTotal,BTotal,RetVal
        Pixels(1).R=(TL AND &HFF0000) SHR 16
        Pixels(2).R=(TM AND &HFF0000) SHR 16
        Pixels(3).R=(TR AND &HFF0000) SHR 16
        Pixels(4).R=(TM AND &HFF0000) SHR 16
        Pixels(5).R=(MM AND &HFF0000) SHR 16
        Pixels(6).R=(MR AND &HFF0000) SHR 16
        Pixels(7).R=(BL AND &HFF0000) SHR 16
        Pixels(8).R=(BM AND &HFF0000) SHR 16
        Pixels(9).R=(BR AND &HFF0000) SHR 16
        
        Pixels(1).G=(TL AND &HFF00) SHR 8
        Pixels(2).G=(TM AND &HFF00) SHR 8
        Pixels(3).G=(TR AND &HFF00) SHR 8
        Pixels(4).G=(ML AND &HFF00) SHR 8
        Pixels(5).G=(MM AND &HFF00) SHR 8
        Pixels(6).G=(MR AND &HFF00) SHR 8
        Pixels(7).G=(ML AND &HFF00) SHR 8
        Pixels(8).G=(BM AND &HFF00) SHR 8
        Pixels(9).G=(BR AND &HFF00) SHR 8
        
        Pixels(1).B=TL AND &HFF
        Pixels(2).B=TM AND &HFF
        Pixels(3).B=TR AND &HFF
        Pixels(4).B=ML AND &HFF
        Pixels(5).B=MM AND &HFF
        Pixels(6).B=MR AND &HFF
        Pixels(7).B=BL AND &HFF
        Pixels(8).B=BM AND &HFF
        Pixels(9).B=BR AND &HFF
        
        FOR I=1 TO 9
            RetPixel.R=RetPixel.R+Pixels(I).R
            RetPixel.G=RetPixel.G+Pixels(I).G
            RetPixel.B=RetPixel.B+Pixels(I).B
        NEXT
        RetPixel.R=RetPixel.R/9
        RetPixel.G=RetPixel.G/9
        RetPixel.B=RetPixel.B/9
        RETURN RetPixel
END FUNCTION
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#23
Bluring and Antialiasing are two very different things.
Bluring takes average and converts each pixel to that.
Antialiasing removes jagged edges by blending sharp "corners" to become more smooth, a diagonal line for example would be made up of numerous shades of the color you really want.
Bluring that same line would just make it unfocused
Reply
#24
I know, but blurring is adequate in most of my situations.
OK, here's the better code. It's a heck of a lot like Dave's, but it's in my coding style and I did it from memory (without copying. Tongue )
I also used SCREENINFO to minimize external CONSTs.
Code:
TYPE Pixel
    R AS INTEGER
    G AS INTEGER
    B AS INTEGER
END TYPE
DECLARE FUNCTION BlurPixel (INTEGER,INTEGER,INTEGER) AS Pixel
SCREENRES 800,600,24,2
WP=1
SCREENSET WP,WP XOR 1
RANDOMIZE TIMER
FOR I=1 TO 5000
    CIRCLE (INT(RND*800),INT(RND*600)),INT(RND*30),RGB(INT(RND*255),INT(RND*255),INT(RND*255))
NEXT
DIM AS Pixel BlurredPixel
FOR X=300 TO 500
    FOR Y=200 TO 400
        BlurredPixel=BlurPixel(X,Y,1)
        PSET (X,Y),RGB(BlurredPixel.R,BlurredPixel.G,BlurredPixel.B)
    NEXT
NEXT
WP=WP XOR 1
SCREENSET WP,WP XOR 1
SLEEP
FUNCTION BlurPixel (X AS INTEGER,Y AS INTEGER,Intensity AS INTEGER) AS Pixel
    DIM AS Pixel RetPixel
    DIM AS INTEGER StartX,EndX,StartY,EndY,CDepth,ScreenHeight,ScreenWidth,FX,FY,PHits
    IF Intensity<=0 THEN Intensity=1
    StartX=X-Intensity
    EndX=X+Intensity
    StartY=Y-Intensity
    EndY=Y+Intensity
    SCREENINFO ScreenWidth,ScreenHeight,CDepth
    IF CDepth=8 THEN
        RetPixel.R=-1
        RetPixel.G=-1
        RetPixel.B=-1
        RETURN RetPixel
    END IF
    IF StartX<=0 THEN StartX=0
    IF EndX>=ScreenWidth THEN EndX=ScreenWidth
    IF StartY<=0 THEN StartY=0
    IF EndY>=ScreenWidth THEN EndY=ScreenWidth
    FOR FX=StartX TO EndX
        FOR FY=StartY TO EndY
            RetPixel.R+=(POINT(FX,FY) AND &HFF0000) SHR 16
            RetPixel.G+=(POINT(FX,FY) AND &HFF00) SHR 8
            RetPixel.B+=(POINT(FX,FY) AND &HFF)
            PHits+=1
        NEXT
    NEXT
    RetPixel.R/=PHits
    RetPixel.G/=PHits
    RetPixel.B/=PHits
    RETURN RetPixel
END FUNCTION
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#25
Oh, and here's a standalone module that can be used.
Code:
'BlurPixel.Bas
'By Zachary Vernon
'Contains BlurPixel function, an essential TYPE, and the function declaration.
'Date (mm/dd/yy): 02/10/06
'Usage: BlurPixel (X,Y,I)
'       Returns a Pixel TYPE with the R, G and B value for the blurred
'       version of pixel (X,Y), with I blurring intensity. I must be > 0, otherwise it is
'       set to 1.
'       Pixel TYPE contains three variables: R, G and B, each representing
'       the red, green and blue value of a pixel.
'       IMPORTANT: Colour depth must be 16 bits or higher, otherwise BlurPixel()
'                  returns -1 for R, G and B.
TYPE Pixel
    R AS INTEGER
    G AS INTEGER
    B AS INTEGER
END TYPE
DECLARE FUNCTION BlurPixel (INTEGER,INTEGER,INTEGER) AS Pixel
FUNCTION BlurPixel (X AS INTEGER,Y AS INTEGER,Intensity AS INTEGER) AS Pixel
    DIM AS Pixel RetPixel
    DIM AS INTEGER StartX,EndX,StartY,EndY,CDepth,ScreenHeight,ScreenWidth,FX,FY,PHits
    IF Intensity<=0 THEN Intensity=1
    StartX=X-Intensity
    EndX=X+Intensity
    StartY=Y-Intensity
    EndY=Y+Intensity
    SCREENINFO ScreenWidth,ScreenHeight,CDepth
    IF CDepth=8 THEN
        RetPixel.R=-1
        RetPixel.G=-1
        RetPixel.B=-1
        RETURN RetPixel
    END IF
    IF StartX<=0 THEN StartX=0
    IF EndX>=ScreenWidth THEN EndX=ScreenWidth
    IF StartY<=0 THEN StartY=0
    IF EndY>=ScreenWidth THEN EndY=ScreenWidth
    FOR FX=StartX TO EndX
        FOR FY=StartY TO EndY
            RetPixel.R+=(POINT(FX,FY) AND &HFF0000) SHR 16
            RetPixel.G+=(POINT(FX,FY) AND &HFF00) SHR 8
            RetPixel.B+=(POINT(FX,FY) AND &HFF)
            PHits+=1
        NEXT
    NEXT
    RetPixel.R/=PHits
    RetPixel.G/=PHits
    RetPixel.B/=PHits
    RETURN RetPixel
END FUNCTION
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#26
looks loads better than your first one.

a little tip, that may make it faster
replace this...
Code:
FOR FX=StartX TO EndX
        FOR FY=StartY TO EndY
            RetPixel.R+=(POINT(FX,FY) AND &HFF0000) SHR 16
            RetPixel.G+=(POINT(FX,FY) AND &HFF00) SHR 8
            RetPixel.B+=(POINT(FX,FY) AND &HFF)
            PHits+=1
        NEXT
    NEXT
With this, and hopefully it will go faster, because POINT can be slow, calling it three times with the same values could be a waste. I haven't actually checked, but i expect this would be faster.
Code:
Dim c As uInteger
    FOR FX=StartX TO EndX
        FOR FY=StartY TO EndY
            c = POINT(FX,FY)
            RetPixel.R+=(c AND &HFF0000) SHR 16
            RetPixel.G+=(c AND &HFF00) SHR 8
            RetPixel.B+=(c AND &HFF)
            PHits+=1
        NEXT
    NEXT
EVEN MEN OF STEEL RUST.
[Image: chav.gif]
Reply
#27
Excellent point, my friend. Let's test it...
Whoo-ee! It's three times faster that way.
Corrected code, yet again...
Code:
'BlurPixel.Bas
'By Zachary Vernon
'Contains BlurPixel function, an essential TYPE, and the function declaration.
'Date (mm/dd/yy): 02/10/06
'Usage: BlurPixel (X,Y,I)
'       Returns a Pixel TYPE with the R, G and B value for the blurred
'       version of pixel (X,Y), with I  blurring intensity. I must be > 0, otherwise it is
'       set to 1.
'       Pixel TYPE contains three variables: R, G and B, each representing
'       the red, green and blue value of a pixel.
'       IMPORTANT: Colour depth must be 16 bits or higher, otherwise BlurPixel()
'                  returns -1 for R, G and B.
TYPE Pixel
    R AS INTEGER
    G AS INTEGER
    B AS INTEGER
END TYPE
DECLARE FUNCTION BlurPixel (INTEGER,INTEGER,INTEGER) AS Pixel
FUNCTION BlurPixel (X AS INTEGER,Y AS INTEGER,Intensity AS INTEGER) AS Pixel
    DIM AS Pixel RetPixel
    DIM AS INTEGER StartX,EndX,StartY,EndY,CDepth,ScreenHeight,ScreenWidth,FX,FY,PHits,C
    IF Intensity<=0 THEN Intensity=1
    StartX=X-Intensity
    EndX=X+Intensity
    StartY=Y-Intensity
    EndY=Y+Intensity
    SCREENINFO ScreenWidth,ScreenHeight,CDepth
    IF CDepth=8 THEN
        RetPixel.R=-1
        RetPixel.G=-1
        RetPixel.B=-1
        RETURN RetPixel
    END IF
    IF StartX<=0 THEN StartX=0
    IF EndX>=ScreenWidth THEN EndX=ScreenWidth
    IF StartY<=0 THEN StartY=0
    IF EndY>=ScreenWidth THEN EndY=ScreenWidth
    FOR FX=StartX TO EndX
        FOR FY=StartY TO EndY
            C=POINT(FX,FY)
            RetPixel.R+=(C AND &HFF0000) SHR 16
            RetPixel.G+=(C AND &HFF00) SHR 8
            RetPixel.B+=(C AND &HFF)
            PHits+=1
        NEXT
    NEXT
    RetPixel.R/=PHits
    RetPixel.G/=PHits
    RetPixel.B/=PHits
    RETURN RetPixel
END FUNCTION
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#28
Don't forget to fix this too...

Code:
IF StartX<=0 THEN StartX=0
IF EndX>=ScreenWidth THEN EndX=ScreenWidth
IF StartY<=0 THEN StartY=0
IF EndY>=ScreenWidth THEN EndY=[b]ScreenWidth[/b]

You should also subtract one from screenwidth/screenheight. That way it doesn't try to sample pixels that are off of the screen. Blur the whole screen and you'll see what I mean. Wink
Reply
#29
Oy Vey, so many things!! Thanks, Doc. Big Grin
Code:
'BlurPixel.Bas
'By Zachary Vernon
'Contains BlurPixel function, an essential TYPE, and the function declaration.
'Date (mm/dd/yy): 02/10/06
'Usage: BlurPixel (X,Y,I)
'       Returns a Pixel TYPE with the R, G and B value for the blurred
'       version of pixel (X,Y), with I  blurring intensity. I must be > 0, otherwise it is
'       set to 1.
'       Pixel TYPE contains three variables: R, G and B, each representing
'       the red, green and blue value of a pixel.
'       IMPORTANT: Colour depth must be 16 bits or higher, otherwise BlurPixel()
'                  returns -1 for R, G and B.
TYPE Pixel
    R AS INTEGER
    G AS INTEGER
    B AS INTEGER
END TYPE
DECLARE FUNCTION BlurPixel (INTEGER,INTEGER,INTEGER) AS Pixel
FUNCTION BlurPixel (X AS INTEGER,Y AS INTEGER,Intensity AS INTEGER) AS Pixel
    DIM AS Pixel RetPixel
    DIM AS INTEGER StartX,EndX,StartY,EndY,CDepth,ScreenHeight,ScreenWidth,FX,FY,PHits,C
    IF Intensity<=0 THEN Intensity=1
    StartX=X-Intensity
    EndX=X+Intensity
    StartY=Y-Intensity
    EndY=Y+Intensity
    SCREENINFO ScreenWidth,ScreenHeight,CDepth
    IF CDepth=8 THEN
        RetPixel.R=-1
        RetPixel.G=-1
        RetPixel.B=-1
        RETURN RetPixel
    END IF
    IF StartX<=0 THEN StartX=0
    IF EndX>=ScreenWidth THEN EndX=ScreenWidth - 1
    IF StartY<=0 THEN StartY=0
    IF EndY>=ScreenWidth THEN EndY=ScreenHeight - 1
    FOR FX=StartX TO EndX
        FOR FY=StartY TO EndY
            C=POINT(FX,FY)
            RetPixel.R+=(C AND &HFF0000) SHR 16
            RetPixel.G+=(C AND &HFF00) SHR 8
            RetPixel.B+=(C AND &HFF)
            PHits+=1
        NEXT
    NEXT
    RetPixel.R/=PHits
    RetPixel.G/=PHits
    RetPixel.B/=PHits
    RETURN RetPixel
END FUNCTION
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#30
Hmm... almost got it. Look at this line again... Wink

IF EndY>=ScreenWidth THEN EndY=ScreenHeight - 1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)