ViSP  2.9.0
vpImageConvert.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImageConvert.cpp 4661 2014-02-10 19:34:58Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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 
50 #include <sstream>
51 
52 // image
53 #include <visp/vpImageConvert.h>
54 
55 bool vpImageConvert::YCbCrLUTcomputed = false;
56 int vpImageConvert::vpCrr[256];
57 int vpImageConvert::vpCgb[256];
58 int vpImageConvert::vpCgr[256];
59 int vpImageConvert::vpCbb[256];
60 
61 
67 void
69 {
70  dest.resize(src.getHeight(), src.getWidth()) ;
71 
72  GreyToRGBa(src.bitmap, (unsigned char *)dest.bitmap,
73  src.getHeight() * src.getWidth() );
74 }
75 
81 void
83 {
84  dest.resize(src.getHeight(), src.getWidth()) ;
85 
86  RGBaToGrey((unsigned char *)src.bitmap, dest.bitmap,
87  src.getHeight() * src.getWidth() );
88 }
89 
90 
96 void
98 {
99  dest.resize(src.getHeight(), src.getWidth()) ;
100  unsigned int max_xy = src.getWidth()*src.getHeight();
101  float min, max;
102 
103  src.getMinMaxValue(min,max);
104 
105  for (unsigned int i = 0; i < max_xy; i++) {
106  float val = 255.f * (src.bitmap[i] - min) / (max - min);
107  if(val < 0)
108  dest.bitmap[i] = 0;
109  else if(val > 255)
110  dest.bitmap[i] = 255;
111  else
112  dest.bitmap[i] = (unsigned char)val;
113  }
114 }
115 
121 void
123 {
124  dest.resize(src.getHeight(), src.getWidth()) ;
125  for (unsigned int i = 0; i < src.getHeight()*src.getWidth(); i++)
126  dest.bitmap[i] = (float)src.bitmap[i];
127 }
128 
134 void
136 {
137  dest.resize(src.getHeight(), src.getWidth()) ;
138  unsigned int max_xy = src.getWidth()*src.getHeight();
139  double min, max;
140 
141  src.getMinMaxValue(min,max);
142 
143  for (unsigned int i = 0; i < max_xy; i++) {
144  double val = 255. * (src.bitmap[i] - min) / (max - min);
145  if(val < 0)
146  dest.bitmap[i] = 0;
147  else if(val > 255)
148  dest.bitmap[i] = 255;
149  else
150  dest.bitmap[i] = (unsigned char)val;
151  }
152 }
153 
159 void
161 {
162  dest.resize(src.getHeight(), src.getWidth()) ;
163  for (unsigned int i = 0; i < src.getHeight()*src.getWidth(); i++)
164  dest.bitmap[i] = (double)src.bitmap[i];
165 }
166 
167 #ifdef VISP_HAVE_OPENCV
168 
208 void
209 vpImageConvert::convert(const IplImage* src, vpImage<vpRGBa> & dest, bool flip)
210 {
211  int nChannel = src->nChannels;
212  int depth = src->depth;
213  int height = src->height;
214  int width = src->width;
215  int widthStep = src->widthStep;
216  int lineStep = (flip) ? 1 : 0;
217 
218  if(nChannel == 3 && depth == 8){
219  dest.resize((unsigned int)height, (unsigned int)width);
220 
221  //starting source address
222  unsigned char* input = (unsigned char*)src->imageData;
223  unsigned char* line;
224  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
225  unsigned char* output = NULL;
226 
227  for(int i=0 ; i < height ; i++)
228  {
229  line = input;
230  output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
231  for(int j=0 ; j < width ; j++)
232  {
233  *(output++) = *(line+2);
234  *(output++) = *(line+1);
235  *(output++) = *(line);
236  *(output++) = 0;
237 
238  line+=3;
239  }
240  //go to the next line
241  input+=widthStep;
242  }
243  }
244  else if(nChannel == 1 && depth == 8 ){
245  dest.resize((unsigned int)height, (unsigned int)width);
246  //starting source address
247  unsigned char * input = (unsigned char*)src->imageData;
248  unsigned char * line;
249  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
250  unsigned char* output = NULL;
251 
252  for(int i=0 ; i < height ; i++)
253  {
254  line = input;
255  output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
256  for(int j=0 ; j < width ; j++)
257  {
258  *output++ = *(line);
259  *output++ = *(line);
260  *output++ = *(line);
261  *output++ = *(line);;
262 
263  line++;
264  }
265  //go to the next line
266  input+=widthStep;
267  }
268  }
269 }
270 
311 void
312 vpImageConvert::convert(const IplImage* src, vpImage<unsigned char> &dest, bool flip)
313 {
314  int nChannel = src->nChannels;
315  int depth = src->depth;
316  int height = src->height;
317  int width = src->width;
318  int widthStep = src->widthStep;
319  int lineStep = (flip) ? 1 : 0;
320 
321  if (flip == false)
322  {
323  if(widthStep == width){
324  if(nChannel == 1 && depth == 8){
325  dest.resize((unsigned int)height, (unsigned int)width) ;
326  memcpy(dest.bitmap, src->imageData,
327  (size_t)(height*width));
328  }
329  if(nChannel == 3 && depth == 8){
330  dest.resize((unsigned int)height, (unsigned int)width) ;
331  BGRToGrey((unsigned char*)src->imageData,dest.bitmap, (unsigned int)width, (unsigned int)height,false);
332  }
333  }
334  else{
335  if(nChannel == 1 && depth == 8){
336  dest.resize((unsigned int)height, (unsigned int)width) ;
337  for (int i =0 ; i < height ; i++){
338  memcpy(dest.bitmap+i*width, src->imageData + i*widthStep,
339  (size_t)width);
340  }
341  }
342  if(nChannel == 3 && depth == 8){
343  dest.resize((unsigned int)height, (unsigned int)width) ;
344  for (int i = 0 ; i < height ; i++){
345  BGRToGrey((unsigned char*)src->imageData + i*widthStep,
346  dest.bitmap + i*width, (unsigned int)width, 1, false);
347  }
348  }
349  }
350  }
351  else
352  {
353  if(nChannel == 1 && depth == 8){
354  dest.resize((unsigned int)height, (unsigned int)width) ;
355  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
356  for (int i =0 ; i < height ; i++){
357  memcpy(beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) , src->imageData + i*widthStep,
358  (size_t)width);
359  }
360  }
361  if(nChannel == 3 && depth == 8){
362  dest.resize((unsigned int)height, (unsigned int)width) ;
363  //for (int i = 0 ; i < height ; i++){
364  BGRToGrey((unsigned char*)src->imageData /*+ i*widthStep*/,
365  dest.bitmap /*+ i*width*/, (unsigned int)width, (unsigned int)height/*1*/, true);
366  //}
367  }
368  }
369 }
370 
412 void
413 vpImageConvert::convert(const vpImage<vpRGBa> & src, IplImage *&dest)
414 {
415  int height = (int)src.getHeight();
416  int width = (int)src.getWidth();
417  CvSize size = cvSize(width, height);
418  int depth = 8;
419  int channels = 3;
420  if (dest != NULL){
421  if(dest->nChannels != channels || dest->depth != depth
422  || dest->height != height || dest->width != width){
423  if(dest->nChannels != 0) cvReleaseImage(&dest);
424  dest = cvCreateImage( size, depth, channels );
425  }
426  }
427  else dest = cvCreateImage( size, depth, channels );
428 
429 
430  //starting source address
431  unsigned char * input = (unsigned char*)src.bitmap;//rgba image
432  unsigned char * line;
433  unsigned char * output = (unsigned char*)dest->imageData;//bgr image
434 
435  int j=0;
436  int i=0;
437  int widthStep = dest->widthStep;
438 
439  for(i=0 ; i < height ; i++)
440  {
441  output = (unsigned char*)dest->imageData + i*widthStep;
442  line = input;
443  for( j=0 ; j < width ; j++)
444  {
445  *output++ = *(line+2); //B
446  *output++ = *(line+1); //G
447  *output++ = *(line); //R
448 
449  line+=4;
450  }
451  //go to the next line
452  input+=4*width;
453  }
454 }
455 
497 void
498 vpImageConvert::convert(const vpImage<unsigned char> & src, IplImage* &dest)
499 {
500  unsigned int height = src.getHeight();
501  unsigned int width = src.getWidth();
502  CvSize size = cvSize((int)width, (int)height);
503  int depth = 8;
504  int channels = 1;
505  if (dest != NULL){
506  if(dest->nChannels != channels || dest->depth != depth
507  || dest->height != (int) height || dest->width != (int) width){
508  if(dest->nChannels != 0) cvReleaseImage(&dest);
509  dest = cvCreateImage( size, depth, channels );
510  }
511  }
512  else dest = cvCreateImage( size, depth, channels );
513 
514  unsigned int widthStep = (unsigned int)dest->widthStep;
515 
516  if ( width == widthStep){
517  memcpy(dest->imageData,src.bitmap, width*height);
518  }
519  else{
520  //copying each line taking account of the widthStep
521  for (unsigned int i =0 ; i < height ; i++){
522  memcpy(dest->imageData + i*widthStep, src.bitmap + i*width,
523  width);
524  }
525  }
526 }
527 
528 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
529 
571 void
572 vpImageConvert::convert(const cv::Mat& src, vpImage<vpRGBa>& dest, const bool flip)
573 {
574  if(src.type() == CV_8UC4){
575  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
576  vpRGBa rgbaVal;
577  for(unsigned int i=0; i<dest.getRows(); ++i)
578  for(unsigned int j=0; j<dest.getCols(); ++j){
579  cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (int)j);
580  rgbaVal.R = tmp[2];
581  rgbaVal.G = tmp[1];
582  rgbaVal.B = tmp[0];
583  rgbaVal.A = tmp[3];
584  if(flip)
585  dest[dest.getRows()-i-1][j] = rgbaVal;
586  else
587  dest[i][j] = rgbaVal;
588  }
589  }else if(src.type() == CV_8UC3){
590  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
591  vpRGBa rgbaVal;
592  rgbaVal.A = 0;
593  for(unsigned int i=0; i<dest.getRows(); ++i){
594  for(unsigned int j=0; j<dest.getCols(); ++j){
595  cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (int)j);
596  rgbaVal.R = tmp[2];
597  rgbaVal.G = tmp[1];
598  rgbaVal.B = tmp[0];
599  if(flip){
600  dest[dest.getRows()-i-1][j] = rgbaVal;
601  }else{
602  dest[i][j] = rgbaVal;
603  }
604  }
605  }
606  }else if(src.type() == CV_8UC1){
607  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
608  vpRGBa rgbaVal;
609  for(unsigned int i=0; i<dest.getRows(); ++i){
610  for(unsigned int j=0; j<dest.getCols(); ++j){
611  rgbaVal = src.at<unsigned char>((int)i, (int)j);
612  if(flip){
613  dest[dest.getRows()-i-1][j] = rgbaVal;
614  }else{
615  dest[i][j] = rgbaVal;
616  }
617  }
618  }
619  }
620 }
621 
664 void
665 vpImageConvert::convert(const cv::Mat& src, vpImage<unsigned char>& dest, const bool flip)
666 {
667  if(src.type() == CV_8UC1){
668  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
669  if(src.isContinuous() && !flip){
670  memcpy(dest.bitmap, src.data, (size_t)(src.rows*src.cols));
671  }
672  else{
673  if(flip){
674  for(unsigned int i=0; i<dest.getRows(); ++i){
675  memcpy(dest.bitmap+i*dest.getCols(), src.data+(dest.getRows()-i-1)*src.step1(), (size_t)src.step);
676  }
677  }else{
678  for(unsigned int i=0; i<dest.getRows(); ++i){
679  memcpy(dest.bitmap+i*dest.getCols(), src.data+i*src.step1(), (size_t)src.step);
680  }
681  }
682  }
683  }else if(src.type() == CV_8UC3){
684  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
685  if(src.isContinuous() && !flip){
686  BGRToGrey((unsigned char*)src.data, (unsigned char*)dest.bitmap, (unsigned int)src.cols, (unsigned int)src.rows, flip);
687  }
688  else{
689  if(flip){
690  for(unsigned int i=0; i<dest.getRows(); ++i){
691  BGRToGrey((unsigned char*)src.data+i*src.step1(),
692  (unsigned char*)dest.bitmap+(dest.getRows()-i-1)*dest.getCols(),
693  (unsigned int)dest.getCols(), 1, false);
694  }
695  }else{
696  for(unsigned int i=0; i<dest.getRows(); ++i){
697  BGRToGrey((unsigned char*)src.data+i*src.step1(),
698  (unsigned char*)dest.bitmap+i*dest.getCols(),
699  (unsigned int)dest.getCols(), 1, false);
700  }
701  }
702  }
703  }
704 }
705 
706 
746 void
747 vpImageConvert::convert(const vpImage<vpRGBa> & src, cv::Mat& dest)
748 {
749  cv::Mat vpToMat((int)src.getRows(), (int)src.getCols(), CV_8UC4, (void*)src.bitmap);
750 
751  dest = cv::Mat((int)src.getRows(), (int)src.getCols(), CV_8UC3);
752  cv::Mat alpha((int)src.getRows(), (int)src.getCols(), CV_8UC1);
753 
754  cv::Mat out[] = {dest, alpha};
755  int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
756  cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
757 }
758 
800 void
801 vpImageConvert::convert(const vpImage<unsigned char> & src, cv::Mat& dest, const bool copyData)
802 {
803  if(copyData){
804  cv::Mat tmpMap((int)src.getRows(), (int)src.getCols(), CV_8UC1, (void*)src.bitmap);
805  dest = tmpMap.clone();
806  }else{
807  dest = cv::Mat((int)src.getRows(), (int)src.getCols(), CV_8UC1, (void*)src.bitmap);
808  }
809 }
810 
811 #endif
812 #endif
813 
814 #ifdef VISP_HAVE_YARP
815 
848  yarp::sig::ImageOf< yarp::sig::PixelMono > *dest, const bool copyData)
849 {
850  if(copyData)
851  {
852  dest->resize(src.getWidth(),src.getHeight());
853  memcpy(dest->getRawImage(), src.bitmap, src.getHeight()*src.getWidth());
854  }
855  else
856  dest->setExternal(src.bitmap, (int)src.getCols(), (int)src.getRows());
857 }
858 
895 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
896  vpImage<unsigned char> & dest,const bool copyData)
897 {
898  dest.resize(src->height(),src->width());
899  if(copyData)
900  memcpy(dest.bitmap, src->getRawImage(), src->height()*src->width()*sizeof(yarp::sig::PixelMono));
901  else
902  dest.bitmap = src->getRawImage();
903 }
904 
939  yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest, const bool copyData)
940 {
941  if(copyData){
942  dest->resize(src.getWidth(),src.getHeight());
943  memcpy(dest->getRawImage(), src.bitmap, src.getHeight()*src.getWidth()*sizeof(vpRGBa));
944  }
945  else
946  dest->setExternal(src.bitmap, (int)src.getCols(), (int)src.getRows());
947 }
948 
986 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
987  vpImage<vpRGBa> & dest,const bool copyData)
988 {
989  dest.resize(src->height(),src->width());
990  if(copyData)
991  memcpy(dest.bitmap, src->getRawImage(),src->height()*src->width()*sizeof(yarp::sig::PixelRgba));
992  else
993  dest.bitmap = (vpRGBa*)src->getRawImage();
994 }
995 
1028 void vpImageConvert::convert(const vpImage<vpRGBa> & src, yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest)
1029 {
1030  dest->resize(src.getWidth(),src.getHeight());
1031  for(unsigned int i = 0 ; i < src.getRows() ; i++){
1032  for(unsigned int j = 0 ; j < src.getWidth() ; j++){
1033  dest->pixel(j,i).r = src[i][j].R;
1034  dest->pixel(j,i).g = src[i][j].G;
1035  dest->pixel(j,i).b = src[i][j].B;
1036  }
1037  }
1038 }
1039 
1076 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src, vpImage<vpRGBa> & dest)
1077 {
1078  dest.resize(src->height(),src->width());
1079  for(int i = 0 ; i < src->height() ; i++){
1080  for(int j = 0 ; j < src->width() ; j++){
1081  dest[i][j].R = src->pixel(j,i).r;
1082  dest[i][j].G = src->pixel(j,i).g;
1083  dest[i][j].B = src->pixel(j,i).b;
1084  dest[i][j].A = 0;
1085  }
1086  }
1087 }
1088 
1089 #endif
1090 
1091 #if defined(VISP_HAVE_LIBJPEG)
1092 #if JPEG_LIB_VERSION > 70
1093 
1101 void vpImageConvert::convertToJPEGBuffer(const vpImage<unsigned char> &src,
1102  unsigned char **dest, long unsigned int &destSize, int quality)
1103 {
1104  struct jpeg_compress_struct cinfo;
1105  struct jpeg_error_mgr jerr;
1106 
1107  cinfo.err = jpeg_std_error(&jerr);
1108  jpeg_create_compress(&cinfo);
1109 
1110  *dest = NULL;
1111  destSize = 0;
1112 
1113  jpeg_mem_dest(&cinfo, dest, &destSize);
1114 
1115  unsigned int width = src.getWidth();
1116  unsigned int height = src.getHeight();
1117 
1118  cinfo.image_width = width;
1119  cinfo.image_height = height;
1120  cinfo.input_components = 1;
1121  cinfo.in_color_space = JCS_GRAYSCALE;
1122  jpeg_set_defaults(&cinfo);
1123  jpeg_set_quality(&cinfo, quality, TRUE);
1124 
1125  jpeg_start_compress(&cinfo,TRUE);
1126 
1127  unsigned char *line;
1128  line = new unsigned char[width];
1129  unsigned char* input = (unsigned char*)src.bitmap;
1130  while (cinfo.next_scanline < cinfo.image_height)
1131  {
1132  for (unsigned int i = 0; i < width; i++)
1133  {
1134  line[i] = *(input);
1135  input++;
1136  }
1137  jpeg_write_scanlines(&cinfo, &line, 1);
1138  }
1139 
1140  jpeg_finish_compress(&cinfo);
1141  jpeg_destroy_compress(&cinfo);
1142  delete [] line;
1143 }
1144 
1152 void vpImageConvert::convertToJPEGBuffer(unsigned char *src, long unsigned int srcSize,
1153  vpImage<unsigned char> &dest)
1154 {
1155  struct jpeg_decompress_struct cinfo;
1156  struct jpeg_error_mgr jerr;
1157 
1158  cinfo.err = jpeg_std_error(&jerr);
1159  jpeg_create_decompress(&cinfo);
1160 
1161  jpeg_mem_src(&cinfo, src, srcSize);
1162  jpeg_read_header(&cinfo, TRUE);
1163 
1164  unsigned int width = cinfo.image_width;
1165  unsigned int height = cinfo.image_height;
1166 
1167  if ( (width != dest.getWidth()) || (height != dest.getHeight()) )
1168  dest.resize(height,width);
1169 
1170  jpeg_start_decompress(&cinfo);
1171 
1172  unsigned int rowbytes = cinfo.output_width * (unsigned int)(cinfo.output_components);
1173  JSAMPARRAY buf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, rowbytes, 1);
1174 
1175  if (cinfo.out_color_space == JCS_GRAYSCALE)
1176  {
1177  unsigned int row;
1178  while (cinfo.output_scanline<cinfo.output_height)
1179  {
1180  row = cinfo.output_scanline;
1181  jpeg_read_scanlines(&cinfo,buf,1);
1182  memcpy(dest[row], buf[0], rowbytes);
1183  }
1184  }
1185 
1186  jpeg_finish_decompress(&cinfo);
1187  jpeg_destroy_decompress(&cinfo);
1188 }
1189 #endif
1190 #endif // defined(VISP_HAVE_LIBJPEG)
1191 
1192 
1193 #define vpSAT(c) \
1194  if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1195 
1201 void vpImageConvert::YUYVToRGBa(unsigned char* yuyv, unsigned char* rgba,
1202  unsigned int width, unsigned int height)
1203 {
1204  unsigned char *s;
1205  unsigned char *d;
1206  int w, h, c;
1207  int r, g, b, cr, cg, cb, y1, y2;
1208 
1209  h = (int)height;
1210  w = (int)width;
1211  s = yuyv;
1212  d = rgba;
1213  while (h--) {
1214  c = w >> 1;
1215  while (c--) {
1216  y1 = *s++;
1217  cb = ((*s - 128) * 454) >> 8;
1218  cg = (*s++ - 128) * 88;
1219  y2 = *s++;
1220  cr = ((*s - 128) * 359) >> 8;
1221  cg = (cg + (*s++ - 128) * 183) >> 8;
1222 
1223  r = y1 + cr;
1224  b = y1 + cb;
1225  g = y1 - cg;
1226  vpSAT(r);
1227  vpSAT(g);
1228  vpSAT(b);
1229 
1230  *d++ = static_cast<unsigned char>(r);
1231  *d++ = static_cast<unsigned char>(g);
1232  *d++ = static_cast<unsigned char>(b);
1233  *d++ = 0;
1234 
1235  r = y2 + cr;
1236  b = y2 + cb;
1237  g = y2 - cg;
1238  vpSAT(r);
1239  vpSAT(g);
1240  vpSAT(b);
1241 
1242  *d++ = static_cast<unsigned char>(r);
1243  *d++ = static_cast<unsigned char>(g);
1244  *d++ = static_cast<unsigned char>(b);
1245  *d++ = 0;
1246 
1247  }
1248  }
1249 }
1257 void vpImageConvert::YUYVToRGB(unsigned char* yuyv, unsigned char* rgb,
1258  unsigned int width, unsigned int height)
1259 {
1260  unsigned char *s;
1261  unsigned char *d;
1262  int h, w, c;
1263  int r, g, b, cr, cg, cb, y1, y2;
1264 
1265  h = (int)height;
1266  w = (int)width;
1267  s = yuyv;
1268  d = rgb;
1269  while (h--) {
1270  c = w >> 1;
1271  while (c--) {
1272  y1 = *s++;
1273  cb = ((*s - 128) * 454) >> 8;
1274  cg = (*s++ - 128) * 88;
1275  y2 = *s++;
1276  cr = ((*s - 128) * 359) >> 8;
1277  cg = (cg + (*s++ - 128) * 183) >> 8;
1278 
1279  r = y1 + cr;
1280  b = y1 + cb;
1281  g = y1 - cg;
1282  vpSAT(r);
1283  vpSAT(g);
1284  vpSAT(b);
1285 
1286  *d++ = static_cast<unsigned char>(r);
1287  *d++ = static_cast<unsigned char>(g);
1288  *d++ = static_cast<unsigned char>(b);
1289 
1290  r = y2 + cr;
1291  b = y2 + cb;
1292  g = y2 - cg;
1293  vpSAT(r);
1294  vpSAT(g);
1295  vpSAT(b);
1296 
1297  *d++ = static_cast<unsigned char>(r);
1298  *d++ = static_cast<unsigned char>(g);
1299  *d++ = static_cast<unsigned char>(b);
1300  }
1301  }
1302 }
1310 void vpImageConvert::YUYVToGrey(unsigned char* yuyv, unsigned char* grey, unsigned int size)
1311 {
1312  unsigned int i=0,j=0;
1313 
1314  while( j < size*2)
1315  {
1316  grey[i++] = yuyv[j];
1317  grey[i++] = yuyv[j+2];
1318  j+=4;
1319  }
1320 }
1321 
1322 
1329 void vpImageConvert::YUV411ToRGBa(unsigned char* yuv, unsigned char* rgba, unsigned int size)
1330 {
1331 #if 1
1332  // std::cout << "call optimized ConvertYUV411ToRGBa()" << std::endl;
1333  register int U, V, R, G, B, V2, U5, UV;
1334  register int Y0, Y1, Y2, Y3;
1335  for(unsigned int i = size / 4; i; i--) {
1336  U = (int)((*yuv++ - 128) * 0.354);
1337  U5 = 5*U;
1338  Y0 = *yuv++;
1339  Y1 = *yuv++;
1340  V = (int)((*yuv++ - 128) * 0.707);
1341  V2 = 2*V;
1342  Y2 = *yuv++;
1343  Y3 = *yuv++;
1344  UV = - U - V;
1345 
1346  // Original equations
1347  // R = Y + 1.402 V
1348  // G = Y - 0.344 U - 0.714 V
1349  // B = Y + 1.772 U
1350  R = Y0 + V2;
1351  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1352 
1353  G = Y0 + UV;
1354  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1355 
1356  B = Y0 + U5;
1357  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1358 
1359  *rgba++ = (unsigned char)R;
1360  *rgba++ = (unsigned char)G;
1361  *rgba++ = (unsigned char)B;
1362  rgba++;
1363 
1364  //---
1365  R = Y1 + V2;
1366  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1367 
1368  G = Y1 + UV;
1369  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1370 
1371  B = Y1 + U5;
1372  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1373 
1374  *rgba++ = (unsigned char)R;
1375  *rgba++ = (unsigned char)G;
1376  *rgba++ = (unsigned char)B;
1377  rgba++;
1378 
1379  //---
1380  R = Y2 + V2;
1381  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1382 
1383  G = Y2 + UV;
1384  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1385 
1386  B = Y2 + U5;
1387  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1388 
1389  *rgba++ = (unsigned char)R;
1390  *rgba++ = (unsigned char)G;
1391  *rgba++ = (unsigned char)B;
1392  rgba++;
1393 
1394  //---
1395  R = Y3 + V2;
1396  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1397 
1398  G = Y3 + UV;
1399  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1400 
1401  B = Y3 + U5;
1402  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1403 
1404  *rgba++ = (unsigned char)R;
1405  *rgba++ = (unsigned char)G;
1406  *rgba++ = (unsigned char)B;
1407  rgba++;
1408  }
1409 #else
1410  // tres tres lent ....
1411  unsigned int i=0,j=0;
1412  unsigned char r, g, b;
1413  while( j < numpixels*3/2)
1414  {
1415 
1416  YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1417  rgba[i] = r;
1418  rgba[i+1] = g;
1419  rgba[i+2] = b;
1420  rgba[i+3] = 0;
1421  i+=4;
1422 
1423  YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1424  rgba[i] = r;
1425  rgba[i+1] = g;
1426  rgba[i+2] = b;
1427  rgba[i+3] = 0;
1428  i+=4;
1429 
1430  YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1431  rgba[i] = r;
1432  rgba[i+1] = g;
1433  rgba[i+2] = b;
1434  rgba[i+3] = 0;
1435  i+=4;
1436 
1437  YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1438  rgba[i] = r;
1439  rgba[i+1] = g;
1440  rgba[i+2] = b;
1441  rgba[i+3] = 0;
1442  i+=4;
1443 
1444  j+=6;
1445  }
1446 #endif
1447 
1448 }
1449 
1456 void vpImageConvert::YUV422ToRGBa(unsigned char* yuv, unsigned char* rgba, unsigned int size)
1457 {
1458 
1459 #if 1
1460  // std::cout << "call optimized convertYUV422ToRGBa()" << std::endl;
1461  register int U, V, R, G, B, V2, U5, UV;
1462  register int Y0, Y1;
1463  for( unsigned int i = size / 2; i; i-- ) {
1464  U = (int)((*yuv++ - 128) * 0.354);
1465  U5 = 5*U;
1466  Y0 = *yuv++;
1467  V = (int)((*yuv++ - 128) * 0.707);
1468  V2 = 2*V;
1469  Y1 = *yuv++;
1470  UV = - U - V;
1471 
1472  //---
1473  R = Y0 + V2;
1474  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1475 
1476  G = Y0 + UV;
1477  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1478 
1479  B = Y0 + U5;
1480  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1481 
1482  *rgba++ = (unsigned char)R;
1483  *rgba++ = (unsigned char)G;
1484  *rgba++ = (unsigned char)B;
1485  rgba++;
1486 
1487  //---
1488  R = Y1 + V2;
1489  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1490 
1491  G = Y1 + UV;
1492  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1493 
1494  B = Y1 + U5;
1495  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1496 
1497  *rgba++ = (unsigned char)R;
1498  *rgba++ = (unsigned char)G;
1499  *rgba++ = (unsigned char)B;
1500  rgba++;
1501  }
1502 
1503 #else
1504  // tres tres lent ....
1505  unsigned int i=0,j=0;
1506  unsigned char r, g, b;
1507 
1508  while( j < size*2)
1509  {
1510 
1511  YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1512  rgba[i] = r;
1513  rgba[i+1] = g;
1514  rgba[i+2] = b;
1515  rgba[i+3] = 0;
1516  i+=4;
1517 
1518  YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1519  rgba[i] = r;
1520  rgba[i+1] = g;
1521  rgba[i+2] = b;
1522  rgba[i+3] = 0;
1523  i+=4;
1524  j+=4;
1525 
1526  }
1527 #endif
1528 }
1529 
1536 void vpImageConvert::YUV411ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
1537 {
1538  unsigned int i=0,j=0;
1539  while( j < size*3/2)
1540  {
1541 
1542  grey[i ] = yuv[j+1];
1543  grey[i+1] = yuv[j+2];
1544  grey[i+2] = yuv[j+4];
1545  grey[i+3] = yuv[j+5];
1546 
1547  i+=4;
1548 
1549  j+=6;
1550  }
1551 }
1552 
1561 void vpImageConvert::YUV422ToRGB(unsigned char* yuv, unsigned char* rgb, unsigned int size)
1562 {
1563 #if 1
1564  // std::cout << "call optimized convertYUV422ToRGB()" << std::endl;
1565  register int U, V, R, G, B, V2, U5, UV;
1566  register int Y0, Y1;
1567  for( unsigned int i = size / 2; i; i-- ) {
1568  U = (int)((*yuv++ - 128) * 0.354);
1569  U5 = 5*U;
1570  Y0 = *yuv++;
1571  V = (int)((*yuv++ - 128) * 0.707);
1572  V2 = 2*V;
1573  Y1 = *yuv++;
1574  UV = - U - V;
1575 
1576  //---
1577  R = Y0 + V2;
1578  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1579 
1580  G = Y0 + UV;
1581  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1582 
1583  B = Y0 + U5;
1584  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1585 
1586  *rgb++ = (unsigned char)R;
1587  *rgb++ = (unsigned char)G;
1588  *rgb++ = (unsigned char)B;
1589 
1590  //---
1591  R = Y1 + V2;
1592  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1593 
1594  G = Y1 + UV;
1595  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1596 
1597  B = Y1 + U5;
1598  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1599 
1600  *rgb++ = (unsigned char)R;
1601  *rgb++ = (unsigned char)G;
1602  *rgb++ = (unsigned char)B;
1603 
1604  }
1605 
1606 #else
1607  // tres tres lent ....
1608  unsigned int i=0,j=0;
1609  unsigned char r, g, b;
1610 
1611  while( j < size*2)
1612  {
1613 
1614  YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1615  rgb[i] = r;
1616  rgb[i+1] = g;
1617  rgb[i+2] = b;
1618  i+=3;
1619 
1620  YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1621  rgb[i] = r;
1622  rgb[i+1] = g;
1623  rgb[i+2] = b;
1624  i+=3;
1625  j+=4;
1626 
1627  }
1628 #endif
1629 }
1630 
1639 void vpImageConvert::YUV422ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
1640 {
1641  unsigned int i=0,j=0;
1642 
1643  while( j < size*2)
1644  {
1645  grey[i++] = yuv[j+1];
1646  grey[i++] = yuv[j+3];
1647  j+=4;
1648  }
1649 }
1650 
1657 void vpImageConvert::YUV411ToRGB(unsigned char* yuv, unsigned char* rgb, unsigned int size)
1658 {
1659 #if 1
1660  // std::cout << "call optimized ConvertYUV411ToRGB()" << std::endl;
1661  register int U, V, R, G, B, V2, U5, UV;
1662  register int Y0, Y1, Y2, Y3;
1663  for(unsigned int i = size / 4; i; i--) {
1664  U = (int)((*yuv++ - 128) * 0.354);
1665  U5 = 5*U;
1666  Y0 = *yuv++;
1667  Y1 = *yuv++;
1668  V = (int)((*yuv++ - 128) * 0.707);
1669  V2 = 2*V;
1670  Y2 = *yuv++;
1671  Y3 = *yuv++;
1672  UV = - U - V;
1673 
1674  // Original equations
1675  // R = Y + 1.402 V
1676  // G = Y - 0.344 U - 0.714 V
1677  // B = Y + 1.772 U
1678  R = Y0 + V2;
1679  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1680 
1681  G = Y0 + UV;
1682  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1683 
1684  B = Y0 + U5;
1685  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1686 
1687  *rgb++ = (unsigned char)R;
1688  *rgb++ = (unsigned char)G;
1689  *rgb++ = (unsigned char)B;
1690 
1691  //---
1692  R = Y1 + V2;
1693  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1694 
1695  G = Y1 + UV;
1696  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1697 
1698  B = Y1 + U5;
1699  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1700 
1701  *rgb++ = (unsigned char)R;
1702  *rgb++ = (unsigned char)G;
1703  *rgb++ = (unsigned char)B;
1704 
1705  //---
1706  R = Y2 + V2;
1707  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1708 
1709  G = Y2 + UV;
1710  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1711 
1712  B = Y2 + U5;
1713  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1714 
1715  *rgb++ = (unsigned char)R;
1716  *rgb++ = (unsigned char)G;
1717  *rgb++ = (unsigned char)B;
1718 
1719  //---
1720  R = Y3 + V2;
1721  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1722 
1723  G = Y3 + UV;
1724  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1725 
1726  B = Y3 + U5;
1727  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1728 
1729  *rgb++ = (unsigned char)R;
1730  *rgb++ = (unsigned char)G;
1731  *rgb++ = (unsigned char)B;
1732  }
1733 #else
1734  // tres tres lent ....
1735 
1736  unsigned int i=0,j=0;
1737  unsigned char r, g, b;
1738 
1739  while( j < size*3/2)
1740  {
1741  YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1742  rgb[i] = r;
1743  rgb[i+1] = g;
1744  rgb[i+2] = b;
1745  i+=3;
1746 
1747  YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1748  rgb[i] = r;
1749  rgb[i+1] = g;
1750  rgb[i+2] = b;
1751  i+=3;
1752 
1753  YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1754  rgb[i] = r;
1755  rgb[i+1] = g;
1756  rgb[i+2] = b;
1757  i+=3;
1758 
1759  YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1760  rgb[i] = r;
1761  rgb[i+1] = g;
1762  rgb[i+2] = b;
1763  i+=3;
1764  //TRACE("r= %d g=%d b=%d", r, g, b);
1765 
1766  j+=6;
1767  }
1768 #endif
1769 
1770 }
1771 
1772 
1773 
1780 void vpImageConvert::YUV420ToRGBa(unsigned char* yuv, unsigned char* rgba,
1781  unsigned int width, unsigned int height)
1782 {
1783  // std::cout << "call optimized ConvertYUV420ToRGBa()" << std::endl;
1784  register int U, V, R, G, B, V2, U5, UV;
1785  register int Y0, Y1, Y2, Y3;
1786  unsigned int size = width*height;
1787  unsigned char* iU = yuv + size;
1788  unsigned char* iV = yuv + 5*size/4;
1789  for(unsigned int i = 0; i<height/2; i++)
1790  {
1791  for(unsigned int j = 0; j < width/2 ; j++)
1792  {
1793  U = (int)((*iU++ - 128) * 0.354);
1794  U5 = 5*U;
1795  V = (int)((*iV++ - 128) * 0.707);
1796  V2 = 2*V;
1797  UV = - U - V;
1798  Y0 = *yuv++;
1799  Y1 = *yuv;
1800  yuv = yuv+width-1;
1801  Y2 = *yuv++;
1802  Y3 = *yuv;
1803  yuv = yuv-width+1;
1804 
1805  // Original equations
1806  // R = Y + 1.402 V
1807  // G = Y - 0.344 U - 0.714 V
1808  // B = Y + 1.772 U
1809  R = Y0 + V2;
1810  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1811 
1812  G = Y0 + UV;
1813  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1814 
1815  B = Y0 + U5;
1816  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1817 
1818  *rgba++ = (unsigned char)R;
1819  *rgba++ = (unsigned char)G;
1820  *rgba++ = (unsigned char)B;
1821  *rgba++ = 0;
1822 
1823  //---
1824  R = Y1 + V2;
1825  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1826 
1827  G = Y1 + UV;
1828  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1829 
1830  B = Y1 + U5;
1831  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1832 
1833  *rgba++ = (unsigned char)R;
1834  *rgba++ = (unsigned char)G;
1835  *rgba++ = (unsigned char)B;
1836  *rgba = 0;
1837  rgba = rgba + 4*width-7;
1838 
1839  //---
1840  R = Y2 + V2;
1841  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1842 
1843  G = Y2 + UV;
1844  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1845 
1846  B = Y2 + U5;
1847  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1848 
1849  *rgba++ = (unsigned char)R;
1850  *rgba++ = (unsigned char)G;
1851  *rgba++ = (unsigned char)B;
1852  *rgba++ = 0;
1853 
1854  //---
1855  R = Y3 + V2;
1856  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1857 
1858  G = Y3 + UV;
1859  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1860 
1861  B = Y3 + U5;
1862  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1863 
1864  *rgba++ = (unsigned char)R;
1865  *rgba++ = (unsigned char)G;
1866  *rgba++ = (unsigned char)B;
1867  *rgba = 0;
1868  rgba = rgba -4*width+1;
1869  }
1870  yuv+=width;
1871  rgba+=4*width;
1872  }
1873 }
1880 void vpImageConvert::YUV420ToRGB(unsigned char* yuv,
1881  unsigned char* rgb,
1882  unsigned int width, unsigned int height)
1883 {
1884  // std::cout << "call optimized ConvertYUV420ToRGB()" << std::endl;
1885  register int U, V, R, G, B, V2, U5, UV;
1886  register int Y0, Y1, Y2, Y3;
1887  unsigned int size = width*height;
1888  unsigned char* iU = yuv + size;
1889  unsigned char* iV = yuv + 5*size/4;
1890  for(unsigned int i = 0; i<height/2; i++)
1891  {
1892  for(unsigned int j = 0; j < width/2 ; j++)
1893  {
1894  U = (int)((*iU++ - 128) * 0.354);
1895  U5 = 5*U;
1896  V = (int)((*iV++ - 128) * 0.707);
1897  V2 = 2*V;
1898  UV = - U - V;
1899  Y0 = *yuv++;
1900  Y1 = *yuv;
1901  yuv = yuv+width-1;
1902  Y2 = *yuv++;
1903  Y3 = *yuv;
1904  yuv = yuv-width+1;
1905 
1906  // Original equations
1907  // R = Y + 1.402 V
1908  // G = Y - 0.344 U - 0.714 V
1909  // B = Y + 1.772 U
1910  R = Y0 + V2;
1911  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1912 
1913  G = Y0 + UV;
1914  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1915 
1916  B = Y0 + U5;
1917  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1918 
1919  *rgb++ = (unsigned char)R;
1920  *rgb++ = (unsigned char)G;
1921  *rgb++ = (unsigned char)B;
1922 
1923  //---
1924  R = Y1 + V2;
1925  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1926 
1927  G = Y1 + UV;
1928  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1929 
1930  B = Y1 + U5;
1931  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1932 
1933  *rgb++ = (unsigned char)R;
1934  *rgb++ = (unsigned char)G;
1935  *rgb = (unsigned char)B;
1936  rgb = rgb + 3*width-5;
1937 
1938  //---
1939  R = Y2 + V2;
1940  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1941 
1942  G = Y2 + UV;
1943  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1944 
1945  B = Y2 + U5;
1946  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1947 
1948  *rgb++ = (unsigned char)R;
1949  *rgb++ = (unsigned char)G;
1950  *rgb++ = (unsigned char)B;
1951 
1952  //---
1953  R = Y3 + V2;
1954  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1955 
1956  G = Y3 + UV;
1957  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1958 
1959  B = Y3 + U5;
1960  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1961 
1962  *rgb++ = (unsigned char)R;
1963  *rgb++ = (unsigned char)G;
1964  *rgb = (unsigned char)B;
1965  rgb = rgb -3*width+1;
1966  }
1967  yuv+=width;
1968  rgb+=3*width;
1969  }
1970 }
1971 
1978 void vpImageConvert::YUV420ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
1979 {
1980  for(unsigned int i=0 ; i < size ; i++)
1981  {
1982  *grey++ = *yuv++;
1983  }
1984 
1985 }
1992 void vpImageConvert::YUV444ToRGBa(unsigned char* yuv, unsigned char* rgba, unsigned int size)
1993 {
1994  register int U, V, R, G, B, V2, U5, UV;
1995  register int Y;
1996  for(unsigned int i = 0; i<size; i++)
1997  {
1998  U = (int)((*yuv++ - 128) * 0.354);
1999  U5 = 5*U;
2000  Y = *yuv++;
2001  V = (int)((*yuv++ - 128) * 0.707);
2002  V2 = 2*V;
2003  UV = - U - V;
2004 
2005 
2006  // Original equations
2007  // R = Y + 1.402 V
2008  // G = Y - 0.344 U - 0.714 V
2009  // B = Y + 1.772 U
2010  R = Y + V2;
2011  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2012 
2013  G = Y + UV;
2014  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2015 
2016  B = Y + U5;
2017  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2018 
2019  *rgba++ = (unsigned char)R;
2020  *rgba++ = (unsigned char)G;
2021  *rgba++ = (unsigned char)B;
2022  *rgba++ = 0;
2023  }
2024 }
2031 void vpImageConvert::YUV444ToRGB(unsigned char* yuv, unsigned char* rgb, unsigned int size)
2032 {
2033  register int U, V, R, G, B, V2, U5, UV;
2034  register int Y;
2035  for(unsigned int i = 0; i<size; i++)
2036  {
2037 
2038  U = (int)((*yuv++ - 128) * 0.354);
2039  U5 = 5*U;
2040  Y = *yuv++;
2041  V = (int)((*yuv++ - 128) * 0.707);
2042  V2 = 2*V;
2043  UV = - U - V;
2044 
2045  // Original equations
2046  // R = Y + 1.402 V
2047  // G = Y - 0.344 U - 0.714 V
2048  // B = Y + 1.772 U
2049  R = Y + V2;
2050  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2051 
2052  G = Y + UV;
2053  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2054 
2055  B = Y + U5;
2056  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2057 
2058  *rgb++ = (unsigned char)R;
2059  *rgb++ = (unsigned char)G;
2060  *rgb++ = (unsigned char)B;
2061  }
2062 }
2063 
2070 void vpImageConvert::YUV444ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
2071 {
2072  yuv++;
2073  for(unsigned int i=0 ; i < size ; i++)
2074  {
2075  *grey++ = *yuv;
2076  yuv = yuv + 3;
2077  }
2078 }
2079 
2086 void vpImageConvert::YV12ToRGBa(unsigned char* yuv, unsigned char* rgba,
2087  unsigned int width, unsigned int height)
2088 {
2089  // std::cout << "call optimized ConvertYV12ToRGBa()" << std::endl;
2090  register int U, V, R, G, B, V2, U5, UV;
2091  register int Y0, Y1, Y2, Y3;
2092  unsigned int size = width*height;
2093  unsigned char* iV = yuv + size;
2094  unsigned char* iU = yuv + 5*size/4;
2095  for(unsigned int i = 0; i<height/2; i++)
2096  {
2097  for(unsigned int j = 0; j < width/2 ; j++)
2098  {
2099  U = (int)((*iU++ - 128) * 0.354);
2100  U5 = 5*U;
2101  V = (int)((*iV++ - 128) * 0.707);
2102  V2 = 2*V;
2103  UV = - U - V;
2104  Y0 = *yuv++;
2105  Y1 = *yuv;
2106  yuv = yuv+width-1;
2107  Y2 = *yuv++;
2108  Y3 = *yuv;
2109  yuv = yuv-width+1;
2110 
2111  // Original equations
2112  // R = Y + 1.402 V
2113  // G = Y - 0.344 U - 0.714 V
2114  // B = Y + 1.772 U
2115  R = Y0 + V2;
2116  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2117 
2118  G = Y0 + UV;
2119  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2120 
2121  B = Y0 + U5;
2122  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2123 
2124  *rgba++ = (unsigned char)R;
2125  *rgba++ = (unsigned char)G;
2126  *rgba++ = (unsigned char)B;
2127  *rgba++ = 0;
2128 
2129  //---
2130  R = Y1 + V2;
2131  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2132 
2133  G = Y1 + UV;
2134  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2135 
2136  B = Y1 + U5;
2137  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2138 
2139  *rgba++ = (unsigned char)R;
2140  *rgba++ = (unsigned char)G;
2141  *rgba++ = (unsigned char)B;
2142  *rgba = 0;
2143  rgba = rgba + 4*width-7;
2144 
2145  //---
2146  R = Y2 + V2;
2147  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2148 
2149  G = Y2 + UV;
2150  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2151 
2152  B = Y2 + U5;
2153  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2154 
2155  *rgba++ = (unsigned char)R;
2156  *rgba++ = (unsigned char)G;
2157  *rgba++ = (unsigned char)B;
2158  *rgba++ = 0;
2159 
2160  //---
2161  R = Y3 + V2;
2162  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2163 
2164  G = Y3 + UV;
2165  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2166 
2167  B = Y3 + U5;
2168  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2169 
2170  *rgba++ = (unsigned char)R;
2171  *rgba++ = (unsigned char)G;
2172  *rgba++ = (unsigned char)B;
2173  *rgba = 0;
2174  rgba = rgba -4*width+1;
2175  }
2176  yuv+=width;
2177  rgba+=4*width;
2178  }
2179 }
2186 void vpImageConvert::YV12ToRGB(unsigned char* yuv, unsigned char* rgb,
2187  unsigned int height, unsigned int width)
2188 {
2189  // std::cout << "call optimized ConvertYV12ToRGB()" << std::endl;
2190  register int U, V, R, G, B, V2, U5, UV;
2191  register int Y0, Y1, Y2, Y3;
2192  unsigned int size = width*height;
2193  unsigned char* iV = yuv + size;
2194  unsigned char* iU = yuv + 5*size/4;
2195  for(unsigned int i = 0; i<height/2; i++)
2196  {
2197  for(unsigned int j = 0; j < width/2 ; j++)
2198  {
2199  U = (int)((*iU++ - 128) * 0.354);
2200  U5 = 5*U;
2201  V = (int)((*iV++ - 128) * 0.707);
2202  V2 = 2*V;
2203  UV = - U - V;
2204  Y0 = *yuv++;
2205  Y1 = *yuv;
2206  yuv = yuv+width-1;
2207  Y2 = *yuv++;
2208  Y3 = *yuv;
2209  yuv = yuv-width+1;
2210 
2211  // Original equations
2212  // R = Y + 1.402 V
2213  // G = Y - 0.344 U - 0.714 V
2214  // B = Y + 1.772 U
2215  R = Y0 + V2;
2216  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2217 
2218  G = Y0 + UV;
2219  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2220 
2221  B = Y0 + U5;
2222  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2223 
2224  *rgb++ = (unsigned char)R;
2225  *rgb++ = (unsigned char)G;
2226  *rgb++ = (unsigned char)B;
2227 
2228  //---
2229  R = Y1 + V2;
2230  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2231 
2232  G = Y1 + UV;
2233  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2234 
2235  B = Y1 + U5;
2236  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2237 
2238  *rgb++ = (unsigned char)R;
2239  *rgb++ = (unsigned char)G;
2240  *rgb = (unsigned char)B;
2241  rgb = rgb + 3*width-5;
2242 
2243  //---
2244  R = Y2 + V2;
2245  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2246 
2247  G = Y2 + UV;
2248  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2249 
2250  B = Y2 + U5;
2251  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2252 
2253  *rgb++ = (unsigned char)R;
2254  *rgb++ = (unsigned char)G;
2255  *rgb++ = (unsigned char)B;
2256 
2257  //---
2258  R = Y3 + V2;
2259  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2260 
2261  G = Y3 + UV;
2262  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2263 
2264  B = Y3 + U5;
2265  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2266 
2267  *rgb++ = (unsigned char)R;
2268  *rgb++ = (unsigned char)G;
2269  *rgb = (unsigned char)B;
2270  rgb = rgb -3*width+1;
2271  }
2272  yuv+=width;
2273  rgb+=3*width;
2274  }
2275 }
2276 
2283 void vpImageConvert::YVU9ToRGBa(unsigned char* yuv, unsigned char* rgba,
2284  unsigned int width, unsigned int height)
2285 {
2286  // std::cout << "call optimized ConvertYVU9ToRGBa()" << std::endl;
2287  register int U, V, R, G, B, V2, U5, UV;
2288  register int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2289  unsigned int size = width*height;
2290  unsigned char* iV = yuv + size;
2291  unsigned char* iU = yuv + 17*size/16;
2292  for(unsigned int i = 0; i<height/4; i++)
2293  {
2294  for(unsigned int j = 0; j < width/4 ; j++)
2295  {
2296  U = (int)((*iU++ - 128) * 0.354);
2297  U5 = 5*U;
2298  V = (int)((*iV++ - 128) * 0.707);
2299  V2 = 2*V;
2300  UV = - U - V;
2301  Y0 = *yuv++;
2302  Y1 = *yuv++;
2303  Y2 = *yuv++;
2304  Y3 = *yuv;
2305  yuv = yuv+width-3;
2306  Y4 = *yuv++;
2307  Y5 = *yuv++;
2308  Y6 = *yuv++;
2309  Y7 = *yuv;
2310  yuv = yuv+width-3;
2311  Y8 = *yuv++;
2312  Y9 = *yuv++;
2313  Y10 = *yuv++;
2314  Y11 = *yuv;
2315  yuv = yuv+width-3;
2316  Y12 = *yuv++;
2317  Y13 = *yuv++;
2318  Y14 = *yuv++;
2319  Y15 = *yuv;
2320  yuv = yuv-3*width+1;
2321 
2322  // Original equations
2323  // R = Y + 1.402 V
2324  // G = Y - 0.344 U - 0.714 V
2325  // B = Y + 1.772 U
2326  R = Y0 + V2;
2327  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2328 
2329  G = Y0 + UV;
2330  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2331 
2332  B = Y0 + U5;
2333  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2334 
2335  *rgba++ = (unsigned char)R;
2336  *rgba++ = (unsigned char)G;
2337  *rgba++ = (unsigned char)B;
2338  *rgba++ = 0;
2339 
2340  //---
2341  R = Y1 + V2;
2342  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2343 
2344  G = Y1 + UV;
2345  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2346 
2347  B = Y1 + U5;
2348  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2349 
2350  *rgba++ = (unsigned char)R;
2351  *rgba++ = (unsigned char)G;
2352  *rgba++ = (unsigned char)B;
2353  *rgba++ = 0;
2354 
2355  //---
2356  R = Y2 + V2;
2357  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2358 
2359  G = Y2 + UV;
2360  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2361 
2362  B = Y2 + U5;
2363  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2364 
2365  *rgba++ = (unsigned char)R;
2366  *rgba++ = (unsigned char)G;
2367  *rgba++ = (unsigned char)B;
2368  *rgba++ = 0;
2369 
2370  //---
2371  R = Y3 + V2;
2372  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2373 
2374  G = Y3 + UV;
2375  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2376 
2377  B = Y3 + U5;
2378  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2379 
2380  *rgba++ = (unsigned char)R;
2381  *rgba++ = (unsigned char)G;
2382  *rgba++ = (unsigned char)B;
2383  *rgba = 0;
2384  rgba = rgba + 4*width-15;
2385 
2386  R = Y4 + V2;
2387  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2388 
2389  G = Y4 + UV;
2390  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2391 
2392  B = Y4 + U5;
2393  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2394 
2395  *rgba++ = (unsigned char)R;
2396  *rgba++ = (unsigned char)G;
2397  *rgba++ = (unsigned char)B;
2398  *rgba++ = 0;
2399 
2400  //---
2401  R = Y5 + V2;
2402  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2403 
2404  G = Y5 + UV;
2405  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2406 
2407  B = Y5 + U5;
2408  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2409 
2410  *rgba++ = (unsigned char)R;
2411  *rgba++ = (unsigned char)G;
2412  *rgba++ = (unsigned char)B;
2413  *rgba++ = 0;
2414 
2415  //---
2416  R = Y6 + V2;
2417  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2418 
2419  G = Y6 + UV;
2420  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2421 
2422  B = Y6 + U5;
2423  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2424 
2425  *rgba++ = (unsigned char)R;
2426  *rgba++ = (unsigned char)G;
2427  *rgba++ = (unsigned char)B;
2428  *rgba++ = 0;
2429 
2430  //---
2431  R = Y7 + V2;
2432  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2433 
2434  G = Y7 + UV;
2435  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2436 
2437  B = Y7 + U5;
2438  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2439 
2440  *rgba++ = (unsigned char)R;
2441  *rgba++ = (unsigned char)G;
2442  *rgba++ = (unsigned char)B;
2443  *rgba = 0;
2444  rgba = rgba + 4*width-15;
2445 
2446  R = Y8 + V2;
2447  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2448 
2449  G = Y8 + UV;
2450  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2451 
2452  B = Y8 + U5;
2453  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2454 
2455  *rgba++ = (unsigned char)R;
2456  *rgba++ = (unsigned char)G;
2457  *rgba++ = (unsigned char)B;
2458  *rgba++ = 0;
2459 
2460  //---
2461  R = Y9 + V2;
2462  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2463 
2464  G = Y9 + UV;
2465  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2466 
2467  B = Y9 + U5;
2468  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2469 
2470  *rgba++ = (unsigned char)R;
2471  *rgba++ = (unsigned char)G;
2472  *rgba++ = (unsigned char)B;
2473  *rgba++ = 0;
2474 
2475  //---
2476  R = Y10 + V2;
2477  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2478 
2479  G = Y10 + UV;
2480  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2481 
2482  B = Y10 + U5;
2483  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2484 
2485  *rgba++ = (unsigned char)R;
2486  *rgba++ = (unsigned char)G;
2487  *rgba++ = (unsigned char)B;
2488  *rgba++ = 0;
2489 
2490  //---
2491  R = Y11 + V2;
2492  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2493 
2494  G = Y11 + UV;
2495  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2496 
2497  B = Y11 + U5;
2498  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2499 
2500  *rgba++ = (unsigned char)R;
2501  *rgba++ = (unsigned char)G;
2502  *rgba++ = (unsigned char)B;
2503  *rgba = 0;
2504  rgba = rgba + 4*width-15;
2505 
2506  R = Y12 + V2;
2507  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2508 
2509  G = Y12 + UV;
2510  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2511 
2512  B = Y12 + U5;
2513  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2514 
2515  *rgba++ = (unsigned char)R;
2516  *rgba++ = (unsigned char)G;
2517  *rgba++ = (unsigned char)B;
2518  *rgba++ = 0;
2519 
2520  //---
2521  R = Y13 + V2;
2522  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2523 
2524  G = Y13 + UV;
2525  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2526 
2527  B = Y13 + U5;
2528  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2529 
2530  *rgba++ = (unsigned char)R;
2531  *rgba++ = (unsigned char)G;
2532  *rgba++ = (unsigned char)B;
2533  *rgba++ = 0;
2534 
2535  //---
2536  R = Y14 + V2;
2537  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2538 
2539  G = Y14 + UV;
2540  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2541 
2542  B = Y14 + U5;
2543  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2544 
2545  *rgba++ = (unsigned char)R;
2546  *rgba++ = (unsigned char)G;
2547  *rgba++ = (unsigned char)B;
2548  *rgba++ = 0;
2549 
2550  //---
2551  R = Y15 + V2;
2552  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2553 
2554  G = Y15 + UV;
2555  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2556 
2557  B = Y15 + U5;
2558  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2559 
2560  *rgba++ = (unsigned char)R;
2561  *rgba++ = (unsigned char)G;
2562  *rgba++ = (unsigned char)B;
2563  *rgba = 0;
2564  rgba = rgba -12*width+1;
2565  }
2566  yuv+=3*width;
2567  rgba+=12*width;
2568  }
2569 }
2576 void vpImageConvert::YVU9ToRGB(unsigned char* yuv, unsigned char* rgb,
2577  unsigned int height, unsigned int width)
2578 {
2579  // std::cout << "call optimized ConvertYVU9ToRGB()" << std::endl;
2580  register int U, V, R, G, B, V2, U5, UV;
2581  register int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2582  unsigned int size = width*height;
2583  unsigned char* iV = yuv + size;
2584  unsigned char* iU = yuv + 17*size/16;
2585  for(unsigned int i = 0; i<height/4; i++)
2586  {
2587  for(unsigned int j = 0; j < width/4 ; j++)
2588  {
2589  U = (int)((*iU++ - 128) * 0.354);
2590  U5 = 5*U;
2591  V = (int)((*iV++ - 128) * 0.707);
2592  V2 = 2*V;
2593  UV = - U - V;
2594  Y0 = *yuv++;
2595  Y1 = *yuv++;
2596  Y2 = *yuv++;
2597  Y3 = *yuv;
2598  yuv = yuv+width-3;
2599  Y4 = *yuv++;
2600  Y5 = *yuv++;
2601  Y6 = *yuv++;
2602  Y7 = *yuv;
2603  yuv = yuv+width-3;
2604  Y8 = *yuv++;
2605  Y9 = *yuv++;
2606  Y10 = *yuv++;
2607  Y11 = *yuv;
2608  yuv = yuv+width-3;
2609  Y12 = *yuv++;
2610  Y13 = *yuv++;
2611  Y14 = *yuv++;
2612  Y15 = *yuv;
2613  yuv = yuv-3*width+1;
2614 
2615  // Original equations
2616  // R = Y + 1.402 V
2617  // G = Y - 0.344 U - 0.714 V
2618  // B = Y + 1.772 U
2619  R = Y0 + V2;
2620  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2621 
2622  G = Y0 + UV;
2623  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2624 
2625  B = Y0 + U5;
2626  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2627 
2628  *rgb++ = (unsigned char)R;
2629  *rgb++ = (unsigned char)G;
2630  *rgb++ = (unsigned char)B;
2631 
2632  //---
2633  R = Y1 + V2;
2634  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2635 
2636  G = Y1 + UV;
2637  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2638 
2639  B = Y1 + U5;
2640  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2641 
2642  *rgb++ = (unsigned char)R;
2643  *rgb++ = (unsigned char)G;
2644  *rgb++ = (unsigned char)B;
2645 
2646  //---
2647  R = Y2 + V2;
2648  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2649 
2650  G = Y2 + UV;
2651  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2652 
2653  B = Y2 + U5;
2654  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2655 
2656  *rgb++ = (unsigned char)R;
2657  *rgb++ = (unsigned char)G;
2658  *rgb++ = (unsigned char)B;
2659 
2660  //---
2661  R = Y3 + V2;
2662  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2663 
2664  G = Y3 + UV;
2665  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2666 
2667  B = Y3 + U5;
2668  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2669 
2670  *rgb++ = (unsigned char)R;
2671  *rgb++ = (unsigned char)G;
2672  *rgb = (unsigned char)B;
2673  rgb = rgb + 3*width-11;
2674 
2675  R = Y4 + V2;
2676  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2677 
2678  G = Y4 + UV;
2679  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2680 
2681  B = Y4 + U5;
2682  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2683 
2684  *rgb++ = (unsigned char)R;
2685  *rgb++ = (unsigned char)G;
2686  *rgb++ = (unsigned char)B;
2687 
2688  //---
2689  R = Y5 + V2;
2690  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2691 
2692  G = Y5 + UV;
2693  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2694 
2695  B = Y5 + U5;
2696  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2697 
2698  *rgb++ = (unsigned char)R;
2699  *rgb++ = (unsigned char)G;
2700  *rgb++ = (unsigned char)B;
2701 
2702  //---
2703  R = Y6 + V2;
2704  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2705 
2706  G = Y6 + UV;
2707  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2708 
2709  B = Y6 + U5;
2710  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2711 
2712  *rgb++ = (unsigned char)R;
2713  *rgb++ = (unsigned char)G;
2714  *rgb++ = (unsigned char)B;
2715 
2716  //---
2717  R = Y7 + V2;
2718  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2719 
2720  G = Y7 + UV;
2721  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2722 
2723  B = Y7 + U5;
2724  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2725 
2726  *rgb++ = (unsigned char)R;
2727  *rgb++ = (unsigned char)G;
2728  *rgb = (unsigned char)B;
2729  rgb = rgb + 3*width-11;
2730 
2731  R = Y8 + V2;
2732  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2733 
2734  G = Y8 + UV;
2735  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2736 
2737  B = Y8 + U5;
2738  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2739 
2740  *rgb++ = (unsigned char)R;
2741  *rgb++ = (unsigned char)G;
2742  *rgb++ = (unsigned char)B;
2743 
2744  //---
2745  R = Y9 + V2;
2746  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2747 
2748  G = Y9 + UV;
2749  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2750 
2751  B = Y9 + U5;
2752  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2753 
2754  *rgb++ = (unsigned char)R;
2755  *rgb++ = (unsigned char)G;
2756  *rgb++ = (unsigned char)B;
2757 
2758  //---
2759  R = Y10 + V2;
2760  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2761 
2762  G = Y10 + UV;
2763  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2764 
2765  B = Y10 + U5;
2766  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2767 
2768  *rgb++ = (unsigned char)R;
2769  *rgb++ = (unsigned char)G;
2770  *rgb++ = (unsigned char)B;
2771 
2772  //---
2773  R = Y11 + V2;
2774  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2775 
2776  G = Y11 + UV;
2777  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2778 
2779  B = Y11 + U5;
2780  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2781 
2782  *rgb++ = (unsigned char)R;
2783  *rgb++ = (unsigned char)G;
2784  *rgb = (unsigned char)B;
2785  rgb = rgb + 3*width-11;
2786 
2787  R = Y12 + V2;
2788  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2789 
2790  G = Y12 + UV;
2791  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2792 
2793  B = Y12 + U5;
2794  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2795 
2796  *rgb++ = (unsigned char)R;
2797  *rgb++ = (unsigned char)G;
2798  *rgb++ = (unsigned char)B;
2799 
2800  //---
2801  R = Y13 + V2;
2802  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2803 
2804  G = Y13 + UV;
2805  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2806 
2807  B = Y13 + U5;
2808  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2809 
2810  *rgb++ = (unsigned char)R;
2811  *rgb++ = (unsigned char)G;
2812  *rgb++ = (unsigned char)B;
2813 
2814  //---
2815  R = Y14 + V2;
2816  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2817 
2818  G = Y14 + UV;
2819  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2820 
2821  B = Y14 + U5;
2822  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2823 
2824  *rgb++ = (unsigned char)R;
2825  *rgb++ = (unsigned char)G;
2826  *rgb++ = (unsigned char)B;
2827 
2828  //---
2829  R = Y15 + V2;
2830  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2831 
2832  G = Y15 + UV;
2833  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2834 
2835  B = Y15 + U5;
2836  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2837 
2838  *rgb++ = (unsigned char)R;
2839  *rgb++ = (unsigned char)G;
2840  *rgb++ = (unsigned char)B;
2841  rgb = rgb -9*width+1;
2842  }
2843  yuv+=3*width;
2844  rgb+=9*width;
2845  }
2846 }
2847 
2853 void vpImageConvert::RGBToRGBa(unsigned char* rgb, unsigned char* rgba, unsigned int size)
2854 {
2855  unsigned char *pt_input = rgb;
2856  unsigned char *pt_end = rgb + 3*size;
2857  unsigned char *pt_output = rgba;
2858 
2859  while(pt_input != pt_end) {
2860  *(pt_output++) = *(pt_input++) ; // R
2861  *(pt_output++) = *(pt_input++) ; // G
2862  *(pt_output++) = *(pt_input++) ; // B
2863  *(pt_output++) = 0 ; // A
2864  }
2865 }
2866 
2872 void vpImageConvert::RGBaToRGB(unsigned char* rgba, unsigned char* rgb, unsigned int size)
2873 {
2874  unsigned char *pt_input = rgba;
2875  unsigned char *pt_end = rgba + 4*size;
2876  unsigned char *pt_output = rgb;
2877 
2878  while(pt_input != pt_end) {
2879  *(pt_output++) = *(pt_input++) ; // R
2880  *(pt_output++) = *(pt_input++) ; // G
2881  *(pt_output++) = *(pt_input++) ; // B
2882  pt_input++ ;
2883  }
2884 }
2891 void vpImageConvert::RGBToGrey(unsigned char* rgb, unsigned char* grey, unsigned int size)
2892 {
2893  unsigned char *pt_input = rgb;
2894  unsigned char* pt_end = rgb + size*3;
2895  unsigned char *pt_output = grey;
2896  while(pt_input != pt_end) {
2897  *pt_output = (unsigned char) (0.2126 * (*pt_input)
2898  + 0.7152 * (*(pt_input + 1))
2899  + 0.0722 * (*(pt_input + 2)) );
2900  pt_input += 3;
2901  pt_output ++;
2902  }
2903 }
2911 void vpImageConvert::RGBaToGrey(unsigned char* rgba, unsigned char* grey, unsigned int size)
2912 {
2913  unsigned char *pt_input = rgba;
2914  unsigned char* pt_end = rgba + size*4;
2915  unsigned char *pt_output = grey;
2916 
2917  while(pt_input != pt_end) {
2918  *pt_output = (unsigned char) (0.2126 * (*pt_input)
2919  + 0.7152 * (*(pt_input + 1))
2920  + 0.0722 * (*(pt_input + 2)) );
2921  pt_input += 4;
2922  pt_output ++;
2923  }
2924 }
2925 
2930 void
2931 vpImageConvert::GreyToRGBa(unsigned char* grey, unsigned char* rgba, unsigned int size)
2932 {
2933  unsigned char *pt_input = grey;
2934  unsigned char *pt_end = grey + size;
2935  unsigned char *pt_output = rgba;
2936 
2937  while(pt_input != pt_end) {
2938  unsigned char p = *pt_input ;
2939  *(pt_output ) = p ; // R
2940  *(pt_output + 1) = p ; // G
2941  *(pt_output + 2) = p ; // B
2942  *(pt_output + 3) = p ; // A
2943 
2944  pt_input ++;
2945  pt_output += 4;
2946  }
2947 }
2948 
2953 void
2954 vpImageConvert::GreyToRGB(unsigned char* grey, unsigned char* rgb, unsigned int size)
2955 {
2956  unsigned char *pt_input = grey;
2957  unsigned char* pt_end = grey + size;
2958  unsigned char *pt_output = rgb;
2959 
2960  while(pt_input != pt_end) {
2961  unsigned char p = *pt_input ;
2962  *(pt_output ) = p ; // R
2963  *(pt_output + 1) = p ; // G
2964  *(pt_output + 2) = p ; // B
2965 
2966  pt_input ++;
2967  pt_output += 3;
2968  }
2969 }
2970 
2971 
2977 void
2978 vpImageConvert::BGRToRGBa(unsigned char * bgr, unsigned char * rgba,
2979  unsigned int width, unsigned int height, bool flip)
2980 {
2981  //if we have to flip the image, we start from the end last scanline so the
2982  //step is negative
2983  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
2984 
2985  //starting source address = last line if we need to flip the image
2986  unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
2987  unsigned char * line;
2988 
2989  unsigned int j=0;
2990  unsigned int i=0;
2991 
2992  for(i=0 ; i < height ; i++)
2993  {
2994  line = src;
2995  for( j=0 ; j < width ; j++)
2996  {
2997  *rgba++ = *(line+2);
2998  *rgba++ = *(line+1);
2999  *rgba++ = *(line+0);
3000  *rgba++ = 0;
3001 
3002  line+=3;
3003  }
3004  //go to the next line
3005  src+=lineStep;
3006  }
3007 
3008 }
3009 
3015 void
3016 vpImageConvert::BGRToGrey(unsigned char * bgr, unsigned char * grey,
3017  unsigned int width, unsigned int height, bool flip)
3018 {
3019  //if we have to flip the image, we start from the end last scanline so the
3020  //step is negative
3021  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3022 
3023  //starting source address = last line if we need to flip the image
3024  unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
3025  unsigned char * line;
3026 
3027  unsigned int j=0;
3028  unsigned int i=0;
3029 
3030  for(i=0 ; i < height ; i++)
3031  {
3032  line = src;
3033  for( j=0 ; j < width ; j++)
3034  {
3035  *grey++ = (unsigned char)( 0.2126 * *(line+2)
3036  + 0.7152 * *(line+1)
3037  + 0.0722 * *(line+0)) ;
3038  line+=3;
3039  }
3040 
3041  //go to the next line
3042  src+=lineStep;
3043  }
3044 }
3050 void
3051 vpImageConvert::RGBToRGBa(unsigned char * rgb, unsigned char * rgba,
3052  unsigned int width, unsigned int height, bool flip)
3053 {
3054  //if we have to flip the image, we start from the end last scanline so the
3055  //step is negative
3056  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3057 
3058  //starting source address = last line if we need to flip the image
3059  unsigned char * src = (flip) ? (rgb+(width*height*3)+lineStep) : rgb;
3060  unsigned char * line;
3061 
3062  unsigned int j=0;
3063  unsigned int i=0;
3064 
3065  for(i=0 ; i < height ; i++)
3066  {
3067  line = src;
3068  for( j=0 ; j < width ; j++)
3069  {
3070  *rgba++ = *(line++);
3071  *rgba++ = *(line++);
3072  *rgba++ = *(line++);
3073  *rgba++ = 0;
3074  }
3075  //go to the next line
3076  src+=lineStep;
3077  }
3078 }
3079 
3085 void
3086 vpImageConvert::RGBToGrey(unsigned char * rgb, unsigned char * grey,
3087  unsigned int width, unsigned int height, bool flip)
3088 {
3089  //if we have to flip the image, we start from the end last scanline so the
3090  //step is negative
3091  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3092 
3093  //starting source address = last line if we need to flip the image
3094  unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3095  unsigned char * line;
3096 
3097  unsigned int j=0;
3098  unsigned int i=0;
3099 
3100  unsigned r,g,b;
3101 
3102  for(i=0 ; i < height ; i++)
3103  {
3104  line = src;
3105  for( j=0 ; j < width ; j++)
3106  {
3107  r = *(line++);
3108  g = *(line++);
3109  b = *(line++);
3110  *grey++ = (unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3111  }
3112 
3113  //go to the next line
3114  src+=lineStep;
3115  }
3116 }
3117 
3123 void vpImageConvert::computeYCbCrLUT()
3124 {
3125  if (YCbCrLUTcomputed == false) {
3126  int index = 256, aux;
3127 
3128  while (index-- ) {
3129 
3130  aux = index - 128;
3131  vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3132  vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3133  vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3134  vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3135  }
3136 
3137  YCbCrLUTcomputed = true;
3138  }
3139 }
3140 
3141 
3161 void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
3162 {
3163  unsigned char *cbv;
3164  unsigned char *crv;
3165  unsigned char *pt_ycbcr = ycbcr;
3166  unsigned char *pt_rgb = rgb;
3167  cbv = pt_ycbcr + 1;
3168  crv = pt_ycbcr + 3;
3169 
3170  vpImageConvert::computeYCbCrLUT();
3171 
3172  int col = 0;
3173 
3174  while (size--) {
3175  register int val_r, val_g, val_b;
3176  if (!(col++ % 2)) {
3177  cbv = pt_ycbcr + 1;
3178  crv = pt_ycbcr + 3;
3179  }
3180 
3181  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3182  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3183  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3184 
3185  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3186 
3187  *pt_rgb++ = (val_r < 0) ? 0u :
3188  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3189  *pt_rgb++ = (val_g < 0) ? 0u :
3190  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3191  *pt_rgb++ = (val_b < 0) ? 0u :
3192  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3193 
3194  pt_ycbcr += 2;
3195  }
3196 }
3197 
3219 void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsigned int size)
3220 {
3221  unsigned char *cbv;
3222  unsigned char *crv;
3223  unsigned char *pt_ycbcr = ycbcr;
3224  unsigned char *pt_rgba = rgba;
3225  cbv = pt_ycbcr + 1;
3226  crv = pt_ycbcr + 3;
3227 
3228  vpImageConvert::computeYCbCrLUT();
3229 
3230  int col = 0;
3231 
3232  while (size--) {
3233  register int val_r, val_g, val_b;
3234  if (!(col++ % 2)) {
3235  cbv = pt_ycbcr + 1;
3236  crv = pt_ycbcr + 3;
3237  }
3238 
3239  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3240  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3241  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3242 
3243  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3244 
3245  *pt_rgba++ = (val_r < 0) ? 0u :
3246  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3247  *pt_rgba++ = (val_g < 0) ? 0u :
3248  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3249  *pt_rgba++ = (val_b < 0) ? 0u :
3250  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3251  *pt_rgba++ = 0;
3252 
3253  pt_ycbcr += 2;
3254  }
3255 }
3256 
3257 
3274 void vpImageConvert::YCbCrToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
3275 {
3276  unsigned int i=0,j=0;
3277 
3278  while( j < size*2)
3279  {
3280  grey[i++] = yuv[j];
3281  grey[i++] = yuv[j+2];
3282  j+=4;
3283  }
3284 }
3285 
3304 void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsigned int size)
3305 {
3306  unsigned char *cbv;
3307  unsigned char *crv;
3308  unsigned char *pt_ycbcr = ycrcb;
3309  unsigned char *pt_rgb = rgb;
3310  crv = pt_ycbcr + 1;
3311  cbv = pt_ycbcr + 3;
3312 
3313  vpImageConvert::computeYCbCrLUT();
3314 
3315  int col = 0;
3316 
3317  while (size--) {
3318  register int val_r, val_g, val_b;
3319  if (!(col++ % 2)) {
3320  crv = pt_ycbcr + 1;
3321  cbv = pt_ycbcr + 3;
3322  }
3323 
3324  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3325  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3326  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3327 
3328  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3329 
3330  *pt_rgb++ = (val_r < 0) ? 0u :
3331  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3332  *pt_rgb++ = (val_g < 0) ? 0u :
3333  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3334  *pt_rgb++ = (val_b < 0) ? 0u :
3335  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3336 
3337  pt_ycbcr += 2;
3338  }
3339 }
3360 void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsigned int size)
3361 {
3362  unsigned char *cbv;
3363  unsigned char *crv;
3364  unsigned char *pt_ycbcr = ycrcb;
3365  unsigned char *pt_rgba = rgba;
3366  crv = pt_ycbcr + 1;
3367  cbv = pt_ycbcr + 3;
3368 
3369  vpImageConvert::computeYCbCrLUT();
3370 
3371  int col = 0;
3372 
3373  while (size--) {
3374  register int val_r, val_g, val_b;
3375  if (!(col++ % 2)) {
3376  crv = pt_ycbcr + 1;
3377  cbv = pt_ycbcr + 3;
3378  }
3379 
3380  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3381  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3382  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3383 
3384  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3385 
3386  *pt_rgba++ = (val_r < 0) ? 0u :
3387  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3388  *pt_rgba++ = (val_g < 0) ? 0u :
3389  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3390  *pt_rgba++ = (val_b < 0) ? 0u :
3391  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3392  *pt_rgba++ = 0;
3393 
3394  pt_ycbcr += 2;
3395  }
3396 }
3397 
3438 {
3439  register size_t n = src.getNumberOfPixel();
3440  unsigned int height = src.getHeight();
3441  unsigned int width = src.getWidth();
3442  unsigned char* input;
3443  unsigned char* dst ;
3444 
3445  vpImage<unsigned char>* tabChannel[4];
3446 
3447 /* incrsrc[0] = 0; //init
3448  incrsrc[1] = 0; //step after the first used channel
3449  incrsrc[2] = 0; //step after the second used channel
3450  incrsrc[3] = 0;
3451  incrsrc[4] = 0;
3452  */
3453  tabChannel[0] = pR;
3454  tabChannel[1] = pG;
3455  tabChannel[2] = pB;
3456  tabChannel[3] = pa;
3457 
3458  register size_t i; /* ordre */
3459  for(unsigned int j = 0;j < 4;j++){
3460  if(tabChannel[j]!=NULL){
3461  if(tabChannel[j]->getHeight() != height ||
3462  tabChannel[j]->getWidth() != width){
3463  tabChannel[j]->resize(height,width);
3464  }
3465  dst = (unsigned char*)tabChannel[j]->bitmap;
3466 
3467  input = (unsigned char*)src.bitmap+j;
3468  i = 0;
3469 #if 1 //optimization
3470  if (n >= 4) { /* boucle deroulee lsize fois */
3471  n -= 3;
3472  for (; i < n; i += 4) {
3473  *dst = *input; input += 4; dst++;
3474  *dst = *input; input += 4; dst++;
3475  *dst = *input; input += 4; dst++;
3476  *dst = *input; input += 4; dst++;
3477  }
3478  n += 3;
3479  }
3480 #endif
3481  for (; i < n; i++) {
3482  *dst = *input; input += 4; dst ++;
3483  }
3484  }
3485  }
3486 }
3487 
3498 void vpImageConvert::MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
3499 {
3500  register int i = (((int)size)<<1)-1;
3501  register int j = (int)size-1;
3502  register int y;
3503 
3504  while (i >= 0) {
3505  y = grey16[i--];
3506  grey[j--] = static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3507  }
3508 }
3509 
3520 void vpImageConvert::MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba, unsigned int size)
3521 {
3522  register int i = (((int)size)<<1)-1;
3523  register int j = (int)(size*4-1);
3524  register int y;
3525  register unsigned char v;
3526 
3527  while (i >= 0) {
3528  y = grey16[i--];
3529  v = static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3530  rgba[j--] = 0;
3531  rgba[j--] = v;
3532  rgba[j--] = v;
3533  rgba[j--] = v;
3534  }
3535 }
3536 
3537 /*
3538  * Local variables:
3539  * c-basic-offset: 2
3540  * End:
3541  */
unsigned int getCols() const
Definition: vpImage.h:178
#define vpDEBUG_TRACE
Definition: vpDebug.h:482
static void YUYVToRGBa(unsigned char *yuyv, unsigned char *rgba, unsigned int width, unsigned int height)
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int size)
unsigned int getWidth() const
Definition: vpImage.h:159
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void getMinMaxValue(Type &min, Type &max) const
Look for the minimum and the maximum value within the bitmap.
Definition: vpImage.h:649
unsigned char B
Blue component.
Definition: vpRGBa.h:148
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Type * bitmap
points toward the bitmap
Definition: vpImage.h:120
static void MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
static void YUV422ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV420ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int size)
static void YUV422ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YUV411ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void split(const vpImage< vpRGBa > &src, vpImage< unsigned char > *pR, vpImage< unsigned char > *pG, vpImage< unsigned char > *pB, vpImage< unsigned char > *pa=NULL)
static void YUVToRGB(unsigned char y, unsigned char u, unsigned char v, unsigned char &r, unsigned char &g, unsigned char &b)
unsigned char G
Green component.
Definition: vpRGBa.h:147
static void GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned int size)
Class that defines a RGB 32 bits structure.
Definition: vpRGBa.h:68
static void YUV444ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
static void YUV420ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YVU9ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
unsigned int getRows() const
Definition: vpImage.h:169
static void YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YV12ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int width, unsigned int height)
static void YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsigned int size)
unsigned char A
Additionnal component.
Definition: vpRGBa.h:149
static void YUYVToGrey(unsigned char *yuyv, unsigned char *grey, unsigned int size)
static void MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba, unsigned int size)
unsigned int getNumberOfPixel() const
Definition: vpImage.h:212
void resize(const unsigned int h, const unsigned int w)
set the size of the image
Definition: vpImage.h:532
static void YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int size)
static void YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void YUV411ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigned int size)
unsigned char R
Red component.
Definition: vpRGBa.h:146
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip)
unsigned int getHeight() const
Definition: vpImage.h:150
static void YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size)
static void RGBaToRGB(unsigned char *rgba, unsigned char *rgb, unsigned int size)
static void YCrCbToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void YCrCbToRGBa(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
static void RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int size)
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip)
static void YV12ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)
static void YUV420ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned int width, unsigned int height)