labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ImageTools.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : ImageTools.cpp
3  Project : LabPlot
4  Description : Collection of different image processing algorithms
5  --------------------------------------------------------------------
6  Copyright : (C) 2017 by Alexander Semke (alexander.semke@web.de)
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  * This program is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU General Public License *
23  * along with this program; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
25  * Boston, MA 02110-1301 USA *
26  * *
27  ***************************************************************************/
28 #include "ImageTools.h"
29 
30 /*!
31  \class ImageToools
32  \brief Provides static functions implementing different image processing algorithms.
33  \ingroup tools
34 */
35 QImage ImageTools::blurred(const QImage& image, QRect rect, int radius, bool alphaOnly) {
36  int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
37  int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];
38 
39  QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
40  int r1 = rect.top();
41  int r2 = rect.bottom();
42  int c1 = rect.left();
43  int c2 = rect.right();
44 
45  int bpl = result.bytesPerLine();
46  int rgba[4];
47  unsigned char* p;
48 
49  int i1 = 0;
50  int i2 = 3;
51 
52  if (alphaOnly)
53  i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::LittleEndian)*3;
54 
55  for (int col = c1; col <= c2; col++) {
56  p = result.scanLine(r1) + col * 4;
57  for (int i = i1; i <= i2; i++)
58  rgba[i] = p[i] << 4;
59 
60  p += bpl;
61  for (int j = r1; j < r2; j++, p += bpl)
62  for (int i = i1; i <= i2; i++)
63  p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
64  }
65 
66  for (int row = r1; row <= r2; row++) {
67  p = result.scanLine(row) + c1 * 4;
68  for (int i = i1; i <= i2; i++)
69  rgba[i] = p[i] << 4;
70 
71  p += 4;
72  for (int j = c1; j < c2; j++, p += 4)
73  for (int i = i1; i <= i2; i++)
74  p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
75  }
76 
77  for (int col = c1; col <= c2; col++) {
78  p = result.scanLine(r2) + col * 4;
79  for (int i = i1; i <= i2; i++)
80  rgba[i] = p[i] << 4;
81 
82  p -= bpl;
83  for (int j = r1; j < r2; j++, p -= bpl)
84  for (int i = i1; i <= i2; i++)
85  p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
86  }
87 
88  for (int row = r1; row <= r2; row++) {
89  p = result.scanLine(row) + c2 * 4;
90  for (int i = i1; i <= i2; i++)
91  rgba[i] = p[i] << 4;
92 
93  p -= 4;
94  for (int j = c1; j < c2; j++, p -= 4)
95  for (int i = i1; i <= i2; i++)
96  p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
97  }
98 
99  return result;
100 }
static QImage blurred(const QImage &image, QRect rect, int radius, bool alphaOnly=false)
Definition: ImageTools.cpp:35