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>
64 #if defined(_MSC_VER) && (_MSC_VER < 1700)
65 typedef long long int64_t;
66 typedef unsigned short uint16_t;
68 # include <inttypes.h>
73 #if defined(__GLIBC__) || (defined(__GNUC__) && !defined(__llvm__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && defined(__BYTE_ORDER__))
75 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
76 #define VISP_LITTLE_ENDIAN
77 #elif (__BYTE_ORDER == __BIG_ENDIAN)
78 #define VISP_BIG_ENDIAN
79 #elif (__BYTE_ORDER == __PDP_ENDIAN)
81 #define VISP_PDP_ENDIAN
84 #error Unknown machine endianness detected.
86 #elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) || defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
87 #define VISP_BIG_ENDIAN
88 #elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) || defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
89 #define VISP_LITTLE_ENDIAN
90 #elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \
91 defined(__hpux) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
93 #define VISP_BIG_ENDIAN
94 #elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || \
95 defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \
96 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__ANDROID__)
99 #define VISP_LITTLE_ENDIAN
100 #elif defined(WINRT) // For UWP
102 #define VISP_LITTLE_ENDIAN
104 #error Cannot detect host machine endianness.
172 template <
class Type>
class vpImage
184 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
188 vpImage(
unsigned int height,
unsigned int width);
191 vpImage(
unsigned int height,
unsigned int width, Type value);
193 vpImage(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
213 inline unsigned int getCols()
const {
return width; }
222 inline unsigned int getHeight()
const {
return height; }
252 inline unsigned int getRows()
const {
return height; }
261 inline unsigned int getSize()
const {
return width * height; }
264 Type
getValue(
unsigned int i,
unsigned int j)
const;
280 inline unsigned int getWidth()
const {
return width; }
286 void init(
unsigned int height,
unsigned int width);
288 void init(
unsigned int height,
unsigned int width, Type value);
290 void init(Type *
const array,
unsigned int height,
unsigned int width,
bool copyData =
false);
301 inline const Type *
operator[](
unsigned int i)
const {
return row[i]; }
302 inline const Type *
operator[](
int i)
const {
return row[i]; }
310 inline Type
operator()(
unsigned int i,
unsigned int j)
const {
return bitmap[i * width + j]; }
316 inline void operator()(
unsigned int i,
unsigned int j,
const Type &v) {
bitmap[i * width + j] = v; }
330 unsigned int i = (
unsigned int)ip.
get_i();
331 unsigned int j = (
unsigned int)ip.
get_j();
333 return bitmap[i * width + j];
346 unsigned int i = (
unsigned int)ip.
get_i();
347 unsigned int j = (
unsigned int)ip.
get_j();
349 bitmap[i * width + j] = v;
360 friend std::ostream &operator<< <>(std::ostream &s,
const vpImage<Type> &I);
367 void performLut(
const Type (&lut)[256],
unsigned int nbThreads = 1);
373 void resize(
unsigned int h,
unsigned int w);
375 void resize(
unsigned int h,
unsigned int w,
const Type &val);
386 unsigned int npixels;
399 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
400 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
422 std::ios_base::fmtflags original_flags = s.flags();
424 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
425 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
426 s << std::setw(3) << static_cast<unsigned>(I[i][j]) <<
" ";
430 s << std::setw(3) << static_cast<unsigned>(I[i][I.
getWidth() - 1]);
438 s.flags(original_flags);
448 std::ios_base::fmtflags original_flags = s.flags();
450 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
451 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
452 s << std::setw(4) << static_cast<int>(I[i][j]) <<
" ";
456 s << std::setw(4) << static_cast<int>(I[i][I.
getWidth() - 1]);
464 s.flags(original_flags);
474 std::ios_base::fmtflags original_flags = s.flags();
477 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
478 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
491 s.flags(original_flags);
501 std::ios_base::fmtflags original_flags = s.flags();
504 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
505 for (
unsigned int j = 0; j < I.
getWidth() - 1; j++) {
518 s.flags(original_flags);
522 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
525 struct ImageLut_Param_t {
526 unsigned int m_start_index;
527 unsigned int m_end_index;
529 unsigned char m_lut[256];
530 unsigned char *m_bitmap;
532 ImageLut_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(NULL) {}
534 ImageLut_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
535 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
542 ImageLut_Param_t *imageLut_param =
static_cast<ImageLut_Param_t *
>(args);
543 unsigned int start_index = imageLut_param->m_start_index;
544 unsigned int end_index = imageLut_param->m_end_index;
546 unsigned char *bitmap = imageLut_param->m_bitmap;
548 unsigned char *ptrStart = bitmap + start_index;
549 unsigned char *ptrEnd = bitmap + end_index;
550 unsigned char *ptrCurrent = ptrStart;
557 if (end_index - start_index >= 8) {
559 for (; ptrCurrent <= ptrEnd - 8;) {
560 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
563 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
566 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
569 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
572 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
575 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
578 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
581 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
586 for (; ptrCurrent != ptrEnd; ++ptrCurrent) {
587 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent];
593 struct ImageLutRGBa_Param_t {
594 unsigned int m_start_index;
595 unsigned int m_end_index;
598 unsigned char *m_bitmap;
600 ImageLutRGBa_Param_t() : m_start_index(0), m_end_index(0), m_lut(), m_bitmap(NULL) {}
602 ImageLutRGBa_Param_t(
unsigned int start_index,
unsigned int end_index,
unsigned char *bitmap)
603 : m_start_index(start_index), m_end_index(end_index), m_lut(), m_bitmap(bitmap)
610 ImageLutRGBa_Param_t *imageLut_param =
static_cast<ImageLutRGBa_Param_t *
>(args);
611 unsigned int start_index = imageLut_param->m_start_index;
612 unsigned int end_index = imageLut_param->m_end_index;
614 unsigned char *bitmap = imageLut_param->m_bitmap;
616 unsigned char *ptrStart = bitmap + start_index * 4;
617 unsigned char *ptrEnd = bitmap + end_index * 4;
618 unsigned char *ptrCurrent = ptrStart;
620 if (end_index - start_index >= 4 * 2) {
622 for (; ptrCurrent <= ptrEnd - 4 * 2;) {
623 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
625 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
627 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
629 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
632 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
634 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
636 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
638 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
643 while (ptrCurrent != ptrEnd) {
644 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].R;
647 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].G;
650 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].B;
653 *ptrCurrent = imageLut_param->m_lut[*ptrCurrent].A;
681 std::fill(bitmap, bitmap + npixels, value);
703 if (h != this->height) {
711 if ((h != this->height) || (w != this->width)) {
712 if (bitmap != NULL) {
724 npixels = width * height;
726 if (bitmap == NULL) {
727 bitmap =
new Type[npixels];
731 if (bitmap == NULL) {
736 row =
new Type *[height];
741 for (
unsigned int i = 0; i < height; i++)
742 row[i] = bitmap + i * width;
758 template <
class Type>
761 if (h != this->height) {
769 if ((copyData && ((h != this->height) || (w != this->width))) || !copyData) {
770 if (bitmap != NULL) {
778 hasOwnership = copyData;
782 npixels = width * height;
786 bitmap =
new Type[npixels];
788 if (bitmap == NULL) {
793 memcpy(
static_cast<void*
>(bitmap),
static_cast<void*
>(array), (
size_t)(npixels *
sizeof(Type)));
800 row =
new Type *[height];
805 for (
unsigned int i = 0; i < height; i++) {
806 row[i] = bitmap + i * width;
828 template <
class Type>
830 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
852 template <
class Type>
854 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
874 template <
class Type>
876 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
878 init(array, h, w, copyData);
891 bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
936 template <
class Type>
void vpImage<Type>::resize(
unsigned int h,
unsigned int w,
const Type &val) { init(h, w, val); }
948 if (bitmap != NULL) {
976 template <
class Type>
978 : bitmap(NULL), display(NULL), npixels(0), width(0), height(0), row(NULL), hasOwnership(true)
981 memcpy(
static_cast<void*
>(
bitmap),
static_cast<void*
>(I.
bitmap), I.npixels *
sizeof(Type));
984 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
988 template <
class Type>
990 : bitmap(I.bitmap), display(I.display), npixels(I.npixels), width(I.width), height(I.height), row(I.row), hasOwnership(I.hasOwnership)
998 I.hasOwnership =
false;
1012 for (
unsigned int i = 0; i < npixels; i++) {
1024 if ((height == 0) || (width == 0))
1027 return getSum() / (height * width);
1040 for (
unsigned int i = 0; i < npixels; i++)
1058 min = max = bitmap[0];
1059 for (
unsigned int i = 0; i < npixels; i++) {
1060 if (bitmap[i] < min)
1062 if (bitmap[i] > max)
1088 template <
class Type>
1093 "values of an empty image"));
1095 Type min = bitmap[0], max = bitmap[0];
1097 for (
unsigned int i = 0; i < height; i++) {
1098 for (
unsigned int j = 0; j < width; j++) {
1099 if (row[i][j] < min) {
1104 if (row[i][j] > max) {
1148 for (
unsigned int i = 0; i < npixels; i++)
1168 for (
unsigned int i = 0; i < npixels; i++) {
1169 if (bitmap[i] != I.
bitmap[i]) {
1184 return !(*
this == I);
1232 int itl = (int)topLeft.
get_i();
1233 int jtl = (int)topLeft.
get_j();
1235 int dest_ibegin = 0;
1236 int dest_jbegin = 0;
1239 int dest_w = (int)this->getWidth();
1240 int dest_h = (int)this->getHeight();
1241 int src_w = (int)src.getWidth();
1242 int src_h = (int)src.getHeight();
1243 int wsize = (int)src.getWidth();
1244 int hsize = (int)src.getHeight();
1246 if (itl >= dest_h || jtl >= dest_w)
1259 if (src_w - src_jbegin > dest_w - dest_jbegin)
1260 wsize = dest_w - dest_jbegin;
1262 wsize = src_w - src_jbegin;
1264 if (src_h - src_ibegin > dest_h - dest_ibegin)
1265 hsize = dest_h - dest_ibegin;
1267 hsize = src_h - src_ibegin;
1269 for (
int i = 0; i < hsize; i++) {
1270 Type *srcBitmap = src.bitmap + ((src_ibegin + i) * src_w + src_jbegin);
1271 Type *destBitmap = this->bitmap + ((dest_ibegin + i) * dest_w + dest_jbegin);
1273 memcpy(
static_cast<void*
>(destBitmap),
static_cast<void*
>(srcBitmap), (
size_t)wsize *
sizeof(Type));
1309 unsigned int h = height / 2;
1310 unsigned int w = width / 2;
1312 for (
unsigned int i = 0; i < h; i++)
1313 for (
unsigned int j = 0; j < w; j++)
1314 res[i][j] = (*
this)[i << 1][j << 1];
1334 template <
class Type>
1337 unsigned int h = height / v_scale;
1338 unsigned int w = width / h_scale;
1340 for (
unsigned int i = 0; i < h; i++)
1341 for (
unsigned int j = 0; j < w; j++)
1342 sampled[i][j] = (*
this)[i * v_scale][j * h_scale];
1369 unsigned int h = height / 4;
1370 unsigned int w = width / 4;
1372 for (
unsigned int i = 0; i < h; i++)
1373 for (
unsigned int j = 0; j < w; j++)
1374 res[i][j] = (*
this)[i << 2][j << 2];
1416 for (
int i = 0; i < h; i++)
1417 for (
int j = 0; j < w; j++)
1418 res[i][j] = (*
this)[i >> 1][j >> 1];
1429 for (
int i = 0; i < h; i += 2)
1430 for (
int j = 1; j < w - 1; j += 2)
1431 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1]));
1434 for (
int i = 1; i < h - 1; i += 2)
1435 for (
int j = 0; j < w; j += 2)
1436 res[i][j] = (Type)(0.5 * ((*this)[i >> 1][j >> 1] + (*this)[(i >> 1) + 1][j >> 1]));
1439 for (
int i = 1; i < h - 1; i += 2)
1440 for (
int j = 1; j < w - 1; j += 2)
1441 res[i][j] = (Type)(0.25 * ((*this)[i >> 1][j >> 1] + (*this)[i >> 1][(j >> 1) + 1] +
1442 (*
this)[(i >> 1) + 1][j >> 1] + (*
this)[(i >> 1) + 1][(j >> 1) + 1]));
1460 if (i >= height || j >= width) {
1486 if (i < 0 || j < 0 || i+1 > height || j+1 > width) {
1489 if (height * width == 0) {
1493 unsigned int iround =
static_cast<unsigned int>(floor(i));
1494 unsigned int jround =
static_cast<unsigned int>(floor(j));
1496 double rratio = i -
static_cast<double>(iround);
1497 double cratio = j -
static_cast<double>(jround);
1499 double rfrac = 1.0 - rratio;
1500 double cfrac = 1.0 - cratio;
1502 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1503 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1505 double value = (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1506 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) * cratio;
1529 if (i < 0 || j < 0 || i+1 > height || j+1 > width) {
1532 if (height * width == 0) {
1536 unsigned int iround =
static_cast<unsigned int>(floor(i));
1537 unsigned int jround =
static_cast<unsigned int>(floor(j));
1539 double rratio = i -
static_cast<double>(iround);
1540 double cratio = j -
static_cast<double>(jround);
1542 double rfrac = 1.0 - rratio;
1543 double cfrac = 1.0 - cratio;
1545 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1546 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1548 return (row[iround][jround] * rfrac + row[iround_1][jround] * rratio) * cfrac +
1549 (row[iround][jround_1] * rfrac + row[iround_1][jround_1] * rratio) * cratio;
1553 if (i < 0 || j < 0 || i+1 > height || j+1 > width) {
1556 if (height * width == 0) {
1560 #if defined(VISP_LITTLE_ENDIAN)
1562 const int precision = 1 << 16;
1563 int64_t y =
static_cast<int64_t
>(i * precision);
1564 int64_t x =
static_cast<int64_t
>(j * precision);
1566 int64_t iround = y & (~0xFFFF);
1567 int64_t jround = x & (~0xFFFF);
1569 int64_t rratio = y - iround;
1570 int64_t cratio = x - jround;
1572 int64_t rfrac = precision - rratio;
1573 int64_t cfrac = precision - cratio;
1575 int64_t x_ = x >> 16;
1576 int64_t y_ = y >> 16;
1578 if (y_ + 1 < height && x_ + 1 < width) {
1579 uint16_t up = *
reinterpret_cast<uint16_t *
>(
bitmap + y_ * width + x_);
1580 uint16_t down = *
reinterpret_cast<uint16_t *
>(
bitmap + (y_ + 1) * width + x_);
1582 return static_cast<unsigned char>((((up & 0x00FF) * rfrac + (down & 0x00FF) * rratio) * cfrac +
1583 ((up >> 8) * rfrac + (down >> 8) * rratio) * cratio) >> 32);
1584 }
else if (y_ + 1 < height) {
1585 return static_cast<unsigned char>(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16);
1586 }
else if (x_ + 1 < width) {
1587 uint16_t up = *
reinterpret_cast<uint16_t *
>(
bitmap + y_ * width + x_);
1588 return static_cast<unsigned char>(((up & 0x00FF) * cfrac + (up >> 8) * cratio) >> 16);
1592 #elif defined(VISP_BIG_ENDIAN)
1594 const int precision = 1 << 16;
1595 int64_t y =
static_cast<int64_t
>(i * precision);
1596 int64_t x =
static_cast<int64_t
>(j * precision);
1598 int64_t iround = y & (~0xFFFF);
1599 int64_t jround = x & (~0xFFFF);
1601 int64_t rratio = y - iround;
1602 int64_t cratio = x - jround;
1604 int64_t rfrac = precision - rratio;
1605 int64_t cfrac = precision - cratio;
1607 int64_t x_ = x >> 16;
1608 int64_t y_ = y >> 16;
1610 if (y_ + 1 < height && x_ + 1 < width) {
1611 uint16_t up = *
reinterpret_cast<uint16_t *
>(
bitmap + y_ * width + x_);
1612 uint16_t down = *
reinterpret_cast<uint16_t *
>(
bitmap + (y_ + 1) * width + x_);
1614 return static_cast<unsigned char>((((up >> 8) * rfrac + (down >> 8) * rratio) * cfrac +
1615 ((up & 0x00FF) * rfrac + (down & 0x00FF) * rratio) * cratio) >> 32);
1616 }
else if (y_ + 1 < height) {
1617 return static_cast<unsigned char>(((row[y_][x_] * rfrac + row[y_ + 1][x_] * rratio)) >> 16);
1618 }
else if (x_ + 1 < width) {
1619 uint16_t up = *
reinterpret_cast<uint16_t *
>(
bitmap + y_ * width + x_);
1620 return static_cast<unsigned char>(((up >> 8) * cfrac + (up & 0x00FF) * cratio) >> 16);
1625 unsigned int iround =
static_cast<unsigned int>(floor(i));
1626 unsigned int jround =
static_cast<unsigned int>(floor(j));
1628 if (iround >= height || jround >= width) {
1631 "Pixel outside the image"));
1634 double rratio = i -
static_cast<double>(iround);
1635 double cratio = j -
static_cast<double>(jround);
1637 double rfrac = 1.0 - rratio;
1638 double cfrac = 1.0 - cratio;
1640 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1641 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1643 double value = (
static_cast<double>(row[iround][jround]) * rfrac +
static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
1644 (
static_cast<double>(row[iround][jround_1]) * rfrac +
static_cast<double>(row[iround_1][jround_1]) * rratio) * cratio;
1651 if (i < 0 || j < 0 || i+1 > height || j+1 > width) {
1654 if (height * width == 0) {
1658 unsigned int iround =
static_cast<unsigned int>(floor(i));
1659 unsigned int jround =
static_cast<unsigned int>(floor(j));
1661 double rratio = i -
static_cast<double>(iround);
1662 double cratio = j -
static_cast<double>(jround);
1664 double rfrac = 1.0 - rratio;
1665 double cfrac = 1.0 - cratio;
1667 unsigned int iround_1 = (std::min)(height - 1, iround + 1);
1668 unsigned int jround_1 = (std::min)(width - 1, jround + 1);
1670 double valueR = (
static_cast<double>(row[iround][jround].R) * rfrac +
static_cast<double>(row[iround_1][jround].R) * rratio) * cfrac +
1671 (
static_cast<double>(row[iround][jround_1].R) * rfrac +
static_cast<double>(row[iround_1][jround_1].R) * rratio) * cratio;
1672 double valueG = (
static_cast<double>(row[iround][jround].G) * rfrac +
static_cast<double>(row[iround_1][jround].G) * rratio) * cfrac +
1673 (
static_cast<double>(row[iround][jround_1].G) * rfrac +
static_cast<double>(row[iround_1][jround_1].G) * rratio) * cratio;
1674 double valueB = (
static_cast<double>(row[iround][jround].B) * rfrac +
static_cast<double>(row[iround_1][jround].B) * rratio) * cfrac +
1675 (
static_cast<double>(row[iround][jround_1].B) * rfrac +
static_cast<double>(row[iround_1][jround_1].B) * rratio) * cratio;
1723 if ((height == 0) || (width == 0))
1727 for (
unsigned int i = 0; i < height * width; ++i) {
1728 res +=
static_cast<double>(bitmap[i]);
1767 C.
resize(this->getHeight(), this->getWidth());
1769 std::cout << me << std::endl;
1773 if ((this->getWidth() != B.
getWidth()) || (this->getHeight() != B.
getHeight())) {
1777 for (
unsigned int i = 0; i < this->getWidth() * this->getHeight(); i++) {
1800 std::cout << me << std::endl;
1825 std::cerr <<
"Not implemented !" << std::endl;
1840 unsigned char *ptrStart = (
unsigned char *)
bitmap;
1841 unsigned char *ptrEnd = ptrStart + size;
1842 unsigned char *ptrCurrent = ptrStart;
1844 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
1845 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
1846 use_single_thread =
true;
1849 if (!use_single_thread &&
getSize() <= nbThreads) {
1850 use_single_thread =
true;
1853 if (use_single_thread) {
1856 while (ptrCurrent != ptrEnd) {
1857 *ptrCurrent = lut[*ptrCurrent];
1861 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
1864 std::vector<vpThread *> threadpool;
1865 std::vector<ImageLut_Param_t *> imageLutParams;
1867 unsigned int image_size =
getSize();
1868 unsigned int step = image_size / nbThreads;
1869 unsigned int last_step = image_size - step * (nbThreads - 1);
1871 for (
unsigned int index = 0; index < nbThreads; index++) {
1872 unsigned int start_index = index * step;
1873 unsigned int end_index = (index + 1) * step;
1875 if (index == nbThreads - 1) {
1876 end_index = start_index + last_step;
1879 ImageLut_Param_t *imageLut_param =
new ImageLut_Param_t(start_index, end_index,
bitmap);
1880 memcpy(imageLut_param->m_lut, lut, 256 *
sizeof(
unsigned char));
1882 imageLutParams.push_back(imageLut_param);
1886 threadpool.push_back(imageLut_thread);
1889 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
1891 threadpool[cpt]->join();
1895 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
1896 delete threadpool[cpt];
1899 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
1900 delete imageLutParams[cpt];
1917 unsigned char *ptrStart = (
unsigned char *)
bitmap;
1918 unsigned char *ptrEnd = ptrStart + size * 4;
1919 unsigned char *ptrCurrent = ptrStart;
1921 bool use_single_thread = (nbThreads == 0 || nbThreads == 1);
1922 #if !defined(VISP_HAVE_PTHREAD) && !defined(_WIN32)
1923 use_single_thread =
true;
1926 if (!use_single_thread &&
getSize() <= nbThreads) {
1927 use_single_thread =
true;
1930 if (use_single_thread) {
1932 while (ptrCurrent != ptrEnd) {
1933 *ptrCurrent = lut[*ptrCurrent].R;
1936 *ptrCurrent = lut[*ptrCurrent].G;
1939 *ptrCurrent = lut[*ptrCurrent].B;
1942 *ptrCurrent = lut[*ptrCurrent].A;
1946 #if defined(VISP_HAVE_PTHREAD) || (defined(_WIN32) && !defined(WINRT_8_0))
1948 std::vector<vpThread *> threadpool;
1949 std::vector<ImageLutRGBa_Param_t *> imageLutParams;
1951 unsigned int image_size =
getSize();
1952 unsigned int step = image_size / nbThreads;
1953 unsigned int last_step = image_size - step * (nbThreads - 1);
1955 for (
unsigned int index = 0; index < nbThreads; index++) {
1956 unsigned int start_index = index * step;
1957 unsigned int end_index = (index + 1) * step;
1959 if (index == nbThreads - 1) {
1960 end_index = start_index + last_step;
1963 ImageLutRGBa_Param_t *imageLut_param =
new ImageLutRGBa_Param_t(start_index, end_index, (
unsigned char *)
bitmap);
1964 memcpy(imageLut_param->m_lut, lut, 256 *
sizeof(
vpRGBa));
1966 imageLutParams.push_back(imageLut_param);
1970 threadpool.push_back(imageLut_thread);
1973 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
1975 threadpool[cpt]->join();
1979 for (
size_t cpt = 0; cpt < threadpool.size(); cpt++) {
1980 delete threadpool[cpt];
1983 for (
size_t cpt = 0; cpt < imageLutParams.size(); cpt++) {
1984 delete imageLutParams[cpt];
1995 swap(first.npixels, second.npixels);
1996 swap(first.width, second.width);
1997 swap(first.height, second.height);
1998 swap(first.row, second.row);