1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_BITMAPDEVICE_HXX
#define INCLUDED_BASEBMP_BITMAPDEVICE_HXX
#include <sal/types.h>
#include <basebmp/scanlineformats.hxx>
#include <basebmp/basebmpdllapi.h>
#include <boost/shared_array.hpp>
#include <memory>
#include <vector>
namespace basegfx
{
class B2IPoint;
class B2DPoint;
class B2IVector;
class B2IBox;
}
namespace basebmp
{
// Temporary. Use like the tools color object
class Color;
typedef std::shared_ptr< class BitmapDevice > BitmapDeviceSharedPtr;
typedef boost::shared_array< sal_uInt8 > RawMemorySharedArray;
typedef std::shared_ptr< const std::vector<Color> > PaletteMemorySharedVector;
struct ImplBitmapDevice;
/** Definition of BitmapDevice interface
Use the createBitmapDevice() function to create instances.
Implementation note: the clip mask and bitmap parameter instances
of BitmapDevice that are passed to individual BitmapDevice
instances work best with 1 bit grey masks for the clip and a
format matching that of the target BitmapDevice for the other
parameters.
*/
class BASEBMP_DLLPUBLIC BitmapDevice : public std::enable_shared_from_this<BitmapDevice>
{
public:
/** Query size of device in pixel columns (X) and rows (Y, "scanlines")
*/
basegfx::B2IVector getSize() const;
/** Query type of scanline memory format
*/
Format getScanlineFormat() const;
/** Query byte offset to get from scanline n to scanline n+1
@return the scanline stride in bytes.
*/
sal_Int32 getScanlineStride() const;
/** Get pointer to frame buffer
@return a shared ptr to the bitmap buffer memory. As this is a
shared ptr, you can freely store and use the pointer, even
after this object has been deleted.
*/
RawMemorySharedArray getBuffer() const;
/** Get pointer to palette
The returned pointer is const on purpose, since the
BitmapDevice might internally cache lookup information. Don't
modify the returned data, unless you want to enter the realm
of completely undefined behaviour.
@return shared pointer to vector of Color entries.
*/
PaletteMemorySharedVector getPalette() const;
/** Get color value at given pixel
*/
Color getPixel( const basegfx::B2IPoint& rPt );
/** Draw another bitmap into this device
@param rSrcBitmap
Bitmap to render into this one.
*/
void convertBitmap( const BitmapDeviceSharedPtr& rSrcBitmap );
protected:
BASEBMP_DLLPRIVATE BitmapDevice( const basegfx::B2IBox& rBounds,
Format nScanlineFormat,
sal_Int32 nScanlineStride,
sal_uInt8* pFirstScanline,
const RawMemorySharedArray& rMem,
const PaletteMemorySharedVector& rPalette );
BASEBMP_DLLPRIVATE virtual ~BitmapDevice();
BitmapDevice(const BitmapDevice&) = delete;
BitmapDevice& operator=( const BitmapDevice& ) = delete;
private:
BASEBMP_DLLPRIVATE virtual Color getPixel_i( const basegfx::B2IPoint& rPt ) = 0;
BASEBMP_DLLPRIVATE virtual void convertBitmap_i( const BitmapDeviceSharedPtr& rSrcBitmap ) = 0;
std::unique_ptr< ImplBitmapDevice > mpImpl;
};
/** Function to calculate a suitable BitmapDevice Scanline Stride for a given scanline format and width
* you can provide this value or any larger value.
*/
sal_Int32 BASEBMP_DLLPUBLIC getBitmapDeviceStrideForWidth(Format nScanlineFormat, sal_Int32 nWidth);
/** Function to create a BitmapDevice for given scanline format
*/
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC createBitmapDevice( const basegfx::B2IVector& rSize,
Format nScanlineFormat );
/** Function to create a BitmapDevice for given scanline format
with the given palette
Note: the provided palette must have sufficient size, to satisfy
lookups for the whole range of pixel values from the specified
format.
*/
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC createBitmapDevice( const basegfx::B2IVector& rSize,
Format nScanlineFormat,
const PaletteMemorySharedVector& rPalette );
/** Function to create a BitmapDevice for given scanline format
from the given piece of raw memory and palette
Note: the provided memory must have sufficient size, to store the
image of the specified area and format.
*/
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC createBitmapDevice( const basegfx::B2IVector& rSize,
Format nScanlineFormat,
const RawMemorySharedArray& rMem,
const PaletteMemorySharedVector& rPalette );
/** Function to clone a BitmapDevice from a given prototype.
*/
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC cloneBitmapDevice(const BitmapDeviceSharedPtr& rProto);
}
#endif /* INCLUDED_BASEBMP_BITMAPDEVICE_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|