58 VL_DEBUG_SET_OBJECT_NAME()
65 VL_DEBUG_SET_OBJECT_NAME()
68 mPixels->setUserAllocatedBuffer( buffer_ptr, buffer_bytes );
73 VL_DEBUG_SET_OBJECT_NAME()
81 VL_DEBUG_SET_OBJECT_NAME()
112 VL_DEBUG_SET_OBJECT_NAME()
141 bool z =
mWidth > 0 && mHeight > 0 && mDepth > 0;
145 bool okformat =
false;
283 Log::debug( isvalid ?
"" : ( okformat ?
"Image::isValid(): invalid dimensions or pitch/bytealign combination:\n" :
"Image::isValid() reported an invalid format/type combination:\n") +
print() );
291 std::map<int, const char*> ty;
325 std::map<int, const char*> fo;
392 case IT_BYTE: comp_size =
sizeof(GLbyte) * 8;
break;
394 case IT_SHORT: comp_size =
sizeof(GLshort) * 8;
break;
396 case IT_INT: comp_size =
sizeof(int) * 8;
break;
397 case IT_FLOAT: comp_size =
sizeof(float) * 8;
break;
419 case IF_RED:
return comp_size * 1;
420 case IF_GREEN:
return comp_size * 1;
421 case IF_BLUE:
return comp_size * 1;
422 case IF_ALPHA:
return comp_size * 1;
428 case IF_RG:
return comp_size * 2;
429 case IF_RGB:
return comp_size * 3;
430 case IF_BGR:
return comp_size * 3;
431 case IF_RGBA:
return comp_size * 4;
432 case IF_BGRA:
return comp_size * 4;
455 case IF_RED:
return comp_size * 0;
456 case IF_GREEN:
return comp_size * 0;
457 case IF_BLUE:
return comp_size * 0;
458 case IF_ALPHA:
return comp_size * 1;
464 case IF_RGB:
return comp_size * 0;
465 case IF_BGR:
return comp_size * 0;
466 case IF_RGBA:
return comp_size * 1;
467 case IF_BGRA:
return comp_size * 1;
485 case IT_BYTE: comp_size =
sizeof(GLbyte) * 8;
break;
487 case IT_SHORT: comp_size =
sizeof(GLshort) * 8;
break;
489 case IT_INT: comp_size =
sizeof(int) * 8;
break;
490 case IT_FLOAT: comp_size =
sizeof(float) * 8;
break;
558 bytealign =
sizeof(
unsigned char*);
576 int xbytes = xbits/8 + ( (xbits % 8) ? 1 : 0 );
600 Log::bug(
"Image::allocate1D() failed, probably your image settings are invalid.\n");
623 Log::bug(
"Image::allocate2D() failed, probably your image settings are invalid.\n");
647 Log::bug(
"Image::allocate3D() failed, probably your image settings are invalid.\n");
668 Log::bug(
"Image::allocateCubemap() failed, probably your image settings are invalid.\n");
710 super::operator=(other);
729 for(
int i=0; i<(int)
mMipmaps.size(); ++i)
866 const Image* img[] = {xp, xn, yp, yn, zp, zn};
871 Log::error(
"Cubemap creation failed: all the images must be square.\n");
875 for(
int i=0; i<6; ++i)
879 Log::error(
"Cubemap creation failed: one or more image is invalid (could be NULL, not allocated, not 2D, wrong internal_ configuration or other).\n");
886 Log::error(
"Cubemap creation failed: the faces of the cube must have the very same dimensions.\n");
893 Log::error(
"Cubemap creation failed: the faces of the cube must have the very same dimensions.\n");
900 Log::error(
"Cubemap creation failed: the faces of the cube must have the very same format.\n");
905 if (img[0]->
type() != img[i]->
type())
907 Log::error(
"Cubemap creation failed: the faces of the cube must have the very same type.\n");
914 Log::error(
"Cubemap creation failed: the faces of the cube must have the very same byte alignment.\n");
921 Log::error(
"Cubemap creation failed: the faces of the cube must require the very same amount of memory.\n");
939 return cubemap.
get();
948 int row_size =
pitch();
949 std::vector<unsigned char> row1;
950 row1.resize(row_size);
952 std::vector<unsigned char*> pxl;
956 pxl.push_back( (
unsigned char*)
pixels() );
961 pxl.push_back( (
unsigned char*)
pixelsXP() );
962 pxl.push_back( (
unsigned char*)
pixelsXN() );
963 pxl.push_back( (
unsigned char*)
pixelsYP() );
964 pxl.push_back( (
unsigned char*)
pixelsYN() );
965 pxl.push_back( (
unsigned char*)
pixelsZP() );
966 pxl.push_back( (
unsigned char*)
pixelsZN() );
971 for(
int zslice=0; zslice<
depth(); zslice++)
975 for(
unsigned img=0; img<pxl.size(); img++)
977 for(
int i=0; i<
height()/2; ++i)
980 memcpy(&row1[0], pxl[img]+i*row_size, row_size);
981 memcpy(pxl[img]+i*row_size, pxl[img]+j*row_size, row_size);
982 memcpy(pxl[img]+j*row_size, &row1[0], row_size);
1000 bytealign =
sizeof(
unsigned char*);
1012 width = width - width % 4 + 4;
1014 height = height - height % 4 + 4;
1022 int xbytes = xbits/8 + ( (xbits % 8) ? 1 : 0 );
1023 int pitch = xbytes/bytealign*bytealign + ( (xbytes % bytealign) ? bytealign : 0 );
1027 height = height ?
height : 1;
1028 depth = depth ?
depth : 1;
1029 int req_mem = pitch * height *
depth;
1056 std::vector<fvec4> colors;
1057 colors.push_back(c0); colors.push_back(c1);
1063 std::vector<fvec4> colors;
1064 colors.push_back(c0); colors.push_back(c1); colors.push_back(c2);
1070 std::vector<fvec4> colors;
1071 colors.push_back(c0); colors.push_back(c1); colors.push_back(c2); colors.push_back(c3);
1077 std::vector<fvec4> colors;
1078 colors.push_back(c0); colors.push_back(c1); colors.push_back(c2); colors.push_back(c3); colors.push_back(c4);
1084 std::vector<fvec4> colors;
1085 colors.push_back(c0); colors.push_back(c1); colors.push_back(c2); colors.push_back(c3); colors.push_back(c4); colors.push_back(c5);
1098 int last = (int)col_count-1;
1099 for(
int i=0; i<img->
width(); ++i)
1101 float t = (float)i/(img->
width()-1);
1103 px[i] = (
ubvec4)(colors[0]*255.0f);
1105 if (t>=col_pos[last])
1106 px[i] = (
ubvec4)(colors[last]*255.0f);
1109 for(
size_t j=0; j<col_count-1; ++j)
1111 if (t>=col_pos[j] && t<=col_pos[j+1])
1114 if (col_pos[j+1]-col_pos[j] != 0)
1115 tt = (t-col_pos[j])/(col_pos[j+1]-col_pos[j]);
1117 px[i] = (
ubvec4)((colors[j] * (1.0f-tt) + colors[j+1] * tt)*255.0f);
1128 if (colors.empty() || colors.size() != col_pos.size())
1137 int index = (int)colors.size() - 1;
1138 for(
int i=0; i<img->
width(); ++i)
1140 int coli = (int)(index * (
float)i/img->
width());
1141 float colt = (index * (float)i/img->
width()) - coli;
1142 img->
pixels()[i*4 + 0] = (
unsigned char)(255.0 * (colors[coli].r()*(1.0f-colt) + colors[coli+1].r()*colt));
1143 img->
pixels()[i*4 + 1] = (
unsigned char)(255.0 * (colors[coli].g()*(1.0f-colt) + colors[coli+1].g()*colt));
1144 img->
pixels()[i*4 + 2] = (
unsigned char)(255.0 * (colors[coli].b()*(1.0f-colt) + colors[coli+1].b()*colt));
1145 img->
pixels()[i*4 + 3] = 255;
1156 for(
unsigned i=1; i<images.size(); ++i)
1158 if (images[i]->
width() != images[0]->width())
return NULL;
1159 if (images[i]->
height() != images[0]->height())
return NULL;
1160 if (images[i]->
depth() != images[0]->depth())
return NULL;
1161 if (images[i]->
type() != images[0]->type())
return NULL;
1162 if (images[i]->
format() != images[0]->format())
return NULL;
1169 img->
allocate3D( images[0]->
width(), images[0]->
height(), images.size(), 1, images[0]->format(), images[0]->type() );
1171 for(
unsigned i=0; i<images.size(); ++i)
1174 memcpy(img->
pixelsZSlice(i), images[i]->pixels(), images[i]->requiredMemory());
1187 std::vector<String> files;
1189 std::sort(files.begin(), files.end());
1190 for(
unsigned i=0; i<files.size(); ++i)
1192 if (files[i].extractFileExtension().toLowerCase() == ext.
toLowerCase())
1194 images.push_back(
loadImage(files[i]) );
1195 if (images.back().get() ==
NULL)
1269 if (!xp || !xn || !yp || !yn || !zp || !zn)
1282 ref<Image> img =
new Image(width, height, depth, bytealign, format, type);
1285 bool ok = file_offset == -1 || file->
seekSet(file_offset);
1288 Log::error(
Say(
"loadRAW('%s'): seek set to position %n failed.\n") << file_offset );
1298 Log::error(
Say(
"loadRAW('%s'): could not open file for reading.\n") << file->
path() );
1316 Log::error(
"Image::convertType(): unsupported source image type.\n");
1331 Log::error(
"Image::convertType(): unsupported destination image type.\n");
1350 Log::error(
"Image::convertType(): unsupported image format.\n");
1370 case IF_RGB: components = 3;
break;
1371 case IF_RGBA: components = 4;
break;
1372 case IF_BGR: components = 3;
break;
1373 case IF_BGRA: components = 4;
break;
1374 case IF_RED: components = 1;
break;
1375 case IF_GREEN: components = 1;
break;
1376 case IF_BLUE: components = 1;
break;
1377 case IF_ALPHA: components = 1;
break;
1387 line_count *= img->
depth();
1392 for(
int i=0; i<line_count; ++i)
1397 const unsigned char* srcUByte = (
const unsigned char*)srcLine;
1398 const GLbyte* srcSByte = (
const GLbyte*)srcLine;
1399 const GLushort* srcUShort = (
const GLushort*)srcLine;
1400 const GLshort* srcSShort = (
const GLshort*)srcLine;
1401 const unsigned int* srcUInt = (
const unsigned int*)srcLine;
1402 const int* srcSInt = (
const int*)srcLine;
1403 const float* srcFloat = (
const float*)srcLine;
1405 unsigned char* dstUByte = (
unsigned char*)dstLine;
1406 GLbyte* dstSByte = (GLbyte*)dstLine;
1407 GLushort* dstUShort = (GLushort*)dstLine;
1408 GLshort* dstSShort = (GLshort*)dstLine;
1409 unsigned int* dstUInt = (
unsigned int*)dstLine;
1410 int* dstSInt = (
int*)dstLine;
1411 float* dstFloat = (
float*)dstLine;
1413 for(
int j=0; j<img->
width(); ++j)
1415 for(
int c=0; c<components; ++c)
1424 case IT_UNSIGNED_BYTE: qint = *srcUByte; dval = qint/255.0; ++srcUByte;
break;
1425 case IT_BYTE: qint = *srcSByte; dval = qint/127.0; ++srcSByte;
break;
1426 case IT_UNSIGNED_SHORT: qint = *srcUShort; dval = qint/65535.0; ++srcUShort;
break;
1427 case IT_SHORT: qint = *srcSShort; dval = qint/32767.0; ++srcSShort;
break;
1428 case IT_UNSIGNED_INT: qint = *srcUInt; dval = qint/4294967295.0; ++srcUInt;
break;
1429 case IT_INT: qint = *srcSInt; dval = qint/2147483647.0; ++srcSInt;
break;
1430 case IT_FLOAT: dval = *srcFloat; ++srcFloat;
break;
1436 dval = dval < 0.0 ? 0.0 :
1444 case IT_UNSIGNED_BYTE: *dstUByte = (
unsigned char) (dval*255.0); ++dstUByte;
break;
1445 case IT_BYTE: *dstSByte = (GLbyte) (dval*127.0); ++dstSByte;
break;
1446 case IT_UNSIGNED_SHORT: *dstUShort = (GLushort)(dval*65535.0); ++dstUShort;
break;
1447 case IT_SHORT: *dstSShort = (GLshort) (dval*32767.0); ++dstSShort;
break;
1448 case IT_UNSIGNED_INT: *dstUInt = (
unsigned int) (dval*4294967295.0); ++dstUInt;
break;
1449 case IT_INT: *dstSInt = (int) (dval*2147483647.0); ++dstSInt;
break;
1450 case IT_FLOAT: *dstFloat = (float)dval; ++dstFloat;
break;
1462 template<
typename T>
1463 void equalizeTemplate(
void* ptr,
int pitch,
int comps,
int w,
int h, T max_val)
1466 T vmin = *((T*)ptr);
1467 T vmax = *((T*)ptr);
1468 for(
int y=0; y<h; ++y)
1470 T* px = (T*)((
char*)ptr + pitch*y);
1471 for(
int x=0; x<w; ++x)
1473 for(
int i=0; i<comps; ++i)
1475 if (vmin > px[x*comps+i]) vmin = px[x*comps+i];
1476 if (vmax < px[x*comps+i]) vmax = px[x*comps+i];
1481 T range = vmax-vmin;
1482 for(
int y=0; y<h; ++y)
1484 T* px = (T*)((
char*)ptr + pitch*y);
1485 for(
int x=0; x<w; ++x)
1487 for(
int i=0; i<comps; ++i)
1488 px[x*comps+i] = (T)(((float)px[x*comps+i]-vmin)/range*max_val);
1500 case IF_RGB: comps = 3;
break;
1501 case IF_RGBA: comps = 4;
break;
1502 case IF_BGR: comps = 3;
break;
1503 case IF_BGRA: comps = 4;
break;
1504 case IF_RED: comps = 1;
break;
1506 case IF_BLUE: comps = 1;
break;
1512 Log::error(
"Image::equalize(): unsupported image format().\n");
1531 Log::error(
"Image::equalize(): unsupported image type(). Types supported are IT_UNSIGNED_BYTE, IT_UNSIGNED_SHORT, IT_UNSIGNED_INT, IT_FLOAT.\n");
1559 if ( !
tags()->has(
"WindowCenter") || !
tags()->has(
"WindowWidth") || !
tags()->has(
"BitsStored") || !
tags()->has(
"RescaleIntercept"))
1570 center = (center-intercept) / range / slope;
1571 width = width / range / slope;
1572 return contrast( center-width/2.0f, center+width/2.0f );
1589 center = (center-intercept) / range;
1590 width = width / range;
1591 return contrast( center-width/2.0f, center+width/2.0f );
1595 template<
typename T>
1596 void contrastTemplate(
void* ptr,
int pitch,
int w,
int h, T max_val,
float black,
float white)
1598 float range = white-black;
1599 for(
int y=0; y<h; ++y)
1601 T* px = (T*)((
char*)ptr + pitch*y);
1602 for(
int x=0; x<w; ++x)
1604 float t = (float)px[x]/max_val;
1605 t = (t-black)/range;
1607 px[x] = (T)(t*max_val);
1626 Log::error(
"Image::equalize(): unsupported image format().\n");
1642 case IT_FLOAT: contrastTemplate<float> (
pixels(),
pitch(), w, h, 1.0f, black, white);
break;
1645 Log::error(
"Image::equalize(): unsupported image type(). Types supported are IT_UNSIGNED_BYTE, IT_UNSIGNED_SHORT, IT_UNSIGNED_INT, IT_FLOAT.\n");
1656 rgbal(): r(-1), g(-1), b(-1), a(-1), l(-1) {}
1660 template<
typename T>
1661 void convert(
const T*src_px, T*dst_px, T max_value,
const rgbal& srco,
const rgbal& dsto)
1671 dst_px[dsto.a] = max_value;
1676 if (dsto.r != -1 && srco.r != -1 )
1677 dst_px[dsto.r] = src_px[srco.r];
1678 if (dsto.g != -1 && srco.g != -1)
1679 dst_px[dsto.g] = src_px[srco.g];
1680 if (dsto.b != -1 && srco.b != -1)
1681 dst_px[dsto.b] = src_px[srco.b];
1682 if (dsto.a != -1 && srco.a != -1)
1683 dst_px[dsto.a] = src_px[srco.a];
1684 if (dsto.l != -1 && srco.l != -1)
1685 dst_px[dsto.l] = src_px[srco.l];
1688 if (dsto.l != -1 && srco.r != -1 && srco.g != -1 && srco.b != -1)
1690 dvec3 col(src_px[srco.r], src_px[srco.g], src_px[srco.b]);
1691 double gray =
dot(col /
dvec3(max_value,max_value,max_value),
dvec3(0.299,0.587,0.114));
1692 dst_px[dsto.l] = T(gray * max_value);
1696 if (dsto.l != -1 && srco.r != -1 && srco.g == -1 && srco.b == -1)
1697 dst_px[dsto.l] = src_px[srco.r];
1700 if (dsto.l != -1 && srco.r == -1 && srco.g != -1 && srco.b == -1)
1701 dst_px[dsto.l] = src_px[srco.g];
1704 if (dsto.l != -1 && srco.r == -1 && srco.g == -1 && srco.b != -1)
1705 dst_px[dsto.l] = src_px[srco.b];
1711 dst_px[dsto.r] = src_px[srco.l];
1713 dst_px[dsto.g] = src_px[srco.l];
1715 dst_px[dsto.b] = src_px[srco.l];
1732 Log::error(
"Image::convertType(): unsupported image type.\n");
1750 Log::error(
"Image::convertType(): unsupported source image format.\n");
1768 Log::error(
"Image::convertType(): unsupported destination image format.\n");
1792 case IF_RGB: srco.r = 0; srco.g = 1; srco.b = 2;
break;
1793 case IF_RGBA: srco.r = 0; srco.g = 1; srco.b = 2; srco.a = 3;
break;
1794 case IF_BGR: srco.r = 2; srco.g = 1; srco.b = 0;
break;
1795 case IF_BGRA: srco.r = 2; srco.g = 1; srco.b = 0; srco.a = 3;
break;
1796 case IF_RED: srco.r = 0;
break;
1798 case IF_BLUE: srco.b = 0;
break;
1808 case IF_RGB: dsto.r = 0; dsto.g = 1; dsto.b = 2;
break;
1809 case IF_RGBA: dsto.r = 0; dsto.g = 1; dsto.b = 2; dsto.a = 3;
break;
1810 case IF_BGR: dsto.r = 2; dsto.g = 1; dsto.b = 0;
break;
1811 case IF_BGRA: dsto.r = 2; dsto.g = 1; dsto.b = 0; dsto.a = 3;
break;
1812 case IF_RED: dsto.r = 0;
break;
1814 case IF_BLUE: dsto.b = 0;
break;
1825 case IF_RGB: src_comp = 3;
break;
1826 case IF_RGBA: src_comp = 4;
break;
1827 case IF_BGR: src_comp = 3;
break;
1828 case IF_BGRA: src_comp = 4;
break;
1829 case IF_RED: src_comp = 1;
break;
1830 case IF_GREEN: src_comp = 1;
break;
1831 case IF_BLUE: src_comp = 1;
break;
1832 case IF_ALPHA: src_comp = 1;
break;
1842 case IF_RGB: dst_comp = 3;
break;
1843 case IF_RGBA: dst_comp = 4;
break;
1844 case IF_BGR: dst_comp = 3;
break;
1845 case IF_BGRA: dst_comp = 4;
break;
1846 case IF_RED: dst_comp = 1;
break;
1847 case IF_GREEN: dst_comp = 1;
break;
1848 case IF_BLUE: dst_comp = 1;
break;
1849 case IF_ALPHA: dst_comp = 1;
break;
1859 line_count *= img->
depth();
1864 for(
int i=0; i<line_count; ++i)
1869 const unsigned char* srcUByte = (
const unsigned char*)srcLine;
1870 const GLbyte* srcSByte = (
const GLbyte*)srcLine;
1871 const GLushort* srcUShort = (
const GLushort*)srcLine;
1872 const GLshort* srcSShort = (
const GLshort*)srcLine;
1873 const unsigned int* srcUInt = (
const unsigned int*)srcLine;
1874 const int* srcSInt = (
const int*)srcLine;
1875 const float* srcFloat = (
const float*)srcLine;
1877 unsigned char* dstUByte = (
unsigned char*)dstLine;
1878 GLbyte* dstSByte = (GLbyte*)dstLine;
1879 GLushort* dstUShort = (GLushort*)dstLine;
1880 GLshort* dstSShort = (GLshort*)dstLine;
1881 unsigned int* dstUInt = (
unsigned int*)dstLine;
1882 int* dstSInt = (
int*)dstLine;
1883 float* dstFloat = (
float*)dstLine;
1885 for(
int j=0; j<img->
width(); ++j)
1889 case IT_UNSIGNED_BYTE: convert<unsigned char> (srcUByte, dstUByte, 255, srco, dsto); srcUByte+=src_comp; dstUByte+=dst_comp;
break;
1890 case IT_BYTE: convert<GLbyte> (srcSByte, dstSByte, 127, srco, dsto); srcSByte+=src_comp; dstSByte+=dst_comp;
break;
1891 case IT_UNSIGNED_SHORT: convert<GLushort> (srcUShort, dstUShort, 65535, srco, dsto); srcUShort+=src_comp; dstUShort+=dst_comp;
break;
1892 case IT_SHORT: convert<GLshort> (srcSShort, dstSShort, 32767, srco, dsto); srcSShort+=src_comp; dstSShort+=dst_comp;
break;
1893 case IT_UNSIGNED_INT: convert<unsigned int> (srcUInt, dstUInt, 4294967295U, srco, dsto); srcUInt+=src_comp; dstUInt+=dst_comp;
break;
1894 case IT_INT: convert<int> (srcSInt, dstSInt, 2147483647, srco, dsto); srcSInt+=src_comp; dstSInt+=dst_comp;
break;
1895 case IT_FLOAT: convert<float> (srcFloat, dstFloat, 1.0f, srco, dsto); srcFloat+=src_comp; dstFloat+=dst_comp;
break;
1910 x = (
width()-1) - 0.000001;
1918 float w11 = 1.0f - w21;
1923 return c11*w11 + c21*w21;
1934 x = (
width()-1) - 0.000001;
1936 y = (h-1) - 0.000001;
1951 float w11 = float(tx1*ty1);
1952 float w12 = float(tx1*ty);
1953 float w22 = float(tx *ty);
1954 float w21 = float(tx *ty1);
1961 return c11*w11 + c12*w12 + c22*w22 + c21*w21;
1966 if (x>
width() -1.000001) x =
width() -1.000001;
1968 if (z>
depth() -1.000001) z =
depth() -1.000001;
1973 float xt = float(x - ix);
1975 float yt = float(y - iy);
1977 float zt = float(z - iz);
1989 fvec4 v1 = val0*(yt1) + val3*yt;
1990 fvec4 v2 = val1*(yt1) + val2*yt;
1991 fvec4 a = v1*(xt1) + v2*xt;
1992 v1 = val4*(yt1) + val7*yt;
1993 v2 = val5*(yt1) + val6*yt;
1994 fvec4 b = v1*(xt1) + v2*xt;
1995 return a*(zt1) + b*zt;
2011 case IF_RGB: comp = 3;
break;
2012 case IF_RGBA: comp = 4;
break;
2013 case IF_BGR: comp = 3;
break;
2014 case IF_BGRA: comp = 4;
break;
2015 case IF_RED: comp = 1;
break;
2017 case IF_BLUE: comp = 1;
break;
2029 case IT_BYTE: px += x*comp*1;
break;
2031 case IT_SHORT: px += x*comp*2;
break;
2033 case IT_INT: px += x*comp*4;
break;
2034 case IT_FLOAT: px += x*comp*4;
break;
2041 fvec4 pixel(0,0,0,0);
2043 for(
int i=0; i<comp; ++i)
2049 case IT_UNSIGNED_BYTE: value = (double)((
unsigned char*)px)[i]; value/=255.0;
break;
2050 case IT_BYTE: value = (double)((
char*)px)[i]; value/=127.0;
break;
2051 case IT_UNSIGNED_SHORT: value = (double)((
unsigned short*)px)[i]; value/=65535.0;
break;
2052 case IT_SHORT: value = (double)((
short*)px)[i]; value/=32767.0;
break;
2053 case IT_UNSIGNED_INT: value = (double)((
unsigned int*)px)[i]; value/=4294967295.0;
break;
2054 case IT_INT: value = (double)((
int*)px)[i]; value/=2147483647.0;
break;
2055 case IT_FLOAT: value = (double)((
float*)px)[i];
break;
2060 pixel[i] = (float)value;
2068 case IF_RGB: p = pixel;
break;
2069 case IF_RGBA: p = pixel;
break;
2070 case IF_BGR: p = pixel; p.
r() = pixel.
b(); p.
b() = pixel.
r();
break;
2071 case IF_BGRA: p = pixel; p.
r() = pixel.
b(); p.
b() = pixel.
r();
break;
2094 for(
int i=0; i<
height; ++i)
2096 unsigned char* dst = img->
pixels() + img->
pitch()*i;
2119 for(
int i=0; i<src.
height(); ++i)
2121 int ysrc = i+src.
y();
2122 int ydst = i+dst.
y();
2133 Log::error(
"Image::substituteColorRGB_RGBA(): this function can be called only on images whose type() is IT_UNSIGNED_BYTE\n");
2138 Log::error(
"Image::substituteColorRGB_RGBA(): this function can be called only on images whose format() is either IF_RGBA or IF_RGB\n");
2141 unsigned char bef[3];
2142 unsigned char aft[4];
2143 bef[0] = (
unsigned char)((before >> 16) & 0xFF);
2144 bef[1] = (
unsigned char)((before >> 8) & 0xFF);
2145 bef[2] = (
unsigned char)((before >> 0) & 0xFF);
2147 aft[0] = (
unsigned char)((after >> 24) & 0xFF);
2148 aft[1] = (
unsigned char)((after >> 16) & 0xFF);
2149 aft[2] = (
unsigned char)((after >> 8) & 0xFF);
2150 aft[3] = (
unsigned char)((after >> 0) & 0xFF);
2154 for(
int y=0; y<
height()*d; ++y)
2156 for(
int x=0; x<
width(); ++x)
2158 unsigned char* px =
pixels() +
pitch()*y + x*comps;
2159 if (px[0] == bef[0] && px[1] == bef[1] && px[2] == bef[2])
2175 Log::error(
"Image::substituteColorRGB_RGB(): this function can be called only on images whose type() is IT_UNSIGNED_BYTE\n");
2180 Log::error(
"Image::substituteColorRGB_RGB(): this function can be called only on images whose format() is either IF_RGBA or IF_RGB\n");
2183 unsigned char bef[3];
2184 unsigned char aft[3];
2185 bef[0] = (
unsigned char)((before >> 16) & 0xFF);
2186 bef[1] = (
unsigned char)((before >> 8) & 0xFF);
2187 bef[2] = (
unsigned char)((before >> 0) & 0xFF);
2189 aft[0] = (
unsigned char)((after >> 24) & 0xFF);
2190 aft[1] = (
unsigned char)((after >> 16) & 0xFF);
2191 aft[2] = (
unsigned char)((after >> 8) & 0xFF);
2195 for(
int y=0; y<
height()*d; ++y)
2197 for(
int x=0; x<
width(); ++x)
2199 unsigned char* px =
pixels() +
pitch()*y + x*comps;
2200 if (px[0] == bef[0] && px[1] == bef[1] && px[2] == bef[2])
2214 Log::error(
"Image::substituteColorRGB_RGB(): this function can be called only on images whose type() is IT_UNSIGNED_BYTE\n");
2219 Log::error(
"Image::substituteColorRGB_RGB(): this function can be called only on images whose format() is either IF_RGBA or IF_RGB\n");
2222 unsigned char c0[3];
2223 unsigned char c1[3];
2224 c0[0] = (
unsigned char)((col0 >> 16) & 0xFF);
2225 c0[1] = (
unsigned char)((col0 >> 8) & 0xFF);
2226 c0[2] = (
unsigned char)((col0 >> 0) & 0xFF);
2228 c1[0] = (
unsigned char)((col1 >> 16) & 0xFF);
2229 c1[1] = (
unsigned char)((col1 >> 8) & 0xFF);
2230 c1[2] = (
unsigned char)((col1 >> 0) & 0xFF);
2234 for(
int y=0; y<
height()*d; ++y)
2236 for(
int x=0; x<
width(); ++x)
2238 unsigned char* px =
pixels() +
pitch()*y + x*comps;
2239 double t = (double)px[1] / 0xFF;
2240 px[0] = (
unsigned char)(c0[0]*(1.0-t) + c1[0]*t);
2241 px[1] = (
unsigned char)(c0[1]*(1.0-t) + c1[1]*t);
2242 px[2] = (
unsigned char)(c0[2]*(1.0-t) + c1[2]*t);
static void debug(const String &message)
Use this function to provide extra information useful to investigate and solve problems.
String toLowerCase() const
Returns the lower-case version of a String.
long long read(void *buffer, long long byte_count)
Reads byte_count bytes from a file. Returns the number of bytes actually read.
float clamp(float x, float minval, float maxval)
int isCompressedFormat(EImageFormat fmt)
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
An abstract class representing a file.
Vector4< float > fvec4
A 4 components vector with float precision.
The RectI class represents a 2D rectangular area using int precision.
A simple String formatting class.
const unsigned char * pixels() const
Raw pointer to pixels.
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
Vector4< unsigned char > ubvec4
A 4 components vector with unsigned char precision.
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
VLCORE_EXPORT ref< Image > loadRAW(VirtualFile *file, long long file_offset, int width, int height, int depth, int bytealign, EImageFormat format, EImageType type)
Loads a raw image file.
ref< Image > convertType(EImageType new_type) const
Converts the type() of an image.
const T_Scalar & r() const
void copySubImage(Image *img_src, RectI src, ivec2 dst)
Copies the rectangular area specified by src of img_src into an Image at position dst...
void setByteAlignment(int bytealign)
Modifies the byte-alignment of the rows of the image, thus changing its pitch.
virtual bool isOpen() const =0
Returns true if the file has been opened.
VLCORE_EXPORT ref< Image > loadCubemap(const String &xp_file, const String &xn_file, const String &yp_file, const String &yn_file, const String &zp_file, const String &zn_file)
Loads six images and assembles them into a cubemap image.
int alphaBits() const
The number of bits dedicated to the alpha channel.
bool contrastHounsfield(float center, float width, float intercept, float range)
Adjusts the contrast of an image using the window-center/window-width method used for CT images...
String value(const String &key) const
ref< ResourceDatabase > loadResource(const String &path, bool quick=true) const
Loads the resource specified by the given path using the appropriate ResourceLoadWriter.
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
virtual ref< VirtualFile > locateFile(const String &full_path, const String &alternate_path=String()) const
Looks for a VirtualFile on the disk and in the currently active FileSystem.
ref< Image > subImage(int xstart, int ystart, int width, int height)
Creates a new image containing the specified rectangular pixel area taken from the source image...
std::vector< ref< Image > > mMipmaps
bool contrastHounsfieldAuto()
Adjusts the contrast of an image using the window-center/window-width method used for CT images...
Implements a buffer whose storage is in local memory.
VLCORE_EXPORT bool loadImagesFromDir(const String &dir_path, const String &ext, std::vector< ref< Image > > &images)
Loads all the images with the specified extension from the given directory.
void setType(EImageType type)
int requiredMemory() const
Returns the number of bytes requested to store the image.
VLCORE_EXPORT ref< Image > makeColorSpectrum(size_t width, const std::vector< fvec4 > &colors)
Creates a 1D Image whose color is interpolated from left to right from the specified spectrum...
bool isValid() const
Returns true if the image has valid width/height/depth, pitch and byte alignment, type/format combina...
int toInt(bool hex=false) const
Returns the int number represented by the string. The conversion is done using the standard atoi() fu...
VLCORE_EXPORT ref< Image > loadImage(VirtualFile *file)
Loads an image from the specified file.
virtual void close()=0
Closes the file.
void substituteColorGreenKey(unsigned int col0, unsigned int col1)
void allocate3D(int x, int y, int z, int bytealign, EImageFormat format, EImageType type)
String printFormat() const
const String & path() const
Returns the path of the file.
int byteAlignment() const
Returns the byte-alignment of the row of the image.
VLCORE_EXPORT ref< Image > assemble3DImage(const std::vector< ref< Image > > &images)
Assembles the given 2D images in a single 2D image, all the images must be 2D images and have the sam...
unsigned char * pixelsXN()
X-negative cubemap face.
void setFilePath(const String &path)
The file from which the image was loaded.
Visualization Library main namespace.
ref< Image > createCubemap(const Image *xp, const Image *xn, const Image *yp, const Image *yn, const Image *zp, const Image *zn)
Assembles a cubemap image.
float dot(float a, float b)
virtual ref< VirtualDirectory > locateDirectory(const String &name) const
unsigned char * pixelsZN()
Z-negative cubemap face.
void allocate1D(int x, EImageFormat format, EImageType type)
bool equalize()
Equalizes the image. Returns false if the image format() or type() is not supported. This function supports both 3D images and cubemaps.
Image & operator=(const Image &other)
static void bug(const String &message)
Use this function to provide information about programming errors: wrong parameter initialization...
The Vector3 class is a template class that implements a generic 3 components vector, see also vl::fvec3, vl::dvec3, vl::uvec3, vl::ivec3, vl::svec3, vl::usvec3, vl::bvec3, vl::ubvec3.
const KeyValues * tags() const
A set of key/value couples that can be used to attach extra information to an image like DICOM inform...
unsigned char * pixelsZP()
Z-positive cubemap face.
const std::vector< ref< Object > > & resources() const
VLCORE_EXPORT bool saveImage(Image *img, VirtualFile *file)
Writes an image on the specified file.
The base class for all the reference counted objects.
float toFloat() const
Returns the float number represented by the string. The conversion is done using the standard atof() ...
EImageDimension dimension() const
void get(std::vector< ref< T > > &resources, bool clear_vector=true)
Returns all the objects of the specified type in the given vector.
Implements the OpenGL Shading Language convenience functions for scalar and vector operations...
The type is implicitly defined by the EImageFormat value, for ex.
fvec4 sampleLinear(double x) const
Performs a sampling on a 1d image using linear filtering.
Vector3< double > dvec3
A 3 components vector with double precision.
VLCORE_EXPORT ref< Image > makeNonUniformColorSpectrum(size_t width, size_t col_count, const fvec4 *colors, const float *col_pos)
Creates a 1D Image whose color is interpolated from left to right from the specified spectrum...
bool empty() const
Returns true if length() == 0.
virtual bool open(EOpenMode mode)=0
Opens the file in the specified mode.
unsigned char * pixelsYP()
Y-positive cubemap face.
const T_Scalar & b() const
void setFormat(EImageFormat format)
bool seekSet(long long offset)
Changes the current read/write position of a file.
unsigned char * pixelsYN()
Y-negative cubemap face.
const std::string & objectName() const
The name of the object, by default set to the object's class name.
ref< Image > convertFormat(EImageFormat new_format) const
Converts the format() of an image.
virtual void listFiles(std::vector< String > &file_list, bool append=false) const =0
void substituteColorRGB_RGB(unsigned int before, unsigned int after)
Substitutes the color 'before' with the new color 'after'.
void allocateCubemap(int x, int y, int bytealign, EImageFormat format, EImageType type)
bool contrast(float black, float white)
Adjusts the contrast of an image. Returns false if the image format() or type() is not supported...
Implements a generic 1d, 2d, 3d and cubemap image that can have mipmaps.
The ref<> class is used to reference-count an Object.
const T_Scalar & x() const
void substituteColorRGB_RGBA(unsigned int before, unsigned int after)
Substitutes the color 'before' with the new color 'after'.
void allocate2D(int x, int y, int bytealign, EImageFormat format, EImageType type)
std::string toStdString() const
Returns a UTF8 encoded std::string.
unsigned char * pixelsXP()
X-positive cubemap face.
const T_Scalar & y() const
fvec4 sample(int x, int y=0, int z=0) const
Returns the color associated to the specified pixel.
static int bitsPerPixel(EImageType type, EImageFormat format)
Returns the number of bits used to represents one pixel.
unsigned char * pixelsZSlice(int zth_slice)
Zth slice of 3D image.
static int requiredMemory2D(int x, int y, int bytealign, EImageFormat format, EImageType type)
void reset()
Disposes all the pixel data and resets the image settings to its defaults.
VLCORE_EXPORT LoadWriterManager * defLoadWriterManager()
Returs the default LoadWriterManager used by Visualization Library.
EImageFormat format() const
The ResourceDatabase class contains and manipulates a set of resources.
bool writeResource(const String &path, ResourceDatabase *resource) const
Writes the resource specified by the given file using the appropriate ResourceLoadWriter.