ViSP  2.8.0
vpImageConvert.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImageConvert.cpp 4323 2013-07-18 09:24:01Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  vpImage<vpRGBa> & dest)
70 {
71  dest.resize(src.getHeight(), src.getWidth()) ;
72 
73  GreyToRGBa(src.bitmap, (unsigned char *)dest.bitmap,
74  src.getHeight() * src.getWidth() );
75 }
76 
82 void
85 {
86  dest.resize(src.getHeight(), src.getWidth()) ;
87 
88  RGBaToGrey((unsigned char *)src.bitmap, dest.bitmap,
89  src.getHeight() * src.getWidth() );
90 }
91 
92 
98 void
101 {
102  dest.resize(src.getHeight(), src.getWidth()) ;
103  unsigned int max_xy = src.getWidth()*src.getHeight();
104  float min, max;
105 
106  src.getMinMaxValue(min,max);
107 
108  for (unsigned int i = 0; i < max_xy; i++) {
109  float val = 255.f * (src.bitmap[i] - min) / (max - min);
110  if(val < 0)
111  dest.bitmap[i] = 0;
112  else if(val > 255)
113  dest.bitmap[i] = 255;
114  else
115  dest.bitmap[i] = (int)val;
116  }
117 }
118 
124 void
126  vpImage<float> &dest)
127 {
128  dest.resize(src.getHeight(), src.getWidth()) ;
129  for (unsigned int i = 0; i < src.getHeight()*src.getWidth(); i++)
130  dest.bitmap[i] = (float)src.bitmap[i];
131 }
132 
138 void
141 {
142  dest.resize(src.getHeight(), src.getWidth()) ;
143  unsigned int max_xy = src.getWidth()*src.getHeight();
144  double min, max;
145 
146  src.getMinMaxValue(min,max);
147 
148  for (unsigned int i = 0; i < max_xy; i++) {
149  double val = 255. * (src.bitmap[i] - min) / (max - min);
150  if(val < 0)
151  dest.bitmap[i] = 0;
152  else if(val > 255)
153  dest.bitmap[i] = 255;
154  else
155  dest.bitmap[i] = (int)val;
156  }
157 }
158 
164 void
166  vpImage<double> &dest)
167 {
168  dest.resize(src.getHeight(), src.getWidth()) ;
169  for (unsigned int i = 0; i < src.getHeight()*src.getWidth(); i++)
170  dest.bitmap[i] = (double)src.bitmap[i];
171 }
172 
173 #ifdef VISP_HAVE_OPENCV
174 
214 void
215 vpImageConvert::convert(const IplImage* src, vpImage<vpRGBa> & dest, bool flip)
216 {
217  int nChannel = src->nChannels;
218  int depth = src->depth;
219  int height = src->height;
220  int width = src->width;
221  int widthStep = src->widthStep;
222  int lineStep = (flip) ? 1 : 0;
223 
224  if(nChannel == 3 && depth == 8){
225  dest.resize((unsigned int)height, (unsigned int)width);
226 
227  //starting source address
228  unsigned char* input = (unsigned char*)src->imageData;
229  unsigned char* line;
230  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
231  unsigned char* output = NULL;
232 
233  for(int i=0 ; i < height ; i++)
234  {
235  line = input;
236  output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
237  for(int j=0 ; j < width ; j++)
238  {
239  *(output++) = *(line+2);
240  *(output++) = *(line+1);
241  *(output++) = *(line);
242  *(output++) = 0;
243 
244  line+=3;
245  }
246  //go to the next line
247  input+=widthStep;
248  }
249  }
250  else if(nChannel == 1 && depth == 8 ){
251  dest.resize((unsigned int)height, (unsigned int)width);
252  //starting source address
253  unsigned char * input = (unsigned char*)src->imageData;
254  unsigned char * line;
255  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
256  unsigned char* output = NULL;
257 
258  for(int i=0 ; i < height ; i++)
259  {
260  line = input;
261  output = beginOutput + lineStep * ( 4 * width * ( height - 1 - i ) ) + (1-lineStep) * 4 * width * i;
262  for(int j=0 ; j < width ; j++)
263  {
264  *output++ = *(line);
265  *output++ = *(line);
266  *output++ = *(line);
267  *output++ = *(line);;
268 
269  line++;
270  }
271  //go to the next line
272  input+=widthStep;
273  }
274  }
275 }
276 
317 void
318 vpImageConvert::convert(const IplImage* src,
319  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  unsigned char* beginOutput = (unsigned char*)dest.bitmap;
362  dest.resize((unsigned int)height, (unsigned int)width) ;
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 
419 void
420 vpImageConvert::convert(const vpImage<vpRGBa> & src, IplImage *&dest)
421 {
422  int height = (int)src.getHeight();
423  int width = (int)src.getWidth();
424  CvSize size = cvSize(width, height);
425  int depth = 8;
426  int channels = 3;
427  if (dest != NULL){
428  if(dest->nChannels != channels || dest->depth != depth
429  || dest->height != height || dest->width != width){
430  if(dest->nChannels != 0) cvReleaseImage(&dest);
431  dest = cvCreateImage( size, depth, channels );
432  }
433  }
434  else dest = cvCreateImage( size, depth, channels );
435 
436 
437  //starting source address
438  unsigned char * input = (unsigned char*)src.bitmap;//rgba image
439  unsigned char * line;
440  unsigned char * output = (unsigned char*)dest->imageData;//bgr image
441 
442  int j=0;
443  int i=0;
444  int widthStep = dest->widthStep;
445 
446  for(i=0 ; i < height ; i++)
447  {
448  output = (unsigned char*)dest->imageData + i*widthStep;
449  line = input;
450  for( j=0 ; j < width ; j++)
451  {
452  *output++ = *(line+2); //B
453  *output++ = *(line+1); //G
454  *output++ = *(line); //R
455 
456  line+=4;
457  }
458  //go to the next line
459  input+=4*width;
460  }
461 }
462 
504 void
506  IplImage* &dest)
507 {
508  unsigned int height = src.getHeight();
509  unsigned int width = src.getWidth();
510  CvSize size = cvSize((int)width, (int)height);
511  int depth = 8;
512  int channels = 1;
513  if (dest != NULL){
514  if(dest->nChannels != channels || dest->depth != depth
515  || dest->height != (int) height || dest->width != (int) width){
516  if(dest->nChannels != 0) cvReleaseImage(&dest);
517  dest = cvCreateImage( size, depth, channels );
518  }
519  }
520  else dest = cvCreateImage( size, depth, channels );
521 
522  unsigned int widthStep = (unsigned int)dest->widthStep;
523 
524  if ( width == widthStep){
525  memcpy(dest->imageData,src.bitmap, width*height);
526  }
527  else{
528  //copying each line taking account of the widthStep
529  for (unsigned int i =0 ; i < height ; i++){
530  memcpy(dest->imageData + i*widthStep, src.bitmap + i*width,
531  width);
532  }
533  }
534 }
535 
536 #if VISP_HAVE_OPENCV_VERSION >= 0x020100
537 
579 void
580 vpImageConvert::convert(const cv::Mat& src,
581  vpImage<vpRGBa>& dest, const bool flip)
582 {
583  if(src.type() == CV_8UC4){
584  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
585  vpRGBa rgbaVal;
586  for(unsigned int i=0; i<dest.getRows(); ++i)
587  for(unsigned int j=0; j<dest.getCols(); ++j){
588  cv::Vec4b tmp = src.at<cv::Vec4b>((int)i, (int)j);
589  rgbaVal.R = tmp[2];
590  rgbaVal.G = tmp[1];
591  rgbaVal.B = tmp[0];
592  rgbaVal.A = tmp[3];
593  if(flip)
594  dest[dest.getRows()-i-1][j] = rgbaVal;
595  else
596  dest[i][j] = rgbaVal;
597  }
598  }else if(src.type() == CV_8UC3){
599  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
600  vpRGBa rgbaVal;
601  rgbaVal.A = 0;
602  for(unsigned int i=0; i<dest.getRows(); ++i){
603  for(unsigned int j=0; j<dest.getCols(); ++j){
604  cv::Vec3b tmp = src.at<cv::Vec3b>((int)i, (int)j);
605  rgbaVal.R = tmp[2];
606  rgbaVal.G = tmp[1];
607  rgbaVal.B = tmp[0];
608  if(flip){
609  dest[dest.getRows()-i-1][j] = rgbaVal;
610  }else{
611  dest[i][j] = rgbaVal;
612  }
613  }
614  }
615  }else if(src.type() == CV_8UC1){
616  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
617  vpRGBa rgbaVal;
618  for(unsigned int i=0; i<dest.getRows(); ++i){
619  for(unsigned int j=0; j<dest.getCols(); ++j){
620  rgbaVal = src.at<unsigned char>((int)i, (int)j);
621  if(flip){
622  dest[dest.getRows()-i-1][j] = rgbaVal;
623  }else{
624  dest[i][j] = rgbaVal;
625  }
626  }
627  }
628  }
629 }
630 
673 void
674 vpImageConvert::convert(const cv::Mat& src,
675  vpImage<unsigned char>& dest, const bool flip)
676 {
677  if(src.type() == CV_8UC1){
678  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
679  if(src.isContinuous() && !flip){
680  memcpy(dest.bitmap, src.data, (size_t)(src.rows*src.cols));
681  }
682  else{
683  if(flip){
684  for(unsigned int i=0; i<dest.getRows(); ++i){
685  memcpy(dest.bitmap+i*dest.getCols(), src.data+(dest.getRows()-i-1)*src.step1(), (size_t)src.step);
686  }
687  }else{
688  for(unsigned int i=0; i<dest.getRows(); ++i){
689  memcpy(dest.bitmap+i*dest.getCols(), src.data+i*src.step1(), (size_t)src.step);
690  }
691  }
692  }
693  }else if(src.type() == CV_8UC3){
694  dest.resize((unsigned int)src.rows, (unsigned int)src.cols);
695  if(src.isContinuous() && !flip){
696  BGRToGrey((unsigned char*)src.data, (unsigned char*)dest.bitmap, (unsigned int)src.cols, (unsigned int)src.rows, flip);
697  }
698  else{
699  if(flip){
700  for(unsigned int i=0; i<dest.getRows(); ++i){
701  BGRToGrey((unsigned char*)src.data+i*src.step1(),
702  (unsigned char*)dest.bitmap+(dest.getRows()-i-1)*dest.getCols(),
703  (unsigned int)dest.getCols(), 1, false);
704  }
705  }else{
706  for(unsigned int i=0; i<dest.getRows(); ++i){
707  BGRToGrey((unsigned char*)src.data+i*src.step1(),
708  (unsigned char*)dest.bitmap+i*dest.getCols(),
709  (unsigned int)dest.getCols(), 1, false);
710  }
711  }
712  }
713  }
714 }
715 
716 
756 void
758  cv::Mat& dest)
759 {
760  cv::Mat vpToMat((int)src.getRows(), (int)src.getCols(), CV_8UC4, (void*)src.bitmap);
761 
762  dest = cv::Mat((int)src.getRows(), (int)src.getCols(), CV_8UC3);
763  cv::Mat alpha((int)src.getRows(), (int)src.getCols(), CV_8UC1);
764 
765  cv::Mat out[] = {dest, alpha};
766  int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
767  cv::mixChannels(&vpToMat, 1, out, 2, from_to, 4);
768 }
769 
811 void
813  cv::Mat& dest, const bool copyData)
814 {
815  if(copyData){
816  cv::Mat tmpMap((int)src.getRows(), (int)src.getCols(), CV_8UC1, (void*)src.bitmap);
817  dest = tmpMap.clone();
818  }else{
819  dest = cv::Mat((int)src.getRows(), (int)src.getCols(), CV_8UC1, (void*)src.bitmap);
820  }
821 }
822 
823 #endif
824 #endif
825 
826 #ifdef VISP_HAVE_YARP
827 
860  yarp::sig::ImageOf< yarp::sig::PixelMono > *dest, const bool copyData)
861 {
862  if(copyData)
863  {
864  dest->resize(src.getWidth(),src.getHeight());
865  memcpy(dest->getRawImage(), src.bitmap, src.getHeight()*src.getWidth());
866  }
867  else
868  dest->setExternal(src.bitmap, (int)src.getCols(), (int)src.getRows());
869 }
870 
907 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelMono > *src,
908  vpImage<unsigned char> & dest,const bool copyData )
909 {
910  dest.resize(src->height(),src->width());
911  if(copyData)
912  memcpy(dest.bitmap, src->getRawImage(), src->height()*src->width()*sizeof(yarp::sig::PixelMono));
913  else
914  dest.bitmap = src->getRawImage();
915 }
916 
951  yarp::sig::ImageOf< yarp::sig::PixelRgba > *dest, const bool copyData)
952 {
953  if(copyData){
954  dest->resize(src.getWidth(),src.getHeight());
955  memcpy(dest->getRawImage(), src.bitmap, src.getHeight()*src.getWidth()*sizeof(vpRGBa));
956  }
957  else
958  dest->setExternal(src.bitmap, (int)src.getCols(), (int)src.getRows());
959 }
960 
998 void vpImageConvert::convert(const yarp::sig::ImageOf< yarp::sig::PixelRgba > *src,
999  vpImage<vpRGBa> & dest,const bool copyData)
1000 {
1001  dest.resize(src->height(),src->width());
1002  if(copyData)
1003  memcpy(dest.bitmap, src->getRawImage(),src->height()*src->width()*sizeof(yarp::sig::PixelRgba));
1004  else
1005  dest.bitmap = (vpRGBa*)src->getRawImage();
1006 }
1007 
1041  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,
1090  vpImage<vpRGBa> & dest)
1091 {
1092  dest.resize(src->height(),src->width());
1093  for(int i = 0 ; i < src->height() ; i++){
1094  for(int j = 0 ; j < src->width() ; j++){
1095  dest[i][j].R = src->pixel(j,i).r;
1096  dest[i][j].G = src->pixel(j,i).g;
1097  dest[i][j].B = src->pixel(j,i).b;
1098  dest[i][j].A = 0;
1099  }
1100  }
1101 }
1102 
1103 #endif
1104 
1105 #if defined(VISP_HAVE_LIBJPEG)
1106 #if JPEG_LIB_VERSION > 70
1107 
1115 void vpImageConvert::convertToJPEGBuffer(const vpImage<unsigned char> &src,
1116  unsigned char **dest, long unsigned int &destSize, int quality)
1117 {
1118  struct jpeg_compress_struct cinfo;
1119  struct jpeg_error_mgr jerr;
1120 
1121  cinfo.err = jpeg_std_error(&jerr);
1122  jpeg_create_compress(&cinfo);
1123 
1124  *dest = NULL;
1125  destSize = 0;
1126 
1127  jpeg_mem_dest(&cinfo, dest, &destSize);
1128 
1129  unsigned int width = src.getWidth();
1130  unsigned int height = src.getHeight();
1131 
1132  cinfo.image_width = width;
1133  cinfo.image_height = height;
1134  cinfo.input_components = 1;
1135  cinfo.in_color_space = JCS_GRAYSCALE;
1136  jpeg_set_defaults(&cinfo);
1137  jpeg_set_quality(&cinfo, quality, TRUE);
1138 
1139  jpeg_start_compress(&cinfo,TRUE);
1140 
1141  unsigned char *line;
1142  line = new unsigned char[width];
1143  unsigned char* input = (unsigned char*)src.bitmap;
1144  while (cinfo.next_scanline < cinfo.image_height)
1145  {
1146  for (unsigned int i = 0; i < width; i++)
1147  {
1148  line[i] = *(input);
1149  input++;
1150  }
1151  jpeg_write_scanlines(&cinfo, &line, 1);
1152  }
1153 
1154  jpeg_finish_compress(&cinfo);
1155  jpeg_destroy_compress(&cinfo);
1156  delete [] line;
1157 }
1158 
1166 void vpImageConvert::convertToJPEGBuffer(unsigned char *src, long unsigned int srcSize,
1167  vpImage<unsigned char> &dest)
1168 {
1169  struct jpeg_decompress_struct cinfo;
1170  struct jpeg_error_mgr jerr;
1171 
1172  cinfo.err = jpeg_std_error(&jerr);
1173  jpeg_create_decompress(&cinfo);
1174 
1175  jpeg_mem_src(&cinfo, src, srcSize);
1176  jpeg_read_header(&cinfo, TRUE);
1177 
1178  unsigned int width = cinfo.image_width;
1179  unsigned int height = cinfo.image_height;
1180 
1181  if ( (width != dest.getWidth()) || (height != dest.getHeight()) )
1182  dest.resize(height,width);
1183 
1184  jpeg_start_decompress(&cinfo);
1185 
1186  unsigned int rowbytes = cinfo.output_width * (unsigned int)(cinfo.output_components);
1187  JSAMPARRAY buf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, rowbytes, 1);
1188 
1189  if (cinfo.out_color_space == JCS_GRAYSCALE)
1190  {
1191  unsigned int row;
1192  while (cinfo.output_scanline<cinfo.output_height)
1193  {
1194  row = cinfo.output_scanline;
1195  jpeg_read_scanlines(&cinfo,buf,1);
1196  memcpy(dest[row], buf[0], rowbytes);
1197  }
1198  }
1199 
1200  jpeg_finish_decompress(&cinfo);
1201  jpeg_destroy_decompress(&cinfo);
1202 }
1203 #endif
1204 #endif // defined(VISP_HAVE_LIBJPEG)
1205 
1206 
1207 #define vpSAT(c) \
1208  if (c & (~255)) { if (c < 0) c = 0; else c = 255; }
1209 
1215 void vpImageConvert::YUYVToRGBa(unsigned char* yuyv, unsigned char* rgba,
1216  unsigned int width, unsigned int height)
1217 {
1218  unsigned char *s;
1219  unsigned char *d;
1220  int w, h, c;
1221  int r, g, b, cr, cg, cb, y1, y2;
1222 
1223  h = (int)height;
1224  w = (int)width;
1225  s = yuyv;
1226  d = rgba;
1227  while (h--) {
1228  c = w >> 1;
1229  while (c--) {
1230  y1 = *s++;
1231  cb = ((*s - 128) * 454) >> 8;
1232  cg = (*s++ - 128) * 88;
1233  y2 = *s++;
1234  cr = ((*s - 128) * 359) >> 8;
1235  cg = (cg + (*s++ - 128) * 183) >> 8;
1236 
1237  r = y1 + cr;
1238  b = y1 + cb;
1239  g = y1 - cg;
1240  vpSAT(r);
1241  vpSAT(g);
1242  vpSAT(b);
1243 
1244  *d++ = static_cast<unsigned char>(r);
1245  *d++ = static_cast<unsigned char>(g);
1246  *d++ = static_cast<unsigned char>(b);
1247  *d++ = 0;
1248 
1249  r = y2 + cr;
1250  b = y2 + cb;
1251  g = y2 - cg;
1252  vpSAT(r);
1253  vpSAT(g);
1254  vpSAT(b);
1255 
1256  *d++ = static_cast<unsigned char>(r);
1257  *d++ = static_cast<unsigned char>(g);
1258  *d++ = static_cast<unsigned char>(b);
1259  *d++ = 0;
1260 
1261  }
1262  }
1263 }
1271 void vpImageConvert::YUYVToRGB(unsigned char* yuyv, unsigned char* rgb,
1272  unsigned int width, unsigned int height)
1273 {
1274  unsigned char *s;
1275  unsigned char *d;
1276  int h, w, c;
1277  int r, g, b, cr, cg, cb, y1, y2;
1278 
1279  h = (int)height;
1280  w = (int)width;
1281  s = yuyv;
1282  d = rgb;
1283  while (h--) {
1284  c = w >> 1;
1285  while (c--) {
1286  y1 = *s++;
1287  cb = ((*s - 128) * 454) >> 8;
1288  cg = (*s++ - 128) * 88;
1289  y2 = *s++;
1290  cr = ((*s - 128) * 359) >> 8;
1291  cg = (cg + (*s++ - 128) * 183) >> 8;
1292 
1293  r = y1 + cr;
1294  b = y1 + cb;
1295  g = y1 - cg;
1296  vpSAT(r);
1297  vpSAT(g);
1298  vpSAT(b);
1299 
1300  *d++ = static_cast<unsigned char>(r);
1301  *d++ = static_cast<unsigned char>(g);
1302  *d++ = static_cast<unsigned char>(b);
1303 
1304  r = y2 + cr;
1305  b = y2 + cb;
1306  g = y2 - cg;
1307  vpSAT(r);
1308  vpSAT(g);
1309  vpSAT(b);
1310 
1311  *d++ = static_cast<unsigned char>(r);
1312  *d++ = static_cast<unsigned char>(g);
1313  *d++ = static_cast<unsigned char>(b);
1314  }
1315  }
1316 }
1324 void vpImageConvert::YUYVToGrey(unsigned char* yuyv, unsigned char* grey,
1325  unsigned int size)
1326 {
1327  unsigned int i=0,j=0;
1328 
1329  while( j < size*2)
1330  {
1331  grey[i++] = yuyv[j];
1332  grey[i++] = yuyv[j+2];
1333  j+=4;
1334  }
1335 }
1336 
1337 
1344 void vpImageConvert::YUV411ToRGBa(unsigned char* yuv,
1345  unsigned char* rgba,
1346  unsigned int size)
1347 {
1348 #if 1
1349  // std::cout << "call optimized ConvertYUV411ToRGBa()" << std::endl;
1350  register int U, V, R, G, B, V2, U5, UV;
1351  register int Y0, Y1, Y2, Y3;
1352  for(unsigned int i = size / 4; i; i--) {
1353  U = (int)((*yuv++ - 128) * 0.354);
1354  U5 = 5*U;
1355  Y0 = *yuv++;
1356  Y1 = *yuv++;
1357  V = (int)((*yuv++ - 128) * 0.707);
1358  V2 = 2*V;
1359  Y2 = *yuv++;
1360  Y3 = *yuv++;
1361  UV = - U - V;
1362 
1363  // Original equations
1364  // R = Y + 1.402 V
1365  // G = Y - 0.344 U - 0.714 V
1366  // B = Y + 1.772 U
1367  R = Y0 + V2;
1368  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1369 
1370  G = Y0 + UV;
1371  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1372 
1373  B = Y0 + U5;
1374  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1375 
1376  *rgba++ = (unsigned char)R;
1377  *rgba++ = (unsigned char)G;
1378  *rgba++ = (unsigned char)B;
1379  rgba++;
1380 
1381  //---
1382  R = Y1 + V2;
1383  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1384 
1385  G = Y1 + UV;
1386  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1387 
1388  B = Y1 + U5;
1389  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1390 
1391  *rgba++ = (unsigned char)R;
1392  *rgba++ = (unsigned char)G;
1393  *rgba++ = (unsigned char)B;
1394  rgba++;
1395 
1396  //---
1397  R = Y2 + V2;
1398  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1399 
1400  G = Y2 + UV;
1401  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1402 
1403  B = Y2 + U5;
1404  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1405 
1406  *rgba++ = (unsigned char)R;
1407  *rgba++ = (unsigned char)G;
1408  *rgba++ = (unsigned char)B;
1409  rgba++;
1410 
1411  //---
1412  R = Y3 + V2;
1413  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1414 
1415  G = Y3 + UV;
1416  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1417 
1418  B = Y3 + U5;
1419  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1420 
1421  *rgba++ = (unsigned char)R;
1422  *rgba++ = (unsigned char)G;
1423  *rgba++ = (unsigned char)B;
1424  rgba++;
1425  }
1426 #else
1427  // tres tres lent ....
1428  unsigned int i=0,j=0;
1429  unsigned char r, g, b;
1430  while( j < numpixels*3/2)
1431  {
1432 
1433  YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1434  rgba[i] = r;
1435  rgba[i+1] = g;
1436  rgba[i+2] = b;
1437  rgba[i+3] = 0;
1438  i+=4;
1439 
1440  YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1441  rgba[i] = r;
1442  rgba[i+1] = g;
1443  rgba[i+2] = b;
1444  rgba[i+3] = 0;
1445  i+=4;
1446 
1447  YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1448  rgba[i] = r;
1449  rgba[i+1] = g;
1450  rgba[i+2] = b;
1451  rgba[i+3] = 0;
1452  i+=4;
1453 
1454  YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1455  rgba[i] = r;
1456  rgba[i+1] = g;
1457  rgba[i+2] = b;
1458  rgba[i+3] = 0;
1459  i+=4;
1460 
1461  j+=6;
1462  }
1463 #endif
1464 
1465 }
1466 
1473 void vpImageConvert::YUV422ToRGBa(unsigned char* yuv,
1474  unsigned char* rgba,
1475  unsigned int size)
1476 {
1477 
1478 #if 1
1479  // std::cout << "call optimized convertYUV422ToRGBa()" << std::endl;
1480  register int U, V, R, G, B, V2, U5, UV;
1481  register int Y0, Y1;
1482  for( unsigned int i = size / 2; i; i-- ) {
1483  U = (int)((*yuv++ - 128) * 0.354);
1484  U5 = 5*U;
1485  Y0 = *yuv++;
1486  V = (int)((*yuv++ - 128) * 0.707);
1487  V2 = 2*V;
1488  Y1 = *yuv++;
1489  UV = - U - V;
1490 
1491  //---
1492  R = Y0 + V2;
1493  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1494 
1495  G = Y0 + UV;
1496  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1497 
1498  B = Y0 + U5;
1499  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1500 
1501  *rgba++ = (unsigned char)R;
1502  *rgba++ = (unsigned char)G;
1503  *rgba++ = (unsigned char)B;
1504  rgba++;
1505 
1506  //---
1507  R = Y1 + V2;
1508  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1509 
1510  G = Y1 + UV;
1511  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1512 
1513  B = Y1 + U5;
1514  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1515 
1516  *rgba++ = (unsigned char)R;
1517  *rgba++ = (unsigned char)G;
1518  *rgba++ = (unsigned char)B;
1519  rgba++;
1520  }
1521 
1522 #else
1523  // tres tres lent ....
1524  unsigned int i=0,j=0;
1525  unsigned char r, g, b;
1526 
1527  while( j < size*2)
1528  {
1529 
1530  YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1531  rgba[i] = r;
1532  rgba[i+1] = g;
1533  rgba[i+2] = b;
1534  rgba[i+3] = 0;
1535  i+=4;
1536 
1537  YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1538  rgba[i] = r;
1539  rgba[i+1] = g;
1540  rgba[i+2] = b;
1541  rgba[i+3] = 0;
1542  i+=4;
1543  j+=4;
1544 
1545  }
1546 #endif
1547 }
1548 
1555 void vpImageConvert::YUV411ToGrey(unsigned char* yuv,
1556  unsigned char* grey,
1557  unsigned int size)
1558 {
1559 
1560 
1561  unsigned int i=0,j=0;
1562  while( j < size*3/2)
1563  {
1564 
1565  grey[i ] = yuv[j+1];
1566  grey[i+1] = yuv[j+2];
1567  grey[i+2] = yuv[j+4];
1568  grey[i+3] = yuv[j+5];
1569 
1570  i+=4;
1571 
1572  j+=6;
1573  }
1574 }
1575 
1584 void vpImageConvert::YUV422ToRGB(unsigned char* yuv,
1585  unsigned char* rgb,
1586  unsigned int size)
1587 {
1588 #if 1
1589  // std::cout << "call optimized convertYUV422ToRGB()" << std::endl;
1590  register int U, V, R, G, B, V2, U5, UV;
1591  register int Y0, Y1;
1592  for( unsigned int i = size / 2; i; i-- ) {
1593  U = (int)((*yuv++ - 128) * 0.354);
1594  U5 = 5*U;
1595  Y0 = *yuv++;
1596  V = (int)((*yuv++ - 128) * 0.707);
1597  V2 = 2*V;
1598  Y1 = *yuv++;
1599  UV = - U - V;
1600 
1601  //---
1602  R = Y0 + V2;
1603  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1604 
1605  G = Y0 + UV;
1606  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1607 
1608  B = Y0 + U5;
1609  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1610 
1611  *rgb++ = (unsigned char)R;
1612  *rgb++ = (unsigned char)G;
1613  *rgb++ = (unsigned char)B;
1614 
1615  //---
1616  R = Y1 + V2;
1617  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1618 
1619  G = Y1 + UV;
1620  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1621 
1622  B = Y1 + U5;
1623  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1624 
1625  *rgb++ = (unsigned char)R;
1626  *rgb++ = (unsigned char)G;
1627  *rgb++ = (unsigned char)B;
1628 
1629  }
1630 
1631 #else
1632  // tres tres lent ....
1633  unsigned int i=0,j=0;
1634  unsigned char r, g, b;
1635 
1636  while( j < size*2)
1637  {
1638 
1639  YUVToRGB (yuv[j+1], yuv[j], yuv[j+2], r, g, b);
1640  rgb[i] = r;
1641  rgb[i+1] = g;
1642  rgb[i+2] = b;
1643  i+=3;
1644 
1645  YUVToRGB (yuv[j+3], yuv[j], yuv[j+2], r, g, b);
1646  rgb[i] = r;
1647  rgb[i+1] = g;
1648  rgb[i+2] = b;
1649  i+=3;
1650  j+=4;
1651 
1652  }
1653 #endif
1654 }
1655 
1664 void vpImageConvert::YUV422ToGrey(unsigned char* yuv,
1665  unsigned char* grey,
1666  unsigned int size)
1667 {
1668  unsigned int i=0,j=0;
1669 
1670  while( j < size*2)
1671  {
1672  grey[i++] = yuv[j+1];
1673  grey[i++] = yuv[j+3];
1674  j+=4;
1675  }
1676 }
1677 
1684 void vpImageConvert::YUV411ToRGB(unsigned char* yuv,
1685  unsigned char* rgb,
1686  unsigned int size)
1687 {
1688 #if 1
1689  // std::cout << "call optimized ConvertYUV411ToRGB()" << std::endl;
1690  register int U, V, R, G, B, V2, U5, UV;
1691  register int Y0, Y1, Y2, Y3;
1692  for(unsigned int i = size / 4; i; i--) {
1693  U = (int)((*yuv++ - 128) * 0.354);
1694  U5 = 5*U;
1695  Y0 = *yuv++;
1696  Y1 = *yuv++;
1697  V = (int)((*yuv++ - 128) * 0.707);
1698  V2 = 2*V;
1699  Y2 = *yuv++;
1700  Y3 = *yuv++;
1701  UV = - U - V;
1702 
1703  // Original equations
1704  // R = Y + 1.402 V
1705  // G = Y - 0.344 U - 0.714 V
1706  // B = Y + 1.772 U
1707  R = Y0 + V2;
1708  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1709 
1710  G = Y0 + UV;
1711  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1712 
1713  B = Y0 + U5;
1714  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1715 
1716  *rgb++ = (unsigned char)R;
1717  *rgb++ = (unsigned char)G;
1718  *rgb++ = (unsigned char)B;
1719 
1720  //---
1721  R = Y1 + V2;
1722  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1723 
1724  G = Y1 + UV;
1725  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1726 
1727  B = Y1 + U5;
1728  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1729 
1730  *rgb++ = (unsigned char)R;
1731  *rgb++ = (unsigned char)G;
1732  *rgb++ = (unsigned char)B;
1733 
1734  //---
1735  R = Y2 + V2;
1736  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1737 
1738  G = Y2 + UV;
1739  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1740 
1741  B = Y2 + U5;
1742  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1743 
1744  *rgb++ = (unsigned char)R;
1745  *rgb++ = (unsigned char)G;
1746  *rgb++ = (unsigned char)B;
1747 
1748  //---
1749  R = Y3 + V2;
1750  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1751 
1752  G = Y3 + UV;
1753  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1754 
1755  B = Y3 + U5;
1756  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1757 
1758  *rgb++ = (unsigned char)R;
1759  *rgb++ = (unsigned char)G;
1760  *rgb++ = (unsigned char)B;
1761  }
1762 #else
1763  // tres tres lent ....
1764 
1765  unsigned int i=0,j=0;
1766  unsigned char r, g, b;
1767 
1768  while( j < size*3/2)
1769  {
1770  YUVToRGB (yuv[j+1], yuv[j], yuv[j+3], r, g, b);
1771  rgb[i] = r;
1772  rgb[i+1] = g;
1773  rgb[i+2] = b;
1774  i+=3;
1775 
1776  YUVToRGB (yuv[j+2], yuv[j], yuv[j+3], r, g, b);
1777  rgb[i] = r;
1778  rgb[i+1] = g;
1779  rgb[i+2] = b;
1780  i+=3;
1781 
1782  YUVToRGB (yuv[j+4], yuv[j], yuv[j+3], r, g, b);
1783  rgb[i] = r;
1784  rgb[i+1] = g;
1785  rgb[i+2] = b;
1786  i+=3;
1787 
1788  YUVToRGB (yuv[j+5], yuv[j], yuv[j+3], r, g, b);
1789  rgb[i] = r;
1790  rgb[i+1] = g;
1791  rgb[i+2] = b;
1792  i+=3;
1793  //TRACE("r= %d g=%d b=%d", r, g, b);
1794 
1795  j+=6;
1796  }
1797 #endif
1798 
1799 }
1800 
1801 
1802 
1809 void vpImageConvert::YUV420ToRGBa(unsigned char* yuv,
1810  unsigned char* rgba,
1811  unsigned int width, unsigned int height)
1812 {
1813  // std::cout << "call optimized ConvertYUV420ToRGBa()" << std::endl;
1814  register int U, V, R, G, B, V2, U5, UV;
1815  register int Y0, Y1, Y2, Y3;
1816  unsigned int size = width*height;
1817  unsigned char* iU = yuv + size;
1818  unsigned char* iV = yuv + 5*size/4;
1819  for(unsigned int i = 0; i<height/2; i++)
1820  {
1821  for(unsigned int j = 0; j < width/2 ; j++)
1822  {
1823  U = (int)((*iU++ - 128) * 0.354);
1824  U5 = 5*U;
1825  V = (int)((*iV++ - 128) * 0.707);
1826  V2 = 2*V;
1827  UV = - U - V;
1828  Y0 = *yuv++;
1829  Y1 = *yuv;
1830  yuv = yuv+width-1;
1831  Y2 = *yuv++;
1832  Y3 = *yuv;
1833  yuv = yuv-width+1;
1834 
1835  // Original equations
1836  // R = Y + 1.402 V
1837  // G = Y - 0.344 U - 0.714 V
1838  // B = Y + 1.772 U
1839  R = Y0 + V2;
1840  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1841 
1842  G = Y0 + UV;
1843  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1844 
1845  B = Y0 + U5;
1846  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1847 
1848  *rgba++ = (unsigned char)R;
1849  *rgba++ = (unsigned char)G;
1850  *rgba++ = (unsigned char)B;
1851  *rgba++ = 0;
1852 
1853  //---
1854  R = Y1 + V2;
1855  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1856 
1857  G = Y1 + UV;
1858  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1859 
1860  B = Y1 + U5;
1861  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1862 
1863  *rgba++ = (unsigned char)R;
1864  *rgba++ = (unsigned char)G;
1865  *rgba++ = (unsigned char)B;
1866  *rgba = 0;
1867  rgba = rgba + 4*width-7;
1868 
1869  //---
1870  R = Y2 + V2;
1871  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1872 
1873  G = Y2 + UV;
1874  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1875 
1876  B = Y2 + U5;
1877  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1878 
1879  *rgba++ = (unsigned char)R;
1880  *rgba++ = (unsigned char)G;
1881  *rgba++ = (unsigned char)B;
1882  *rgba++ = 0;
1883 
1884  //---
1885  R = Y3 + V2;
1886  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1887 
1888  G = Y3 + UV;
1889  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1890 
1891  B = Y3 + U5;
1892  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1893 
1894  *rgba++ = (unsigned char)R;
1895  *rgba++ = (unsigned char)G;
1896  *rgba++ = (unsigned char)B;
1897  *rgba = 0;
1898  rgba = rgba -4*width+1;
1899  }
1900  yuv+=width;
1901  rgba+=4*width;
1902  }
1903 }
1910 void vpImageConvert::YUV420ToRGB(unsigned char* yuv,
1911  unsigned char* rgb,
1912  unsigned int width, unsigned int height)
1913 {
1914  // std::cout << "call optimized ConvertYUV420ToRGB()" << std::endl;
1915  register int U, V, R, G, B, V2, U5, UV;
1916  register int Y0, Y1, Y2, Y3;
1917  unsigned int size = width*height;
1918  unsigned char* iU = yuv + size;
1919  unsigned char* iV = yuv + 5*size/4;
1920  for(unsigned int i = 0; i<height/2; i++)
1921  {
1922  for(unsigned int j = 0; j < width/2 ; j++)
1923  {
1924  U = (int)((*iU++ - 128) * 0.354);
1925  U5 = 5*U;
1926  V = (int)((*iV++ - 128) * 0.707);
1927  V2 = 2*V;
1928  UV = - U - V;
1929  Y0 = *yuv++;
1930  Y1 = *yuv;
1931  yuv = yuv+width-1;
1932  Y2 = *yuv++;
1933  Y3 = *yuv;
1934  yuv = yuv-width+1;
1935 
1936  // Original equations
1937  // R = Y + 1.402 V
1938  // G = Y - 0.344 U - 0.714 V
1939  // B = Y + 1.772 U
1940  R = Y0 + V2;
1941  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1942 
1943  G = Y0 + UV;
1944  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1945 
1946  B = Y0 + U5;
1947  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1948 
1949  *rgb++ = (unsigned char)R;
1950  *rgb++ = (unsigned char)G;
1951  *rgb++ = (unsigned char)B;
1952 
1953  //---
1954  R = Y1 + V2;
1955  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1956 
1957  G = Y1 + UV;
1958  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1959 
1960  B = Y1 + U5;
1961  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1962 
1963  *rgb++ = (unsigned char)R;
1964  *rgb++ = (unsigned char)G;
1965  *rgb = (unsigned char)B;
1966  rgb = rgb + 3*width-5;
1967 
1968  //---
1969  R = Y2 + V2;
1970  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1971 
1972  G = Y2 + UV;
1973  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1974 
1975  B = Y2 + U5;
1976  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1977 
1978  *rgb++ = (unsigned char)R;
1979  *rgb++ = (unsigned char)G;
1980  *rgb++ = (unsigned char)B;
1981 
1982  //---
1983  R = Y3 + V2;
1984  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
1985 
1986  G = Y3 + UV;
1987  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
1988 
1989  B = Y3 + U5;
1990  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
1991 
1992  *rgb++ = (unsigned char)R;
1993  *rgb++ = (unsigned char)G;
1994  *rgb = (unsigned char)B;
1995  rgb = rgb -3*width+1;
1996  }
1997  yuv+=width;
1998  rgb+=3*width;
1999  }
2000 }
2001 
2008 void vpImageConvert::YUV420ToGrey(unsigned char* yuv,
2009  unsigned char* grey,
2010  unsigned int size)
2011 {
2012  for(unsigned int i=0 ; i < size ; i++)
2013  {
2014  *grey++ = *yuv++;
2015  }
2016 
2017 }
2024 void vpImageConvert::YUV444ToRGBa(unsigned char* yuv,
2025  unsigned char* rgba,
2026  unsigned int size)
2027 {
2028  register int U, V, R, G, B, V2, U5, UV;
2029  register int Y;
2030  for(unsigned int i = 0; i<size; i++)
2031  {
2032  U = (int)((*yuv++ - 128) * 0.354);
2033  U5 = 5*U;
2034  Y = *yuv++;
2035  V = (int)((*yuv++ - 128) * 0.707);
2036  V2 = 2*V;
2037  UV = - U - V;
2038 
2039 
2040  // Original equations
2041  // R = Y + 1.402 V
2042  // G = Y - 0.344 U - 0.714 V
2043  // B = Y + 1.772 U
2044  R = Y + V2;
2045  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2046 
2047  G = Y + UV;
2048  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2049 
2050  B = Y + U5;
2051  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2052 
2053  *rgba++ = (unsigned char)R;
2054  *rgba++ = (unsigned char)G;
2055  *rgba++ = (unsigned char)B;
2056  *rgba++ = 0;
2057  }
2058 }
2065 void vpImageConvert::YUV444ToRGB(unsigned char* yuv,
2066  unsigned char* rgb,
2067  unsigned int size)
2068 {
2069  register int U, V, R, G, B, V2, U5, UV;
2070  register int Y;
2071  for(unsigned int i = 0; i<size; i++)
2072  {
2073 
2074  U = (int)((*yuv++ - 128) * 0.354);
2075  U5 = 5*U;
2076  Y = *yuv++;
2077  V = (int)((*yuv++ - 128) * 0.707);
2078  V2 = 2*V;
2079  UV = - U - V;
2080 
2081  // Original equations
2082  // R = Y + 1.402 V
2083  // G = Y - 0.344 U - 0.714 V
2084  // B = Y + 1.772 U
2085  R = Y + V2;
2086  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2087 
2088  G = Y + UV;
2089  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2090 
2091  B = Y + U5;
2092  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2093 
2094  *rgb++ = (unsigned char)R;
2095  *rgb++ = (unsigned char)G;
2096  *rgb++ = (unsigned char)B;
2097  }
2098 }
2099 
2106 void vpImageConvert::YUV444ToGrey(unsigned char* yuv,
2107  unsigned char* grey,
2108  unsigned int size)
2109 {
2110  yuv++;
2111  for(unsigned int i=0 ; i < size ; i++)
2112  {
2113  *grey++ = *yuv;
2114  yuv = yuv + 3;
2115  }
2116 }
2117 
2124 void vpImageConvert::YV12ToRGBa(unsigned char* yuv,
2125  unsigned char* rgba,
2126  unsigned int width, unsigned int height)
2127 {
2128  // std::cout << "call optimized ConvertYV12ToRGBa()" << std::endl;
2129  register int U, V, R, G, B, V2, U5, UV;
2130  register int Y0, Y1, Y2, Y3;
2131  unsigned int size = width*height;
2132  unsigned char* iV = yuv + size;
2133  unsigned char* iU = yuv + 5*size/4;
2134  for(unsigned int i = 0; i<height/2; i++)
2135  {
2136  for(unsigned int j = 0; j < width/2 ; j++)
2137  {
2138  U = (int)((*iU++ - 128) * 0.354);
2139  U5 = 5*U;
2140  V = (int)((*iV++ - 128) * 0.707);
2141  V2 = 2*V;
2142  UV = - U - V;
2143  Y0 = *yuv++;
2144  Y1 = *yuv;
2145  yuv = yuv+width-1;
2146  Y2 = *yuv++;
2147  Y3 = *yuv;
2148  yuv = yuv-width+1;
2149 
2150  // Original equations
2151  // R = Y + 1.402 V
2152  // G = Y - 0.344 U - 0.714 V
2153  // B = Y + 1.772 U
2154  R = Y0 + V2;
2155  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2156 
2157  G = Y0 + UV;
2158  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2159 
2160  B = Y0 + U5;
2161  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2162 
2163  *rgba++ = (unsigned char)R;
2164  *rgba++ = (unsigned char)G;
2165  *rgba++ = (unsigned char)B;
2166  *rgba++ = 0;
2167 
2168  //---
2169  R = Y1 + V2;
2170  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2171 
2172  G = Y1 + UV;
2173  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2174 
2175  B = Y1 + U5;
2176  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2177 
2178  *rgba++ = (unsigned char)R;
2179  *rgba++ = (unsigned char)G;
2180  *rgba++ = (unsigned char)B;
2181  *rgba = 0;
2182  rgba = rgba + 4*width-7;
2183 
2184  //---
2185  R = Y2 + V2;
2186  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2187 
2188  G = Y2 + UV;
2189  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2190 
2191  B = Y2 + U5;
2192  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2193 
2194  *rgba++ = (unsigned char)R;
2195  *rgba++ = (unsigned char)G;
2196  *rgba++ = (unsigned char)B;
2197  *rgba++ = 0;
2198 
2199  //---
2200  R = Y3 + V2;
2201  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2202 
2203  G = Y3 + UV;
2204  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2205 
2206  B = Y3 + U5;
2207  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2208 
2209  *rgba++ = (unsigned char)R;
2210  *rgba++ = (unsigned char)G;
2211  *rgba++ = (unsigned char)B;
2212  *rgba = 0;
2213  rgba = rgba -4*width+1;
2214  }
2215  yuv+=width;
2216  rgba+=4*width;
2217  }
2218 }
2225 void vpImageConvert::YV12ToRGB(unsigned char* yuv,
2226  unsigned char* rgb,
2227  unsigned int height, unsigned int width)
2228 {
2229  // std::cout << "call optimized ConvertYV12ToRGB()" << std::endl;
2230  register int U, V, R, G, B, V2, U5, UV;
2231  register int Y0, Y1, Y2, Y3;
2232  unsigned int size = width*height;
2233  unsigned char* iV = yuv + size;
2234  unsigned char* iU = yuv + 5*size/4;
2235  for(unsigned int i = 0; i<height/2; i++)
2236  {
2237  for(unsigned int j = 0; j < width/2 ; j++)
2238  {
2239  U = (int)((*iU++ - 128) * 0.354);
2240  U5 = 5*U;
2241  V = (int)((*iV++ - 128) * 0.707);
2242  V2 = 2*V;
2243  UV = - U - V;
2244  Y0 = *yuv++;
2245  Y1 = *yuv;
2246  yuv = yuv+width-1;
2247  Y2 = *yuv++;
2248  Y3 = *yuv;
2249  yuv = yuv-width+1;
2250 
2251  // Original equations
2252  // R = Y + 1.402 V
2253  // G = Y - 0.344 U - 0.714 V
2254  // B = Y + 1.772 U
2255  R = Y0 + V2;
2256  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2257 
2258  G = Y0 + UV;
2259  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2260 
2261  B = Y0 + U5;
2262  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2263 
2264  *rgb++ = (unsigned char)R;
2265  *rgb++ = (unsigned char)G;
2266  *rgb++ = (unsigned char)B;
2267 
2268  //---
2269  R = Y1 + V2;
2270  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2271 
2272  G = Y1 + UV;
2273  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2274 
2275  B = Y1 + U5;
2276  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2277 
2278  *rgb++ = (unsigned char)R;
2279  *rgb++ = (unsigned char)G;
2280  *rgb = (unsigned char)B;
2281  rgb = rgb + 3*width-5;
2282 
2283  //---
2284  R = Y2 + V2;
2285  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2286 
2287  G = Y2 + UV;
2288  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2289 
2290  B = Y2 + U5;
2291  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2292 
2293  *rgb++ = (unsigned char)R;
2294  *rgb++ = (unsigned char)G;
2295  *rgb++ = (unsigned char)B;
2296 
2297  //---
2298  R = Y3 + V2;
2299  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2300 
2301  G = Y3 + UV;
2302  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2303 
2304  B = Y3 + U5;
2305  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2306 
2307  *rgb++ = (unsigned char)R;
2308  *rgb++ = (unsigned char)G;
2309  *rgb = (unsigned char)B;
2310  rgb = rgb -3*width+1;
2311  }
2312  yuv+=width;
2313  rgb+=3*width;
2314  }
2315 }
2316 
2323 void vpImageConvert::YVU9ToRGBa(unsigned char* yuv,
2324  unsigned char* rgba,
2325  unsigned int width, unsigned int height)
2326 {
2327  // std::cout << "call optimized ConvertYVU9ToRGBa()" << std::endl;
2328  register int U, V, R, G, B, V2, U5, UV;
2329  register int Y0, Y1, Y2, Y3,Y4, Y5, Y6, Y7,Y8, Y9, Y10, Y11,Y12, Y13, Y14, Y15;
2330  unsigned int size = width*height;
2331  unsigned char* iV = yuv + size;
2332  unsigned char* iU = yuv + 17*size/16;
2333  for(unsigned int i = 0; i<height/4; i++)
2334  {
2335  for(unsigned int j = 0; j < width/4 ; j++)
2336  {
2337  U = (int)((*iU++ - 128) * 0.354);
2338  U5 = 5*U;
2339  V = (int)((*iV++ - 128) * 0.707);
2340  V2 = 2*V;
2341  UV = - U - V;
2342  Y0 = *yuv++;
2343  Y1 = *yuv++;
2344  Y2 = *yuv++;
2345  Y3 = *yuv;
2346  yuv = yuv+width-3;
2347  Y4 = *yuv++;
2348  Y5 = *yuv++;
2349  Y6 = *yuv++;
2350  Y7 = *yuv;
2351  yuv = yuv+width-3;
2352  Y8 = *yuv++;
2353  Y9 = *yuv++;
2354  Y10 = *yuv++;
2355  Y11 = *yuv;
2356  yuv = yuv+width-3;
2357  Y12 = *yuv++;
2358  Y13 = *yuv++;
2359  Y14 = *yuv++;
2360  Y15 = *yuv;
2361  yuv = yuv-3*width+1;
2362 
2363  // Original equations
2364  // R = Y + 1.402 V
2365  // G = Y - 0.344 U - 0.714 V
2366  // B = Y + 1.772 U
2367  R = Y0 + V2;
2368  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2369 
2370  G = Y0 + UV;
2371  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2372 
2373  B = Y0 + U5;
2374  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2375 
2376  *rgba++ = (unsigned char)R;
2377  *rgba++ = (unsigned char)G;
2378  *rgba++ = (unsigned char)B;
2379  *rgba++ = 0;
2380 
2381  //---
2382  R = Y1 + V2;
2383  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2384 
2385  G = Y1 + UV;
2386  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2387 
2388  B = Y1 + U5;
2389  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2390 
2391  *rgba++ = (unsigned char)R;
2392  *rgba++ = (unsigned char)G;
2393  *rgba++ = (unsigned char)B;
2394  *rgba++ = 0;
2395 
2396  //---
2397  R = Y2 + V2;
2398  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2399 
2400  G = Y2 + UV;
2401  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2402 
2403  B = Y2 + U5;
2404  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2405 
2406  *rgba++ = (unsigned char)R;
2407  *rgba++ = (unsigned char)G;
2408  *rgba++ = (unsigned char)B;
2409  *rgba++ = 0;
2410 
2411  //---
2412  R = Y3 + V2;
2413  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2414 
2415  G = Y3 + UV;
2416  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2417 
2418  B = Y3 + U5;
2419  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2420 
2421  *rgba++ = (unsigned char)R;
2422  *rgba++ = (unsigned char)G;
2423  *rgba++ = (unsigned char)B;
2424  *rgba = 0;
2425  rgba = rgba + 4*width-15;
2426 
2427  R = Y4 + V2;
2428  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2429 
2430  G = Y4 + UV;
2431  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2432 
2433  B = Y4 + U5;
2434  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2435 
2436  *rgba++ = (unsigned char)R;
2437  *rgba++ = (unsigned char)G;
2438  *rgba++ = (unsigned char)B;
2439  *rgba++ = 0;
2440 
2441  //---
2442  R = Y5 + V2;
2443  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2444 
2445  G = Y5 + UV;
2446  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2447 
2448  B = Y5 + U5;
2449  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2450 
2451  *rgba++ = (unsigned char)R;
2452  *rgba++ = (unsigned char)G;
2453  *rgba++ = (unsigned char)B;
2454  *rgba++ = 0;
2455 
2456  //---
2457  R = Y6 + V2;
2458  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2459 
2460  G = Y6 + UV;
2461  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2462 
2463  B = Y6 + U5;
2464  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2465 
2466  *rgba++ = (unsigned char)R;
2467  *rgba++ = (unsigned char)G;
2468  *rgba++ = (unsigned char)B;
2469  *rgba++ = 0;
2470 
2471  //---
2472  R = Y7 + V2;
2473  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2474 
2475  G = Y7 + UV;
2476  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2477 
2478  B = Y7 + U5;
2479  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2480 
2481  *rgba++ = (unsigned char)R;
2482  *rgba++ = (unsigned char)G;
2483  *rgba++ = (unsigned char)B;
2484  *rgba = 0;
2485  rgba = rgba + 4*width-15;
2486 
2487  R = Y8 + V2;
2488  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2489 
2490  G = Y8 + UV;
2491  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2492 
2493  B = Y8 + U5;
2494  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2495 
2496  *rgba++ = (unsigned char)R;
2497  *rgba++ = (unsigned char)G;
2498  *rgba++ = (unsigned char)B;
2499  *rgba++ = 0;
2500 
2501  //---
2502  R = Y9 + V2;
2503  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2504 
2505  G = Y9 + UV;
2506  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2507 
2508  B = Y9 + U5;
2509  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2510 
2511  *rgba++ = (unsigned char)R;
2512  *rgba++ = (unsigned char)G;
2513  *rgba++ = (unsigned char)B;
2514  *rgba++ = 0;
2515 
2516  //---
2517  R = Y10 + V2;
2518  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2519 
2520  G = Y10 + UV;
2521  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2522 
2523  B = Y10 + U5;
2524  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2525 
2526  *rgba++ = (unsigned char)R;
2527  *rgba++ = (unsigned char)G;
2528  *rgba++ = (unsigned char)B;
2529  *rgba++ = 0;
2530 
2531  //---
2532  R = Y11 + V2;
2533  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2534 
2535  G = Y11 + UV;
2536  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2537 
2538  B = Y11 + U5;
2539  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2540 
2541  *rgba++ = (unsigned char)R;
2542  *rgba++ = (unsigned char)G;
2543  *rgba++ = (unsigned char)B;
2544  *rgba = 0;
2545  rgba = rgba + 4*width-15;
2546 
2547  R = Y12 + V2;
2548  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2549 
2550  G = Y12 + UV;
2551  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2552 
2553  B = Y12 + U5;
2554  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2555 
2556  *rgba++ = (unsigned char)R;
2557  *rgba++ = (unsigned char)G;
2558  *rgba++ = (unsigned char)B;
2559  *rgba++ = 0;
2560 
2561  //---
2562  R = Y13 + V2;
2563  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2564 
2565  G = Y13 + UV;
2566  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2567 
2568  B = Y13 + U5;
2569  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2570 
2571  *rgba++ = (unsigned char)R;
2572  *rgba++ = (unsigned char)G;
2573  *rgba++ = (unsigned char)B;
2574  *rgba++ = 0;
2575 
2576  //---
2577  R = Y14 + V2;
2578  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2579 
2580  G = Y14 + UV;
2581  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2582 
2583  B = Y14 + U5;
2584  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2585 
2586  *rgba++ = (unsigned char)R;
2587  *rgba++ = (unsigned char)G;
2588  *rgba++ = (unsigned char)B;
2589  *rgba++ = 0;
2590 
2591  //---
2592  R = Y15 + V2;
2593  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2594 
2595  G = Y15 + UV;
2596  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2597 
2598  B = Y15 + U5;
2599  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2600 
2601  *rgba++ = (unsigned char)R;
2602  *rgba++ = (unsigned char)G;
2603  *rgba++ = (unsigned char)B;
2604  *rgba = 0;
2605  rgba = rgba -12*width+1;
2606  }
2607  yuv+=3*width;
2608  rgba+=12*width;
2609  }
2610 }
2617 void vpImageConvert::YVU9ToRGB(unsigned char* yuv,
2618  unsigned char* rgb,
2619  unsigned int height, unsigned int width)
2620 {
2621  // std::cout << "call optimized ConvertYVU9ToRGB()" << std::endl;
2622  register int U, V, R, G, B, V2, U5, UV;
2623  register int Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7, Y8, Y9, Y10, Y11, Y12, Y13, Y14, Y15;
2624  unsigned int size = width*height;
2625  unsigned char* iV = yuv + size;
2626  unsigned char* iU = yuv + 17*size/16;
2627  for(unsigned int i = 0; i<height/4; i++)
2628  {
2629  for(unsigned int j = 0; j < width/4 ; j++)
2630  {
2631  U = (int)((*iU++ - 128) * 0.354);
2632  U5 = 5*U;
2633  V = (int)((*iV++ - 128) * 0.707);
2634  V2 = 2*V;
2635  UV = - U - V;
2636  Y0 = *yuv++;
2637  Y1 = *yuv++;
2638  Y2 = *yuv++;
2639  Y3 = *yuv;
2640  yuv = yuv+width-3;
2641  Y4 = *yuv++;
2642  Y5 = *yuv++;
2643  Y6 = *yuv++;
2644  Y7 = *yuv;
2645  yuv = yuv+width-3;
2646  Y8 = *yuv++;
2647  Y9 = *yuv++;
2648  Y10 = *yuv++;
2649  Y11 = *yuv;
2650  yuv = yuv+width-3;
2651  Y12 = *yuv++;
2652  Y13 = *yuv++;
2653  Y14 = *yuv++;
2654  Y15 = *yuv;
2655  yuv = yuv-3*width+1;
2656 
2657  // Original equations
2658  // R = Y + 1.402 V
2659  // G = Y - 0.344 U - 0.714 V
2660  // B = Y + 1.772 U
2661  R = Y0 + V2;
2662  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2663 
2664  G = Y0 + UV;
2665  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2666 
2667  B = Y0 + 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 
2674  //---
2675  R = Y1 + V2;
2676  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2677 
2678  G = Y1 + UV;
2679  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2680 
2681  B = Y1 + 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 = Y2 + V2;
2690  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2691 
2692  G = Y2 + UV;
2693  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2694 
2695  B = Y2 + 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 = Y3 + V2;
2704  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2705 
2706  G = Y3 + UV;
2707  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2708 
2709  B = Y3 + 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  rgb = rgb + 3*width-11;
2716 
2717  R = Y4 + V2;
2718  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2719 
2720  G = Y4 + UV;
2721  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2722 
2723  B = Y4 + 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 
2730  //---
2731  R = Y5 + V2;
2732  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2733 
2734  G = Y5 + UV;
2735  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2736 
2737  B = Y5 + 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 = Y6 + V2;
2746  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2747 
2748  G = Y6 + UV;
2749  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2750 
2751  B = Y6 + 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 = Y7 + V2;
2760  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2761 
2762  G = Y7 + UV;
2763  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2764 
2765  B = Y7 + 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  rgb = rgb + 3*width-11;
2772 
2773  R = Y8 + V2;
2774  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2775 
2776  G = Y8 + UV;
2777  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2778 
2779  B = Y8 + 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 
2786  //---
2787  R = Y9 + V2;
2788  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2789 
2790  G = Y9 + UV;
2791  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2792 
2793  B = Y9 + 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 = Y10 + V2;
2802  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2803 
2804  G = Y10 + UV;
2805  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2806 
2807  B = Y10 + 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 = Y11 + V2;
2816  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2817 
2818  G = Y11 + UV;
2819  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2820 
2821  B = Y11 + 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  rgb = rgb + 3*width-11;
2828 
2829  R = Y12 + V2;
2830  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2831 
2832  G = Y12 + UV;
2833  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2834 
2835  B = Y12 + 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 
2842  //---
2843  R = Y13 + V2;
2844  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2845 
2846  G = Y13 + UV;
2847  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2848 
2849  B = Y13 + U5;
2850  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2851 
2852  *rgb++ = (unsigned char)R;
2853  *rgb++ = (unsigned char)G;
2854  *rgb++ = (unsigned char)B;
2855 
2856  //---
2857  R = Y14 + V2;
2858  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2859 
2860  G = Y14 + UV;
2861  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2862 
2863  B = Y14 + U5;
2864  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2865 
2866  *rgb++ = (unsigned char)R;
2867  *rgb++ = (unsigned char)G;
2868  *rgb++ = (unsigned char)B;
2869 
2870  //---
2871  R = Y15 + V2;
2872  if ((R >> 8) > 0) R = 255; else if (R < 0) R = 0;
2873 
2874  G = Y15 + UV;
2875  if ((G >> 8) > 0) G = 255; else if (G < 0) G = 0;
2876 
2877  B = Y15 + U5;
2878  if ((B >> 8) > 0) B = 255; else if (B < 0) B = 0;
2879 
2880  *rgb++ = (unsigned char)R;
2881  *rgb++ = (unsigned char)G;
2882  *rgb++ = (unsigned char)B;
2883  rgb = rgb -9*width+1;
2884  }
2885  yuv+=3*width;
2886  rgb+=9*width;
2887  }
2888 }
2889 
2895 void vpImageConvert::RGBToRGBa(unsigned char* rgb, unsigned char* rgba,
2896  unsigned int size)
2897 {
2898  unsigned char *pt_input = rgb;
2899  unsigned char *pt_end = rgb + 3*size;
2900  unsigned char *pt_output = rgba;
2901 
2902  while(pt_input != pt_end) {
2903  *(pt_output++) = *(pt_input++) ; // R
2904  *(pt_output++) = *(pt_input++) ; // G
2905  *(pt_output++) = *(pt_input++) ; // B
2906  *(pt_output++) = 0 ; // A
2907  }
2908 }
2909 
2915 void vpImageConvert::RGBaToRGB(unsigned char* rgba, unsigned char* rgb,
2916  unsigned int size)
2917 {
2918  unsigned char *pt_input = rgba;
2919  unsigned char *pt_end = rgba + 4*size;
2920  unsigned char *pt_output = rgb;
2921 
2922  while(pt_input != pt_end) {
2923  *(pt_output++) = *(pt_input++) ; // R
2924  *(pt_output++) = *(pt_input++) ; // G
2925  *(pt_output++) = *(pt_input++) ; // B
2926  pt_input++ ;
2927  }
2928 }
2935 void vpImageConvert::RGBToGrey(unsigned char* rgb, unsigned char* grey,
2936  unsigned int size)
2937 {
2938  unsigned char *pt_input = rgb;
2939  unsigned char* pt_end = rgb + size*3;
2940  unsigned char *pt_output = grey;
2941  while(pt_input != pt_end) {
2942  *pt_output = (unsigned char) (0.2126 * (*pt_input)
2943  + 0.7152 * (*(pt_input + 1))
2944  + 0.0722 * (*(pt_input + 2)) );
2945  pt_input += 3;
2946  pt_output ++;
2947  }
2948 }
2956 void vpImageConvert::RGBaToGrey(unsigned char* rgba, unsigned char* grey,
2957  unsigned int size)
2958 {
2959  unsigned char *pt_input = rgba;
2960  unsigned char* pt_end = rgba + size*4;
2961  unsigned char *pt_output = grey;
2962 
2963  while(pt_input != pt_end) {
2964  *pt_output = (unsigned char) (0.2126 * (*pt_input)
2965  + 0.7152 * (*(pt_input + 1))
2966  + 0.0722 * (*(pt_input + 2)) );
2967  pt_input += 4;
2968  pt_output ++;
2969  }
2970 }
2971 
2976 void
2977 vpImageConvert::GreyToRGBa(unsigned char* grey,
2978  unsigned char* rgba, unsigned int size)
2979 {
2980  unsigned char *pt_input = grey;
2981  unsigned char *pt_end = grey + size;
2982  unsigned char *pt_output = rgba;
2983 
2984  while(pt_input != pt_end) {
2985  unsigned char p = *pt_input ;
2986  *(pt_output ) = p ; // R
2987  *(pt_output + 1) = p ; // G
2988  *(pt_output + 2) = p ; // B
2989  *(pt_output + 3) = p ; // A
2990 
2991  pt_input ++;
2992  pt_output += 4;
2993  }
2994 }
2995 
3000 void
3001 vpImageConvert::GreyToRGB(unsigned char* grey,
3002  unsigned char* rgb, unsigned int size)
3003 {
3004  unsigned char *pt_input = grey;
3005  unsigned char* pt_end = grey + size;
3006  unsigned char *pt_output = rgb;
3007 
3008  while(pt_input != pt_end) {
3009  unsigned char p = *pt_input ;
3010  *(pt_output ) = p ; // R
3011  *(pt_output + 1) = p ; // G
3012  *(pt_output + 2) = p ; // B
3013 
3014  pt_input ++;
3015  pt_output += 3;
3016  }
3017 }
3018 
3019 
3025 void
3026 vpImageConvert::BGRToRGBa(unsigned char * bgr, unsigned char * rgba,
3027  unsigned int width, unsigned int height, bool flip)
3028 {
3029  //if we have to flip the image, we start from the end last scanline so the
3030  //step is negative
3031  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3032 
3033  //starting source address = last line if we need to flip the image
3034  unsigned char * src = (flip) ? (bgr+(width*height*3)+lineStep) : bgr;
3035  unsigned char * line;
3036 
3037  unsigned int j=0;
3038  unsigned int i=0;
3039 
3040  for(i=0 ; i < height ; i++)
3041  {
3042  line = src;
3043  for( j=0 ; j < width ; j++)
3044  {
3045  *rgba++ = *(line+2);
3046  *rgba++ = *(line+1);
3047  *rgba++ = *(line+0);
3048  *rgba++ = 0;
3049 
3050  line+=3;
3051  }
3052  //go to the next line
3053  src+=lineStep;
3054  }
3055 
3056 }
3057 
3063 void
3064 vpImageConvert::BGRToGrey(unsigned char * bgr, unsigned char * grey,
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) ? bgr+(width*height*3)+lineStep : bgr;
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  *grey++ = (unsigned char)( 0.2126 * *(line+2)
3084  + 0.7152 * *(line+1)
3085  + 0.0722 * *(line+0)) ;
3086  line+=3;
3087  }
3088 
3089  //go to the next line
3090  src+=lineStep;
3091  }
3092 }
3098 void
3099 vpImageConvert::RGBToRGBa(unsigned char * rgb, unsigned char * rgba,
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  for(i=0 ; i < height ; i++)
3114  {
3115  line = src;
3116  for( j=0 ; j < width ; j++)
3117  {
3118  *rgba++ = *(line++);
3119  *rgba++ = *(line++);
3120  *rgba++ = *(line++);
3121  *rgba++ = 0;
3122  }
3123  //go to the next line
3124  src+=lineStep;
3125  }
3126 }
3127 
3133 void
3134 vpImageConvert::RGBToGrey(unsigned char * rgb, unsigned char * grey,
3135  unsigned int width, unsigned int height, bool flip)
3136 {
3137  //if we have to flip the image, we start from the end last scanline so the
3138  //step is negative
3139  int lineStep = (flip) ? -(int)(width*3) : (int)(width*3);
3140 
3141  //starting source address = last line if we need to flip the image
3142  unsigned char * src = (flip) ? rgb+(width*height*3)+lineStep : rgb;
3143  unsigned char * line;
3144 
3145  unsigned int j=0;
3146  unsigned int i=0;
3147 
3148  unsigned r,g,b;
3149 
3150  for(i=0 ; i < height ; i++)
3151  {
3152  line = src;
3153  for( j=0 ; j < width ; j++)
3154  {
3155  r = *(line++);
3156  g = *(line++);
3157  b = *(line++);
3158  *grey++ = (unsigned char)( 0.2126 * r + 0.7152 * g + 0.0722 * b) ;
3159  }
3160 
3161  //go to the next line
3162  src+=lineStep;
3163  }
3164 }
3165 
3171 void vpImageConvert::computeYCbCrLUT()
3172 {
3173  if (YCbCrLUTcomputed == false) {
3174  int index = 256, aux;
3175 
3176  while (index-- ) {
3177 
3178  aux = index - 128;
3179  vpImageConvert::vpCrr[index] = (int)( 364.6610 * aux) >> 8;
3180  vpImageConvert::vpCgb[index] = (int)( -89.8779 * aux) >> 8;
3181  vpImageConvert::vpCgr[index] = (int)(-185.8154 * aux) >> 8;
3182  vpImageConvert::vpCbb[index] = (int)( 460.5724 * aux) >> 8;
3183  }
3184 
3185  YCbCrLUTcomputed = true;
3186  }
3187 }
3188 
3189 
3209 void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb,
3210  unsigned int size)
3211 {
3212  unsigned char *cbv;
3213  unsigned char *crv;
3214  unsigned char *pt_ycbcr = ycbcr;
3215  unsigned char *pt_rgb = rgb;
3216  cbv = pt_ycbcr + 1;
3217  crv = pt_ycbcr + 3;
3218 
3219  vpImageConvert::computeYCbCrLUT();
3220 
3221  int col = 0;
3222 
3223  while (size--) {
3224  register int val_r, val_g, val_b;
3225  if (!(col++ % 2)) {
3226  cbv = pt_ycbcr + 1;
3227  crv = pt_ycbcr + 3;
3228  }
3229 
3230  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3231  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3232  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3233 
3234  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3235 
3236  *pt_rgb++ = (val_r < 0) ? 0u :
3237  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3238  *pt_rgb++ = (val_g < 0) ? 0u :
3239  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3240  *pt_rgb++ = (val_b < 0) ? 0u :
3241  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3242 
3243  pt_ycbcr += 2;
3244  }
3245 }
3246 
3268 void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba,
3269  unsigned int size)
3270 {
3271  unsigned char *cbv;
3272  unsigned char *crv;
3273  unsigned char *pt_ycbcr = ycbcr;
3274  unsigned char *pt_rgba = rgba;
3275  cbv = pt_ycbcr + 1;
3276  crv = pt_ycbcr + 3;
3277 
3278  vpImageConvert::computeYCbCrLUT();
3279 
3280  int col = 0;
3281 
3282  while (size--) {
3283  register int val_r, val_g, val_b;
3284  if (!(col++ % 2)) {
3285  cbv = pt_ycbcr + 1;
3286  crv = pt_ycbcr + 3;
3287  }
3288 
3289  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3290  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3291  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3292 
3293  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3294 
3295  *pt_rgba++ = (val_r < 0) ? 0u :
3296  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3297  *pt_rgba++ = (val_g < 0) ? 0u :
3298  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3299  *pt_rgba++ = (val_b < 0) ? 0u :
3300  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3301  *pt_rgba++ = 0;
3302 
3303  pt_ycbcr += 2;
3304  }
3305 }
3306 
3307 
3324 void vpImageConvert::YCbCrToGrey(unsigned char* yuv,
3325  unsigned char* grey,
3326  unsigned int size)
3327 {
3328  unsigned int i=0,j=0;
3329 
3330  while( j < size*2)
3331  {
3332  grey[i++] = yuv[j];
3333  grey[i++] = yuv[j+2];
3334  j+=4;
3335  }
3336 }
3337 
3356 void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb,
3357  unsigned int size)
3358 {
3359  unsigned char *cbv;
3360  unsigned char *crv;
3361  unsigned char *pt_ycbcr = ycrcb;
3362  unsigned char *pt_rgb = rgb;
3363  crv = pt_ycbcr + 1;
3364  cbv = pt_ycbcr + 3;
3365 
3366  vpImageConvert::computeYCbCrLUT();
3367 
3368  int col = 0;
3369 
3370  while (size--) {
3371  register int val_r, val_g, val_b;
3372  if (!(col++ % 2)) {
3373  crv = pt_ycbcr + 1;
3374  cbv = pt_ycbcr + 3;
3375  }
3376 
3377  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3378  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3379  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3380 
3381  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3382 
3383  *pt_rgb++ = (val_r < 0) ? 0u :
3384  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3385  *pt_rgb++ = (val_g < 0) ? 0u :
3386  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3387  *pt_rgb++ = (val_b < 0) ? 0u :
3388  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3389 
3390  pt_ycbcr += 2;
3391  }
3392 }
3413 void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba,
3414  unsigned int size)
3415 {
3416  unsigned char *cbv;
3417  unsigned char *crv;
3418  unsigned char *pt_ycbcr = ycrcb;
3419  unsigned char *pt_rgba = rgba;
3420  crv = pt_ycbcr + 1;
3421  cbv = pt_ycbcr + 3;
3422 
3423  vpImageConvert::computeYCbCrLUT();
3424 
3425  int col = 0;
3426 
3427  while (size--) {
3428  register int val_r, val_g, val_b;
3429  if (!(col++ % 2)) {
3430  crv = pt_ycbcr + 1;
3431  cbv = pt_ycbcr + 3;
3432  }
3433 
3434  val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv];
3435  val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv];
3436  val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv];
3437 
3438  vpDEBUG_TRACE(5, "[%d] R: %d G: %d B: %d\n", size, val_r, val_g, val_b);
3439 
3440  *pt_rgba++ = (val_r < 0) ? 0u :
3441  ((val_r > 255) ? 255u : (unsigned char)val_r); // Red component.
3442  *pt_rgba++ = (val_g < 0) ? 0u :
3443  ((val_g > 255) ? 255u : (unsigned char)val_g); // Green component.
3444  *pt_rgba++ = (val_b < 0) ? 0u :
3445  ((val_b > 255) ? 255u : (unsigned char)val_b); // Blue component.
3446  *pt_rgba++ = 0;
3447 
3448  pt_ycbcr += 2;
3449  }
3450 }
3451 
3492 {
3493  register size_t n = src.getNumberOfPixel();
3494  unsigned int height = src.getHeight();
3495  unsigned int width = src.getWidth();
3496  unsigned char* input;
3497  unsigned char* dst ;
3498 
3499  vpImage<unsigned char>* tabChannel[4];
3500 
3501 /* incrsrc[0] = 0; //init
3502  incrsrc[1] = 0; //step after the first used channel
3503  incrsrc[2] = 0; //step after the second used channel
3504  incrsrc[3] = 0;
3505  incrsrc[4] = 0;
3506  */
3507  tabChannel[0] = pR;
3508  tabChannel[1] = pG;
3509  tabChannel[2] = pB;
3510  tabChannel[3] = pa;
3511 
3512  register size_t i; /* ordre */
3513  for(unsigned int j = 0;j < 4;j++){
3514  if(tabChannel[j]!=NULL){
3515  if(tabChannel[j]->getHeight() != height ||
3516  tabChannel[j]->getWidth() != width){
3517  tabChannel[j]->resize(height,width);
3518  }
3519  dst = (unsigned char*)tabChannel[j]->bitmap;
3520 
3521  input = (unsigned char*)src.bitmap+j;
3522  i = 0;
3523 #if 1 //optimization
3524  if (n >= 4) { /* boucle deroulee lsize fois */
3525  n -= 3;
3526  for (; i < n; i += 4) {
3527  *dst = *input; input += 4; dst++;
3528  *dst = *input; input += 4; dst++;
3529  *dst = *input; input += 4; dst++;
3530  *dst = *input; input += 4; dst++;
3531  }
3532  n += 3;
3533  }
3534 #endif
3535  for (; i < n; i++) {
3536  *dst = *input; input += 4; dst ++;
3537  }
3538  }
3539  }
3540 }
3541 
3552 void vpImageConvert::MONO16ToGrey(unsigned char *grey16, unsigned char *grey,
3553  unsigned int size)
3554 {
3555  register int i = (((int)size)<<1)-1;
3556  register int j = (int)size-1;
3557  register int y;
3558 
3559  while (i >= 0) {
3560  y = grey16[i--];
3561  grey[j--] = static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3562  }
3563 }
3564 
3575 void vpImageConvert::MONO16ToRGBa(unsigned char *grey16, unsigned char *rgba,
3576  unsigned int size)
3577 {
3578  register int i = (((int)size)<<1)-1;
3579  register int j = (int)(size*4-1);
3580  register int y;
3581  register unsigned char v;
3582 
3583  while (i >= 0) {
3584  y = grey16[i--];
3585  v = static_cast<unsigned char>( (y+(grey16[i--]<<8))>>8 );
3586  rgba[j--] = 0;
3587  rgba[j--] = v;
3588  rgba[j--] = v;
3589  rgba[j--] = v;
3590  }
3591 }
3592 
3593 /*
3594  * Local variables:
3595  * c-basic-offset: 2
3596  * End:
3597  */
unsigned int getCols() const
Definition: vpImage.h:178
#define vpDEBUG_TRACE
Definition: vpDebug.h:454
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:662
unsigned char B
Blue component.
Definition: vpRGBa.h:155
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)
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:535
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:154
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:156
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
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:153
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)