bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / gdi / bmpacc3.cxx
blobf2fc66427e29825761d4e0da3b0a7fcd6359e1fb
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/bitmap.hxx>
22 #include <bmpfast.hxx>
23 #include <bitmapwriteaccess.hxx>
25 void BitmapWriteAccess::SetLineColor( const Color& rColor )
27 if (rColor.GetTransparency() == 255)
29 mpLineColor.reset();
31 else
33 if (HasPalette())
35 mpLineColor = BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)));
37 else
39 mpLineColor = BitmapColor(rColor);
44 void BitmapWriteAccess::SetFillColor()
46 mpFillColor.reset();
49 void BitmapWriteAccess::SetFillColor( const Color& rColor )
51 if (rColor.GetTransparency() == 255)
53 mpFillColor.reset();
55 else
57 if (HasPalette())
59 mpFillColor = BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)));
61 else
63 mpFillColor = BitmapColor(rColor);
68 void BitmapWriteAccess::Erase( const Color& rColor )
70 // convert the color format from RGB to palette index if needed
71 // TODO: provide and use Erase( BitmapColor& method)
72 BitmapColor aColor = rColor;
73 if (HasPalette())
75 aColor = BitmapColor(static_cast<sal_uInt8>(GetBestPaletteIndex(rColor)));
78 // try fast bitmap method first
79 if (ImplFastEraseBitmap(*mpBuffer, aColor))
80 return;
82 tools::Rectangle aRect(Point(), maBitmap.GetSizePixel());
83 if (aRect.IsEmpty())
84 return;
85 // clear the bitmap by filling the first line pixel by pixel,
86 // then dup the first line over each other line
87 Scanline pFirstScanline = GetScanline(0);
88 const long nEndX = aRect.Right();
89 for (long nX = 0; nX <= nEndX; ++nX)
90 SetPixelOnData(pFirstScanline, nX, rColor);
91 const auto nScanlineSize = GetScanlineSize();
92 const long nEndY = aRect.Bottom();
93 for (long nY = 1; nY <= nEndY; nY++)
95 Scanline pDestScanline = GetScanline(nY);
96 memcpy(pDestScanline, pFirstScanline, nScanlineSize);
100 void BitmapWriteAccess::DrawLine( const Point& rStart, const Point& rEnd )
102 if (mpLineColor)
104 const BitmapColor& rLineColor = *mpLineColor;
105 long nX, nY;
107 if (rStart.X() == rEnd.X())
109 // Vertical Line
110 const long nEndY = rEnd.Y();
112 nX = rStart.X();
113 nY = rStart.Y();
115 if (nEndY > nY)
117 for (; nY <= nEndY; nY++ )
118 SetPixel( nY, nX, rLineColor );
120 else
122 for (; nY >= nEndY; nY-- )
123 SetPixel( nY, nX, rLineColor );
126 else if (rStart.Y() == rEnd.Y())
128 // Horizontal Line
129 const long nEndX = rEnd.X();
131 nX = rStart.X();
132 nY = rStart.Y();
134 if (nEndX > nX)
136 for (; nX <= nEndX; nX++)
137 SetPixel(nY, nX, rLineColor);
139 else
141 for (; nX >= nEndX; nX--)
142 SetPixel(nY, nX, rLineColor);
145 else
147 const long nDX = labs( rEnd.X() - rStart.X() );
148 const long nDY = labs( rEnd.Y() - rStart.Y() );
149 long nX1;
150 long nY1;
151 long nX2;
152 long nY2;
154 if (nDX >= nDY)
156 if (rStart.X() < rEnd.X())
158 nX1 = rStart.X();
159 nY1 = rStart.Y();
160 nX2 = rEnd.X();
161 nY2 = rEnd.Y();
163 else
165 nX1 = rEnd.X();
166 nY1 = rEnd.Y();
167 nX2 = rStart.X();
168 nY2 = rStart.Y();
171 const long nDYX = (nDY - nDX) << 1;
172 const long nDY2 = nDY << 1;
173 long nD = nDY2 - nDX;
174 bool bPos = nY1 < nY2;
176 for (nX = nX1, nY = nY1; nX <= nX2; nX++)
178 SetPixel(nY, nX, rLineColor);
180 if (nD < 0)
181 nD += nDY2;
182 else
184 nD += nDYX;
186 if (bPos)
187 nY++;
188 else
189 nY--;
193 else
195 if (rStart.Y() < rEnd.Y())
197 nX1 = rStart.X();
198 nY1 = rStart.Y();
199 nX2 = rEnd.X();
200 nY2 = rEnd.Y();
202 else
204 nX1 = rEnd.X();
205 nY1 = rEnd.Y();
206 nX2 = rStart.X();
207 nY2 = rStart.Y();
210 const long nDYX = (nDX - nDY) << 1;
211 const long nDY2 = nDX << 1;
212 long nD = nDY2 - nDY;
213 bool bPos = nX1 < nX2;
215 for (nX = nX1, nY = nY1; nY <= nY2; nY++)
217 SetPixel(nY, nX, rLineColor);
219 if (nD < 0)
220 nD += nDY2;
221 else
223 nD += nDYX;
225 if (bPos)
226 nX++;
227 else
228 nX--;
236 void BitmapWriteAccess::FillRect( const tools::Rectangle& rRect )
238 if (mpFillColor)
240 const BitmapColor& rFillColor = *mpFillColor;
241 tools::Rectangle aRect(Point(), maBitmap.GetSizePixel());
243 aRect.Intersection(rRect);
245 if (!aRect.IsEmpty())
247 const long nStartX = rRect.Left();
248 const long nStartY = rRect.Top();
249 const long nEndX = rRect.Right();
250 const long nEndY = rRect.Bottom();
252 for (long nY = nStartY; nY <= nEndY; nY++)
254 Scanline pScanline = GetScanline( nY );
255 for (long nX = nStartX; nX <= nEndX; nX++)
257 SetPixelOnData(pScanline, nX, rFillColor);
264 void BitmapWriteAccess::DrawRect( const tools::Rectangle& rRect )
266 if (mpFillColor)
267 FillRect(rRect);
269 if (mpLineColor && (!mpFillColor || ( *mpFillColor != *mpLineColor)))
271 DrawLine(rRect.TopLeft(), rRect.TopRight());
272 DrawLine(rRect.TopRight(), rRect.BottomRight());
273 DrawLine(rRect.BottomRight(), rRect.BottomLeft());
274 DrawLine(rRect.BottomLeft(), rRect.TopLeft());
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */