LibreOffice Module vcl (master) 1
BitmapReadAccess.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
21#include <vcl/BitmapTools.hxx>
22
23#include <salbmp.hxx>
24#include <svdata.hxx>
25#include <salinst.hxx>
26
28 : BitmapInfoAccess(rBitmap, nMode)
29 , mFncGetPixel(nullptr)
30 , mFncSetPixel(nullptr)
31{
32 if (!mpBuffer)
33 return;
34
35 const std::shared_ptr<SalBitmap>& xImpBmp = rBitmap.ImplGetSalBitmap();
36 if (!xImpBmp)
37 return;
38
40
43
45 {
46 xImpBmp->ReleaseBuffer(mpBuffer, mnAccessMode);
47 mpBuffer = nullptr;
48 }
49}
50
52
54
56{
57 switch (RemoveScanline(nFormat))
58 {
70 else
75 else
80 else
85 else
89
90 default:
91 return nullptr;
92 }
93}
94
96{
97 switch (RemoveScanline(nFormat))
98 {
102 return SetPixelForN8BitPal;
110 else
115 else
120 else
125 else
129
130 default:
131 return nullptr;
132 }
133}
134
136 const BitmapColor& rFallback) const
137{
138 // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative
139 // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!)
140 if (mpBuffer && fX >= 0.0 && fY >= 0.0)
141 {
142 const sal_Int64 nX(static_cast<sal_Int64>(fX));
143 const sal_Int64 nY(static_cast<sal_Int64>(fY));
144
145 if (nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
146 {
147 // get base-return value from inside pixel
148 BitmapColor aRetval(GetColor(nY, nX));
149
150 // calculate deltas and indices for neighbour accesses
151 sal_Int16 nDeltaX((fX - (nX + 0.5)) * 255.0); // [-255 .. 255]
152 sal_Int16 nDeltaY((fY - (nY + 0.5)) * 255.0); // [-255 .. 255]
153 sal_Int16 nIndX(0);
154 sal_Int16 nIndY(0);
155
156 if (nDeltaX > 0)
157 {
158 nIndX = nX + 1;
159 }
160 else
161 {
162 nIndX = nX - 1;
163 nDeltaX = -nDeltaX;
164 }
165
166 if (nDeltaY > 0)
167 {
168 nIndY = nY + 1;
169 }
170 else
171 {
172 nIndY = nY - 1;
173 nDeltaY = -nDeltaY;
174 }
175
176 // get right/left neighbour
177 BitmapColor aXCol(rFallback);
178
179 if (nDeltaX && nIndX >= 0 && nIndX < mpBuffer->mnWidth)
180 {
181 aXCol = GetColor(nY, nIndX);
182 }
183
184 // get top/bottom neighbour
185 BitmapColor aYCol(rFallback);
186
187 if (nDeltaY && nIndY >= 0 && nIndY < mpBuffer->mnHeight)
188 {
189 aYCol = GetColor(nIndY, nX);
190 }
191
192 // get one of four edge neighbours
193 BitmapColor aXYCol(rFallback);
194
195 if (nDeltaX && nDeltaY && nIndX >= 0 && nIndY >= 0 && nIndX < mpBuffer->mnWidth
196 && nIndY < mpBuffer->mnHeight)
197 {
198 aXYCol = GetColor(nIndY, nIndX);
199 }
200
201 // merge return value with right/left neighbour
202 if (aXCol != aRetval)
203 {
204 aRetval.Merge(aXCol, 255 - nDeltaX);
205 }
206
207 // merge top/bottom neighbour with edge
208 if (aYCol != aXYCol)
209 {
210 aYCol.Merge(aXYCol, 255 - nDeltaX);
211 }
212
213 // merge return value with already merged top/bottom neighbour
214 if (aRetval != aYCol)
215 {
216 aRetval.Merge(aYCol, 255 - nDeltaY);
217 }
218
219 return aRetval;
220 }
221 }
222
223 return rFallback;
224}
225
227 const BitmapColor& rFallback) const
228{
229 // ask directly doubles >= 0.0 here to avoid rounded values of 0 at small negative
230 // double values, e.g. static_cast< sal_Int32 >(-0.25) is 0, not -1, but *has* to be outside (!)
231 if (mpBuffer && fX >= 0.0 && fY >= 0.0)
232 {
233 const sal_Int32 nX(static_cast<sal_Int32>(fX));
234 const sal_Int32 nY(static_cast<sal_Int32>(fY));
235
236 if (nX < mpBuffer->mnWidth && nY < mpBuffer->mnHeight)
237 {
238 return GetColor(nY, nX);
239 }
240 }
241
242 return rFallback;
243}
244
246 const ColorMask&)
247{
248 return BitmapColor(pScanline[nX >> 3] & (1 << (7 - (nX & 7))) ? 1 : 0);
249}
250
252 const BitmapColor& rBitmapColor, const ColorMask&)
253{
254 sal_uInt8& rByte = pScanline[nX >> 3];
255
256 if (rBitmapColor.GetIndex() & 1)
257 rByte |= 1 << (7 - (nX & 7));
258 else
259 rByte &= ~(1 << (7 - (nX & 7)));
260}
261
263 const ColorMask&)
264{
265 return BitmapColor(pScanline[nX]);
266}
267
269 const BitmapColor& rBitmapColor, const ColorMask&)
270{
271 pScanline[nX] = rBitmapColor.GetIndex();
272}
273
275 const ColorMask&)
276{
277 BitmapColor aBitmapColor;
278
279 pScanline = pScanline + nX * 3;
280 aBitmapColor.SetBlue(*pScanline++);
281 aBitmapColor.SetGreen(*pScanline++);
282 aBitmapColor.SetRed(*pScanline);
283
284 return aBitmapColor;
285}
286
288 const BitmapColor& rBitmapColor, const ColorMask&)
289{
290 pScanline = pScanline + nX * 3;
291 *pScanline++ = rBitmapColor.GetBlue();
292 *pScanline++ = rBitmapColor.GetGreen();
293 *pScanline = rBitmapColor.GetRed();
294}
295
297 const ColorMask&)
298{
299 BitmapColor aBitmapColor;
300
301 pScanline = pScanline + nX * 3;
302 aBitmapColor.SetRed(*pScanline++);
303 aBitmapColor.SetGreen(*pScanline++);
304 aBitmapColor.SetBlue(*pScanline);
305
306 return aBitmapColor;
307}
308
310 const BitmapColor& rBitmapColor, const ColorMask&)
311{
312 pScanline = pScanline + nX * 3;
313 *pScanline++ = rBitmapColor.GetRed();
314 *pScanline++ = rBitmapColor.GetGreen();
315 *pScanline = rBitmapColor.GetBlue();
316}
317
319 const ColorMask&)
320{
321 pScanline = pScanline + nX * 4;
322
323 sal_uInt8 a = *pScanline++;
324 sal_uInt8 b = *pScanline++;
325 sal_uInt8 g = *pScanline++;
326 sal_uInt8 r = *pScanline;
327
330}
331
333 const ColorMask&)
334{
335 BitmapColor aBitmapColor;
336
337 pScanline = pScanline + (nX << 2) + 1;
338 aBitmapColor.SetBlue(*pScanline++);
339 aBitmapColor.SetGreen(*pScanline++);
340 aBitmapColor.SetRed(*pScanline);
341
342 return aBitmapColor;
343}
344
346 const BitmapColor& rBitmapColor, const ColorMask&)
347{
348 pScanline = pScanline + nX * 4;
349
350 sal_uInt8 alpha = rBitmapColor.GetAlpha();
351 *pScanline++ = alpha;
352 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
353 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
354 *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
355}
356
358 const BitmapColor& rBitmapColor, const ColorMask&)
359{
360 pScanline = pScanline + (nX << 2);
361 *pScanline++ = 0xFF;
362 *pScanline++ = rBitmapColor.GetBlue();
363 *pScanline++ = rBitmapColor.GetGreen();
364 *pScanline = rBitmapColor.GetRed();
365}
366
368 const ColorMask&)
369{
370 pScanline = pScanline + nX * 4;
371
372 sal_uInt8 a = *pScanline++;
373 sal_uInt8 r = *pScanline++;
374 sal_uInt8 g = *pScanline++;
375 sal_uInt8 b = *pScanline;
376
379}
380
382 const ColorMask&)
383{
384 BitmapColor aBitmapColor;
385
386 pScanline = pScanline + (nX << 2) + 1;
387 aBitmapColor.SetRed(*pScanline++);
388 aBitmapColor.SetGreen(*pScanline++);
389 aBitmapColor.SetBlue(*pScanline);
390
391 return aBitmapColor;
392}
393
395 const BitmapColor& rBitmapColor, const ColorMask&)
396{
397 pScanline = pScanline + nX * 4;
398
399 sal_uInt8 alpha = rBitmapColor.GetAlpha();
400 *pScanline++ = alpha;
401 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
402 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
403 *pScanline = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
404}
405
407 const BitmapColor& rBitmapColor, const ColorMask&)
408{
409 pScanline = pScanline + (nX << 2);
410 *pScanline++ = 0xFF;
411 *pScanline++ = rBitmapColor.GetRed();
412 *pScanline++ = rBitmapColor.GetGreen();
413 *pScanline = rBitmapColor.GetBlue();
414}
415
417 const ColorMask&)
418{
419 pScanline = pScanline + nX * 4;
420
421 sal_uInt8 b = *pScanline++;
422 sal_uInt8 g = *pScanline++;
423 sal_uInt8 r = *pScanline++;
424 sal_uInt8 a = *pScanline;
425
428}
429
431 const ColorMask&)
432{
433 BitmapColor aBitmapColor;
434
435 pScanline = pScanline + (nX << 2);
436 aBitmapColor.SetBlue(*pScanline++);
437 aBitmapColor.SetGreen(*pScanline++);
438 aBitmapColor.SetRed(*pScanline);
439
440 return aBitmapColor;
441}
442
444 const BitmapColor& rBitmapColor, const ColorMask&)
445{
446 pScanline = pScanline + nX * 4;
447
448 sal_uInt8 alpha = rBitmapColor.GetAlpha();
449 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
450 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
451 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
452 *pScanline = alpha;
453}
454
456 const BitmapColor& rBitmapColor, const ColorMask&)
457{
458 pScanline = pScanline + (nX << 2);
459 *pScanline++ = rBitmapColor.GetBlue();
460 *pScanline++ = rBitmapColor.GetGreen();
461 *pScanline++ = rBitmapColor.GetRed();
462 *pScanline = 0xFF;
463}
464
466 const ColorMask&)
467{
468 pScanline = pScanline + nX * 4;
469
470 sal_uInt8 r = *pScanline++;
471 sal_uInt8 g = *pScanline++;
472 sal_uInt8 b = *pScanline++;
473 sal_uInt8 a = *pScanline;
474
477}
478
480 const ColorMask&)
481{
482 BitmapColor aBitmapColor;
483
484 pScanline = pScanline + (nX << 2);
485 aBitmapColor.SetRed(*pScanline++);
486 aBitmapColor.SetGreen(*pScanline++);
487 aBitmapColor.SetBlue(*pScanline);
488
489 return aBitmapColor;
490}
491
493 const BitmapColor& rBitmapColor, const ColorMask&)
494{
495 pScanline = pScanline + nX * 4;
496
497 sal_uInt8 alpha = rBitmapColor.GetAlpha();
498 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetRed(), alpha);
499 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetGreen(), alpha);
500 *pScanline++ = vcl::bitmap::premultiply(rBitmapColor.GetBlue(), alpha);
501 *pScanline = alpha;
502}
503
505 const BitmapColor& rBitmapColor, const ColorMask&)
506{
507 pScanline = pScanline + (nX << 2);
508 *pScanline++ = rBitmapColor.GetRed();
509 *pScanline++ = rBitmapColor.GetGreen();
510 *pScanline++ = rBitmapColor.GetBlue();
511 *pScanline = 0xFF;
512}
513
515 const ColorMask& rMask)
516{
517 BitmapColor aColor;
518 rMask.GetColorFor32Bit(aColor, pScanline + (nX << 2));
519 return aColor;
520}
521
523 const BitmapColor& rBitmapColor,
524 const ColorMask& rMask)
525{
526 rMask.SetColorFor32Bit(rBitmapColor, pScanline + (nX << 2));
527}
528
529/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapAccessMode
void(* FncSetPixel)(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapColor(* FncGetPixel)(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
bool Bitmap32IsPreMultipled()
const sal_uInt8 * ConstScanline
Definition: Scanline.hxx:27
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
ScanlineFormat
Definition: Scanline.hxx:29
ScanlineFormat RemoveScanline(ScanlineFormat nFormat)
Definition: Scanline.hxx:53
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:70
BitmapAccessMode mnAccessMode
friend class BitmapReadAccess
BitmapBuffer * mpBuffer
static void SetPixelForN32BitTcRgbx(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
BitmapColor GetColorWithFallback(double fY, double fX, const BitmapColor &rFallback) const
Get the color at coordinates fY, fX; if outside, return rFallback.
static void SetPixelForN32BitTcAbgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN8BitPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcRgbx(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
FncGetPixel mFncGetPixel
static FncGetPixel GetPixelFunction(ScanlineFormat nFormat)
static BitmapColor GetPixelForN24BitTcRgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
virtual VCL_DLLPUBLIC ~BitmapReadAccess() override
static BitmapColor GetPixelForN32BitTcXbgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
FncSetPixel mFncSetPixel
static FncSetPixel SetPixelFunction(ScanlineFormat nFormat)
static BitmapColor GetPixelForN32BitTcBgra(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN1BitMsbPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN1BitMsbPal(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN24BitTcBgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN24BitTcRgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN24BitTcBgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
BitmapColor GetColor(tools::Long nY, tools::Long nX) const
static void SetPixelForN32BitTcXrgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcAbgr(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN32BitTcRgba(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN32BitTcBgrx(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcBgrx(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcArgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
BitmapColor GetInterpolatedColorWithFallback(double fY, double fX, const BitmapColor &rFallback) const
Get the interpolated color at coordinates fY, fX; if outside, return rFallback.
static void SetPixelForN8BitPal(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN32BitTcBgra(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN32BitTcArgb(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static void SetPixelForN32BitTcMask(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcXrgb(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static void SetPixelForN32BitTcXbgr(Scanline pScanline, tools::Long nX, const BitmapColor &rBitmapColor, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcRgba(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
static BitmapColor GetPixelForN32BitTcMask(ConstScanline pScanline, tools::Long nX, const ColorMask &rMask)
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
void SetColorFor32Bit(const BitmapColor &rColor, sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:182
void GetColorFor32Bit(BitmapColor &rColor, const sal_uInt8 *pPixel) const
Definition: ColorMask.hxx:165
sal_uInt8 GetBlue() const
void SetGreen(sal_uInt8 nGreen)
void SetRed(sal_uInt8 nRed)
void Merge(const Color &rMergeColor, sal_uInt8 cTransparency)
sal_uInt8 GetAlpha() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
void SetBlue(sal_uInt8 nBlue)
bool supportsBitmap32() const
Definition: salinst.hxx:90
ColorAlpha
uno_Any a
constexpr double alpha[nDetails]
long Long
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a)
sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a)
double mnWidth
double mnHeight
ColorMask maColorMask
ScanlineFormat mnFormat
SalInstance * mpDefInst
Definition: svdata.hxx:389
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77
unsigned char sal_uInt8