-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.C
79 lines (69 loc) · 1.59 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
#include "image.h"
#include <memory.h>
#include <source.h>
Pixel::Pixel()
{
}
Pixel::Pixel(unsigned char R, unsigned char G, unsigned char B)
{
this->R = R;
this->G = G;
this->B = B;
}
Image::Image()
{
width = 0;
height = 0;
pixels = NULL;
src = NULL;
}
Image::Image(Source *s)
{
width = 0;
height = 0;
pixels = NULL;
src = s;
}
Image::Image(const Image &img)
{
width = img.width;
height = img.height;
pixels = (Pixel *)malloc(sizeof(img.pixels));
pixels = img.pixels;
}
Image::Image(int width, int height)
{
this->width = width;
this->height = height;
}
Image::Image(int width, int height, Pixel *pixels)
{
this->width = width;
this->height = height;
memcpy(this->pixels, pixels, 3 * width * height * sizeof(unsigned char));
}
void Image::setPixelAt(int i, int i2, Pixel *pix) {
pixels[i].setPixelR(pix[i2].getR());
pixels[i].setPixelG(pix[i2].getG());
pixels[i].setPixelB(pix[i2].getB());
}
void Image::setPixelAt(int i, Pixel pix) {
pixels[i].setPixelR(pix.getR());
pixels[i].setPixelG(pix.getG());
pixels[i].setPixelB(pix.getB());
}
void Image::setWidth(int newWidth) { width = newWidth; }
void Image::setHeight(int newHeight) { height = newHeight; }
void Image::setPixels(Pixel *pixels, int num) { memcpy(this->pixels, pixels, num); }
void Image::setSource(Source *src) { this->src = src; };
void Image::allocatePixels(int num) { pixels = (Pixel *)malloc(num); };
void Image::freeMe()
{
free(pixels);
free(this);
}
void Image::Update() const
{
//printf("UPDATING AN IMAGE\n");
src->Update();
}