mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0025544: Visualization, TKOpenGl - support grayscale textures
Image_PixMap::ImgFormat - extend enumeration by ImgAlpha and ImgAlphaF. OpenGl_Workspace::setTextureParams() - specify GL_REPLACE for 1-component textures with disabled modulation. OpenGl_Texture::GetDataFormat() - return GL_LUMINANCE format for ImgGray format and GL_ALPHA for ImgAlpha. vmarkerstest - override pixel format for grayscale images to ImgAlpha. Add test case bugs/vis/bug25544_graytexture.
This commit is contained in:
@@ -78,6 +78,7 @@ namespace
|
||||
switch (theFormat)
|
||||
{
|
||||
case Image_PixMap::ImgGrayF:
|
||||
case Image_PixMap::ImgAlphaF:
|
||||
return FIT_FLOAT;
|
||||
case Image_PixMap::ImgRGBAF:
|
||||
return FIT_RGBAF;
|
||||
@@ -90,6 +91,7 @@ namespace
|
||||
case Image_PixMap::ImgRGB:
|
||||
case Image_PixMap::ImgBGR:
|
||||
case Image_PixMap::ImgGray:
|
||||
case Image_PixMap::ImgAlpha:
|
||||
return FIT_BITMAP;
|
||||
default:
|
||||
return FIT_UNKNOWN;
|
||||
@@ -448,7 +450,8 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
|
||||
}
|
||||
case FIF_EXR:
|
||||
{
|
||||
if (Format() == Image_PixMap::ImgGray)
|
||||
if (Format() == Image_PixMap::ImgGray
|
||||
|| Format() == Image_PixMap::ImgAlpha)
|
||||
{
|
||||
anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_FLOAT);
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <Image_PixMap.hxx>
|
||||
#include <NCollection_AlignedAllocator.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -48,6 +49,7 @@ Standard_Size Image_PixMap::SizePixelBytes (const Image_PixMap::ImgFormat thePix
|
||||
switch (thePixelFormat)
|
||||
{
|
||||
case ImgGrayF:
|
||||
case ImgAlphaF:
|
||||
return sizeof(float);
|
||||
case ImgRGBAF:
|
||||
case ImgBGRAF:
|
||||
@@ -65,17 +67,32 @@ Standard_Size Image_PixMap::SizePixelBytes (const Image_PixMap::ImgFormat thePix
|
||||
case ImgBGR:
|
||||
return 3;
|
||||
case ImgGray:
|
||||
default:
|
||||
case ImgAlpha:
|
||||
return 1;
|
||||
case ImgUNKNOWN:
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : setFormat
|
||||
// function : SetFormat
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void Image_PixMap::setFormat (Image_PixMap::ImgFormat thePixelFormat)
|
||||
void Image_PixMap::SetFormat (Image_PixMap::ImgFormat thePixelFormat)
|
||||
{
|
||||
if (myImgFormat == thePixelFormat)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsEmpty()
|
||||
&& SizePixelBytes (myImgFormat) != SizePixelBytes (thePixelFormat))
|
||||
{
|
||||
Standard_ProgramError::Raise ("Image_PixMap::SetFormat() - incompatible pixel format");
|
||||
return;
|
||||
}
|
||||
|
||||
myImgFormat = thePixelFormat;
|
||||
}
|
||||
|
||||
@@ -201,6 +218,12 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
|
||||
Quantity_Parameter (Standard_Real (aPixel)),
|
||||
Quantity_TOC_RGB);
|
||||
}
|
||||
case ImgAlphaF:
|
||||
{
|
||||
const Standard_ShortReal& aPixel = Value<Standard_ShortReal> (theY, theX);
|
||||
theAlpha = aPixel;
|
||||
return Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB);
|
||||
}
|
||||
case ImgRGBAF:
|
||||
{
|
||||
const Image_ColorRGBAF& aPixel = Value<Image_ColorRGBAF> (theY, theX);
|
||||
@@ -300,11 +323,19 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
|
||||
Quantity_Parameter (Standard_Real (aPixel) / 255.0),
|
||||
Quantity_TOC_RGB);
|
||||
}
|
||||
default:
|
||||
case ImgAlpha:
|
||||
{
|
||||
// not supported image type
|
||||
theAlpha = 0.0; // transparent
|
||||
return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);
|
||||
const Standard_Byte& aPixel = Value<Standard_Byte> (theY, theX);
|
||||
theAlpha = Standard_Real (aPixel) / 255.0;
|
||||
return Quantity_Color (1.0, 1.0, 1.0, Quantity_TOC_RGB);
|
||||
}
|
||||
case ImgUNKNOWN:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// unsupported image type
|
||||
theAlpha = 0.0; // transparent
|
||||
return Quantity_Color (0.0, 0.0, 0.0, Quantity_TOC_RGB);
|
||||
}
|
||||
|
@@ -30,14 +30,16 @@ public:
|
||||
//! This enumeration define packed image plane formats
|
||||
typedef enum tagFormat {
|
||||
ImgUNKNOWN = 0, //!< unsupported or unknown format
|
||||
ImgGray = 1, //!< 1 byte per pixel
|
||||
ImgGray = 1, //!< 1 byte per pixel, intensity of the color
|
||||
ImgAlpha, //!< 1 byte per pixel, transparency
|
||||
ImgRGB, //!< 3 bytes packed RGB image plane
|
||||
ImgBGR, //!< same as RGB but with different components order
|
||||
ImgRGB32, //!< 4 bytes packed RGB image plane (1 extra byte for alignment, may have undefined value)
|
||||
ImgBGR32, //!< same as RGB but with different components order
|
||||
ImgRGBA, //!< 4 bytes packed RGBA image plane
|
||||
ImgBGRA, //!< same as RGBA but with different components order
|
||||
ImgGrayF, //!< 1 float (4-bytes) per pixel (1-component plane)
|
||||
ImgGrayF, //!< 1 float (4-bytes) per pixel (1-component plane), intensity of the color
|
||||
ImgAlphaF, //!< 1 float (4-bytes) per pixel (1-component plane), transparency
|
||||
ImgRGBF, //!< 3 floats (12-bytes) RGB image plane
|
||||
ImgBGRF, //!< same as RGBF but with different components order
|
||||
ImgRGBAF, //!< 4 floats (16-bytes) RGBA image plane
|
||||
@@ -59,6 +61,12 @@ public: // high-level API
|
||||
return myImgFormat;
|
||||
}
|
||||
|
||||
//! Override pixel format specified by InitXXX() methods.
|
||||
//! Will throw exception if pixel size of new format is not equal to currently initialized format.
|
||||
//! Intended to switch formats indicating different interpretation of the same data
|
||||
//! (e.g. ImgGray and ImgAlpha).
|
||||
Standard_EXPORT void SetFormat (const ImgFormat thePixelFormat);
|
||||
|
||||
//! @return image width in pixels
|
||||
inline Standard_Size Width() const
|
||||
{
|
||||
@@ -258,11 +266,6 @@ public: //! @name low-level API for batch-processing (pixels reading / compariso
|
||||
return *reinterpret_cast<ColorType_t* >(myData.ChangeValue (theRow, theCol));
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//! Setup pixel format
|
||||
Standard_EXPORT void setFormat (ImgFormat thePixelFormat);
|
||||
|
||||
protected:
|
||||
|
||||
Image_PixMapData myData; //!< data buffer
|
||||
|
Reference in New Issue
Block a user