ViSP  2.10.0
vpImageConvert.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImageConvert.cpp 5204 2015-01-24 13:18:18Z 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 // Deprecated: will be removed with OpenCV transcient from C to C++ api
212 void
213 vpImageConvert::convert(const IplImage* src, vpImage<vpRGBa> & dest, bool flip)
214 {
215  int nChannel = src->nChannels;
216  int depth = src->depth;
217  int height = src->height;
218  int width = src->width;
219  int widthStep = src->widthStep;
220  int lineStep = (flip) ? 1 : 0;
221 
222  if(nChannel == 3 && depth == 8){
223  dest.resize((unsigned int)height, (unsigned int)width);
224 
225  //starting source address
226  unsigned char* input = (unsigned char*)src->imageData;
227  unsigned char* line;
228  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
229  unsigned char* output = NULL;
230 
231  for(int i=0 ; i < height ; i++)
232  {
233  line = input;
234  output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
235  for(int j=0 ; j < width ; j++)
236  {
237  *(output++) = *(line+2);
238  *(output++) = *(line+1);
239  *(output++) = *(line);
240  *(output++) = 0;
241 
242  line+=3;
243  }
244  //go to the next line
245  input+=widthStep;
246  }
247  }
248  else if(nChannel == 1 && depth == 8 ){
249  dest.resize((unsigned int)height, (unsigned int)width);
250  //starting source address
251  unsigned char * input = (unsigned char*)src->imageData;
252  unsigned char * line;
253  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
254  unsigned char* output = NULL;
255 
256  for(int i=0 ; i < height ; i++)
257  {
258  line = input;
259  output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
260  for(int j=0 ; j < width ; j++)
261  {
262  *output++ = *(line);
263  *output++ = *(line);
264  *output++ = *(line);
265  *output++ = *(line);;
266 
267  line++;
268  }
269  //go to the next line
270  input+=widthStep;
271  }
272  }
273 }
274 
318 void
319 vpImageConvert::convert(const IplImage* src, vpImage<unsigned char> &dest, bool flip)
320 {
321  int nChannel = src->nChannels;
322  int depth = src->depth;
323  int height = src->height;
324  int width = src->width;
325  int widthStep = src->widthStep;
326  int lineStep = (flip) ? 1 : 0;
327 
328  if (flip == false)
329  {
330  if(widthStep == width){
331  if(nChannel == 1 && depth == 8){
332  dest.resize((unsigned int)height, (unsigned int)width) ;
333  memcpy(dest.bitmap, src->imageData,
334  (size_t)(height*width));
335  }
336  if(nChannel == 3 && depth == 8){
337  dest.resize((unsigned int)height, (unsigned int)width) ;
338  BGRToGrey((unsigned char*)src->imageData,dest.bitmap, (unsigned int)width, (unsigned int)height,false);
339  }
340  }
341  else{
342  if(nChannel == 1 && depth == 8){
343  dest.resize((unsigned int)height, (unsigned int)width) ;
344  for (int i =0 ; i < height ; i++){
345  memcpy(dest.bitmap+i*width, src->imageData + i*widthStep,
346  (size_t)width);
347  }
348  }
349  if(nChannel == 3 && depth == 8){
350  dest.resize((unsigned int)height, (unsigned int)width) ;
351  for (int i = 0 ; i < height ; i++){
352  BGRToGrey((unsigned char*)src->imageData + i*widthStep,
353  dest.bitmap + i*width, (unsigned int)width, 1, false);
354  }
355  }
356  }
357  }
358  else
359  {
360  if(nChannel == 1 && depth == 8){
361  dest.resize((unsigned int)height, (unsigned int)width) ;
362  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
363  for (int i =0 ; i < height ; i++){
364  memcpy(beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) , src->imageData + i*widthStep,
365  (size_t)width);
366  }
367  }
368  if(nChannel == 3 && depth == 8){
369  dest.resize((unsigned int)height, (unsigned int)width) ;
370  //for (int i = 0 ; i < height ; i++){
371  BGRToGrey((unsigned char*)src->imageData /*+ i*widthStep*/,
372  dest.bitmap /*+ i*width*/, (unsigned int)width, (unsigned int)height/*1*/, true);
373  //}
374  }
375  }
376 }
377 
422 void
423 vpImageConvert::convert(const vpImage<vpRGBa> & src, IplImage *&dest)
424 {
425  int height = (int)src.getHeight();
426  int width = (int)src.getWidth();
427  CvSize size = cvSize(width, height);
428  int depth = 8;
429  int channels = 3;
430  if (dest != NULL){
431  if(dest->nChannels != channels || dest->depth != depth
432  || dest->height != height || dest->width != width){
433  if(dest->nChannels != 0) cvReleaseImage(&dest);
434  dest = cvCreateImage( size, depth, channels );
435  }
436  }
437  else dest = cvCreateImage( size, depth, channels );
438 
439 
440  //starting source address
441  unsigned char * input = (unsigned char*)src.bitmap;//rgba image
442  unsigned char * line;
443  unsigned char * output = (unsigned char*)dest->imageData;//bgr image
444 
445  int j=0;
446  int i=0;
447  int widthStep = dest->widthStep;
448 
449  for(i=0 ; i < height ; i++)
450  {
451  output = (unsigned char*)dest->imageData + i*widthStep;
452  line = input;
453  for( j=0 ; j < width ; j++)
454  {
455  *output++ = *(line+2); //B
456  *output++ = *(line+1); //G
457  *output++ = *(line); //R
458 
459  line+=4;
460  }
461  //go to the next line
462  input+=4*width;
463  }
464 }
465 
510 void
511 vpImageConvert::convert(const vpImage<unsigned char> & src, IplImage* &dest)
512 {
513  unsigned int height = src.getHeight();
514  unsigned int width = src.getWidth();
515  CvSize size = cvSize((int)width, (int)height);
516  int depth = 8;
517  int channels = 1;
518  if (dest != NULL){
519  if(dest->nChannels != channels || dest->depth != depth
520  || dest->height != (int) height || dest->width != (int) width){
521  if(dest->nChannels != 0) cvReleaseImage(&dest);
522  dest = cvCreateImage( size, depth, channels );
523  }
524  }
525  else dest = cvCreateImage( size, depth, channels );
526 
527  unsigned int widthStep = (unsigned int)dest->widthStep;
528 
529  if ( width == widthStep){
530  memcpy(dest->imageData,src.bitmap, width*height);
531  }
532  else{
533  //copying each line taking account of the widthStep
534  for (unsigned int i =0 ; i < height ; i++){
535  memcpy(dest->imageData + i*widthStep, src.bitmap + i*width,
536  width);
537  }
538  }
539 }
540 
541 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
542 
584 void
585 vpImageConvert::convert(const cv::Mat& src, vpImage<vpRGBa>& dest, const bool flip)
586 {
587  if(src.type() == CV_8UC4){
588  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
589  vpRGBa rgbaVal;
590  for(unsigned int i=0; i<dest.getRows(); ++i)
591  for(unsigned int j=0; j<dest.getCols(); ++j){
592  cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (int)j);
593  rgbaVal.R = tmp[2];
594  rgbaVal.G = tmp[1];
595  rgbaVal.B = tmp[0];
596  rgbaVal.A = tmp[3];
597  if(flip)
598  dest[dest.getRows()-i-1][j] = rgbaVal;
599  else
600  dest[i][j] = rgbaVal;
601  }
602  }else if(src.type() == CV_8UC3){
603  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
604  vpRGBa rgbaVal;
605  rgbaVal.A = 0;
606  for(unsigned int i=0; i<dest.getRows(); ++i){
607  for(unsigned int j=0; j<dest.getCols(); ++j){
608  cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (int)j);
609  rgbaVal.R = tmp[2];
610  rgbaVal.G = tmp[1];
611  rgbaVal.B = tmp[0];
612  if(flip){
613  dest[dest.getRows()-i-1][j] = rgbaVal;
614  }else{
615  dest[i][j] = rgbaVal;
616  }
617  }
618  }
619  }else if(src.type() == CV_8UC1){
620  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
621  vpRGBa rgbaVal;
622  for(unsigned int i=0; i<dest.getRows(); ++i){
623  for(unsigned int j=0; j<dest.getCols(); ++j){
624  rgbaVal = src.at<unsigned char>((int)i, (int)j);
625  if(flip){
626  dest[dest.getRows()-i-1][j] = rgbaVal;
627  }else{
628  dest[i][j] = rgbaVal;
629  }
630  }
631  }
632  }
633 }
634 
677 void
678 vpImageConvert::convert(const cv::Mat& src, vpImage<unsigned char>& dest, const bool flip)
679 {
680  if(src.type() == CV_8UC1){
681  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
682  if(src.isContinuous() && !flip){
683  memcpy(dest.bitmap, src.data, (size_t)(src.rows*src.cols));
684  }
685  else{
686  if(flip){
687  for(unsigned int i=0; i<dest.getRows(); ++i){
688  memcpy(dest.bitmap+i*dest.getCols(), src.data+(dest.getRows()-i-1)*src.step1(), (size_t)src.step);
689  }
690  }else{
691  for(unsigned int i=0; i<dest.getRows(); ++i){
692  memcpy(dest.bitmap+i*dest.getCols(), src.data+i*src.step1(), (size_t)src.step);
693  }
694  }
695  }
696  }else if(src.type() == CV_8UC3){
697  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
698  if(src.isContinuous() && !flip){
699  BGRToGrey((unsigned char*)src.data, (unsigned char*)dest.bitmap, (unsigned int)src.cols, (unsigned int)src.rows, flip);
700  }
701  else{
702  if(flip){
703  for(unsigned int i=0; i<dest.getRows(); ++i){
704  BGRToGrey((unsigned char*)src.data+i*src.step1(),
705  (unsigned char*)dest.bitmap+(dest.getRows()-i-1)*dest.getCols(),
706  (unsigned int)dest.getCols(), 1, false);
707  }
708  }else{
709  for(unsigned int i=0; i<dest.getRows(); ++i){
710  BGRToGrey((unsigned char*)src.data+i*src.step1(),
711  (unsigned char*)dest.bitmap+i*dest.getCols(),
712  (unsigned int)dest.getCols(), 1, false);
713  }
714  }
715  }
716  }
717 }
718 
719 
759 void
760 vpImageConvert::convert(const vpImage<vpRGBa> & src, cv::Mat& dest)
761 {
762  cv::Mat vpToMat((int)src.getRows(), (int)src.getCols(), CV_8UC4, (void*)src.bitmap);
763 
764  dest = cv::Mat((int)src.getRows(), (int)src.getCols(), CV_8UC3);
765  cv::Mat alpha((int)src.getRows(), (int)src.getCols(), CV_8UC1);
766 
767  cv::Mat out[] = {dest, alpha};
768  int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
769  cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
770 }
771 
813 void
814 vpImageConvert::convert(const vpImage<unsigned char> & src, cv::Mat& dest, const bool copyData)
815 {
816  if(copyData){
817  cv::Mat tmpMap((int)src.getRows(), (int)src.getCols(), CV_8UC1, (void*)src.bitmap);
818  dest = tmpMap.clone();
819  }else{
820  dest = cv::Mat((int)src.getRows(), (int)src.getCols(), CV_8UC1, (void*)src.bitmap);
821  }
822 }
823 
824 #endif
825 #endif
826 
827 #ifdef VISP_HAVE_YARP
828 
861  yarp::sig::ImageOf< yarp::sig::PixelMono > *dest, const bool copyData)
862 {
863  if(copyData)
864  {
865  dest->resize(src.getWidth(),src.getHeight());
866  memcpy(dest->getRawImage(), src.bitmap, src.getHeight()*src.getWidth());
867  }
868  else
869  dest->setExternal(src.bitmap, (int)src.getCols(), (int)src.getRows());
870 }
871 
908 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
909  vpImage<unsigned char> & dest,const bool copyData)
910 {
911  dest.resize(src->height(),src->width());
912  if(copyData)
913  memcpy(dest.bitmap, src->getRawImage(), src->height()*src->width()*sizeof(yarp::sig::PixelMono));
914  else
915  dest.bitmap = src->getRawImage();
916 }
917 
952  yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest, const bool copyData)
953 {
954  if(copyData){
955  dest->resize(src.getWidth(),src.getHeight());
956  memcpy(dest->getRawImage(), src.bitmap, src.getHeight()*src.getWidth()*sizeof(vpRGBa));
957  }
958  else
959  dest->setExternal(src.bitmap, (int)src.getCols(), (int)src.getRows());
960 }
961 
999 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
1000  vpImage<vpRGBa> & dest,const bool copyData)
1001 {
1002  dest.resize(src->height(),src->width());
1003  if(copyData)
1004  memcpy(dest.bitmap, src->getRawImage(),src->height()*src->width()*sizeof(yarp::sig::PixelRgba));
1005  else
1006  dest.bitmap = (vpRGBa*)src->getRawImage();
1007 }
1008 
1041 void vpImageConvert::convert(const vpImage<vpRGBa> & src, yarp::sig::ImageOf< yarp::sig::PixelRgb > *dest)
1042 {
1043  dest->resize(src.getWidth(),src.getHeight());
1044  for(unsigned int i = 0 ; i < src.getRows() ; i++){
1045  for(unsigned int j = 0 ; j < src.getWidth() ; j++){
1046  dest->pixel(j,i).r = src[i][j].R;
1047  dest->pixel(j,i).g = src[i][j].G;
1048  dest->pixel(j,i).b = src[i][j].B;
1049  }
1050  }
1051 }
1052 
1089 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelRgb > *src, vpImage<vpRGBa> & dest)
1090 {
1091  dest.resize(src->height(),src->width());
1092  for(int i = 0 ; i < src->height() ; i++){
1093  for(int j = 0 ; j < src->width() ; j++){
1094  dest[i][j].R = src->pixel(j,i).r;
1095  dest[i][j].G = src->pixel(j,i).g;
1096  dest[i][j].B = src->pixel(j,i).b;
1097  dest[i][j].A = 0;
1098  }
1099  }
1100 }
1101 
1102 #endif
1103 
1104 #if defined(VISP_HAVE_LIBJPEG)
1105 #if JPEG_LIB_VERSION > 70
1106 
1114 void vpImageConvert::convertToJPEGBuffer(const vpImage<unsigned char> &src,
1115  unsigned char **dest, long unsigned int &destSize, int quality)
1116 {
1117  struct jpeg_compress_struct cinfo;
1118  struct jpeg_error_mgr jerr;
1119 
1120  cinfo.err = jpeg_std_error(&jerr);
1121  jpeg_create_compress(&cinfo);
1122 
1123  *dest = NULL;
1124  destSize = 0;
1125 
1126  jpeg_mem_dest(&cinfo, dest, &destSize);
1127 
1128  unsigned int width = src.getWidth();
1129  unsigned int height = src.getHeight();
1130 
1131  cinfo.image_width = width;
1132  cinfo.image_height = height;
1133  cinfo.input_components = 1;
1134  cinfo.in_color_space = JCS_GRAYSCALE;
1135  jpeg_set_defaults(&cinfo);
1136  jpeg_set_quality(&cinfo, quality, TRUE);
1137 
1138  jpeg_start_compress(&cinfo,TRUE);
1139 
1140  unsigned char *line;
1141  line = new unsigned char[width];
1142  unsigned char* input = (unsigned char*)src.bitmap;
1143  while (cinfo.next_scanline < cinfo.image_height)
1144  {
1145  for (unsigned int i = 0; i < width; i++)
1146  {
1147  line[i] = *(input);
1148  input++;
1149  }
1150  jpeg_write_scanlines(&cinfo, &line, 1);
1151  }
1152 
1153  jpeg_finish_compress(&cinfo);
1154  jpeg_destroy_compress(&cinfo);
1155  delete [] line;
1156 }
1157 
1165 void vpImageConvert::convertToJPEGBuffer(unsigned char *src, long unsigned int srcSize,
1166  vpImage<unsigned char> &dest)
1167 {
1168  struct jpeg_decompress_struct cinfo;
1169  struct jpeg_error_mgr jerr;
1170 
1171  cinfo.err = jpeg_std_error(&jerr);
1172  jpeg_create_decompress(&cinfo);
1173 
1174  jpeg_mem_src(&cinfo, src, srcSize);
1175  jpeg_read_header(&cinfo, TRUE);
1176 
1177  unsigned int width = cinfo.image_width;
1178  unsigned int height = cinfo.image_height;
1179 
1180  if ( (width != dest.getWidth()) || (height != dest.getHeight()) )
1181  dest.resize(height,width);
1182 
1183  jpeg_start_decompress(&cinfo);
1184 
1185  unsigned int rowbytes = cinfo.output_width * (unsigned int)(cinfo.output_components);
1186  JSAMPARRAY buf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, rowbytes, 1);
1187 
1188  if (cinfo.out_color_space == JCS_GRAYSCALE)
1189  {
1190  unsigned int row;
1191  while (cinfo.output_scanline<cinfo.output_height)
1192  {
1193  row = cinfo.output_scanline;
1194  jpeg_read_scanlines(&cinfo,buf,1);
1195  memcpy(dest[row], buf[0], rowbytes);
1196  }
1197  }
1198 
1199  jpeg_finish_decompress(&cinfo);
1200  jpeg_destroy_decompress(&cinfo);
1201 }
1202 #endif
1203 #endif // defined(VISP_HAVE_LIBJPEG)
1204 
1205 
1206 #define vpSAT(c) \
1207  if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1208 
1214 void vpImageConvert::YUYVToRGBa(unsigned char* yuyv, unsigned char* rgba,
1215  unsigned int width, unsigned int height)
1216 {
1217  unsigned char *s;
1218  unsigned char *d;
1219  int w, h, c;
1220  int r, g, b, cr, cg, cb, y1, y2;
1221 
1222  h = (int)height;
1223  w = (int)width;
1224  s = yuyv;
1225  d = rgba;
1226  while (h--) {
1227  c = w >> 1;
1228  while (c--) {
1229  y1 = *s++;
1230  cb = ((*s - 128) * 454) >> 8;
1231  cg = (*s++ - 128) * 88;
1232  y2 = *s++;
1233  cr = ((*s - 128) * 359) >> 8;
1234  cg = (cg + (*s++ - 128) * 183) >> 8;
1235 
1236  r = y1 + cr;
1237  b = y1 + cb;
1238  g = y1 - cg;
1239  vpSAT(r);
1240  vpSAT(g);
1241  vpSAT(b);
1242 
1243  *d++ = static_cast<unsigned char>(r);
1244  *d++ = static_cast<unsigned char>(g);
1245  *d++ = static_cast<unsigned char>(b);
1246  *d++ = 0;
1247 
1248  r = y2 + cr;
1249  b = y2 + cb;
1250  g = y2 - cg;
1251  vpSAT(r);
1252  vpSAT(g);
1253  vpSAT(b);
1254 
1255  *d++ = static_cast<unsigned char>(r);
1256  *d++ = static_cast<unsigned char>(g);
1257  *d++ = static_cast<unsigned char>(b);
1258  *d++ = 0;
1259 
1260  }
1261  }
1262 }
1270 void vpImageConvert::YUYVToRGB(unsigned char* yuyv, unsigned char* rgb,
1271  unsigned int width, unsigned int height)
1272 {
1273  unsigned char *s;
1274  unsigned char *d;
1275  int h, w, c;
1276  int r, g, b, cr, cg, cb, y1, y2;
1277 
1278  h = (int)height;
1279  w = (int)width;
1280  s = yuyv;
1281  d = rgb;
1282  while (h--) {
1283  c = w >> 1;
1284  while (c--) {
1285  y1 = *s++;
1286  cb = ((*s - 128) * 454) >> 8;
1287  cg = (*s++ - 128) * 88;
1288  y2 = *s++;
1289  cr = ((*s - 128) * 359) >> 8;
1290  cg = (cg + (*s++ - 128) * 183) >> 8;
1291 
1292  r = y1 + cr;
1293  b = y1 + cb;
1294  g = y1 - cg;
1295  vpSAT(r);
1296  vpSAT(g);
1297  vpSAT(b);
1298 
1299  *d++ = static_cast<unsigned char>(r);
1300  *d++ = static_cast<unsigned char>(g);
1301  *d++ = static_cast<unsigned char>(b);
1302 
1303  r = y2 + cr;
1304  b = y2 + cb;
1305  g = y2 - cg;
1306  vpSAT(r);
1307  vpSAT(g);
1308  vpSAT(b);
1309 
1310  *d++ = static_cast<unsigned char>(r);
1311  *d++ = static_cast<unsigned char>(g);
1312  *d++ = static_cast<unsigned char>(b);
1313  }
1314  }
1315 }
1323 void vpImageConvert::YUYVToGrey(unsigned char* yuyv, unsigned char* grey, unsigned int size)
1324 {
1325  unsigned int i=0,j=0;
1326 
1327  while( j < size*2)
1328  {
1329  grey[i++] = yuyv[j];
1330  grey[i++] = yuyv[j+2];
1331  j+=4;
1332  }
1333 }
1334 
1335 
1342 void vpImageConvert::YUV411ToRGBa(unsigned char* yuv, unsigned char* rgba, unsigned int size)
1343 {
1344 #if 1
1345  // std::cout << "call optimized ConvertYUV411ToRGBa()" << std::endl;
1346  register int U, V, R, G, B, V2, U5, UV;
1347  register int Y0, Y1, Y2, Y3;
1348  for(unsigned int i = size / 4; i; i--) {
1349  U = (int)((*yuv++ - 128) * 0.354);
1350  U5 = 5*U;
1351  Y0 = *yuv++;
1352  Y1 = *yuv++;
1353  V = (int)((*yuv++ - 128) * 0.707);
1354  V2 = 2*V;
1355  Y2 = *yuv++;
1356  Y3 = *yuv++;
1357  UV = - U - V;
1358 
1359  // Original equations
1360  // R = Y + 1.402 V
1361  // G = Y - 0.344 U - 0.714 V
1362  // B = Y + 1.772 U
1363  R = Y0 + V2;
1364  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1365 
1366  G = Y0 + UV;
1367  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1368 
1369  B = Y0 + U5;
1370  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1371 
1372  *rgba++ = (unsigned char)R;
1373  *rgba++ = (unsigned char)G;
1374  *rgba++ = (unsigned char)B;
1375  rgba++;
1376 
1377  //---
1378  R = Y1 + V2;
1379  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1380 
1381  G = Y1 + UV;
1382  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1383 
1384  B = Y1 + U5;
1385  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1386 
1387  *rgba++ = (unsigned char)R;
1388  *rgba++ = (unsigned char)G;
1389  *rgba++ = (unsigned char)B;
1390  rgba++;
1391 
1392  //---
1393  R = Y2 + V2;
1394  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1395 
1396  G = Y2 + UV;
1397  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1398 
1399  B = Y2 + U5;
1400  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1401 
1402  *rgba++ = (unsigned char)R;
1403  *rgba++ = (unsigned char)G;
1404  *rgba++ = (unsigned char)B;
1405  rgba++;
1406 
1407  //---
1408  R = Y3 + V2;
1409  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1410 
1411  G = Y3 + UV;
1412  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1413 
1414  B = Y3 + U5;
1415  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1416 
1417  *rgba++ = (unsigned char)R;
1418  *rgba++ = (unsigned char)G;
1419  *rgba++ = (unsigned char)B;
1420  rgba++;
1421  }
1422 #else
1423  // tres tres lent ....
1424  unsigned int i=0,j=0;
1425  unsigned char r, g, b;
1426  while( j < numpixels*3/2)
1427  {
1428 
1429  YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1430  rgba[i] = r;
1431  rgba[i+1] = g;
1432  rgba[i+2] = b;
1433  rgba[i+3] = 0;
1434  i+=4;
1435 
1436  YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1437  rgba[i] = r;
1438  rgba[i+1] = g;
1439  rgba[i+2] = b;
1440  rgba[i+3] = 0;
1441  i+=4;
1442 
1443  YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1444  rgba[i] = r;
1445  rgba[i+1] = g;
1446  rgba[i+2] = b;
1447  rgba[i+3] = 0;
1448  i+=4;
1449 
1450  YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1451  rgba[i] = r;
1452  rgba[i+1] = g;
1453  rgba[i+2] = b;
1454  rgba[i+3] = 0;
1455  i+=4;
1456 
1457  j+=6;
1458  }
1459 #endif
1460 
1461 }
1462 
1469 void vpImageConvert::YUV422ToRGBa(unsigned char* yuv, unsigned char* rgba, unsigned int size)
1470 {
1471 
1472 #if 1
1473  // std::cout << "call optimized convertYUV422ToRGBa()" << std::endl;
1474  register int U, V, R, G, B, V2, U5, UV;
1475  register int Y0, Y1;
1476  for( unsigned int i = size / 2; i; i-- ) {
1477  U = (int)((*yuv++ - 128) * 0.354);
1478  U5 = 5*U;
1479  Y0 = *yuv++;
1480  V = (int)((*yuv++ - 128) * 0.707);
1481  V2 = 2*V;
1482  Y1 = *yuv++;
1483  UV = - U - V;
1484 
1485  //---
1486  R = Y0 + V2;
1487  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1488 
1489  G = Y0 + UV;
1490  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1491 
1492  B = Y0 + U5;
1493  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1494 
1495  *rgba++ = (unsigned char)R;
1496  *rgba++ = (unsigned char)G;
1497  *rgba++ = (unsigned char)B;
1498  rgba++;
1499 
1500  //---
1501  R = Y1 + V2;
1502  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1503 
1504  G = Y1 + UV;
1505  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1506 
1507  B = Y1 + U5;
1508  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1509 
1510  *rgba++ = (unsigned char)R;
1511  *rgba++ = (unsigned char)G;
1512  *rgba++ = (unsigned char)B;
1513  rgba++;
1514  }
1515 
1516 #else
1517  // tres tres lent ....
1518  unsigned int i=0,j=0;
1519  unsigned char r, g, b;
1520 
1521  while( j < size*2)
1522  {
1523 
1524  YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1525  rgba[i] = r;
1526  rgba[i+1] = g;
1527  rgba[i+2] = b;
1528  rgba[i+3] = 0;
1529  i+=4;
1530 
1531  YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1532  rgba[i] = r;
1533  rgba[i+1] = g;
1534  rgba[i+2] = b;
1535  rgba[i+3] = 0;
1536  i+=4;
1537  j+=4;
1538 
1539  }
1540 #endif
1541 }
1542 
1549 void vpImageConvert::YUV411ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
1550 {
1551  unsigned int i=0,j=0;
1552  while( j < size*3/2)
1553  {
1554 
1555  grey[i ] = yuv[j+1];
1556  grey[i+1] = yuv[j+2];
1557  grey[i+2] = yuv[j+4];
1558  grey[i+3] = yuv[j+5];
1559 
1560  i+=4;
1561 
1562  j+=6;
1563  }
1564 }
1565 
1574 void vpImageConvert::YUV422ToRGB(unsigned char* yuv, unsigned char* rgb, unsigned int size)
1575 {
1576 #if 1
1577  // std::cout << "call optimized convertYUV422ToRGB()" << std::endl;
1578  register int U, V, R, G, B, V2, U5, UV;
1579  register int Y0, Y1;
1580  for( unsigned int i = size / 2; i; i-- ) {
1581  U = (int)((*yuv++ - 128) * 0.354);
1582  U5 = 5*U;
1583  Y0 = *yuv++;
1584  V = (int)((*yuv++ - 128) * 0.707);
1585  V2 = 2*V;
1586  Y1 = *yuv++;
1587  UV = - U - V;
1588 
1589  //---
1590  R = Y0 + V2;
1591  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1592 
1593  G = Y0 + UV;
1594  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1595 
1596  B = Y0 + U5;
1597  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1598 
1599  *rgb++ = (unsigned char)R;
1600  *rgb++ = (unsigned char)G;
1601  *rgb++ = (unsigned char)B;
1602 
1603  //---
1604  R = Y1 + V2;
1605  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1606 
1607  G = Y1 + UV;
1608  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1609 
1610  B = Y1 + U5;
1611  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1612 
1613  *rgb++ = (unsigned char)R;
1614  *rgb++ = (unsigned char)G;
1615  *rgb++ = (unsigned char)B;
1616 
1617  }
1618 
1619 #else
1620  // tres tres lent ....
1621  unsigned int i=0,j=0;
1622  unsigned char r, g, b;
1623 
1624  while( j < size*2)
1625  {
1626 
1627  YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1628  rgb[i] = r;
1629  rgb[i+1] = g;
1630  rgb[i+2] = b;
1631  i+=3;
1632 
1633  YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1634  rgb[i] = r;
1635  rgb[i+1] = g;
1636  rgb[i+2] = b;
1637  i+=3;
1638  j+=4;
1639 
1640  }
1641 #endif
1642 }
1643 
1652 void vpImageConvert::YUV422ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
1653 {
1654  unsigned int i=0,j=0;
1655 
1656  while( j < size*2)
1657  {
1658  grey[i++] = yuv[j+1];
1659  grey[i++] = yuv[j+3];
1660  j+=4;
1661  }
1662 }
1663 
1670 void vpImageConvert::YUV411ToRGB(unsigned char* yuv, unsigned char* rgb, unsigned int size)
1671 {
1672 #if 1
1673  // std::cout << "call optimized ConvertYUV411ToRGB()" << std::endl;
1674  register int U, V, R, G, B, V2, U5, UV;
1675  register int Y0, Y1, Y2, Y3;
1676  for(unsigned int i = size / 4; i; i--) {
1677  U = (int)((*yuv++ - 128) * 0.354);
1678  U5 = 5*U;
1679  Y0 = *yuv++;
1680  Y1 = *yuv++;
1681  V = (int)((*yuv++ - 128) * 0.707);
1682  V2 = 2*V;
1683  Y2 = *yuv++;
1684  Y3 = *yuv++;
1685  UV = - U - V;
1686 
1687  // Original equations
1688  // R = Y + 1.402 V
1689  // G = Y - 0.344 U - 0.714 V
1690  // B = Y + 1.772 U
1691  R = Y0 + V2;
1692  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1693 
1694  G = Y0 + UV;
1695  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1696 
1697  B = Y0 + U5;
1698  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1699 
1700  *rgb++ = (unsigned char)R;
1701  *rgb++ = (unsigned char)G;
1702  *rgb++ = (unsigned char)B;
1703 
1704  //---
1705  R = Y1 + V2;
1706  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1707 
1708  G = Y1 + UV;
1709  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1710 
1711  B = Y1 + U5;
1712  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1713 
1714  *rgb++ = (unsigned char)R;
1715  *rgb++ = (unsigned char)G;
1716  *rgb++ = (unsigned char)B;
1717 
1718  //---
1719  R = Y2 + V2;
1720  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1721 
1722  G = Y2 + UV;
1723  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1724 
1725  B = Y2 + U5;
1726  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1727 
1728  *rgb++ = (unsigned char)R;
1729  *rgb++ = (unsigned char)G;
1730  *rgb++ = (unsigned char)B;
1731 
1732  //---
1733  R = Y3 + V2;
1734  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1735 
1736  G = Y3 + UV;
1737  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1738 
1739  B = Y3 + U5;
1740  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1741 
1742  *rgb++ = (unsigned char)R;
1743  *rgb++ = (unsigned char)G;
1744  *rgb++ = (unsigned char)B;
1745  }
1746 #else
1747  // tres tres lent ....
1748 
1749  unsigned int i=0,j=0;
1750  unsigned char r, g, b;
1751 
1752  while( j < size*3/2)
1753  {
1754  YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1755  rgb[i] = r;
1756  rgb[i+1] = g;
1757  rgb[i+2] = b;
1758  i+=3;
1759 
1760  YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1761  rgb[i] = r;
1762  rgb[i+1] = g;
1763  rgb[i+2] = b;
1764  i+=3;
1765 
1766  YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1767  rgb[i] = r;
1768  rgb[i+1] = g;
1769  rgb[i+2] = b;
1770  i+=3;
1771 
1772  YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1773  rgb[i] = r;
1774  rgb[i+1] = g;
1775  rgb[i+2] = b;
1776  i+=3;
1777  //TRACE("r= %d g=%d b=%d", r, g, b);
1778 
1779  j+=6;
1780  }
1781 #endif
1782 
1783 }
1784 
1785 
1786 
1793 void vpImageConvert::YUV420ToRGBa(unsigned char* yuv, unsigned char* rgba,
1794  unsigned int width, unsigned int height)
1795 {
1796  // std::cout << "call optimized ConvertYUV420ToRGBa()" << std::endl;
1797  register int U, V, R, G, B, V2, U5, UV;
1798  register int Y0, Y1, Y2, Y3;
1799  unsigned int size = width*height;
1800  unsigned char* iU = yuv + size;
1801  unsigned char* iV = yuv + 5*size/4;
1802  for(unsigned int i = 0; i<height/2; i++)
1803  {
1804  for(unsigned int j = 0; j < width/2 ; j++)
1805  {
1806  U = (int)((*iU++ - 128) * 0.354);
1807  U5 = 5*U;
1808  V = (int)((*iV++ - 128) * 0.707);
1809  V2 = 2*V;
1810  UV = - U - V;
1811  Y0 = *yuv++;
1812  Y1 = *yuv;
1813  yuv = yuv+width-1;
1814  Y2 = *yuv++;
1815  Y3 = *yuv;
1816  yuv = yuv-width+1;
1817 
1818  // Original equations
1819  // R = Y + 1.402 V
1820  // G = Y - 0.344 U - 0.714 V
1821  // B = Y + 1.772 U
1822  R = Y0 + V2;
1823  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1824 
1825  G = Y0 + UV;
1826  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1827 
1828  B = Y0 + U5;
1829  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1830 
1831  *rgba++ = (unsigned char)R;
1832  *rgba++ = (unsigned char)G;
1833  *rgba++ = (unsigned char)B;
1834  *rgba++ = 0;
1835 
1836  //---
1837  R = Y1 + V2;
1838  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1839 
1840  G = Y1 + UV;
1841  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1842 
1843  B = Y1 + U5;
1844  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1845 
1846  *rgba++ = (unsigned char)R;
1847  *rgba++ = (unsigned char)G;
1848  *rgba++ = (unsigned char)B;
1849  *rgba = 0;
1850  rgba = rgba + 4*width-7;
1851 
1852  //---
1853  R = Y2 + V2;
1854  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1855 
1856  G = Y2 + UV;
1857  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1858 
1859  B = Y2 + U5;
1860  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1861 
1862  *rgba++ = (unsigned char)R;
1863  *rgba++ = (unsigned char)G;
1864  *rgba++ = (unsigned char)B;
1865  *rgba++ = 0;
1866 
1867  //---
1868  R = Y3 + V2;
1869  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1870 
1871  G = Y3 + UV;
1872  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1873 
1874  B = Y3 + U5;
1875  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1876 
1877  *rgba++ = (unsigned char)R;
1878  *rgba++ = (unsigned char)G;
1879  *rgba++ = (unsigned char)B;
1880  *rgba = 0;
1881  rgba = rgba -4*width+1;
1882  }
1883  yuv+=width;
1884  rgba+=4*width;
1885  }
1886 }
1893 void vpImageConvert::YUV420ToRGB(unsigned char* yuv,
1894  unsigned char* rgb,
1895  unsigned int width, unsigned int height)
1896 {
1897  // std::cout << "call optimized ConvertYUV420ToRGB()" << std::endl;
1898  register int U, V, R, G, B, V2, U5, UV;
1899  register int Y0, Y1, Y2, Y3;
1900  unsigned int size = width*height;
1901  unsigned char* iU = yuv + size;
1902  unsigned char* iV = yuv + 5*size/4;
1903  for(unsigned int i = 0; i<height/2; i++)
1904  {
1905  for(unsigned int j = 0; j < width/2 ; j++)
1906  {
1907  U = (int)((*iU++ - 128) * 0.354);
1908  U5 = 5*U;
1909  V = (int)((*iV++ - 128) * 0.707);
1910  V2 = 2*V;
1911  UV = - U - V;
1912  Y0 = *yuv++;
1913  Y1 = *yuv;
1914  yuv = yuv+width-1;
1915  Y2 = *yuv++;
1916  Y3 = *yuv;
1917  yuv = yuv-width+1;
1918 
1919  // Original equations
1920  // R = Y + 1.402 V
1921  // G = Y - 0.344 U - 0.714 V
1922  // B = Y + 1.772 U
1923  R = Y0 + V2;
1924  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1925 
1926  G = Y0 + UV;
1927  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1928 
1929  B = Y0 + U5;
1930  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1931 
1932  *rgb++ = (unsigned char)R;
1933  *rgb++ = (unsigned char)G;
1934  *rgb++ = (unsigned char)B;
1935 
1936  //---
1937  R = Y1 + V2;
1938  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1939 
1940  G = Y1 + UV;
1941  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1942 
1943  B = Y1 + U5;
1944  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1945 
1946  *rgb++ = (unsigned char)R;
1947  *rgb++ = (unsigned char)G;
1948  *rgb = (unsigned char)B;
1949  rgb = rgb + 3*width-5;
1950 
1951  //---
1952  R = Y2 + V2;
1953  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1954 
1955  G = Y2 + UV;
1956  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1957 
1958  B = Y2 + U5;
1959  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1960 
1961  *rgb++ = (unsigned char)R;
1962  *rgb++ = (unsigned char)G;
1963  *rgb++ = (unsigned char)B;
1964 
1965  //---
1966  R = Y3 + V2;
1967  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1968 
1969  G = Y3 + UV;
1970  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1971 
1972  B = Y3 + U5;
1973  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1974 
1975  *rgb++ = (unsigned char)R;
1976  *rgb++ = (unsigned char)G;
1977  *rgb = (unsigned char)B;
1978  rgb = rgb -3*width+1;
1979  }
1980  yuv+=width;
1981  rgb+=3*width;
1982  }
1983 }
1984 
1991 void vpImageConvert::YUV420ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
1992 {
1993  for(unsigned int i=0 ; i < size ; i++)
1994  {
1995  *grey++ = *yuv++;
1996  }
1997 
1998 }
2005 void vpImageConvert::YUV444ToRGBa(unsigned char* yuv, unsigned char* rgba, unsigned int size)
2006 {
2007  register int U, V, R, G, B, V2, U5, UV;
2008  register int Y;
2009  for(unsigned int i = 0; i<size; i++)
2010  {
2011  U = (int)((*yuv++ - 128) * 0.354);
2012  U5 = 5*U;
2013  Y = *yuv++;
2014  V = (int)((*yuv++ - 128) * 0.707);
2015  V2 = 2*V;
2016  UV = - U - V;
2017 
2018 
2019  // Original equations
2020  // R = Y + 1.402 V
2021  // G = Y - 0.344 U - 0.714 V
2022  // B = Y + 1.772 U
2023  R = Y + V2;
2024  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2025 
2026  G = Y + UV;
2027  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2028 
2029  B = Y + U5;
2030  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2031 
2032  *rgba++ = (unsigned char)R;
2033  *rgba++ = (unsigned char)G;
2034  *rgba++ = (unsigned char)B;
2035  *rgba++ = 0;
2036  }
2037 }
2044 void vpImageConvert::YUV444ToRGB(unsigned char* yuv, unsigned char* rgb, unsigned int size)
2045 {
2046  register int U, V, R, G, B, V2, U5, UV;
2047  register int Y;
2048  for(unsigned int i = 0; i<size; i++)
2049  {
2050 
2051  U = (int)((*yuv++ - 128) * 0.354);
2052  U5 = 5*U;
2053  Y = *yuv++;
2054  V = (int)((*yuv++ - 128) * 0.707);
2055  V2 = 2*V;
2056  UV = - U - V;
2057 
2058  // Original equations
2059  // R = Y + 1.402 V
2060  // G = Y - 0.344 U - 0.714 V
2061  // B = Y + 1.772 U
2062  R = Y + V2;
2063  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2064 
2065  G = Y + UV;
2066  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2067 
2068  B = Y + U5;
2069  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2070 
2071  *rgb++ = (unsigned char)R;
2072  *rgb++ = (unsigned char)G;
2073  *rgb++ = (unsigned char)B;
2074  }
2075 }
2076 
2083 void vpImageConvert::YUV444ToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
2084 {
2085  yuv++;
2086  for(unsigned int i=0 ; i < size ; i++)
2087  {
2088  *grey++ = *yuv;
2089  yuv = yuv + 3;
2090  }
2091 }
2092 
2099 void vpImageConvert::YV12ToRGBa(unsigned char* yuv, unsigned char* rgba,
2100  unsigned int width, unsigned int height)
2101 {
2102  // std::cout << "call optimized ConvertYV12ToRGBa()" << std::endl;
2103  register int U, V, R, G, B, V2, U5, UV;
2104  register int Y0, Y1, Y2, Y3;
2105  unsigned int size = width*height;
2106  unsigned char* iV = yuv + size;
2107  unsigned char* iU = yuv + 5*size/4;
2108  for(unsigned int i = 0; i<height/2; i++)
2109  {
2110  for(unsigned int j = 0; j < width/2 ; j++)
2111  {
2112  U = (int)((*iU++ - 128) * 0.354);
2113  U5 = 5*U;
2114  V = (int)((*iV++ - 128) * 0.707);
2115  V2 = 2*V;
2116  UV = - U - V;
2117  Y0 = *yuv++;
2118  Y1 = *yuv;
2119  yuv = yuv+width-1;
2120  Y2 = *yuv++;
2121  Y3 = *yuv;
2122  yuv = yuv-width+1;
2123 
2124  // Original equations
2125  // R = Y + 1.402 V
2126  // G = Y - 0.344 U - 0.714 V
2127  // B = Y + 1.772 U
2128  R = Y0 + V2;
2129  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2130 
2131  G = Y0 + UV;
2132  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2133 
2134  B = Y0 + U5;
2135  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2136 
2137  *rgba++ = (unsigned char)R;
2138  *rgba++ = (unsigned char)G;
2139  *rgba++ = (unsigned char)B;
2140  *rgba++ = 0;
2141 
2142  //---
2143  R = Y1 + V2;
2144  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2145 
2146  G = Y1 + UV;
2147  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2148 
2149  B = Y1 + U5;
2150  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2151 
2152  *rgba++ = (unsigned char)R;
2153  *rgba++ = (unsigned char)G;
2154  *rgba++ = (unsigned char)B;
2155  *rgba = 0;
2156  rgba = rgba + 4*width-7;
2157 
2158  //---
2159  R = Y2 + V2;
2160  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2161 
2162  G = Y2 + UV;
2163  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2164 
2165  B = Y2 + U5;
2166  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2167 
2168  *rgba++ = (unsigned char)R;
2169  *rgba++ = (unsigned char)G;
2170  *rgba++ = (unsigned char)B;
2171  *rgba++ = 0;
2172 
2173  //---
2174  R = Y3 + V2;
2175  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2176 
2177  G = Y3 + UV;
2178  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2179 
2180  B = Y3 + U5;
2181  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2182 
2183  *rgba++ = (unsigned char)R;
2184  *rgba++ = (unsigned char)G;
2185  *rgba++ = (unsigned char)B;
2186  *rgba = 0;
2187  rgba = rgba -4*width+1;
2188  }
2189  yuv+=width;
2190  rgba+=4*width;
2191  }
2192 }
2199 void vpImageConvert::YV12ToRGB(unsigned char* yuv, unsigned char* rgb,
2200  unsigned int height, unsigned int width)
2201 {
2202  // std::cout << "call optimized ConvertYV12ToRGB()" << std::endl;
2203  register int U, V, R, G, B, V2, U5, UV;
2204  register int Y0, Y1, Y2, Y3;
2205  unsigned int size = width*height;
2206  unsigned char* iV = yuv + size;
2207  unsigned char* iU = yuv + 5*size/4;
2208  for(unsigned int i = 0; i<height/2; i++)
2209  {
2210  for(unsigned int j = 0; j < width/2 ; j++)
2211  {
2212  U = (int)((*iU++ - 128) * 0.354);
2213  U5 = 5*U;
2214  V = (int)((*iV++ - 128) * 0.707);
2215  V2 = 2*V;
2216  UV = - U - V;
2217  Y0 = *yuv++;
2218  Y1 = *yuv;
2219  yuv = yuv+width-1;
2220  Y2 = *yuv++;
2221  Y3 = *yuv;
2222  yuv = yuv-width+1;
2223 
2224  // Original equations
2225  // R = Y + 1.402 V
2226  // G = Y - 0.344 U - 0.714 V
2227  // B = Y + 1.772 U
2228  R = Y0 + V2;
2229  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2230 
2231  G = Y0 + UV;
2232  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2233 
2234  B = Y0 + U5;
2235  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2236 
2237  *rgb++ = (unsigned char)R;
2238  *rgb++ = (unsigned char)G;
2239  *rgb++ = (unsigned char)B;
2240 
2241  //---
2242  R = Y1 + V2;
2243  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2244 
2245  G = Y1 + UV;
2246  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2247 
2248  B = Y1 + U5;
2249  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2250 
2251  *rgb++ = (unsigned char)R;
2252  *rgb++ = (unsigned char)G;
2253  *rgb = (unsigned char)B;
2254  rgb = rgb + 3*width-5;
2255 
2256  //---
2257  R = Y2 + V2;
2258  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2259 
2260  G = Y2 + UV;
2261  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2262 
2263  B = Y2 + U5;
2264  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2265 
2266  *rgb++ = (unsigned char)R;
2267  *rgb++ = (unsigned char)G;
2268  *rgb++ = (unsigned char)B;
2269 
2270  //---
2271  R = Y3 + V2;
2272  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2273 
2274  G = Y3 + UV;
2275  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2276 
2277  B = Y3 + U5;
2278  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2279 
2280  *rgb++ = (unsigned char)R;
2281  *rgb++ = (unsigned char)G;
2282  *rgb = (unsigned char)B;
2283  rgb = rgb -3*width+1;
2284  }
2285  yuv+=width;
2286  rgb+=3*width;
2287  }
2288 }
2289 
2296 void vpImageConvert::YVU9ToRGBa(unsigned char* yuv, unsigned char* rgba,
2297  unsigned int width, unsigned int height)
2298 {
2299  // std::cout << "call optimized ConvertYVU9ToRGBa()" << std::endl;
2300  register int U, V, R, G, B, V2, U5, UV;
2301  register int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2302  unsigned int size = width*height;
2303  unsigned char* iV = yuv + size;
2304  unsigned char* iU = yuv + 17*size/16;
2305  for(unsigned int i = 0; i<height/4; i++)
2306  {
2307  for(unsigned int j = 0; j < width/4 ; j++)
2308  {
2309  U = (int)((*iU++ - 128) * 0.354);
2310  U5 = 5*U;
2311  V = (int)((*iV++ - 128) * 0.707);
2312  V2 = 2*V;
2313  UV = - U - V;
2314  Y0 = *yuv++;
2315  Y1 = *yuv++;
2316  Y2 = *yuv++;
2317  Y3 = *yuv;
2318  yuv = yuv+width-3;
2319  Y4 = *yuv++;
2320  Y5 = *yuv++;
2321  Y6 = *yuv++;
2322  Y7 = *yuv;
2323  yuv = yuv+width-3;
2324  Y8 = *yuv++;
2325  Y9 = *yuv++;
2326  Y10 = *yuv++;
2327  Y11 = *yuv;
2328  yuv = yuv+width-3;
2329  Y12 = *yuv++;
2330  Y13 = *yuv++;
2331  Y14 = *yuv++;
2332  Y15 = *yuv;
2333  yuv = yuv-3*width+1;
2334 
2335  // Original equations
2336  // R = Y + 1.402 V
2337  // G = Y - 0.344 U - 0.714 V
2338  // B = Y + 1.772 U
2339  R = Y0 + V2;
2340  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2341 
2342  G = Y0 + UV;
2343  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2344 
2345  B = Y0 + U5;
2346  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2347 
2348  *rgba++ = (unsigned char)R;
2349  *rgba++ = (unsigned char)G;
2350  *rgba++ = (unsigned char)B;
2351  *rgba++ = 0;
2352 
2353  //---
2354  R = Y1 + V2;
2355  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2356 
2357  G = Y1 + UV;
2358  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2359 
2360  B = Y1 + U5;
2361  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2362 
2363  *rgba++ = (unsigned char)R;
2364  *rgba++ = (unsigned char)G;
2365  *rgba++ = (unsigned char)B;
2366  *rgba++ = 0;
2367 
2368  //---
2369  R = Y2 + V2;
2370  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2371 
2372  G = Y2 + UV;
2373  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2374 
2375  B = Y2 + U5;
2376  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2377 
2378  *rgba++ = (unsigned char)R;
2379  *rgba++ = (unsigned char)G;
2380  *rgba++ = (unsigned char)B;
2381  *rgba++ = 0;
2382 
2383  //---
2384  R = Y3 + V2;
2385  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2386 
2387  G = Y3 + UV;
2388  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2389 
2390  B = Y3 + U5;
2391  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2392 
2393  *rgba++ = (unsigned char)R;
2394  *rgba++ = (unsigned char)G;
2395  *rgba++ = (unsigned char)B;
2396  *rgba = 0;
2397  rgba = rgba + 4*width-15;
2398 
2399  R = Y4 + V2;
2400  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2401 
2402  G = Y4 + UV;
2403  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2404 
2405  B = Y4 + U5;
2406  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2407 
2408  *rgba++ = (unsigned char)R;
2409  *rgba++ = (unsigned char)G;
2410  *rgba++ = (unsigned char)B;
2411  *rgba++ = 0;
2412 
2413  //---
2414  R = Y5 + V2;
2415  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2416 
2417  G = Y5 + UV;
2418  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2419 
2420  B = Y5 + U5;
2421  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2422 
2423  *rgba++ = (unsigned char)R;
2424  *rgba++ = (unsigned char)G;
2425  *rgba++ = (unsigned char)B;
2426  *rgba++ = 0;
2427 
2428  //---
2429  R = Y6 + V2;
2430  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2431 
2432  G = Y6 + UV;
2433  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2434 
2435  B = Y6 + U5;
2436  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2437 
2438  *rgba++ = (unsigned char)R;
2439  *rgba++ = (unsigned char)G;
2440  *rgba++ = (unsigned char)B;
2441  *rgba++ = 0;
2442 
2443  //---
2444  R = Y7 + V2;
2445  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2446 
2447  G = Y7 + UV;
2448  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2449 
2450  B = Y7 + U5;
2451  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2452 
2453  *rgba++ = (unsigned char)R;
2454  *rgba++ = (unsigned char)G;
2455  *rgba++ = (unsigned char)B;
2456  *rgba = 0;
2457  rgba = rgba + 4*width-15;
2458 
2459  R = Y8 + V2;
2460  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2461 
2462  G = Y8 + UV;
2463  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2464 
2465  B = Y8 + U5;
2466  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2467 
2468  *rgba++ = (unsigned char)R;
2469  *rgba++ = (unsigned char)G;
2470  *rgba++ = (unsigned char)B;
2471  *rgba++ = 0;
2472 
2473  //---
2474  R = Y9 + V2;
2475  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2476 
2477  G = Y9 + UV;
2478  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2479 
2480  B = Y9 + U5;
2481  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2482 
2483  *rgba++ = (unsigned char)R;
2484  *rgba++ = (unsigned char)G;
2485  *rgba++ = (unsigned char)B;
2486  *rgba++ = 0;
2487 
2488  //---
2489  R = Y10 + V2;
2490  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2491 
2492  G = Y10 + UV;
2493  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2494 
2495  B = Y10 + U5;
2496  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2497 
2498  *rgba++ = (unsigned char)R;
2499  *rgba++ = (unsigned char)G;
2500  *rgba++ = (unsigned char)B;
2501  *rgba++ = 0;
2502 
2503  //---
2504  R = Y11 + V2;
2505  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2506 
2507  G = Y11 + UV;
2508  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2509 
2510  B = Y11 + U5;
2511  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2512 
2513  *rgba++ = (unsigned char)R;
2514  *rgba++ = (unsigned char)G;
2515  *rgba++ = (unsigned char)B;
2516  *rgba = 0;
2517  rgba = rgba + 4*width-15;
2518 
2519  R = Y12 + V2;
2520  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2521 
2522  G = Y12 + UV;
2523  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2524 
2525  B = Y12 + U5;
2526  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2527 
2528  *rgba++ = (unsigned char)R;
2529  *rgba++ = (unsigned char)G;
2530  *rgba++ = (unsigned char)B;
2531  *rgba++ = 0;
2532 
2533  //---
2534  R = Y13 + V2;
2535  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2536 
2537  G = Y13 + UV;
2538  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2539 
2540  B = Y13 + U5;
2541  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2542 
2543  *rgba++ = (unsigned char)R;
2544  *rgba++ = (unsigned char)G;
2545  *rgba++ = (unsigned char)B;
2546  *rgba++ = 0;
2547 
2548  //---
2549  R = Y14 + V2;
2550  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2551 
2552  G = Y14 + UV;
2553  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2554 
2555  B = Y14 + U5;
2556  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2557 
2558  *rgba++ = (unsigned char)R;
2559  *rgba++ = (unsigned char)G;
2560  *rgba++ = (unsigned char)B;
2561  *rgba++ = 0;
2562 
2563  //---
2564  R = Y15 + V2;
2565  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2566 
2567  G = Y15 + UV;
2568  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2569 
2570  B = Y15 + U5;
2571  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2572 
2573  *rgba++ = (unsigned char)R;
2574  *rgba++ = (unsigned char)G;
2575  *rgba++ = (unsigned char)B;
2576  *rgba = 0;
2577  rgba = rgba -12*width+1;
2578  }
2579  yuv+=3*width;
2580  rgba+=12*width;
2581  }
2582 }
2589 void vpImageConvert::YVU9ToRGB(unsigned char* yuv, unsigned char* rgb,
2590  unsigned int height, unsigned int width)
2591 {
2592  // std::cout << "call optimized ConvertYVU9ToRGB()" << std::endl;
2593  register int U, V, R, G, B, V2, U5, UV;
2594  register int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2595  unsigned int size = width*height;
2596  unsigned char* iV = yuv + size;
2597  unsigned char* iU = yuv + 17*size/16;
2598  for(unsigned int i = 0; i<height/4; i++)
2599  {
2600  for(unsigned int j = 0; j < width/4 ; j++)
2601  {
2602  U = (int)((*iU++ - 128) * 0.354);
2603  U5 = 5*U;
2604  V = (int)((*iV++ - 128) * 0.707);
2605  V2 = 2*V;
2606  UV = - U - V;
2607  Y0 = *yuv++;
2608  Y1 = *yuv++;
2609  Y2 = *yuv++;
2610  Y3 = *yuv;
2611  yuv = yuv+width-3;
2612  Y4 = *yuv++;
2613  Y5 = *yuv++;
2614  Y6 = *yuv++;
2615  Y7 = *yuv;
2616  yuv = yuv+width-3;
2617  Y8 = *yuv++;
2618  Y9 = *yuv++;
2619  Y10 = *yuv++;
2620  Y11 = *yuv;
2621  yuv = yuv+width-3;
2622  Y12 = *yuv++;
2623  Y13 = *yuv++;
2624  Y14 = *yuv++;
2625  Y15 = *yuv;
2626  yuv = yuv-3*width+1;
2627 
2628  // Original equations
2629  // R = Y + 1.402 V
2630  // G = Y - 0.344 U - 0.714 V
2631  // B = Y + 1.772 U
2632  R = Y0 + V2;
2633  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2634 
2635  G = Y0 + UV;
2636  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2637 
2638  B = Y0 + U5;
2639  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2640 
2641  *rgb++ = (unsigned char)R;
2642  *rgb++ = (unsigned char)G;
2643  *rgb++ = (unsigned char)B;
2644 
2645  //---
2646  R = Y1 + V2;
2647  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2648 
2649  G = Y1 + UV;
2650  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2651 
2652  B = Y1 + U5;
2653  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2654 
2655  *rgb++ = (unsigned char)R;
2656  *rgb++ = (unsigned char)G;
2657  *rgb++ = (unsigned char)B;
2658 
2659  //---
2660  R = Y2 + V2;
2661  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2662 
2663  G = Y2 + UV;
2664  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2665 
2666  B = Y2 + U5;
2667  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2668 
2669  *rgb++ = (unsigned char)R;
2670  *rgb++ = (unsigned char)G;
2671  *rgb++ = (unsigned char)B;
2672 
2673  //---
2674  R = Y3 + V2;
2675  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2676 
2677  G = Y3 + UV;
2678  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2679 
2680  B = Y3 + U5;
2681  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2682 
2683  *rgb++ = (unsigned char)R;
2684  *rgb++ = (unsigned char)G;
2685  *rgb = (unsigned char)B;
2686  rgb = rgb + 3*width-11;
2687 
2688  R = Y4 + V2;
2689  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2690 
2691  G = Y4 + UV;
2692  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2693 
2694  B = Y4 + U5;
2695  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2696 
2697  *rgb++ = (unsigned char)R;
2698  *rgb++ = (unsigned char)G;
2699  *rgb++ = (unsigned char)B;
2700 
2701  //---
2702  R = Y5 + V2;
2703  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2704 
2705  G = Y5 + UV;
2706  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2707 
2708  B = Y5 + U5;
2709  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2710 
2711  *rgb++ = (unsigned char)R;
2712  *rgb++ = (unsigned char)G;
2713  *rgb++ = (unsigned char)B;
2714 
2715  //---
2716  R = Y6 + V2;
2717  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2718 
2719  G = Y6 + UV;
2720  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2721 
2722  B = Y6 + U5;
2723  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2724 
2725  *rgb++ = (unsigned char)R;
2726  *rgb++ = (unsigned char)G;
2727  *rgb++ = (unsigned char)B;
2728 
2729  //---
2730  R = Y7 + V2;
2731  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2732 
2733  G = Y7 + UV;
2734  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2735 
2736  B = Y7 + U5;
2737  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2738 
2739  *rgb++ = (unsigned char)R;
2740  *rgb++ = (unsigned char)G;
2741  *rgb = (unsigned char)B;
2742  rgb = rgb + 3*width-11;
2743 
2744  R = Y8 + V2;
2745  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2746 
2747  G = Y8 + UV;
2748  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2749 
2750  B = Y8 + U5;
2751  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2752 
2753  *rgb++ = (unsigned char)R;
2754  *rgb++ = (unsigned char)G;
2755  *rgb++ = (unsigned char)B;
2756 
2757  //---
2758  R = Y9 + V2;
2759  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2760 
2761  G = Y9 + UV;
2762  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2763 
2764  B = Y9 + U5;
2765  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2766 
2767  *rgb++ = (unsigned char)R;
2768  *rgb++ = (unsigned char)G;
2769  *rgb++ = (unsigned char)B;
2770 
2771  //---
2772  R = Y10 + V2;
2773  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2774 
2775  G = Y10 + UV;
2776  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2777 
2778  B = Y10 + U5;
2779  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2780 
2781  *rgb++ = (unsigned char)R;
2782  *rgb++ = (unsigned char)G;
2783  *rgb++ = (unsigned char)B;
2784 
2785  //---
2786  R = Y11 + V2;
2787  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2788 
2789  G = Y11 + UV;
2790  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2791 
2792  B = Y11 + U5;
2793  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2794 
2795  *rgb++ = (unsigned char)R;
2796  *rgb++ = (unsigned char)G;
2797  *rgb = (unsigned char)B;
2798  rgb = rgb + 3*width-11;
2799 
2800  R = Y12 + V2;
2801  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2802 
2803  G = Y12 + UV;
2804  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2805 
2806  B = Y12 + U5;
2807  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2808 
2809  *rgb++ = (unsigned char)R;
2810  *rgb++ = (unsigned char)G;
2811  *rgb++ = (unsigned char)B;
2812 
2813  //---
2814  R = Y13 + V2;
2815  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2816 
2817  G = Y13 + UV;
2818  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2819 
2820  B = Y13 + U5;
2821  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2822 
2823  *rgb++ = (unsigned char)R;
2824  *rgb++ = (unsigned char)G;
2825  *rgb++ = (unsigned char)B;
2826 
2827  //---
2828  R = Y14 + V2;
2829  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2830 
2831  G = Y14 + UV;
2832  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2833 
2834  B = Y14 + U5;
2835  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2836 
2837  *rgb++ = (unsigned char)R;
2838  *rgb++ = (unsigned char)G;
2839  *rgb++ = (unsigned char)B;
2840 
2841  //---
2842  R = Y15 + V2;
2843  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2844 
2845  G = Y15 + UV;
2846  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2847 
2848  B = Y15 + U5;
2849  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2850 
2851  *rgb++ = (unsigned char)R;
2852  *rgb++ = (unsigned char)G;
2853  *rgb++ = (unsigned char)B;
2854  rgb = rgb -9*width+1;
2855  }
2856  yuv+=3*width;
2857  rgb+=9*width;
2858  }
2859 }
2860 
2866 void vpImageConvert::RGBToRGBa(unsigned char* rgb, unsigned char* rgba, unsigned int size)
2867 {
2868  unsigned char *pt_input = rgb;
2869  unsigned char *pt_end = rgb + 3*size;
2870  unsigned char *pt_output = rgba;
2871 
2872  while(pt_input != pt_end) {
2873  *(pt_output++) = *(pt_input++) ; // R
2874  *(pt_output++) = *(pt_input++) ; // G
2875  *(pt_output++) = *(pt_input++) ; // B
2876  *(pt_output++) = 0 ; // A
2877  }
2878 }
2879 
2885 void vpImageConvert::RGBaToRGB(unsigned char* rgba, unsigned char* rgb, unsigned int size)
2886 {
2887  unsigned char *pt_input = rgba;
2888  unsigned char *pt_end = rgba + 4*size;
2889  unsigned char *pt_output = rgb;
2890 
2891  while(pt_input != pt_end) {
2892  *(pt_output++) = *(pt_input++) ; // R
2893  *(pt_output++) = *(pt_input++) ; // G
2894  *(pt_output++) = *(pt_input++) ; // B
2895  pt_input++ ;
2896  }
2897 }
2904 void vpImageConvert::RGBToGrey(unsigned char* rgb, unsigned char* grey, unsigned int size)
2905 {
2906  unsigned char *pt_input = rgb;
2907  unsigned char* pt_end = rgb + size*3;
2908  unsigned char *pt_output = grey;
2909  while(pt_input != pt_end) {
2910  *pt_output = (unsigned char) (0.2126 * (*pt_input)
2911  + 0.7152 * (*(pt_input + 1))
2912  + 0.0722 * (*(pt_input + 2)) );
2913  pt_input += 3;
2914  pt_output ++;
2915  }
2916 }
2924 void vpImageConvert::RGBaToGrey(unsigned char* rgba, unsigned char* grey, unsigned int size)
2925 {
2926  unsigned char *pt_input = rgba;
2927  unsigned char* pt_end = rgba + size*4;
2928  unsigned char *pt_output = grey;
2929 
2930  while(pt_input != pt_end) {
2931  *pt_output = (unsigned char) (0.2126 * (*pt_input)
2932  + 0.7152 * (*(pt_input + 1))
2933  + 0.0722 * (*(pt_input + 2)) );
2934  pt_input += 4;
2935  pt_output ++;
2936  }
2937 }
2938 
2943 void
2944 vpImageConvert::GreyToRGBa(unsigned char* grey, unsigned char* rgba, unsigned int size)
2945 {
2946  unsigned char *pt_input = grey;
2947  unsigned char *pt_end = grey + size;
2948  unsigned char *pt_output = rgba;
2949 
2950  while(pt_input != pt_end) {
2951  unsigned char p = *pt_input ;
2952  *(pt_output ) = p ; // R
2953  *(pt_output + 1) = p ; // G
2954  *(pt_output + 2) = p ; // B
2955  *(pt_output + 3) = p ; // A
2956 
2957  pt_input ++;
2958  pt_output += 4;
2959  }
2960 }
2961 
2966 void
2967 vpImageConvert::GreyToRGB(unsigned char* grey, unsigned char* rgb, unsigned int size)
2968 {
2969  unsigned char *pt_input = grey;
2970  unsigned char* pt_end = grey + size;
2971  unsigned char *pt_output = rgb;
2972 
2973  while(pt_input != pt_end) {
2974  unsigned char p = *pt_input ;
2975  *(pt_output ) = p ; // R
2976  *(pt_output + 1) = p ; // G
2977  *(pt_output + 2) = p ; // B
2978 
2979  pt_input ++;
2980  pt_output += 3;
2981  }
2982 }
2983 
2984 
2990 void
2991 vpImageConvert::BGRToRGBa(unsigned char * bgr, unsigned char * rgba,
2992  unsigned int width, unsigned int height, bool flip)
2993 {
2994  //if we have to flip the image, we start from the end last scanline so the
2995  //step is negative
2996  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
2997 
2998  //starting source address = last line if we need to flip the image
2999  unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
3000  unsigned char * line;
3001 
3002  unsigned int j=0;
3003  unsigned int i=0;
3004 
3005  for(i=0 ; i < height ; i++)
3006  {
3007  line = src;
3008  for( j=0 ; j < width ; j++)
3009  {
3010  *rgba++ = *(line+2);
3011  *rgba++ = *(line+1);
3012  *rgba++ = *(line+0);
3013  *rgba++ = 0;
3014 
3015  line+=3;
3016  }
3017  //go to the next line
3018  src+=lineStep;
3019  }
3020 
3021 }
3022 
3028 void
3029 vpImageConvert::BGRToGrey(unsigned char * bgr, unsigned char * grey,
3030  unsigned int width, unsigned int height, bool flip)
3031 {
3032  //if we have to flip the image, we start from the end last scanline so the
3033  //step is negative
3034  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3035 
3036  //starting source address = last line if we need to flip the image
3037  unsigned char * src = (flip) ? bgr+(width*height*3)+lineStep : bgr;
3038  unsigned char * line;
3039 
3040  unsigned int j=0;
3041  unsigned int i=0;
3042 
3043  for(i=0 ; i < height ; i++)
3044  {
3045  line = src;
3046  for( j=0 ; j < width ; j++)
3047  {
3048  *grey++ = (unsigned char)( 0.2126 * *(line+2)
3049  + 0.7152 * *(line+1)
3050  + 0.0722 * *(line+0)) ;
3051  line+=3;
3052  }
3053 
3054  //go to the next line
3055  src+=lineStep;
3056  }
3057 }
3063 void
3064 vpImageConvert::RGBToRGBa(unsigned char * rgb, unsigned char * rgba,
3065  unsigned int width, unsigned int height, bool flip)
3066 {
3067  //if we have to flip the image, we start from the end last scanline so the
3068  //step is negative
3069  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3070 
3071  //starting source address = last line if we need to flip the image
3072  unsigned char * src = (flip) ? (rgb+(width*height*3)+lineStep) : rgb;
3073  unsigned char * line;
3074 
3075  unsigned int j=0;
3076  unsigned int i=0;
3077 
3078  for(i=0 ; i < height ; i++)
3079  {
3080  line = src;
3081  for( j=0 ; j < width ; j++)
3082  {
3083  *rgba++ = *(line++);
3084  *rgba++ = *(line++);
3085  *rgba++ = *(line++);
3086  *rgba++ = 0;
3087  }
3088  //go to the next line
3089  src+=lineStep;
3090  }
3091 }
3092 
3098 void
3099 vpImageConvert::RGBToGrey(unsigned char * rgb, unsigned char * grey,
3100  unsigned int width, unsigned int height, bool flip)
3101 {
3102  //if we have to flip the image, we start from the end last scanline so the
3103  //step is negative
3104  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3105 
3106  //starting source address = last line if we need to flip the image
3107  unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3108  unsigned char * line;
3109 
3110  unsigned int j=0;
3111  unsigned int i=0;
3112 
3113  unsigned r,g,b;
3114 
3115  for(i=0 ; i < height ; i++)
3116  {
3117  line = src;
3118  for( j=0 ; j < width ; j++)
3119  {
3120  r = *(line++);
3121  g = *(line++);
3122  b = *(line++);
3123  *grey++ = (unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3124  }
3125 
3126  //go to the next line
3127  src+=lineStep;
3128  }
3129 }
3130 
3136 void vpImageConvert::computeYCbCrLUT()
3137 {
3138  if (YCbCrLUTcomputed == false) {
3139  int index = 256, aux;
3140 
3141  while (index-- ) {
3142 
3143  aux = index - 128;
3144  vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3145  vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3146  vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3147  vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3148  }
3149 
3150  YCbCrLUTcomputed = true;
3151  }
3152 }
3153 
3154 
3174 void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size)
3175 {
3176  unsigned char *cbv;
3177  unsigned char *crv;
3178  unsigned char *pt_ycbcr = ycbcr;
3179  unsigned char *pt_rgb = rgb;
3180  cbv = pt_ycbcr + 1;
3181  crv = pt_ycbcr + 3;
3182 
3183  vpImageConvert::computeYCbCrLUT();
3184 
3185  int col = 0;
3186 
3187  while (size--) {
3188  register int val_r, val_g, val_b;
3189  if (!(col++ % 2)) {
3190  cbv = pt_ycbcr + 1;
3191  crv = pt_ycbcr + 3;
3192  }
3193 
3194  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3195  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3196  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3197 
3198  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3199 
3200  *pt_rgb++ = (val_r < 0) ? 0u :
3201  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3202  *pt_rgb++ = (val_g < 0) ? 0u :
3203  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3204  *pt_rgb++ = (val_b < 0) ? 0u :
3205  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3206 
3207  pt_ycbcr += 2;
3208  }
3209 }
3210 
3232 void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsigned int size)
3233 {
3234  unsigned char *cbv;
3235  unsigned char *crv;
3236  unsigned char *pt_ycbcr = ycbcr;
3237  unsigned char *pt_rgba = rgba;
3238  cbv = pt_ycbcr + 1;
3239  crv = pt_ycbcr + 3;
3240 
3241  vpImageConvert::computeYCbCrLUT();
3242 
3243  int col = 0;
3244 
3245  while (size--) {
3246  register int val_r, val_g, val_b;
3247  if (!(col++ % 2)) {
3248  cbv = pt_ycbcr + 1;
3249  crv = pt_ycbcr + 3;
3250  }
3251 
3252  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3253  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3254  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3255 
3256  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3257 
3258  *pt_rgba++ = (val_r < 0) ? 0u :
3259  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3260  *pt_rgba++ = (val_g < 0) ? 0u :
3261  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3262  *pt_rgba++ = (val_b < 0) ? 0u :
3263  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3264  *pt_rgba++ = 0;
3265 
3266  pt_ycbcr += 2;
3267  }
3268 }
3269 
3270 
3287 void vpImageConvert::YCbCrToGrey(unsigned char* yuv, unsigned char* grey, unsigned int size)
3288 {
3289  unsigned int i=0,j=0;
3290 
3291  while( j < size*2)
3292  {
3293  grey[i++] = yuv[j];
3294  grey[i++] = yuv[j+2];
3295  j+=4;
3296  }
3297 }
3298 
3317 void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsigned int size)
3318 {
3319  unsigned char *cbv;
3320  unsigned char *crv;
3321  unsigned char *pt_ycbcr = ycrcb;
3322  unsigned char *pt_rgb = rgb;
3323  crv = pt_ycbcr + 1;
3324  cbv = pt_ycbcr + 3;
3325 
3326  vpImageConvert::computeYCbCrLUT();
3327 
3328  int col = 0;
3329 
3330  while (size--) {
3331  register int val_r, val_g, val_b;
3332  if (!(col++ % 2)) {
3333  crv = pt_ycbcr + 1;
3334  cbv = pt_ycbcr + 3;
3335  }
3336 
3337  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3338  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3339  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3340 
3341  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3342 
3343  *pt_rgb++ = (val_r < 0) ? 0u :
3344  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3345  *pt_rgb++ = (val_g < 0) ? 0u :
3346  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3347  *pt_rgb++ = (val_b < 0) ? 0u :
3348  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3349 
3350  pt_ycbcr += 2;
3351  }
3352 }
3373 void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsigned int size)
3374 {
3375  unsigned char *cbv;
3376  unsigned char *crv;
3377  unsigned char *pt_ycbcr = ycrcb;
3378  unsigned char *pt_rgba = rgba;
3379  crv = pt_ycbcr + 1;
3380  cbv = pt_ycbcr + 3;
3381 
3382  vpImageConvert::computeYCbCrLUT();
3383 
3384  int col = 0;
3385 
3386  while (size--) {
3387  register int val_r, val_g, val_b;
3388  if (!(col++ % 2)) {
3389  crv = pt_ycbcr + 1;
3390  cbv = pt_ycbcr + 3;
3391  }
3392 
3393  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3394  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3395  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3396 
3397  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3398 
3399  *pt_rgba++ = (val_r < 0) ? 0u :
3400  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3401  *pt_rgba++ = (val_g < 0) ? 0u :
3402  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3403  *pt_rgba++ = (val_b < 0) ? 0u :
3404  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3405  *pt_rgba++ = 0;
3406 
3407  pt_ycbcr += 2;
3408  }
3409 }
3410 
3451 {
3452  register size_t n = src.getNumberOfPixel();
3453  unsigned int height = src.getHeight();
3454  unsigned int width = src.getWidth();
3455  unsigned char* input;
3456  unsigned char* dst ;
3457 
3458  vpImage<unsigned char>* tabChannel[4];
3459 
3460 /* incrsrc[0] = 0; //init
3461  incrsrc[1] = 0; //step after the first used channel
3462  incrsrc[2] = 0; //step after the second used channel
3463  incrsrc[3] = 0;
3464  incrsrc[4] = 0;
3465  */
3466  tabChannel[0] = pR;
3467  tabChannel[1] = pG;
3468  tabChannel[2] = pB;
3469  tabChannel[3] = pa;
3470 
3471  register size_t i; /* ordre */
3472  for(unsigned int j = 0;j < 4;j++){
3473  if(tabChannel[j]!=NULL){
3474  if(tabChannel[j]->getHeight() != height ||
3475  tabChannel[j]->getWidth() != width){
3476  tabChannel[j]->resize(height,width);
3477  }
3478  dst = (unsigned char*)tabChannel[j]->bitmap;
3479 
3480  input = (unsigned char*)src.bitmap+j;
3481  i = 0;
3482 #if 1 //optimization
3483  if (n >= 4) { /* boucle deroulee lsize fois */
3484  n -= 3;
3485  for (; i < n; i += 4) {
3486  *dst = *input; input += 4; dst++;
3487  *dst = *input; input += 4; dst++;
3488  *dst = *input; input += 4; dst++;
3489  *dst = *input; input += 4; dst++;
3490  }
3491  n += 3;
3492  }
3493 #endif
3494  for (; i < n; i++) {
3495  *dst = *input; input += 4; dst ++;
3496  }
3497  }
3498  }
3499 }
3500 
3511 void vpImageConvert::MONO16ToGrey(unsigned char *grey16, unsigned char *grey, unsigned int size)
3512 {
3513  register int i = (((int)size)<<1)-1;
3514  register int j = (int)size-1;
3515  register int y;
3516 
3517  while (i >= 0) {
3518  y = grey16[i--];
3519  grey[j--] = static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3520  }
3521 }
3522 
3533 void vpImageConvert::MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba, unsigned int size)
3534 {
3535  register int i = (((int)size)<<1)-1;
3536  register int j = (int)(size*4-1);
3537  register int y;
3538  register unsigned char v;
3539 
3540  while (i >= 0) {
3541  y = grey16[i--];
3542  v = static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3543  rgba[j--] = 0;
3544  rgba[j--] = v;
3545  rgba[j--] = v;
3546  rgba[j--] = v;
3547  }
3548 }
3549 
3550 /*
3551  * Local variables:
3552  * c-basic-offset: 2
3553  * End:
3554  */
unsigned int getCols() const
Definition: vpImage.h:180
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
#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:161
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:688
unsigned char B
Blue component.
Definition: vpRGBa.h:148
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
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:171
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:214
void resize(const unsigned int h, const unsigned int w)
set the size of the image without initializing it.
Definition: vpImage.h:536
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
unsigned int getHeight() const
Definition: vpImage.h:152
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 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)