File indexing completed on 2024-11-15 09:47:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef Image_PixMapData_HeaderFile
0017 #define Image_PixMapData_HeaderFile
0018
0019 #include <Image_Color.hxx>
0020 #include <NCollection_Buffer.hxx>
0021 #include <NCollection_Vec3.hxx>
0022
0023
0024 class Image_PixMapData : public NCollection_Buffer
0025 {
0026 public:
0027
0028
0029 Image_PixMapData()
0030 : NCollection_Buffer (Handle(NCollection_BaseAllocator)()),
0031 myTopRowPtr (NULL),
0032 SizeBPP (0),
0033 SizeX (0),
0034 SizeY (0),
0035 SizeZ (0),
0036 SizeRowBytes (0),
0037 SizeSliceBytes (0),
0038 TopToDown (Standard_Size(-1))
0039 {
0040
0041 }
0042
0043
0044 bool Init (const Handle(NCollection_BaseAllocator)& theAlloc,
0045 const Standard_Size theSizeBPP,
0046 const Standard_Size theSizeX,
0047 const Standard_Size theSizeY,
0048 const Standard_Size theSizeRowBytes,
0049 Standard_Byte* theDataPtr)
0050 {
0051 return Init (theAlloc, theSizeBPP, NCollection_Vec3<Standard_Size> (theSizeX, theSizeY, 1), theSizeRowBytes, theDataPtr);
0052 }
0053
0054
0055 bool Init (const Handle(NCollection_BaseAllocator)& theAlloc,
0056 const Standard_Size theSizeBPP,
0057 const NCollection_Vec3<Standard_Size>& theSizeXYZ,
0058 const Standard_Size theSizeRowBytes,
0059 Standard_Byte* theDataPtr)
0060 {
0061 SetAllocator (theAlloc);
0062
0063 myData = theDataPtr;
0064 myTopRowPtr = NULL;
0065 SizeBPP = theSizeBPP;
0066 SizeX = theSizeXYZ.x();
0067 SizeY = theSizeXYZ.y();
0068 SizeZ = theSizeXYZ.z();
0069 SizeRowBytes = theSizeRowBytes != 0 ? theSizeRowBytes : (SizeX * theSizeBPP);
0070 SizeSliceBytes = SizeRowBytes * SizeY;
0071 mySize = SizeSliceBytes * SizeZ;
0072 if (myData == NULL)
0073 {
0074 Allocate (mySize);
0075 }
0076 SetTopDown (TopToDown == 1);
0077 return !IsEmpty();
0078 }
0079
0080
0081 void ZeroData()
0082 {
0083 if (myData != NULL)
0084 {
0085 memset (myData, 0, mySize);
0086 }
0087 }
0088
0089
0090 const Standard_Byte* Row (const Standard_Size theRow) const
0091 {
0092 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown);
0093 }
0094
0095
0096 Standard_Byte* ChangeRow (const Standard_Size theRow)
0097 {
0098 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown);
0099 }
0100
0101
0102 const Standard_Byte* Value (const Standard_Size theRow,
0103 const Standard_Size theCol) const
0104 {
0105 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + SizeBPP * theCol;
0106 }
0107
0108
0109 Standard_Byte* ChangeValue (Standard_Size theRow,
0110 Standard_Size theCol)
0111 {
0112 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + SizeBPP * theCol;
0113 }
0114
0115
0116 const Standard_Byte* ValueXY (Standard_Size theX,
0117 Standard_Size theY) const
0118 {
0119 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX;
0120 }
0121
0122
0123 Standard_Byte* ChangeValueXY (Standard_Size theX,
0124 Standard_Size theY)
0125 {
0126 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX;
0127 }
0128
0129 public:
0130
0131
0132 const Standard_Byte* Slice (Standard_Size theSlice) const
0133 {
0134 return myData + ptrdiff_t(SizeSliceBytes * theSlice);
0135 }
0136
0137
0138 Standard_Byte* ChangeSlice (Standard_Size theSlice)
0139 {
0140 return myData + ptrdiff_t(SizeSliceBytes * theSlice);
0141 }
0142
0143
0144 const Standard_Byte* SliceRow (Standard_Size theSlice,
0145 Standard_Size theRow) const
0146 {
0147 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + ptrdiff_t(SizeSliceBytes * theSlice);
0148 }
0149
0150
0151 Standard_Byte* ChangeSliceRow (Standard_Size theSlice,
0152 Standard_Size theRow)
0153 {
0154 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theRow * TopToDown) + ptrdiff_t(SizeSliceBytes * theSlice);
0155 }
0156
0157
0158 const Standard_Byte* ValueXYZ (Standard_Size theX,
0159 Standard_Size theY,
0160 Standard_Size theZ) const
0161 {
0162 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX + ptrdiff_t(SizeSliceBytes * theZ);
0163 }
0164
0165
0166 Standard_Byte* ChangeValueXYZ (Standard_Size theX,
0167 Standard_Size theY,
0168 Standard_Size theZ)
0169 {
0170 return myTopRowPtr + ptrdiff_t(SizeRowBytes * theY * TopToDown) + SizeBPP * theX + ptrdiff_t(SizeSliceBytes * theZ);
0171 }
0172
0173
0174
0175 Standard_Size MaxRowAligmentBytes() const
0176 {
0177 Standard_Size anAlignment = 2;
0178 for (; anAlignment <= 16; anAlignment <<= 1)
0179 {
0180 if ((SizeRowBytes % anAlignment) != 0 || (Standard_Size(myData) % anAlignment) != 0)
0181 {
0182 return (anAlignment >> 1);
0183 }
0184 }
0185 return anAlignment;
0186 }
0187
0188
0189
0190
0191 void SetTopDown (const bool theIsTopDown)
0192 {
0193 TopToDown = (theIsTopDown ? 1 : Standard_Size(-1));
0194 myTopRowPtr = ((TopToDown == 1 || myData == NULL)
0195 ? myData : (myData + SizeRowBytes * (SizeY - 1)));
0196 }
0197
0198 protected:
0199
0200 Standard_Byte* myTopRowPtr;
0201
0202 public:
0203
0204 Standard_Size SizeBPP;
0205 Standard_Size SizeX;
0206 Standard_Size SizeY;
0207 Standard_Size SizeZ;
0208 Standard_Size SizeRowBytes;
0209 Standard_Size SizeSliceBytes;
0210 Standard_Size TopToDown;
0211
0212 public:
0213
0214 DEFINE_STANDARD_RTTIEXT(Image_PixMapData, NCollection_Buffer)
0215
0216 };
0217
0218 DEFINE_STANDARD_HANDLE(Image_PixMapData, NCollection_Buffer)
0219
0220 #endif