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

Linux Cross Reference
Tina6/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 
 68 #define LIMIT_TO_UCHAR(_grey) (((_grey)<0) ? 0 : (((_grey)<256) ? (_grey) : 255))
 69 static Bool bigtolittle = false;
 70 
 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 
 89 
 90 static void    cshort_swap(char *d)
 91 {
 92     union swap
 93     {
 94         char    in[4];
 95         short   out;
 96     }       Swap;
 97 
 98     if (!bigtolittle)
 99         return;
100     Swap.in[0] = *(d + 1);
101     Swap.in[1] = *d;
102     *(short *) d = Swap.out;
103 }
104 
105 
106 void toggle_bigtolittle(void)
107 {
108     bigtolittle = !bigtolittle;
109 }
110 
111 
112 void cmap_get_stdlut(Cmap_data_visible *cmap,int clut,char *im,int loc)
113 {
114     unsigned short *im16 = (unsigned short *) im;
115     unsigned int *im32 = (unsigned int *) im;
116 
117     if (cmap->nplanes == 8)
118        im[loc] = cmap->std_lut[clut];
119     else if (cmap->nplanes == 16)
120     {
121        im16[loc] = cmap->std_lut[clut]; 
122        cshort_swap((char *)&im16[loc]);
123     }
124 
125     else if (cmap->nplanes == 24 || cmap->nplanes == 32)
126     {
127        im32[loc] = cmap->std_lut[clut];
128        cword_swap((char *)&im32[loc]);
129     }
130 }
131 
132 
133 int cmap_get_storage(Cmap_data_visible *cmap)
134 {
135     if (cmap->nplanes != 8 && cmap->nplanes !=16 && cmap->nplanes != 24)
136        errorf(warning,"cmap_get_storage: %d bits not tested \n", cmap->nplanes);
137     if (cmap->nplanes == 24) return 4;
138     else return(cmap->nplanes/8);
139 }
140 
141 
142 static void linexy(Tv * tv, int x1, int y1, int x2, int y2)
143 {
144     tv_line2(tv, vec2((float) x1, (float) y1), vec2((float) x2, (float) y2));
145 }
146 
147 
148 void    tv_imrect_skel(Tv * tv, Imrect * imrect)
149 {
150     int     lx, ly, ux, uy;
151     int     dx, dy;
152     int     x, y;
153 
154     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->region == NULL)
155         return;
156 
157     lx = imrect->region->lx;
158     ux = imrect->region->ux;
159     ly = imrect->region->ly;
160     uy = imrect->region->uy;
161 
162     dx = (ux - lx) / 16;
163     dy = (uy - ly) / 16;
164     if (dx<1) dx = 1; /* BUG fix NAT */
165     if (dy<1) dy = 1; /* 26/5/95     */
166 
167     for (x = lx; x < ux; x += dx)
168         linexy(tv, x, ly, x, uy);
169     linexy(tv, ux, ly, ux, uy);
170     for (y = ly; y < uy; y += dy)
171         linexy(tv, lx, y, ux, y);
172     linexy(tv, lx, y, ux, y);
173 }
174 
175 
176 void tv_image(Tv * tv, int c, int r, int w, int h, char *data)
177 {
178     if (tv == NULL || tv->tv_screen == NULL)
179         return;
180 
181     tv_screen_image(tv->tv_screen, c, r, w, h, data);
182 }
183 
184 
185 void tv_image2(Tv * tv, int c, int r, int w, int h, char *data)
186 {
187     int storage;
188     char *im;
189     Ipos ll = {Ipos_id};
190     Ipos ur = {Ipos_id};        /* low left and upper right */
191     Vec2 origin = {Vec2_id};
192     int lx, ly, ux, uy;
193     float sx, sy, imx, imy;
194     int i, j, k;
195     if (tv == NULL || tv->tv_screen == NULL)
196         return;
197 
198     storage = cmap_get_storage(tv->cmap_data_visible);
199     ll = tv_proj2(tv, vec2((float) c, (float) r));
200     ur = tv_proj2(tv, vec2((float) c + w, (float) r + h));
201     lx = ipos_x(ll);
202     ly = ipos_y(ll);
203     ux = ipos_x(ur);
204     uy = ipos_y(ur);
205     sx = (float)(1.0 / tv->scalex);
206     sy = (float)(1.0 / tv->scaley);
207     if (lx > ux)
208     {
209         SWAP(int, lx, ux);
210         sx = -sx;
211     }
212     if (ly > uy)
213     {
214         SWAP(int, ly, uy);
215         sy = -sy;
216     }
217     lx = MAX(0, lx);
218     ux = MIN(tv->width, ux);
219     ly = MAX(0, ly);
220     uy = MIN(tv->height, uy);
221 
222     origin = tv_backproj2(tv, ipos(lx, ly));
223     im = cvector_alloc(0, storage*(ux - lx) * (uy - ly));
224 
225     imy = vec2_y(origin);
226     for (i = ly, k = 0; i < uy; ++i)
227     {
228         int y, yoff;
229         y = (int)(imy - r);
230         yoff = y * w;
231 
232         imx = vec2_x(origin);
233         for (j = lx; j < ux; ++j, ++k)
234         {
235             int x = (int)(imx - c);
236             if (y < 0 || x < 0 || y >= h || x >= w)
237             {
238                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
239             }
240             else
241             {
242                 if (storage==1)
243                    im[k] = data[yoff+x];
244                 else if (storage==2)
245                 {
246                       im[2*k] = data[2*(yoff+x)];
247                       im[2*k+1] = data[2*(yoff+x)+1]; 
248                 }
249                 else if (storage==3)
250                 {
251                       im[3*k] = data[3*(yoff+x)];
252                       im[3*k+1] = data[3*(yoff+x)+1];
253                       im[3*k+2] = data[3*(yoff+x)+2];
254                 }
255                 else if (storage ==4)
256                 {
257                       im[4*k] = data[4*(yoff+x)];
258                       im[4*k+1] = data[4*(yoff+x)+1];
259                       im[4*k+2] = data[4*(yoff+x)+2];
260                       im[4*k+3] = data[4*(yoff+x)+3];
261                 }
262             }
263 
264             imx += sx;
265         }
266         imy += sy;
267     }
268 
269     tv_screen_image(tv->tv_screen, lx, ly, ux - lx, uy - ly, (char *)im);
270     cvector_free(im, 0);
271 }
272 
273 
274 void tv_col_image2(Tv * tv, int c, int r, int w, int h, char *data)
275 {
276     char *im;
277     Ipos ll = {Ipos_id};
278     Ipos ur = {Ipos_id};        /* low left and upper right */
279     Vec2 origin = {Vec2_id};
280     int lx, ly, ux, uy;
281     float sx, sy, imx, imy;
282     int i, j, k;
283     if (tv == NULL || tv->tv_screen == NULL)
284         return;
285 
286     ll = tv_proj2(tv, vec2((float) c, (float) r));
287     ur = tv_proj2(tv, vec2((float) c + w, (float) r + h));
288     lx = ipos_x(ll);
289     ly = ipos_y(ll);
290     ux = ipos_x(ur);
291     uy = ipos_y(ur);
292     sx = (float)(1.0 / tv->scalex);
293     sy = (float)(1.0 / tv->scaley);
294     if (lx > ux)
295     {
296         SWAP(int, lx, ux);
297         sx = -sx;
298     }
299     if (ly > uy)
300     {
301         SWAP(int, ly, uy);
302         sy = -sy;
303     }
304     lx = MAX(0, lx);
305     ux = MIN(tv->width, ux);
306     ly = MAX(0, ly);
307     uy = MIN(tv->height, uy);
308 
309     origin = tv_backproj2(tv, ipos(lx, ly));
310     im = cvector_alloc(0, 3*(ux - lx) * (uy - ly));
311 
312     imy = vec2_y(origin);
313     for (i = ly, k = 0; i < uy; ++i)
314     {
315         int y, yoff;
316         y = (int)(imy - r);
317         yoff = y * w;
318 
319         imx = vec2_x(origin);
320         for (j = lx; j < ux; ++j, ++k)
321         {
322             int x = (int)(imx - c);
323             if (y < 0 || x < 0 || y >= h || x >= w)
324             {
325                 im[3*k] = 0;
326                 im[3*k+1] = 0;
327                 im[3*k+2] = 0;
328             }
329             else
330             {
331                 im[3*k] = data[3*(yoff+x)];
332                 im[3*k+1] = data[3*(yoff+x)+1];
333                 im[3*k+2] = data[3*(yoff+x)+2];
334             }
335 
336             imx += sx;
337         }
338         imy += sy;
339     }
340 
341     tv_screen_col_image(tv->tv_screen, lx, ly, ux - lx, uy - ly, (char *)im);
342     cvector_free(im, 0);
343 }
344 
345 
346 void    tv_imrect(Tv * tv, Imrect * imrect, int sample)
347 {
348     char *im;
349     int     storage;
350     int     lx, ly, ux, uy;
351     int     h, w, size;
352     int     i, j, k;
353 
354     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->region == NULL)
355         return;
356     storage = cmap_get_storage(tv->cmap_data_visible);
357 
358     lx = imrect->region->lx;
359     ux = imrect->region->ux;
360     ly = imrect->region->ly;
361     uy = imrect->region->uy;
362 
363     h = (uy - ly) / sample;
364     w = (ux - lx) / sample;
365     size = h * w;
366 
367     im = (char *) cvector_alloc(0, storage*size);
368 
369     for (i = ly, k = 0; i < uy; i += sample)
370     {
371         for (j = lx; j < ux; j += sample, ++k)
372         {
373             int     gl;
374 
375             IM_PIX_GET(imrect, i, j, gl);
376             if (gl < 0)
377                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
378             else if (gl > 255)
379                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
380             else
381                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
382         }
383     }
384 
385     tv_image(tv, lx, ly, w, h, (char *) im);
386     cvector_free(im, 0);
387 }
388 
389 
390 void    tv_imrect2_interpol(Tv * tv, Imrect * imrect)
391 {
392     int     storage;
393     char    *im;
394     Vec2    v = {Vec2_id};
395     int     i, j, k;
396     int     height, width;
397     int     gl;
398 
399 
400     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
401         return;
402     storage = cmap_get_storage(tv->cmap_data_visible);
403 
404     height = tv->height;
405     width = tv->width;
406     im = (char *) cvector_alloc(0, storage* height * width);
407 
408     for (i = 0, k = 0; i < height; ++i)
409     {
410         for (j = 0; j < width; ++j, ++k)
411         {
412             v = tv_backproj2(tv, ipos(j, i));
413             gl = (int)(im_sub_pixf(imrect, vec2_y(v), vec2_x(v)) + 0.5);
414             if (gl < 0)
415                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
416             else if (gl > 255)
417                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
418             else
419                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
420         }
421     }
422 
423     tv_image(tv, 0, 0, width, height, (char *) im);
424     cvector_free(im, 0);
425 }
426 
427 
428 void    tv_imrect2(Tv * tv, Imrect * imrect)
429 {
430     int    *row;
431     int storage=1;
432     char *im;
433     int     lx, ly, ux, uy;
434     int     i, j, k;
435     Imregion *region;
436     Imregion *tvregion;
437 
438     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
439         return;
440     storage = cmap_get_storage(tv->cmap_data_visible);
441     tvregion = tv_get_tv_screen_region(tv);
442     tvregion->ux++;
443     tvregion->uy++;
444     region = roi_inter(tvregion, imrect->region);
445     rfree((void *) tvregion);
446 
447     if (region == NULL)
448         return;
449 
450     lx = region->lx;
451     ux = region->ux;
452     ly = region->ly;
453     uy = region->uy;
454     rfree((void *) region);
455 
456     row = ivector_alloc(lx, ux);/* intensisty */
457 
458     im = (char *) cvector_alloc(0, storage * (ux - lx) * (uy - ly));
459 
460     for (i = ly, k = 0; i < uy; ++i)
461     {
462         im_get_row(row, imrect, i, lx, ux);
463         for (j = lx; j < ux; ++j, ++k)
464         {
465             int     gl = row[j];
466 
467             if (gl < 0)
468             {
469                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
470             }
471             else if (gl > 255)
472             {
473                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
474             }
475             else
476             {
477                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
478             }
479         }
480     }
481 
482     tv_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
483     ivector_free(row, lx);
484     cvector_free(im, 0);
485 }
486 
487 
488 void    tv_col_imrect2(Tv * tv, Imrect * imrect)
489 {
490     int      *rowr = NULL, *rowb = NULL, *rowg = NULL;
491     char     *im = NULL, *im2;
492     int      lx, ly, ux, uy;
493     int      i, j, k;
494     Imregion *region = NULL;
495     Imregion *tvregion = NULL;
496 
497     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->rdata==NULL 
498         || imrect->gdata==NULL || imrect->bdata==NULL) return;
499     tvregion = tv_get_tv_screen_region(tv);
500     tvregion->ux++;
501     tvregion->uy++;
502     region = roi_inter(tvregion, imrect->region);
503     rfree((void *) tvregion);
504 
505     if (region == NULL)
506         return;
507 
508     lx = region->lx;
509     ux = region->ux;
510     ly = region->ly;
511     uy = region->uy;
512     rfree((void *) region);
513 
514     rowr = ivector_alloc(lx, ux); /* red values */
515     rowg = ivector_alloc(lx, ux); /* green values */
516     rowb = ivector_alloc(lx, ux); /* blue values */
517 
518     im = (char *) cvector_alloc(0, 3 * (ux - lx) * (uy - ly));
519 
520     for (i = ly, k = 0; i < uy; ++i)
521     {
522         im_r_get_row(rowr, imrect, i, lx, ux);
523         im_g_get_row(rowg, imrect, i, lx, ux);
524         im_b_get_row(rowb, imrect, i, lx, ux);
525 
526         for (j = lx; j < ux; ++j, ++k)
527         {
528             int     glr = rowr[j], glg = rowg[j], glb = rowb[j];
529 
530             if(glr<0) 
531             {
532                 im[3*k] = 0;
533             }
534             else if(glr>255)
535             {
536                 im[3*k] = 255;
537             }
538             else
539             {
540                 im[3*k] = glr;
541             }
542 
543             if(glg<0) 
544             {
545                 im[3*k+1] = 0;
546             }
547             else if(glg>255)
548             {
549                 im[3*k+1] = 255;
550             }
551             else
552             {
553                 im[3*k+1] = glg;
554             }
555 
556             if(glb<0) 
557             {
558                 im[3*k+2] = 0;
559             }
560             else if(glb>255)
561             {
562                 im[3*k+2] = 255;
563             }
564             else
565             {
566                 im[3*k+2] = glb;
567             }
568         }
569     }
570 
571     tv_col_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
572     ivector_free(rowr, lx);
573     ivector_free(rowg, lx);
574     ivector_free(rowb, lx);
575     cvector_free(im, 0);
576 }
577 
578 
579 void    tv_imrect_row(Tv * tv, Imrect * im, int r)
580 {
581     int    *row;
582     int storage;
583     char *rast;
584     int     lx, ux;
585     int     i;
586 
587     if (tv == NULL || tv->tv_screen == NULL || im == NULL || im->region == NULL)
588         return;
589     storage = cmap_get_storage(tv->cmap_data_visible);
590 
591     lx = im->region->lx;
592     ux = im->region->ux;
593 
594     row = ivector_alloc(lx, ux);
595     rast = (char *) cvector_alloc(storage*lx, storage*ux);      
596 
597     im_get_row(row, im, r, lx, ux);
598     for (i = lx; i < ux; ++i)
599                 cmap_get_stdlut(tv->cmap_data_visible,row[i],rast,i);
600 
601     tv_raster(tv, lx, ux, i, (char *) rast);
602 
603     ivector_free(row, lx);
604     cvector_free(rast, lx);
605 }
606 
607 void    tv_imrect_row2(Tv * tv, Imrect * im, int r)
608 {
609     int    *row;
610     int     storage;
611     char *rast;
612     int     lx, ux;
613     Imregion *region;
614     Imregion *tvregion;
615     int     i;
616 
617     if (tv == NULL || tv->tv_screen == NULL || im == NULL)
618         return;
619     storage = cmap_get_storage(tv->cmap_data_visible);
620 
621     tvregion = tv_get_tv_screen_region(tv);
622     tvregion->ux++;
623     tvregion->uy++;
624     region = roi_inter(tvregion, im->region);
625     rfree((void *) tvregion);
626 
627     if (region == NULL)
628         return;
629 
630     lx = region->lx;
631     ux = region->ux;
632     rfree((void *) region);
633 
634     row = ivector_alloc(lx, ux);/* intensisty */
635     rast = (char *) cvector_alloc(storage*lx, storage*ux);      /* display grey level */
636 
637     im_get_row(row, im, r, lx, ux);
638     for (i = lx; i < ux; ++i)
639         cmap_get_stdlut(tv->cmap_data_visible,row[i],rast,i);
640 
641     tv_raster(tv, lx, ux, i, (char *) rast);
642 
643     ivector_free(row, lx);
644     cvector_free(rast, lx);
645 }
646 
647 
648 void    tv_edges(Tv * tv, Imrect * edgerect)
649 {
650     int     lx, ly, ux, uy;
651     int     x, y;
652     Imregion *tvregion;
653     Imregion *region;
654 
655     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
656         return;
657 
658     tvregion = tv_get_tv_screen_region(tv);
659     tvregion->ux++;
660     tvregion->uy++;
661     region = roi_inter(tvregion, edgerect->region);
662     rfree((void *) tvregion);
663 
664     if (region == NULL)
665         return;
666 
667     lx = region->lx;
668     ly = region->ly;
669     ux = region->ux;
670     uy = region->uy;
671 
672     tv_save_draw(tv);
673     tv_set_color(tv, green);
674     for (y = ly; y < uy; y++)
675         for (x = lx; x < ux; x++)
676         {
677             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
678 
679             if (eptr == NULL)
680                 continue;
681             tv_pixel2(tv, vec2((float) x, (float) y));
682         }
683     rfree((void *) region);
684 
685     tv_reset_draw(tv);
686 }
687 
688 
689 void    tv_edges_conn(Tv * tv, Imrect * edgerect)
690 {
691     int     lx, ly, ux, uy;
692     int     x, y;
693     Imregion *tvregion;
694     Imregion *region;
695 
696     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
697         return;
698 
699     tvregion = tv_get_tv_screen_region(tv);
700     tvregion->ux++;
701     tvregion->uy++;
702     region = roi_inter(tvregion, edgerect->region);
703     rfree((void *) tvregion);
704 
705     if (region == NULL)
706         return;
707 
708     lx = region->lx;
709     ly = region->ly;
710     ux = region->ux;
711     uy = region->uy;
712 
713     tv_save_draw(tv);
714     for (y = ly; y < uy; y++)
715         for (x = lx; x < ux; x++)
716         {
717             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
718 
719             if (eptr == NULL)
720                 continue;
721 
722             switch (eptr->type & EDGE_GET_CONN_MASK)
723             {
724             case EDGE_NOLINK:
725                 tv_set_color(tv, salmon);
726                 break;
727             case EDGE_TERMIN:
728                 tv_set_color(tv, blue);
729                 break;
730             case EDGE_CONN:
731                 tv_set_color(tv, magenta);
732                 break;
733             case EDGE_JUNC:
734                 tv_set_color(tv, orange);
735                 break;
736             case EDGE_ISOLATED:/* corner feature */
737                 tv_set_color(tv, yellow);
738                 break;
739             }
740             tv_pixel2(tv, vec2((float) x, (float) y));
741         }
742 
743     tv_reset_draw(tv);
744 
745     rfree((void *) region);
746 }
747 
748 
749 void    tv_string2(Tv * tv, Tstring * string)
750 {
751     List *start;
752     List *end;
753     List *dptr;
754     Vec2    oldpos = {Vec2_id};
755     Vec2    pos = {Vec2_id};
756 
757     if (string == NULL)
758         return;
759 
760     start = string->start;
761     end = string->end;
762 
763     if (start == end)
764     {
765         tv_pixel2(tv, edge_image_pos((Edgel *) start->to));
766         return;
767     }
768     oldpos = edge_image_pos((Edgel *) start->to);
769     tv_cross2(tv, oldpos, 5);
770     for (dptr = start; dptr != end;)
771     {
772         dptr = dptr->next;
773         pos = edge_image_pos((Edgel *) dptr->to);
774         tv_point2(tv, oldpos);  /* for xor */
775         tv_line2(tv, oldpos, pos);
776         oldpos = pos;
777     }
778     tv_cross2(tv, oldpos, 5);
779 }
780 
781 
782 void    tv_string2_col(Tv * tv, Tstring * string, int type)
783 {
784     List *start;
785     List *end;
786     List *dptr;
787     Vec2    oldpos = {Vec2_id};
788     Vec2    pos = {Vec2_id};
789 
790     if (string == NULL)
791         return;
792 
793     start = string->start;
794     end = string->end;
795 
796     tv_save_draw(tv);
797     if (start == end)
798     {
799         tv_color_set(tv, salmon);
800         tv_pixel2(tv, edge_image_pos((Edgel *) start->to));
801         tv_reset_draw(tv);
802         return;
803     }
804     oldpos = edge_image_pos((Edgel *) start->to);
805     tv_color_set(tv, red);
806     tv_point2(tv, oldpos);
807     for (dptr = start; dptr != end;)
808     {
809         dptr = dptr->next;
810         pos = edge_image_pos((Edgel *) dptr->to);
811         tv_color_set(tv, salmon);
812         tv_line2(tv, oldpos, pos);
813         oldpos = pos;
814     }
815     tv_color_set(tv, red);
816     tv_point2(tv, oldpos);
817     tv_reset_draw(tv);
818 }
819 
820 
821 void    tv_string_list(Tv * tv, List * string_list)
822 {
823     List   *sptr;
824     int    type;
825 
826     if (tv == NULL || tv->tv_screen == NULL || string_list == NULL)
827         return;
828 
829     for (sptr = string_list; sptr != NULL; sptr = sptr->next)
830         tv_string2_col(tv, sptr->to, type);
831 }
832 
833 
834 void    tv_strings(Tv * tv, Imrect * edgerect)
835 {
836     List   *string_list;
837 
838     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
839         return;
840 
841     string_list = (List *) prop_get(edgerect->props, STRING);
842     tv_save_draw(tv);
843     tv_string_list(tv, string_list);
844 }
845 
846 
847 void    tv_edge_string(Tv * tv, Tstring * string)
848 {
849     List *dptr;
850     List *end;
851 
852     if (string == NULL)
853         return;
854 
855     dptr = string->start;
856     end = string->end;
857 
858     tv_pixel2(tv, edge_image_pos((Edgel *) dptr->to));
859     if (dptr == end)            /* a single pixel */
860         return;
861     for (; dptr != end;)
862     {
863         dptr = dptr->next;
864         tv_pixel2(tv, edge_image_pos((Edgel *) dptr->to));
865     }
866 }
867 
868 
869 void    tv_edge_match(Tv * tv1, Tv * tv2, Match * em)
870 {
871     if (em == NULL)
872         return;
873 
874     tv_edge_string(tv1, (Tstring *) em->to1);
875     tv_edge_string(tv2, (Tstring *) em->to2);
876 }
877 
878 
879 void    tv_edge_match_list(Tv * tv1, Tv * tv2, List * mlist)
880 {
881     List   *lptr;
882 
883     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
884         tv_edge_match(tv1, tv2, (Match *) lptr->to);
885 }
886 
887 
888 void    tv_edges_conn_propmask(Tv * tv, Imrect * edgerect, int mask, int type)
889 {
890     int     lx, ly, ux, uy;
891     int     x, y;
892     Imregion *tvregion;
893     Imregion *region;
894 
895     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL || mask == 0)
896         return;
897 
898     tvregion = tv_get_tv_screen_region(tv);
899     tvregion->ux++;
900     tvregion->uy++;
901     region = roi_inter(tvregion, edgerect->region);
902     rfree((void *) tvregion);
903 
904     if (region == NULL)
905         return;
906 
907     lx = region->lx;
908     ly = region->ly;
909     ux = region->ux;
910     uy = region->uy;
911 
912     tv_save_draw(tv);
913     for (y = ly; y < uy; y++)
914         for (x = lx; x < ux; x++)
915         {
916             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
917 
918             /*if (eptr == NULL || !((int) prop_get(eptr->props, type) & mask))*/ 
919             if (eptr == NULL || !((long int) prop_get(eptr->props, type) & mask)) /* JD, 2015.01.27 */
920                 continue;
921 
922             switch (eptr->type & EDGE_GET_CONN_MASK)
923             {
924             case EDGE_NOLINK:
925                 tv_set_color(tv, salmon);
926                 break;
927             case EDGE_TERMIN:
928                 tv_set_color(tv, blue);
929                 break;
930             case EDGE_CONN:
931                 tv_set_color(tv, magenta);
932                 break;
933             case EDGE_JUNC:
934                 tv_set_color(tv, orange);
935                 break;
936             case EDGE_ISOLATED:/* corner feature */
937                 tv_set_color(tv, yellow);
938                 break;
939             }
940             tv_pixel2(tv, vec2((float) x, (float) y));
941         }
942     rfree((void *) region);
943 
944     tv_reset_draw(tv);
945 }
946 
947 
948 void    tv_imrect_scale(Tv * tv, Imrect * imrect, double low, double high)
949 {
950     char *im;
951     int     storage;
952     int     lx, ly, ux, uy;
953     int     i, j, k, gl;
954     double  gld, scale255;
955     Imregion *region;
956     Imregion *tvregion;
957     Imregion *tv_get_tv_screen_region();
958 
959     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
960         return;
961     storage = cmap_get_storage(tv->cmap_data_visible);
962     tvregion = tv_get_tv_screen_region(tv);
963     tvregion->ux++;
964     tvregion->uy++;
965     region = roi_inter(tvregion, imrect->region);
966     rfree((void *) tvregion);
967 
968     if (region == NULL)
969         return;
970 
971     lx = region->lx;
972     ux = region->ux;
973     ly = region->ly;
974     uy = region->uy;
975     rfree((void *) region);
976 
977     /* display grey level */
978     im = (char *) cvector_alloc(0, (ux - lx) * (uy - ly));
979     scale255 = 255 / (high - low);
980 
981     for (i = ly, k = 0; i < uy; ++i)
982     {
983         for (j = lx; j < ux; ++j, ++k)
984         {
985             IM_PIX_GET(imrect, i, j, gld);
986             gl = (int) ((gld - low) * scale255);
987             if (gl < 0)
988                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
989 
990             else if (gl > 255)
991                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
992 
993             else
994                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
995         }
996     }
997 
998     tv_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
999     cvector_free(im, 0);
1000 }
1001 
1002 
1003 void    tv_imrect_anaglyph(Tv * tv, Imrect * imrect_left, Imrect * imrect_right, double low, double high)
1004 {
1005     int storage;
1006     float *row1, *row2;
1007     if (tv && tv->tv_screen && imrect_left && imrect_right)
1008     {
1009 
1010 /* Memory leak fixed PAB 21 / 4 / 2004: double call of roi_outer leaked a roi */
1011 
1012         Imregion *region, *region2;
1013         Imregion *tvregion;
1014         Imregion *tv_get_tv_screen_region();
1015 
1016         tvregion = tv_get_tv_screen_region(tv);
1017         tvregion->ux++;
1018         tvregion->uy++;
1019         region = roi_outer(imrect_right->region, imrect_left->region);
1020         region2 = roi_outer(tvregion, region);
1021         rfree((void *) tvregion);
1022         rfree((void *) region);
1023         storage = cmap_get_storage(tv->cmap_data_visible);
1024 
1025         if (region2)
1026         {
1027             double  scale255 = 255 / (high - low);
1028             int     gl_left, gl_right;
1029             int     k;
1030             int     row, col;
1031             int     x1 = region2->lx;   /* Top left x co-ord */
1032             int     x2 = region2->ux;   /* Bottom right x co-ord */
1033             int     y1 = region2->ly;   /* Top left y co-ord */
1034             int     y2 = region2->uy;   /* Bottom right y co-ord */
1035             unsigned char gluc_left, gluc_right;
1036             char *image_anag = (char *) cvector_alloc(0, storage*(x2 - x1) * (y2 - y1));
1037 
1038             rfree((void *) region2);
1039             row1 = fvector_alloc(x1, x2);
1040             row2 = fvector_alloc(x1, x2);
1041 
1042 
1043             /* For each row in the image */
1044             for (row = y1, k = 0; row < y2; ++row)
1045             {
1046                 im_get_rowf(row1, imrect_left, row, x1, x2);
1047                 im_get_rowf(row2, imrect_right, row, x1, x2);
1048 
1049                 /* For each column in the row */
1050                 for (col = x1; col < x2; ++col, k++)
1051                 {
1052                     /* Get the scaled left grey-level */
1053                     gl_left = (int) ((row1[col] - low) * scale255);
1054                     gluc_left = LIMIT_TO_UCHAR(gl_left);
1055 
1056                     /* Get the scaled right grey-level */
1057                     gl_right = (int) ((row2[col] - low) * scale255);
1058                     gluc_right = LIMIT_TO_UCHAR(gl_right);
1059 
1060                     /* Left = green = hi nibble. Right = red = lo
1061                      * nibble */
1062                     cmap_get_stdlut(tv->cmap_data_visible,
1063                         (gluc_left & 0xf0) | (gluc_right >> 4),image_anag,k);
1064 
1065                 }
1066             }
1067             tv_image2(tv, x1, y1, x2 - x1, y2 - y1, (char *) image_anag);
1068             cvector_free(image_anag, 0);
1069             fvector_free(row1, x1);
1070             fvector_free(row2, x1);
1071 
1072         }
1073     }
1074 }
1075 
1076 /* apply drawfunc to image of pointers */
1077 
1078 void    im_ptr_draw(Tv * tv, Imrect * im, int sx, int sy,
1079                             void (*drawfunc) (), void *data)
1080 {
1081     int     x, y, lx, ly, ux, uy;
1082 
1083     if (tv == NULL || im == NULL)
1084         return;
1085     lx = im->region->lx;
1086     ly = im->region->ly;
1087     ux = im->region->ux;
1088     uy = im->region->uy;
1089     for (x = lx; x < ux; x++)
1090         for (y = ly; y < uy; y++)
1091             (*drawfunc) (tv, IM_PTR(im, y, x), x, y, data);
1092     return;
1093 }
1094 
1095 /* draw scaled image of vec2's at sampling grid space sx, sy */
1096 
1097 static void pvec2_draw(Tv * tv, Vec2 * v, int x, int y, double *data)
1098 {
1099     int     sx = (int)data[0];
1100     int     sy = (int)data[1];
1101 
1102     if (x % sx == 0 && x % sy == 0)
1103     {
1104         double  scale = data[2];
1105 
1106         tv_vector2(tv, vec2(x + 0.5, y + 0.5), vec2_times(scale, *v));
1107     }
1108 }
1109 
1110 
1111 void    im_vec2_draw(Tv * tv, Imrect * im, int sx, int sy, double scale)
1112 {
1113     double  data[3];
1114 
1115     data[0] = sx;
1116     data[1] = sy;
1117     data[2] = scale;
1118     im_ptr_draw(tv, im, sx, sy, pvec2_draw, data);
1119 }
1120 

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