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

Linux Cross Reference
Tina5/tina-tools/tinatool/draw/drawPaint_imrect.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester 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  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawPaint_imrect.c,v $
 37  * Date    :  $Date: 2008/12/16 11:38:52 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: drawPaint_imrect.c,v 1.6 2008/12/16 11:38:52 neil Exp $
 40  *
 41  * Author  : Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "drawPaint_imrect.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/math/mathDef.h>
 58 #include <tina/math/mathPro.h>
 59 #include <tina/image/imgDef.h>
 60 #include <tina/image/imgPro.h>
 61 #include <tina/geometry/geomDef.h>
 62 #include <tina/geometry/geomPro.h>
 63 #include <tinatool/draw/draw_TvDef.h>
 64 #include <tinatool/draw/draw_TvPro.h>
 65 #include <tinatool/draw/draw_PaintDef.h>
 66 #include <tinatool/draw/draw_PaintPro.h>
 67 #include <tinatool/gphx/null/gphxNull_draw.h>
 68 
 69 #define LIMIT_TO_UCHAR(_grey) (((_grey)<0) ? 0 : (((_grey)<256) ? (_grey) : 255))
 70 static Bool bigtolittle = false;
 71 
 72 static void    cword_swap(char *d)
 73 {
 74     union swap
 75     {
 76         char    in[4];
 77         int     out;
 78     }       Swap;
 79 
 80     if (!bigtolittle)
 81         return;
 82     Swap.in[0] = *(d + 3);
 83     Swap.in[1] = *(d + 2);
 84     Swap.in[2] = *(d + 1);
 85     Swap.in[3] = *d;
 86     *(int *) d = Swap.out;
 87 }
 88 static void    cshort_swap(char *d)
 89 {
 90     union swap
 91     {
 92         char    in[4];
 93         short   out;
 94     }       Swap;
 95 
 96     if (!bigtolittle)
 97         return;
 98     Swap.in[0] = *(d + 1);
 99     Swap.in[1] = *d;
100     *(short *) d = Swap.out;
101 }
102 
103 void toggle_bigtolittle(void)
104 {
105     bigtolittle = !bigtolittle;
106 }
107 
108 void cmap_get_stdlut(Cmap_data_visible *cmap,int clut,char *im,int loc)
109 {
110     unsigned short *im16 = (unsigned short *) im;
111     unsigned int *im32 = (unsigned int *) im;
112     
113     if (cmap->nplanes == 8)
114        im[loc] = cmap->std_lut[clut];
115     else if (cmap->nplanes == 16)
116     {
117        im16[loc] = cmap->std_lut[clut]; 
118        cshort_swap((char *)&im16[loc]);
119     }
120      
121     else if (cmap->nplanes == 24 || cmap->nplanes == 32)
122     {
123        im32[loc] = cmap->std_lut[clut];
124        cword_swap((char *)&im32[loc]);
125     }
126 }
127 
128 int cmap_get_storage(Cmap_data_visible *cmap)
129 {
130     if (cmap->nplanes != 8 && cmap->nplanes !=16 && cmap->nplanes != 24)
131        errorf(warning,"cmap_get_storage: %d bits not tested \n", cmap->nplanes);
132     if (cmap->nplanes == 24) return 4;
133     else return(cmap->nplanes/8);
134 }
135 
136 static void linexy(Tv * tv, int x1, int y1, int x2, int y2)
137 {
138     tv_line2(tv, vec2((float) x1, (float) y1), vec2((float) x2, (float) y2));
139 }
140 
141 void    tv_imrect_skel(Tv * tv, Imrect * imrect)
142 {
143     int     lx, ly, ux, uy;
144     int     dx, dy;
145     int     x, y;
146 
147     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->region == NULL)
148         return;
149 
150     lx = imrect->region->lx;
151     ux = imrect->region->ux;
152     ly = imrect->region->ly;
153     uy = imrect->region->uy;
154 
155     dx = (ux - lx) / 16;
156     dy = (uy - ly) / 16;
157     if (dx<1) dx = 1; /* BUG fix NAT */
158     if (dy<1) dy = 1; /* 26/5/95     */
159 
160     for (x = lx; x < ux; x += dx)
161         linexy(tv, x, ly, x, uy);
162     linexy(tv, ux, ly, ux, uy);
163     for (y = ly; y < uy; y += dy)
164         linexy(tv, lx, y, ux, y);
165     linexy(tv, lx, y, ux, y);
166 }
167 
168 void tv_image(Tv * tv, int c, int r, int w, int h, char *data)
169 {
170     if (tv == NULL || tv->tv_screen == NULL)
171         return;
172 
173     tv_screen_image(tv->tv_screen, c, r, w, h, data);
174 }
175 
176 void tv_image2(Tv * tv, int c, int r, int w, int h, char *data)
177 {
178     int storage;
179     char *im;
180     Ipos ll = {Ipos_id};
181     Ipos ur = {Ipos_id};        /* low left and upper right */
182     Vec2 origin = {Vec2_id};
183     int lx, ly, ux, uy;
184     float sx, sy, imx, imy;
185     int i, j, k;
186     if (tv == NULL || tv->tv_screen == NULL)
187         return;
188 
189     storage = cmap_get_storage(tv->cmap_data_visible);
190     ll = tv_proj2(tv, vec2((float) c, (float) r));
191     ur = tv_proj2(tv, vec2((float) c + w, (float) r + h));
192     lx = ipos_x(ll);
193     ly = ipos_y(ll);
194     ux = ipos_x(ur);
195     uy = ipos_y(ur);
196     sx = (float)(1.0 / tv->scalex);
197     sy = (float)(1.0 / tv->scaley);
198     if (lx > ux)
199     {
200         SWAP(int, lx, ux);
201         sx = -sx;
202     }
203     if (ly > uy)
204     {
205         SWAP(int, ly, uy);
206         sy = -sy;
207     }
208     lx = MAX(0, lx);
209     ux = MIN(tv->width, ux);
210     ly = MAX(0, ly);
211     uy = MIN(tv->height, uy);
212 
213     origin = tv_backproj2(tv, ipos(lx, ly));
214     im = cvector_alloc(0, storage*(ux - lx) * (uy - ly));
215 
216     imy = vec2_y(origin);
217     for (i = ly, k = 0; i < uy; ++i)
218     {
219         int y, yoff;
220         y = (int)(imy - r);
221         yoff = y * w;
222 
223         imx = vec2_x(origin);
224         for (j = lx; j < ux; ++j, ++k)
225         {
226             int x = (int)(imx - c);
227             if (y < 0 || x < 0 || y >= h || x >= w)
228             {
229                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
230             }
231             else
232             {
233                 if (storage==1)
234                    im[k] = data[yoff+x];
235                 else if (storage==2)
236                 {
237                       im[2*k] = data[2*(yoff+x)];
238                       im[2*k+1] = data[2*(yoff+x)+1]; 
239                 }
240                 else if (storage==3)
241                 {
242                       im[3*k] = data[3*(yoff+x)];
243                       im[3*k+1] = data[3*(yoff+x)+1];
244                       im[3*k+2] = data[3*(yoff+x)+2];
245                 }
246                 else if (storage ==4)
247                 {
248                       im[4*k] = data[4*(yoff+x)];
249                       im[4*k+1] = data[4*(yoff+x)+1];
250                       im[4*k+2] = data[4*(yoff+x)+2];
251                       im[4*k+3] = data[4*(yoff+x)+3];
252                 }
253             }
254 
255             imx += sx;
256         }
257         imy += sy;
258     }
259 
260     tv_screen_image(tv->tv_screen, lx, ly, ux - lx, uy - ly, (char *)im);
261     cvector_free(im, 0);
262 }
263 
264 void    tv_imrect(Tv * tv, Imrect * imrect, int sample)
265 {
266     char *im;
267     int     storage;
268     int     lx, ly, ux, uy;
269     int     h, w, size;
270     int     i, j, k;
271 
272     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->region == NULL)
273         return;
274     storage = cmap_get_storage(tv->cmap_data_visible);
275 
276     lx = imrect->region->lx;
277     ux = imrect->region->ux;
278     ly = imrect->region->ly;
279     uy = imrect->region->uy;
280 
281     h = (uy - ly) / sample;
282     w = (ux - lx) / sample;
283     size = h * w;
284 
285     im = (char *) cvector_alloc(0, storage*size);
286 
287     for (i = ly, k = 0; i < uy; i += sample)
288     {
289         for (j = lx; j < ux; j += sample, ++k)
290         {
291             int     gl;
292 
293             IM_PIX_GET(imrect, i, j, gl);
294             if (gl < 0)
295               /* warning: pointer targets in passing argument 3 of 'cmap_get_stdlut' differ in signedness */
296                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
297             else if (gl > 255)
298                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
299             else
300                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
301         }
302     }
303 
304     tv_image(tv, lx, ly, w, h, (char *) im);
305     cvector_free(im, 0);
306 }
307 
308 void    tv_imrect2_interpol(Tv * tv, Imrect * imrect)
309 {
310     int     storage;
311     char    *im;
312     Vec2    v = {Vec2_id};
313     int     i, j, k;
314     int     height, width;
315     int     gl;
316 
317 
318     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
319         return;
320     storage = cmap_get_storage(tv->cmap_data_visible);
321 
322     height = tv->height;
323     width = tv->width;
324     im = (char *) cvector_alloc(0, storage* height * width);
325 
326     for (i = 0, k = 0; i < height; ++i)
327     {
328         for (j = 0; j < width; ++j, ++k)
329         {
330             v = tv_backproj2(tv, ipos(j, i));
331             gl = (int)(im_sub_pixf(imrect, vec2_y(v), vec2_x(v)) + 0.5);
332             if (gl < 0)
333                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
334             else if (gl > 255)
335                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
336             else
337                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
338         }
339     }
340 
341     tv_image(tv, 0, 0, width, height, (char *) im);
342     cvector_free(im, 0);
343 }
344 
345 void    tv_imrect2(Tv * tv, Imrect * imrect)
346 {
347     int    *row;
348     int storage=1;
349     char *im;
350     int     lx, ly, ux, uy;
351     int     i, j, k;
352     Imregion *region;
353     Imregion *tvregion;
354 
355     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
356         return;
357     storage = cmap_get_storage(tv->cmap_data_visible);
358     tvregion = tv_get_tv_screen_region(tv);
359     tvregion->ux++;
360     tvregion->uy++;
361     region = roi_inter(tvregion, imrect->region);
362     rfree((void *) tvregion);
363 
364     if (region == NULL)
365         return;
366 
367     lx = region->lx;
368     ux = region->ux;
369     ly = region->ly;
370     uy = region->uy;
371     rfree((void *) region);
372 
373     row = ivector_alloc(lx, ux);/* intensisty */
374 
375     im = (char *) cvector_alloc(0, storage * (ux - lx) * (uy - ly));
376 
377     for (i = ly, k = 0; i < uy; ++i)
378     {
379         im_get_row(row, imrect, i, lx, ux);
380         for (j = lx; j < ux; ++j, ++k)
381         {
382             int     gl = row[j];
383 
384             if (gl < 0)
385             {
386                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
387             }
388             else if (gl > 255)
389             {
390                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
391             }
392             else
393             {
394                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
395             }
396         }
397     }
398 
399     tv_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
400     ivector_free(row, lx);
401     cvector_free(im, 0);
402 }
403 
404 void    tv_imrect_row(Tv * tv, Imrect * im, int r)
405 {
406     int    *row;
407     int storage;
408     char *rast;
409     int     lx, ux;
410     int     i;
411 
412     if (tv == NULL || tv->tv_screen == NULL || im == NULL || im->region == NULL)
413         return;
414     storage = cmap_get_storage(tv->cmap_data_visible);
415 
416     lx = im->region->lx;
417     ux = im->region->ux;
418 
419     row = ivector_alloc(lx, ux);
420     rast = (char *) cvector_alloc(storage*lx, storage*ux);      
421 
422     im_get_row(row, im, r, lx, ux);
423     for (i = lx; i < ux; ++i)
424                 cmap_get_stdlut(tv->cmap_data_visible,row[i],rast,i);
425 
426 
427     /* BUG tv_raster(tv, x1, x2, y, char   *raster) NOT unsigned char* */
428     tv_raster(tv, lx, ux, i, (char *) rast);
429 
430     ivector_free(row, lx);
431     cvector_free(rast, lx);
432 }
433 
434 void    tv_imrect_row2(Tv * tv, Imrect * im, int r)
435 {
436     int    *row;
437     int     storage;
438     char *rast;
439     int     lx, ux;
440     Imregion *region;
441     Imregion *tvregion;
442     int     i;
443 
444     if (tv == NULL || tv->tv_screen == NULL || im == NULL)
445         return;
446     storage = cmap_get_storage(tv->cmap_data_visible);
447 
448     tvregion = tv_get_tv_screen_region(tv);
449     tvregion->ux++;
450     tvregion->uy++;
451     region = roi_inter(tvregion, im->region);
452     rfree((void *) tvregion);
453 
454     if (region == NULL)
455         return;
456 
457     lx = region->lx;
458     ux = region->ux;
459     rfree((void *) region);
460 
461     row = ivector_alloc(lx, ux);/* intensisty */
462     rast = (char *) cvector_alloc(storage*lx, storage*ux);      /* display grey level */
463 
464     im_get_row(row, im, r, lx, ux);
465     for (i = lx; i < ux; ++i)
466         cmap_get_stdlut(tv->cmap_data_visible,row[i],rast,i);
467 
468 
469 
470     /* BUG tv_raster(tv, lx, ux, i,char *rast NOT unsigned char * */
471     tv_raster(tv, lx, ux, i, (char *) rast);
472 
473     ivector_free(row, lx);
474     cvector_free(rast, lx);
475 }
476 
477 void    tv_edges(Tv * tv, Imrect * edgerect)
478 {
479     int     lx, ly, ux, uy;
480     int     x, y;
481     Imregion *tvregion;
482     Imregion *region;
483 
484     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
485         return;
486 
487     tvregion = tv_get_tv_screen_region(tv);
488     tvregion->ux++;
489     tvregion->uy++;
490     region = roi_inter(tvregion, edgerect->region);
491     rfree((void *) tvregion);
492 
493     if (region == NULL)
494         return;
495 
496     lx = region->lx;
497     ly = region->ly;
498     ux = region->ux;
499     uy = region->uy;
500 
501     tv_save_draw(tv);
502     tv_set_color(tv, green);
503     for (y = ly; y < uy; y++)
504         for (x = lx; x < ux; x++)
505         {
506             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
507 
508             if (eptr == NULL)
509                 continue;
510             tv_pixel2(tv, vec2((float) x, (float) y));
511         }
512     rfree((void *) region);
513 
514     tv_reset_draw(tv);
515 }
516 
517 void    tv_edges_conn(Tv * tv, Imrect * edgerect)
518 {
519     int     lx, ly, ux, uy;
520     int     x, y;
521     Imregion *tvregion;
522     Imregion *region;
523 
524     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
525         return;
526 
527     tvregion = tv_get_tv_screen_region(tv);
528     tvregion->ux++;
529     tvregion->uy++;
530     region = roi_inter(tvregion, edgerect->region);
531     rfree((void *) tvregion);
532 
533     if (region == NULL)
534         return;
535 
536     lx = region->lx;
537     ly = region->ly;
538     ux = region->ux;
539     uy = region->uy;
540 
541     tv_save_draw(tv);
542     for (y = ly; y < uy; y++)
543         for (x = lx; x < ux; x++)
544         {
545             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
546 
547             if (eptr == NULL)
548                 continue;
549 
550             switch (eptr->type & EDGE_GET_CONN_MASK)
551             {
552             case EDGE_NOLINK:
553                 tv_set_color(tv, salmon);
554                 break;
555             case EDGE_TERMIN:
556                 tv_set_color(tv, blue);
557                 break;
558             case EDGE_CONN:
559                 tv_set_color(tv, magenta);
560                 break;
561             case EDGE_JUNC:
562                 tv_set_color(tv, orange);
563                 break;
564             case EDGE_ISOLATED:/* corner feature */
565                 tv_set_color(tv, yellow);
566                 break;
567             }
568             tv_pixel2(tv, vec2((float) x, (float) y));
569         }
570 
571     tv_reset_draw(tv);
572 
573     rfree((void *) region);
574 }
575 
576 void    tv_string2(Tv * tv, Tstring * string)
577 {
578     List *start;
579     List *end;
580     List *dptr;
581     Vec2    oldpos = {Vec2_id};
582     Vec2    pos = {Vec2_id};
583 
584     if (string == NULL)
585         return;
586 
587     start = string->start;
588     end = string->end;
589 
590     if (start == end)
591     {
592         tv_pixel2(tv, edge_image_pos((Edgel *) start->to));
593         return;
594     }
595     oldpos = edge_image_pos((Edgel *) start->to);
596     tv_cross2(tv, oldpos, 5);
597     for (dptr = start; dptr != end;)
598     {
599         dptr = dptr->next;
600         pos = edge_image_pos((Edgel *) dptr->to);
601         tv_point2(tv, oldpos);  /* for xor */
602         tv_line2(tv, oldpos, pos);
603         oldpos = pos;
604     }
605     tv_cross2(tv, oldpos, 5);
606 }
607 
608 void    tv_string2_col(Tv * tv, Tstring * string, int type)
609 {
610     List *start;
611     List *end;
612     List *dptr;
613     Vec2    oldpos = {Vec2_id};
614     Vec2    pos = {Vec2_id};
615 
616     if (string == NULL)
617         return;
618 
619     start = string->start;
620     end = string->end;
621 
622     tv_save_draw(tv);
623     if (start == end)
624     {
625         tv_color_set(tv, salmon);
626         tv_pixel2(tv, edge_image_pos((Edgel *) start->to));
627         tv_reset_draw(tv);
628         return;
629     }
630     oldpos = edge_image_pos((Edgel *) start->to);
631     tv_color_set(tv, red);
632     tv_point2(tv, oldpos);
633     for (dptr = start; dptr != end;)
634     {
635         dptr = dptr->next;
636         pos = edge_image_pos((Edgel *) dptr->to);
637         tv_color_set(tv, salmon);
638         tv_line2(tv, oldpos, pos);
639         oldpos = pos;
640     }
641     tv_color_set(tv, red);
642     tv_point2(tv, oldpos);
643     tv_reset_draw(tv);
644 }
645 
646 void    tv_string_list(Tv * tv, List * string_list)
647 {
648     List   *sptr;
649     int    type;
650 
651     if (tv == NULL || tv->tv_screen == NULL || string_list == NULL)
652         return;
653 
654     for (sptr = string_list; sptr != NULL; sptr = sptr->next)
655         tv_string2_col(tv, sptr->to, type);
656 }
657 
658 void    tv_strings(Tv * tv, Imrect * edgerect)
659 {
660     List   *string_list;
661 
662     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
663         return;
664 
665     string_list = (List *) prop_get(edgerect->props, STRING);
666     tv_save_draw(tv);
667     tv_string_list(tv, string_list);
668 }
669 
670 void    tv_edge_string(Tv * tv, Tstring * string)
671 {
672     List *dptr;
673     List *end;
674 
675     if (string == NULL)
676         return;
677 
678     dptr = string->start;
679     end = string->end;
680 
681     tv_pixel2(tv, edge_image_pos((Edgel *) dptr->to));
682     if (dptr == end)            /* a single pixel */
683         return;
684     for (; dptr != end;)
685     {
686         dptr = dptr->next;
687         tv_pixel2(tv, edge_image_pos((Edgel *) dptr->to));
688     }
689 }
690 
691 void    tv_edge_match(Tv * tv1, Tv * tv2, Match * em)
692 {
693     if (em == NULL)
694         return;
695 
696     tv_edge_string(tv1, (Tstring *) em->to1);
697     tv_edge_string(tv2, (Tstring *) em->to2);
698 }
699 
700 void    tv_edge_match_list(Tv * tv1, Tv * tv2, List * mlist)
701 {
702     List   *lptr;
703 
704     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
705         tv_edge_match(tv1, tv2, (Match *) lptr->to);
706 }
707 
708 void    tv_edges_conn_propmask(Tv * tv, Imrect * edgerect, int mask, int type)
709 {
710     int     lx, ly, ux, uy;
711     int     x, y;
712     Imregion *tvregion;
713     Imregion *region;
714 
715     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL || mask == 0)
716         return;
717 
718     tvregion = tv_get_tv_screen_region(tv);
719     tvregion->ux++;
720     tvregion->uy++;
721     region = roi_inter(tvregion, edgerect->region);
722     rfree((void *) tvregion);
723 
724     if (region == NULL)
725         return;
726 
727     lx = region->lx;
728     ly = region->ly;
729     ux = region->ux;
730     uy = region->uy;
731 
732     tv_save_draw(tv);
733     for (y = ly; y < uy; y++)
734         for (x = lx; x < ux; x++)
735         {
736             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
737 
738             if (eptr == NULL || !((int) prop_get(eptr->props, type) & mask))
739                 continue;
740 
741             switch (eptr->type & EDGE_GET_CONN_MASK)
742             {
743             case EDGE_NOLINK:
744                 tv_set_color(tv, salmon);
745                 break;
746             case EDGE_TERMIN:
747                 tv_set_color(tv, blue);
748                 break;
749             case EDGE_CONN:
750                 tv_set_color(tv, magenta);
751                 break;
752             case EDGE_JUNC:
753                 tv_set_color(tv, orange);
754                 break;
755             case EDGE_ISOLATED:/* corner feature */
756                 tv_set_color(tv, yellow);
757                 break;
758             }
759             tv_pixel2(tv, vec2((float) x, (float) y));
760         }
761     rfree((void *) region);
762 
763     tv_reset_draw(tv);
764 }
765 
766 void    tv_imrect_scale(Tv * tv, Imrect * imrect, double low, double high)
767 {
768     char *im;
769     int     storage;
770     int     lx, ly, ux, uy;
771     int     i, j, k, gl;
772     double  gld, scale255;
773     Imregion *region;
774     Imregion *tvregion;
775     Imregion *tv_get_tv_screen_region();
776 
777     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
778         return;
779     storage = cmap_get_storage(tv->cmap_data_visible);
780     tvregion = tv_get_tv_screen_region(tv);
781     tvregion->ux++;
782     tvregion->uy++;
783     region = roi_inter(tvregion, imrect->region);
784     rfree((void *) tvregion);
785 
786     if (region == NULL)
787         return;
788 
789     lx = region->lx;
790     ux = region->ux;
791     ly = region->ly;
792     uy = region->uy;
793     rfree((void *) region);
794 
795     /* display grey level */
796     im = (char *) cvector_alloc(0, (ux - lx) * (uy - ly));
797     scale255 = 255 / (high - low);
798 
799     for (i = ly, k = 0; i < uy; ++i)
800     {
801         for (j = lx; j < ux; ++j, ++k)
802         {
803             IM_PIX_GET(imrect, i, j, gld);
804             gl = (int) ((gld - low) * scale255);
805             if (gl < 0)
806                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
807 
808             else if (gl > 255)
809                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
810 
811             else
812                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
813         }
814     }
815 
816     tv_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
817     cvector_free(im, 0);
818 }
819 
820 
821 
822 
823 
824 void    tv_imrect_anaglyph(Tv * tv, Imrect * imrect_left, Imrect * imrect_right, double low, double high)
825 {
826     int storage;
827     float *row1, *row2;
828     if (tv && tv->tv_screen && imrect_left && imrect_right)
829     {
830 
831 /* Memory leak fixed PAB 21 / 4 / 2004: double call of roi_outer leaked a roi */
832 
833         Imregion *region, *region2;
834         Imregion *tvregion;
835         Imregion *tv_get_tv_screen_region();
836 
837         tvregion = tv_get_tv_screen_region(tv);
838         tvregion->ux++;
839         tvregion->uy++;
840         region = roi_outer(imrect_right->region, imrect_left->region);
841         region2 = roi_outer(tvregion, region);
842         rfree((void *) tvregion);
843         rfree((void *) region);
844         storage = cmap_get_storage(tv->cmap_data_visible);
845 
846         if (region2)
847         {
848             double  scale255 = 255 / (high - low);
849             int     gl_left, gl_right;
850             int     k;
851             int     row, col;
852             int     x1 = region2->lx;   /* Top left x co-ord */
853             int     x2 = region2->ux;   /* Bottom right x co-ord */
854             int     y1 = region2->ly;   /* Top left y co-ord */
855             int     y2 = region2->uy;   /* Bottom right y co-ord */
856             unsigned char gluc_left, gluc_right;
857             char *image_anag = (char *) cvector_alloc(0, storage*(x2 - x1) * (y2 - y1));
858 
859             rfree((void *) region2);
860             row1 = fvector_alloc(x1, x2);
861             row2 = fvector_alloc(x1, x2);
862 
863 
864             /* For each row in the image */
865             for (row = y1, k = 0; row < y2; ++row)
866             {
867                 im_get_rowf(row1, imrect_left, row, x1, x2);
868                 im_get_rowf(row2, imrect_right, row, x1, x2);
869                 
870                 /* For each column in the row */
871                 for (col = x1; col < x2; ++col, k++)
872                 {
873                     /* Get the scaled left grey-level */
874                     gl_left = (int) ((row1[col] - low) * scale255);
875                     gluc_left = LIMIT_TO_UCHAR(gl_left);
876 
877                     /* Get the scaled right grey-level */
878                     gl_right = (int) ((row2[col] - low) * scale255);
879                     gluc_right = LIMIT_TO_UCHAR(gl_right);
880 
881                     /* Left = green = hi nibble. Right = red = lo
882                      * nibble */
883                     cmap_get_stdlut(tv->cmap_data_visible,
884                         (gluc_left & 0xf0) | (gluc_right >> 4),image_anag,k);
885 
886                 }
887             }
888             tv_image2(tv, x1, y1, x2 - x1, y2 - y1, (char *) image_anag);
889             cvector_free(image_anag, 0);
890             fvector_free(row1, x1);
891             fvector_free(row2, x1);
892 
893         }
894     }
895 }
896 
897 /* apply drawfunc to image of pointers */
898 
899 void    im_ptr_draw(Tv * tv, Imrect * im, int sx, int sy,
900                             void (*drawfunc) (), void *data)
901 {
902     int     x, y, lx, ly, ux, uy;
903 
904     if (tv == NULL || im == NULL)
905         return;
906     lx = im->region->lx;
907     ly = im->region->ly;
908     ux = im->region->ux;
909     uy = im->region->uy;
910     for (x = lx; x < ux; x++)
911         for (y = ly; y < uy; y++)
912             (*drawfunc) (tv, IM_PTR(im, y, x), x, y, data);
913     return;
914 }
915 
916 /* draw scaled image of vec2's at sampling grid space sx, sy */
917 
918 static void pvec2_draw(Tv * tv, Vec2 * v, int x, int y, double *data)
919 {
920     int     sx = (int)data[0];
921     int     sy = (int)data[1];
922 
923     if (x % sx == 0 && x % sy == 0)
924     {
925         double  scale = data[2];
926 
927         tv_vector2(tv, vec2(x + 0.5, y + 0.5), vec2_times(scale, *v));
928     }
929 }
930 
931 void    im_vec2_draw(Tv * tv, Imrect * im, int sx, int sy, double scale)
932 {
933     double  data[3];
934 
935     data[0] = sx;
936     data[1] = sy;
937     data[2] = scale;
938     im_ptr_draw(tv, im, sx, sy, pvec2_draw, data);
939 }
940 

~ [ 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.