Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / source / gdi / bmpacc2.cxx
blobab67ddda9d3e9c9283426c80a69c07eeefea343c
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/salbtype.hxx>
21 #include <vcl/bitmapaccess.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(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
30 sal_uInt8& rByte = pScanline[ nX >> 3 ];
32 ( rBitmapColor.GetIndex() & 1 ) ? ( rByte |= 1 << ( 7 - ( nX & 7 ) ) ) :
33 ( rByte &= ~( 1 << ( 7 - ( nX & 7 ) ) ) );
36 BitmapColor BitmapReadAccess::GetPixelForN1BitLsbPal(ConstScanline pScanline, long nX, const ColorMask&)
38 return BitmapColor( pScanline[ nX >> 3 ] & ( 1 << ( nX & 7 ) ) ? 1 : 0 );
41 void BitmapReadAccess::SetPixelForN1BitLsbPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
43 sal_uInt8& rByte = pScanline[ nX >> 3 ];
45 ( rBitmapColor.GetIndex() & 1 ) ? ( rByte |= 1 << ( nX & 7 ) ) :
46 ( rByte &= ~( 1 << ( nX & 7 ) ) );
49 BitmapColor BitmapReadAccess::GetPixelForN4BitMsnPal(ConstScanline pScanline, long nX, const ColorMask&)
51 return BitmapColor( ( pScanline[ nX >> 1 ] >> ( nX & 1 ? 0 : 4 ) ) & 0x0f );
54 void BitmapReadAccess::SetPixelForN4BitMsnPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
56 sal_uInt8& rByte = pScanline[ nX >> 1 ];
58 ( nX & 1 ) ? ( rByte &= 0xf0, rByte |= ( rBitmapColor.GetIndex() & 0x0f ) ) :
59 ( rByte &= 0x0f, rByte |= ( rBitmapColor.GetIndex() << 4 ) );
62 BitmapColor BitmapReadAccess::GetPixelForN4BitLsnPal(ConstScanline pScanline, long nX, const ColorMask&)
64 return BitmapColor( ( pScanline[ nX >> 1 ] >> ( nX & 1 ? 4 : 0 ) ) & 0x0f );
67 void BitmapReadAccess::SetPixelForN4BitLsnPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
69 sal_uInt8& rByte = pScanline[ nX >> 1 ];
71 ( nX & 1 ) ? ( rByte &= 0x0f, rByte |= ( rBitmapColor.GetIndex() << 4 ) ) :
72 ( rByte &= 0xf0, rByte |= ( rBitmapColor.GetIndex() & 0x0f ) );
75 BitmapColor BitmapReadAccess::GetPixelForN8BitPal(ConstScanline pScanline, long nX, const ColorMask&)
77 return BitmapColor( pScanline[ nX ] );
80 void BitmapReadAccess::SetPixelForN8BitPal(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
82 if (rBitmapColor.IsIndex())
83 pScanline[ nX ] = rBitmapColor.GetIndex();
84 else
85 // Let's hope that the RGB color values equal, so it doesn't matter what do we pick
86 pScanline[ nX ] = rBitmapColor.GetBlueOrIndex();
89 BitmapColor BitmapReadAccess::GetPixelForN8BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask)
91 BitmapColor aColor;
92 rMask.GetColorFor8Bit( aColor, pScanline + nX );
93 return aColor;
96 void BitmapReadAccess::SetPixelForN8BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
98 rMask.SetColorFor8Bit( rBitmapColor, pScanline + nX );
102 BitmapColor BitmapReadAccess::GetPixelForN16BitTcMsbMask(ConstScanline pScanline, long nX, const ColorMask& rMask)
104 BitmapColor aColor;
105 rMask.GetColorFor16BitMSB( aColor, pScanline + ( nX << 1UL ) );
106 return aColor;
109 void BitmapReadAccess::SetPixelForN16BitTcMsbMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
111 rMask.SetColorFor16BitMSB( rBitmapColor, pScanline + ( nX << 1UL ) );
114 BitmapColor BitmapReadAccess::GetPixelForN16BitTcLsbMask(ConstScanline pScanline, long nX, const ColorMask& rMask)
116 BitmapColor aColor;
117 rMask.GetColorFor16BitLSB( aColor, pScanline + ( nX << 1UL ) );
118 return aColor;
121 void BitmapReadAccess::SetPixelForN16BitTcLsbMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
123 rMask.SetColorFor16BitLSB( rBitmapColor, pScanline + ( nX << 1UL ) );
126 BitmapColor BitmapReadAccess::GetPixelForN24BitTcBgr(ConstScanline pScanline, long nX, const ColorMask&)
128 BitmapColor aBitmapColor;
130 pScanline = pScanline + nX * 3;
131 aBitmapColor.SetBlue( *pScanline++ );
132 aBitmapColor.SetGreen( *pScanline++ );
133 aBitmapColor.SetRed( *pScanline );
135 return aBitmapColor;
138 void BitmapReadAccess::SetPixelForN24BitTcBgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
140 pScanline = pScanline + nX * 3;
141 *pScanline++ = rBitmapColor.GetBlue();
142 *pScanline++ = rBitmapColor.GetGreen();
143 *pScanline = rBitmapColor.GetRed();
146 BitmapColor BitmapReadAccess::GetPixelForN24BitTcRgb(ConstScanline pScanline, long nX, const ColorMask&)
148 BitmapColor aBitmapColor;
150 pScanline = pScanline + nX * 3;
151 aBitmapColor.SetRed( *pScanline++ );
152 aBitmapColor.SetGreen( *pScanline++ );
153 aBitmapColor.SetBlue( *pScanline );
155 return aBitmapColor;
158 void BitmapReadAccess::SetPixelForN24BitTcRgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
160 pScanline = pScanline + nX * 3;
161 *pScanline++ = rBitmapColor.GetRed();
162 *pScanline++ = rBitmapColor.GetGreen();
163 *pScanline = rBitmapColor.GetBlue();
166 BitmapColor BitmapReadAccess::GetPixelForN32BitTcAbgr(ConstScanline pScanline, long nX, const ColorMask&)
168 BitmapColor aBitmapColor;
170 pScanline = pScanline + ( nX << 2 ) + 1;
171 aBitmapColor.SetBlue( *pScanline++ );
172 aBitmapColor.SetGreen( *pScanline++ );
173 aBitmapColor.SetRed( *pScanline );
175 return aBitmapColor;
178 void BitmapReadAccess::SetPixelForN32BitTcAbgr(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
180 pScanline = pScanline + ( nX << 2 );
181 *pScanline++ = 0xFF;
182 *pScanline++ = rBitmapColor.GetBlue();
183 *pScanline++ = rBitmapColor.GetGreen();
184 *pScanline = rBitmapColor.GetRed();
187 BitmapColor BitmapReadAccess::GetPixelForN32BitTcArgb(ConstScanline pScanline, long nX, const ColorMask&)
189 BitmapColor aBitmapColor;
191 pScanline = pScanline + ( nX << 2 ) + 1;
192 aBitmapColor.SetRed( *pScanline++ );
193 aBitmapColor.SetGreen( *pScanline++ );
194 aBitmapColor.SetBlue( *pScanline );
196 return aBitmapColor;
199 void BitmapReadAccess::SetPixelForN32BitTcArgb(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
201 pScanline = pScanline + ( nX << 2 );
202 *pScanline++ = 0xFF;
203 *pScanline++ = rBitmapColor.GetRed();
204 *pScanline++ = rBitmapColor.GetGreen();
205 *pScanline = rBitmapColor.GetBlue();
208 BitmapColor BitmapReadAccess::GetPixelForN32BitTcBgra(ConstScanline pScanline, long nX, const ColorMask&)
210 BitmapColor aBitmapColor;
212 pScanline = pScanline + ( nX << 2 );
213 aBitmapColor.SetBlue( *pScanline++ );
214 aBitmapColor.SetGreen( *pScanline++ );
215 aBitmapColor.SetRed( *pScanline );
217 return aBitmapColor;
220 void BitmapReadAccess::SetPixelForN32BitTcBgra(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
222 pScanline = pScanline + ( nX << 2 );
223 *pScanline++ = rBitmapColor.GetBlue();
224 *pScanline++ = rBitmapColor.GetGreen();
225 *pScanline++ = rBitmapColor.GetRed();
226 *pScanline = 0xFF;
229 BitmapColor BitmapReadAccess::GetPixelForN32BitTcRgba(ConstScanline pScanline, long nX, const ColorMask&)
231 BitmapColor aBitmapColor;
233 pScanline = pScanline + ( nX << 2 );
234 aBitmapColor.SetRed( *pScanline++ );
235 aBitmapColor.SetGreen( *pScanline++ );
236 aBitmapColor.SetBlue( *pScanline );
238 return aBitmapColor;
241 void BitmapReadAccess::SetPixelForN32BitTcRgba(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask&)
243 pScanline = pScanline + ( nX << 2 );
244 *pScanline++ = rBitmapColor.GetRed();
245 *pScanline++ = rBitmapColor.GetGreen();
246 *pScanline++ = rBitmapColor.GetBlue();
247 *pScanline = 0xFF;
250 BitmapColor BitmapReadAccess::GetPixelForN32BitTcMask(ConstScanline pScanline, long nX, const ColorMask& rMask)
252 BitmapColor aColor;
253 rMask.GetColorFor32Bit( aColor, pScanline + ( nX << 2UL ) );
254 return aColor;
257 void BitmapReadAccess::SetPixelForN32BitTcMask(Scanline pScanline, long nX, const BitmapColor& rBitmapColor, const ColorMask& rMask)
259 rMask.SetColorFor32Bit( rBitmapColor, pScanline + ( nX << 2UL ) );
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */