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

Linux Cross Reference
Tina4/src/draw/paint/tv_imrect.c

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

  1 /** @(#)Display imrects on tv (ie on the tv_screen installed on the tv).
  2  **/
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 #include <tina/tv.h>
 11 #include <tina/draw.h>
 12 #include <tina/drawfuncs.h>
 13 #include <tina/tvfuncs.h>
 14 
 15 #define LIMIT_TO_UCHAR(_grey) (((_grey)<0) ? 0 : (((_grey)<256) ? (_grey) : 255))
 16 
 17 
 18 cmap_get_stdlut(Cmap_data_visible *cmap,int clut,char *im,int loc)
 19 {
 20     unsigned short *im16 = (unsigned short *) im;
 21     unsigned int *im32 = (unsigned int *) im;
 22     
 23     if (cmap->nplanes == 8)
 24        im[loc] = cmap->std_lut[clut];
 25     else if (cmap->nplanes == 16)
 26        im16[loc] = cmap->std_lut[clut]; 
 27     else if (cmap->nplanes == 24 || cmap->nplanes == 32)
 28        im32[loc] = cmap->std_lut[clut];
 29 }
 30 
 31 int cmap_get_storage(Cmap_data_visible *cmap)
 32 {
 33     if (cmap->nplanes != 8 && cmap->nplanes !=16 && cmap->nplanes != 24)
 34        errorf(warning,"cmap_get_storage: %d bits not tested \n", cmap->nplanes);
 35     if (cmap->nplanes == 24) return 4;
 36     else return(cmap->nplanes/8);
 37 }
 38 
 39 static void linexy(Tv * tv, int x1, int y1, int x2, int y2)
 40 {
 41     tv_line2(tv, vec2((float) x1, (float) y1), vec2((float) x2, (float) y2));
 42 }
 43 
 44 void    tv_imrect_skel(Tv * tv, Imrect * imrect)
 45 {
 46     int     lx, ly, ux, uy;
 47     int     dx, dy;
 48     int     x, y;
 49 
 50     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->region == NULL)
 51         return;
 52 
 53     lx = imrect->region->lx;
 54     ux = imrect->region->ux;
 55     ly = imrect->region->ly;
 56     uy = imrect->region->uy;
 57 
 58     dx = (ux - lx) / 16;
 59     dy = (uy - ly) / 16;
 60     if (dx<1) dx = 1; /* BUG fix NAT */
 61     if (dy<1) dy = 1; /* 26/5/95     */
 62 
 63     for (x = lx; x < ux; x += dx)
 64         linexy(tv, x, ly, x, uy);
 65     linexy(tv, ux, ly, ux, uy);
 66     for (y = ly; y < uy; y += dy)
 67         linexy(tv, lx, y, ux, y);
 68     linexy(tv, lx, y, ux, y);
 69 }
 70 
 71 void tv_image(Tv * tv, int c, int r, int w, int h, char *data)
 72 {
 73     if (tv == NULL || tv->tv_screen == NULL)
 74         return;
 75 
 76     tv_screen_image(tv->tv_screen, c, r, w, h, data);
 77 }
 78 
 79 void tv_image2(Tv * tv, int c, int r, int w, int h, char *data)
 80 {
 81     int storage;
 82     char *im;
 83     Ipos ll = {Ipos_id};
 84     Ipos ur = {Ipos_id};        /* low left and upper right */
 85     Vec2 origin = {Vec2_id};
 86     int lx, ly, ux, uy;
 87     float sx, sy, imx, imy;
 88     int i, j, k;
 89     if (tv == NULL || tv->tv_screen == NULL)
 90         return;
 91 
 92     storage = cmap_get_storage(tv->cmap_data_visible);
 93     ll = tv_proj2(tv, vec2((float) c, (float) r));
 94     ur = tv_proj2(tv, vec2((float) c + w, (float) r + h));
 95     lx = ipos_x(ll);
 96     ly = ipos_y(ll);
 97     ux = ipos_x(ur);
 98     uy = ipos_y(ur);
 99     sx = (float)(1.0 / tv->scalex);
100     sy = (float)(1.0 / tv->scaley);
101     if (lx > ux)
102     {
103         SWAP(int, lx, ux);
104         sx = -sx;
105     }
106     if (ly > uy)
107     {
108         SWAP(int, ly, uy);
109         sy = -sy;
110     }
111     lx = MAX(0, lx);
112     ux = MIN(tv->width, ux);
113     ly = MAX(0, ly);
114     uy = MIN(tv->height, uy);
115 
116     origin = tv_backproj2(tv, ipos(lx, ly));
117     im = cvector_alloc(0, storage*(ux - lx) * (uy - ly));
118 
119     imy = vec2_y(origin);
120     for (i = ly, k = 0; i < uy; ++i)
121     {
122         int y, yoff;
123         y = (int)(imy - r);
124         yoff = y * w;
125 
126         imx = vec2_x(origin);
127         for (j = lx; j < ux; ++j, ++k)
128         {
129             int x = (int)(imx - c);
130             if (y < 0 || x < 0 || y >= h || x >= w)
131             {
132                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
133             }
134             else
135             {
136                 if (storage==1)
137                    im[k] = data[yoff+x];
138                 else if (storage==2)
139                 {
140                    im[2*k] = data[2*(yoff+x)];
141                    im[2*k+1] = data[2*(yoff+x)+1]; 
142                 }
143                 else if (storage==3)
144                 {
145                    im[3*k] = data[3*(yoff+x)];
146                    im[3*k+1] = data[3*(yoff+x)+1];
147                    im[3*k+2] = data[3*(yoff+x)+2];
148                 }
149                 else if (storage ==4)
150                 {
151                    im[4*k] = data[4*(yoff+x)];
152                    im[4*k+1] = data[4*(yoff+x)+1];
153                    im[4*k+2] = data[4*(yoff+x)+2];
154                    im[4*k+3] = data[4*(yoff+x)+3];
155                 }
156             }
157 
158             imx += sx;
159         }
160         imy += sy;
161     }
162 
163     tv_screen_image(tv->tv_screen, lx, ly, ux - lx, uy - ly, (char *)im);
164     cvector_free((void *) im, 0);
165 }
166 
167 void    tv_imrect(Tv * tv, Imrect * imrect, int sample)
168 {
169     unsigned char *im;
170     int     storage;
171     int     lx, ly, ux, uy;
172     int     h, w, size;
173     int     i, j, k;
174 
175     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL || imrect->region == NULL)
176         return;
177     storage = cmap_get_storage(tv->cmap_data_visible);
178 
179     lx = imrect->region->lx;
180     ux = imrect->region->ux;
181     ly = imrect->region->ly;
182     uy = imrect->region->uy;
183 
184     h = (uy - ly) / sample;
185     w = (ux - lx) / sample;
186     size = h * w;
187 
188     im = (unsigned char *) cvector_alloc(0, storage*size);
189 
190     for (i = ly, k = 0; i < uy; i += sample)
191     {
192         for (j = lx; j < ux; j += sample, ++k)
193         {
194             int     gl;
195 
196             IM_PIX_GET(imrect, i, j, gl);
197             if (gl < 0)
198                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
199             else if (gl > 255)
200                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
201             else
202                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
203         }
204     }
205 
206     tv_image(tv, lx, ly, w, h, (char *) im);
207     cvector_free((void *) im, 0);
208 }
209 
210 void    tv_imrect2_interpol(Tv * tv, Imrect * imrect)
211 {
212     int     storage;
213     unsigned char *im;
214     Vec2    v = {Vec2_id};
215     int     i, j, k;
216     int     height, width;
217     int     gl;
218 
219 
220     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
221         return;
222     storage = cmap_get_storage(tv->cmap_data_visible);
223 
224     height = tv->height;
225     width = tv->width;
226     im = (unsigned char *) cvector_alloc(0, storage* height * width);
227 
228     for (i = 0, k = 0; i < height; ++i)
229     {
230         for (j = 0; j < width; ++j, ++k)
231         {
232             v = tv_backproj2(tv, ipos(j, i));
233             gl = (int)(im_sub_pixf(imrect, vec2_y(v), vec2_x(v)) + 0.5);
234             if (gl < 0)
235                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
236             else if (gl > 255)
237                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
238             else
239                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
240         }
241     }
242 
243     tv_image(tv, 0, 0, width, height, (char *) im);
244     cvector_free((void *) im, 0);
245 }
246 
247 void    tv_imrect2(Tv * tv, Imrect * imrect)
248 {
249     int    *row;
250     int storage=1;
251     unsigned char *im;
252     unsigned short *im16;
253     int     lx, ly, ux, uy;
254     int     i, j, k;
255     Imregion *region;
256     Imregion *tvregion;
257 
258     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
259         return;
260     storage = cmap_get_storage(tv->cmap_data_visible);
261     tvregion = tv_get_tv_screen_region(tv);
262     tvregion->ux++;
263     tvregion->uy++;
264     region = roi_inter(tvregion, imrect->region);
265     rfree((void *) tvregion);
266 
267     if (region == NULL)
268         return;
269 
270     lx = region->lx;
271     ux = region->ux;
272     ly = region->ly;
273     uy = region->uy;
274     rfree((void *) region);
275 
276     row = ivector_alloc(lx, ux);/* intensisty */
277 
278     im = (unsigned char *) cvector_alloc(0, storage * (ux - lx) * (uy - ly));
279 
280     for (i = ly, k = 0; i < uy; ++i)
281     {
282         im_get_row(row, imrect, i, lx, ux);
283         for (j = lx; j < ux; ++j, ++k)
284         {
285             int     gl = row[j];
286 
287             if (gl < 0)
288             {
289                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
290             }
291             else if (gl > 255)
292             {
293                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
294             }
295             else
296             {
297                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
298             }
299         }
300     }
301 
302     tv_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
303     ivector_free((void *) row, lx);
304     cvector_free((void *) im, 0);
305 }
306 
307 void    tv_imrect_row(Tv * tv, Imrect * im, int r)
308 {
309     int    *row;
310     int storage;
311     unsigned char *rast;
312     int     lx, ux;
313     int     i;
314 
315     if (tv == NULL || tv->tv_screen == NULL || im == NULL || im->region == NULL)
316         return;
317     storage = cmap_get_storage(tv->cmap_data_visible);
318 
319     lx = im->region->lx;
320     ux = im->region->ux;
321 
322     row = ivector_alloc(lx, ux);
323     rast = (unsigned char *) cvector_alloc(storage*lx, storage*ux);     
324 
325     im_get_row(row, im, r, lx, ux);
326     for (i = lx; i < ux; ++i)
327                 cmap_get_stdlut(tv->cmap_data_visible,row[i],rast,i);
328 
329 
330     /* BUG tv_raster(tv, x1, x2, y, char   *raster) NOT unsigned char* */
331     tv_raster(tv, lx, ux, i, (char *) rast);
332 
333     ivector_free((void *) row, lx);
334     cvector_free((void *) rast, lx);
335 }
336 
337 void    tv_imrect_row2(Tv * tv, Imrect * im, int r)
338 {
339     int    *row;
340     int     storage;
341     unsigned char *rast;
342     int     lx, ux;
343     Imregion *region;
344     Imregion *tvregion;
345     int     i;
346 
347     if (tv == NULL || tv->tv_screen == NULL || im == NULL)
348         return;
349     storage = cmap_get_storage(tv->cmap_data_visible);
350 
351     tvregion = tv_get_tv_screen_region(tv);
352     tvregion->ux++;
353     tvregion->uy++;
354     region = roi_inter(tvregion, im->region);
355     rfree((void *) tvregion);
356 
357     if (region == NULL)
358         return;
359 
360     lx = region->lx;
361     ux = region->ux;
362     rfree((void *) region);
363 
364     row = ivector_alloc(lx, ux);/* intensisty */
365     rast = (unsigned char *) cvector_alloc(storage*lx, storage*ux);     /* display grey level */
366 
367     im_get_row(row, im, r, lx, ux);
368     for (i = lx; i < ux; ++i)
369         cmap_get_stdlut(tv->cmap_data_visible,row[i],rast,i);
370 
371 
372 
373     /* BUG tv_raster(tv, lx, ux, i,char *rast NOT unsigned char * */
374     tv_raster(tv, lx, ux, i, (char *) rast);
375 
376     ivector_free((void *) row, lx);
377     cvector_free((void *) rast, lx);
378 }
379 
380 void    tv_edges(Tv * tv, Imrect * edgerect)
381 {
382     int     lx, ly, ux, uy;
383     int     x, y;
384     Imregion *tvregion;
385     Imregion *region;
386 
387     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
388         return;
389 
390     tvregion = tv_get_tv_screen_region(tv);
391     tvregion->ux++;
392     tvregion->uy++;
393     region = roi_inter(tvregion, edgerect->region);
394     rfree((void *) tvregion);
395 
396     if (region == NULL)
397         return;
398 
399     lx = region->lx;
400     ly = region->ly;
401     ux = region->ux;
402     uy = region->uy;
403 
404     tv_save_draw(tv);
405     tv_set_color(tv, green);
406     for (y = ly; y < uy; y++)
407         for (x = lx; x < ux; x++)
408         {
409             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
410 
411             if (eptr == NULL)
412                 continue;
413             tv_pixel2(tv, vec2((float) x, (float) y));
414         }
415     rfree((void *) region);
416 
417     tv_reset_draw(tv);
418 }
419 
420 void    tv_edges_conn(Tv * tv, Imrect * edgerect)
421 {
422     int     lx, ly, ux, uy;
423     int     x, y;
424     Imregion *tvregion;
425     Imregion *region;
426 
427     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
428         return;
429 
430     tvregion = tv_get_tv_screen_region(tv);
431     tvregion->ux++;
432     tvregion->uy++;
433     region = roi_inter(tvregion, edgerect->region);
434     rfree((void *) tvregion);
435 
436     if (region == NULL)
437         return;
438 
439     lx = region->lx;
440     ly = region->ly;
441     ux = region->ux;
442     uy = region->uy;
443 
444     tv_save_draw(tv);
445     for (y = ly; y < uy; y++)
446         for (x = lx; x < ux; x++)
447         {
448             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
449 
450             if (eptr == NULL)
451                 continue;
452 
453             switch (eptr->type & EDGE_GET_CONN_MASK)
454             {
455             case EDGE_NOLINK:
456                 tv_set_color(tv, salmon);
457                 break;
458             case EDGE_TERMIN:
459                 tv_set_color(tv, blue);
460                 break;
461             case EDGE_CONN:
462                 tv_set_color(tv, magenta);
463                 break;
464             case EDGE_JUNC:
465                 tv_set_color(tv, orange);
466                 break;
467             case EDGE_ISOLATED:/* corner feature */
468                 tv_set_color(tv, yellow);
469                 break;
470             }
471             tv_pixel2(tv, vec2((float) x, (float) y));
472         }
473 
474     tv_reset_draw(tv);
475 
476     rfree((void *) region);
477 }
478 
479 void    tv_string2(Tv * tv, Tstring * string)
480 {
481     List *start;
482     List *end;
483     List *dptr;
484     Vec2    oldpos = {Vec2_id};
485     Vec2    pos = {Vec2_id};
486 
487     if (string == NULL)
488         return;
489 
490     start = string->start;
491     end = string->end;
492 
493     if (start == end)
494     {
495         tv_pixel2(tv, edge_image_pos((Edgel *) start->to));
496         return;
497     }
498     oldpos = edge_image_pos((Edgel *) start->to);
499     tv_cross2(tv, oldpos, 5);
500     for (dptr = start; dptr != end;)
501     {
502         dptr = dptr->next;
503         pos = edge_image_pos((Edgel *) dptr->to);
504         tv_point2(tv, oldpos);  /* for xor */
505         tv_line2(tv, oldpos, pos);
506         oldpos = pos;
507     }
508     tv_cross2(tv, oldpos, 5);
509 }
510 
511 void    tv_string2_col(Tv * tv, Tstring * string, int type)
512 {
513     List *start;
514     List *end;
515     List *dptr;
516     Vec2    oldpos = {Vec2_id};
517     Vec2    pos = {Vec2_id};
518 
519     if (string == NULL)
520         return;
521 
522     start = string->start;
523     end = string->end;
524 
525     tv_save_draw(tv);
526     if (start == end)
527     {
528         tv_color_set(tv, salmon);
529         tv_pixel2(tv, edge_image_pos((Edgel *) start->to));
530         tv_reset_draw(tv);
531         return;
532     }
533     oldpos = edge_image_pos((Edgel *) start->to);
534     tv_color_set(tv, red);
535     tv_point2(tv, oldpos);
536     for (dptr = start; dptr != end;)
537     {
538         dptr = dptr->next;
539         pos = edge_image_pos((Edgel *) dptr->to);
540         tv_color_set(tv, salmon);
541         tv_line2(tv, oldpos, pos);
542         oldpos = pos;
543     }
544     tv_color_set(tv, red);
545     tv_point2(tv, oldpos);
546     tv_reset_draw(tv);
547 }
548 
549 void    tv_string_list(Tv * tv, List * string_list)
550 {
551     List   *sptr;
552     int    type;
553 
554     if (tv == NULL || tv->tv_screen == NULL || string_list == NULL)
555         return;
556 
557     for (sptr = string_list; sptr != NULL; sptr = sptr->next)
558         tv_string2_col(tv, sptr->to, type);
559 }
560 
561 void    tv_strings(Tv * tv, Imrect * edgerect)
562 {
563     List   *string_list;
564 
565     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL)
566         return;
567 
568     string_list = (List *) prop_get(edgerect->props, STRING);
569     tv_save_draw(tv);
570     tv_string_list(tv, string_list);
571 }
572 
573 void    tv_edge_string(Tv * tv, Tstring * string)
574 {
575     List *dptr;
576     List *end;
577 
578     if (string == NULL)
579         return;
580 
581     dptr = string->start;
582     end = string->end;
583 
584     tv_pixel2(tv, edge_image_pos((Edgel *) dptr->to));
585     if (dptr == end)            /* a single pixel */
586         return;
587     for (; dptr != end;)
588     {
589         dptr = dptr->next;
590         tv_pixel2(tv, edge_image_pos((Edgel *) dptr->to));
591     }
592 }
593 
594 void    tv_edge_match(Tv * tv1, Tv * tv2, Match * em)
595 {
596     if (em == NULL)
597         return;
598 
599     tv_edge_string(tv1, (Tstring *) em->to1);
600     tv_edge_string(tv2, (Tstring *) em->to2);
601 }
602 
603 void    tv_edge_match_list(Tv * tv1, Tv * tv2, List * mlist)
604 {
605     List   *lptr;
606 
607     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
608         tv_edge_match(tv1, tv2, (Match *) lptr->to);
609 }
610 
611 void    tv_edges_conn_propmask(Tv * tv, Imrect * edgerect, int mask, int type)
612 {
613     int     lx, ly, ux, uy;
614     int     x, y;
615     Imregion *tvregion;
616     Imregion *region;
617 
618     if (tv == NULL || tv->tv_screen == NULL || edgerect == NULL || mask == 0)
619         return;
620 
621     tvregion = tv_get_tv_screen_region(tv);
622     tvregion->ux++;
623     tvregion->uy++;
624     region = roi_inter(tvregion, edgerect->region);
625     rfree((void *) tvregion);
626 
627     if (region == NULL)
628         return;
629 
630     lx = region->lx;
631     ly = region->ly;
632     ux = region->ux;
633     uy = region->uy;
634 
635     tv_save_draw(tv);
636     for (y = ly; y < uy; y++)
637         for (x = lx; x < ux; x++)
638         {
639             Edgel  *eptr = (Edgel *) IM_PTR(edgerect, y, x);
640 
641             if (eptr == NULL || !((int) prop_get(eptr->props, type) & mask))
642                 continue;
643 
644             switch (eptr->type & EDGE_GET_CONN_MASK)
645             {
646             case EDGE_NOLINK:
647                 tv_set_color(tv, salmon);
648                 break;
649             case EDGE_TERMIN:
650                 tv_set_color(tv, blue);
651                 break;
652             case EDGE_CONN:
653                 tv_set_color(tv, magenta);
654                 break;
655             case EDGE_JUNC:
656                 tv_set_color(tv, orange);
657                 break;
658             case EDGE_ISOLATED:/* corner feature */
659                 tv_set_color(tv, yellow);
660                 break;
661             }
662             tv_pixel2(tv, vec2((float) x, (float) y));
663         }
664     rfree((void *) region);
665 
666     tv_reset_draw(tv);
667 }
668 
669 void    tv_imrect_scale(Tv * tv, Imrect * imrect, double low, double high)
670 {
671     unsigned char *im;
672     int     storage;
673     int     lx, ly, ux, uy;
674     int     i, j, k, gl;
675     double  gld, scale255;
676     Imregion *region;
677     Imregion *tvregion;
678     Imregion *tv_get_tv_screen_region();
679 
680     if (tv == NULL || tv->tv_screen == NULL || imrect == NULL)
681         return;
682     storage = cmap_get_storage(tv->cmap_data_visible);
683     tvregion = tv_get_tv_screen_region(tv);
684     tvregion->ux++;
685     tvregion->uy++;
686     region = roi_inter(tvregion, imrect->region);
687     rfree((void *) tvregion);
688 
689     if (region == NULL)
690         return;
691 
692     lx = region->lx;
693     ux = region->ux;
694     ly = region->ly;
695     uy = region->uy;
696     rfree((void *) region);
697 
698     /* display grey level */
699     im = (unsigned char *) cvector_alloc(0, (ux - lx) * (uy - ly));
700     scale255 = 255 / (high - low);
701 
702     for (i = ly, k = 0; i < uy; ++i)
703     {
704         for (j = lx; j < ux; ++j, ++k)
705         {
706             IM_PIX_GET(imrect, i, j, gld);
707             gl = (int) ((gld - low) * scale255);
708             if (gl < 0)
709                 cmap_get_stdlut(tv->cmap_data_visible,0,im,k);
710 
711             else if (gl > 255)
712                 cmap_get_stdlut(tv->cmap_data_visible,255,im,k);
713 
714             else
715                 cmap_get_stdlut(tv->cmap_data_visible,gl,im,k);
716         }
717     }
718 
719     tv_image2(tv, lx, ly, ux - lx, uy - ly, (char *) im);
720     cvector_free((void *) im, 0);
721 }
722 
723 
724 
725 
726 
727 void    tv_imrect_anaglyph(Tv * tv, Imrect * imrect_left, Imrect * imrect_right, double low, double high)
728 {
729     int storage;
730     float *row1, *row2;
731     if (tv && tv->tv_screen && imrect_left && imrect_right)
732     {
733         Imregion *region;
734         Imregion *tvregion;
735         Imregion *tv_get_tv_screen_region();
736 
737         tvregion = tv_get_tv_screen_region(tv);
738         tvregion->ux++;
739         tvregion->uy++;
740         region = roi_outer(imrect_right->region, imrect_left->region);
741         region = roi_outer(tvregion, region);
742         rfree((void *) tvregion);
743         storage = cmap_get_storage(tv->cmap_data_visible);
744 
745         if (region)
746         {
747             double  gld_left, gld_right;
748             double  scale255 = 255 / (high - low);
749             int     gl_left, gl_right;
750             int     k;
751             int     row, col;
752             int     x1 = region->lx;    /* Top left x co-ord */
753             int     x2 = region->ux;    /* Bottom right x co-ord */
754             int     y1 = region->ly;    /* Top left y co-ord */
755             int     y2 = region->uy;    /* Bottom right y co-ord */
756             unsigned char gluc_left, gluc_right;
757             unsigned char *image_anag = (unsigned char *) cvector_alloc(0, storage*(x2 - x1) * (y2 - y1));
758 
759             rfree((void *) region);
760             row1 = fvector_alloc(x1, x2);
761             row2 = fvector_alloc(x1, x2);
762 
763 
764             /* For each row in the image */
765             for (row = y1, k = 0; row < y2; ++row)
766             {
767                 im_get_rowf(row1, imrect_left, row, x1, x2);
768                 im_get_rowf(row2, imrect_right, row, x1, x2);
769                 
770                 /* For each column in the row */
771                 for (col = x1; col < x2; ++col, k++)
772                 {
773                     /* Get the scaled left grey-level */
774                     gl_left = (int) ((row1[col] - low) * scale255);
775                     gluc_left = LIMIT_TO_UCHAR(gl_left);
776 
777                     /* Get the scaled right grey-level */
778                     gl_right = (int) ((row2[col] - low) * scale255);
779                     gluc_right = LIMIT_TO_UCHAR(gl_right);
780 
781                     /* Left = green = hi nibble. Right = red = lo
782                      * nibble */
783                     cmap_get_stdlut(tv->cmap_data_visible,
784                         (gluc_left & 0xf0) | (gluc_right >> 4),image_anag,k);
785 
786                 }
787             }
788             tv_image2(tv, x1, y1, x2 - x1, y2 - y1, (char *) image_anag);
789             cvector_free((void *) image_anag, 0);
790             fvector_free(row1, x1);
791             fvector_free(row2, x1);
792 
793         }
794     }
795 }
796 
797 /* apply drawfunc to image of pointers */
798 
799 void    im_ptr_draw(Tv * tv, Imrect * im, int sx, int sy,
800                             void (*drawfunc) (), void *data)
801 {
802     int     x, y, lx, ly, ux, uy;
803 
804     if (tv == NULL || im == NULL)
805         return;
806     lx = im->region->lx;
807     ly = im->region->ly;
808     ux = im->region->ux;
809     uy = im->region->uy;
810     for (x = lx; x < ux; x++)
811         for (y = ly; y < uy; y++)
812             (*drawfunc) (tv, IM_PTR(im, y, x), x, y, data);
813     return;
814 }
815 
816 /* draw scaled image of vec2's at sampling grid space sx, sy */
817 
818 static void pvec2_draw(Tv * tv, Vec2 * v, int x, int y, double *data)
819 {
820     int     sx = (int)data[0];
821     int     sy = (int)data[1];
822 
823     if (x % sx == 0 && x % sy == 0)
824     {
825         double  scale = data[2];
826 
827         tv_vector2(tv, vec2(x + 0.5, y + 0.5), vec2_times(scale, *v));
828     }
829 }
830 
831 void    im_vec2_draw(Tv * tv, Imrect * im, int sx, int sy, double scale)
832 {
833     double  data[3];
834 
835     data[0] = sx;
836     data[1] = sy;
837     data[2] = scale;
838     im_ptr_draw(tv, im, sx, sy, pvec2_draw, data);
839 }
840 

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