49 #ifndef vpIMAGECONVERT_H
50 #define vpIMAGECONVERT_H
53 #include <visp/vpConfig.h>
54 #include <visp/vpImage.h>
55 #include <visp/vpDebug.h>
57 #include <visp/vpRGBa.h>
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>
71 # include <yarp/sig/Image.h>
78 #if defined(VISP_HAVE_LIBJPEG)
83 #if defined(VISP_HAVE_LIBPNG)
119 #ifdef VISP_HAVE_OPENCV
120 static void convert(
const IplImage* src,
122 static void convert(
const IplImage* src,
128 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
129 static void convert(
const cv::Mat& src,
131 static void convert(
const cv::Mat& src,
136 cv::Mat& dest,
const bool copyData =
true) ;
140 #ifdef VISP_HAVE_YARP
142 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData =
true) ;
143 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
148 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData =
true) ;
149 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
153 yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest) ;
154 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src,
158 #ifdef VISP_HAVE_LIBJPEG
159 #if JPEG_LIB_VERSION > 70
161 unsigned char **dest,
long unsigned int &destSize,
int quality = 100);
163 static void convertToJPEGBuffer(
unsigned char *src,
long unsigned int srcSize,
199 dr = floor(0.9999695*y - 0.0009508*(u-128) + 1.1359061*(v-128));
200 dg = floor(0.9999695*y - 0.3959609*(u-128) - 0.5782955*(v-128));
201 db = floor(0.9999695*y + 2.04112*(u-128) - 0.0016314*(v-128));
203 dr = dr < 0. ? 0. : dr;
204 dg = dg < 0. ? 0. : dg;
205 db = db < 0. ? 0. : db;
206 dr = dr > 255. ? 255. : dr;
207 dg = dg > 255. ? 255. : dg;
208 db = db > 255. ? 255. : db;
210 r = (
unsigned char) dr;
211 g = (
unsigned char) dg;
212 b = (
unsigned char) db;
214 static void YUYVToRGBa(
unsigned char* yuyv,
unsigned char* rgba,
215 unsigned int width,
unsigned int height);
216 static void YUYVToRGB(
unsigned char* yuyv,
unsigned char* rgb,
217 unsigned int width,
unsigned int height);
218 static void YUYVToGrey(
unsigned char* yuyv,
unsigned char* grey,
220 static void YUV411ToRGBa(
unsigned char* yuv,
221 unsigned char* rgba,
unsigned int size);
222 static void YUV411ToRGB(
unsigned char* yuv,
223 unsigned char* rgb,
unsigned int size);
224 static void YUV411ToGrey(
unsigned char* yuv,
225 unsigned char* grey,
unsigned int size);
226 static void YUV422ToRGBa(
unsigned char* yuv,
227 unsigned char* rgba,
unsigned int size);
228 static void YUV422ToRGB(
unsigned char* yuv,
229 unsigned char* rgb,
unsigned int size);
230 static void YUV422ToGrey(
unsigned char* yuv,
231 unsigned char* grey,
unsigned int size);
232 static void YUV420ToRGBa(
unsigned char* yuv,
233 unsigned char* rgba,
unsigned int width,
unsigned int height);
234 static void YUV420ToRGB(
unsigned char* yuv,
235 unsigned char* rgb,
unsigned int width,
unsigned int height);
236 static void YUV420ToGrey(
unsigned char* yuv,
237 unsigned char* grey,
unsigned int size);
239 static void YUV444ToRGBa(
unsigned char* yuv,
240 unsigned char* rgba,
unsigned int size);
241 static void YUV444ToRGB(
unsigned char* yuv,
242 unsigned char* rgb,
unsigned int size);
243 static void YUV444ToGrey(
unsigned char* yuv,
244 unsigned char* grey,
unsigned int size);
246 static void YV12ToRGBa(
unsigned char* yuv,
247 unsigned char* rgba,
unsigned int width,
unsigned int height);
248 static void YV12ToRGB(
unsigned char* yuv,
249 unsigned char* rgb,
unsigned int width,
unsigned int height);
250 static void YVU9ToRGBa(
unsigned char* yuv,
251 unsigned char* rgba,
unsigned int width,
unsigned int height);
252 static void YVU9ToRGB(
unsigned char* yuv,
253 unsigned char* rgb,
unsigned int width,
unsigned int height);
254 static void RGBToRGBa(
unsigned char* rgb,
255 unsigned char* rgba,
unsigned int size);
256 static void RGBaToRGB(
unsigned char* rgba,
257 unsigned char* rgb,
unsigned int size);
259 static void RGBToGrey(
unsigned char* rgb,
260 unsigned char* grey,
unsigned int size);
261 static void RGBaToGrey(
unsigned char* rgba,
262 unsigned char* grey,
unsigned int size);
264 static void RGBToRGBa(
unsigned char * bgr,
unsigned char * rgba,
265 unsigned int width,
unsigned int height,
bool flip =
false);
266 static void RGBToGrey(
unsigned char * bgr,
unsigned char * grey,
267 unsigned int width,
unsigned int height,
bool flip =
false);
269 static void GreyToRGBa(
unsigned char* grey,
270 unsigned char* rgba,
unsigned int size);
271 static void GreyToRGB(
unsigned char* grey,
272 unsigned char* rgb,
unsigned int size);
274 static void BGRToRGBa(
unsigned char * bgr,
unsigned char * rgba,
275 unsigned int width,
unsigned int height,
bool flip);
277 static void BGRToGrey(
unsigned char * bgr,
unsigned char * grey,
278 unsigned int width,
unsigned int height,
bool flip);
280 static void YCbCrToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
282 static void YCbCrToRGBa (
unsigned char *ycbcr,
unsigned char *rgb,
284 static void YCrCbToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
286 static void YCrCbToRGBa(
unsigned char *ycbcr,
unsigned char *rgb,
288 static void YCbCrToGrey(
unsigned char *ycbcr,
unsigned char *grey,
290 static void MONO16ToGrey(
unsigned char *grey16,
unsigned char *grey,
292 static void MONO16ToRGBa(
unsigned char *grey16,
unsigned char *rgba,
296 static void computeYCbCrLUT();
299 static bool YCbCrLUTcomputed;
300 static int vpCrr[256];
301 static int vpCgb[256];
302 static int vpCgr[256];
303 static int vpCbb[256];
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)