-
Notifications
You must be signed in to change notification settings - Fork 1
/
image.C
94 lines (62 loc) · 1.19 KB
/
image.C
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
image.C
Brandon Cao
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "image.h"
#include "source.h"
Image::Image(void){
src = NULL;
h= 0;
w= 0;
data = NULL;
}
Image::~Image(){
delete [] data;
}
Image::Image(int width, int height){
w = width;
h = height;
data = (unsigned char *) malloc(h*w*3);
src = NULL;
}
Image::Image(Image &i){
w = i.w;
h = i.h;
data = i.data;
src = NULL;
}
void Image::SetSource(Source *source)
{
src = source;
}
void Image::Update() const
{
if(src !=NULL){
src->Update();
}
}
int Image::GetHeight()const {
return h;
}
int Image::GetWidth()const {
return w;
}
void Image::ResetSize(int width, int height)
{
w = width;
h = height;
delete [] data;
data = new unsigned char[3*w*h];
}
unsigned char * Image::GetPixel(int width, int height)const{
return data+3*(height*w+width);
}
void Image::SetPixel(int width, int height, unsigned char *pixel){
//height*w+width = indexing the image
data[3*(height*w+width)+0] = pixel[0];
data[3*(height*w+width)+1] = pixel[1];
data[3*(height*w+width)+2] = pixel[2];
}