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 aBitmapColor;
121 
122  pScanline = pScanline + nX * 3;
123  aBitmapColor.SetBlue( *pScanline++ );
124  aBitmapColor.SetGreen( *pScanline++ );
125  aBitmapColor.SetRed( *pScanline );
126 
127  return aBitmapColor;
128 }
129 
130 void BitmapReadAccess::SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
131 {
132  pScanline = pScanline + nX * 3;
133  *pScanline++ = rBitmapColor.GetBlue();
134  *pScanline++ = rBitmapColor.GetGreen();
135  *pScanline = rBitmapColor.GetRed();
136 }
137 
139 {
140  BitmapColor aBitmapColor;
141 
142  pScanline = pScanline + nX * 3;
143  aBitmapColor.SetRed( *pScanline++ );
144  aBitmapColor.SetGreen( *pScanline++ );
145  aBitmapColor.SetBlue( *pScanline );
146 
147  return aBitmapColor;
148 }
149 
150 void BitmapReadAccess::SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
151 {
152  pScanline = pScanline + nX * 3;
153  *pScanline++ = rBitmapColor.GetRed();
154  *pScanline++ = rBitmapColor.GetGreen();
155  *pScanline = rBitmapColor.GetBlue();
156 }
157 
159 {
160  pScanline = pScanline + nX * 4;
161 
162  sal_uInt8 a = *pScanline++;
163  sal_uInt8 b = *pScanline++;
164  sal_uInt8 g = *pScanline++;
165  sal_uInt8 r = *pScanline;
166 
167  return BitmapColor(
171  0xFF - a);
172 }
173 
175 {
176  BitmapColor aBitmapColor;
177 
178  pScanline = pScanline + ( nX << 2 ) + 1;
179  aBitmapColor.SetBlue( *pScanline++ );
180  aBitmapColor.SetGreen( *pScanline++ );
181  aBitmapColor.SetRed( *pScanline );
182 
183  return aBitmapColor;
184 }
185 
186 void BitmapReadAccess::SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
187 {
188  pScanline = pScanline + nX * 4;
189 
190  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
191  *pScanline++ = alpha;
192  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
193  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
194  *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
195 }
196 
197 void BitmapReadAccess::SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
198 {
199  pScanline = pScanline + ( nX << 2 );
200  *pScanline++ = 0xFF;
201  *pScanline++ = rBitmapColor.GetBlue();
202  *pScanline++ = rBitmapColor.GetGreen();
203  *pScanline = rBitmapColor.GetRed();
204 }
205 
207 {
208  pScanline = pScanline + nX * 4;
209 
210  sal_uInt8 a = *pScanline++;
211  sal_uInt8 r = *pScanline++;
212  sal_uInt8 g = *pScanline++;
213  sal_uInt8 b = *pScanline;
214 
215  return BitmapColor(
219  0xFF - a);
220 }
221 
223 {
224  BitmapColor aBitmapColor;
225 
226  pScanline = pScanline + ( nX << 2 ) + 1;
227  aBitmapColor.SetRed( *pScanline++ );
228  aBitmapColor.SetGreen( *pScanline++ );
229  aBitmapColor.SetBlue( *pScanline );
230 
231  return aBitmapColor;
232 }
233 
234 void BitmapReadAccess::SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
235 {
236  pScanline = pScanline + nX * 4;
237 
238  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
239  *pScanline++ = alpha;
240  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
241  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
242  *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
243 }
244 
245 void BitmapReadAccess::SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
246 {
247  pScanline = pScanline + ( nX << 2 );
248  *pScanline++ = 0xFF;
249  *pScanline++ = rBitmapColor.GetRed();
250  *pScanline++ = rBitmapColor.GetGreen();
251  *pScanline = rBitmapColor.GetBlue();
252 }
253 
255 {
256  pScanline = pScanline + nX * 4;
257 
258  sal_uInt8 b = *pScanline++;
259  sal_uInt8 g = *pScanline++;
260  sal_uInt8 r = *pScanline++;
261  sal_uInt8 a = *pScanline;
262 
263  return BitmapColor(
267  0xFF - a);
268 }
269 
271 {
272  BitmapColor aBitmapColor;
273 
274  pScanline = pScanline + ( nX << 2 );
275  aBitmapColor.SetBlue( *pScanline++ );
276  aBitmapColor.SetGreen( *pScanline++ );
277  aBitmapColor.SetRed( *pScanline );
278 
279  return aBitmapColor;
280 }
281 
282 void BitmapReadAccess::SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
283 {
284  pScanline = pScanline + nX * 4;
285 
286  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
287  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
288  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
289  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
290  *pScanline = alpha;
291 }
292 
293 void BitmapReadAccess::SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
294 {
295  pScanline = pScanline + ( nX << 2 );
296  *pScanline++ = rBitmapColor.GetBlue();
297  *pScanline++ = rBitmapColor.GetGreen();
298  *pScanline++ = rBitmapColor.GetRed();
299  *pScanline = 0xFF;
300 }
301 
303 {
304  pScanline = pScanline + nX * 4;
305 
306  sal_uInt8 r = *pScanline++;
307  sal_uInt8 g = *pScanline++;
308  sal_uInt8 b = *pScanline++;
309  sal_uInt8 a = *pScanline;
310 
311  return BitmapColor(
315  0xFF - a);
316 }
317 
319 {
320  BitmapColor aBitmapColor;
321 
322  pScanline = pScanline + ( nX << 2 );
323  aBitmapColor.SetRed( *pScanline++ );
324  aBitmapColor.SetGreen( *pScanline++ );
325  aBitmapColor.SetBlue( *pScanline );
326 
327  return aBitmapColor;
328 }
329 
330 void BitmapReadAccess::SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
331 {
332  pScanline = pScanline + nX * 4;
333 
334  sal_uInt8 alpha = 0xFF - rBitmapColor.GetAlpha();
335  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
336  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
337  *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
338  *pScanline = alpha;
339 }
340 
341 void BitmapReadAccess::SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
342 {
343  pScanline = pScanline + ( nX << 2 );
344  *pScanline++ = rBitmapColor.GetRed();
345  *pScanline++ = rBitmapColor.GetGreen();
346  *pScanline++ = rBitmapColor.GetBlue();
347  *pScanline = 0xFF;
348 }
349 
351 {
352  BitmapColor aColor;
353  rMask.GetColorFor32Bit( aColor, pScanline + ( nX << 2 ) );
354  return aColor;
355 }
356 
357 void BitmapReadAccess::SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
358 {
359  rMask.SetColorFor32Bit( rBitmapColor, pScanline + ( nX << 2 ) );
360 }
361 
362 /* 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 SetBlue(sal_uInt8 nBlue)
static void SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:330
sal_uInt8 GetAlpha() const
Definition: BitmapColor.hxx:71
static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:206
static void SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:293
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:270
static void SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:245
static void SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:130
static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:302
static void SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:357
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:350
sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
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:254
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:174
sal_uInt8 GetBlue() const
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
static void SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:197
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:118
void SetRed(sal_uInt8 nRed)
static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:222
static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask &rMask)
Definition: bmpacc2.cxx:158
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:26
sal_uInt8 GetGreen() const
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:318
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:282
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:341
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:138
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:234
static void SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:186
static void SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
Definition: bmpacc2.cxx:150