Assignments Assignments

image.h
Go to the documentation of this file.
1#ifndef IMAGE_INCLUDED
2#define IMAGE_INCLUDED
3
4#include <stdio.h>
5#include <string>
6#include <stdexcept>
7#include <Util/geometry.h>
8#include "lineSegments.h"
9
10 namespace Image
11{
13 class Pixel32
14 {
15 public:
17 unsigned char r;
18
20 unsigned char g;
21
23 unsigned char b;
24
26 unsigned char a;
27
29 Pixel32( void );
30 };
31
32
34 class Image32
35 {
37 int _width , _height;
38
40 Pixel32* _pixels;
41
43 void _assertInBounds( int x , int y ) const;
44 public:
45
47 struct iterator
48 {
49 using iterator_category = std::forward_iterator_tag;
50 using reference = Pixel32 &;
51 using pointer = Pixel32 *;
52 using value_type = Pixel32;
53 using difference_type = std::ptrdiff_t;
54
55 iterator( void ) : _p(nullptr) {}
56 iterator( Pixel32 *p ) : _p(p) {}
57 bool operator == ( const iterator &it ) const { return _p==it._p; }
58 bool operator != ( const iterator &it ) const { return _p!=it._p; }
59 iterator operator ++( int ){ iterator it = *this ; _p++ ; return it; }
60 iterator &operator ++( void ){ _p++ ; return *this; }
61 Pixel32 &operator * ( void ){ return *_p; }
62 Pixel32 *operator -> ( void ){ return _p; }
63 protected:
64 friend Image32;
65 Pixel32 *_p;
66 };
67
68 struct const_iterator
69 {
70 using iterator_category = std::forward_iterator_tag;
71 using reference = const Pixel32 &;
72 using pointer = const Pixel32 *;
73 using value_type = Pixel32;
74 using difference_type = std::ptrdiff_t;
75
76 const_iterator( void ) : _p(nullptr) {}
77 const_iterator( const Pixel32 *p ) : _p(p) {}
78 bool operator == ( const const_iterator &it ) const { return _p==it._p; }
79 bool operator != ( const const_iterator &it ) const { return _p!=it._p; }
80 const_iterator operator ++( int ){ const_iterator it = *this ; _p++ ; return it; }
81 const_iterator &operator ++( void ){ _p++ ; return *this; }
82 const Pixel32 &operator * ( void ){ return *_p; }
83 const Pixel32 *operator -> ( void ){ return _p; }
84 protected:
85 friend Image32;
86 const Pixel32 *_p;
87 };
88
89 iterator begin( void ){ return iterator( _pixels ); }
90 iterator end( void ){ return iterator( _pixels+_width*_height ); }
91 const_iterator begin( void ) const { return const_iterator( _pixels ); }
92 const_iterator end( void ) const { return const_iterator( _pixels+_width*_height ); }
93
95 Image32( void );
96
98 Image32( const Image32& img );
99
101 Image32( Image32&& img );
102
104 Image32& operator = ( const Image32& img );
105
107 Image32& operator = ( Image32&& img );
108
110 ~Image32( void );
111
113 void setSize( int width , int height );
114
116 int width( void ) const;
117
119 int height( void ) const;
120
123 Pixel32& operator() ( int x , int y );
124
127 const Pixel32& operator() ( int x , int y ) const;
128
130 void read( std::string fileName );
131
133 void write( std::string fileName ) const;
134
138 Image32 addRandomNoise( double noise ) const;
139
142 Image32 brighten( double brightness ) const;
143
145 Image32 luminance( void ) const;
146
149 Image32 contrast( double contrast ) const;
150
153 Image32 saturate( double saturation ) const;
154
158 Image32 quantize( int bits ) const;
159
163 Image32 randomDither( int bits ) const;
164
168 Image32 orderedDither2X2( int bits ) const;
169
173 Image32 floydSteinbergDither( int bits ) const;
174
176 Image32 blur3X3( void ) const;
177
179 Image32 edgeDetect3X3( void ) const;
180
184 Image32 scaleNearest( double scaleFactor ) const;
185
188 Image32 scaleBilinear( double scaleFactor ) const;
189
192 Image32 scaleGaussian( double scaleFactor ) const;
193
196 Image32 rotateNearest( double angle ) const;
197
200 Image32 rotateBilinear( double angle ) const;
201
204 Image32 rotateGaussian( double angle ) const;
205
208 void setAlpha( const Image32& matte );
209
212 Image32 composite( const Image32& overlay ) const;
213
216 Image32 crop( int x1 , int y1 , int x2 , int y2 ) const;
217
219 Image32 funFilter( void ) const;
220
224 static Image32 BeierNeelyMorph( const Image32& source , const Image32& destination , const OrientedLineSegmentPairs& olsp , double timeStep );
225
227 Image32 warp( const OrientedLineSegmentPairs& olsp ) const;
228
232 static Image32 CrossDissolve( const Image32& source , const Image32& destination , double blendWeight );
233
236 Pixel32 nearestSample( Util::Point2D p ) const;
237
240 Pixel32 bilinearSample( Util::Point2D p ) const;
241
244 Pixel32 gaussianSample( Util::Point2D p , double variance , double radius ) const;
245 };
246}
247#endif // IMAGE_INCLUDED
248
Image::Image32
Definition image.h:35
Image::Image32::composite
Image32 composite(const Image32 &overlay) const
Definition image.todo.cpp:174
Image::Image32::operator=
Image32 & operator=(const Image32 &img)
Definition image.cpp:29
Image::Image32::blur3X3
Image32 blur3X3(void) const
Definition image.todo.cpp:94
Image::Image32::brighten
Image32 brighten(double brightness) const
Definition image.todo.cpp:22
Image::Image32::_pixels
Pixel32 * _pixels
Definition image.h:40
Image::Image32::~Image32
~Image32(void)
Definition image.cpp:52
Image::Image32::end
const_iterator end(void) const
Definition image.h:92
Image::Image32::scaleNearest
Image32 scaleNearest(double scaleFactor) const
Definition image.todo.cpp:112
Image::Image32::scaleGaussian
Image32 scaleGaussian(double scaleFactor) const
Definition image.todo.cpp:130
Image::Image32::orderedDither2X2
Image32 orderedDither2X2(int bits) const
Definition image.todo.cpp:76
Image::Image32::randomDither
Image32 randomDither(int bits) const
Definition image.todo.cpp:67
Image::Image32::height
int height(void) const
Definition image.cpp:89
Image::Image32::_assertInBounds
void _assertInBounds(int x, int y) const
Definition image.cpp:70
Image::Image32::setAlpha
void setAlpha(const Image32 &matte)
Definition image.todo.cpp:166
Image::Image32::rotateBilinear
Image32 rotateBilinear(double angle) const
Definition image.todo.cpp:148
Image::Image32::warp
Image32 warp(const OrientedLineSegmentPairs &olsp) const
Definition image.todo.cpp:192
Image::Image32::_height
int _height
Definition image.h:37
Image::Image32::_width
int _width
Definition image.h:37
Image::Image32::contrast
Image32 contrast(double contrast) const
Definition image.todo.cpp:40
Image::Image32::scaleBilinear
Image32 scaleBilinear(double scaleFactor) const
Definition image.todo.cpp:121
Image::Image32::bilinearSample
Pixel32 bilinearSample(Util::Point2D p) const
Definition image.todo.cpp:228
Image::Image32::read
void read(std::string fileName)
Definition image.cpp:118
Image::Image32::crop
Image32 crop(int x1, int y1, int x2, int y2) const
Definition image.todo.cpp:210
Image::Image32::funFilter
Image32 funFilter(void) const
Definition image.todo.cpp:201
Image::Image32::addRandomNoise
Image32 addRandomNoise(double noise) const
Definition image.todo.cpp:13
Image::Image32::begin
const_iterator begin(void) const
Definition image.h:91
Image::Image32::operator()
Pixel32 & operator()(int x, int y)
Definition image.cpp:75
Image::Image32::luminance
Image32 luminance(void) const
Definition image.todo.cpp:31
Image::Image32::edgeDetect3X3
Image32 edgeDetect3X3(void) const
Definition image.todo.cpp:103
Image::Image32::quantize
Image32 quantize(int bits) const
Definition image.todo.cpp:58
Image::Image32::gaussianSample
Pixel32 gaussianSample(Util::Point2D p, double variance, double radius) const
Definition image.todo.cpp:237
Image::Image32::width
int width(void) const
Definition image.cpp:87
Image::Image32::setSize
void setSize(int width, int height)
Definition image.cpp:54
Image::Image32::nearestSample
Pixel32 nearestSample(Util::Point2D p) const
Definition image.todo.cpp:219
Image::Image32::floydSteinbergDither
Image32 floydSteinbergDither(int bits) const
Definition image.todo.cpp:85
Image::Image32::write
void write(std::string fileName) const
Definition image.cpp:126
Image::Image32::Image32
Image32(void)
Definition image.cpp:21
Image::Image32::begin
iterator begin(void)
Definition image.h:89
Image::Image32::rotateGaussian
Image32 rotateGaussian(double angle) const
Definition image.todo.cpp:157
Image::Image32::rotateNearest
Image32 rotateNearest(double angle) const
Definition image.todo.cpp:139
Image::Image32::saturate
Image32 saturate(double saturation) const
Definition image.todo.cpp:49
Image::Image32::CrossDissolve
static Image32 CrossDissolve(const Image32 &source, const Image32 &destination, double blendWeight)
Definition image.todo.cpp:183
Image::Image32::end
iterator end(void)
Definition image.h:90
Image::OrientedLineSegmentPairs
Definition lineSegments.h:63
Image::Pixel32
Definition image.h:14
Image::Pixel32::Pixel32
Pixel32(void)
Definition image.cpp:16
Image::Pixel32::r
unsigned char r
Definition image.h:17
Image::Pixel32::a
unsigned char a
Definition image.h:26
Image::Pixel32::b
unsigned char b
Definition image.h:23
Image::Pixel32::g
unsigned char g
Definition image.h:20
geometry.h
lineSegments.h
BeierNeelyMorph
CmdLineParameterArray< string, 3 > BeierNeelyMorph("bnMorph")
Image
Definition bmp.cpp:142
Util::Point2D
Point< 2 > Point2D
Definition geometry.h:523
Image::Image32::const_iterator
Definition image.h:69
Image::Image32::const_iterator::operator!=
bool operator!=(const const_iterator &it) const
Definition image.h:79
Image::Image32::const_iterator::const_iterator
const_iterator(void)
Definition image.h:76
Image::Image32::const_iterator::operator==
bool operator==(const const_iterator &it) const
Definition image.h:78
Image::Image32::const_iterator::value_type
Pixel32 value_type
Definition image.h:73
Image::Image32::const_iterator::_p
const Pixel32 * _p
Definition image.h:86
Image::Image32::const_iterator::operator++
const_iterator & operator++(void)
Definition image.h:81
Image::Image32::const_iterator::operator*
const Pixel32 & operator*(void)
Definition image.h:82
Image::Image32::const_iterator::operator->
const Pixel32 * operator->(void)
Definition image.h:83
Image::Image32::const_iterator::pointer
const Pixel32 * pointer
Definition image.h:72
Image::Image32::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition image.h:70
Image::Image32::const_iterator::const_iterator
const_iterator(const Pixel32 *p)
Definition image.h:77
Image::Image32::const_iterator::difference_type
std::ptrdiff_t difference_type
Definition image.h:74
Image::Image32::const_iterator::reference
const Pixel32 & reference
Definition image.h:71
Image::Image32::const_iterator::Image32
friend Image32
Definition image.h:85
Image::Image32::iterator
Definition image.h:48
Image::Image32::iterator::Image32
friend Image32
Definition image.h:64
Image::Image32::iterator::operator->
Pixel32 * operator->(void)
Definition image.h:62
Image::Image32::iterator::operator!=
bool operator!=(const iterator &it) const
Definition image.h:58
Image::Image32::iterator::_p
Pixel32 * _p
Definition image.h:65
Image::Image32::iterator::operator*
Pixel32 & operator*(void)
Definition image.h:61
Image::Image32::iterator::iterator
iterator(void)
Definition image.h:55
Image::Image32::iterator::reference
Pixel32 & reference
Definition image.h:50
Image::Image32::iterator::operator++
iterator & operator++(void)
Definition image.h:60
Image::Image32::iterator::pointer
Pixel32 * pointer
Definition image.h:51
Image::Image32::iterator::iterator
iterator(Pixel32 *p)
Definition image.h:56
Image::Image32::iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition image.h:49
Image::Image32::iterator::difference_type
std::ptrdiff_t difference_type
Definition image.h:53
Image::Image32::iterator::value_type
Pixel32 value_type
Definition image.h:52
Image::Image32::iterator::operator==
bool operator==(const iterator &it) const
Definition image.h:57