6 #include <Base/Image/ImageIO.hh>
32 const unsigned int & widthBrutto,
33 const unsigned int & heightBrutto,
34 const GLenum & target )
53 if (!GLEW_VERSION_1_1){
57 BIASWARN(
"initializing glewInit.");
61 if (glewGetErrorString(err)==NULL) {
62 BIASERR(
"could not init GLEW. glewGetErrorString(err) is NULL");
65 BIASERR(
"could not init GLEW. Error -42 ");
67 BIASERR(
"could not init GLEW. Error: "<<glewGetErrorString(err));
74 #endif // BIAS_HAVE_GLEW
125 glDeleteTextures(1, (GLuint*)(&
id) );
137 return target == GL_TEXTURE_2D;
142 #if defined(BIAS_HAVE_GLEW)
143 return target == GL_TEXTURE_RECTANGLE_NV;
151 #if defined(BIAS_HAVE_GLEW)
152 return target == GL_TEXTURE_CUBE_MAP_EXT;
165 #if defined(BIAS_HAVE_GLEW)
166 target=GL_TEXTURE_RECTANGLE_NV;
168 BIASEXIT(1,
"you need glew to use GL_TEXTURE_RECTANGLE_NV");
172 #if defined(BIAS_HAVE_GLEW)
173 target=GL_TEXTURE_CUBE_MAP_EXT;
175 BIASEXIT(1,
"you need glew to use GL_TEXTURE_RECTANGLE_NV");
183 const bool & forcePow2tex,
185 const bool ImmediateCopyData )
216 if (ImmediateCopyData)
240 glGenTextures(1, &
id);
241 glBindTexture(
target,
id);
245 glPixelStorei(GL_PACK_ALIGNMENT, 1);
246 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
248 glTexParameteri(
target, GL_TEXTURE_WRAP_S, GL_CLAMP);
249 glTexParameteri(
target, GL_TEXTURE_WRAP_T, GL_CLAMP);
254 glTexParameteri(
target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
256 glTexParameteri(
target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
260 case GL_NEAREST_MIPMAP_NEAREST:
261 case GL_LINEAR_MIPMAP_NEAREST:
262 case GL_NEAREST_MIPMAP_LINEAR:
263 case GL_LINEAR_MIPMAP_LINEAR:
264 #ifdef BIAS_HAVE_GLEW
266 glTexParameteri(
target, GL_GENERATE_MIPMAP, GL_TRUE);
267 glTexParameteri(
target, GL_TEXTURE_BASE_LEVEL, 0);
268 glTexParameteri(
target, GL_TEXTURE_MAX_LEVEL, 10);
269 #endif //BIAS_HAVE_GLEW
270 #ifdef BIAS_HAVE_GLEW
271 glTexParameterf(
target, GL_TEXTURE_LOD_BIAS, 0.0);
272 #endif // BIAS_HAVE_GLEW
277 #ifdef BIAS_HAVE_GLEW
278 glTexParameteri(
target, GL_GENERATE_MIPMAP, GL_FALSE);
279 glTexParameteri(
target, GL_TEXTURE_BASE_LEVEL, 0);
280 glTexParameteri(
target, GL_TEXTURE_MAX_LEVEL, 0);
281 glTexParameterf(
target, GL_TEXTURE_LOD_BIAS, 0.0);
282 #endif // BIAS_HAVE_GLEW
293 GLvoid * p_pixels=NULL;
295 if (ImmediateCopyData)
309 switch (gpu_internalFmt)
323 BIASERR(
"Your requested GPU internal format (>8 bit) and texture target (pow2 GL_TEXTURE_2D) are possibly not compatible!");
343 BIASASSERT( GL_TRUE == glIsTexture(
id ) );
348 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
356 const bool ImmediateCopyData,
357 const bool mipmapped )
361 #if defined(BIAS_HAVE_GLEW)
362 target=GL_TEXTURE_CUBE_MAP_EXT;
364 BIASEXIT(1,
"You nee dglew to use GL_TEXTURE_CUBE_MAP_EXT")
372 BIASASSERT(cm.size()==6);
373 BIASASSERT(cm[0]!=NULL);
374 const unsigned int w=cm[0]->GetWidth();
375 const unsigned int h=cm[0]->GetHeight();
388 for (face=0; face<cm.size(); face++) {
389 BIASASSERT(cm[face]!=NULL);
391 BIASASSERT(w==cm[face]->GetWidth() );
392 BIASASSERT(h==cm[face]->GetHeight());
396 case GL_NEAREST_MIPMAP_NEAREST:
397 case GL_LINEAR_MIPMAP_NEAREST:
398 case GL_NEAREST_MIPMAP_LINEAR:
399 case GL_LINEAR_MIPMAP_LINEAR:
400 #ifdef BIAS_HAVE_GLEW
402 glTexParameteri(
target, GL_GENERATE_MIPMAP, GL_TRUE);
403 glTexParameteri(
target, GL_TEXTURE_BASE_LEVEL, 0);
404 glTexParameteri(
target, GL_TEXTURE_MAX_LEVEL, 10);
405 glTexParameterf(
target, GL_TEXTURE_LOD_BIAS, 0.0);
406 #endif // BIAS_HAVE_GLEW
412 #ifdef BIAS_HAVE_GLEW
413 glTexParameteri(
target, GL_GENERATE_MIPMAP, GL_FALSE);
414 glTexParameteri(
target, GL_TEXTURE_BASE_LEVEL, 0);
415 glTexParameteri(
target, GL_TEXTURE_MAX_LEVEL, 0);
416 glTexParameterf(
target, GL_TEXTURE_LOD_BIAS, 0.0);
417 #endif // BIAS_HAVE_GLEW
426 if (ImmediateCopyData){
427 #if defined(BIAS_HAVE_GLEW)
429 GLvoid * p_pixels = cm[face]->GetImageData();
430 GLenum pixSrc_fmt =
GetGLPixelFormat(cm[face]->GetColorModel(), cm[face]->GetChannelCount() );
431 GLenum pixSrc_type =
GetGLStorageType(cm[face]->GetStorageType(), cm[face]->GetDepth() );
433 glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT +face ,
443 BIASEXIT(1,
"you need glew to use GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT");
448 BIASASSERT( GL_TRUE == glIsTexture(
id ) );
460 GLint gpu_internalFmt,
461 const bool & mipmapped)
463 #if !defined(BIAS_HAVE_GLEW)
464 BIASEXIT(1,
"you need glew to use GL_TEXTURE_CUBE_MAP_EXT");
470 target=GL_TEXTURE_CUBE_MAP_EXT;
477 BIASASSERT(
target==GL_TEXTURE_CUBE_MAP_EXT);
491 maxLevel = (int)(logf((
float)w)/logf(2.0f));
492 BIASASSERT(maxLevel>=0);
493 BIASASSERT(maxLevel<=12);
498 glGenTextures(1, &
id);
499 glBindTexture(
target,
id);
503 glPixelStorei(GL_PACK_ALIGNMENT, 1);
504 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
507 glTexParameteri(
target, GL_TEXTURE_WRAP_S, GL_CLAMP);
508 glTexParameteri(
target, GL_TEXTURE_WRAP_T, GL_CLAMP);
509 glTexParameteri(
target, GL_TEXTURE_BASE_LEVEL, 0);
511 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
513 #ifdef BIAS_HAVE_GLEW
514 glTexParameterf(
target, GL_TEXTURE_LOD_BIAS, 0.0);
515 #endif // BIAS_HAVE_GLEW
519 case GL_NEAREST_MIPMAP_NEAREST:
520 case GL_LINEAR_MIPMAP_NEAREST:
521 case GL_NEAREST_MIPMAP_LINEAR:
522 case GL_LINEAR_MIPMAP_LINEAR:
524 BIASASSERT(mipmapped);
525 glTexParameteri(
target, GL_TEXTURE_MAX_LEVEL, (GLint)maxLevel );
531 BIASASSERT(!mipmapped);
532 glTexParameteri(
target, GL_TEXTURE_MAX_LEVEL, 0);
538 GLvoid * p_pixels_dummy=NULL;
542 for (face=0; face<6; face++)
544 for (level=0; level<=maxLevel; level++)
546 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT+face,
548 (GLint)gpu_internalFmt,
559 BIASASSERT( GL_TRUE == glIsTexture(
id ) );
569 const std::string & cm1NegX,
570 const std::string & cm2PosY,
571 const std::string & cm3NegY,
572 const std::string & cm4PosZ,
573 const std::string & cm5NegZ,
574 const bool ImmediateCopyData,
575 const bool mipmapped)
577 std::vector< std::string > filenames;
578 filenames.push_back(cm0PosX);
579 filenames.push_back(cm1NegX);
580 filenames.push_back(cm2PosY);
581 filenames.push_back(cm3NegY);
582 filenames.push_back(cm4PosZ);
583 filenames.push_back(cm5NegZ);
584 BIASASSERT(filenames.size()==6);
590 const bool ImmediateCopyData,
591 const bool mipmapped)
594 BIASASSERT(cmFilenames.size()==6);
595 std::vector< BIAS::ImageBase > img;
596 img.resize(cmFilenames.size());
598 for (
unsigned int i=0; i<img.size(); i++)
602 BIASERR(
"could not load "<<cmFilenames[i]);
613 std::vector<BIAS::ImageBase * > v_ptr;
614 for (
unsigned int i=0; i<img.size(); i++)
615 v_ptr.push_back( &img[i] );
617 BIASASSERT(v_ptr.size()==6);
626 const unsigned int & ByteDepth )
631 BIASASSERT(ByteDepth==1);
632 return GL_UNSIGNED_BYTE;
635 BIASASSERT(ByteDepth==1);
639 BIASASSERT(ByteDepth==2);
640 return GL_UNSIGNED_SHORT;
643 BIASASSERT(ByteDepth==2);
647 BIASASSERT(ByteDepth==4);
648 return GL_UNSIGNED_INT;
651 BIASASSERT(ByteDepth==4);
655 BIASASSERT(ByteDepth==4);
659 BIASERR(
"unsupported StorageType:"<<biasST<<
" "
660 <<
"(with Byte depth="<<ByteDepth<<
")" );
669 const unsigned int & channelcount )
676 BIASASSERT(channelcount==3);
677 #ifdef BIAS_HAVE_GLEW
678 if (!GLEW_VERSION_1_1)
679 BIASERR(
"You need a BGR capable GPU!");
680 #endif // BIAS_HAVE_GLEW
685 BIASASSERT(channelcount==3);
686 #ifdef BIAS_HAVE_GLEW
687 if (!GLEW_VERSION_1_1)
688 BIASERR(
"You need a BGRA_EXT capable GPU!");
689 #endif // BIAS_HAVE_GLEW
694 BIASASSERT(channelcount==1);
699 BIASASSERT(channelcount==2);
700 return GL_LUMINANCE_ALPHA;
708 BIASASSERT(channelcount==3);
709 BIASWARN(
"you are loading raw Bayer image as RGBA.");
716 BIASWARN(
"you are loading HSV/HSL/hsL as RGB.");
718 BIASASSERT(channelcount==3);
724 BIASASSERT(channelcount==4);
729 BIASERR(
"unsupported ColroModel:"<<biasCM<<
" "
730 <<
"(with channelcount ="<<channelcount<<
")" );
753 const unsigned int & channelcount,
754 const unsigned int & ByteDepth,
755 const unsigned int & BitDepth )
782 BIASERR(
"unsupported channel count for 8 bit");
788 #if defined(BIAS_DEBUG) && defined(BIAS_HAVE_GLEW)
789 if (!GLEW_VERSION_1_1)
790 BIASERR(
"glew said not even OpenGL 1.1 is supported - did you call glewInit() ?");
793 #ifdef BIAS_HAVE_GLEW
794 if (GLEW_ARB_texture_float){
797 return GL_RGBA16F_ARB;
798 else if (channelcount==3)
799 return GL_RGB16F_ARB;
801 }
else if (GLEW_NV_float_buffer){
804 return GL_FLOAT_RGBA16_NV;
805 else if (channelcount==3)
806 return GL_FLOAT_RGB16_NV;
807 else if (channelcount==1)
808 return GL_FLOAT_RGBA16_NV;
810 #endif // BIAS_HAVE_GLEW
811 BIASERR(
"unsupported channelcount="<<channelcount<<
" for 16 bit or missing extension (e.g. ARB_texture_float,NV_float_buffer)");
817 #if defined(BIAS_DEBUG) && defined(BIAS_HAVE_GLEW)
818 if (!GLEW_VERSION_1_1)
819 BIASERR(
"glew said not even OpenGL 1.1 is supported - did you call glewInit() ?");
820 #endif //BIAS_DEBUG + BIAS_HAVE_GLEW
822 #ifdef BIAS_HAVE_GLEW
824 if (GLEW_ARB_texture_float){
827 return GL_RGBA32F_ARB;
828 else if (channelcount==3)
829 return GL_RGB32F_ARB;
830 else if (channelcount==2)
831 return GL_LUMINANCE_ALPHA32F_ARB;
832 else if (channelcount==1) {
833 BIASWARNONCE(
"One channel (e.g.LUMINANCE) image is probably not GPU Hardware accelerated! "
834 "You may want to use RGB or RGBA instead!");
836 return GL_RGB16F_ARB;
839 }
else if (GLEW_NV_float_buffer){
842 return GL_FLOAT_RGBA32_NV;
843 else if (channelcount==3)
844 return GL_FLOAT_RGB32_NV;
845 else if (channelcount==1) {
846 BIASWARNONCE(
"One channel (e.g. LUMINANCE) images are probably not GPU Hardware accelerated! "
847 "Using RGBA for one channel image.");
848 return GL_FLOAT_RGBA32_NV;
852 #endif // BIAS_HAVE_GLEW
854 BIASERR(
"unsupported channelcount="<<channelcount<<
" for 32 bit or missing extension (e.g. ARB_texture_float,NV_float_buffer)");
859 BIASERR(
"unsupported ByteDepth.");
EColorModel
These are the most often used color models.
Bayer_GRBG, 1 channel RGB image Bayer tile.
static GLenum GetGLStorageType(const BIAS::ImageBase::EStorageType &biasST, const unsigned int &ByteDepth)
get the GLenum pixel storage type for the corresponding BIAS enum
bool IsPowerOfTwoSize() const
hsl, similar to HSL but euclidean (h,s) for CNCC
void Release()
frees the pointer members if we allocated them
static unsigned int PowerOfTwoSize(const unsigned int &val)
(16bit) unsigned integer image storage type
BIAS::ImageBase * p_valueImage
unsigned int GetDepth() const
returns the bytes per channel, which is the sizeof(StorageType) Should match GetSizeDepth(GetStorageT...
HSL, similar to HSV but space is a double tipped cone.
(8bit) signed char image storage type
unsigned int GetSizeByte() const
returns the nr.
Bayer_RGGB, 1 channel RGB image Bayer tile.
bool IsRectangleTexture() const
unsigned int heightBrutto
unsigned int GetWidth() const
unsigned int GetBitDepth() const
returns the bits per channel Is not necessairily 8*sizeof(StorageType), could be fewer bits...
bool p_valueImage_SelfAllocated
(16bit) signed integer image storage type
color values, 3 channels, order: blue,green,red
Bayer_BGGR, 1 channel RGB image Bayer tile.
const void * GetImageData() const
Bayer_GBRG, 1 channel RGB image Bayer tile.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
static GLenum GetGLPixelFormat(const BIAS::ImageBase::EColorModel &biasCM, const unsigned int &channelcount)
get the GLenum pixel src format for the corresponding BIAS enum ColroModel
static GLint GetGLInternalFormat(const BIAS::ImageBase::EStorageType &biasST, const BIAS::ImageBase::EColorModel &biasCM, const unsigned int &channelcount, const unsigned int &ByteDepth, const unsigned int &BitDepth)
JW determin the GPU internal format the src data should be mapped to.
unsigned int GetHeight() const
void SetTargetPOW2()
set the textur retarget to rectangular or pow 2 texture JW
void InitMembers()
set members to defaults
RGBA, 4 channels, order: red,green,blue,alpha.
enum EColorModel GetColorModel() const
(32bit) signed integer image storage type
void CreateGLTexture(const BIAS::ImageBase &c_img, const bool &forcePow2tex=true, const bool &flipY=true, const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT)
creates an OpenGL texture from p_valueImage JW if ImmediateCopyData is false the memory is just all...
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
void CreateGLCubemap(const std::vector< BIAS::ImageBase * > cm, const bool ImmediateCopyData=IMGOBJ_IMMEDIATE_COPY_DEFAULT, const bool mipmapped=IMGOBJ_DEFAULT_MIPMAPPED)
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
HSV, 3 channels, order: hue, sat , value.
static void InitGlew()
convenience interace for glewInit() c´with checks and ifdefs
int Flip()
flips the image vertically (row order is inverted) In place function return 0 in case of success...
void DeleteGLTexture()
deletes the texture memory and frees texture in GL
int PadToPowerOfTwoAndFlip(const int &padVal=0)
first pad, then flip.
GreyA, 2 channels, grey plus Alpha.
This is the base class for images in BIAS.
int PadToPowerOfTwo(BIAS::ImageBase &dest, const int &padVal=0) const
increase the size of this image to next power of two (e.g.
void CreateGLCubemapEmpty(const unsigned int w, const unsigned int h, GLint gpu_internalFmt=GL_RGBA, const bool &mipmapped=false)
BGRA color values, 4 channels, order: blue,green,red,alpha.
(32bit) unsigned integer image storage type