ViSP  2.6.2
vpImageConvert.h
1 /****************************************************************************
2 *
3 * $Id: vpImageConvert.h 3797 2012-06-21 07:44:05Z fspindle $
4 *
5 * This file is part of the ViSP software.
6 * Copyright (C) 2005 - 2012 by INRIA. All rights reserved.
7 *
8 * This software is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * ("GPL") version 2 as published by the Free Software Foundation.
11 * See the file LICENSE.txt at the root directory of this source
12 * distribution for additional information about the GNU GPL.
13 *
14 * For using ViSP with software that can not be combined with the GNU
15 * GPL, please contact INRIA about acquiring a ViSP Professional
16 * Edition License.
17 *
18 * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19 *
20 * This software was developed at:
21 * INRIA Rennes - Bretagne Atlantique
22 * Campus Universitaire de Beaulieu
23 * 35042 Rennes Cedex
24 * France
25 * http://www.irisa.fr/lagadic
26 *
27 * If you have questions regarding the use of this file, please contact
28 * INRIA at visp@inria.fr
29 *
30 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32 *
33 *
34 * Description:
35 * Convert image types.
36 *
37 * Authors:
38 * Eric Marchand
39 * Fabien Spindler
40 * Anthony Saunier
41 *
42 *****************************************************************************/
43 
49 #ifndef vpIMAGECONVERT_H
50 #define vpIMAGECONVERT_H
51 
52 // image
53 #include <visp/vpConfig.h>
54 #include <visp/vpImage.h>
55 #include <visp/vpDebug.h>
56 // color
57 #include <visp/vpRGBa.h>
58 
59 #ifdef VISP_HAVE_OPENCV
60 # if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
61 # include <opencv2/core/core.hpp>
62 # include <opencv2/legacy/legacy.hpp>
63 # include <opencv2/highgui/highgui.hpp>
64 # include <opencv2/highgui/highgui_c.h>
65 # else
66 # include <highgui.h>
67 # endif
68 #endif
69 
70 #ifdef VISP_HAVE_YARP
71 # include <yarp/sig/Image.h>
72 #endif
73 
74 #ifdef WIN32
75 # include <windows.h>
76 #endif
77 
78 #if defined(VISP_HAVE_LIBJPEG)
79 # include <jpeglib.h>
80 # include <jerror.h>
81 #endif
82 
83 #if defined(VISP_HAVE_LIBPNG)
84 # include <png.h>
85 #endif
86 
95 class VISP_EXPORT vpImageConvert
96 {
97 
98 public:
99  static void convert(const vpImage<unsigned char> &src,
100  vpImage<vpRGBa> & dest) ;
101  static void convert(const vpImage<vpRGBa> &src,
102  vpImage<unsigned char> & dest) ;
103 
104  static void convert(const vpImage<float> &src,
105  vpImage<unsigned char> &dest);
106  static void convert(const vpImage<unsigned char> &src,
107  vpImage<float> &dest);
108 
109  static void convert(const vpImage<double> &src,
110  vpImage<unsigned char> &dest);
111  static void convert(const vpImage<unsigned char> &src,
112  vpImage<double> &dest);
113 
114 #ifdef VISP_HAVE_OPENCV
115  static void convert(const IplImage* src,
116  vpImage<vpRGBa> & dest, bool flip = false) ;
117  static void convert(const IplImage* src,
118  vpImage<unsigned char> & dest, bool flip = false) ;
119  static void convert(const vpImage<vpRGBa> & src,
120  IplImage *&dest) ;
121  static void convert(const vpImage<unsigned char> & src,
122  IplImage* &dest) ;
123 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
124  static void convert(const cv::Mat& src,
125  vpImage<vpRGBa>& dest, const bool flip = false);
126  static void convert(const cv::Mat& src,
127  vpImage<unsigned char>& dest, const bool flip = false);
128  static void convert(const vpImage<vpRGBa> & src,
129  cv::Mat& dest) ;
130  static void convert(const vpImage<unsigned char> & src,
131  cv::Mat& dest, const bool copyData = true) ;
132 #endif
133 #endif
134 
135 #ifdef VISP_HAVE_YARP
136  static void convert(const vpImage<unsigned char> & src,
137  yarp::sig::ImageOf< yarp::sig::PixelMono > *dest, const bool copyData = true) ;
138  static void convert(const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
139  vpImage<unsigned char> & dest,const bool copyData = true ) ;
140 
141 
142  static void convert(const vpImage<vpRGBa> & src,
143  yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest, const bool copyData = true) ;
144  static void convert(const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
145  vpImage<vpRGBa> & dest,const bool copyData = true) ;
146 
147  static void convert(const vpImage<vpRGBa> & src,
148  yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest) ;
149  static void convert(const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src,
150  vpImage<vpRGBa> & dest) ;
151 #endif
152 
153 #ifdef VISP_HAVE_LIBJPEG
154 #if JPEG_LIB_VERSION > 70
155  static void convertToJPEGBuffer(const vpImage<unsigned char> &src,
156  unsigned char **dest, long unsigned int &destSize, unsigned int quality = 100);
157 
158  static void convertToJPEGBuffer(unsigned char *src, long unsigned int srcSize,
159  vpImage<unsigned char> &dest);
160 #endif
161 #endif
162 
163  static void split(const vpImage<vpRGBa> &src,
167  vpImage<unsigned char>* pa = NULL) ;
168 
186  static inline void YUVToRGB(unsigned char y,
187  unsigned char u,
188  unsigned char v,
189  unsigned char &r,
190  unsigned char &g,
191  unsigned char &b)
192  {
193  double dr, dg, db;
194  dr = floor(0.9999695*y - 0.0009508*(u-128) + 1.1359061*(v-128));
195  dg = floor(0.9999695*y - 0.3959609*(u-128) - 0.5782955*(v-128));
196  db = floor(0.9999695*y + 2.04112*(u-128) - 0.0016314*(v-128));
197 
198  dr = dr < 0. ? 0. : dr;
199  dg = dg < 0. ? 0. : dg;
200  db = db < 0. ? 0. : db;
201  dr = dr > 255. ? 255. : dr;
202  dg = dg > 255. ? 255. : dg;
203  db = db > 255. ? 255. : db;
204 
205  r = (unsigned char) dr;
206  g = (unsigned char) dg;
207  b = (unsigned char) db;
208  };
209  static void YUYVToRGBa(unsigned char* yuyv, unsigned char* rgba,
210  unsigned int width, unsigned int height);
211  static void YUYVToRGB(unsigned char* yuyv, unsigned char* rgb,
212  unsigned int width, unsigned int height);
213  static void YUYVToGrey(unsigned char* yuyv, unsigned char* grey,
214  unsigned int size);
215  static void YUV411ToRGBa(unsigned char* yuv,
216  unsigned char* rgba, unsigned int size);
217  static void YUV411ToRGB(unsigned char* yuv,
218  unsigned char* rgb, unsigned int size);
219  static void YUV411ToGrey(unsigned char* yuv,
220  unsigned char* grey, unsigned int size);
221  static void YUV422ToRGBa(unsigned char* yuv,
222  unsigned char* rgba, unsigned int size);
223  static void YUV422ToRGB(unsigned char* yuv,
224  unsigned char* rgb, unsigned int size);
225  static void YUV422ToGrey(unsigned char* yuv,
226  unsigned char* grey, unsigned int size);
227  static void YUV420ToRGBa(unsigned char* yuv,
228  unsigned char* rgba, unsigned int width, unsigned int height);
229  static void YUV420ToRGB(unsigned char* yuv,
230  unsigned char* rgb, unsigned int width, unsigned int height);
231  static void YUV420ToGrey(unsigned char* yuv,
232  unsigned char* grey, unsigned int size);
233 
234  static void YUV444ToRGBa(unsigned char* yuv,
235  unsigned char* rgba, unsigned int size);
236  static void YUV444ToRGB(unsigned char* yuv,
237  unsigned char* rgb, unsigned int size);
238  static void YUV444ToGrey(unsigned char* yuv,
239  unsigned char* grey, unsigned int size);
240 
241  static void YV12ToRGBa(unsigned char* yuv,
242  unsigned char* rgba, unsigned int width, unsigned int height);
243  static void YV12ToRGB(unsigned char* yuv,
244  unsigned char* rgb, unsigned int width, unsigned int height);
245  static void YVU9ToRGBa(unsigned char* yuv,
246  unsigned char* rgba, unsigned int width, unsigned int height);
247  static void YVU9ToRGB(unsigned char* yuv,
248  unsigned char* rgb, unsigned int width, unsigned int height);
249  static void RGBToRGBa(unsigned char* rgb,
250  unsigned char* rgba, unsigned int size);
251  static void RGBaToRGB(unsigned char* rgba,
252  unsigned char* rgb, unsigned int size);
253 
254  static void RGBToGrey(unsigned char* rgb,
255  unsigned char* grey, unsigned int size);
256  static void RGBaToGrey(unsigned char* rgba,
257  unsigned char* grey, unsigned int size);
258 
259  static void RGBToRGBa(unsigned char * bgr, unsigned char * rgba,
260  unsigned int width, unsigned int height, bool flip = false);
261  static void RGBToGrey(unsigned char * bgr, unsigned char * grey,
262  unsigned int width, unsigned int height, bool flip = false);
263 
264  static void GreyToRGBa(unsigned char* grey,
265  unsigned char* rgba, unsigned int size);
266  static void GreyToRGB(unsigned char* grey,
267  unsigned char* rgb, unsigned int size);
268 
269  static void BGRToRGBa(unsigned char * bgr, unsigned char * rgba,
270  unsigned int width, unsigned int height, bool flip);
271 
272  static void BGRToGrey(unsigned char * bgr, unsigned char * grey,
273  unsigned int width, unsigned int height, bool flip);
274 
275  static void YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb,
276  unsigned int size);
277  static void YCbCrToRGBa (unsigned char *ycbcr, unsigned char *rgb,
278  unsigned int size);
279  static void YCrCbToRGB(unsigned char *ycbcr, unsigned char *rgb,
280  unsigned int size);
281  static void YCrCbToRGBa(unsigned char *ycbcr, unsigned char *rgb,
282  unsigned int size);
283  static void YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey,
284  unsigned int size);
285  static void MONO16ToGrey(unsigned char *grey16, unsigned char *grey,
286  unsigned int size);
287  static void MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba,
288  unsigned int size);
289 
290 private:
291  static void computeYCbCrLUT();
292 
293 private:
294  static bool YCbCrLUTcomputed;
295  static int vpCrr[256];
296  static int vpCgb[256];
297  static int vpCgr[256];
298  static int vpCbb[256];
299 
300 } ;
301 
302 #endif
303 
304 
305 /*
306 * Local variables:
307 * c-basic-offset: 2
308 * End:
309 */
Convert image types.
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)