Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Demos. Updated to take advantage of their code running in a namespace. |
|---|---|
| Timelines: | family | ancestors | descendants | both | ak-experimental |
| Files: | files | file ages | folders |
| SHA1: |
93e9361948406ebf4c89fc7395297c92 |
| User & Date: | andreask 2010-07-15 06:41:00.000 |
Context
|
2010-07-15
| ||
| 19:03 |
Demos.
The demos are now handled like they are in a matrix, with the choice of images and actions as the two axes. Choose an action and it applies to the current image. Choose an image and the current action is applied. So, choose an image and walk the toolbar to see the various actions. Or, choose an action, maybe parameterize it, and then walk the images. check-in: 8ee78df8f1 user: andreask tags: ak-experimental | |
| 06:41 | Demos. Updated to take advantage of their code running in a namespace. check-in: 93e9361948 user: andreask tags: ak-experimental | |
| 05:39 | Demos. Moved execution of demo code into a namespace. Updated demos negatively affected by this back to working order. check-in: 8f6d5aad23 user: andreask tags: ak-experimental | |
Changes
Changes to demos/blend_hsv.tcl.
1 2 3 4 |
def op_alpha_blend_hsv {
label {Blend HSV}
active { expr {[bases] == 2} }
setup {
| < > | | | | | > | | > > > > | | | > | < | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
def op_alpha_blend_hsv {
label {Blend HSV}
active { expr {[bases] == 2} }
setup {
# We manage a cache of the blended images to make the
# scrolling of the scale smoother over time. An improvement
# would be to use timer events to precompute the various
# blends.
variable cache
array set cache {}
set cache(255) [base 0]
set cache(0) [base 1]
variable fore [crimp convert 2hsv [base 0]]
variable back [crimp convert 2hsv [base 1]]
variable alpha 255
scale .left.s -variable DEMO::alpha \
-from 0 -to 255 \
-orient vertical \
-command [list ::apply {{thealpha} {
variable cache
variable fore
variable back
if {[info exists cache($thealpha)]} {
show_image $cache($thealpha)
return
}
set theblend [crimp convert 2rgb [crimp blend $fore $back $thealpha]]
set cache($thealpha) $theblend
show_image $theblend
return
} ::DEMO}]
pack .left.s -side left -fill both -expand 1
}
}
|
Changes to demos/blend_rgb.tcl.
1 2 3 4 |
def op_alpha_blend_rgb {
label {Blend RGB}
active { expr {[bases] == 2} }
setup {
| < < > | | | > > | | > > > | | | > | < | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
def op_alpha_blend_rgb {
label {Blend RGB}
active { expr {[bases] == 2} }
setup {
# We manage a cache of the blended images to make the
# scrolling of the scale smoother over time. An improvement
# would be to use timer events to precompute the various
# blends.
variable cache
array set cache {}
set cache(255) [base 0]
set cache(0) [base 1]
variable black [crimp blank rgba 800 600 0 0 0 255]
variable alpha 255
scale .left.s -variable DEMO::alpha \
-from 0 -to 255 \
-orient vertical \
-command [list ::apply {{thealpha} {
variable cache
variable black
if {[info exists cache($thealpha)]} {
show_image $cache($thealpha)
return
}
set theblend [crimp blend [base 0] [base 1] $thealpha]
set cache($thealpha) $theblend
show_image $theblend
return
} ::DEMO}]
pack .left.s -side left -fill both -expand 1
}
}
|
Changes to demos/degamma.tcl.
1 2 3 |
def op_gamma_invers {
label Degamma
setup {
| | | | | | | | | | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def op_gamma_invers {
label Degamma
setup {
variable gamma 1
variable table {}
plot .left.p -variable ::DEMO::table -title {Invers Gamma}
scale .left.s -variable ::DEMO::gamma \
-from 5 -to 1 -resolution 0.01 \
-orient vertical \
-command [list ::apply {{thegamma} {
variable table [crimp table degamma $thegamma]
show_image [crimp degamma [base] $thegamma]
} ::DEMO}]
grid .left.p -row 0 -column 0 -sticky swen
grid .left.s -row 0 -column 1 -sticky swen
}
}
|
Changes to demos/gamma.tcl.
1 2 3 |
def op_gamma {
label Gamma
setup {
| | | | | | | | | | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def op_gamma {
label Gamma
setup {
variable gamma 1
variable table {}
plot .left.p -variable ::DEMO::table -title Gamma
scale .left.s -variable ::DEMO::gamma \
-from 5 -to 1 -resolution 0.01 \
-orient vertical \
-command [list ::apply {{thegamma} {
variable table [crimp table gamma $thegamma]
show_image [crimp gamma [base] $thegamma]
} ::DEMO}]
grid .left.p -row 0 -column 0 -sticky swen
grid .left.s -row 0 -column 1 -sticky swen
}
}
|
Changes to demos/histogram.tcl.
1 2 3 |
def effect_histogram {
label Histogram
setup {
| | | | | | | > > | < < > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
def effect_histogram {
label Histogram
setup {
variable TR {0 1}
variable TG {0 1}
variable TB {0 1}
variable TS {0 1}
variable TV {0 1}
variable TL {0 1}
variable mask [lindex [crimp split [base]] end]
proc HISTO {image} {
variable HR ; variable HG ; variable HB ; variable HL ; variable HH ; variable HS ; variable HV
variable TR ; variable TG ; variable TB ; variable TL ; variable TS ; variable TV
array set TMP [crimp histogram $image]
array set TMP [crimp histogram [crimp convert 2grey8 $image]]
array set TMP [crimp histogram [crimp convert 2hsv $image]]
set HR [dict values $TMP(red)] ; set TR [CUMULATE $HR]
set HG [dict values $TMP(green)] ; set TG [CUMULATE $HG]
|
| ︙ | ︙ | |||
35 36 37 38 39 40 41 | lset HL 0 0 ; lset HL 255 0 lset HS 0 0 ; lset HS 255 0 lset HV 0 0 ; lset HV 255 0 return } | | > | > | > > | | | | > | | > | | | | | | | | | | | | | | | | | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
lset HL 0 0 ; lset HL 255 0
lset HS 0 0 ; lset HS 255 0
lset HV 0 0 ; lset HV 255 0
return
}
proc EQNONE {} {
HISTO [base]
show_image [base]
return
}
proc EQHSV {} {
HISTO [base]
# H is not stretched. Does not make sense for HUE.
variable HH ; variable HS ; variable HV
variable TS ; variable TV
variable mask
set fs [FIT $TS 255]
set fv [FIT $TV 255]
set h [crimp map identity]
#set s [crimp map identity]
#set v [crimp map identity]
set s [crimp read tcl [list $fs]]
set v [crimp read tcl [list $fv]]
set new [crimp setalpha \
[crimp convert 2rgb \
[crimp remap \
[crimp convert 2hsv [base]] \
$h $s $v]] \
$mask]
show_image $new
HISTO $new
return
}
proc EQRGB {} {
HISTO [base]
variable HR ; variable HG ; variable HB
variable TR ; variable TG ; variable TB
set fr [FIT $TR 255]
set fg [FIT $TG 255]
set fb [FIT $TB 255]
set r [crimp read tcl [list $fr]]
set g [crimp read tcl [list $fg]]
set b [crimp read tcl [list $fb]]
set new [crimp remap [base] $r $g $b]
show_image $new
HISTO $new
return
}
# series(int) --> series (int)
proc CUMULATE {series} {
set res {}
set sum 0
foreach x $series {
lappend res $sum
incr sum $x
}
return $res
}
# series(int/float) --> series(int), all(x): x <= max
proc FIT {series max} {
# Assumes that the input is a monotonically increasing
# series. The maximum value of the series is at the end.
set top [lindex $series end]
set f [expr {double($max) / double($top)}]
set res {}
foreach x $series {
lappend res [expr {round(double($x)*$f)}]
}
return $res
}
HISTO [base]
# For the sake of the display we cut out the pure white and
# black, as they are likely outliers with an extreme number of
# pixels using them.
plot .left.hr -variable ::DEMO::HR -locked 0 -title Red
plot .left.hg -variable ::DEMO::HG -locked 0 -title Green
plot .left.hb -variable ::DEMO::HB -locked 0 -title Blue
plot .top.hl -variable ::DEMO::HL -locked 0 -title Luma
plot .top.hh -variable ::DEMO::HH -locked 0 -title Hue
plot .top.hs -variable ::DEMO::HS -locked 0 -title Saturation
plot .top.hv -variable ::DEMO::HV -locked 0 -title Value
ttk::button .right.eqhsv -text {Equalize HSV} -command ::DEMO::EQHSV
ttk::button .right.eqrgb -text {Equalize RGB} -command ::DEMO::EQRGB
ttk::button .right.eqnone -text {Equalize None} -command ::DEMO::EQNONE
plot .right.tr -variable ::DEMO::TR -locked 0 -title {CDF Red}
plot .right.tg -variable ::DEMO::TG -locked 0 -title {CDF Green}
plot .right.tb -variable ::DEMO::TB -locked 0 -title {CDF Blue}
plot .top.tl -variable ::DEMO::TL -locked 0 -title {CDF Luma}
plot .top.ts -variable ::DEMO::TS -locked 0 -title {CDF Saturation}
plot .top.tv -variable ::DEMO::TV -locked 0 -title {CDF Value}
grid .left.hr -row 0 -column 0 -sticky swen
grid .left.hg -row 1 -column 0 -sticky swen
grid .left.hb -row 2 -column 0 -sticky swen
grid .top.hl -row 0 -column 0 -sticky swen
|
| ︙ | ︙ | |||
155 156 157 158 159 160 161 | grid .right.tr -row 3 -column 0 -sticky swen grid .right.tg -row 4 -column 0 -sticky swen grid .right.tb -row 5 -column 0 -sticky swen grid .top.tl -row 1 -column 0 -sticky swen grid .top.ts -row 1 -column 2 -sticky swen grid .top.tv -row 1 -column 3 -sticky swen | | | < < < < < < < | 163 164 165 166 167 168 169 170 171 |
grid .right.tr -row 3 -column 0 -sticky swen
grid .right.tg -row 4 -column 0 -sticky swen
grid .right.tb -row 5 -column 0 -sticky swen
grid .top.tl -row 1 -column 0 -sticky swen
grid .top.ts -row 1 -column 2 -sticky swen
grid .top.tv -row 1 -column 3 -sticky swen
}
}
|
Changes to demos/matrix.tcl.
1 2 3 4 5 6 |
def effect_matrix {
label RotMatrix
setup {
scale .left.s \
-from -180 -to 180 -resolution 0.01 \
-orient vertical \
| | | | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def effect_matrix {
label RotMatrix
setup {
scale .left.s \
-from -180 -to 180 -resolution 0.01 \
-orient vertical \
-command [list ::apply {{theangle} {
set s [expr {sin($theangle * 0.017453292519943295769236907684886)}]
set c [expr {cos($theangle * 0.017453292519943295769236907684886)}]
set matrix [list \
[list $c $s 0] \
[list [expr {-$s}] $c 0] \
[list $s $s 1]]
show_image [crimp matrix [base] $matrix]
}}]
pack .left.s -side left -fill both -expand 1
}
}
|
Changes to demos/psych.tcl.
1 2 3 |
def effect_psychedelia {
label Psychedelia
setup {
| > > | > | > | > | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
def effect_psychedelia {
label Psychedelia
setup {
variable token
proc next {} {
variable token
show_image [crimp psychedelia 320 240 100]
set token [after 100 DEMO::next]
return
}
next
}
shutdown {
after cancel $token
}
}
|
Changes to demos/rehsv.tcl.
1 2 3 |
def effect_rehsv {
label {Change HSV}
setup {
| | > > < < | < | | < < | < < | | > > | | > | > > | | > | > > | | > > > > > > > < < | > > | | | | > > > | | | > | | > | | < < < < < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
def effect_rehsv {
label {Change HSV}
setup {
variable hsvbase [crimp convert 2hsv [base]]
variable ghg 1 ; variable gsg 1 ; variable gvg 1
variable ghb 0 ; variable gsb 0 ; variable gvb 0
variable th [crimp table gainw $ghg $ghb] ; variable mh [crimp map gainw $ghg $ghb]
variable ts [crimp table gain $gsg $gsb] ; variable ms [crimp map gain $gsg $gsb]
variable tv [crimp table gain $gvg $gvb] ; variable mv [crimp map gain $gvg $gvb]
variable mask [lindex [crimp split [base]] end]
proc H {args} {
variable ghb
variable ghg
variable th [crimp table gainw $ghg $ghb]
variable mh [crimp map gainw $ghg $ghb]
UPDATE
return
}
proc S {args} {
variable gsb
variable gsg
variable ts [crimp table gain $gsg $gsb]
variable ms [crimp map gain $gsg $gsb]
UPDATE
return
}
proc V {args} {
variable gvb
variable gvg
variable tv [crimp table gain $gvg $gvb]
variable mv [crimp map gain $gvg $gvb]
UPDATE
return
}
proc UPDATE {} {
variable mh
variable ms
variable mv
variable hsvbase
variable mask
show_image [crimp setalpha \
[crimp convert 2rgb [crimp remap $hsvbase $mh $ms $mv]] \
$mask]
return
}
scale .left.hg -variable ::DEMO::ghg -from -10 -to 10 -resolution 0.01 -orient vertical -command ::DEMO::H
scale .left.sg -variable ::DEMO::gsg -from -10 -to 10 -resolution 0.01 -orient vertical -command ::DEMO::S
scale .left.vg -variable ::DEMO::gvg -from -10 -to 10 -resolution 0.01 -orient vertical -command ::DEMO::V
scale .left.hb -variable ::DEMO::ghb -from 0 -to 255 -resolution 1 -orient vertical -command ::DEMO::H
scale .left.sb -variable ::DEMO::gsb -from 0 -to 255 -resolution 1 -orient vertical -command ::DEMO::S
scale .left.vb -variable ::DEMO::gvb -from 0 -to 255 -resolution 1 -orient vertical -command ::DEMO::V
plot .left.ph -variable ::DEMO::th -title Hue
plot .left.ps -variable ::DEMO::ts -title Saturation
plot .left.pv -variable ::DEMO::tv -title Value
grid .left.hg -row 0 -column 0 -sticky sen
grid .left.ph -row 0 -column 1 -sticky swen
grid .left.hb -row 0 -column 2 -sticky sen
grid .left.sg -row 1 -column 0 -sticky sen
grid .left.ps -row 1 -column 1 -sticky swen
grid .left.sb -row 1 -column 2 -sticky sen
grid .left.vg -row 2 -column 0 -sticky sen
grid .left.pv -row 2 -column 1 -sticky swen
grid .left.vb -row 2 -column 2 -sticky sen
}
}
|
Changes to demos/solarize.tcl.
1 2 3 |
def op_solarize {
label Solarize
setup {
| | | | | | | | | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def op_solarize {
label Solarize
setup {
variable threshold 256
variable table {}
plot .left.p -variable ::DEMO::table -title Threshold
scale .left.s -variable ::DEMO::threshold \
-from 0 -to 256 \
-orient horizontal \
-command [list ::apply {{thethreshold} {
variable table [crimp table solarize $thethreshold]
show_image [crimp solarize [base] $thethreshold]
} ::DEMO}]
grid .left.s -row 0 -column 0 -sticky swen
grid .left.p -row 1 -column 0 -sticky swen
}
}
|
Changes to demos/wavy.tcl.
1 2 3 |
def effect_wavy {
label Wavy
setup {
| | | > > | | | | | | | < < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
def effect_wavy {
label Wavy
setup {
proc W {args} {
variable wa
variable wb
variable wc
show_image [crimp wavy [base] $wa $wb $wc]
return
}
variable wa 1
variable wb 1
variable wc 1
scale .left.wa -variable ::DEMO::wa -from -20 -to 20 -resolution 0.01 -orient vertical -command ::DEMO::W
scale .left.wb -variable ::DEMO::wb -from -20 -to 20 -resolution 0.01 -orient vertical -command ::DEMO::W
scale .left.wc -variable ::DEMO::wc -from -20 -to 20 -resolution 0.01 -orient vertical -command ::DEMO::W
pack .left.wa -side left -expand 1 -fill both
pack .left.wb -side left -expand 1 -fill both
pack .left.wc -side left -expand 1 -fill both
}
}
|