1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <tools/color.hxx>
22 #include <vcl/BitmapColor.hxx>
23 #include <vcl/BitmapWriteAccess.hxx>
25 #include <bitmap/BlendFrameCache.hxx>
27 BlendFrameCache::BlendFrameCache(Size
const& rSize
, sal_uInt8 nAlpha
, Color
const& rColorTopLeft
,
28 Color
const& rColorTopRight
, Color
const& rColorBottomRight
,
29 Color
const& rColorBottomLeft
)
31 , m_nLastAlpha(nAlpha
)
32 , m_aLastColorTopLeft(rColorTopLeft
)
33 , m_aLastColorTopRight(rColorTopRight
)
34 , m_aLastColorBottomRight(rColorBottomRight
)
35 , m_aLastColorBottomLeft(rColorBottomLeft
)
37 if (rSize
.Width() <= 1 || rSize
.Height() <= 1)
40 sal_uInt8
aEraseTrans(0xff);
41 Bitmap
aContent(rSize
, vcl::PixelFormat::N24_BPP
);
42 AlphaMask
aAlpha(rSize
, &aEraseTrans
);
44 aContent
.Erase(COL_BLACK
);
47 BitmapScopedWriteAccess
pContent(aContent
);
48 BitmapScopedWriteAccess
pAlpha(aAlpha
);
50 if (!pContent
|| !pAlpha
)
53 Scanline pScanContent
= pContent
->GetScanline(0);
54 Scanline pScanAlpha
= pContent
->GetScanline(0);
56 // x == 0, y == 0, top-left corner
57 pContent
->SetPixelOnData(pScanContent
, 0, rColorTopLeft
);
58 pAlpha
->SetPixelOnData(pScanAlpha
, 0, BitmapColor(nAlpha
));
61 const tools::Long
nW(rSize
.Width());
63 // y == 0, top line left to right
64 for (x
= 1; x
< nW
- 1; x
++)
66 Color
aMix(rColorTopLeft
);
68 aMix
.Merge(rColorTopRight
, 255 - sal_uInt8((x
* 255) / nW
));
69 pContent
->SetPixelOnData(pScanContent
, x
, aMix
);
70 pAlpha
->SetPixelOnData(pScanAlpha
, x
, BitmapColor(nAlpha
));
73 // x == nW - 1, y == 0, top-right corner
74 // #i123690# Caution! When nW is 1, x == nW is possible (!)
77 pContent
->SetPixelOnData(pScanContent
, x
, rColorTopRight
);
78 pAlpha
->SetPixelOnData(pScanAlpha
, x
, BitmapColor(nAlpha
));
82 const tools::Long
nH(rSize
.Height());
84 // x == 0 and nW - 1, left and right line top-down
85 for (y
= 1; y
< nH
- 1; y
++)
87 pScanContent
= pContent
->GetScanline(y
);
88 pScanAlpha
= pContent
->GetScanline(y
);
89 Color
aMixA(rColorTopLeft
);
91 aMixA
.Merge(rColorBottomLeft
, 255 - sal_uInt8((y
* 255) / nH
));
92 pContent
->SetPixelOnData(pScanContent
, 0, aMixA
);
93 pAlpha
->SetPixelOnData(pScanAlpha
, 0, BitmapColor(nAlpha
));
95 // #i123690# Caution! When nW is 1, x == nW is possible (!)
98 Color
aMixB(rColorTopRight
);
100 aMixB
.Merge(rColorBottomRight
, 255 - sal_uInt8((y
* 255) / nH
));
101 pContent
->SetPixelOnData(pScanContent
, x
, aMixB
);
102 pAlpha
->SetPixelOnData(pScanAlpha
, x
, BitmapColor(nAlpha
));
106 // #i123690# Caution! When nH is 1, y == nH is possible (!)
109 // x == 0, y == nH - 1, bottom-left corner
110 pContent
->SetPixelOnData(pScanContent
, 0, rColorBottomLeft
);
111 pAlpha
->SetPixelOnData(pScanAlpha
, 0, BitmapColor(nAlpha
));
113 // y == nH - 1, bottom line left to right
114 for (x
= 1; x
< nW
- 1; x
++)
116 Color
aMix(rColorBottomLeft
);
118 aMix
.Merge(rColorBottomRight
, 255 - sal_uInt8(((x
- 0) * 255) / nW
));
119 pContent
->SetPixelOnData(pScanContent
, x
, aMix
);
120 pAlpha
->SetPixelOnData(pScanAlpha
, x
, BitmapColor(nAlpha
));
123 // x == nW - 1, y == nH - 1, bottom-right corner
124 // #i123690# Caution! When nW is 1, x == nW is possible (!)
127 pContent
->SetPixelOnData(pScanContent
, x
, rColorBottomRight
);
128 pAlpha
->SetPixelOnData(pScanAlpha
, x
, BitmapColor(nAlpha
));
133 m_aLastResult
= BitmapEx(aContent
, aAlpha
);
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */