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, 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, 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, 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, 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, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
101 {
102  pScanline[ nX ] = rBitmapColor.GetIndex();
103 }
104 
106 {
107  BitmapColor aColor;
108  rMask.GetColorFor8Bit( aColor, pScanline + nX );
109  return aColor;
110 }
111 
112 void BitmapReadAccess::SetPixelForN8BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
113 {
114  rMask.SetColorFor8Bit( rBitmapColor, pScanline + nX );
115 }
116 
117 
119 {
120  BitmapColor aColor;
121  rMask.GetColorFor16BitMSB( aColor, pScanline + ( nX << 1 ) );
122  return aColor;
123 }
124 
125 void BitmapReadAccess::SetPixelForN16BitTcMsbMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
126 {
127  rMask.SetColorFor16BitMSB( rBitmapColor, pScanline + ( nX << 1 ) );
128 }
129 
131 {
132  BitmapColor aColor;
133  rMask.GetColorFor16BitLSB( aColor, pScanline + ( nX << 1 ) );
134  return aColor;
135 }
136 
137 void BitmapReadAccess::SetPixelForN16BitTcLsbMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
138 {
139  rMask.SetColorFor16BitLSB( rBitmapColor, pScanline + ( nX << 1 ) );
140 }
141 
143 {
144  BitmapColor aBitmapColor;
145 
146  pScanline = pScanline + nX * 3;
147  aBitmapColor.SetBlue( *pScanline++ );
148  aBitmapColor.SetGreen( *pScanline++ );
149  aBitmapColor.SetRed( *pScanline );
150 
151  return aBitmapColor;
152 }
153 
154 void BitmapReadAccess::SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
155 {
156  pScanline = pScanline + nX * 3;
157  *pScanline++ = rBitmapColor.GetBlue();
158  *pScanline++ = rBitmapColor.GetGreen();
159  *pScanline = rBitmapColor.GetRed();
160 }
161 
163 {
164  BitmapColor aBitmapColor;
165 
166  pScanline = pScanline + nX * 3;
167  aBitmapColor.SetRed( *pScanline++ );
168  aBitmapColor.SetGreen( *pScanline++ );
169  aBitmapColor.SetBlue( *pScanline );
170 
171  return aBitmapColor;
172 }
173 
174 void BitmapReadAccess::SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
175 {
176  pScanline = pScanline + nX * 3;
177  *pScanline++ = rBitmapColor.GetRed();
178  *pScanline++ = rBitmapColor.GetGreen();
179  *pScanline = rBitmapColor.GetBlue();
180 }
181 
183 {
184  pScanline = pScanline + nX * 4;
185 
186  sal_uInt8 a = *pScanline++;
187  sal_uInt8 b = *pScanline++;
188  sal_uInt8 g = *pScanline++;
189  sal_uInt8 r = *pScanline;
190 
191  return BitmapColor(
195  0xFF - a);
196 }
197 
199 {
200  BitmapColor aBitmapColor;
201 
202  pScanline = pScanline + ( nX << 2 ) + 1;
203  aBitmapColor.SetBlue( *pScanline++ );
204  aBitmapColor.SetGreen( *pScanline++ );
205  aBitmapColor.SetRed( *pScanline );
206 
207  return aBitmapColor;
208 }
209 
210 void BitmapReadAccess::SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
211 {
212  pScanline = pScanline + nX * 4;
213 
214  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
215  *pScanline++ = alpha;
216  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
217  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
218  *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
219 }
220 
221 void BitmapReadAccess::SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
222 {
223  pScanline = pScanline + ( nX << 2 );
224  *pScanline++ = 0xFF;
225  *pScanline++ = rBitmapColor.GetBlue();
226  *pScanline++ = rBitmapColor.GetGreen();
227  *pScanline = rBitmapColor.GetRed();
228 }
229 
231 {
232  pScanline = pScanline + nX * 4;
233 
234  sal_uInt8 a = *pScanline++;
235  sal_uInt8 r = *pScanline++;
236  sal_uInt8 g = *pScanline++;
237  sal_uInt8 b = *pScanline;
238 
239  return BitmapColor(
243  0xFF - a);
244 }
245 
247 {
248  BitmapColor aBitmapColor;
249 
250  pScanline = pScanline + ( nX << 2 ) + 1;
251  aBitmapColor.SetRed( *pScanline++ );
252  aBitmapColor.SetGreen( *pScanline++ );
253  aBitmapColor.SetBlue( *pScanline );
254 
255  return aBitmapColor;
256 }
257 
258 void BitmapReadAccess::SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
259 {
260  pScanline = pScanline + nX * 4;
261 
262  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
263  *pScanline++ = alpha;
264  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
265  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
266  *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
267 }
268 
269 void BitmapReadAccess::SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
270 {
271  pScanline = pScanline + ( nX << 2 );
272  *pScanline++ = 0xFF;
273  *pScanline++ = rBitmapColor.GetRed();
274  *pScanline++ = rBitmapColor.GetGreen();
275  *pScanline = rBitmapColor.GetBlue();
276 }
277 
279 {
280  pScanline = pScanline + nX * 4;
281 
282  sal_uInt8 b = *pScanline++;
283  sal_uInt8 g = *pScanline++;
284  sal_uInt8 r = *pScanline++;
285  sal_uInt8 a = *pScanline;
286 
287  return BitmapColor(
291  0xFF - a);
292 }
293 
295 {
296  BitmapColor aBitmapColor;
297 
298  pScanline = pScanline + ( nX << 2 );
299  aBitmapColor.SetBlue( *pScanline++ );
300  aBitmapColor.SetGreen( *pScanline++ );
301  aBitmapColor.SetRed( *pScanline );
302 
303  return aBitmapColor;
304 }
305 
306 void BitmapReadAccess::SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
307 {
308  pScanline = pScanline + nX * 4;
309 
310  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
311  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
312  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
313  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
314  *pScanline = alpha;
315 }
316 
317 void BitmapReadAccess::SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
318 {
319  pScanline = pScanline + ( nX << 2 );
320  *pScanline++ = rBitmapColor.GetBlue();
321  *pScanline++ = rBitmapColor.GetGreen();
322  *pScanline++ = rBitmapColor.GetRed();
323  *pScanline = 0xFF;
324 }
325 
327 {
328  pScanline = pScanline + nX * 4;
329 
330  sal_uInt8 r = *pScanline++;
331  sal_uInt8 g = *pScanline++;
332  sal_uInt8 b = *pScanline++;
333  sal_uInt8 a = *pScanline;
334 
335  return BitmapColor(
339  0xFF - a);
340 }
341 
343 {
344  BitmapColor aBitmapColor;
345 
346  pScanline = pScanline + ( nX << 2 );
347  aBitmapColor.SetRed( *pScanline++ );
348  aBitmapColor.SetGreen( *pScanline++ );
349  aBitmapColor.SetBlue( *pScanline );
350 
351  return aBitmapColor;
352 }
353 
354 void BitmapReadAccess::SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
355 {
356  pScanline = pScanline + nX * 4;
357 
358  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
359  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
360  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
361  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
362  *pScanline = alpha;
363 }
364 
365 void BitmapReadAccess::SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
366 {
367  pScanline = pScanline + ( nX << 2 );
368  *pScanline++ = rBitmapColor.GetRed();
369  *pScanline++ = rBitmapColor.GetGreen();
370  *pScanline++ = rBitmapColor.GetBlue();
371  *pScanline = 0xFF;
372 }
373 
375 {
376  BitmapColor aColor;
377  rMask.GetColorFor32Bit( aColor, pScanline + ( nX << 2 ) );
378  return aColor;
379 }
380 
381 void BitmapReadAccess::SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
382 {
383  rMask.SetColorFor32Bit( rBitmapColor, pScanline + ( nX << 2 ) );
384 }
385 
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static BitmapColor GetPixelForN4BitLsnPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:74
static BitmapColor GetPixelForN8BitTcMask(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:105
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:61
sal_uInt8 GetRed() const
void GetColorFor16BitMSB(BitmapColor &rColor, const sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:149
void SetBlue(sal_uInt8 nBlue)
static void SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:354
sal_uInt8 GetAlpha() const
Definition: BitmapColor.hxx:71
static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:230
static void SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:317
void GetColorFor8Bit(BitmapColor &rColor, const sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:138
void SetColorFor32Bit(const BitmapColor &rColor, sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:196
static BitmapColor GetPixelForN32BitTcBgrx(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:294
static void SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:269
static void SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:154
static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:326
static void SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:381
static void SetPixelForN4BitMsnPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:58
static BitmapColor GetPixelForN4BitMsnPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:53
static BitmapColor GetPixelForN32BitTcMask(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:374
sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
void GetColorFor16BitLSB(BitmapColor &rColor, const sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:164
static BitmapColor GetPixelForN16BitTcMsbMask(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:118
static BitmapColor GetPixelForN8BitPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:95
static BitmapColor GetPixelForN32BitTcBgra(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:278
static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:23
static BitmapColor GetPixelForN32BitTcXbgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:198
sal_uInt8 GetBlue() const
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
static void SetPixelForN16BitTcLsbMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:137
static void SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:221
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:142
void SetRed(sal_uInt8 nRed)
static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:246
static BitmapColor GetPixelForN16BitTcLsbMask(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:130
static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:182
void SetColorFor16BitMSB(const BitmapColor &rColor, sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:156
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:26
sal_uInt8 GetGreen() const
void SetColorFor16BitLSB(const BitmapColor &rColor, sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:171
void SetColorFor8Bit(const BitmapColor &rColor, sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:144
static BitmapColor GetPixelForN32BitTcRgbx(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:342
static void SetPixelForN16BitTcMsbMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:125
unsigned char sal_uInt8
static void SetPixelForN8BitPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:100
void SetGreen(sal_uInt8 nGreen)
static void SetPixelForN1BitLsbPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:43
static void SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:306
void GetColorFor32Bit(BitmapColor &rColor, const sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:179
static void SetPixelForN4BitLsnPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:79
static void SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:365
static BitmapColor GetPixelForN1BitLsbPal(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:38
static BitmapColor GetPixelForN24BitTcRgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:162
static void SetPixelForN8BitTcMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:112
static void SetPixelForN1BitMsbPal(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:28
static void SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:258
static void SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:210
static void SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:174