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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgGen_alloc.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-libs/tina/image/imgGen_alloc.c,v $
 37  * Date    :  $Date: 2004/08/05 14:32:44 $
 38  * Version :  $Revision: 1.8 $
 39  * CVS Id  :  $Id: imgGen_alloc.c,v 1.8 2004/08/05 14:32:44 neil Exp $
 40  *
 41  * Author  : Legacy TINA
 42  */
 43 
 44 /** 
 45  *  @file
 46  *  @brief Allocation and copying of Imrect - Tina's generic image structure.
 47  *
 48  *  Imrect is:
 49  *  Ts_id ts_id The TINA structure identifier.
 50  *  Vartype vtype The variable type of the image data.
 51  *  int width, height The width and height of the image.
 52  *  Imregion *region The region coveredby the image.
 53  *  void *data Array of pointers to the image rows.
 54  *  List *props Properties list: covers all the extras for an edge rect.
 55  */
 56 
 57 
 58 #include "imgGen_alloc.h"
 59 
 60 #if HAVE_CONFIG_H
 61 #include <config.h>
 62 #endif
 63 
 64 
 65 #include <stdio.h>
 66 #include <memory.h>
 67 #include <tina/sys/sysDef.h>
 68 #include <tina/sys/sysPro.h>
 69 #include <tina/image/img_GenDef.h>
 70 #include <tina/image/imgGen_region.h>
 71 
 72 
 73 /**
 74  * @brief Allocates an imrect structure.
 75  * @param height The image height (i.e. no of rows).
 76  * @param width The image width (i.e. length of rows).
 77  * @param region Pointer to the roi: the region covered.
 78  * @param vtype The variable type of the image data.
 79  * @return image Pointer to the allocated imrect
 80  *
 81  * Image allocation.  Allocate memory for Imrect data structure and for
 82  * region of interest (roi) i.e. Imrect (image rectangle) and imregion. Set
 83  * roi co-ordinates (top-left bottom-right). Allocate memory for image data.
 84  * Note that if the argument roi is NULL, a roi will be allocated from 0 to height
 85  * and 0 to width; if not, the argument roi will be copied i.e. a new roi is 
 86  * always allocated.
 87  */
 88 Imrect         *im_alloc(int height, int width, Imregion * region, Vartype vtype)
 89 {
 90         Imrect         *image;
 91         /*
 92                 Imregion *roi_alloc();
 93                 Imregion *roi_copy();
 94         
 95                 void **narray_alloc();
 96         */
 97 
 98         int             lx, ly, ux, uy;
 99 
100         if (region == NULL)     /* alloc whole image */
101                 region = roi_alloc(0, 0, width, height);
102         else                    /* use copy of given region */
103                 region = roi_copy(region);
104 
105         if (region == NULL)
106                 return (NULL);
107 
108         lx = region->lx;
109         ly = region->ly;
110         ux = region->ux;
111         uy = region->uy;
112 
113         image = ts_ralloc(Imrect);
114 
115         image->height = height;
116         image->width = width;
117         image->vtype = vtype;
118         image->region = region;
119         image->props = NULL;
120         if (vtype == complex_v)
121         {
122                 image->data = (void *) ts_narray_alloc(ly, lx, uy, ux, Complex);
123         } else
124         {
125                 image->data = (void *) narray_alloc(ly, lx, uy, ux, var_size(vtype));
126         }
127 
128         image->rdata = NULL;
129         image->gdata = NULL;
130         image->bdata = NULL;
131 
132         return image;
133 }
134 
135 
136 /**
137  * @brief Allocates the rgb fields of an imrect structure.
138  * @param im An Imrect structure.
139  *
140  * Allocate the RGB fields of an Imrect structure. These are not allocated by default as they 
141  * are only intended for colour display and are not used in the majority of the algorithmic
142  * functionality: always allocating them would waste a great deal of memory when dealing with 
143  * large sequences of data.
144  *
145  * For the moment, the RGB fields have the same type as the intensity field, and are only 
146  * implemented for types that resolve to a single number (i.e. not for complex, pointer 
147  * or vram data types).
148  *
149  */
150 void im_col_alloc(Imrect *im)
151 {
152         int lx, ly, ux, uy;
153         int vsize;
154         Imregion *roi = NULL;
155 
156         if(im==NULL) return;
157         roi = im->region;
158         if (roi == NULL) return;
159 
160         vsize = var_size(im->vtype);
161 
162         lx = roi->lx;
163         ly = roi->ly;
164         ux = roi->ux;
165         uy = roi->uy;
166 
167         if(im->vtype == char_v || im->vtype == uchar_v || im->vtype == short_v || im->vtype == ushort_v || 
168            im->vtype == int_v || im->vtype == uint_v || im->vtype == float_v || im->vtype == double_v)
169         {
170                 if(im->rdata!=NULL) narray_free((char **) im->rdata, ly, lx, uy, ux, vsize);
171                 if(im->gdata!=NULL) narray_free((char **) im->gdata, ly, lx, uy, ux, vsize);
172                 if(im->bdata!=NULL) narray_free((char **) im->bdata, ly, lx, uy, ux, vsize);
173 
174                 im->rdata = (void *) narray_alloc(ly, lx, uy, ux, vsize);
175                 im->gdata = (void *) narray_alloc(ly, lx, uy, ux, vsize);
176                 im->bdata = (void *) narray_alloc(ly, lx, uy, ux, vsize);
177         }
178 }
179 
180 
181 /**
182  * @brief Wrap an imrect data structure around the contiguous block of memory.
183  * @param mem_ptr Pointer to a contiguous memory block to be wrapped in an imrect.
184  * @param height The height of the image i.e. no. of rows.
185  * @param width The width of the image i.e. length of rows.
186  * @param region The region covered.
187  * @param vtype The variable type of the image data.
188  * @return image Pointer to the allocated imrect.
189  * 
190  * Wrap an imrect data structure around the contiguous block of memory
191  * specified by the region and vtype arguments. Note that if the argument region 
192  * is NULL, a region will be allocated from 0 to height and 0 to width; if not, the
193  * argument region will be copied i.e. a new region is always allocated.
194  *
195  * TINA6: this function is not used and should be deprecated on reversioning to TINA6.
196  *
197  */
198 Imrect         *im_wrap_contig(void *mem_ptr, int height, int width,
199                                            Imregion * region, Vartype vtype)
200 {
201         Imrect         *image;
202         Imregion       *roi_alloc();
203         Imregion       *roi_copy();
204         int             i;
205         int             lx, ly, ux, uy;
206         int             roi_width;
207         unsigned int    vsize;
208         void           *nvector_alloc();
209         void          **data;
210 
211         if (region == NULL)     /* alloc whole image */
212                 region = roi_alloc(0, 0, width, height);
213         else                    /* use copy of given region */
214                 region = roi_copy(region);
215 
216         if (region == NULL)
217                 return (NULL);
218 
219         lx = region->lx;
220         ly = region->ly;
221         ux = region->ux;
222         uy = region->uy;
223         roi_width = ux - lx;
224 
225         image = ts_ralloc(Imrect);
226 
227         image->height = height;
228         image->width = width;
229         image->vtype = vtype;
230         image->region = region;
231         image->props = NULL;
232 
233         image->rdata = NULL;
234         image->gdata = NULL;
235         image->bdata = NULL;
236 
237         data = (void **) nvector_alloc(ly, uy, sizeof(void *));
238         image->data = (void *) data;
239 
240         vsize = var_size(vtype);
241 
242         for (i = ly; i < uy; ++i)
243                 data[i] =
244                         /*(void *) ((int) mem_ptr + (roi_width * (i - ly) - lx) * vsize);*/
245                         (void *) ((long int) mem_ptr + (roi_width * (i - ly) - lx) * vsize); /*JD, 2015.01.27*/
246 
247         return image;
248 }
249 
250 
251 /**
252  * @brief Copy specified roi of image1 to image2 through a double.
253  * @param image1 Pointer to the image acting as a data source.
254  * @param image2 Pointer to the image acting as a data destination.
255  * @param roi The region of image1 to be copied into image 2.
256  * @return void
257  *
258  * Copy specified roi of image1 to image2 through a double. Storage must
259  * already be allocated for image2.
260  */
261 static void     write_thro_double(Imrect * image1, Imrect * image2,
262                                                   Imregion * roi)
263 {
264         int             lx, ly, ux, uy;
265         int             i, j;
266         double          gl;
267 
268 
269         lx = roi->lx;
270         ly = roi->ly;
271         ux = roi->ux;
272         uy = roi->uy;
273 
274         for (i = ly; i < uy; ++i)
275                 for (j = lx; j < ux; ++j)
276                 {
277                         IM_PIX_GET(image1, i, j, gl);
278                         IM_PIX_SET(image2, i, j, gl);
279                 }
280 }
281 
282 
283 /**
284  * @brief Copy specified roi of image1 rdata to image2 rdata through a double.
285  * @param image1 Pointer to the image acting as a data source.
286  * @param image2 Pointer to the image acting as a data destination.
287  * @param roi The region of image1 rdata to be copied into image 2.
288  * @return void
289  *
290  * Copy specified roi of image1 rdata to image2 rdata through a double. Storage must
291  * already be allocated for image2.
292  */
293 static void     write_r_thro_double(Imrect * image1, Imrect * image2,
294                                                   Imregion * roi)
295 {
296         int             lx, ly, ux, uy;
297         int             i, j;
298         double          gl;
299 
300 
301         lx = roi->lx;
302         ly = roi->ly;
303         ux = roi->ux;
304         uy = roi->uy;
305 
306         for (i = ly; i < uy; ++i)
307                 for (j = lx; j < ux; ++j)
308                 {
309                         IM_R_PIX_GET(image1, i, j, gl);
310                         IM_R_PIX_SET(image2, i, j, gl);
311                 }
312 }
313 
314 
315 /**
316  * @brief Copy specified roi of image1 gdata to image2 gdata through a double.
317  * @param image1 Pointer to the image acting as a data source.
318  * @param image2 Pointer to the image acting as a data destination.
319  * @param roi The region of image1 gdata to be copied into image 2.
320  * @return void
321  *
322  * Copy specified roi of image1 gdata to image2 gdata through a double. Storage must
323  * already be allocated for image2.
324  */
325 static void     write_g_thro_double(Imrect * image1, Imrect * image2,
326                                                   Imregion * roi)
327 {
328         int             lx, ly, ux, uy;
329         int             i, j;
330         double          gl;
331 
332 
333         lx = roi->lx;
334         ly = roi->ly;
335         ux = roi->ux;
336         uy = roi->uy;
337 
338         for (i = ly; i < uy; ++i)
339                 for (j = lx; j < ux; ++j)
340                 {
341                         IM_G_PIX_GET(image1, i, j, gl);
342                         IM_G_PIX_SET(image2, i, j, gl);
343                 }
344 }
345 
346 
347 /**
348  * @brief Copy specified roi of image1 bdata to image2 bdata through a double.
349  * @param image1 Pointer to the image acting as a data source.
350  * @param image2 Pointer to the image acting as a data destination.
351  * @param roi The region of image1 rdata to be copied into image 2.
352  * @return void
353  *
354  * Copy specified roi of image1 bdata to image2 rdata through a double. Storage must
355  * already be allocated for image2.
356  */
357 static void     write_b_thro_double(Imrect * image1, Imrect * image2,
358                                                   Imregion * roi)
359 {
360         int             lx, ly, ux, uy;
361         int             i, j;
362         double          gl;
363 
364 
365         lx = roi->lx;
366         ly = roi->ly;
367         ux = roi->ux;
368         uy = roi->uy;
369 
370         for (i = ly; i < uy; ++i)
371                 for (j = lx; j < ux; ++j)
372                 {
373                         IM_B_PIX_GET(image1, i, j, gl);
374                         IM_B_PIX_SET(image2, i, j, gl);
375                 }
376 }
377 
378 
379 /**
380  * @brief Copy specified roi of image1 to image2 through type int (ok for ptr).
381  * @param image1 Pointer to the image acting as a data source.
382  * @param image2 Pointer to the image acting as a data destination.
383  * @param roi The region of image1 to be copied into image 2.
384  * @return void
385  *
386  * Copy specified roi of image1 to image2 through type int (ok for ptr).
387  * Storage must already be allocated for image2.
388  */
389 static void     write_thro_int(Imrect * image1, Imrect * image2,
390                                                Imregion * roi)
391 {
392         int             lx, ly, ux, uy;
393         int             i, j;
394         double          gl;
395 
396         lx = roi->lx;
397         ly = roi->ly;
398         ux = roi->ux;
399         uy = roi->uy;
400 
401         for (i = ly; i < uy; ++i)
402                 for (j = lx; j < ux; ++j)
403                 {
404                         IM_PIX_GET(image1, i, j, gl);
405                         IM_PIX_SET(image2, i, j, (int) gl);
406                 }
407 }
408 
409 
410 /**
411  * @brief Copy specified roi of image1 rdata to image2 rdata through type int.
412  * @param image1 Pointer to the image acting as a data source.
413  * @param image2 Pointer to the image acting as a data destination.
414  * @param roi The region of image1 rdata to be copied into image 2.
415  * @return void
416  *
417  * Copy specified roi of image1 rdata to image2 rdata through type int.
418  * Storage must already be allocated for image2.
419  */
420 static void     write_r_thro_int(Imrect * image1, Imrect * image2,
421                                                Imregion * roi)
422 {
423         int             lx, ly, ux, uy;
424         int             i, j;
425         double          gl;
426 
427         lx = roi->lx;
428         ly = roi->ly;
429         ux = roi->ux;
430         uy = roi->uy;
431 
432         for (i = ly; i < uy; ++i)
433                 for (j = lx; j < ux; ++j)
434                 {
435                         IM_R_PIX_GET(image1, i, j, gl);
436                         IM_R_PIX_SET(image2, i, j, (int) gl);
437                 }
438 }
439 
440 
441 /**
442  * @brief Copy specified roi of image1 gdata to image2 gdata through type int.
443  * @param image1 Pointer to the image acting as a data source.
444  * @param image2 Pointer to the image acting as a data destination.
445  * @param roi The region of image1 rdata to be copied into image 2.
446  * @return void
447  *
448  * Copy specified roi of image1 gdata to image2 gdata through type int.
449  * Storage must already be allocated for image2.
450  */
451 static void     write_g_thro_int(Imrect * image1, Imrect * image2,
452                                                Imregion * roi)
453 {
454         int             lx, ly, ux, uy;
455         int             i, j;
456         double          gl;
457 
458         lx = roi->lx;
459         ly = roi->ly;
460         ux = roi->ux;
461         uy = roi->uy;
462 
463         for (i = ly; i < uy; ++i)
464                 for (j = lx; j < ux; ++j)
465                 {
466                         IM_G_PIX_GET(image1, i, j, gl);
467                         IM_G_PIX_SET(image2, i, j, (int) gl);
468                 }
469 }
470 
471 
472 /**
473  * @brief Copy specified roi of image1 bdata to image2 bdata through type int.
474  * @param image1 Pointer to the image acting as a data source.
475  * @param image2 Pointer to the image acting as a data destination.
476  * @param roi The region of image1 bdata to be copied into image 2.
477  * @return void
478  *
479  * Copy specified roi of image1 bdata to image2 bdata through type int.
480  * Storage must already be allocated for image2.
481  */
482 static void     write_b_thro_int(Imrect * image1, Imrect * image2,
483                                                Imregion * roi)
484 {
485         int             lx, ly, ux, uy;
486         int             i, j;
487         double          gl;
488 
489         lx = roi->lx;
490         ly = roi->ly;
491         ux = roi->ux;
492         uy = roi->uy;
493 
494         for (i = ly; i < uy; ++i)
495                 for (j = lx; j < ux; ++j)
496                 {
497                         IM_B_PIX_GET(image1, i, j, gl);
498                         IM_B_PIX_SET(image2, i, j, (int) gl);
499                 }
500 }
501 
502 
503 /**
504  * @brief Copy specified roi of image1 to image2 through type complex.
505  * @param image1 Pointer to the image acting as a data source.
506  * @param image2 Pointer to the image acting as a data destination.
507  * @param roi The region of image1 to be copied into image 2.
508  * @return void
509  *
510  * Copy specified roi of image1 to image2 through type complex.
511  * Storage must already be allocated for image2.
512  */
513 static void     write_thro_complex(Imrect * image1, Imrect * image2,
514                                                    Imregion * roi)
515 {
516         int             lx, ly, ux, uy;
517         int             i, j;
518         Complex         gl = {Complex_id};
519 
520         lx = roi->lx;
521         ly = roi->ly;
522         ux = roi->ux;
523         uy = roi->uy;
524 
525         for (i = ly; i < uy; ++i)
526                 for (j = lx; j < ux; ++j)
527                 {
528                         IM_PIX_GETZ(image1, i, j, gl);
529                         IM_PIX_SETZ(image2, i, j, gl);
530                 }
531 }
532 
533 
534 /**
535  * @brief Overwrite region of image2 by region of image1.
536  * @param image2 Pointer to the image acting as a data destination.
537  * @param image1 Pointer to the image acting as a data source.
538  * @return void
539  *
540  * Overwrite region of image2 by region of image1. The region used is the
541  * intersection of the roi's of image1 and image2.  Storage must already be
542  * allocated for image2.
543  */
544 void            im_copy_inplace(Imrect * image2, Imrect * image1)
545 {
546         Imregion       *roi;
547         Imregion       *roi_inter();
548         Vartype         vtype;
549 
550         if (image1 == NULL || image2 == NULL)
551                 return;
552 
553         roi = roi_inter(image1->region, image2->region);
554         if (!roi)
555         {
556                 errorf(warning, "im_copy_inplace() regions do not overlap\n");
557                 return;
558         }
559         vtype = (Vartype) MAX((int) image1->vtype, (int) image2->vtype);
560 
561         if (image1->vtype != image2->vtype
562             || (int) image1->vtype > (int) complex_v)
563         {
564                 switch (vtype)
565                 {
566                 case char_v:
567                 case uchar_v:
568                 case short_v:
569                 case ushort_v:
570                 case int_v:
571                 case uint_v:
572                         write_thro_int(image1, image2, roi);
573                         if(image1->rdata!=NULL) write_r_thro_int(image1, image2, roi);
574                         if(image1->gdata!=NULL) write_g_thro_int(image1, image2, roi);
575                         if(image1->bdata!=NULL) write_b_thro_int(image1, image2, roi);
576                         break;
577                 case ptr_v:
578                         write_thro_int(image1, image2, roi);
579                         break;
580                 case float_v:
581                 case double_v:
582                         write_thro_double(image1, image2, roi);
583                         if(image1->rdata!=NULL) write_r_thro_double(image1, image2, roi);
584                         if(image1->gdata!=NULL) write_g_thro_double(image1, image2, roi);
585                         if(image1->bdata!=NULL) write_b_thro_double(image1, image2, roi);
586                         break;
587                 case complex_v:
588                         write_thro_complex(image1, image2, roi);
589                         break;
590                 case vram0_v:
591                 case vram1_v:
592                 case vram2_v:
593                 case vram3_v:
594                         write_thro_int(image1, image2, roi);
595                         break;
596                 default:
597                         error("Cannot copy this image type", fatal);
598                         break;
599                 }
600         } else
601         {
602                 /* same type */
603                 int             lx, ly, ux, uy;
604                 int             nchars;
605                 unsigned int    vsize;
606                 int             i;
607                 char          **array1 = (char **) image1->data;
608                 char          **array2 = (char **) image2->data;
609                 char          **rarray1 = (char **) image1->rdata;
610                 char          **rarray2 = (char **) image2->rdata;
611                 char          **garray1 = (char **) image1->gdata;
612                 char          **garray2 = (char **) image2->gdata;
613                 char          **barray1 = (char **) image1->bdata;
614                 char          **barray2 = (char **) image2->bdata;
615 
616                 vsize = var_size(image1->vtype);
617 
618                 lx = roi->lx;
619                 ly = roi->ly;
620                 ux = roi->ux;
621                 uy = roi->uy;
622                 lx *= vsize;
623                 ux *= vsize;
624                 nchars = ux - lx;
625 
626                 for (i = ly; i < uy; ++i) (void) memcpy(array2[i] + lx, array1[i] + lx, nchars);
627 
628                 if(image1->vtype == char_v || image1->vtype == uchar_v || image1->vtype == short_v || image1->vtype == ushort_v || 
629                    image1->vtype == int_v || image1->vtype == uint_v || image1->vtype == float_v || image1->vtype == double_v)
630                 {
631                         if(image1->rdata!=NULL) for (i = ly; i < uy; ++i) (void) memcpy(rarray2[i] + lx, rarray1[i] + lx, nchars);
632                         if(image1->gdata!=NULL) for (i = ly; i < uy; ++i) (void) memcpy(garray2[i] + lx, garray1[i] + lx, nchars);
633                         if(image1->bdata!=NULL) for (i = ly; i < uy; ++i) (void) memcpy(barray2[i] + lx, barray1[i] + lx, nchars);
634                 }
635         }
636 
637         rfree((void *) (char *) roi);
638 }
639 
640 
641 /**
642  * @brief Make new copy of specified roi of image. 
643  * @param image Image acting as a data source.
644  * @param region The region of the image to be copied.
645  * @return subimage Pointer to the new image.
646  *
647  * Make new copy of specified roi of image.  Allocate storage for new copy.
648  * Copy specified roi of image into it. Return pointer to it.
649  */
650 Imrect         *im_subim(Imrect * image, Imregion * region)
651 {
652         Imregion       *subregion;
653         Imregion       *roi_inter();
654         Imrect         *subimage;
655 
656         if (image == NULL)
657                 return (NULL);
658 
659         subregion = roi_inter(region, image->region);
660         if (subregion == NULL) return (NULL);
661 
662         subimage = im_alloc(image->height, image->width, subregion, image->vtype);
663 
664         rfree((void *) (char *) subregion);
665         im_copy_inplace(subimage, image);
666         return (subimage);
667 }
668 
669 
670 /**
671  * @brief Make new copy of image of given type.
672  * @param image Pointer to the image to be copied.
673  * @param vtype The variable type of the image data.
674  * @return copy Pointer to the copy of the input image.
675  *
676  * Make new copy of image of given type.  Allocate storage for new copy. Copy
677  * whole image into it. Return pointer to it.
678  */
679 Imrect         *im_cast(Imrect * image, Vartype vtype)
680 {
681         Imrect         *copy;
682 
683         if (image == NULL)
684                 return (NULL);
685 
686         copy = im_alloc(image->height, image->width, image->region, vtype);
687         im_copy_inplace(copy, image);
688 
689         return (copy);
690 }
691 
692 
693 /**
694  * @brief Make new copy of an image.  
695  * @param image Pointer to the image to be copied.
696  * @return copy Pointer to the copy of the input image.
697  *
698  * Make new copy of image.  Allocate storage for new copy. Copy whole image
699  * into it. Return pointer to it.
700  */
701 Imrect         *im_copy(Imrect * image)
702 {
703         Imrect         *copy;
704 
705         if (image == NULL)
706                 return (NULL);
707 
708         copy = im_alloc(image->height, image->width, image->region, image->vtype);
709         im_copy_inplace(copy, image);
710 
711         return (copy);
712 }
713 
714 
715 /**
716  * @brief Free an imrect structure.
717  * @param image Pointer to the imrect structure to be freed.
718  * @return void
719  *
720  * Free an imrect structure. All elements are freed: the data array, the region, and 
721  * the proplist.
722  */
723 void            im_free(Imrect * image)
724 {
725         int             lx, ly, ux, uy;
726         unsigned int    vsize;
727 
728         if (image == NULL)
729                 return;
730 
731         proplist_freelist(image->props);
732 
733         lx = image->region->lx;
734         ly = image->region->ly;
735         ux = image->region->ux;
736         uy = image->region->uy;
737 
738         vsize = var_size(image->vtype);
739         narray_free((char **) image->data, ly, lx, uy, ux, vsize);
740 
741         if(image->rdata!=NULL) narray_free((char **) image->rdata, ly, lx, uy, ux, vsize);
742         if(image->gdata!=NULL) narray_free((char **) image->gdata, ly, lx, uy, ux, vsize);
743         if(image->bdata!=NULL) narray_free((char **) image->bdata, ly, lx, uy, ux, vsize);
744 
745         rfree((void *) image->region);
746         rfree((void *) image);
747 }
748 
749 
750 /**
751  * @brief Shift the data and roi of an image.
752  * @param im Pointer to the image to be shifted.
753  * @param dy Shift applied to the rows.
754  * @param dx Shift applied to the columns.
755  * @return void.
756  *
757  * Shifts data and roi of an image by dy rows and dx cols, cheaply, in place
758  */
759 void            im_shift(Imrect * im, int dy, int dx)
760 {
761         Imregion       *roi;
762         int             y, ly, uy;
763         unsigned int    vsize;
764         void           *row;
765 
766         if (im == NULL)
767                 return;
768 
769         roi = im->region;
770         ly = roi->ly;
771         uy = roi->uy;
772         vsize = var_size(im->vtype);
773 
774         for (y = ly; y < uy; y++)
775         {
776                 IM_ROW_GET(im, y, row);
777                 /*
778                         row = (void *) ((int) row - vsize * dx);
779                 */
780                 row = nvector_shift(row, roi->lx, roi->lx + dx, vsize);
781                 IM_ROW_SET(im, y, row);
782         }
783         /*
784             im->data = (void **) im->data - dy;
785         */
786         im->data = nvector_shift((void **) im->data, roi->ly, roi->ly + dy,
787                                  var_size(ptr_v));
788 
789         if(im->rdata!=NULL) im->rdata = nvector_shift((void **) im->rdata, roi->ly, roi->ly + dy,
790                                  var_size(ptr_v));
791 
792         if(im->gdata!=NULL) im->gdata = nvector_shift((void **) im->gdata, roi->ly, roi->ly + dy,
793                                  var_size(ptr_v));
794 
795         if(im->bdata!=NULL) im->bdata = nvector_shift((void **) im->bdata, roi->ly, roi->ly + dy,
796                                  var_size(ptr_v));
797 
798         roi->lx += dx;
799         roi->ux += dx;
800         roi->ly += dy;
801         roi->uy += dy;
802 }
803 

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