1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 ) );
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 );
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 ];
65 rByte
|= ( rBitmapColor
.GetIndex() & 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 ];
86 rByte
|= ( rBitmapColor
.GetIndex() << 4 );
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
)
108 rMask
.GetColorFor8Bit( aColor
, pScanline
+ nX
);
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
);
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
);
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
;
168 vcl::bitmap::unpremultiply(r
, a
),
169 vcl::bitmap::unpremultiply(g
, a
),
170 vcl::bitmap::unpremultiply(b
, 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
);
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 );
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
;
216 vcl::bitmap::unpremultiply(r
, a
),
217 vcl::bitmap::unpremultiply(g
, a
),
218 vcl::bitmap::unpremultiply(b
, 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
);
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 );
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
;
264 vcl::bitmap::unpremultiply(r
, a
),
265 vcl::bitmap::unpremultiply(g
, a
),
266 vcl::bitmap::unpremultiply(b
, 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
);
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
);
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();
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
;
312 vcl::bitmap::unpremultiply(r
, a
),
313 vcl::bitmap::unpremultiply(g
, a
),
314 vcl::bitmap::unpremultiply(b
, 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
);
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
);
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();
350 BitmapColor
BitmapReadAccess::GetPixelForN32BitTcMask(ConstScanline pScanline
, long nX
, const ColorMask
& rMask
)
353 rMask
.GetColorFor32Bit( aColor
, pScanline
+ ( nX
<< 2 ) );
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: */