1 // Copyright (c) 2019 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13 
14 #ifndef _Image_PixMapTypedData_Header
15 #define _Image_PixMapTypedData_Header
16 
17 #include <Image_PixMapData.hxx>
18 
19 //! Structure to manage image buffer with predefined pixel type.
20 template<typename PixelType_t>
21 class Image_PixMapTypedData : public Image_PixMapData
22 {
23 public:
24   //! Empty constructor.
Image_PixMapTypedData()25   Image_PixMapTypedData() {}
26 
27   //! Initializer.
Init(const Handle (NCollection_BaseAllocator)& theAlloc,Standard_Size theSizeX,Standard_Size theSizeY,Standard_Size theSizeRowBytes=0,Standard_Byte * theDataPtr=0)28   bool Init (const Handle(NCollection_BaseAllocator)& theAlloc,
29              Standard_Size  theSizeX,
30              Standard_Size  theSizeY,
31              Standard_Size  theSizeRowBytes = 0,
32              Standard_Byte* theDataPtr = 0)
33   {
34     const Standard_Size aSizeBPP = sizeof(PixelType_t);
35     return Image_PixMapData::Init (theAlloc, aSizeBPP, theSizeX, theSizeY, theSizeRowBytes, theDataPtr);
36   }
37 
38   //! Reset all values to specified one.
Init(const PixelType_t & theValue)39   void Init (const PixelType_t& theValue)
40   {
41     for (Standard_Size aRowIter = 0; aRowIter < SizeY; ++aRowIter)
42     {
43       for (Standard_Size aColIter = 0; aColIter < SizeX; ++aColIter)
44       {
45         ChangeValue (aRowIter, aColIter) = theValue;
46       }
47     }
48   }
49 
50   //! @return data pointer to requested row (first column).
Row(Standard_Size theRow) const51   const PixelType_t* Row (Standard_Size theRow) const { return (const PixelType_t* )Image_PixMapData::Row (theRow); }
52 
53   //! @return data pointer to requested row (first column).
ChangeRow(Standard_Size theRow)54   PixelType_t* ChangeRow (Standard_Size theRow) { return (PixelType_t* )Image_PixMapData::ChangeRow (theRow); }
55 
56   //! @return data pointer to requested position.
Value(Standard_Size theRow,Standard_Size theCol) const57   const PixelType_t& Value (Standard_Size theRow, Standard_Size theCol) const { return *(const PixelType_t* )Image_PixMapData::Value (theRow, theCol); }
58 
59   //! @return data pointer to requested position.
ChangeValue(Standard_Size theRow,Standard_Size theCol)60   PixelType_t& ChangeValue (Standard_Size theRow, Standard_Size theCol) { return *(PixelType_t* )Image_PixMapData::ChangeValue (theRow, theCol); }
61 
62 };
63 
64 #endif // _Image_PixMapTypedData_Header
65