-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.h
98 lines (68 loc) · 1.9 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
95
96
97
98
//
// Created by Артем Парфенов on 23.03.2022.
//
#pragma once
#include <string>
#include <fstream>
#include <vector>
struct Color {
Color() : red_(0), green_(0), blue_(0) {};
Color(double r, double g, double b) : red_(r), green_(g), blue_(b) {};
double red_;
double green_;
double blue_;
};
class Image {
public:
Image();
Image(size_t width, size_t height);
size_t GetWidth() const;
size_t GetHeight() const;
Color GetColor(size_t i, size_t j) ;
Color &SetColor(size_t i, size_t j);
void Read(const char *filepath);
void Write(const char *filepath);
template<typename type>
static type BinaryRead(std::ifstream& in);
template<typename type>
static void BinaryWrite(std::ofstream& out, type& output);
class BMP {
public:
BMP() = default;
void Read(std::ifstream &in);
void Save(std::ofstream &out);
struct FileHeader {
uint16_t Type;
uint32_t Size;
uint16_t Reserved1;
uint16_t Reserved2;
uint32_t OffBits;
FileHeader() = default;
FileHeader(std::ifstream& in);
void Write(std::ofstream &out);
};
struct ImageHeader {
uint32_t Size;
uint32_t Width;
uint32_t Height;
uint16_t Planes;
uint16_t BitsPerPixel;
uint32_t Compression;
uint32_t SizeImage;
uint32_t XPelsPerMeter;
uint32_t YPelsPerMeter;
uint32_t ClrUsed;
uint32_t ClrImportant;
ImageHeader() = default;
ImageHeader(std::ifstream &in);
void Write(std::ofstream &out);
};
FileHeader file_header_;
ImageHeader image_header_;
};
BMP file_;
private:
size_t width_;
size_t height_;
std::vector<Color> colors_;
};