Visual Servoing Platform  version 3.6.1 under development (2024-12-17)
testImageOwnership.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Test vpImage ownership
32  */
33 
34 #include <visp3/core/vpImage.h>
35 
42 int main(int /* argc */, const char ** /* argv */)
43 {
44 #ifdef ENABLE_VISP_NAMESPACE
45  using namespace VISP_NAMESPACE_NAME;
46 #endif
47  try {
48  {
49  unsigned char bitmap[4];
50  bitmap[0] = 0;
51  bitmap[1] = 1;
52  bitmap[2] = 2;
53  bitmap[3] = 3;
54 
55  vpImage<unsigned char> I(bitmap, 2, 2, true);
56  std::cout << "I:\n" << I << std::endl;
57  I.destroy();
58  }
59  {
60  unsigned char bitmap[4];
61  bitmap[0] = 0;
62  bitmap[1] = 1;
63  bitmap[2] = 2;
64  bitmap[3] = 3;
65 
66  vpImage<unsigned char> I(bitmap, 2, 2, false);
67  std::cout << "\nI:\n" << I << std::endl;
68  }
69  {
70  unsigned char bitmap[4];
71  bitmap[0] = 0;
72  bitmap[1] = 1;
73  bitmap[2] = 2;
74  bitmap[3] = 3;
75 
76  vpImage<unsigned char> I(bitmap, 2, 2, false);
77  {
79  std::cout << "\nI2:\n" << I2 << std::endl;
80  }
81  {
83  std::cout << "I2:\n" << I2 << std::endl;
84  }
85  }
86  {
87  unsigned char bitmap[12];
88  for (unsigned char i = 0; i < 12; i++) {
89  bitmap[i] = i;
90  }
91 
92  vpImage<unsigned char> I(bitmap, 3, 4, false);
93  std::cout << "\nI:\n" << I << std::endl;
94  I.init(2, 2, 0);
95  std::cout << "I:\n" << I << std::endl;
96  }
97  {
98  unsigned char bitmap[12];
99  for (unsigned char i = 0; i < 12; i++) {
100  bitmap[i] = i;
101  }
102  vpImage<unsigned char> I(bitmap, 3, 4, false);
103  std::cout << "\nI:\n" << I << std::endl;
104  I.init(bitmap, 4, 3, true);
105  std::cout << "I:\n" << I << std::endl;
106  }
107  {
108  unsigned char *bitmap = new unsigned char[12];
109  {
110  vpImage<unsigned char> I(bitmap, 3, 4, true);
111  }
112  delete[] bitmap;
113  }
114  {
115  unsigned char *bitmap = new unsigned char[12];
116  {
117  vpImage<unsigned char> I(bitmap, 3, 4, false);
118  }
119  vpImage<unsigned char> I(bitmap, 3, 4, false);
120 
121  delete[] bitmap;
122 
123  bitmap = new unsigned char[16];
124  I.init(bitmap, 4, 4, false);
125 
126  delete[] bitmap;
127  }
128  {
129  unsigned char *bitmap = new unsigned char[12];
130  vpImage<unsigned char> I(bitmap, 3, 4, false);
131  I.destroy();
132  I.init(bitmap, 3, 4, false);
133 
134  delete[] bitmap;
135 
136  I.destroy();
137  bitmap = new unsigned char[16];
138  I.init(bitmap, 4, 4, false);
139 
140  delete[] bitmap;
141  }
142 
143 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
144  {
145  unsigned char *bitmap = new unsigned char[12];
146  vpImage<unsigned char> I = vpImage<unsigned char>(bitmap, 3, 4, false);
147  if (bitmap != I.bitmap) {
148  std::cout << "std::move(vpImage) failed" << std::endl;
149  return EXIT_FAILURE;
150  }
151  delete[] bitmap;
152  }
153  {
154  unsigned char *bitmap = new unsigned char[12];
155  vpImage<unsigned char> I(vpImage<unsigned char>(bitmap, 3, 4, false));
156  if (bitmap != I.bitmap) {
157  std::cout << "vpImage(td::move(vpImage)) failed" << std::endl;
158  return EXIT_FAILURE;
159  }
160  delete[] bitmap;
161  }
162 #endif
163  }
164  catch (const std::exception &e) {
165  std::cerr << "Exception: " << e.what() << std::endl;
166  return EXIT_FAILURE;
167  }
168 
169  std::cout << "Test succeed" << std::endl;
170  return EXIT_SUCCESS;
171 }
void destroy()
Destructor : Memory de-allocation.
Definition: vpImage.h:573
void init(unsigned int height, unsigned int width)
Set the size of the image.
Definition: vpImage.h:387
Type * bitmap
points toward the bitmap
Definition: vpImage.h:135