KiCad PCB EDA Suite
cimage.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) 1992-2016 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 CIMAGE_H
31 #define CIMAGE_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 typedef struct {
79  signed char kernel[5][5];
80  unsigned int div;
81  unsigned char offset;
82 }S_FILTER;
83 
84 
89 class CIMAGE
90 {
91 
92 public:
93 
100  CIMAGE( unsigned int aXsize, unsigned int aYsize );
101 
108  CIMAGE( const CIMAGE &aSrcImage );
109 
110  ~CIMAGE();
111 
120  void Setpixel( int aX, int aY, unsigned char aValue );
121 
130  unsigned char Getpixel( int aX, int aY ) const;
131 
139  void Hline( int aXStart, int aXEnd, int aY, unsigned char aValue );
140 
148  void CircleFilled( int aCx, int aCy, int aRadius, unsigned char aValue );
149 
169  void CopyFull( const CIMAGE* aImgA, const CIMAGE* aImgB, IMAGE_OP aOperation );
170 
175  void Invert();
176 
184  void EfxFilter( CIMAGE* aInImg, IMAGE_FILTER aFilterType );
185 
192  void SaveAsPNG( const wxString& aFileName ) const;
193 
200  void SetPixelsFromNormalizedFloat( const float * aNormalizedFloatArray );
201 
207  unsigned char* GetBuffer() const;
208 
209  unsigned int GetWidth() const { return m_width; }
210  unsigned int GetHeight() const { return m_height; }
211 private:
212 
220  bool wrapCoords( int *aXo, int *aYo ) const;
221 
222  void plot8CircleLines( int aCx, int aCy, int aX, int aY, unsigned char aValue );
223 
224 private:
225  unsigned char* m_pixels;
226  unsigned int m_width;
227  unsigned int m_height;
228  unsigned int m_wxh;
230 };
231 
232 #endif // CIMAGE_H
~CIMAGE()
Definition: cimage.cpp:65
unsigned int m_height
height of the image
Definition: cimage.h:227
unsigned int GetWidth() const
Definition: cimage.h:209
void SaveAsPNG(const wxString &aFileName) const
Function SaveAsPNG save image buffer to a PNG file into the working folder.
Definition: cimage.cpp:538
Coords are wrapped arround.
Coords that wraps are not evaluated.
IMAGE_WRAP m_wraping
current wrapping type
Definition: cimage.h:229
unsigned char * m_pixels
buffer to store the image 8bit-channel
Definition: cimage.h:225
void Hline(int aXStart, int aXEnd, int aY, unsigned char aValue)
hline - Draws an horizontal line
Definition: cimage.cpp:137
void CircleFilled(int aCx, int aCy, int aRadius, unsigned char aValue)
CircleFilled.
Definition: cimage.cpp:172
void Setpixel(int aX, int aY, unsigned char aValue)
Function Setpixel set a value in a pixel position, position is clamped in accord with the current cla...
Definition: cimage.cpp:121
CIMAGE(unsigned int aXsize, unsigned int aYsize)
Constructor CIMAGE constructs a CIMAGE based on image size.
Definition: cimage.cpp:43
void Invert()
Function Invert invert the values of image this <- (255 - this)
Definition: cimage.cpp:197
unsigned int GetHeight() const
Definition: cimage.h:210
unsigned char offset
Definition: cimage.h:81
unsigned int m_width
width of the image
Definition: cimage.h:226
unsigned int m_wxh
width * height precalc value
Definition: cimage.h:228
IMAGE_FILTER
Filter type enumeration.
Definition: cimage.h:62
void plot8CircleLines(int aCx, int aCy, int aX, int aY, unsigned char aValue)
Definition: cimage.cpp:112
unsigned char Getpixel(int aX, int aY) const
Function Getpixel get the pixel value from pixel position, position is clamped in accord with the cur...
Definition: cimage.cpp:128
unsigned int div
Definition: cimage.h:80
bool wrapCoords(int *aXo, int *aYo) const
Function wrapCoords calculate the coordinates points in accord with the current clamping settings.
Definition: cimage.cpp:77
5x5 Filter struct parameters
Definition: cimage.h:78
IMAGE_OP
Image operation type.
Definition: cimage.h:36
void SetPixelsFromNormalizedFloat(const float *aNormalizedFloatArray)
Function SetPixelsFromNormalizedFloat set the current channel from a float normalized (0....
Definition: cimage.cpp:526
CIMAGE manages a 8-bit channel image.
Definition: cimage.h:89
void CopyFull(const CIMAGE *aImgA, const CIMAGE *aImgB, IMAGE_OP aOperation)
Function CopyFull perform a copy operation, based on operation type.
Definition: cimage.cpp:204
IMAGE_WRAP
Image wrap type enumeration.
Definition: cimage.h:53
unsigned char * GetBuffer() const
Function GetBuffer get the image buffer pointer.
Definition: cimage.cpp:71
void EfxFilter(CIMAGE *aInImg, IMAGE_FILTER aFilterType)
Function EfxFilter apply a filter to the input image and stores it in the image class this <- FilterT...
Definition: cimage.cpp:471
Coords are clamped to image size.