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 | // |
973c2be1 |
7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public 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. |
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> |
20 | |
21 | //! POD template structure to access image buffer |
22 | template<typename ColorType_t> |
23 | struct Image_PixMapData |
24 | { |
25 | |
26 | //! @return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.). |
27 | inline const ColorType_t* Data() const |
28 | { |
29 | return (const ColorType_t* )myDataPtr; |
30 | } |
31 | |
32 | //! @return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.). |
33 | inline ColorType_t* ChangeData() |
34 | { |
35 | return (ColorType_t* )myDataPtr; |
36 | } |
37 | |
38 | //! @return data pointer to requested row (first column). |
39 | inline const ColorType_t* Row (const Standard_Size theRow) const |
40 | { |
41 | return (ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown); |
42 | } |
43 | |
44 | //! @return data pointer to requested row (first column). |
45 | inline ColorType_t* ChangeRow (const Standard_Size theRow) |
46 | { |
47 | return (ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown); |
48 | } |
49 | |
50 | //! @return data pointer to requested position. |
51 | inline const ColorType_t& Value (const Standard_Size theRow, |
52 | const Standard_Size theCol) const |
53 | { |
54 | return *(const ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown + mySizeBPP * theCol); |
55 | } |
56 | |
57 | //! @return data pointer to requested position. |
58 | inline ColorType_t& ChangeValue (const Standard_Size theRow, |
59 | const Standard_Size theCol) |
60 | { |
61 | return *(ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown + mySizeBPP * theCol); |
62 | } |
63 | |
64 | //! Compute the maximal row alignment for current row size. |
65 | //! @return maximal row alignment in bytes (up to 16 bytes). |
66 | inline Standard_Size MaxRowAligmentBytes() const |
67 | { |
68 | Standard_Size anAlignment = 2; |
69 | for (; anAlignment <= 16; anAlignment <<= 1) |
70 | { |
71 | if ((mySizeRowBytes % anAlignment) != 0 || (Standard_Size(myDataPtr) % anAlignment) != 0) |
72 | { |
73 | return (anAlignment >> 1); |
74 | } |
75 | } |
76 | return anAlignment; |
77 | } |
78 | |
79 | //! @return bytes allocated for the whole image plane. |
80 | inline Standard_Size SizeBytes() const |
81 | { |
82 | return mySizeRowBytes * mySizeY; |
83 | } |
84 | |
85 | //! @return image width in pixels |
86 | inline Standard_Size SizeX() const |
87 | { |
88 | return mySizeX; |
89 | } |
90 | |
91 | //! @return image height in pixels |
92 | inline Standard_Size SizeY() const |
93 | { |
94 | return mySizeY; |
95 | } |
96 | |
97 | public: |
98 | |
99 | Standard_Byte* myDataPtr; //!< pointer to the data |
100 | Standard_Byte* myTopRowPtr; //!< pointer to the topmost row (depending on scanlines order in memory) |
101 | Standard_Size mySizeBPP; //!< bytes per pixel |
102 | Standard_Size mySizeX; //!< width in pixels |
103 | Standard_Size mySizeY; //!< height in pixels |
104 | Standard_Size mySizeRowBytes; //!< number of bytes per line (in most cases equal to 3 * sizeX) |
105 | Standard_Size myTopToDown; //!< image scanlines direction in memory from Top to the Down |
106 | |
107 | }; |
108 | |
109 | #endif // _Image_PixMapData_H__ |