47 #include <visp3/core/vpConfig.h>
48 #include <visp3/core/vpDebug.h>
49 #include <visp3/core/vpException.h>
50 #include <visp3/core/vpImageException.h>
51 #include <visp3/core/vpImagePoint.h>
52 #include <visp3/core/vpRGBa.h>
53 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
54 # include <visp3/core/vpThread.h>
121 std::ostream& operator<<(std::ostream&, const vpImage<Type>&);
123 std::ostream& operator<<(std::ostream&, const vpImage<unsigned char>&);
124 std::ostream& operator<<(std::ostream&, const vpImage<char>&);
125 std::ostream& operator<<(std::ostream&, const vpImage<float>&);
126 std::ostream& operator<<(std::ostream&, const vpImage<double>&);
142 vpImage(
unsigned int height,
unsigned int width) ;
144 vpImage(
unsigned int height,
unsigned int width, Type value) ;
146 vpImage(Type *
const array,
const unsigned int height,
const unsigned int width,
const bool copyData=
false) ;
166 inline unsigned int getCols()
const {
return width ; }
175 inline unsigned int getHeight()
const {
return height; }
204 inline unsigned int getRows()
const {
return height ; }
212 inline unsigned int getSize()
const {
return width*height ; }
215 Type
getValue(
double i,
double j)
const;
226 inline unsigned int getWidth()
const {
return width; }
232 void init(
unsigned int height,
unsigned int width) ;
234 void init(
unsigned int height,
unsigned int width, Type value) ;
236 void init(Type *
const array,
const unsigned int height,
const unsigned int width,
const bool copyData=
false);
243 inline Type *
operator[](
const unsigned int i) {
return row[i];}
247 inline const Type *
operator[](
unsigned int i)
const {
return row[i];}
257 inline Type
operator()(
const unsigned int i,
const unsigned int j)
const
259 return bitmap[i*width+j] ;
266 inline void operator()(
const unsigned int i,
const unsigned int j,
284 unsigned int i = (
unsigned int) ip.
get_i();
285 unsigned int j = (
unsigned int) ip.
get_j();
287 return bitmap[i*width+j] ;
300 unsigned int i = (
unsigned int) ip.
get_i();
301 unsigned int j = (
unsigned int) ip.
get_j();
314 friend std::ostream& operator<< <> (std::ostream &s,
const vpImage<Type> &I);
315 friend std::ostream& operator<<(std::ostream &s, const vpImage<unsigned char> &I);
316 friend std::ostream& operator<<(std::ostream &s, const vpImage<char> &I);
317 friend std::ostream& operator<<(std::ostream &s, const vpImage<float> &I);
318 friend std::ostream& operator<<(std::ostream &s, const vpImage<double> &I);
321 void performLut(
const Type (&lut)[256],
const unsigned int nbThreads=1);
327 void resize(
const unsigned int h,
const unsigned int w);
329 void resize(
const unsigned int h,
const unsigned int w,
const Type val);
338 unsigned int npixels ;
340 unsigned int height ;
345 std::ostream& operator<<(std::ostream &s, const vpImage<Type> &I) {
350 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
351 for (
unsigned int j = 0; j < I.
getWidth()-1; j++) {
359 if (i < I.getHeight()-1) {
367 inline std::ostream& operator<<(std::ostream &s, const vpImage<unsigned char> &I) {
372 std::ios_base::fmtflags original_flags = s.flags();
374 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
375 for (
unsigned int j = 0; j < I.
getWidth()-1; j++) {
376 s << std::setw(3) << static_cast<unsigned>(I[i][j]) <<
" ";
380 s << std::setw(3) << static_cast<unsigned>(I[i][I.
getWidth() -1]);
388 s.flags(original_flags);
392 inline std::ostream& operator<<(std::ostream &s, const vpImage<char> &I) {
397 std::ios_base::fmtflags original_flags = s.flags();
399 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
400 for (
unsigned int j = 0; j < I.
getWidth()-1; j++) {
401 s <<std::setw(4) << static_cast<int>(I[i][j]) <<
" ";
405 s << std::setw(4) << static_cast<int>(I[i][I.
getWidth() -1]);
413 s.flags(original_flags);
417 inline std::ostream& operator<<(std::ostream &s, const vpImage<float> &I) {
422 std::ios_base::fmtflags original_flags = s.flags();
425 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
426 for (
unsigned int j = 0; j < I.
getWidth()-1; j++) {
434 if (i < I.getHeight()-1) {
439 s.flags(original_flags);
443 inline std::ostream& operator<<(std::ostream &s, const vpImage<double> &I) {
448 std::ios_base::fmtflags original_flags = s.flags();
451 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
452 for (
unsigned int j = 0; j < I.
getWidth()-1; j++) {
460 if (i < I.getHeight()-1) {
465 s.flags(original_flags);
470 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
472 struct ImageLut_Param_t {
473 unsigned int m_start_index;
474 unsigned int m_end_index;
476 unsigned char m_lut[256];
477 unsigned char *m_bitmap;
479 ImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(NULL) {
482 ImageLut_Param_t(
const unsigned int start_index,
const unsigned int end_index,
483 unsigned char *bitmap) :
484 m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap) {
489 ImageLut_Param_t *imageLut_param = ( (ImageLut_Param_t *) args );
490 unsigned int start_index = imageLut_param->m_start_index;
491 unsigned int end_index = imageLut_param->m_end_index;
493 unsigned char *bitmap = imageLut_param->m_bitmap;
495 unsigned char *ptrStart = bitmap + start_index;
496 unsigned char *ptrEnd = bitmap + end_index;
497 unsigned char *ptrCurrent = ptrStart;
505 if(end_index - start_index >= 8) {
507 for(; ptrCurrent <= ptrEnd - 8;) {
508 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
511 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
514 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
517 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
520 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
523 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
526 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
529 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
534 for(; ptrCurrent != ptrEnd; ++ptrCurrent) {
535 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
542 struct ImageLutRGBa_Param_t {
543 unsigned int m_start_index;
544 unsigned int m_end_index;
547 unsigned char *m_bitmap;
549 ImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(NULL) {
552 ImageLutRGBa_Param_t(
const unsigned int start_index,
const unsigned int end_index,
553 unsigned char *bitmap) :
554 m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap) {
559 ImageLutRGBa_Param_t *imageLut_param = ( (ImageLutRGBa_Param_t *) args );
560 unsigned int start_index = imageLut_param->m_start_index;
561 unsigned int end_index = imageLut_param->m_end_index;
563 unsigned char *bitmap = imageLut_param->m_bitmap;
565 unsigned char *ptrStart = bitmap + start_index*4;
566 unsigned char *ptrEnd = bitmap + end_index*4;
567 unsigned char *ptrCurrent = ptrStart;
570 if(end_index - start_index >= 4*2) {
572 for(; ptrCurrent <= ptrEnd - 4*2;) {
573 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
575 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
577 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
579 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
582 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
584 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
586 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
588 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
593 while(ptrCurrent != ptrEnd) {
594 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
597 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
600 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
603 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
640 for (
unsigned int i=0 ; i < npixels ; i++)
666 if (h != this->height) {
674 if ((h != this->height) || (w != this->width))
676 if (bitmap != NULL) {
686 npixels=width*height;
688 if (bitmap == NULL) bitmap =
new Type[npixels] ;
695 "cannot allocate bitmap ")) ;
698 if (row == NULL) row =
new Type*[height] ;
704 "cannot allocate row ")) ;
708 for ( i =0 ; i < height ; i++)
709 row[i] = bitmap + i*width ;
728 if (h != this->height) {
736 if ( (copyData && ((h != this->height) || (w != this->width))) || !copyData ) {
737 if (bitmap != NULL) {
746 npixels = width*height;
749 if (bitmap == NULL) bitmap =
new Type[npixels];
751 if (bitmap == NULL) {
753 "cannot allocate bitmap ")) ;
757 memcpy(bitmap, array, (
size_t) (npixels *
sizeof(Type)));
763 if (row == NULL) row =
new Type*[height];
766 "cannot allocate row ")) ;
769 for (
unsigned int i = 0 ; i < height ; i++) {
770 row[i] = bitmap + i*width;
794 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
825 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
854 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
858 init(array, h, w, copyData);
877 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
1000 template<
class Type>
1002 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL)
1007 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
1008 for (
unsigned int i =0 ; i < this->height ; i++) row[i] = bitmap + i*this->width ;
1022 template<
class Type>
1025 Type m = bitmap[0] ;
1026 for (
unsigned int i=0 ; i < npixels ; i++)
1028 if (bitmap[i]>m) m = bitmap[i] ;
1038 template<
class Type>
1042 for (
unsigned int i=0 ; i < npixels ; i++)
1043 if (bitmap[i]<m) m = bitmap[i] ;
1054 template<
class Type>
1057 min = max = bitmap[0];
1058 for (
unsigned int i=0 ; i < npixels ; i++)
1060 if (bitmap[i]<min) min = bitmap[i] ;
1061 if (bitmap[i]>max) max = bitmap[i] ;
1068 template<
class Type>
1081 this->width = I.width;
1082 this->height = I.height;
1083 this->npixels = I.npixels;
1088 if (bitmap == NULL){
1089 bitmap =
new Type[npixels] ;
1092 if (bitmap == NULL){
1095 "cannot allocate bitmap ")) ;
1099 row =
new Type*[height] ;
1104 "cannot allocate row ")) ;
1107 memcpy(bitmap, I.
bitmap, I.npixels*
sizeof(Type)) ;
1109 for (
unsigned int i=0; i<this->height; i++){
1110 row[i] = bitmap + i*this->width;
1129 template<
class Type>
1132 for (
unsigned int i=0 ; i < npixels ; i++)
1143 template<
class Type>
1152 for (
unsigned int i=0 ; i < npixels ; i++)
1154 if (bitmap[i] != I.
bitmap[i]) {
1166 template<
class Type>
1180 return !(*
this == I);
1208 template<
class Type>
1225 template<
class Type>
1231 int itl = (int)topLeft.
get_i();
1232 int jtl = (int)topLeft.
get_j();
1234 int dest_ibegin = 0;
1235 int dest_jbegin = 0;
1238 int dest_w = (int)this->getWidth();
1239 int dest_h = (int)this->getHeight();
1245 if (itl >= dest_h || jtl >= dest_w)
1258 if (src_w - src_jbegin > dest_w - dest_jbegin)
1259 wsize = dest_w - dest_jbegin;
1261 wsize = src_w - src_jbegin;
1263 if (src_h - src_ibegin > dest_h - dest_ibegin)
1264 hsize = dest_h - dest_ibegin;
1266 hsize = src_h - src_ibegin;
1268 for (
int i = 0; i < hsize; i++)
1270 srcBitmap = src.
bitmap + ((src_ibegin+i)*src_w+src_jbegin);
1271 destBitmap = this->bitmap + ((dest_ibegin+i)*dest_w+dest_jbegin);
1273 memcpy(destBitmap, srcBitmap, (
size_t)wsize*
sizeof(Type));
1307 template<
class Type>
1311 unsigned int h = height/2;
1312 unsigned int w = width/2;
1314 for(
unsigned int i = 0; i < h; i++)
1315 for(
unsigned int j = 0; j < w; j++)
1316 res[i][j] = (*
this)[i<<1][j<<1];
1336 template<
class Type>
1340 unsigned int h = height/v_scale;
1341 unsigned int w = width/h_scale;
1343 for(
unsigned int i = 0; i < h; i++)
1344 for(
unsigned int j = 0; j < w; j++)
1345 sampled[i][j] = (*
this)[i*v_scale][j*h_scale];
1372 template<
class Type>
1376 unsigned int h = height/4;
1377 unsigned int w = width/4;
1379 for(
unsigned int i = 0; i < h; i++)
1380 for(
unsigned int j = 0; j < w; j++)
1381 res[i][j] = (*
this)[i<<2][j<<2];
1417 template<
class Type>
1426 for(
int i = 0; i < h; i++)
1427 for(
int j = 0; j < w; j++)
1428 res[i][j] = (*
this)[i>>1][j>>1];
1439 for(
int i = 0; i < h; i += 2)
1440 for(
int j = 1; j < w - 1; j += 2)
1441 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1442 + (*this)[i>>1][(j>>1) + 1]));
1445 for(
int i = 1; i < h - 1; i += 2)
1446 for(
int j = 0; j < w; j += 2)
1447 res[i][j] = (Type)(0.5 * ((*this)[i>>1][j>>1]
1448 + (*this)[(i>>1)+1][j>>1]));
1451 for(
int i = 1; i < h - 1; i += 2)
1452 for(
int j = 1; j < w - 1; j += 2)
1453 res[i][j] = (Type)(0.25 * ((*this)[i>>1][j>>1]
1454 + (*this)[i>>1][(j>>1)+1]
1455 + (*
this)[(i>>1)+1][j>>1]
1456 + (*
this)[(i>>1)+1][(j>>1)+1]));
1476 template<
class Type>
1479 unsigned int iround, jround;
1480 double rfrac, cfrac;
1482 iround = (
unsigned int)floor(i);
1483 jround = (
unsigned int)floor(j);
1485 if (iround >= height || jround >= width) {
1488 "Pixel outside the image"));
1492 i = (double)(height - 1);
1495 j = (double)(width - 1);
1497 double rratio = i - (double) iround;
1500 double cratio = j - (double) jround;
1504 rfrac = 1.0f - rratio;
1505 cfrac = 1.0f - cratio;
1507 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1508 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1532 unsigned int iround, jround;
1533 double rfrac, cfrac;
1535 iround = (
unsigned int)floor(i);
1536 jround = (
unsigned int)floor(j);
1538 if (iround >= height || jround >= width) {
1541 "Pixel outside the image"));
1545 i = (double)(height - 1);
1548 j = (double)(width - 1);
1550 double rratio = i - (double) iround;
1553 double cratio = j - (double) jround;
1557 rfrac = 1.0f - rratio;
1558 cfrac = 1.0f - cratio;
1561 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1562 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1569 unsigned int iround, jround;
1570 double rfrac, cfrac;
1572 iround = (
unsigned int)floor(i);
1573 jround = (
unsigned int)floor(j);
1575 if (iround >= height || jround >= width) {
1578 "Pixel outside the image"));
1582 i = (double)(height - 1);
1585 j = (double)(width - 1);
1587 double rratio = i - (double) iround;
1590 double cratio = j - (double) jround;
1594 rfrac = 1.0f - rratio;
1595 cfrac = 1.0f - cratio;
1597 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1598 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1599 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1600 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1601 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1602 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1622 template<
class Type>
1625 unsigned int iround, jround;
1626 double rfrac, cfrac;
1628 iround = (
unsigned int)floor(ip.
get_i());
1629 jround = (
unsigned int)floor(ip.
get_j());
1631 if (iround >= height || jround >= width) {
1634 "Pixel outside the image"));
1637 if (ip.
get_i() > height - 1)
1638 ip.
set_i((
double)(height - 1));
1640 if (ip.
get_j() > width - 1)
1641 ip.
set_j((
double)(width - 1));
1643 double rratio = ip.
get_i() - (double) iround;
1646 double cratio = ip.
get_j() - (double) jround;
1650 rfrac = 1.0f - rratio;
1651 cfrac = 1.0f - cratio;
1653 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1654 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1661 unsigned int iround, jround;
1662 double rfrac, cfrac;
1664 iround = (
unsigned int)floor(ip.
get_i());
1665 jround = (
unsigned int)floor(ip.
get_j());
1667 if (iround >= height || jround >= width) {
1670 "Pixel outside the image"));
1673 if (ip.
get_i() > height - 1)
1674 ip.
set_i((
double)(height - 1));
1676 if (ip.
get_j() > width - 1)
1677 ip.
set_j((
double)(width - 1));
1679 double rratio = ip.
get_i() - (double) iround;
1682 double cratio = ip.
get_j() - (double) jround;
1686 rfrac = 1.0f - rratio;
1687 cfrac = 1.0f - cratio;
1690 double value = ((double)row[iround][jround] * rfrac + (
double)row[iround+1][jround] * rratio)*cfrac
1691 + ((
double)row[iround][jround+1]*rfrac + (double)row[iround+1][jround+1] * rratio)*cratio;
1698 unsigned int iround, jround;
1699 double rfrac, cfrac;
1701 iround = (
unsigned int)floor(ip.
get_i());
1702 jround = (
unsigned int)floor(ip.
get_j());
1704 if (iround >= height || jround >= width) {
1707 "Pixel outside the image"));
1710 if (ip.
get_i() > height - 1)
1711 ip.
set_i((
double)(height - 1));
1713 if (ip.
get_j() > width - 1)
1714 ip.
set_j((
double)(width - 1));
1716 double rratio = ip.
get_i() - (double) iround;
1719 double cratio = ip.
get_j() - (double) jround;
1723 rfrac = 1.0f - rratio;
1724 cfrac = 1.0f - cratio;
1726 double valueR = ((double)row[iround][jround].R * rfrac + (
double)row[iround+1][jround].R * rratio)*cfrac
1727 + ((
double)row[iround][jround+1].R * rfrac + (double)row[iround+1][jround+1].R * rratio)*cratio;
1728 double valueG = ((double)row[iround][jround].G * rfrac + (
double)row[iround+1][jround].G * rratio)*cfrac
1729 + ((
double)row[iround][jround+1].G* rfrac + (double)row[iround+1][jround+1].G * rratio)*cratio;
1730 double valueB = ((double)row[iround][jround].B * rfrac + (
double)row[iround+1][jround].B * rratio)*cfrac
1731 + ((
double)row[iround][jround+1].B*rfrac + (double)row[iround+1][jround+1].B * rratio)*cratio;
1764 template<
class Type>
1770 if ((this->getHeight() != C.
getHeight())
1771 || (this->getWidth() != C.
getWidth()))
1772 C.
resize(this->getHeight(), this->getWidth());
1777 std::cout << me << std::endl ;
1783 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1785 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1788 for (
unsigned int i=0;i<this->getWidth()*this->getHeight();i++)
1805 template<
class Type>
1819 std::cout << me << std::endl ;
1825 vpERROR_TRACE(
"\n\t\t vpImage mismatch in vpImage/vpImage substraction") ;
1827 "vpImage mismatch in vpImage/vpImage substraction ")) ;
1845 template<
class Type>
1849 std::cerr <<
"Not implemented !" << std::endl;
1861 unsigned char *ptrStart = (
unsigned char*) bitmap;
1862 unsigned char *ptrEnd = ptrStart + size;
1863 unsigned char *ptrCurrent = ptrStart;
1866 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
1867 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
1868 use_single_thread =
true;
1871 if(!use_single_thread &&
getSize() <= nbThreads) {
1872 use_single_thread =
true;
1876 if(use_single_thread) {
1879 while(ptrCurrent != ptrEnd) {
1880 *ptrCurrent = lut[*ptrCurrent];
1884 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
1887 std::vector<vpThread *> threadpool;
1888 std::vector<ImageLut_Param_t *> imageLutParams;
1890 ImageLut_Param_t *imageLut_param = NULL;
1893 unsigned int image_size =
getSize();
1894 unsigned int step = image_size / nbThreads;
1895 unsigned int last_step = image_size - step * (nbThreads-1);
1897 for(
unsigned int index = 0; index < nbThreads; index++) {
1898 unsigned int start_index = index*step;
1899 unsigned int end_index = (index+1)*step;
1901 if(index == nbThreads-1) {
1902 end_index = start_index+last_step;
1905 imageLut_param =
new ImageLut_Param_t(start_index, end_index, bitmap);
1906 memcpy(imageLut_param->m_lut, lut, 256*
sizeof(
unsigned char));
1908 imageLutParams.push_back(imageLut_param);
1912 threadpool.push_back(imageLut_thread);
1915 for(
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
1917 threadpool[cpt]->join();
1922 for(
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
1923 delete threadpool[cpt];
1926 for(
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
1927 delete imageLutParams[cpt];
1942 unsigned char *ptrStart = (
unsigned char*) bitmap;
1943 unsigned char *ptrEnd = ptrStart + size*4;
1944 unsigned char *ptrCurrent = ptrStart;
1947 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
1948 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
1949 use_single_thread =
true;
1952 if(!use_single_thread &&
getSize() <= nbThreads) {
1953 use_single_thread =
true;
1957 if(use_single_thread) {
1959 while(ptrCurrent != ptrEnd) {
1960 *ptrCurrent = lut[*ptrCurrent].R;
1963 *ptrCurrent = lut[*ptrCurrent].G;
1966 *ptrCurrent = lut[*ptrCurrent].B;
1969 *ptrCurrent = lut[*ptrCurrent].A;
1973 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
1975 std::vector<vpThread *> threadpool;
1976 std::vector<ImageLutRGBa_Param_t *> imageLutParams;
1978 ImageLutRGBa_Param_t *imageLut_param = NULL;
1981 unsigned int image_size =
getSize();
1982 unsigned int step = image_size / nbThreads;
1983 unsigned int last_step = image_size - step * (nbThreads-1);
1985 for(
unsigned int index = 0; index < nbThreads; index++) {
1986 unsigned int start_index = index*step;
1987 unsigned int end_index = (index+1)*step;
1989 if(index == nbThreads-1) {
1990 end_index = start_index+last_step;
1993 imageLut_param =
new ImageLutRGBa_Param_t(start_index, end_index, (
unsigned char *) bitmap);
1994 memcpy(imageLut_param->m_lut, lut, 256*
sizeof(
vpRGBa));
1996 imageLutParams.push_back(imageLut_param);
2000 threadpool.push_back(imageLut_thread);
2003 for(
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2005 threadpool[cpt]->join();
2010 for(
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
2011 delete threadpool[cpt];
2014 for(
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
2015 delete imageLutParams[cpt];
void quarterSizeImage(vpImage< Type > &res) const
unsigned int getCols() const
void doubleSizeImage(vpImage< Type > &res)
Class that defines generic functionnalities for display.
unsigned int getWidth() const
void init(unsigned int height, unsigned int width)
Set the size of the image.
Type operator()(const unsigned int i, const unsigned int j) const
void getMinMaxValue(Type &min, Type &max) const
Look for the minimum and the maximum value within the bitmap.
Type * bitmap
points toward the bitmap
Type operator()(const vpImagePoint &ip) const
error that can be emited by ViSP classes.
Type getValue(double i, double j) const
Type getMinValue() const
Return the minimum value within the bitmap.
Type * operator[](const unsigned int i)
operator[] allows operation like I[i] = x.
virtual ~vpImage()
destructor
static int round(const double x)
unsigned int getRows() const
void set_i(const double ii)
vpImage< Type > & operator=(const vpImage< Type > &I)
Copy operator.
unsigned int getSize() const
bool operator!=(const vpImage< Type > &I)
void operator()(const vpImagePoint &ip, const Type &v)
Type getMaxValue() const
Return the maximum value within the bitmap.
const Type * operator[](int i) const
unsigned int getNumberOfPixel() const
void resize(const unsigned int h, const unsigned int w)
resize the image : Image initialization
void destroy()
Destructor : Memory de-allocation.
const Type * operator[](unsigned int i) const
operator[] allows operation like x = I[i]
void set_j(const double jj)
void subsample(unsigned int v_scale, unsigned int h_scale, vpImage< Type > &sampled) const
void halfSizeImage(vpImage< Type > &res) const
void insert(const vpImage< Type > &src, const vpImagePoint topLeft)
Type * operator[](const int i)
vpImage< Type > operator-(const vpImage< Type > &B)
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void operator()(const unsigned int i, const unsigned int j, const Type &v)
void performLut(const Type(&lut)[256], const unsigned int nbThreads=1)
Definition of the vpImage class member functions.
bool operator==(const vpImage< Type > &I)
void sub(const vpImage< Type > &B, vpImage< Type > &C)