Added Image_Format_Gray16 pixel format definition, which could be uploaded into GL_R16 texture.
Added Image_Format_GrayF_half mapped to GL_R16F texture.
case FIT_RGBF: return Image_Format_RGBF;
case FIT_RGBAF: return Image_Format_RGBAF;
case FIT_FLOAT: return Image_Format_GrayF;
+ case FIT_INT16:
+ case FIT_UINT16: return Image_Format_Gray16;
case FIT_BITMAP:
{
switch (theColorTypeFI)
case Image_Format_Gray:
case Image_Format_Alpha:
return FIT_BITMAP;
+ case Image_Format_Gray16:
+ return FIT_UINT16;
default:
return FIT_UNKNOWN;
}
{
return Image_Format_Gray;
}
+ else if (theFormat == GUID_WICPixelFormat16bppGray)
+ {
+ return Image_Format_Gray16;
+ }
return Image_Format_UNKNOWN;
}
case Image_Format_BGR: return GUID_WICPixelFormat24bppBGR;
case Image_Format_Gray: return GUID_WICPixelFormat8bppGray;
case Image_Format_Alpha: return GUID_WICPixelFormat8bppGray; // GUID_WICPixelFormat8bppAlpha
+ case Image_Format_Gray16: return GUID_WICPixelFormat16bppGray;
case Image_Format_GrayF: // GUID_WICPixelFormat32bppGrayFloat
case Image_Format_AlphaF:
case Image_Format_RGBAF: // GUID_WICPixelFormat128bppRGBAFloat
{
aFileFormat = GUID_ContainerFormatJpeg;
}
- else if (aFileNameLower.EndsWith (".tiff"))
+ else if (aFileNameLower.EndsWith (".tiff")
+ || aFileNameLower.EndsWith (".tif"))
{
aFileFormat = GUID_ContainerFormatTiff;
}
Image_Format_BGRF, //!< same as RGBF but with different components order
Image_Format_RGBAF, //!< 4 floats (16-bytes) RGBA image plane
Image_Format_BGRAF, //!< same as RGBAF but with different components order
- Image_Format_RGF_half, //!< 2 half-floats (4-bytes) RG image plane
+ Image_Format_GrayF_half, //!< 1 half-float (2-bytes) intensity of color
+ Image_Format_RGF_half, //!< 2 half-floats (4-bytes) RG image plane
Image_Format_RGBAF_half, //!< 4 half-floats (8-bytes) RGBA image plane
+ Image_Format_Gray16, //!< 2 bytes per pixel (unsigned short integer), intensity of the color
};
-enum { Image_Format_NB = Image_Format_RGBAF_half + 1 };
+enum { Image_Format_NB = Image_Format_Gray16 + 1 };
#endif // _Image_Format_HeaderFile
ImageFormatInfo(BGRF, 3, sizeof(float) * 3),
ImageFormatInfo(RGBAF, 4, sizeof(float) * 4),
ImageFormatInfo(BGRAF, 4, sizeof(float) * 4),
+ ImageFormatInfo(GrayF_half, 1, sizeof(uint16_t) * 1),
ImageFormatInfo(RGF_half, 2, sizeof(uint16_t) * 2),
ImageFormatInfo(RGBAF_half, 4, sizeof(uint16_t) * 4),
+ ImageFormatInfo(Gray16, 1, 2),
CompressedImageFormatInfo(RGB_S3TC_DXT1, 3, 1), // DXT1 uses circa half a byte per pixel (64 bits per 4x4 block)
CompressedImageFormatInfo(RGBA_S3TC_DXT1, 4, 1),
CompressedImageFormatInfo(RGBA_S3TC_DXT3, 4, 1), // DXT3/5 uses circa 1 byte per pixel (128 bits per 4x4 block)
const Image_ColorBGRF& aPixel = Value<Image_ColorBGRF> (theY, theX);
return Quantity_ColorRGBA (NCollection_Vec4<float> (aPixel.r(), aPixel.g(), aPixel.b(), 1.0f)); // opaque
}
+ case Image_Format_GrayF_half:
+ {
+ const uint16_t& aPixel = Value<uint16_t> (theY, theX);
+ return Quantity_ColorRGBA (NCollection_Vec4<float> (ConvertFromHalfFloat (aPixel), 0.0f, 0.0f, 1.0f));
+ }
case Image_Format_RGF_half:
{
const NCollection_Vec2<uint16_t>& aPixel = Value<NCollection_Vec2<uint16_t>> (theY, theX);
case Image_Format_Gray:
{
const Standard_Byte& aPixel = Value<Standard_Byte> (theY, theX);
- return Quantity_ColorRGBA (float(aPixel) / 255.0f, float(aPixel) / 255.0f, float(aPixel) / 255.0f, 1.0f); // opaque
+ const float anIntensity = float(aPixel) / 255.0f;
+ return Quantity_ColorRGBA (anIntensity, anIntensity, anIntensity, 1.0f); // opaque
}
case Image_Format_Alpha:
{
const Standard_Byte& aPixel = Value<Standard_Byte> (theY, theX);
return Quantity_ColorRGBA (1.0f, 1.0f, 1.0f, float(aPixel) / 255.0f);
}
+ case Image_Format_Gray16:
+ {
+ const uint16_t& aPixel = Value<uint16_t> (theY, theX);
+ const float anIntensity = float(aPixel) / 65535.0f;
+ return Quantity_ColorRGBA (anIntensity, anIntensity, anIntensity, 1.0f); // opaque
+ }
case Image_Format_UNKNOWN:
{
break;
aPixel.b() = aColor.b();
return;
}
+ case Image_Format_GrayF_half:
+ {
+ uint16_t& aPixel = ChangeValue<uint16_t> (theY, theX);
+ aPixel = ConvertToHalfFloat (aColor.r());
+ return;
+ }
case Image_Format_RGF_half:
{
NCollection_Vec2<uint16_t>& aPixel = ChangeValue<NCollection_Vec2<uint16_t>> (theY, theX);
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(aColor.a() * 255.0f);
return;
}
+ case Image_Format_Gray16:
+ {
+ ChangeValue<uint16_t> (theY, theX) = uint16_t(aColor.r() * 65535.0f);
+ return;
+ }
case Image_Format_UNKNOWN:
{
return;
}
break;
}
+ case Image_Format_Gray16:
+ {
+ for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
+ {
+ for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
+ {
+ uint16_t& aPixel = theImage.ChangeValue<uint16_t> (aRow, aCol);
+ if (aPixel != 0)
+ {
+ aPixel = 65535;
+ }
+ }
+ }
+ break;
+ }
case Image_Format_RGB:
case Image_Format_BGR:
case Image_Format_RGB32:
public: // high-level API
+ //! Return pixel format.
Image_Format Format() const { return myImgFormat; }
//! Override pixel format specified by InitXXX() methods.
//! (e.g. ImgGray and ImgAlpha).
Standard_EXPORT void SetFormat (const Image_Format thePixelFormat);
- //! @return image width in pixels
- inline Standard_Size Width() const
- {
- return myData.SizeX;
- }
+ //! Return image width in pixels
+ Standard_Size Width() const { return myData.SizeX; }
- //! @return image height in pixels
- inline Standard_Size Height() const
- {
- return myData.SizeY;
- }
+ //! Return image height in pixels
+ Standard_Size Height() const { return myData.SizeY; }
- //! @return image width in pixels
- inline Standard_Size SizeX() const
- {
- return myData.SizeX;
- }
+ //! Return image width in pixels
+ Standard_Size SizeX() const { return myData.SizeX; }
- //! @return image height in pixels
- inline Standard_Size SizeY() const
- {
- return myData.SizeY;
- }
+ //! Return image height in pixels
+ Standard_Size SizeY() const { return myData.SizeY; }
- //! @return width / height.
- inline Standard_Real Ratio() const
+ //! Return width / height.
+ Standard_Real Ratio() const
{
return (SizeY() > 0) ? (Standard_Real(SizeX()) / Standard_Real(SizeY())) : 1.0;
}
- //! @return true if data is NULL.
- bool IsEmpty() const
- {
- return myData.IsEmpty();
- }
+ //! Return true if data is NULL.
+ bool IsEmpty() const { return myData.IsEmpty(); }
//! Empty constructor. Initialize the NULL image plane.
Standard_EXPORT Image_PixMap();
return Image_Format_BGR;
case AV_PIX_FMT_GRAY8:
return Image_Format_Gray;
+ case AV_PIX_FMT_GRAY16:
+ return Image_Format_Gray16;
default:
return Image_Format_UNKNOWN;
}
return AV_PIX_FMT_GRAY8;
case Image_Format_Alpha:
return AV_PIX_FMT_GRAY8;
+ case Image_Format_Gray16:
+ return AV_PIX_FMT_GRAY16;
case Image_Format_GrayF:
case Image_Format_AlphaF:
case Image_Format_RGF:
case Image_Format_RGBF:
case Image_Format_BGRAF:
case Image_Format_BGRF:
+ case Image_Format_GrayF_half:
case Image_Format_RGF_half:
case Image_Format_RGBAF_half:
case Image_Format_UNKNOWN:
extDrawBuffers (Standard_False),
extGS (NULL),
extBgra(Standard_False),
+ extTexR16(Standard_False),
extAnis(Standard_False),
extPDS (Standard_False),
atiMem (Standard_False),
mySupportedFormats->Add (Image_Format_BGR32);
mySupportedFormats->Add (Image_Format_BGRA);
}
+ if (extTexR16)
+ {
+ mySupportedFormats->Add (Image_Format_Gray16);
+ }
if (arbTexFloat)
{
mySupportedFormats->Add (Image_Format_GrayF);
mySupportedFormats->Add (Image_Format_RGF);
if (hasHalfFloatBuffer != OpenGl_FeatureNotAvailable)
{
+ mySupportedFormats->Add (Image_Format_GrayF_half);
mySupportedFormats->Add (Image_Format_RGF_half);
}
}
Standard_Boolean extDrawBuffers; //!< GL_EXT_draw_buffers
OpenGl_ExtGS* extGS; //!< GL_EXT_geometry_shader4
Standard_Boolean extBgra; //!< GL_EXT_bgra or GL_EXT_texture_format_BGRA8888 on OpenGL ES
+ Standard_Boolean extTexR16; //!< GL_EXT_texture_norm16 on OpenGL ES; always available on desktop
Standard_Boolean extAnis; //!< GL_EXT_texture_filter_anisotropic
Standard_Boolean extPDS; //!< GL_EXT_packed_depth_stencil
Standard_Boolean atiMem; //!< GL_ATI_meminfo
aType = GL_UNSIGNED_BYTE;
break;
}
+ case Image_Format_Gray16:
+ {
+ if (theGlCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES)
+ {
+ return false;
+ }
+
+ aFormat = theBufferType == Graphic3d_BT_Depth ? GL_DEPTH_COMPONENT : GL_RED;
+ aType = GL_UNSIGNED_SHORT;
+ break;
+ }
case Image_Format_GrayF:
{
if (theGlCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES)
case Image_Format_Alpha:
case Image_Format_AlphaF:
return Standard_False; // GL_ALPHA is no more supported in core context
+ case Image_Format_GrayF_half:
case Image_Format_RGF_half:
case Image_Format_UNKNOWN:
return Standard_False;
theCtx.arbTexRG = isGlGreaterEqualShort (3, 0)
|| checkExtensionShort ("GL_EXT_texture_rg");
theCtx.extBgra = checkExtensionShort ("GL_EXT_texture_format_BGRA8888");
+ theCtx.extTexR16 = checkExtensionShort ("GL_EXT_texture_norm16");
theCtx.extAnis = checkExtensionShort ("GL_EXT_texture_filter_anisotropic");
theCtx.extPDS = isGlGreaterEqualShort (3, 0)
|| checkExtensionShort ("GL_OES_packed_depth_stencil");
|| checkExtensionShort ("NV_depth_clamp");
theCtx.extBgra = isGlGreaterEqualShort (1, 2)
|| checkExtensionShort ("GL_EXT_bgra");
+ theCtx.extTexR16 = true;
theCtx.extAnis = checkExtensionShort ("GL_EXT_texture_filter_anisotropic");
theCtx.extPDS = checkExtensionShort ("GL_EXT_packed_depth_stencil");
theCtx.atiMem = checkExtensionShort ("GL_ATI_meminfo");
#define GL_RGB8 0x8051
#define GL_RGBA8 0x8058
+// only in desktop OpenGL
+#define GL_LUMINANCE16 0x8042
+
// in core since OpenGL ES 3.0, extension GL_OES_rgb8_rgba8
#define GL_LUMINANCE8 0x8040
// GL_EXT_texture_format_BGRA8888
case 0x803C: return "GL_ALPHA8";
case 0x803E: return "GL_ALPHA16";
case GL_LUMINANCE: return "GL_LUMINANCE";
+ case GL_LUMINANCE16: return "GL_LUMINANCE16";
case GL_LUMINANCE_ALPHA: return "GL_LUMINANCE_ALPHA";
//
case GL_DEPTH_COMPONENT: return "GL_DEPTH_COMPONENT";
aFormat.SetDataType (GL_FLOAT);
return aFormat;
}
+ case Image_Format_GrayF_half:
+ {
+ aFormat.SetNbComponents (1);
+ aFormat.SetInternalFormat (GL_R16F);
+ aFormat.SetPixelFormat (GL_RED);
+ aFormat.SetDataType (GL_HALF_FLOAT);
+ if (theCtx->hasHalfFloatBuffer == OpenGl_FeatureInExtensions
+ && theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES)
+ {
+ aFormat.SetDataType (GL_HALF_FLOAT_OES);
+ }
+ return aFormat;
+ }
case Image_Format_RGF_half:
{
aFormat.SetNbComponents (2);
aFormat.SetDataType (GL_UNSIGNED_BYTE);
return aFormat;
}
+ case Image_Format_Gray16:
+ {
+ if (!theCtx->extTexR16)
+ {
+ return OpenGl_TextureFormat();
+ }
+
+ aFormat.SetNbComponents (1);
+ if (useRedRedAlpha
+ || theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES)
+ {
+ aFormat.SetInternalFormat (GL_R16);
+ aFormat.SetPixelFormat (GL_RED);
+ }
+ else
+ {
+ aFormat.SetInternalFormat (GL_LUMINANCE16);
+ aFormat.SetPixelFormat (GL_LUMINANCE);
+ }
+ aFormat.SetDataType (GL_UNSIGNED_SHORT);
+ return aFormat;
+ }
case Image_Format_UNKNOWN:
{
return OpenGl_TextureFormat();
aFormat.SetInternalFormat (theSizedFormat);
aFormat.SetPixelFormat (GL_RED);
aFormat.SetDataType (GL_HALF_FLOAT);
- aFormat.SetImageFormat (Image_Format_GrayF);
+ aFormat.SetImageFormat (Image_Format_GrayF_half);
if (theCtx->hasHalfFloatBuffer == OpenGl_FeatureInExtensions)
{
aFormat.SetDataType (theCtx->GraphicsLibrary() == Aspect_GraphicsLibrary_OpenGLES