-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRGBPixel.h
More file actions
38 lines (32 loc) · 1.25 KB
/
RGBPixel.h
File metadata and controls
38 lines (32 loc) · 1.25 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
#ifndef RGBPIXEL_H_INCLUDED
#define RGBPIXEL_H_INCLUDED
#include <fstream>
#include <iostream>
using namespace std;
namespace Compression{
struct RGBPixel{
//TODO : Comment this
float red;
float green;
float blue;
RGBPixel(){}
RGBPixel(unsigned char red, unsigned char green, unsigned char blue): red(red), green(green), blue(blue){}
friend istream& operator>>(istream& in, RGBPixel& px){
unsigned char rBuf, gBuf, bBuf;
in.read(reinterpret_cast<char*>(&bBuf), sizeof(unsigned char)); px.blue = bBuf;
in.read(reinterpret_cast<char*>(&gBuf), sizeof(unsigned char)); px.green = gBuf;
in.read(reinterpret_cast<char*>(&rBuf), sizeof(unsigned char)); px.red = rBuf;
return in;
}
friend ostream& operator<<(ostream& out, RGBPixel& px){
unsigned char r = (unsigned char)(px.red + 0.5),
g = (unsigned char)(px.green + 0.5),
b = (unsigned char)(px.blue + 0.5);
out.write(reinterpret_cast<char*>(&b), sizeof(b));
out.write(reinterpret_cast<char*>(&g), sizeof(g));
out.write(reinterpret_cast<char*>(&r), sizeof(r));
return out;
}
};
}
#endif