macroScript compareAA category:"Bobo_s Tools"
(

--Compare AntiAliasing FIlters
--Version 0.31
--Started: 9/23/99
--Edited:  9/25/99
--by Borislav Petrov
--http://gfxcentral.com/bobo/
--------------------------------------------------



global compaa_floater 

rollout compaa_roll "Compare AA"
(

group "Filter 1"
(
colorpicker color1 color:(color 255 128 128) height:10 width:120 align:#center
checkbox filter_on1 checked:true across:2 align:#left
dropdownlist filter_one items:#("Area","Blackman","Blend","Catmull_Rom","Cook_Var","Cubic","Mit-Net","Plate","Quadratic","Sharp_Quad","Soften","Video") width:100 align:#right
checkbox use_fsize1 checked:true across:2 align:#left
spinner f_size1 "Filter Size" range:[1.0,10000,1.5] align:#right fieldwidth:40
spinner f_blend1 "Blend" range:[0,1,0.3] align:#right fieldwidth:40 enabled:false
spinner f_blur1 "M-N Blend" range:[0,1,0.3] align:#right fieldwidth:40 enabled:false
spinner f_ring1 "M-N Ringing" range:[0,1,0.3333] align:#right fieldwidth:40 enabled:false
)

group "Filter 2"
(
colorpicker color2 color:(color 128 255 128) height:10 width:120 align:#center
checkbox filter_on2 checked:true across:2 align:#left
dropdownlist filter_two items:#("Area","Blackman","Blend","Catmull_Rom","Cook_Var","Cubic","Mit-Net","Plate","Quadratic","Sharp_Quad","Soften","Video") width:100 selection:2 align:#right
checkbox use_fsize2 checked:true across:2 align:#left
spinner f_size2 "Filter Size" range:[1.0,10000,1.5] align:#right fieldwidth:40 enabled:false
spinner f_blend2 "Blend" range:[0,1,0.3] align:#right fieldwidth:40 enabled:false
spinner f_blur2 "M-N Blend" range:[0,1,0.3] align:#right fieldwidth:40 enabled:false
spinner f_ring2 "M-N Ringing" range:[0,1,0.3333] align:#right fieldwidth:40 enabled:false
)


spinner strip_s "Strip Width" range:[1,1000,20] type:#integer align:#center
dropdownlist strip_mode items:#("Vertical Strips","Horizontal Strips","Checkerboard","RAMplayer")
dropdownlist show_strip_mode items:#("Edge Marking","Line Marking","No Strip Marking")
button compare_it "COMPARE FILTERS" width:130 height:30 align:#center


fn save_ini =
(
ini_file = createfile (scriptspath+"\\aacompare.ini")
format "%\n" "[AAcompare]" to:ini_file
format "%\n" (color1.color as string) to:ini_file
format "%\n" (filter_on1.state as string) to:ini_file
format "%\n" (filter_one.selection as string) to:ini_file
format "%\n" (use_fsize1.state as string) to:ini_file
format "%\n" (f_size1.value as string) to:ini_file
format "%\n" (f_blend1.value as string) to:ini_file
format "%\n" (f_blur1.value as string) to:ini_file
format "%\n" (f_ring1.value as string) to:ini_file

format "%\n" (color2.color as string) to:ini_file
format "%\n" (filter_on2.state as string) to:ini_file
format "%\n" (filter_two.selection as string) to:ini_file
format "%\n" (use_fsize2.state as string) to:ini_file
format "%\n" (f_size2.value as string) to:ini_file
format "%\n" (f_blend2.value as string) to:ini_file
format "%\n" (f_blur2.value as string) to:ini_file
format "%\n" (f_ring2.value as string) to:ini_file

format "%\n" (strip_s.value as string) to:ini_file
format "%\n" (strip_mode.selection as string) to:ini_file
format "%\n" (show_strip_mode.selection as string) to:ini_file

close ini_file
)

on color1 changed color do save_ini ()
on filter_on1 changed state do save_ini ()
on use_fsize1 changed state do save_ini ()
on f_size1 changed value do save_ini ()
on f_blend1 changed value do save_ini ()
on f_blur1 changed value do save_ini ()
on f_ring1 changed value do save_ini ()

on color2 changed color do save_ini ()
on filter_on2 changed state do save_ini ()
on use_fsize2 changed state do save_ini ()
on f_size2 changed value do save_ini ()
on f_blend2 changed value do save_ini ()
on f_blur2 changed value do save_ini ()
on f_ring2 changed value do save_ini ()

on strip_s changed value do save_ini ()
on strip_mode selected itm do save_ini ()
on show_strip_mode selected itm do save_ini ()


on filter_one selected itm do
(
f_size1.enabled = true
f_blend1.enabled = false
f_blur1.enabled = false
f_ring1.enabled = false

if itm == 2 or itm == 4 or itm == 6 or itm == 7 or itm == 9 or itm == 10 or itm == 12 then f_size1.enabled = false
if itm == 3 then f_blend1.enabled = true
if itm == 7 then 
	(
	f_blur1.enabled = true
	f_ring1.enabled = true
	)

save_ini ()
)

on filter_two selected itm do
(
f_size2.enabled = true
f_blend2.enabled = false
f_blur2.enabled = false
f_ring2.enabled = false

if itm == 2 or itm == 4 or itm == 6 or itm == 7 or itm == 9 or itm == 10 or itm == 12 then f_size2.enabled = false
if itm == 3 then f_blend2.enabled = true
if itm == 7 then 
	(
	f_blur2.enabled = true
	f_ring2.enabled = true
	)
save_ini ()
)




on compare_it pressed do
(

old_size = scanlineRender.antiAliasFilterSize 
old_filter = scanlineRender.antiAliasFilter

f1 = filter_one.selection 
f2 = filter_two.selection 
strip_size = strip_s.value



case f1 of
(
1: (
	filt1 = Area()
	fsize1 = 1.5
	)
2: (
	filt1 = Blackman()
	fsize1 = 4
	)
3: (
	filt1 = Blendfilter blend:f_blend1.value
	fsize1 = 8.0
	)
4: (
	filt1 = Catmull_Rom()
	fsize1 = 4.0
	)
5: (
	filt1 = Cook_Variable()
	fsize1 = 2.5
	)
6: (
	filt1 = Cubic()
	fsize1 = 4.0
	)
7: (
	filt1 = Mitchell_Netravali blur:f_blur1.value ringing:f_ring1.value
	fsize1 = 4.0
	)
8: (
	filt1 = Plate_Match_MAX_R2()
	fsize1 = 1.5
	)
9: (
	filt1 = Quadratic()
	fsize1 = 3.0
	)
10: (
	filt1 = Sharp_Quadratic()
	fsize1 = 2.8
	)
11: (
	filt1 = Soften()
	fsize1 = 6.0
	)
12: (
	filt1 = Video()
	fsize1 = 4.0
	)
)

if use_fsize1.checked then fsize1 = f_size1.value

case f2 of
(
1: (
	filt2 = Area()
	fsize2 = 1.5
	)
2: (
	filt2 = Blackman()
	fsize2 = 4
	)
3: (
	filt2 = Blendfilter blend:f_blend2
	fsize2 = 8.0
	)
4: (
	filt2 = Catmull_Rom()
	fsize2 = 4.0
	)
5: (
	filt2 = Cook_Variable()
	fsize2 = 2.5
	)
6: (
	filt2 = Cubic()
	fsize2 = 4.0
	)
7: (
	filt2 = Mitchell_Netravali blur:f_blur2.value ringing:f_ring2.value
	fsize2 = 4.0
	)
8: (
	filt2 = Plate_Match_MAX_R2()
	fsize2 = 1.5
	)
9: (
	filt2 = Quadratic()
	fsize2 = 3.0
	)
10: (
	filt2 = Sharp_Quadratic()
	fsize2 = 2.8
	)
11: (
	filt2 = Soften()
	fsize2 = 6.0
	)
12: (
	filt2 = Video()
	fsize2 = 4.0
	)
)

if use_fsize2.checked then fsize2 = f_size2.value

progressstart "Rendering AA Test"

bmp1 = render antiAliasFilter:filt1 vfb:off antiAliasing:filter_on1.checked antiAliasFilterSize:fsize1 
bmp2 = render antiAliasFilter:filt2 vfb:off antiAliasing:filter_on2.checked antiAliasFilterSize:fsize2 


if strip_mode.selection == 4 then
(
bmp1.filename = ((GetDir #image)+"\\aacompare1.tga")
save bmp1
bmp2.filename = ((GetDir #image)+"\\aacompare2.tga")
save bmp2
ramPlayer bmp1.filename bmp2.filename
close bmp1
close bmp2
)


if strip_mode.selection == 1 then
(
for j = 0 to bmp1.height-1 do
(
progressupdate (j/bmp1.height as float*100.0)

for k = 0 to (bmp1.width/(strip_size*2.0)) do
(
get_pixels = getPixels bmp1 [k*strip_size*2.0,j] (strip_size)
setPixels bmp2 [(k*strip_size*2.0),j] get_pixels

if show_strip_mode.selection == 2 then
(
red_line = #()
append red_line color1.color
green_line = #()
append green_line color2.color
setPixels bmp2 [k*strip_size*2.0,j] red_line
setPixels bmp2 [k*strip_size*2.0+strip_size,j] green_line
)
)
)

if show_strip_mode.selection == 1 then
(
red_line = #()
for i = 1 to strip_size do append red_line color1.color
green_line = #()
for i = 1 to strip_size do append green_line color2.color
for k = 0 to (bmp1.width/(strip_size*2.0)) do
(
setPixels bmp2 [k*strip_size*2.0,0] red_line
setPixels bmp2 [k*strip_size*2.0,bmp1.height-1] red_line
setPixels bmp2 [k*strip_size*2.0+strip_size,0] green_line
setPixels bmp2 [k*strip_size*2.0+strip_size,bmp1.height-1] green_line
)
)
)--end mode 1


if strip_mode.selection == 2 then
(


if show_strip_mode.selection == 1 then
(
red_line = #()
append red_line color1.color
green_line = #()
append green_line color2.color
)

if show_strip_mode.selection == 2 then
(
red_line = #()
green_line = #()
for l = 1 to bmp1.width do 
	(
	append red_line color1.color
	append green_line color2.color
	)
)


for k = 0 to bmp1.height by (strip_size*2.0) do
(
progressupdate (k/bmp1.height as float*100.0)

for j = k to k+strip_size do
(
get_pixels = getPixels bmp1 [0,j] bmp1.width
setPixels bmp2 [0,j] get_pixels

if show_strip_mode.selection == 1 then
(
setPixels bmp2 [0,j] red_line
setPixels bmp2 [bmp1.width-1,j] red_line
setPixels bmp2 [0,j+strip_size] green_line
setPixels bmp2 [bmp1.width-1,j+strip_size] green_line
)
)

if show_strip_mode.selection == 2 then
(
setPixels bmp2 [0,k] red_line
setPixels bmp2 [0,k+strip_size] green_line
)
)

)--end mode 2



if strip_mode.selection == 3 then
(
alternate = 0
counter = 0

for j = 0 to bmp1.height-1 do
(
counter += 1
if counter == strip_size then 
(
alternate = 1 - alternate
counter = 0
)

print alternate

progressupdate (j/bmp1.height as float*100.0)

for k = 0 to (bmp1.width/strip_size*2.0) do
(
if alternate == 0 then
(
get_pixels = getPixels bmp1 [k*strip_size*2.0,j] (strip_size)
setPixels bmp2 [(k*strip_size*2.0),j] get_pixels

if show_strip_mode.selection == 1 then
(
red_line = #()
append red_line color1.color
green_line = #()
append green_line color2.color
setPixels bmp2 [0,j] red_line

red_line = #()
for i = 1 to strip_size do append red_line color1.color
green_line = #()
for i = 1 to strip_size do append green_line color2.color

if ((j+1) as float) / strip_size == floor (((j+1) as float) /strip_size) then
(
setPixels bmp2 [k*strip_size*2.0,0] red_line

)
)

if show_strip_mode.selection == 2 then
(
red_line = #()
append red_line color1.color
green_line = #()
append green_line color2.color
setPixels bmp2 [k*strip_size*2.0,j] red_line
setPixels bmp2 [k*strip_size*2.0+strip_size,j] green_line

red_line = #()
for i = 1 to strip_size do append red_line color1.color
green_line = #()
for i = 1 to strip_size do append green_line color2.color

if ((j+1) as float) / strip_size == floor (((j+1) as float) /strip_size) then
(
setPixels bmp2 [k*strip_size*2.0,j] red_line
setPixels bmp2 [k*strip_size*2.0+strip_size,j] green_line
)
)


)
else
(
get_pixels = getPixels bmp1 [k*strip_size*2.0+strip_size,j] (strip_size)
setPixels bmp2 [(k*strip_size*2.0+strip_size),j] get_pixels


if show_strip_mode.selection == 1 then
(
green_line = #()
append green_line color2.color
setPixels bmp2 [0,j] green_line

green_line = #()
for i = 1 to strip_size do append green_line color2.color

if ((j+1) as float) / strip_size == floor (((j+1) as float) /strip_size) then
(
setPixels bmp2 [k*strip_size*2.0+strip_size,0] green_line
)
)

if show_strip_mode.selection == 2 then
(
red_line = #()
append red_line color1.color
green_line = #()
append green_line color2.color
setPixels bmp2 [k*strip_size*2.0,j] green_line
setPixels bmp2 [k*strip_size*2.0+strip_size,j] red_line

red_line = #()
for i = 1 to strip_size do append red_line color1.color
green_line = #()
for i = 1 to strip_size do append green_line color2.color

if ((j+1) as float) / strip_size == floor (((j+1) as float) /strip_size) then
(
setPixels bmp2 [k*strip_size*2.0+strip_size,j] red_line
setPixels bmp2 [k*strip_size*2.0,j] green_line
)
)

)
)
)

)--end mode 3

progressend ()

if strip_mode.selection < 4 then
(
bmp2.filename = ("AA Filters: " + filter_one.items[filter_one.selection] + " - " + filter_two.items[filter_two.selection] )
display bmp2
)

scanlineRender.antiAliasFilter = old_filter 
scanlineRender.antiAliasFilterSize = old_size 
)--end on

)--end rollout

if compaa_floater != undefined then closerolloutfloater compaa_floater
compaa_floater = newrolloutfloater "CompareAA" 180 470 100 100
addrollout compaa_roll compaa_floater


try
(
ini_file = openfile (scriptspath+"\\aacompare.ini")
str = readline ini_file
compaa_roll.color1.color = execute (readline ini_file)

compaa_roll.filter_on1.state = execute (readline ini_file)
compaa_roll.filter_one.selection = execute (readline ini_file)
compaa_roll.use_fsize1.state = execute (readline ini_file)
compaa_roll.f_size1.value = execute (readline ini_file)
compaa_roll.f_blend1.value = execute (readline ini_file)
compaa_roll.f_blur1.value = execute (readline ini_file)
compaa_roll.f_ring1.value = execute (readline ini_file)

compaa_roll.color2.color = execute (readline ini_file)
compaa_roll.filter_on2.state = execute (readline ini_file)
compaa_roll.filter_two.selection = execute (readline ini_file)
compaa_roll.use_fsize2.state = execute (readline ini_file)
compaa_roll.f_size2.value = execute (readline ini_file)
compaa_roll.f_blend2.value = execute (readline ini_file)
compaa_roll.f_blur2.value = execute (readline ini_file)
compaa_roll.f_ring2.value = execute (readline ini_file)

compaa_roll.strip_s.value = execute (readline ini_file)
compaa_roll.strip_mode.selection = execute (readline ini_file)
compaa_roll.show_strip_mode.selection = execute (readline ini_file)

close ini_file
)
catch()


)--end script

