-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage.h
95 lines (76 loc) · 1.76 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <cmath>
// 1 byte
struct Color {
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
};
class Image
{
public:
Image();
~Image() {
if (m_pixels)
{
//delete[] m_pixels;
}
}
void create(int width, int height, int bpp) {
m_width = width;
m_height= height;
m_bpp = bpp;
m_pixels = new unsigned char[getPitch() * m_height];
}
void decode(const char* filename);
int getWidth() const {
return m_width;
}
int getHeight() const {
return m_height;
}
//BitWISE OPERATION para dividir algo entre 8
int getBpp() const {
return m_bpp >> 3;
}
//Pitch es la densidad de información por línea.
//Se da en bytes o sea dividir los bits entre 8
int getPitch() const {
return m_width * getBpp();
}
Color getPixel(unsigned int x, unsigned int y);
void setPixel(unsigned int x, unsigned int y, const Color& color);
void clearColor(const Color& color);
//Proceso de copiar imágenes de un lugar a otro.
//bit bleet es como si fuera el proceso de draw
void bitBlt(Image& source,
int x,
int y,
int srcInitX = 0,
int srcInitY = 0,
int srcEndX = 0,
int srcEndY = 0,
Color* pColorKey = nullptr);
void line(int x0, int y0, int x1, int y1, const Color& color);
void bresehamLine(int x0, int y0, int x1, int y1, const Color& color);
void encode(const char* filename);
protected:
//Tamaño -> Resolución
int m_width =0;
int m_height = 0;
//Bits por pixel, cuantos bits hay por pixel
int m_bpp = 0;
//El contenido será solemente un arreglo o básicamente un buffer.
//Contenedor de pixeles -> Densidad de cada color
unsigned char* m_pixels = nullptr;
};
/*
Imagen de 1 but
*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*
*-*-*-*-*-*-*-*-*
*/