The MASM Forum

General => The Laboratory => Topic started by: daydreamer on July 19, 2020, 09:02:07 PM

Title: antialias ???
Post by: daydreamer on July 19, 2020, 09:02:07 PM
I try to make a antialias code ,starting with 4 pixels calculate average, but replace the (a+b+c+d)/4,with some downsizing to get gray pixels and replace black pixels with gray to start with?what % white pixels should  grey be?
trying with SSE2 integer instructions
tests with pixel a=0,b= c= d=127
;a,b,c,d different pixels in a square 2x2
movd mm0, a ;start with get it right with 1pixel/register first
movd mm1, b
movd mm2, c
movd mm3, d
psrlw mm0, 2 ;downsizing before,otherwise endresult doesnt fit into byte
pand mm0, mask2
psrlw mm1, 2
pand mm1, mask2
psrlw mm2, 2
pand mm2, mask2
psrlw mm3, 2
pand mm3, mask2
paddusb mm0, mm1;add together 4pixels
paddusb mm2, mm3
paddusb mm0, mm2
; psrlw mm0, ?
; pand mm0,mask2
movd eax, mm0

mov result, eax;
Title: Re: antialias ???
Post by: daydreamer on July 25, 2020, 02:42:59 AM
maybe should cmp each pixel against threshold value,median or average so black/darkest pixels below threshold add pixel, grey,lightest pixels you sub pixel,grey
; a, b, c, d different pixels in a square 2x2
pxor mm7, mm7
movq mm7, unpt
movd mm0, a
movd mm1, b
movd mm2, c
movd mm3, d
movq mm6, mm3

paddd mm0, mm1
paddd mm2, mm3
paddd mm0, mm2
movq mm6, mm0
psrld mm0, 2;average /4
psrld mm6,3;grey1
movq mm5,mm6
movd a,mm6
    psrld mm6,1 ;darker grey


movd eax, mm0

mov result, eax;
Title: Re: antialias ???
Post by: Siekmanski on July 25, 2020, 04:36:44 AM
You could change the aplha channel to a lower value for the surrounding pixels, its easier and no averaging calculations just set the alpha color.
Title: Re: antialias ???
Post by: daydreamer on July 25, 2020, 06:14:22 AM
Quote from: Siekmanski on July 25, 2020, 04:36:44 AM
You could change the aplha channel to a lower value for the surrounding pixels, its easier and no averaging calculations just set the alpha color.
thanks