-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImage.h
More file actions
75 lines (59 loc) · 1.37 KB
/
Image.h
File metadata and controls
75 lines (59 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef IMAGE_H
#define IMAGE_H
#include <cassert>
#include <vecmath.h>
// Simple image class
class Image
{
public:
Image( int w, int h )
{
width = w;
height = h;
data = new Vector3f[ width * height ];
}
~Image()
{
delete[] data;
}
int Width() const
{
return width;
}
int Height() const
{
return height;
}
const Vector3f& GetPixel( int x, int y ) const
{
assert( x >= 0 && x < width );
assert( y >= 0 && y < height );
return data[ y * width + x ];
}
void SetAllPixels( const Vector3f& color )
{
for( int i = 0; i < width * height; ++i )
{
data[i] = color;
}
}
void SetPixel(int x, int y, const Vector3f& color)
{
assert( x >= 0 && x < width );
assert( y >= 0 && y < height );
data[ y * width + x ] = color;
}
static Image* LoadPPM( const char* filename );
void SavePPM( const char* filename ) const;
static Image* LoadTGA( const char* filename );
void SaveTGA( const char* filename ) const;
int SaveBMP(const char *filename);
void SaveImage(const char *filename);
// extension for image comparison
static Image* compare( Image* img1, Image* img2 );
private:
int width;
int height;
Vector3f* data;
};
#endif // IMAGE_H