-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.h
More file actions
77 lines (66 loc) · 1.75 KB
/
Image.h
File metadata and controls
77 lines (66 loc) · 1.75 KB
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
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
class Image {
private:
enum ImageType {
PNG, JPG, BMP
};
struct Pixel {
Pixel(uint8_t R = 0, uint8_t G = 0, uint8_t B = 0);
uint8_t R, G, B;
};
std::vector <Pixel> pixels;
int w;
int h;
int channels;
//CONSTRUCTORS
public:
Image(const char* filename); //read from file
Image(int w, int h, int channels); //new blank
Image(const Image& img); //copy
//MANAGING FILES
public:
void writeImageData(const char* filename);
private:
void readImageData(const char* filename);
void printOperationStatus(bool isOperationSuccessfull, const char* filename, std::string operationName);
//FILTERS
public:
void grayscaleAvg();
void grayscaleLum();
void colorMask(float R, float G, float B);
private:
bool containsAtLeastThreeChannels();
//CHANGING POSITIONS
public:
void flipX();
void flipY();
void flipRight();
public:
void reduce(float dstW, float dstH);
private:
void deducePixelsOrRatio(float& dstH, float& dstW);
bool validateSize(float sizeW, float sizeH);
bool isBiggerThanDstSize(int current, int size);
bool isThePixelToCopy(float& toNext, float ratio);
//ASCII
public:
void printAscii();
void printAscii(std::string resultTextName);
private:
//maps value to the closest value in range (val, base range, range to assing)
int map_value(int value, int MinBaseRange, int MaxBaseRange, int MinDstRange, int MaxDstRange);
template <typename Out>
void print(Out& out);
//HELP FUNKCTIONS
private:
ImageType getFileType(const char* filename);
std::vector <Pixel> formatToPixels(uint8_t* data);
uint8_t* formatToUint8(std::vector <Pixel>& pixels);
public:
size_t size();
int getW();
int getH();
};