LibreOffice Module vcl (master)  1
bmpacc2.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <vcl/bitmapaccess.hxx>
21 #include <vcl/BitmapTools.hxx>
22 
24 {
25  return BitmapColor( pScanline[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 );
26 }
27 
28 void BitmapReadAccess::SetPixelForN1BitMsbPal(const Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, const ColorMask&)
29 {
30  sal_uInt8& rByte = pScanline[ nX >> 3 ];
31 
32  if ( rBitmapColor.GetIndex() & 1 )
33  rByte |= 1 << ( 7 - ( nX & 7 ) );
34  else
35  rByte &= ~( 1 << ( 7 - ( nX & 7 ) ) );
36 }
37 
39 {
40  return BitmapColor( pScanline[ nX >> 3 ] & ( 1 << ( nX & 7 ) ) ? 1 : 0 );
41 }
42 
43 void BitmapReadAccess::SetPixelForN1BitLsbPal(const Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, const ColorMask&)
44 {
45  sal_uInt8& rByte = pScanline[ nX >> 3 ];
46 
47  if ( rBitmapColor.GetIndex() & 1 )
48  rByte |= 1 << ( nX & 7 );
49  else
50  rByte &= ~( 1 << ( nX & 7 ) );
51 }
52 
54 {
55  return BitmapColor( ( pScanline[ nX >> 1 ] >> ( nX & 1 ? 0 : 4 ) ) & 0x0f );
56 }
57 
58 void BitmapReadAccess::SetPixelForN4BitMsnPal(const Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, const ColorMask&)
59 {
60  sal_uInt8& rByte = pScanline[ nX >> 1 ];
61 
62  if ( nX & 1 )
63  {
64  rByte &= 0xf0;
65  rByte |= ( rBitmapColor.GetIndex() & 0x0f );
66  }
67  else
68  {
69  rByte &= 0x0f;
70  rByte |= ( rBitmapColor.GetIndex() << 4 );
71  }
72 }
73 
75 {
76  return BitmapColor( ( pScanline[ nX >> 1 ] >> ( nX & 1 ? 4 : 0 ) ) & 0x0f );
77 }
78 
79 void BitmapReadAccess::SetPixelForN4BitLsnPal(const Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, const ColorMask&)
80 {
81  sal_uInt8& rByte = pScanline[ nX >> 1 ];
82 
83  if ( nX & 1 )
84  {
85  rByte &= 0x0f;
86  rByte |= ( rBitmapColor.GetIndex() << 4 );
87  }
88  else
89  {
90  rByte &= 0xf0;
91  rByte |= ( rBitmapColor.GetIndex() & 0x0f );
92  }
93 }
94 
96 {
97  return BitmapColor( pScanline[ nX ] );
98 }
99 
100 void BitmapReadAccess::SetPixelForN8BitPal(Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, const ColorMask&)
101 {
102  pScanline[ nX ] = rBitmapColor.GetIndex();
103 }
104 
106 {
107  BitmapColor aBitmapColor;
108 
109  pScanline = pScanline + nX * 3;
110  aBitmapColor.SetBlue( *pScanline++ );
111  aBitmapColor.SetGreen( *pScanline++ );
112  aBitmapColor.SetRed( *pScanline );
113 
114  return aBitmapColor;
115 }
116 
118 {
119  pScanline = pScanline + nX * 3;
120  *pScanline++ = rBitmapColor.GetBlue();
121  *pScanline++ = rBitmapColor.GetGreen();
122  *pScanline = rBitmapColor.GetRed();
123 }
124 
126 {
127  BitmapColor aBitmapColor;
128 
129  pScanline = pScanline + nX * 3;
130  aBitmapColor.SetRed( *pScanline++ );
131  aBitmapColor.SetGreen( *pScanline++ );
132  aBitmapColor.SetBlue( *pScanline );
133 
134  return aBitmapColor;
135 }
136 
138 {
139  pScanline = pScanline + nX * 3;
140  *pScanline++ = rBitmapColor.GetRed();
141  *pScanline++ = rBitmapColor.GetGreen();
142  *pScanline = rBitmapColor.GetBlue();
143 }
144 
146 {
147  pScanline = pScanline + nX * 4;
148 
149  sal_uInt8 a = *pScanline++;
150  sal_uInt8 b = *pScanline++;
151  sal_uInt8 g = *pScanline++;
152  sal_uInt8 r = *pScanline;
153 
154  return BitmapColor(
158  0xFF - a);
159 }
160 
162 {
163  BitmapColor aBitmapColor;
164 
165  pScanline = pScanline + ( nX << 2 ) + 1;
166  aBitmapColor.SetBlue( *pScanline++ );
167  aBitmapColor.SetGreen( *pScanline++ );
168  aBitmapColor.SetRed( *pScanline );
169 
170  return aBitmapColor;
171 }
172 
174 {
175  pScanline = pScanline + nX * 4;
176 
177  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
178  *pScanline++ = alpha;
179  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
180  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
181  *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
182 }
183 
185 {
186  pScanline = pScanline + ( nX << 2 );
187  *pScanline++ = 0xFF;
188  *pScanline++ = rBitmapColor.GetBlue();
189  *pScanline++ = rBitmapColor.GetGreen();
190  *pScanline = rBitmapColor.GetRed();
191 }
192 
194 {
195  pScanline = pScanline + nX * 4;
196 
197  sal_uInt8 a = *pScanline++;
198  sal_uInt8 r = *pScanline++;
199  sal_uInt8 g = *pScanline++;
200  sal_uInt8 b = *pScanline;
201 
202  return BitmapColor(
206  0xFF - a);
207 }
208 
210 {
211  BitmapColor aBitmapColor;
212 
213  pScanline = pScanline + ( nX << 2 ) + 1;
214  aBitmapColor.SetRed( *pScanline++ );
215  aBitmapColor.SetGreen( *pScanline++ );
216  aBitmapColor.SetBlue( *pScanline );
217 
218  return aBitmapColor;
219 }
220 
222 {
223  pScanline = pScanline + nX * 4;
224 
225  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
226  *pScanline++ = alpha;
227  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
228  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
229  *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
230 }
231 
233 {
234  pScanline = pScanline + ( nX << 2 );
235  *pScanline++ = 0xFF;
236  *pScanline++ = rBitmapColor.GetRed();
237  *pScanline++ = rBitmapColor.GetGreen();
238  *pScanline = rBitmapColor.GetBlue();
239 }
240 
242 {
243  pScanline = pScanline + nX * 4;
244 
245  sal_uInt8 b = *pScanline++;
246  sal_uInt8 g = *pScanline++;
247  sal_uInt8 r = *pScanline++;
248  sal_uInt8 a = *pScanline;
249 
250  return BitmapColor(
254  0xFF - a);
255 }
256 
258 {
259  BitmapColor aBitmapColor;
260 
261  pScanline = pScanline + ( nX << 2 );
262  aBitmapColor.SetBlue( *pScanline++ );
263  aBitmapColor.SetGreen( *pScanline++ );
264  aBitmapColor.SetRed( *pScanline );
265 
266  return aBitmapColor;
267 }
268 
270 {
271  pScanline = pScanline + nX * 4;
272 
273  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
274  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
275  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
276  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
277  *pScanline = alpha;
278 }
279 
281 {
282  pScanline = pScanline + ( nX << 2 );
283  *pScanline++ = rBitmapColor.GetBlue();
284  *pScanline++ = rBitmapColor.GetGreen();
285  *pScanline++ = rBitmapColor.GetRed();
286  *pScanline = 0xFF;
287 }
288 
290 {
291  pScanline = pScanline + nX * 4;
292 
293  sal_uInt8 r = *pScanline++;
294  sal_uInt8 g = *pScanline++;
295  sal_uInt8 b = *pScanline++;
296  sal_uInt8 a = *pScanline;
297 
298  return BitmapColor(
302  0xFF - a);
303 }
304 
306 {
307  BitmapColor aBitmapColor;
308 
309  pScanline = pScanline + ( nX << 2 );
310  aBitmapColor.SetRed( *pScanline++ );
311  aBitmapColor.SetGreen( *pScanline++ );
312  aBitmapColor.SetBlue( *pScanline );
313 
314  return aBitmapColor;
315 }
316 
318 {
319  pScanline = pScanline + nX * 4;
320 
321  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
322  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
323  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
324  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
325  *pScanline = alpha;
326 }
327 
329 {
330  pScanline = pScanline + ( nX << 2 );
331  *pScanline++ = rBitmapColor.GetRed();
332  *pScanline++ = rBitmapColor.GetGreen();
333  *pScanline++ = rBitmapColor.GetBlue();
334  *pScanline = 0xFF;
335 }
336 
338 {
339  BitmapColor aColor;
340  rMask.GetColorFor32Bit( aColor, pScanline + ( nX << 2 ) );
341  return aColor;
342 }
343 
344 void BitmapReadAccess::SetPixelForN32BitTcMask(Scanline pScanline, tools::Long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
345 {
346  rMask.SetColorFor32Bit( rBitmapColor, pScanline + ( nX << 2 ) );
347 }
348 
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:23
static void SetPixelForN32BitTcBgra(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:269
static BitmapColor GetPixelForN4BitLsnPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:74
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:61
sal_uInt8 GetRed() const
static BitmapColor GetPixelForN32BitTcRgbx(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:305
static BitmapColor GetPixelForN32BitTcXbgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:161
void SetBlue(sal_uInt8 nBlue)
static void SetPixelForN32BitTcArgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:221
sal_uInt8 GetAlpha() const
Definition: BitmapColor.hxx:71
static void SetPixelForN32BitTcXbgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:184
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
long Long
void SetColorFor32Bit(const BitmapColor &rColor, sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:182
static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:209
static void SetPixelForN1BitMsbPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:28
static void SetPixelForN32BitTcBgrx(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:280
static void SetPixelForN32BitTcMask(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:344
sal_uInt8 GetBlue() const
static void SetPixelForN4BitMsnPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:58
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
static BitmapColor GetPixelForN4BitMsnPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:53
uno_Any a
static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:105
static void SetPixelForN1BitLsbPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:43
static BitmapColor GetPixelForN32BitTcBgrx(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:257
static BitmapColor GetPixelForN32BitTcMask(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:337
static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:289
void SetRed(sal_uInt8 nRed)
static void SetPixelForN32BitTcRgbx(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:328
static BitmapColor GetPixelForN1BitLsbPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:38
static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:145
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:26
static BitmapColor GetPixelForN8BitPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:95
sal_uInt8 GetGreen() const
static BitmapColor GetPixelForN32BitTcBgra(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:241
unsigned char sal_uInt8
static void SetPixelForN32BitTcXrgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:232
void SetGreen(sal_uInt8 nGreen)
static BitmapColor GetPixelForN24BitTcRgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:125
void GetColorFor32Bit(BitmapColor &rColor, const sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:165
static void SetPixelForN8BitPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:100
static void SetPixelForN4BitLsnPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:79
static void SetPixelForN24BitTcRgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:137
static void SetPixelForN24BitTcBgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:117
static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:193
static void SetPixelForN32BitTcAbgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:173
static void SetPixelForN32BitTcRgba(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:317