diff options
Diffstat (limited to 'src/image.cpp')
-rw-r--r-- | src/image.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/image.cpp b/src/image.cpp index 384de9a..122df65 100644 --- a/src/image.cpp +++ b/src/image.cpp | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <png.h> | 7 | #include <png.h> |
8 | #include <math.h> | ||
8 | 9 | ||
9 | Image::Image() : | 10 | Image::Image() : |
10 | iWidth( 0 ), | 11 | iWidth( 0 ), |
@@ -27,6 +28,16 @@ Image::~Image() | |||
27 | delete[] pPix; | 28 | delete[] pPix; |
28 | } | 29 | } |
29 | 30 | ||
31 | int Image::getWidth() const | ||
32 | { | ||
33 | return iWidth; | ||
34 | } | ||
35 | |||
36 | int Image::getHeight() const | ||
37 | { | ||
38 | return iHeight; | ||
39 | } | ||
40 | |||
30 | void Image::clear( uint8_t uColor ) | 41 | void Image::clear( uint8_t uColor ) |
31 | { | 42 | { |
32 | memset( pPix, uColor, iWidth*iHeight ); | 43 | memset( pPix, uColor, iWidth*iHeight ); |
@@ -139,5 +150,24 @@ void Image::drawLine( int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t uC | |||
139 | set( j, y1, uColor ); | 150 | set( j, y1, uColor ); |
140 | } | 151 | } |
141 | } | 152 | } |
153 | else | ||
154 | { | ||
155 | int xd = x2-x1; | ||
156 | int yd = y2-y1; | ||
157 | float d = sqrt( xd*xd + yd*yd ); | ||
158 | float ux = xd/d; | ||
159 | float uy = yd/d; | ||
160 | |||
161 | float x = x1; | ||
162 | float y = y1; | ||
163 | |||
164 | set( (int)x, (int)y, uColor ); | ||
165 | for( float n = 0.0; n < d; n += 1.0 ) | ||
166 | { | ||
167 | x += ux; | ||
168 | y += uy; | ||
169 | set( (int)x, (int)y, uColor ); | ||
170 | } | ||
171 | } | ||
142 | } | 172 | } |
143 | 173 | ||