JeVoisBase  1.3
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
env_image.c
Go to the documentation of this file.
1 /*!@file Envision/env_image.c */
2 
3 // //////////////////////////////////////////////////////////////////// //
4 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 //
5 // by the University of Southern California (USC) and the iLab at USC. //
6 // See http://iLab.usc.edu for information about this project. //
7 // //////////////////////////////////////////////////////////////////// //
8 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
9 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
10 // in Visual Environments, and Applications'' by Christof Koch and //
11 // Laurent Itti, California Institute of Technology, 2001 (patent //
12 // pending; application number 09/912,225 filed July 23, 2001; see //
13 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). //
14 // //////////////////////////////////////////////////////////////////// //
15 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. //
16 // //
17 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can //
18 // redistribute it and/or modify it under the terms of the GNU General //
19 // Public License as published by the Free Software Foundation; either //
20 // version 2 of the License, or (at your option) any later version. //
21 // //
22 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope //
23 // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
24 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
25 // PURPOSE. See the GNU General Public License for more details. //
26 // //
27 // You should have received a copy of the GNU General Public License //
28 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write //
29 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, //
30 // Boston, MA 02111-1307 USA. //
31 // //////////////////////////////////////////////////////////////////// //
32 //
33 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu>
34 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Envision/env_image.c $
35 // $Id: env_image.c 7638 2007-01-03 21:23:18Z rjpeters $
36 //
37 
39 
40 // ######################################################################
41 void env_img_init(struct env_image* img, const struct env_dims d)
42 {
43  img->pixels = (intg32*) env_allocate(d.w * d.h * sizeof(intg32));
44  img->dims = d;
45 }
46 
47 // ######################################################################
48 void env_img_swap(struct env_image* img1, struct env_image* img2)
49 {
50  const struct env_image img1copy = *img1;
51  *img1 = *img2;
52  *img2 = img1copy;
53 }
54 
55 // ######################################################################
56 void env_img_make_empty(struct env_image* img)
57 {
58  env_deallocate(img->pixels);
59  img->dims.w = img->dims.h = 0;
60  img->pixels = 0;
61 }
62 
63 // ######################################################################
64 void env_img_resize_dims(struct env_image* img,
65  const struct env_dims d)
66 {
67  if (d.w != img->dims.w || d.h != img->dims.h)
68  {
69  env_deallocate(img->pixels);
70  img->pixels = (intg32*) env_allocate(d.w * d.h * sizeof(intg32));
71  img->dims = d;
72  }
73 }
74 
75 // ######################################################################
76 void env_img_copy_src_dst(const struct env_image* src, struct env_image* dst)
77 {
78  if (src == dst) return;
79 
80  env_img_resize_dims(dst, src->dims);
81 
82  const env_size_t sz = env_img_size(src);
83  const intg32* const sptr = env_img_pixels(src);
84  intg32* const dptr = env_img_pixelsw(dst);
85 
86  for (env_size_t i = 0; i < sz; ++i) dptr[i] = sptr[i];
87 }
void env_img_copy_src_dst(const struct env_image *src, struct env_image *dst)
Definition: env_image.c:76
env_size_t w
The width.
Definition: env_types.h:82
void env_img_make_empty(struct env_image *img)
Definition: env_image.c:56
void env_img_swap(struct env_image *img1, struct env_image *img2)
Definition: env_image.c:48
Basic image class.
Definition: env_image.h:43
void env_deallocate(void *mem)
Definition: env_config.h:59
void env_img_init(struct env_image *img, const struct env_dims d)
Definition: env_image.c:41
struct env_dims dims
Definition: env_image.h:45
void * env_allocate(unsigned long nbytes)
Definition: env_config.h:58
env_size_t h
The height.
Definition: env_types.h:83
unsigned long env_size_t
Definition: env_types.h:71
intg32 * pixels
Definition: env_image.h:46
void env_img_resize_dims(struct env_image *img, const struct env_dims d)
Definition: env_image.c:64
ENV_INTG32_TYPE intg32
32-bit signed integer
Definition: env_types.h:52
A simple struct to hold a pair of width/height dimensions.
Definition: env_types.h:80