~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/psvp/effects/peel.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # peel.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1999-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 
 31 import DaliSubprogram
 32 import RealParameter
 33 
 34 Class PeelSubprogram -superclass DaliSubprogram
 35 
 36 PeelSubprogram instproc init {args} {
 37     eval $self next $args;
 38 
 39     $self instvar input_id_list_;
 40     $self instvar input_info_;
 41 
 42     lappend input_id_list_ i1;
 43 
 44     set input_info_(i1,spec) "";
 45     set input_info_(i1,trigger) 0;
 46     set input_info_(i1,buffertype) Uncompressed;
 47     set input_info_(i1,buffername) [new VidRep/Uncompressed];
 48     set input_info_(i1,decoder) "";
 49 
 50     lappend input_id_list_ i2;
 51 
 52     set input_info_(i2,spec) "";
 53     set input_info_(i2,trigger) 0;
 54     set input_info_(i2,buffertype) Uncompressed;
 55     set input_info_(i2,buffername) [new VidRep/Uncompressed];
 56     set input_info_(i2,decoder) "";
 57 
 58     # Set up outputs
 59 
 60     $self instvar output_id_list_;
 61     $self instvar output_info_;
 62 
 63     lappend output_id_list_ o1;
 64 
 65     set output_info_(o1,spec) "";
 66     set output_info_(o1,buffertype) Uncompressed;
 67     set output_info_(o1,buffername) [new VidRep/Uncompressed];
 68     set output_info_(o1,encoder) "";
 69     set output_info_(o1,format) JPEG;
 70     set output_info_(o1,vagent) "";
 71 
 72     # Set up parameters
 73 
 74     $self instvar parameter_id_list_;
 75     $self instvar parameter_info_;
 76 
 77     lappend parameter_id_list_ pfactor;
 78     set pobj [new RealParameter];
 79     set parameter_info_(pfactor,oname) $pobj;
 80 
 81     $pobj from 0.0
 82     $pobj to 1.0;
 83 
 84     $self instvar comm_obj_;
 85     $comm_obj_ setup;
 86 }
 87 
 88 PeelSubprogram instproc trigger {} {
 89     $self instvar comm_obj_;
 90 
 91     if {![$comm_obj_ parameter_attr_has_value pfactor value]} {
 92         return;
 93     }
 94 
 95     $self instvar parameter_info_;
 96     $self instvar input_info_;
 97     $self instvar output_info_;
 98     $self instvar init_done_;
 99     $self instvar old_pfactor_;
100     $self instvar tb1_;
101 
102     $self instvar w_ h_ pix_pos_ x1_ x2_ y1_ y2_ aff_coords_
103     $self instvar diag_bit_mask_ inv_diag_bit_mask_;
104     $self instvar c_diag_bit_mask_ c_inv_diag_bit_mask_;
105 
106     set pobj $parameter_info_(pfactor,oname)
107 
108     set pfactor [$pobj get];
109 
110     set in_frame1 $input_info_(i1,buffername);
111     set in_frame2 $input_info_(i2,buffername);
112     set out_frame $output_info_(o1,buffername);
113 
114     if {![info exists init_done_]} {
115         if {[$in_frame1 set w_] == 0} {
116             return
117         }
118         if {[$in_frame2 set w_] == 0} {
119             return
120         }
121 
122         $out_frame copy_geometry $in_frame2;
123         if {$output_info_(o1,format) == "JPEG"} {
124             $out_frame set h_subsample_ 2;
125             $out_frame set v_subsample_ 1;
126         } else {
127             $out_frame set h_subsample_ 2;
128             $out_frame set v_subsample_ 2;
129         }
130         $out_frame allocate;
131         set init_done_ 1;
132         set old_pfactor_ "";
133 
134         set w_ [$in_frame2 set w_];
135         set h_ [$in_frame2 set h_];
136 
137         if {$w_ > $h_} {
138             set d $w_;
139         } else {
140             set d $h_;
141         }
142 
143         set diag_bit_mask_ [bit_new $d $d];
144         set inv_diag_bit_mask_ [bit_new $d $d];
145 
146         puts "here"
147 
148         set temp_byte [byte_new $d $d];
149 
150         for {set i 0} {$i < $d} {incr i} {
151             for {set j 0} {$j < $d} {incr j} {
152                 if {[expr $i + $j] < $d} {
153                     byte_poke $temp_byte $i $j 64
154                 } else {
155                     byte_poke $temp_byte $i $j 128
156                 }
157             }
158         }
159 
160         bit_make_from_key $temp_byte 60 70 $diag_bit_mask_;
161         bit_make_from_key $temp_byte 120 140 $inv_diag_bit_mask_;
162 
163         byte_free $temp_byte;
164 
165         set hs [$in_frame2 set h_subsample_];
166         set vs [$in_frame2 set v_subsample_];
167 
168         set c_diag_bit_mask_ [bit_new [expr $d/$hs] [expr $d/$vs]];
169         set c_inv_diag_bit_mask_ [bit_new [expr $d/$hs] [expr $d/$vs]];
170 
171         set temp_byte [byte_new [expr $d/$hs] [expr $d/$vs]];
172 
173         for {set i 0} {$i < [expr $d/$hs]} {incr i} {
174             for {set j 0} {$j < [expr $d/$vs]} {incr j} {
175                 if {[expr ($i*$hs) + ($j*$vs)] < $d} {
176                     byte_poke $temp_byte $i $j 64
177                 } else {
178                     byte_poke $temp_byte $i $j 128
179                 }
180             }
181         }
182 
183         bit_make_from_key $temp_byte 60 70 $c_diag_bit_mask_;
184         bit_make_from_key $temp_byte 120 140 $c_inv_diag_bit_mask_;
185 
186         byte_free $temp_byte;
187 
188         puts "there"
189     }
190 
191 
192     if {$old_pfactor_ != $pfactor} {
193 
194         set old_pfactor_ $pfactor;
195 
196         set pix_len [expr $w_+$h_];
197 
198         set pix_pos_ [expr int($pfactor * $pix_len)];
199 
200         if {[expr $pix_pos_%2] == 1} {
201             incr pix_pos_;
202         }
203 
204         if {$pix_pos_ >= $w_} {
205             set x2_ [expr $w_ - 1];
206         } else {
207             set x2_ $pix_pos_;
208         }
209 
210         if {$pix_pos_ >= $h_} {
211             set y2_ [expr $h_ - 1];
212         } else {
213             set y2_ $pix_pos_;
214         }
215 
216         if {[expr $pix_pos_ - $h_] < 0} {
217             set x1_ 0;
218         } else {
219             set x1_ [expr $pix_pos_ - $h_];
220         }
221 
222         if {[expr $pix_pos_ - $w_] < 0} {
223             set y1_ 0;
224         } else {
225             set y1_ [expr $pix_pos_ - $w_];
226         }
227 
228         if {![info exists tb1_]} {
229             set tb1_ [new VidRep/Uncompressed];
230         }
231 
232         set hs [$in_frame2 set h_subsample_];
233         set vs [$in_frame2 set v_subsample_];
234 
235         $tb1_ set w_ [expr $x2_ - $x1_ + 1];
236         $tb1_ set h_ [expr $y2_ - $y1_ + 1];
237         $tb1_ set true_w_ [$tb1_ set w_]'
238         $tb1_ set true_h_ [$tb1_ set h_]'
239         $tb1_ set h_subsample_ $hs;
240         $tb1_ set v_subsample_ $vs;
241 
242         $tb1_ allocate;
243 
244         set aff_coords_(a) 0;
245         set aff_coords_(b) -1;
246         set aff_coords_(c) [expr $pix_pos_ - $x1_];
247         set aff_coords_(d) -1;
248         set aff_coords_(e) 0;
249         set aff_coords_(f) [expr $pix_pos_ - $y1_];
250 
251         set aff_coords_(ca) 0;
252         set aff_coords_(cb) [expr -1 * $vs / $hs];
253         set aff_coords_(cc) [expr ($pix_pos_ - $x1_)/$hs];
254         set aff_coords_(cd) [expr -1 * $hs / $vs];
255         set aff_coords_(ce) 0;
256         set aff_coords_(cf) [expr ($pix_pos_ - $y1_) / $vs];
257     }
258 
259     set i1_lum [$in_frame1 get_lum_name];
260     set i2_lum [$in_frame2 get_lum_name];
261     set out_lum [$out_frame get_lum_name];
262     set tb1_lum [$tb1_ get_lum_name];
263 
264     set i1_cr [$in_frame1 get_cr_name];
265     set i2_cr [$in_frame2 get_cr_name];
266     set out_cr [$out_frame get_cr_name];
267     set tb1_cr [$tb1_ get_cr_name];
268 
269     set i1_cb [$in_frame1 get_cb_name];
270     set i2_cb [$in_frame2 get_cb_name];
271     set out_cb [$out_frame get_cb_name];
272     set tb1_cb [$tb1_ get_cb_name];
273 
274     set hs [$in_frame2 set h_subsample_];
275     set vs [$in_frame2 set v_subsample_];
276 
277     # Rotate, scale and fill temp buffer with affine transform of
278     # input 1.
279 
280     byte_affine $i1_lum $tb1_lum $aff_coords_(a) $aff_coords_(b) $aff_coords_(c) $aff_coords_(d) $aff_coords_(e) $aff_coords_(f);
281     byte_affine $i1_cr $tb1_cr $aff_coords_(ca) $aff_coords_(cb) $aff_coords_(cc) $aff_coords_(cd) $aff_coords_(ce) $aff_coords_(cf);
282     byte_affine $i1_cb $tb1_cb $aff_coords_(ca) $aff_coords_(cb) $aff_coords_(cc) $aff_coords_(cd) $aff_coords_(ce) $aff_coords_(cf);
283 
284 
285     set tclip [byte_clip $i1_lum 0 0 1 1];
286     set oclip [byte_clip $out_lum 0 0 1 1];
287 
288     if {$x1_ > 0} {
289         byte_reclip $i2_lum 0 0 $x1_ $h_ $tclip;
290         byte_reclip $out_lum 0 0 $x1_ $h_ $oclip;
291         byte_copy $tclip $oclip;
292 
293         byte_reclip $i2_cr 0 0 [expr $x1_ / $hs] [expr $h_ / $vs] $tclip;
294         byte_reclip $out_cr 0 0 [expr $x1_ / $hs] [expr $h_ / $vs] $oclip;
295         byte_copy $tclip $oclip;
296 
297         byte_reclip $i2_cb 0 0 [expr $x1_ / $hs] [expr $h_ / $vs] $tclip;
298         byte_reclip $out_cb 0 0 [expr $x1_ / $hs] [expr $h_ / $vs] $oclip;
299         byte_copy $tclip $oclip;
300     }
301 
302     if {$y1_ > 0} {
303         byte_reclip $i2_lum $x1_ 0 [expr $x2_ - $x1_ +1] $y1_ $tclip;
304         byte_reclip $out_lum $x1_ 0 [expr $x2_- $x1_ +1] $y1_ $oclip;
305         byte_copy $tclip $oclip;
306 
307         byte_reclip $i2_cr [expr $x1_/$hs] 0 [expr ($x2_ - $x1_ +1)/$hs] [expr $y1_ / $vs] $tclip;
308         byte_reclip $out_cr [expr $x1_/$hs] 0 [expr ($x2_ - $x1_ +1)/$hs] [expr $y1_ / $vs] $oclip;
309         byte_copy $tclip $oclip;
310 
311         byte_reclip $i2_cb [expr $x1_/$hs] 0 [expr ($x2_ - $x1_ +1)/$hs] [expr $y1_ / $vs] $tclip;
312         byte_reclip $out_cb [expr $x1_/$hs] 0 [expr ($x2_ - $x1_ +1)/$hs] [expr $y1_ / $vs] $oclip;
313         byte_copy $tclip $oclip;
314     }
315 
316     if {$x2_ < [expr $w_ -1]} {
317         byte_reclip $i1_lum [expr $x2_ + 1] 0 [expr $w_ - $x2_ - 1] $h_ $tclip;
318         byte_reclip $out_lum [expr $x2_+ 1] 0 [expr $w_ - $x2_ - 1] $h_ $oclip;
319         byte_copy $tclip $oclip;
320 
321         byte_reclip $i1_cr [expr ($x2_ + 1)/$hs] 0 [expr ($w_ - $x2_ - 1)/$hs] [expr $h_/$vs] $tclip;
322         byte_reclip $out_cr [expr ($x2_ + 1)/$hs] 0 [expr ($w_ - $x2_ - 1)/$hs] [expr $h_/$vs] $oclip;
323         byte_copy $tclip $oclip;
324 
325         byte_reclip $i1_cb [expr ($x2_ + 1)/$hs] 0 [expr ($w_ - $x2_ - 1)/$hs] [expr $h_/$vs] $tclip;
326         byte_reclip $out_cb [expr ($x2_ + 1)/$hs] 0 [expr ($w_ - $x2_ - 1)/$hs] [expr $h_/$vs] $oclip;
327         byte_copy $tclip $oclip;
328     }
329 
330     if {$y2_ < [expr $h_ -1]} {
331         byte_reclip $i1_lum $x1_ [expr $y2_ + 1] [expr $x2_ - $x1_ + 1] [expr $h_ - $y2_ - 1] $tclip;
332         byte_reclip $out_lum $x1_ [expr $y2_ + 1] [expr $x2_ - $x1_ + 1] [expr $h_ - $y2_ - 1] $oclip;
333         byte_copy $tclip $oclip;
334 
335         byte_reclip $i1_cr [expr $x1_/$hs] [expr ($y2_ + 1)/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($h_ - $y2_ - 1)/$vs] $tclip;
336         byte_reclip $out_cr [expr $x1_/$hs] [expr ($y2_ + 1)/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($h_ - $y2_ - 1)/$vs] $oclip;
337         byte_copy $tclip $oclip;
338 
339         byte_reclip $i1_cb [expr $x1_/$hs] [expr ($y2_ + 1)/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($h_ - $y2_ - 1)/$vs] $tclip;
340         byte_reclip $out_cb [expr $x1_/$hs] [expr ($y2_ + 1)/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($h_ - $y2_ - 1)/$vs] $oclip;
341         byte_copy $tclip $oclip;
342     }
343 
344     set diag_bit_clip [bit_clip $diag_bit_mask_ [expr ([bit_get_width $diag_bit_mask_] - ($x2_ - $x1_ + 1))/2] [expr ([bit_get_height $diag_bit_mask_] - ($y2_ - $y1_ + 1))/2] [expr $x2_ - $x1_ + 1] [expr $y2_ - $y1_ + 1]];
345 
346     set inv_diag_bit_clip [bit_clip $inv_diag_bit_mask_ [expr ([bit_get_width $diag_bit_mask_] - ($x2_ - $x1_ + 1))/2] [expr ([bit_get_height $diag_bit_mask_] - ($y2_ - $y1_ + 1))/2] [expr $x2_ - $x1_ + 1] [expr $y2_ - $y1_ + 1]];
347 
348     byte_reclip $i2_lum $x1_ $y1_ [expr $x2_ - $x1_ + 1] [expr $y2_ - $y1_ + 1] $tclip;
349     byte_reclip $out_lum $x1_ $y1_ [expr $x2_ - $x1_ + 1] [expr $y2_ - $y1_ + 1] $oclip;
350 
351     byte_copy_with_mask $tclip $diag_bit_clip $oclip;
352     byte_copy_with_mask $tb1_lum $inv_diag_bit_clip $oclip;
353 
354     bit_reclip $c_diag_bit_mask_ [expr ([bit_get_width $c_diag_bit_mask_] - (($x2_ - $x1_ + 1)/$hs))/2] [expr ([bit_get_height $c_diag_bit_mask_] - (($y2_ - $y1_ + 1)/$vs))/2] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $diag_bit_clip;
355 
356     bit_reclip $c_inv_diag_bit_mask_ [expr ([bit_get_width $c_diag_bit_mask_] - (($x2_ - $x1_ + 1)/$hs))/2] [expr ([bit_get_height $c_diag_bit_mask_] - (($y2_ - $y1_ + 1)/$vs))/2] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $inv_diag_bit_clip;
357 
358 #    byte_reclip $out_cr [expr $x1_/$hs] [expr $y1_/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $oclip;
359 #    byte_set $oclip 128;
360 
361 #    byte_reclip $out_cb [expr $x1_/$hs] [expr $y1_/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $oclip;
362 #    byte_set $oclip 128;
363 
364 
365    byte_reclip $i2_cr [expr $x1_/$hs] [expr $y1_/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $tclip;
366     byte_reclip $out_cr [expr $x1_/$hs] [expr $y1_/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $oclip;
367 
368     byte_copy_with_mask $tclip $diag_bit_clip $oclip;
369     byte_copy_with_mask $tb1_cr $inv_diag_bit_clip $oclip;
370 
371     byte_reclip $i2_cb [expr $x1_/$hs] [expr $y1_/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $tclip;
372     byte_reclip $out_cb [expr $x1_/$hs] [expr $y1_/$vs] [expr ($x2_ - $x1_ + 1)/$hs] [expr ($y2_ - $y1_ + 1)/$vs] $oclip;
373 
374     byte_copy_with_mask $tclip $diag_bit_clip $oclip;
375     byte_copy_with_mask $tb1_cb $inv_diag_bit_clip $oclip;
376 
377 
378     bit_free $diag_bit_clip;
379     bit_free $inv_diag_bit_clip;
380     byte_free $tclip;
381     byte_free $oclip;
382 
383     $out_frame set ts_ [$in_frame1 set ts_];
384 
385     set encoder $output_info_(o1,encoder);
386 
387     if {$encoder != ""} {
388         $encoder recv $out_frame;
389     }
390 
391     $self send_completion_token
392 
393     [[[[$input_info_(i1,decoder) set agent_] set network_] set net_(0)] set dn_] recv_flush
394     [[[[$input_info_(i2,decoder) set agent_] set network_] set net_(0)] set dn_] recv_flush
395 
396 }
397 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.