KiCad PCB EDA Suite
image.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef IMAGE_H
31 #define IMAGE_H
32 
33 #include <wx/string.h>
34 
36 enum class IMAGE_OP
37 {
38  RAW,
39  ADD,
40  SUB,
41  DIF,
42  MUL,
43  AND,
44  OR,
45  XOR,
46  BLEND50,
47  MIN,
48  MAX
49 };
50 
51 
53 enum class IMAGE_WRAP
54 {
55  ZERO,
56  CLAMP,
57  WRAP
58 };
59 
60 
62 enum class IMAGE_FILTER
63 {
64  HIPASS,
68  CARTOON,
69  EMBOSS,
70  SHARPEN,
71  MELT,
72  SOBEL_GX,
73  SOBEL_GY,
74  BLUR_3X3,
75 };
76 
78 struct S_FILTER
79 {
80  signed char kernel[5][5];
81  unsigned int div;
82  unsigned char offset;
83 };
84 
85 
89 class IMAGE
90 {
91 public:
98  IMAGE( unsigned int aXsize, unsigned int aYsize );
99 
107  IMAGE( const IMAGE& aSrcImage );
108 
109  ~IMAGE();
110 
119  void Setpixel( int aX, int aY, unsigned char aValue );
120 
129  unsigned char Getpixel( int aX, int aY ) const;
130 
139  void Hline( int aXStart, int aXEnd, int aY, unsigned char aValue );
140 
141  void CircleFilled( int aCx, int aCy, int aRadius, unsigned char aValue );
142 
163  void CopyFull( const IMAGE* aImgA, const IMAGE* aImgB, IMAGE_OP aOperation );
164 
168  void Invert();
169 
176  void EfxFilter( IMAGE* aInImg, IMAGE_FILTER aFilterType );
177 
186  void EfxFilter_SkipCenter( IMAGE* aInImg, IMAGE_FILTER aFilterType, unsigned int aRadius );
187 
195  void SaveAsPNG( const wxString& aFileName ) const;
196 
204  void SetPixelsFromNormalizedFloat( const float* aNormalizedFloatArray );
205 
211  unsigned char* GetBuffer() const;
212 
213  unsigned int GetWidth() const { return m_width; }
214  unsigned int GetHeight() const { return m_height; }
215 
216 private:
224  bool wrapCoords( int* aXo, int* aYo ) const;
225 
226  void plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char aValue );
227 
228  unsigned char* m_pixels;
229  unsigned int m_width;
230  unsigned int m_height;
231  unsigned int m_wxh;
233 };
234 
235 #endif // IMAGE_H
unsigned char * GetBuffer() const
Get the image buffer pointer.
Definition: image.cpp:73
Coords are wrapped around.
unsigned int m_width
width of the image
Definition: image.h:229
bool wrapCoords(int *aXo, int *aYo) const
Calculate the coordinates points in accord with the current clamping settings.
Definition: image.cpp:79
IMAGE_OP
Image operation type.
Definition: image.h:36
IMAGE_WRAP m_wraping
current wrapping type
Definition: image.h:232
void CopyFull(const IMAGE *aImgA, const IMAGE *aImgB, IMAGE_OP aOperation)
Perform a copy operation based on aOperation type.
Definition: image.cpp:205
IMAGE_FILTER
Filter type enumeration.
Definition: image.h:62
void Hline(int aXStart, int aXEnd, int aY, unsigned char aValue)
Draw a horizontal line.
Definition: image.cpp:139
~IMAGE()
Definition: image.cpp:67
void SaveAsPNG(const wxString &aFileName) const
Save image buffer to a PNG file into the working folder.
Definition: image.cpp:597
unsigned char Getpixel(int aX, int aY) const
Get the pixel value from pixel position, position is clamped in accord with the current clamp setting...
Definition: image.cpp:130
void EfxFilter_SkipCenter(IMAGE *aInImg, IMAGE_FILTER aFilterType, unsigned int aRadius)
Apply a filter to the input image and store it in the image class.
Definition: image.cpp:527
void CircleFilled(int aCx, int aCy, int aRadius, unsigned char aValue)
Definition: image.cpp:173
void Setpixel(int aX, int aY, unsigned char aValue)
Set a value in a pixel position, position is clamped in accordance with the current clamp settings.
Definition: image.cpp:123
unsigned char * m_pixels
buffer to store the image 8bit-channel
Definition: image.h:228
unsigned char offset
Definition: image.h:82
unsigned int m_wxh
width * height precalc value
Definition: image.h:231
Coords that wraps are not evaluated.
signed char kernel[5][5]
Definition: image.h:80
unsigned int div
Definition: image.h:81
Coords are clamped to image size.
IMAGE(unsigned int aXsize, unsigned int aYsize)
Construct a IMAGE based on image size.
Definition: image.cpp:45
void SetPixelsFromNormalizedFloat(const float *aNormalizedFloatArray)
Set the current channel from a float normalized (0.0 - 1.0) buffer.
Definition: image.cpp:585
5x5 Filter struct parameters
Definition: image.h:78
void Invert()
Invert the values of this image <- (255 - this)
Definition: image.cpp:198
IMAGE_WRAP
Image wrap type enumeration.
Definition: image.h:53
unsigned int GetHeight() const
Definition: image.h:214
Manage an 8-bit channel image.
Definition: image.h:89
void EfxFilter(IMAGE *aInImg, IMAGE_FILTER aFilterType)
Apply a filter to the input image and store it in the image class.
Definition: image.cpp:474
unsigned int GetWidth() const
Definition: image.h:213
unsigned int m_height
height of the image
Definition: image.h:230
void plot8CircleLines(int aCx, int aCy, int aX, int aY, unsigned char aValue)
Definition: image.cpp:114