-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.h
66 lines (52 loc) · 1.54 KB
/
image.h
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
#ifndef _IMAGE_H_
#define _IMAGE_H_
#include <assert.h>
#include "vectors.h"
// ====================================================================
// ====================================================================
// Simple image class
class Image {
public:
// ========================
// CONSTRUCTOR & DESTRUCTOR
Image(int w, int h) {
width = w;
height = h;
data = new Vec3f[width*height]; }
~Image() {
delete [] data; }
// =========
// ACCESSORS
int Width() const { return width; }
int Height() const { return height; }
const Vec3f& GetPixel(int x, int y) const {
assert(x >= 0 && x < width);
assert(y >= 0 && y < height);
return data[y*width + x]; }
// =========
// MODIFIERS
void SetAllPixels(const Vec3f &color) {
for (int i = 0; i < width*height; i++) {
data[i] = color; } }
void SetPixel(int x, int y, const Vec3f &color) {
assert(x >= 0 && x < width);
assert(y >= 0 && y < height);
data[y*width + x] = color; }
// ===========
// LOAD & SAVE
static Image* LoadPPM(const char *filename);
void SavePPM(const char *filename) const;
static Image* LoadTGA(const char *filename);
void SaveTGA(const char *filename) const;
// extension for image comparison
static Image* Compare(Image* img1, Image* img2);
private:
// ==============
// REPRESENTATION
int width;
int height;
Vec3f *data;
};
// ====================================================================
// ====================================================================
#endif