I revised my anti aliasing program (again), but the colors are completely wrong. I checking the averaging algorithm and it seems fine...but the program just doesn't work...I have no idea what the issue is..
Source code (I added comments) :
SCREEN _NEWIMAGE(1280, 720, 32)
' Draws some shapes to test the subroutine
'LINE (0, 0)-(720, 720), _RGB(255, 0, 0)
CIRCLE (500, 500), 100, _RGB(255, 255, 255)
PAINT (500, 500), _RGB(255, 255, 255), _RGB(255, 255, 255)
'call the sub after drawing the shapes.
CALL antialias(1280, 720)
SUB antialias (screenx, screeny)
FOR dx = 1 TO screenx - 1 'goes through each pixel for the entire area of the screen
FOR dy = 1 TO screeny - 1
averagecolor~&& = 0 'reset average color and other values
difpix = 0
op~&& = POINT(dx, dy) ' get the color of the main pixel
FOR cx = -1 TO 1 'gets the 8 pixels around (dx,dy)
FOR cy = -1 TO 1
cp~&& = POINT(dx + cx, dy + cy) 'get the color of each of the 8 pixels
IF (cp~&& > op~&& AND (cp~&& / op~&&) > 1.000459770087633) OR (op~&& > cp~&& AND (op~&& / cp~&& > 1.000459770087633)) THEN difpix = difpix + 1
'check if the colors of the pixels are different enough to antialias them
averagecolor~&& = averagecolor~&& + (cp~&& / 9)
'find the average color of (dx,dy) and the 8 pixels surrounding it regardless of whether the pixel needs antialiasing
NEXT cy
NEXT cx
IF difpix >= 1 AND difpix < 5 THEN 'if there are different colored pixels among the 8
'(but not too many otherwise it would antialias a 1-pixel line causing it to lose color. EG. any point on a vertical 1-pixel line has 6 different colored pixels around it)
' antialiasing this sort of line would only cause it to lose color
PSET (dx, dy), averagecolor~&&
'PRINT , dx, dy, _RED32(averagecolor~&&), _GREEN32(averagecolor~&&), _BLUE32(averagecolor~&&)
'SLEEP
'For debugging - goes through each pixel which needs to be antialiased and gives its
' coordinates and RGB values.
END IF
NEXT dy
NEXT dx
END SUB