-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjpeg.hpp
88 lines (57 loc) · 1.86 KB
/
jpeg.hpp
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
//
// jpeg.hpp
// jpeg
//
// Created by Blake Johnson on 10/15/19.
// Copyright © 2019 Blake Johnson. All rights reserved.
//
#ifndef jpeg_hpp
#define jpeg_hpp
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <string>
#include "huffman.hpp"
/*
take in a ppm image
divide the image into nxn blocks
for each block, covert into YCbCr and also downsample (optional but desired)
for each block, run it through a discrete cosine transform
for each block, quantize
create a huffman tree for ac luminance, ac Yc + Yr, dc luminance, and dc Yc + Yr
for each block use entropy encoding (use run length encoding optional but desired), create a zigzag pattern, encode using huffman trees created above
for each block, populate the new jpeg file
create a method to view the binary of a jpeg file for debugging
*/
//sequential
//non interchange
//Abbreviated format for table-specification data 4.9.3
class DCT;
class Jpeg {
private:
std::string sourceImage;
//in ppm images, the first line says the type, the second line says height and width, the third line says the color size, fourth line starts data
std::ifstream srcImg;
protected:
int width;
int height;
double *** colors; //3 channels for rgb/YCbCr x height x width
public:
Jpeg();
Jpeg(std::string img) {
generateJpeg(img);
}
~Jpeg(){};
void generateJpeg(std::string img);
void parseDimensions();
//extracts rgb data from the file and converts them to YCbCr and stores them into colors array
void parseColors();
void rgbToYCbCr ( double YcBcR []);
//iterate over nxn blocks, call dct, and quantize
void divideIntoBlocks();
//creates 4 huffman trees to eventually encode each block
void createHuffmanTrees();
friend class DCT;
};
#endif /* jpeg_hpp */