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 >= 0x030000) // Require opencv >= 3.0.0
61 # include <opencv2/core/core.hpp>
62 # include <opencv2/highgui/highgui.hpp>
63 # include <opencv2/imgproc/imgproc_c.h>
64 # elif (VISP_HAVE_OPENCV_VERSION >= 0x020408) // Require opencv >= 2.4.8
65 # include <opencv2/core/core.hpp>
66 # include <opencv2/highgui/highgui.hpp>
67 # elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1
68 # include <opencv2/core/core.hpp>
69 # include <opencv2/legacy/legacy.hpp>
70 # include <opencv2/highgui/highgui.hpp>
71 # include <opencv2/highgui/highgui_c.h>
78 # include <yarp/sig/Image.h>
85 #if defined(VISP_HAVE_LIBJPEG)
90 #if defined(VISP_HAVE_LIBPNG)
126 #ifdef VISP_HAVE_OPENCV
128 static void convert(
const IplImage* src,
130 static void convert(
const IplImage* src,
136 # if VISP_HAVE_OPENCV_VERSION >= 0x020100
137 static void convert(
const cv::Mat& src,
139 static void convert(
const cv::Mat& src,
144 cv::Mat& dest,
const bool copyData =
true) ;
148 #ifdef VISP_HAVE_YARP
150 yarp::sig::ImageOf< yarp::sig::PixelMono > *dest,
const bool copyData =
true) ;
151 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
156 yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest,
const bool copyData =
true) ;
157 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
161 yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest) ;
162 static void convert(
const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src,
166 #ifdef VISP_HAVE_LIBJPEG
167 #if JPEG_LIB_VERSION > 70
169 unsigned char **dest,
long unsigned int &destSize,
int quality = 100);
171 static void convertToJPEGBuffer(
unsigned char *src,
long unsigned int srcSize,
207 dr = floor(0.9999695*y - 0.0009508*(u-128) + 1.1359061*(v-128));
208 dg = floor(0.9999695*y - 0.3959609*(u-128) - 0.5782955*(v-128));
209 db = floor(0.9999695*y + 2.04112*(u-128) - 0.0016314*(v-128));
211 dr = dr < 0. ? 0. : dr;
212 dg = dg < 0. ? 0. : dg;
213 db = db < 0. ? 0. : db;
214 dr = dr > 255. ? 255. : dr;
215 dg = dg > 255. ? 255. : dg;
216 db = db > 255. ? 255. : db;
218 r = (
unsigned char) dr;
219 g = (
unsigned char) dg;
220 b = (
unsigned char) db;
222 static void YUYVToRGBa(
unsigned char* yuyv,
unsigned char* rgba,
223 unsigned int width,
unsigned int height);
224 static void YUYVToRGB(
unsigned char* yuyv,
unsigned char* rgb,
225 unsigned int width,
unsigned int height);
226 static void YUYVToGrey(
unsigned char* yuyv,
unsigned char* grey,
228 static void YUV411ToRGBa(
unsigned char* yuv,
229 unsigned char* rgba,
unsigned int size);
230 static void YUV411ToRGB(
unsigned char* yuv,
231 unsigned char* rgb,
unsigned int size);
232 static void YUV411ToGrey(
unsigned char* yuv,
233 unsigned char* grey,
unsigned int size);
234 static void YUV422ToRGBa(
unsigned char* yuv,
235 unsigned char* rgba,
unsigned int size);
236 static void YUV422ToRGB(
unsigned char* yuv,
237 unsigned char* rgb,
unsigned int size);
238 static void YUV422ToGrey(
unsigned char* yuv,
239 unsigned char* grey,
unsigned int size);
240 static void YUV420ToRGBa(
unsigned char* yuv,
241 unsigned char* rgba,
unsigned int width,
unsigned int height);
242 static void YUV420ToRGB(
unsigned char* yuv,
243 unsigned char* rgb,
unsigned int width,
unsigned int height);
244 static void YUV420ToGrey(
unsigned char* yuv,
245 unsigned char* grey,
unsigned int size);
247 static void YUV444ToRGBa(
unsigned char* yuv,
248 unsigned char* rgba,
unsigned int size);
249 static void YUV444ToRGB(
unsigned char* yuv,
250 unsigned char* rgb,
unsigned int size);
251 static void YUV444ToGrey(
unsigned char* yuv,
252 unsigned char* grey,
unsigned int size);
254 static void YV12ToRGBa(
unsigned char* yuv,
255 unsigned char* rgba,
unsigned int width,
unsigned int height);
256 static void YV12ToRGB(
unsigned char* yuv,
257 unsigned char* rgb,
unsigned int width,
unsigned int height);
258 static void YVU9ToRGBa(
unsigned char* yuv,
259 unsigned char* rgba,
unsigned int width,
unsigned int height);
260 static void YVU9ToRGB(
unsigned char* yuv,
261 unsigned char* rgb,
unsigned int width,
unsigned int height);
262 static void RGBToRGBa(
unsigned char* rgb,
263 unsigned char* rgba,
unsigned int size);
264 static void RGBaToRGB(
unsigned char* rgba,
265 unsigned char* rgb,
unsigned int size);
267 static void RGBToGrey(
unsigned char* rgb,
268 unsigned char* grey,
unsigned int size);
269 static void RGBaToGrey(
unsigned char* rgba,
270 unsigned char* grey,
unsigned int size);
272 static void RGBToRGBa(
unsigned char * bgr,
unsigned char * rgba,
273 unsigned int width,
unsigned int height,
bool flip =
false);
274 static void RGBToGrey(
unsigned char * bgr,
unsigned char * grey,
275 unsigned int width,
unsigned int height,
bool flip =
false);
277 static void GreyToRGBa(
unsigned char* grey,
278 unsigned char* rgba,
unsigned int size);
279 static void GreyToRGB(
unsigned char* grey,
280 unsigned char* rgb,
unsigned int size);
282 static void BGRToRGBa(
unsigned char * bgr,
unsigned char * rgba,
283 unsigned int width,
unsigned int height,
bool flip=
false);
285 static void BGRToGrey(
unsigned char * bgr,
unsigned char * grey,
286 unsigned int width,
unsigned int height,
bool flip=
false);
288 static void YCbCrToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
290 static void YCbCrToRGBa (
unsigned char *ycbcr,
unsigned char *rgb,
292 static void YCrCbToRGB(
unsigned char *ycbcr,
unsigned char *rgb,
294 static void YCrCbToRGBa(
unsigned char *ycbcr,
unsigned char *rgb,
296 static void YCbCrToGrey(
unsigned char *ycbcr,
unsigned char *grey,
298 static void MONO16ToGrey(
unsigned char *grey16,
unsigned char *grey,
300 static void MONO16ToRGBa(
unsigned char *grey16,
unsigned char *rgba,
304 static void computeYCbCrLUT();
307 static bool YCbCrLUTcomputed;
308 static int vpCrr[256];
309 static int vpCgb[256];
310 static int vpCgr[256];
311 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)