Qbasicnews.com
April 12, 2021, 06:37:17 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 12251 times)
Zack
*/-\*
*****
Posts: 3974



WWW
« on: February 07, 2006, 11:51:08 PM »

Can anyone point me to a standalone antialiasing function for FB? Any colour depth will do.
Or how could I make one myself?
Logged

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



« Reply #1 on: February 08, 2006, 12:22:41 AM »

The colors would have to be in truecolor mode which I believe is 32 and the RGB values of the colors would have to be stored in variables then modified using a counnting algorythm.  That' my opinion, or maybe put the image down using ALPHA then a 1 pixel smaller version of the picture etc. for the count or steps.  It's only a theory, maybe I just got the ball rolling up a hill, or maybe down.  It's a thinker... :Huh:
Logged
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #2 on: February 08, 2006, 12:59:36 AM »

There's a way you could do it here...

http://forum.qbasicnews.com/viewtopic.php?t=11293

It's more like a blur, but it works. Wink
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #3 on: February 08, 2006, 07:54:57 AM »

If you want antialiased lines peek in the FAQ, I posted something that may give you a start.

If you just need bluring a bitmap, the thing consists on, for each pixel, add the value of the 8 pixels that surround it and the pixel, then divide by 9.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
yetifoot
Ancient Guru
****
Posts: 575



« Reply #4 on: February 08, 2006, 10:26:36 AM »

Look up laplace kernel filtering.  Also look at the comp.graphics.algorithms FAQ
Logged

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



WWW
« Reply #5 on: February 08, 2006, 12:18:30 PM »

Quote from: "na_th_an"
If you want antialiased lines peek in the FAQ, I posted something that may give you a start.

If you just need bluring a bitmap, the thing consists on, for each pixel, add the value of the 8 pixels that surround it and the pixel, then divide by 9.
I think a blur will do. So, for instance in 8-bit colour, I add up all the values of the eight pixels that surround one pixel and divide that value by nine, and replace the original pixel with one of that colour?
Logged

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



WWW
« Reply #6 on: February 08, 2006, 01:21:10 PM »

It won't work in 8 bits mode unless the palette is a gradient. You can get funny effects, tho'.

Bluring in 8 bits is tricky. You wether use gradients in your palette and make sure the limits are not exceded OR you have to blur in truecolour and then convert/dither to 8 bits, which would be slow.

Doing it in 16 or 32 bits modes is a matter of performing the above mentioned average for each colour component R, G, B, then build the pixel and write it.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #7 on: February 08, 2006, 03:17:26 PM »

Got it, thanks.
Heh heh heh, and excuse to use highcolour mode! Cheesy
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 #8 on: February 08, 2006, 04:20:40 PM »

So let's see what you made.  Tongue
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #9 on: February 08, 2006, 04:37:03 PM »

I'm working on it. Smiley
Any ideas on how to extract a particular part of an RGB value? If I use POINT to get the RGB value of a pixel, how can I extract just the R, G or B part?
Logged

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



« Reply #10 on: February 08, 2006, 04:46:37 PM »

there are various ways, but i use this

C = RGB(64, 127, 234)

B = C AND &HFF
G = (C AND &HFF00) SHR 8
R = (C AND &HFF0000) SHR 16

Print R, G, B

Sleep
Logged

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



WWW
« Reply #11 on: February 08, 2006, 04:47:41 PM »

Thanks yetifoot. Bitwise operators to the rescue!
Logged

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



WWW
« Reply #12 on: February 08, 2006, 05:28:44 PM »

OK, I have some extremely crude code. It does blur, but it makes everything that was blurred look grey.
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 1000
    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(1).B=TM AND &HFF
        Pixels(1).B=TR AND &HFF
        Pixels(1).B=ML AND &HFF
        Pixels(1).B=MM AND &HFF
        Pixels(1).B=MR AND &HFF
        Pixels(1).B=BL AND &HFF
        Pixels(1).B=BM AND &HFF
        Pixels(1).B=BR AND &HFF
       
        FOR I=1 TO 9
            RetPixel.R=RetPixel.R+Pixels(I).R
            RetPixel.G=RetPixel.R+Pixels(I).G
            RetPixel.B=RetPixel.R+Pixels(I).B
        NEXT
        RetPixel.R=RetPixel.R/9
        RetPixel.G=RetPixel.G/9
        RetPixel.B=RetPixel.B/9
        RETURN RetPixel
END FUNCTION

I know, I know...But I couldn't think of an elegant way to do it! Tongue
Logged

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



« Reply #13 on: February 08, 2006, 06:15:12 PM »

heres some code from an old VB project of mine.  Couldn't be bothered to update it yet!

the iDATA array is :first part is for rgb then second and third are x and y

hope it helps, maybe i'll convert it at some point.

Code:
Private Sub Smooth()
  Dim X As Long, Y As Long
  Dim r As Long, G As Long, B As Long

  For Y = 2 To PicInfo.bmHeight - 1
    For X = 2 To PicInfo.bmWidth - 1
      B = CLng(iDATA(1, X, Y)) + _
        CLng(iDATA(1, X - 1, Y)) + CLng(iDATA(1, X, Y - 1)) + _
        CLng(iDATA(1, X, Y + 1)) + CLng(iDATA(1, X + 1, Y))
      B = B \ 5
      G = CLng(iDATA(2, X, Y)) + _
        CLng(iDATA(2, X - 1, Y)) + CLng(iDATA(2, X, Y - 1)) + _
        CLng(iDATA(2, X, Y + 1)) + CLng(iDATA(2, X + 1, Y))
      G = G \ 5
      r = CLng(iDATA(3, X, Y)) + _
        CLng(iDATA(3, X - 1, Y)) + CLng(iDATA(3, X, Y - 1)) + _
        CLng(iDATA(3, X, Y + 1)) + CLng(iDATA(3, X + 1, Y))
      r = r \ 5
      iDATA(1, X, Y) = B
      iDATA(2, X, Y) = G
      iDATA(3, X, Y) = r
    Next X
  Next Y
End Sub
Logged

EVEN MEN OF STEEL RUST.
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #14 on: February 08, 2006, 07:48:17 PM »

I changed a few things out of habit. It's basically what I did on that landmaker algo thing. Wink

Code:
Option Explicit
Const Scr_Width As Integer = 320
Const SCR_Height As Integer = 200
Const Bits_Per_Plane As Integer = 24

Screenres Scr_Width,Scr_Height,Bits_Per_Plane
Randomize Timer

Type Pixel
    R As Integer
    G As Integer
    B As Integer
End Type

Declare Function BlurPixel(Byval X As Integer, Byval Y As Integer, Byval Strength As Integer) As Pixel

Dim As Pixel NewPixel
Dim As Integer I, X, Y

For I = 1 To 1000
    Circle (Int(Rnd*300),Int(Rnd*200)),Int(Rnd*15),Rgb(Int(Rnd*255),Int(Rnd*255),Int(Rnd*255))
Next
Sleep


For X=100 To 200
    For Y=50 To 150
        NewPixel = BlurPixel(X, Y, 1)
        Pset (X,Y),Rgb(NewPixel.R,NewPixel.G,NewPixel.B)
    Next
Next
Sleep





Function BlurPixel(Byval X As Integer, Byval Y As Integer, Byval Strength As Integer) As Pixel
    Dim As Integer ScanX, Scany, StartX, EndX, StartY, EndY, TempCol, Hits
    Dim TempRGB As Pixel
   
    If Strength <=0 Then
        TempCol = Point(X,Y)
        TempRGB.R += ((TempCol Shr 16) And &HFF)
        TempRGB.G += ((TempCol Shr 8 ) And &HFF)
        TempRGB.B += ((TempCol       ) And &HFF)
        Function = TempRGB
        Exit Function
    End If    
   
    StartY= Y-Strength
    EndY  = Y+Strength
    StartX= X-Strength
    EndX  = X+Strength
   
    If StartY< 0  Then StartY = 0
    If StartX< 0  Then StartX = 0
    If EndY>Scr_Height-1 Then EndY=Scr_Height-1
    If EndX>Scr_Width-1 Then EndX=Scr_Width-1
   
    For ScanY = StartY To EndY
        For ScanX = StartX To EndX
            TempCol = Point(ScanX,ScanY)
            TempRGB.R += ((TempCol Shr 16) And &HFF)
            TempRGB.G += ((TempCol Shr 8 ) And &HFF)
            TempRGB.B += ((TempCol       ) And &HFF)
            Hits+=1
        Next
    Next
   
    TempRgb.R\=Hits
    TempRgb.G\=Hits
    TempRgb.B\=Hits
   
    Function = TempRGB
End Function
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!