Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / gdi / bmpacc2.cxx
blob9210d52227519b9765cbedc332fc1b84004da761
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/bitmapaccess.hxx>
21 #include <vcl/BitmapTools.hxx>
23 BitmapColor BitmapReadAccess::GetPixelForN1BitMsbPal(ConstScanline pScanline, long nX, const ColorMask&)
25 return BitmapColor( pScanline[ nX >> 3 ] & ( 1 << ( 7 - ( nX & 7 ) ) ) ? 1 : 0 );
28 void BitmapReadAccess::SetPixelForN1BitMsbPal(const Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
30 sal_uInt8& rByte = pScanline[ nX >> 3 ];
32 if ( rBitmapColor.GetIndex() & 1 )
33 rByte |= 1 << ( 7 - ( nX & 7 ) );
34 else
35 rByte &= ~( 1 << ( 7 - ( nX & 7 ) ) );
38 BitmapColor BitmapReadAccess::GetPixelForN1BitLsbPal(ConstScanline pScanline, long nX, const ColorMask&)
40 return BitmapColor( pScanline[ nX >> 3 ] & ( 1 << ( nX & 7 ) ) ? 1 : 0 );
43 void BitmapReadAccess::SetPixelForN1BitLsbPal(const Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
45 sal_uInt8& rByte = pScanline[ nX >> 3 ];
47 if ( rBitmapColor.GetIndex() & 1 )
48 rByte |= 1 << ( nX & 7 );
49 else
50 rByte &= ~( 1 << ( nX & 7 ) );
53 BitmapColor BitmapReadAccess::GetPixelForN4BitMsnPal(ConstScanline pScanline, long nX, const ColorMask&)
55 return BitmapColor( ( pScanline[ nX >> 1 ] >> ( nX & 1 ? 0 : 4 ) ) & 0x0f );
58 void BitmapReadAccess::SetPixelForN4BitMsnPal(const Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
60 sal_uInt8& rByte = pScanline[ nX >> 1 ];
62 if ( nX & 1 )
64 rByte &= 0xf0;
65 rByte |= ( rBitmapColor.GetIndex() & 0x0f );
67 else
69 rByte &= 0x0f;
70 rByte |= ( rBitmapColor.GetIndex() << 4 );
74 BitmapColor BitmapReadAccess::GetPixelForN4BitLsnPal(ConstScanline pScanline, long nX, const ColorMask&)
76 return BitmapColor( ( pScanline[ nX >> 1 ] >> ( nX & 1 ? 4 : 0 ) ) & 0x0f );
79 void BitmapReadAccess::SetPixelForN4BitLsnPal(const Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
81 sal_uInt8& rByte = pScanline[ nX >> 1 ];
83 if ( nX & 1 )
85 rByte &= 0x0f;
86 rByte |= ( rBitmapColor.GetIndex() << 4 );
88 else
90 rByte &= 0xf0;
91 rByte |= ( rBitmapColor.GetIndex() & 0x0f );
95 BitmapColor BitmapReadAccess::GetPixelForN8BitPal(ConstScanline pScanline, long nX, const ColorMask&)
97 return BitmapColor( pScanline[ nX ] );
100 void BitmapReadAccess::SetPixelForN8BitPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
102 pScanline[ nX ] = rBitmapColor.GetIndex();
105 BitmapColor BitmapReadAccess::GetPixelForN8BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask)
107 BitmapColor aColor;
108 rMask.GetColorFor8Bit( aColor, pScanline + nX );
109 return aColor;
112 void BitmapReadAccess::SetPixelForN8BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
114 rMask.SetColorFor8Bit( rBitmapColor, pScanline + nX );
118 BitmapColor BitmapReadAccess::GetPixelForN24BitTcBgr(ConstScanline pScanline, long nX, const ColorMask&)
120 BitmapColor aBitmapColor;
122 pScanline = pScanline + nX * 3;
123 aBitmapColor.SetBlue( *pScanline++ );
124 aBitmapColor.SetGreen( *pScanline++ );
125 aBitmapColor.SetRed( *pScanline );
127 return aBitmapColor;
130 void BitmapReadAccess::SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
132 pScanline = pScanline + nX * 3;
133 *pScanline++ = rBitmapColor.GetBlue();
134 *pScanline++ = rBitmapColor.GetGreen();
135 *pScanline = rBitmapColor.GetRed();
138 BitmapColor BitmapReadAccess::GetPixelForN24BitTcRgb(ConstScanline pScanline, long nX, const ColorMask&)
140 BitmapColor aBitmapColor;
142 pScanline = pScanline + nX * 3;
143 aBitmapColor.SetRed( *pScanline++ );
144 aBitmapColor.SetGreen( *pScanline++ );
145 aBitmapColor.SetBlue( *pScanline );
147 return aBitmapColor;
150 void BitmapReadAccess::SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
152 pScanline = pScanline + nX * 3;
153 *pScanline++ = rBitmapColor.GetRed();
154 *pScanline++ = rBitmapColor.GetGreen();
155 *pScanline = rBitmapColor.GetBlue();
158 BitmapColor BitmapReadAccess::GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask&)
160 pScanline = pScanline + nX * 4;
162 sal_uInt8 a = *pScanline++;
163 sal_uInt8 b = *pScanline++;
164 sal_uInt8 g = *pScanline++;
165 sal_uInt8 r = *pScanline;
167 return BitmapColor(
168 vcl::bitmap::unpremultiply(r, a),
169 vcl::bitmap::unpremultiply(g, a),
170 vcl::bitmap::unpremultiply(b, a),
171 0xFF - a);
174 BitmapColor BitmapReadAccess::GetPixelForN32BitTcXbgr(ConstScanline pScanline, long nX, const ColorMask&)
176 BitmapColor aBitmapColor;
178 pScanline = pScanline + ( nX << 2 ) + 1;
179 aBitmapColor.SetBlue( *pScanline++ );
180 aBitmapColor.SetGreen( *pScanline++ );
181 aBitmapColor.SetRed( *pScanline );
183 return aBitmapColor;
186 void BitmapReadAccess::SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
188 pScanline = pScanline + nX * 4;
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);
197 void BitmapReadAccess::SetPixelForN32BitTcXbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
199 pScanline = pScanline + ( nX << 2 );
200 *pScanline++ = 0xFF;
201 *pScanline++ = rBitmapColor.GetBlue();
202 *pScanline++ = rBitmapColor.GetGreen();
203 *pScanline = rBitmapColor.GetRed();
206 BitmapColor BitmapReadAccess::GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask&)
208 pScanline = pScanline + nX * 4;
210 sal_uInt8 a = *pScanline++;
211 sal_uInt8 r = *pScanline++;
212 sal_uInt8 g = *pScanline++;
213 sal_uInt8 b = *pScanline;
215 return BitmapColor(
216 vcl::bitmap::unpremultiply(r, a),
217 vcl::bitmap::unpremultiply(g, a),
218 vcl::bitmap::unpremultiply(b, a),
219 0xFF - a);
222 BitmapColor BitmapReadAccess::GetPixelForN32BitTcXrgb(ConstScanline pScanline, long nX, const ColorMask&)
224 BitmapColor aBitmapColor;
226 pScanline = pScanline + ( nX << 2 ) + 1;
227 aBitmapColor.SetRed( *pScanline++ );
228 aBitmapColor.SetGreen( *pScanline++ );
229 aBitmapColor.SetBlue( *pScanline );
231 return aBitmapColor;
234 void BitmapReadAccess::SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
236 pScanline = pScanline + nX * 4;
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);
245 void BitmapReadAccess::SetPixelForN32BitTcXrgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
247 pScanline = pScanline + ( nX << 2 );
248 *pScanline++ = 0xFF;
249 *pScanline++ = rBitmapColor.GetRed();
250 *pScanline++ = rBitmapColor.GetGreen();
251 *pScanline = rBitmapColor.GetBlue();
254 BitmapColor BitmapReadAccess::GetPixelForN32BitTcBgra(ConstScanline pScanline, long nX, const ColorMask&)
256 pScanline = pScanline + nX * 4;
258 sal_uInt8 b = *pScanline++;
259 sal_uInt8 g = *pScanline++;
260 sal_uInt8 r = *pScanline++;
261 sal_uInt8 a = *pScanline;
263 return BitmapColor(
264 vcl::bitmap::unpremultiply(r, a),
265 vcl::bitmap::unpremultiply(g, a),
266 vcl::bitmap::unpremultiply(b, a),
267 0xFF - a);
270 BitmapColor BitmapReadAccess::GetPixelForN32BitTcBgrx(ConstScanline pScanline, long nX, const ColorMask&)
272 BitmapColor aBitmapColor;
274 pScanline = pScanline + ( nX << 2 );
275 aBitmapColor.SetBlue( *pScanline++ );
276 aBitmapColor.SetGreen( *pScanline++ );
277 aBitmapColor.SetRed( *pScanline );
279 return aBitmapColor;
282 void BitmapReadAccess::SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
284 pScanline = pScanline + nX * 4;
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;
293 void BitmapReadAccess::SetPixelForN32BitTcBgrx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
295 pScanline = pScanline + ( nX << 2 );
296 *pScanline++ = rBitmapColor.GetBlue();
297 *pScanline++ = rBitmapColor.GetGreen();
298 *pScanline++ = rBitmapColor.GetRed();
299 *pScanline = 0xFF;
302 BitmapColor BitmapReadAccess::GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask&)
304 pScanline = pScanline + nX * 4;
306 sal_uInt8 r = *pScanline++;
307 sal_uInt8 g = *pScanline++;
308 sal_uInt8 b = *pScanline++;
309 sal_uInt8 a = *pScanline;
311 return BitmapColor(
312 vcl::bitmap::unpremultiply(r, a),
313 vcl::bitmap::unpremultiply(g, a),
314 vcl::bitmap::unpremultiply(b, a),
315 0xFF - a);
318 BitmapColor BitmapReadAccess::GetPixelForN32BitTcRgbx(ConstScanline pScanline, long nX, const ColorMask&)
320 BitmapColor aBitmapColor;
322 pScanline = pScanline + ( nX << 2 );
323 aBitmapColor.SetRed( *pScanline++ );
324 aBitmapColor.SetGreen( *pScanline++ );
325 aBitmapColor.SetBlue( *pScanline );
327 return aBitmapColor;
330 void BitmapReadAccess::SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
332 pScanline = pScanline + nX * 4;
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;
341 void BitmapReadAccess::SetPixelForN32BitTcRgbx(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
343 pScanline = pScanline + ( nX << 2 );
344 *pScanline++ = rBitmapColor.GetRed();
345 *pScanline++ = rBitmapColor.GetGreen();
346 *pScanline++ = rBitmapColor.GetBlue();
347 *pScanline = 0xFF;
350 BitmapColor BitmapReadAccess::GetPixelForN32BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask)
352 BitmapColor aColor;
353 rMask.GetColorFor32Bit( aColor, pScanline + ( nX << 2 ) );
354 return aColor;
357 void BitmapReadAccess::SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
359 rMask.SetColorFor32Bit( rBitmapColor, pScanline + ( nX << 2 ) );
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */