0024157: Parallelization of assembly part of BO
[occt.git] / src / Image / Image_PixMapData.hxx
CommitLineData
692613e5 1// Created on: 2012-07-18
2// Created by: Kirill GAVRILOV
3// Copyright (c) 2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20#ifndef _Image_PixMapData_H__
21#define _Image_PixMapData_H__
22
23#include <Image_Color.hxx>
24
25//! POD template structure to access image buffer
26template<typename ColorType_t>
27struct Image_PixMapData
28{
29
30 //! @return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.).
31 inline const ColorType_t* Data() const
32 {
33 return (const ColorType_t* )myDataPtr;
34 }
35
36 //! @return data pointer for low-level operations (copying entire buffer, parsing with extra tools etc.).
37 inline ColorType_t* ChangeData()
38 {
39 return (ColorType_t* )myDataPtr;
40 }
41
42 //! @return data pointer to requested row (first column).
43 inline const ColorType_t* Row (const Standard_Size theRow) const
44 {
45 return (ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown);
46 }
47
48 //! @return data pointer to requested row (first column).
49 inline ColorType_t* ChangeRow (const Standard_Size theRow)
50 {
51 return (ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown);
52 }
53
54 //! @return data pointer to requested position.
55 inline const ColorType_t& Value (const Standard_Size theRow,
56 const Standard_Size theCol) const
57 {
58 return *(const ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown + mySizeBPP * theCol);
59 }
60
61 //! @return data pointer to requested position.
62 inline ColorType_t& ChangeValue (const Standard_Size theRow,
63 const Standard_Size theCol)
64 {
65 return *(ColorType_t* )(myTopRowPtr + mySizeRowBytes * theRow * myTopToDown + mySizeBPP * theCol);
66 }
67
68 //! Compute the maximal row alignment for current row size.
69 //! @return maximal row alignment in bytes (up to 16 bytes).
70 inline Standard_Size MaxRowAligmentBytes() const
71 {
72 Standard_Size anAlignment = 2;
73 for (; anAlignment <= 16; anAlignment <<= 1)
74 {
75 if ((mySizeRowBytes % anAlignment) != 0 || (Standard_Size(myDataPtr) % anAlignment) != 0)
76 {
77 return (anAlignment >> 1);
78 }
79 }
80 return anAlignment;
81 }
82
83 //! @return bytes allocated for the whole image plane.
84 inline Standard_Size SizeBytes() const
85 {
86 return mySizeRowBytes * mySizeY;
87 }
88
89 //! @return image width in pixels
90 inline Standard_Size SizeX() const
91 {
92 return mySizeX;
93 }
94
95 //! @return image height in pixels
96 inline Standard_Size SizeY() const
97 {
98 return mySizeY;
99 }
100
101public:
102
103 Standard_Byte* myDataPtr; //!< pointer to the data
104 Standard_Byte* myTopRowPtr; //!< pointer to the topmost row (depending on scanlines order in memory)
105 Standard_Size mySizeBPP; //!< bytes per pixel
106 Standard_Size mySizeX; //!< width in pixels
107 Standard_Size mySizeY; //!< height in pixels
108 Standard_Size mySizeRowBytes; //!< number of bytes per line (in most cases equal to 3 * sizeX)
109 Standard_Size myTopToDown; //!< image scanlines direction in memory from Top to the Down
110
111};
112
113#endif // _Image_PixMapData_H__