6aca4d39 |
1 | // Created on: 2012-07-18 |
692613e5 |
2 | // Created by: Kirill GAVRILOV |
6aca4d39 |
3 | // Copyright (c) 2012-2014 OPEN CASCADE SAS |
692613e5 |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
692613e5 |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
692613e5 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
692613e5 |
15 | |
16 | #ifndef _Image_PixMapData_H__ |
17 | #define _Image_PixMapData_H__ |
18 | |
19 | #include <Image_Color.hxx> |
ca0c0b11 |
20 | #include <NCollection_Buffer.hxx> |
692613e5 |
21 | |
ca0c0b11 |
22 | //! Structure to manage image buffer. |
23 | class Image_PixMapData : public NCollection_Buffer |
692613e5 |
24 | { |
ca0c0b11 |
25 | public: |
692613e5 |
26 | |
ca0c0b11 |
27 | //! Empty constructor. |
28 | Image_PixMapData() |
29 | : NCollection_Buffer (Handle(NCollection_BaseAllocator)()), |
30 | myTopRowPtr (NULL), |
31 | SizeBPP (0), |
32 | SizeX (0), |
33 | SizeY (0), |
34 | SizeRowBytes (0), |
35 | TopToDown (Standard_Size(-1)) |
692613e5 |
36 | { |
ca0c0b11 |
37 | // |
692613e5 |
38 | } |
39 | |
ca0c0b11 |
40 | //! Initializer. |
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) |
692613e5 |
47 | { |
ca0c0b11 |
48 | SetAllocator (theAlloc); // will free old data as well |
49 | |
50 | myData = theDataPtr; |
51 | myTopRowPtr = NULL; |
52 | SizeBPP = theSizeBPP; |
53 | SizeX = theSizeX; |
54 | SizeY = theSizeY; |
55 | SizeRowBytes = theSizeRowBytes != 0 ? theSizeRowBytes : (theSizeX * theSizeBPP); |
56 | mySize = SizeRowBytes * SizeY; |
57 | if (myData == NULL) |
58 | { |
59 | Allocate (mySize); |
60 | } |
61 | SetTopDown (TopToDown == 1); |
692613e5 |
62 | } |
63 | |
64 | //! @return data pointer to requested row (first column). |
ca0c0b11 |
65 | inline const Standard_Byte* Row (const Standard_Size theRow) const |
692613e5 |
66 | { |
ca0c0b11 |
67 | return myTopRowPtr + SizeRowBytes * theRow * TopToDown; |
692613e5 |
68 | } |
69 | |
70 | //! @return data pointer to requested row (first column). |
ca0c0b11 |
71 | inline Standard_Byte* ChangeRow (const Standard_Size theRow) |
692613e5 |
72 | { |
ca0c0b11 |
73 | return myTopRowPtr + SizeRowBytes * theRow * TopToDown; |
692613e5 |
74 | } |
75 | |
76 | //! @return data pointer to requested position. |
ca0c0b11 |
77 | inline const Standard_Byte* Value (const Standard_Size theRow, |
78 | const Standard_Size theCol) const |
692613e5 |
79 | { |
ca0c0b11 |
80 | return myTopRowPtr + SizeRowBytes * theRow * TopToDown + SizeBPP * theCol; |
692613e5 |
81 | } |
82 | |
83 | //! @return data pointer to requested position. |
ca0c0b11 |
84 | inline Standard_Byte* ChangeValue (const Standard_Size theRow, |
85 | const Standard_Size theCol) |
692613e5 |
86 | { |
ca0c0b11 |
87 | return myTopRowPtr + SizeRowBytes * theRow * TopToDown + SizeBPP * theCol; |
692613e5 |
88 | } |
89 | |
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 |
93 | { |
94 | Standard_Size anAlignment = 2; |
95 | for (; anAlignment <= 16; anAlignment <<= 1) |
96 | { |
ca0c0b11 |
97 | if ((SizeRowBytes % anAlignment) != 0 || (Standard_Size(myData) % anAlignment) != 0) |
692613e5 |
98 | { |
99 | return (anAlignment >> 1); |
100 | } |
101 | } |
102 | return anAlignment; |
103 | } |
104 | |
ca0c0b11 |
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) |
692613e5 |
109 | { |
ca0c0b11 |
110 | TopToDown = (theIsTopDown ? 1 : Standard_Size(-1)); |
111 | myTopRowPtr = ((TopToDown == 1 || myData == NULL) |
112 | ? myData : (myData + SizeRowBytes * (SizeY - 1))); |
692613e5 |
113 | } |
114 | |
ca0c0b11 |
115 | protected: |
692613e5 |
116 | |
ca0c0b11 |
117 | Standard_Byte* myTopRowPtr; //!< pointer to the topmost row (depending on scanlines order in memory) |
692613e5 |
118 | |
119 | public: |
120 | |
ca0c0b11 |
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 |
692613e5 |
126 | |
7d3e64ef |
127 | |
128 | public: |
129 | |
ec357c5c |
130 | DEFINE_STANDARD_RTTI(Image_PixMapData, NCollection_Buffer) // Type definition |
7d3e64ef |
131 | |
692613e5 |
132 | }; |
133 | |
7d3e64ef |
134 | DEFINE_STANDARD_HANDLE(Image_PixMapData, NCollection_Buffer) |
ca0c0b11 |
135 | |
692613e5 |
136 | #endif // _Image_PixMapData_H__ |