1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0028441: Coding Rules - move out nested Image_PixMap::ImgFormat enumeration to dedicated enum Image_Format

Enumeration Image_PixMap::ImgFormat, previously declared as nested
enumeration within class *Image_PixMap*,
has been moved to global namespace as Image_Format following OCCT coding rules.

The enumeration values have suffix Image_Format_ and preserve
previous name scheme for easy renaming of old values.
E.g. Image_PixMap::ImgGray become Image_Format_Gray.
Old definitions are preserved as depreacated aliases to the new ones.
This commit is contained in:
kgv
2017-02-05 13:47:27 +03:00
committed by bugmaster
parent e6afb53983
commit dc858f4c5a
25 changed files with 307 additions and 274 deletions

View File

@@ -3,6 +3,7 @@ Image_AlienPixMap.hxx
Image_Color.hxx
Image_Diff.cxx
Image_Diff.hxx
Image_Format.hxx
Image_PixMap.cxx
Image_PixMap.hxx
Image_PixMapData.hxx

View File

@@ -36,66 +36,66 @@ IMPLEMENT_STANDARD_RTTIEXT(Image_AlienPixMap,Image_PixMap)
#ifdef HAVE_FREEIMAGE
namespace
{
static Image_PixMap::ImgFormat convertFromFreeFormat (FREE_IMAGE_TYPE theFormatFI,
FREE_IMAGE_COLOR_TYPE theColorTypeFI,
unsigned theBitsPerPixel)
static Image_Format convertFromFreeFormat (FREE_IMAGE_TYPE theFormatFI,
FREE_IMAGE_COLOR_TYPE theColorTypeFI,
unsigned theBitsPerPixel)
{
switch (theFormatFI)
{
case FIT_RGBF: return Image_PixMap::ImgRGBF;
case FIT_RGBAF: return Image_PixMap::ImgRGBAF;
case FIT_FLOAT: return Image_PixMap::ImgGrayF;
case FIT_RGBF: return Image_Format_RGBF;
case FIT_RGBAF: return Image_Format_RGBAF;
case FIT_FLOAT: return Image_Format_GrayF;
case FIT_BITMAP:
{
switch (theColorTypeFI)
{
case FIC_MINISBLACK:
{
return Image_PixMap::ImgGray;
return Image_Format_Gray;
}
case FIC_RGB:
{
if (Image_PixMap::IsBigEndianHost())
{
return (theBitsPerPixel == 32) ? Image_PixMap::ImgRGB32 : Image_PixMap::ImgRGB;
return (theBitsPerPixel == 32) ? Image_Format_RGB32 : Image_Format_RGB;
}
else
{
return (theBitsPerPixel == 32) ? Image_PixMap::ImgBGR32 : Image_PixMap::ImgBGR;
return (theBitsPerPixel == 32) ? Image_Format_BGR32 : Image_Format_BGR;
}
}
case FIC_RGBALPHA:
{
return Image_PixMap::IsBigEndianHost() ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA;
return Image_PixMap::IsBigEndianHost() ? Image_Format_RGBA : Image_Format_BGRA;
}
default:
return Image_PixMap::ImgUNKNOWN;
return Image_Format_UNKNOWN;
}
}
default:
return Image_PixMap::ImgUNKNOWN;
return Image_Format_UNKNOWN;
}
}
static FREE_IMAGE_TYPE convertToFreeFormat (Image_PixMap::ImgFormat theFormat)
static FREE_IMAGE_TYPE convertToFreeFormat (Image_Format theFormat)
{
switch (theFormat)
{
case Image_PixMap::ImgGrayF:
case Image_PixMap::ImgAlphaF:
case Image_Format_GrayF:
case Image_Format_AlphaF:
return FIT_FLOAT;
case Image_PixMap::ImgRGBAF:
case Image_Format_RGBAF:
return FIT_RGBAF;
case Image_PixMap::ImgRGBF:
case Image_Format_RGBF:
return FIT_RGBF;
case Image_PixMap::ImgRGBA:
case Image_PixMap::ImgBGRA:
case Image_PixMap::ImgRGB32:
case Image_PixMap::ImgBGR32:
case Image_PixMap::ImgRGB:
case Image_PixMap::ImgBGR:
case Image_PixMap::ImgGray:
case Image_PixMap::ImgAlpha:
case Image_Format_RGBA:
case Image_Format_BGRA:
case Image_Format_RGB32:
case Image_Format_BGR32:
case Image_Format_RGB:
case Image_Format_BGR:
case Image_Format_Gray:
case Image_Format_Alpha:
return FIT_BITMAP;
default:
return FIT_UNKNOWN;
@@ -128,7 +128,7 @@ Image_AlienPixMap::~Image_AlienPixMap()
// function : InitWrapper
// purpose :
// =======================================================================
bool Image_AlienPixMap::InitWrapper (ImgFormat,
bool Image_AlienPixMap::InitWrapper (Image_Format,
Standard_Byte*,
const Standard_Size,
const Standard_Size,
@@ -143,7 +143,7 @@ bool Image_AlienPixMap::InitWrapper (ImgFormat,
// purpose :
// =======================================================================
#ifdef HAVE_FREEIMAGE
bool Image_AlienPixMap::InitTrash (ImgFormat thePixelFormat,
bool Image_AlienPixMap::InitTrash (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size /*theSizeRowBytes*/)
@@ -158,14 +158,14 @@ bool Image_AlienPixMap::InitTrash (ImgFormat thePixelFormat,
}
FIBITMAP* anImage = FreeImage_AllocateT (aFormatFI, (int )theSizeX, (int )theSizeY, aBitsPerPixel);
Image_PixMap::ImgFormat aFormat = convertFromFreeFormat (FreeImage_GetImageType (anImage),
FreeImage_GetColorType (anImage),
FreeImage_GetBPP (anImage));
if (thePixelFormat == Image_PixMap::ImgBGR32
|| thePixelFormat == Image_PixMap::ImgRGB32)
Image_Format aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
FreeImage_GetColorType(anImage),
FreeImage_GetBPP (anImage));
if (thePixelFormat == Image_Format_BGR32
|| thePixelFormat == Image_Format_RGB32)
{
//FreeImage_SetTransparent (anImage, FALSE);
aFormat = (aFormat == Image_PixMap::ImgBGRA) ? Image_PixMap::ImgBGR32 : Image_PixMap::ImgRGB32;
aFormat = (aFormat == Image_Format_BGRA) ? Image_Format_BGR32 : Image_Format_RGB32;
}
Image_PixMap::InitWrapper (aFormat, FreeImage_GetBits (anImage),
@@ -177,7 +177,7 @@ bool Image_AlienPixMap::InitTrash (ImgFormat thePixelFormat,
return true;
}
#else
bool Image_AlienPixMap::InitTrash (ImgFormat thePixelFormat,
bool Image_AlienPixMap::InitTrash (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes)
@@ -297,10 +297,10 @@ bool Image_AlienPixMap::Load (const TCollection_AsciiString& theImagePath)
return false;
}
Image_PixMap::ImgFormat aFormat = convertFromFreeFormat (FreeImage_GetImageType (anImage),
FreeImage_GetColorType (anImage),
FreeImage_GetBPP (anImage));
if (aFormat == Image_PixMap::ImgUNKNOWN)
Image_Format aFormat = convertFromFreeFormat (FreeImage_GetImageType(anImage),
FreeImage_GetColorType(anImage),
FreeImage_GetBPP (anImage));
if (aFormat == Image_Format_UNKNOWN)
{
//anImage = FreeImage_ConvertTo24Bits (anImage);
TCollection_AsciiString aMessage = "Error: image file '";
@@ -401,16 +401,16 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
SetTopDown (false);
}
// FreeImage doesn't provide flexible format convertion API
// so we should perform multiple convertions in some cases!
// FreeImage doesn't provide flexible format conversion API
// so we should perform multiple conversions in some cases!
FIBITMAP* anImageToDump = myLibImage;
switch (anImageFormat)
{
case FIF_PNG:
case FIF_BMP:
{
if (Format() == Image_PixMap::ImgBGR32
|| Format() == Image_PixMap::ImgRGB32)
if (Format() == Image_Format_BGR32
|| Format() == Image_Format_RGB32)
{
// stupid FreeImage treats reserved byte as alpha if some bytes not set to 0xFF
for (Standard_Size aRow = 0; aRow < SizeY(); ++aRow)
@@ -453,7 +453,7 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
aTmpBitmap = aTmpBitmap24;
}
// need convertion to image with pallete (requires 24bit bitmap)
// need conversion to image with palette (requires 24bit bitmap)
anImageToDump = FreeImage_ColorQuantize (aTmpBitmap, FIQ_NNQUANT);
if (aTmpBitmap != myLibImage)
{
@@ -463,13 +463,13 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
}
case FIF_EXR:
{
if (Format() == Image_PixMap::ImgGray
|| Format() == Image_PixMap::ImgAlpha)
if (Format() == Image_Format_Gray
|| Format() == Image_Format_Alpha)
{
anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_FLOAT);
}
else if (Format() == Image_PixMap::ImgRGBA
|| Format() == Image_PixMap::ImgBGRA)
else if (Format() == Image_Format_RGBA
|| Format() == Image_Format_BGRA)
{
anImageToDump = FreeImage_ConvertToType (myLibImage, FIT_RGBAF);
}

View File

@@ -29,11 +29,11 @@ struct FIBITMAP;
//! - *.jpg, *.jpe, *.jpeg - JPEG/JIFF (Joint Photographic Experts Group) lossy format (compressed with quality losses). YUV color space used (automatically converted from/to RGB).
//! - *.tif, *.tiff - TIFF (Tagged Image File Format).
//! - *.tga - TGA (Truevision Targa Graphic), lossless format.
//! - *.gif - GIF (Graphical Interchange Format), lossy format. Color stored using pallete (up to 256 distinct colors).
//! - *.gif - GIF (Graphical Interchange Format), lossy format. Color stored using palette (up to 256 distinct colors).
//! - *.exr - OpenEXR high dynamic-range format (supports float pixel formats).
class Image_AlienPixMap : public Image_PixMap
{
DEFINE_STANDARD_RTTIEXT(Image_AlienPixMap, Image_PixMap)
public:
//! Empty constructor.
@@ -52,7 +52,7 @@ public:
//! thePixelFormat - if specified pixel format doesn't supported by image library
//! than nearest supported will be used instead!
//! theSizeRowBytes - may be ignored by this class and required alignemnt will be used instead!
Standard_EXPORT virtual bool InitTrash (ImgFormat thePixelFormat,
Standard_EXPORT virtual bool InitTrash (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes = 0) Standard_OVERRIDE;
@@ -79,7 +79,7 @@ private:
//! Wrapper initialization is disallowed for this class (will return false in any case)!
//! Use only copying and allocation initializers.
Standard_EXPORT virtual bool InitWrapper (ImgFormat thePixelFormat,
Standard_EXPORT virtual bool InitWrapper (Image_Format thePixelFormat,
Standard_Byte* theDataPtr,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
@@ -88,10 +88,6 @@ private:
//! Built-in PPM export
Standard_EXPORT bool savePPM (const TCollection_AsciiString& theFileName) const;
public:
DEFINE_STANDARD_RTTIEXT(Image_AlienPixMap,Image_PixMap) // Type definition
};
DEFINE_STANDARD_HANDLE(Image_AlienPixMap, Image_PixMap)

View File

@@ -117,14 +117,14 @@ namespace
{ 1, -1}, { 1, 0}, { 1, 1}
};
static bool isSupportedFormat (const Image_PixMap::ImgFormat theFormat)
static bool isSupportedFormat (const Image_Format theFormat)
{
return theFormat == Image_PixMap::ImgRGB
|| theFormat == Image_PixMap::ImgBGR
|| theFormat == Image_PixMap::ImgRGB32
|| theFormat == Image_PixMap::ImgBGR32
|| theFormat == Image_PixMap::ImgRGBA
|| theFormat == Image_PixMap::ImgBGRA;
return theFormat == Image_Format_RGB
|| theFormat == Image_Format_BGR
|| theFormat == Image_Format_RGB32
|| theFormat == Image_Format_BGR32
|| theFormat == Image_Format_RGBA
|| theFormat == Image_Format_BGRA;
}
} // anonymous namespace
@@ -344,7 +344,7 @@ Standard_Boolean Image_Diff::SaveDiffImage (Image_PixMap& theDiffImage) const
|| theDiffImage.SizeY() != myImageRef->SizeY()
|| !isSupportedFormat (theDiffImage.Format()))
{
if (!theDiffImage.InitTrash (Image_PixMap::ImgRGB, myImageRef->SizeX(), myImageRef->SizeY()))
if (!theDiffImage.InitTrash (Image_Format_RGB, myImageRef->SizeX(), myImageRef->SizeY()))
{
return Standard_False;
}
@@ -404,7 +404,7 @@ Standard_Boolean Image_Diff::SaveDiffImage (const TCollection_AsciiString& theDi
}
Image_AlienPixMap aDiff;
if (!aDiff.InitTrash (Image_PixMap::ImgRGB, myImageRef->SizeX(), myImageRef->SizeY())
if (!aDiff.InitTrash (Image_Format_RGB, myImageRef->SizeX(), myImageRef->SizeY())
|| !SaveDiffImage (aDiff))
{
return Standard_False;

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2012-2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Image_Format_HeaderFile
#define _Image_Format_HeaderFile
//! This enumeration defines packed image plane formats
enum Image_Format
{
Image_Format_UNKNOWN = 0, //!< unsupported or unknown format
Image_Format_Gray = 1, //!< 1 byte per pixel, intensity of the color
Image_Format_Alpha, //!< 1 byte per pixel, transparency
Image_Format_RGB, //!< 3 bytes packed RGB image plane
Image_Format_BGR, //!< same as RGB but with different components order
Image_Format_RGB32, //!< 4 bytes packed RGB image plane (1 extra byte for alignment, may have undefined value)
Image_Format_BGR32, //!< same as RGB but with different components order
Image_Format_RGBA, //!< 4 bytes packed RGBA image plane
Image_Format_BGRA, //!< same as RGBA but with different components order
Image_Format_GrayF, //!< 1 float (4-bytes) per pixel (1-component plane), intensity of the color
Image_Format_AlphaF, //!< 1 float (4-bytes) per pixel (1-component plane), transparency
Image_Format_RGBF, //!< 3 floats (12-bytes) RGB image plane
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
};
#endif // _Image_Format_HeaderFile

View File

@@ -26,7 +26,7 @@ IMPLEMENT_STANDARD_RTTIEXT(Image_PixMap,Standard_Transient)
// purpose :
// =======================================================================
Image_PixMap::Image_PixMap()
: myImgFormat (Image_PixMap::ImgGray)
: myImgFormat (Image_Format_Gray)
{
//
}
@@ -40,32 +40,32 @@ Image_PixMap::~Image_PixMap()
Clear();
}
Standard_Size Image_PixMap::SizePixelBytes (const Image_PixMap::ImgFormat thePixelFormat)
Standard_Size Image_PixMap::SizePixelBytes (const Image_Format thePixelFormat)
{
switch (thePixelFormat)
{
case ImgGrayF:
case ImgAlphaF:
case Image_Format_GrayF:
case Image_Format_AlphaF:
return sizeof(float);
case ImgRGBAF:
case ImgBGRAF:
case Image_Format_RGBAF:
case Image_Format_BGRAF:
return sizeof(float) * 4;
case ImgRGBF:
case ImgBGRF:
case Image_Format_RGBF:
case Image_Format_BGRF:
return sizeof(float) * 3;
case ImgRGBA:
case ImgBGRA:
case Image_Format_RGBA:
case Image_Format_BGRA:
return 4;
case ImgRGB32:
case ImgBGR32:
case Image_Format_RGB32:
case Image_Format_BGR32:
return 4;
case ImgRGB:
case ImgBGR:
case Image_Format_RGB:
case Image_Format_BGR:
return 3;
case ImgGray:
case ImgAlpha:
case Image_Format_Gray:
case Image_Format_Alpha:
return 1;
case ImgUNKNOWN:
case Image_Format_UNKNOWN:
return 1;
}
return 1;
@@ -75,7 +75,7 @@ Standard_Size Image_PixMap::SizePixelBytes (const Image_PixMap::ImgFormat thePix
// function : SetFormat
// purpose :
// =======================================================================
void Image_PixMap::SetFormat (Image_PixMap::ImgFormat thePixelFormat)
void Image_PixMap::SetFormat (Image_Format thePixelFormat)
{
if (myImgFormat == thePixelFormat)
{
@@ -96,11 +96,11 @@ void Image_PixMap::SetFormat (Image_PixMap::ImgFormat thePixelFormat)
// function : InitWrapper
// purpose :
// =======================================================================
bool Image_PixMap::InitWrapper (Image_PixMap::ImgFormat thePixelFormat,
Standard_Byte* theDataPtr,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes)
bool Image_PixMap::InitWrapper (Image_Format thePixelFormat,
Standard_Byte* theDataPtr,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes)
{
Clear();
myImgFormat = thePixelFormat;
@@ -119,10 +119,10 @@ bool Image_PixMap::InitWrapper (Image_PixMap::ImgFormat thePixelFormat,
// function : InitTrash
// purpose :
// =======================================================================
bool Image_PixMap::InitTrash (Image_PixMap::ImgFormat thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes)
bool Image_PixMap::InitTrash (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes)
{
Clear();
myImgFormat = thePixelFormat;
@@ -143,11 +143,11 @@ bool Image_PixMap::InitTrash (Image_PixMap::ImgFormat thePixelFormat,
// function : InitZero
// purpose :
// =======================================================================
bool Image_PixMap::InitZero (Image_PixMap::ImgFormat thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes,
const Standard_Byte theValue)
bool Image_PixMap::InitZero (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes,
const Standard_Byte theValue)
{
if (!InitTrash (thePixelFormat, theSizeX, theSizeY, theSizeRowBytes))
{
@@ -205,7 +205,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
switch (myImgFormat)
{
case ImgGrayF:
case Image_Format_GrayF:
{
const Standard_ShortReal& aPixel = Value<Standard_ShortReal> (theY, theX);
theAlpha = 1.0; // opaque
@@ -214,13 +214,13 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel)),
Quantity_TOC_RGB);
}
case ImgAlphaF:
case Image_Format_AlphaF:
{
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:
case Image_Format_RGBAF:
{
const Image_ColorRGBAF& aPixel = Value<Image_ColorRGBAF> (theY, theX);
theAlpha = aPixel.a();
@@ -229,7 +229,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (aPixel.b()),
Quantity_TOC_RGB);
}
case ImgBGRAF:
case Image_Format_BGRAF:
{
const Image_ColorBGRAF& aPixel = Value<Image_ColorBGRAF> (theY, theX);
theAlpha = aPixel.a();
@@ -238,7 +238,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (aPixel.b()),
Quantity_TOC_RGB);
}
case ImgRGBF:
case Image_Format_RGBF:
{
const Image_ColorRGBF& aPixel = Value<Image_ColorRGBF> (theY, theX);
theAlpha = 1.0; // opaque
@@ -247,7 +247,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (aPixel.b()),
Quantity_TOC_RGB);
}
case ImgBGRF:
case Image_Format_BGRF:
{
const Image_ColorBGRF& aPixel = Value<Image_ColorBGRF> (theY, theX);
theAlpha = 1.0; // opaque
@@ -256,7 +256,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (aPixel.b()),
Quantity_TOC_RGB);
}
case ImgRGBA:
case Image_Format_RGBA:
{
const Image_ColorRGBA& aPixel = Value<Image_ColorRGBA> (theY, theX);
theAlpha = Standard_Real (aPixel.a()) / 255.0;
@@ -265,7 +265,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel.b()) / 255.0),
Quantity_TOC_RGB);
}
case ImgBGRA:
case Image_Format_BGRA:
{
const Image_ColorBGRA& aPixel = Value<Image_ColorBGRA> (theY, theX);
theAlpha = Standard_Real (aPixel.a()) / 255.0;
@@ -274,7 +274,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel.b()) / 255.0),
Quantity_TOC_RGB);
}
case ImgRGB32:
case Image_Format_RGB32:
{
const Image_ColorRGB32& aPixel = Value<Image_ColorRGB32> (theY, theX);
theAlpha = 1.0; // opaque
@@ -283,7 +283,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel.b()) / 255.0),
Quantity_TOC_RGB);
}
case ImgBGR32:
case Image_Format_BGR32:
{
const Image_ColorBGR32& aPixel = Value<Image_ColorBGR32> (theY, theX);
theAlpha = 1.0; // opaque
@@ -292,7 +292,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel.b()) / 255.0),
Quantity_TOC_RGB);
}
case ImgRGB:
case Image_Format_RGB:
{
const Image_ColorRGB& aPixel = Value<Image_ColorRGB> (theY, theX);
theAlpha = 1.0; // opaque
@@ -301,7 +301,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel.b()) / 255.0),
Quantity_TOC_RGB);
}
case ImgBGR:
case Image_Format_BGR:
{
const Image_ColorBGR& aPixel = Value<Image_ColorBGR> (theY, theX);
theAlpha = 1.0; // opaque
@@ -310,7 +310,7 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel.b()) / 255.0),
Quantity_TOC_RGB);
}
case ImgGray:
case Image_Format_Gray:
{
const Standard_Byte& aPixel = Value<Standard_Byte> (theY, theX);
theAlpha = 1.0; // opaque
@@ -319,13 +319,13 @@ Quantity_Color Image_PixMap::PixelColor (const Standard_Integer theX,
Quantity_Parameter (Standard_Real (aPixel) / 255.0),
Quantity_TOC_RGB);
}
case ImgAlpha:
case Image_Format_Alpha:
{
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:
case Image_Format_UNKNOWN:
{
break;
}
@@ -353,17 +353,17 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
switch (myImgFormat)
{
case ImgGrayF:
case Image_Format_GrayF:
{
ChangeValue<Standard_ShortReal> (theY, theX) = theColor.r();
return;
}
case ImgAlphaF:
case Image_Format_AlphaF:
{
ChangeValue<Standard_ShortReal> (theY, theX) = theColor.a();
return;
}
case ImgRGBAF:
case Image_Format_RGBAF:
{
Image_ColorRGBAF& aPixel = ChangeValue<Image_ColorRGBAF> (theY, theX);
aPixel.r() = theColor.r();
@@ -372,7 +372,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.a() = theColor.a();
return;
}
case ImgBGRAF:
case Image_Format_BGRAF:
{
Image_ColorBGRAF& aPixel = ChangeValue<Image_ColorBGRAF> (theY, theX);
aPixel.r() = theColor.r();
@@ -381,7 +381,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.a() = theColor.a();
return;
}
case ImgRGBF:
case Image_Format_RGBF:
{
Image_ColorRGBF& aPixel = ChangeValue<Image_ColorRGBF> (theY, theX);
aPixel.r() = theColor.r();
@@ -389,7 +389,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.b() = theColor.b();
return;
}
case ImgBGRF:
case Image_Format_BGRF:
{
Image_ColorBGRF& aPixel = ChangeValue<Image_ColorBGRF> (theY, theX);
aPixel.r() = theColor.r();
@@ -397,7 +397,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.b() = theColor.b();
return;
}
case ImgRGBA:
case Image_Format_RGBA:
{
Image_ColorRGBA& aPixel = ChangeValue<Image_ColorRGBA> (theY, theX);
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
@@ -406,7 +406,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.a() = Standard_Byte(theColor.a() * 255.0f);
return;
}
case ImgBGRA:
case Image_Format_BGRA:
{
Image_ColorBGRA& aPixel = ChangeValue<Image_ColorBGRA> (theY, theX);
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
@@ -415,7 +415,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.a() = Standard_Byte(theColor.a() * 255.0f);
return;
}
case ImgRGB32:
case Image_Format_RGB32:
{
Image_ColorRGB32& aPixel = ChangeValue<Image_ColorRGB32> (theY, theX);
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
@@ -424,7 +424,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.a_() = 255;
return;
}
case ImgBGR32:
case Image_Format_BGR32:
{
Image_ColorBGR32& aPixel = ChangeValue<Image_ColorBGR32> (theY, theX);
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
@@ -433,7 +433,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.a_() = 255;
return;
}
case ImgRGB:
case Image_Format_RGB:
{
Image_ColorRGB& aPixel = ChangeValue<Image_ColorRGB> (theY, theX);
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
@@ -441,7 +441,7 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
return;
}
case ImgBGR:
case Image_Format_BGR:
{
Image_ColorBGR& aPixel = ChangeValue<Image_ColorBGR> (theY, theX);
aPixel.r() = Standard_Byte(theColor.r() * 255.0f);
@@ -449,17 +449,17 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
aPixel.b() = Standard_Byte(theColor.b() * 255.0f);
return;
}
case ImgGray:
case Image_Format_Gray:
{
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(theColor.r() * 255.0f);
return;
}
case ImgAlpha:
case Image_Format_Alpha:
{
ChangeValue<Standard_Byte> (theY, theX) = Standard_Byte(theColor.a() * 255.0f);
return;
}
case ImgUNKNOWN:
case Image_Format_UNKNOWN:
{
return;
}
@@ -474,13 +474,13 @@ bool Image_PixMap::SwapRgbaBgra (Image_PixMap& theImage)
{
switch (theImage.Format())
{
case Image_PixMap::ImgBGR32:
case Image_PixMap::ImgRGB32:
case Image_PixMap::ImgBGRA:
case Image_PixMap::ImgRGBA:
case Image_Format_BGR32:
case Image_Format_RGB32:
case Image_Format_BGRA:
case Image_Format_RGBA:
{
const bool toResetAlpha = theImage.Format() == Image_PixMap::ImgBGR32
|| theImage.Format() == Image_PixMap::ImgRGB32;
const bool toResetAlpha = theImage.Format() == Image_Format_BGR32
|| theImage.Format() == Image_Format_RGB32;
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{
for (Standard_Size aCol = 0; aCol < theImage.SizeX(); ++aCol)
@@ -498,8 +498,8 @@ bool Image_PixMap::SwapRgbaBgra (Image_PixMap& theImage)
}
return true;
}
case Image_PixMap::ImgBGR:
case Image_PixMap::ImgRGB:
case Image_Format_BGR:
case Image_Format_RGB:
{
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{
@@ -514,10 +514,10 @@ bool Image_PixMap::SwapRgbaBgra (Image_PixMap& theImage)
}
return true;
}
case Image_PixMap::ImgBGRF:
case Image_PixMap::ImgRGBF:
case Image_PixMap::ImgBGRAF:
case Image_PixMap::ImgRGBAF:
case Image_Format_BGRF:
case Image_Format_RGBF:
case Image_Format_BGRAF:
case Image_Format_RGBAF:
{
for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow)
{

View File

@@ -16,6 +16,7 @@
#ifndef _Image_PixMap_H__
#define _Image_PixMap_H__
#include <Image_Format.hxx>
#include <Image_PixMapData.hxx>
#include <Standard_Transient.hxx>
#include <Quantity_ColorRGBA.hxx>
@@ -23,28 +24,9 @@
//! Class represents packed image plane.
class Image_PixMap : public Standard_Transient
{
DEFINE_STANDARD_RTTIEXT(Image_PixMap, Standard_Transient)
public:
//! This enumeration define packed image plane formats
typedef enum tagFormat {
ImgUNKNOWN = 0, //!< unsupported or unknown format
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), 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
ImgBGRAF, //!< same as RGBAF but with different components order
} ImgFormat;
//! Determine Big-Endian at runtime
static inline bool IsBigEndianHost()
{
@@ -56,25 +38,22 @@ public:
//! Auxiliary method for swapping bytes between RGB and BGR formats.
//! This method modifies the image data but does not change pixel format!
//! Method will fail if pixel format is not one of the following:
//! - ImgRGB32 / ImgBGR32
//! - ImgRGBA / ImgBGRA
//! - ImgRGB / ImgBGR
//! - ImgRGBF / ImgBGRF
//! - ImgRGBAF / ImgBGRAF
//! - Image_Format_RGB32 / Image_Format_BGR32
//! - Image_Format_RGBA / Image_Format_BGRA
//! - Image_Format_RGB / Image_Format_BGR
//! - Image_Format_RGBF / Image_Format_BGRF
//! - Image_Format_RGBAF / Image_Format_BGRAF
Standard_EXPORT static bool SwapRgbaBgra (Image_PixMap& theImage);
public: // high-level API
inline ImgFormat Format() const
{
return myImgFormat;
}
Image_Format Format() const { 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);
Standard_EXPORT void SetFormat (const Image_Format thePixelFormat);
//! @return image width in pixels
inline Standard_Size Width() const
@@ -167,7 +146,7 @@ public: // high-level API
//! Data will not be copied! Notice that caller should ensure
//! that data pointer will not be released during this wrapper lifetime.
//! You may call InitCopy() to perform data copying.
Standard_EXPORT virtual bool InitWrapper (ImgFormat thePixelFormat,
Standard_EXPORT virtual bool InitWrapper (Image_Format thePixelFormat,
Standard_Byte* theDataPtr,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
@@ -175,7 +154,7 @@ public: // high-level API
//! Initialize image plane with required dimensions.
//! Memory will be left uninitialized (performance trick).
Standard_EXPORT virtual bool InitTrash (ImgFormat thePixelFormat,
Standard_EXPORT virtual bool InitTrash (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes = 0);
@@ -186,7 +165,7 @@ public: // high-level API
//! Initialize image plane with required dimensions.
//! Buffer will be zeroed (black color for most formats).
Standard_EXPORT bool InitZero (ImgFormat thePixelFormat,
Standard_EXPORT bool InitZero (Image_Format thePixelFormat,
const Standard_Size theSizeX,
const Standard_Size theSizeY,
const Standard_Size theSizeRowBytes = 0,
@@ -257,7 +236,7 @@ public: //! @name low-level API for batch-processing (pixels reading / compariso
}
//! @return bytes reserved for one pixel (may include extra bytes for alignment).
Standard_EXPORT static Standard_Size SizePixelBytes (const Image_PixMap::ImgFormat thePixelFormat);
Standard_EXPORT static Standard_Size SizePixelBytes (const Image_Format thePixelFormat);
//! @return bytes reserved per row.
//! Could be larger than needed to store packed row (extra bytes for alignment etc.).
@@ -303,10 +282,30 @@ public: //! @name low-level API for batch-processing (pixels reading / compariso
return *reinterpret_cast<ColorType_t* >(myData.ChangeValue (theRow, theCol));
}
public:
Standard_DEPRECATED("This member is deprecated, use Image_Format enumeration instead")
typedef Image_Format ImgFormat;
static const Image_Format ImgUNKNOWN = Image_Format_UNKNOWN;
static const Image_Format ImgGray = Image_Format_Gray;
static const Image_Format ImgAlpha = Image_Format_Alpha;
static const Image_Format ImgRGB = Image_Format_RGB;
static const Image_Format ImgBGR = Image_Format_BGR;
static const Image_Format ImgRGB32 = Image_Format_RGB32;
static const Image_Format ImgBGR32 = Image_Format_BGR32;
static const Image_Format ImgRGBA = Image_Format_RGBA;
static const Image_Format ImgBGRA = Image_Format_BGRA;
static const Image_Format ImgGrayF = Image_Format_GrayF;
static const Image_Format ImgAlphaF = Image_Format_AlphaF;
static const Image_Format ImgRGBF = Image_Format_RGBF;
static const Image_Format ImgBGRF = Image_Format_BGRF;
static const Image_Format ImgRGBAF = Image_Format_RGBAF;
static const Image_Format ImgBGRAF = Image_Format_BGRAF;
protected:
Image_PixMapData myData; //!< data buffer
ImgFormat myImgFormat; //!< pixel format
Image_Format myImgFormat; //!< pixel format
private:
@@ -314,10 +313,6 @@ private:
Image_PixMap (const Image_PixMap& );
Image_PixMap& operator= (const Image_PixMap& );
public:
DEFINE_STANDARD_RTTIEXT(Image_PixMap,Standard_Transient) // Type definition
};
DEFINE_STANDARD_HANDLE(Image_PixMap, Standard_Transient)