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