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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlbase/tlbaseColour_view.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    :
 37  * Date    :
 38  * Version :
 39  * CVS Id  :
 40  *
 41  * Notes : 
 42  *
 43  * Colour vision tool: functions for the RGB Tv's, images and the error matrix.
 44  *
 45  *********
 46 */
 47 
 48 #include "tlbaseColour_view.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #    include <config.h>
 52 #endif
 53 
 54 #include <memory.h>
 55 #include<tina/image/imgDef.h>
 56 #include<tina/image/imgPro.h>
 57 #include<tinatool/draw/drawPro.h>
 58 
 59 static Imrect *im_red=NULL;
 60 static Imrect *im_green=NULL;
 61 static Imrect *im_blue=NULL;
 62 static Imrect *im_col=NULL;
 63 static Tv *col_tv_red=NULL;
 64 static Tv *col_tv_blue=NULL;
 65 static Tv *col_tv_green=NULL;
 66 static Tv *col_tv=NULL;
 67 
 68 
 69 Tv *col_tv_red_get(void)
 70 {
 71         return(col_tv_red);
 72 }
 73 
 74 
 75 Tv *col_tv_green_get(void)
 76 {
 77         return(col_tv_green);
 78 }
 79 
 80 
 81 Tv *col_tv_blue_get(void)
 82 {
 83         return(col_tv_blue);
 84 }
 85 
 86 
 87 Tv *col_tv_get(void)
 88 {
 89         return(col_tv);
 90 }
 91 
 92 
 93 void col_tv_red_set(Tv * tv)
 94 {
 95         col_tv_red = tv;
 96 }
 97 
 98 
 99 void col_tv_green_set(Tv * tv)
100 {
101         col_tv_green = tv;
102 }
103 
104 
105 void col_tv_blue_set(Tv * tv)
106 {
107         col_tv_blue = tv;
108 }
109 
110 
111 void col_tv_set(Tv * tv)
112 {
113         col_tv = tv;
114 }
115 
116 
117 Imrect *col_im_red_get(void)
118 {
119         return (im_red);
120 }
121 
122 
123 Imrect *col_im_green_get(void)
124 {
125         return (im_green);
126 }
127 
128 
129 Imrect *col_im_blue_get(void)
130 {
131         return (im_blue);
132 }
133 
134 
135 Imrect *col_im_get(void)
136 {
137         return (im_col);
138 }
139 
140 
141 /* Note: im_col is an experimental colour Imrect version of the three RGB images.  It is updated whenever one
142 of im_red, im_green or im_blue is updated */
143 
144 void col_im_update(void)
145 {
146         Imregion *roi=NULL;
147         int i, j, lx, ly, ux, uy, nchars;
148         unsigned int vsize;
149         double pix, pixr, pixg, pixb;
150 
151         if(im_col!=NULL) im_free(im_col);
152         im_col=NULL;
153 
154         if(im_red==NULL || im_green==NULL || im_blue==NULL) return;
155 
156         im_col = im_alloc(im_red->height, im_red->width, NULL, im_red->vtype);
157         im_col_alloc(im_col);
158 
159         char **rarray1 = (char **) im_red->data;
160         char **rarray2 = (char **) im_col->rdata;
161         char **garray1 = (char **) im_green->data;
162         char **garray2 = (char **) im_col->gdata;
163         char **barray1 = (char **) im_blue->data;
164         char **barray2 = (char **) im_col->bdata;
165 
166         roi = im_red->region;
167         lx = roi->lx;
168         ly = roi->ly;
169         ux = roi->ux;
170         uy = roi->uy;
171         vsize = var_size(im_red->vtype);
172 
173         lx *= vsize;
174         ux *= vsize;
175         nchars = ux - lx;
176 
177         for (i = ly; i < uy; ++i) (void) memcpy(rarray2[i] + lx, rarray1[i] + lx, nchars);
178         for (i = ly; i < uy; ++i) (void) memcpy(garray2[i] + lx, garray1[i] + lx, nchars);
179         for (i = ly; i < uy; ++i) (void) memcpy(barray2[i] + lx, barray1[i] + lx, nchars);
180 
181         /* Now prep the data array of the colour image to be the magnitude of the rgb fields */
182 
183         for(i=ly; i<uy; i++)
184         {
185                 for(j=lx; j<ux; j++)
186                 {
187                         pixr = im_get_pixf(im_red, i, j);
188                         pixg = im_get_pixf(im_green, i, j);
189                         pixb = im_get_pixf(im_blue, i, j);
190                         pix = (pixr+pixb+pixg)/3;
191 
192                         IM_PIX_SET(im_col, i, j, pix);
193                 }
194         }
195 }
196 
197 
198 void col_im_red_set(Imrect *im)
199 {
200         im_free(im_red);
201         im_red = im;
202         col_im_update();
203 }
204 
205 
206 void col_im_green_set(Imrect *im)
207 {
208         im_free(im_green);
209         im_green = im;
210         col_im_update();
211 }
212 
213 
214 void col_im_blue_set(Imrect *im)
215 {
216         im_free(im_blue);
217         im_blue = im;
218         col_im_update();
219 }
220 
221 
222 void col_tv_red_backdraw(Tv * tv)
223 {
224         Imrect *im = col_im_red_get();
225 
226         if (im != NULL)
227         {
228                 im = imf_scale(im, 0.0, 255.0); 
229                 tv_imrect2(tv, im);
230                 im_free(im);
231         }
232 }
233 
234 
235 void col_tv_red_init(Tv * tv)
236 {
237         Imrect *im = col_im_red_get();
238 
239         if (im != NULL) tv_camera2_image(tv, im->width, im->height);
240 }
241 
242 
243 void col_tv_red_skeldraw(Tv * tv)
244 {
245         Imrect *im = col_im_red_get();
246 
247         if (im != NULL) tv_imrect_skel(tv, im);
248 }
249 
250 
251 Tv *col_tv_red_make(void)
252 {
253         Tv     *tvred = NULL;
254 
255         tvred = tv_create("Colour: red");
256         (void) tv_set_backdraw(tvred, col_tv_red_backdraw);
257         (void) tv_set_skeldraw(tvred, col_tv_red_skeldraw);
258         (void) tv_set_zoomlevel(tvred, IMZOOM);
259         tv_set_init(tvred, col_tv_red_init);
260         return (tvred);
261 }
262 
263 
264 void col_tv_green_backdraw(Tv * tv)
265 {
266         Imrect *im = col_im_green_get();
267 
268         if (im != NULL)
269         {
270                 im = imf_scale(im, 0.0, 255.0); 
271                 tv_imrect2(tv, im);
272                 im_free(im);
273         }
274 }
275 
276 
277 void col_tv_green_init(Tv * tv)
278 {
279         Imrect *im = col_im_green_get();
280 
281         if (im != NULL) tv_camera2_image(tv, im->width, im->height);
282 }
283 
284 
285 void col_tv_green_skeldraw(Tv * tv)
286 {
287         Imrect *im = col_im_green_get();
288 
289         if (im != NULL) tv_imrect_skel(tv, im);
290 }
291 
292 
293 Tv *col_tv_green_make(void)
294 {
295         Tv     *tvgreen = NULL;
296 
297         tvgreen = tv_create("Colour: green");
298         (void) tv_set_backdraw(tvgreen, col_tv_green_backdraw);
299         (void) tv_set_skeldraw(tvgreen, col_tv_green_skeldraw);
300         (void) tv_set_zoomlevel(tvgreen, IMZOOM);
301         tv_set_init(tvgreen, col_tv_green_init);
302         return (tvgreen);
303 }
304 
305 
306 void col_tv_blue_backdraw(Tv * tv)
307 {
308     Imrect *im = col_im_blue_get();
309 
310     if (im != NULL)
311     {
312         im = imf_scale(im, 0.0, 255.0); 
313         tv_imrect2(tv, im);
314         im_free(im);
315     }
316 }
317 
318 
319 void col_tv_blue_init(Tv * tv)
320 {
321         Imrect *im = col_im_blue_get();
322 
323         if (im != NULL) tv_camera2_image(tv, im->width, im->height);
324 }
325 
326 
327 void col_tv_blue_skeldraw(Tv * tv)
328 {
329         Imrect *im = col_im_blue_get();
330 
331         if (im != NULL) tv_imrect_skel(tv, im);
332 }
333 
334 
335 Tv *col_tv_blue_make(void)
336 {
337         Tv     *tvblue = NULL;
338 
339         tvblue = tv_create("Colour: blue");
340         (void) tv_set_backdraw(tvblue, col_tv_blue_backdraw);
341         (void) tv_set_skeldraw(tvblue, col_tv_blue_skeldraw);
342         (void) tv_set_zoomlevel(tvblue, IMZOOM);
343         tv_set_init(tvblue, col_tv_blue_init);
344         return (tvblue);
345 }
346 
347 
348 void col_tv_backdraw(Tv * tv)
349 {
350     Imrect *im = col_im_get();
351 
352     if (im != NULL)
353     {
354 
355 
356 /***** Need a scaling function here to set the RGB ranges to 0,255 *****/
357 
358         tv_col_imrect2(tv, im);
359     }
360 }
361 
362 
363 void col_tv_init(Tv * tv)
364 {
365         Imrect *im = col_im_get();
366 
367         if (im != NULL) tv_camera2_image(tv, im->width, im->height);
368 }
369 
370 
371 void col_tv_skeldraw(Tv * tv)
372 {
373         Imrect *im = col_im_get();
374 
375         if (im != NULL) tv_imrect_skel(tv, im);
376 }
377 
378 
379 Tv *col_tv_make(void)
380 {
381         Tv     *tvcol = NULL;
382 
383         tvcol = tv_create("Colour: RGB");
384         (void) tv_set_backdraw(tvcol, col_tv_backdraw);
385         (void) tv_set_skeldraw(tvcol, col_tv_skeldraw);
386         (void) tv_set_zoomlevel(tvcol, IMZOOM);
387         tv_set_init(tvcol, col_tv_init);
388         return (tvcol);
389 }
390 

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