1 // Created on: 2012-07-18
2 // Created by: Kirill GAVRILOV
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Image_PixMapData_H__
17 #define _Image_PixMapData_H__
19 #include <Image_Color.hxx>
20 #include <NCollection_Buffer.hxx>
22 //! Structure to manage image buffer.
23 class Image_PixMapData : public NCollection_Buffer
27 //! Empty constructor.
29 : NCollection_Buffer (Handle(NCollection_BaseAllocator)()),
35 TopToDown (Standard_Size(-1))
41 void Init (const Handle(NCollection_BaseAllocator)& theAlloc,
42 const Standard_Size theSizeBPP,
43 const Standard_Size theSizeX,
44 const Standard_Size theSizeY,
45 const Standard_Size theSizeRowBytes,
46 Standard_Byte* theDataPtr)
48 SetAllocator (theAlloc); // will free old data as well
55 SizeRowBytes = theSizeRowBytes != 0 ? theSizeRowBytes : (theSizeX * theSizeBPP);
56 mySize = SizeRowBytes * SizeY;
61 SetTopDown (TopToDown == 1);
64 //! @return data pointer to requested row (first column).
65 inline const Standard_Byte* Row (const Standard_Size theRow) const
67 return myTopRowPtr + SizeRowBytes * theRow * TopToDown;
70 //! @return data pointer to requested row (first column).
71 inline Standard_Byte* ChangeRow (const Standard_Size theRow)
73 return myTopRowPtr + SizeRowBytes * theRow * TopToDown;
76 //! @return data pointer to requested position.
77 inline const Standard_Byte* Value (const Standard_Size theRow,
78 const Standard_Size theCol) const
80 return myTopRowPtr + SizeRowBytes * theRow * TopToDown + SizeBPP * theCol;
83 //! @return data pointer to requested position.
84 inline Standard_Byte* ChangeValue (const Standard_Size theRow,
85 const Standard_Size theCol)
87 return myTopRowPtr + SizeRowBytes * theRow * TopToDown + SizeBPP * theCol;
90 //! Compute the maximal row alignment for current row size.
91 //! @return maximal row alignment in bytes (up to 16 bytes).
92 inline Standard_Size MaxRowAligmentBytes() const
94 Standard_Size anAlignment = 2;
95 for (; anAlignment <= 16; anAlignment <<= 1)
97 if ((SizeRowBytes % anAlignment) != 0 || (Standard_Size(myData) % anAlignment) != 0)
99 return (anAlignment >> 1);
105 //! Setup scanlines order in memory - top-down or bottom-up.
106 //! Drawers should explicitly specify this value if current state IsTopDown() was ignored!
107 //! @param theIsTopDown top-down flag
108 inline void SetTopDown (const bool theIsTopDown)
110 TopToDown = (theIsTopDown ? 1 : Standard_Size(-1));
111 myTopRowPtr = ((TopToDown == 1 || myData == NULL)
112 ? myData : (myData + SizeRowBytes * (SizeY - 1)));
117 Standard_Byte* myTopRowPtr; //!< pointer to the topmost row (depending on scanlines order in memory)
121 Standard_Size SizeBPP; //!< bytes per pixel
122 Standard_Size SizeX; //!< width in pixels
123 Standard_Size SizeY; //!< height in pixels
124 Standard_Size SizeRowBytes; //!< number of bytes per line (in most cases equal to 3 * sizeX)
125 Standard_Size TopToDown; //!< image scanlines direction in memory from Top to the Down
129 typedef NCollection_Handle<Image_PixMapData> Handle(Image_PixMapData);
131 #endif // _Image_PixMapData_H__