Qbasicnews.com
May 11, 2021, 10:58:47 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3
  Print  
Author Topic: Antialiasing  (Read 12412 times)
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #15 on: February 08, 2006, 09:13:29 PM »

I don't understand all of it, but it works much better than mine. Tongue
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #16 on: February 08, 2006, 09:21:21 PM »

What is it that you don't understand? I'd be glad to explain... or I'm sure someone else will.  Cool
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #17 on: February 09, 2006, 01:08:35 PM »

Well...how it works, for one. Tongue  It doesn't resemble my code at all.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
yetifoot
Ancient Guru
****
Posts: 575



« Reply #18 on: February 09, 2006, 04:18:26 PM »

his is still the same principle, which is an average of surrounding colours, but his has strength, which is how many pixels are sampled.
Logged

EVEN MEN OF STEEL RUST.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #19 on: February 09, 2006, 04:23:54 PM »

Well I looked at every line of the code and I understand it now.
But why does his maintain colour while mine makes everything grey?
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
yetifoot
Ancient Guru
****
Posts: 575



« Reply #20 on: February 09, 2006, 06:50:58 PM »

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
Logged

EVEN MEN OF STEEL RUST.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #21 on: February 09, 2006, 10:44:53 PM »

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
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Z!re
*/-\*
*****
Posts: 4599


« Reply #22 on: February 10, 2006, 06:37:51 AM »

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
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #23 on: February 10, 2006, 01:43:14 PM »

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
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #24 on: February 10, 2006, 01:55:18 PM »

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
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
yetifoot
Ancient Guru
****
Posts: 575



« Reply #25 on: February 10, 2006, 03:23:38 PM »

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
Logged

EVEN MEN OF STEEL RUST.
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #26 on: February 10, 2006, 04:23:28 PM »

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
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #27 on: February 10, 2006, 07:34:11 PM »

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
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #28 on: February 11, 2006, 11:01:35 PM »

Oy Vey, so many things!! Thanks, Doc. Cheesy
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
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #29 on: February 11, 2006, 11:11:58 PM »

Hmm... almost got it. Look at this line again... Wink

IF EndY>=ScreenWidth THEN EndY=ScreenHeight - 1
Logged
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!