-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.h
More file actions
186 lines (145 loc) · 5.95 KB
/
Copy pathconvert.h
File metadata and controls
186 lines (145 loc) · 5.95 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef CONVERT_H
#define CONVERT_H
#include <QObject>
#include <QEventLoop>
#include "jpegoptions.h"
#include <vector>
#include <fstream>
#include <string>
#include <map>
#include <stdio.h>
#include <turbojpeg.h>
#include <libheif/heif.h>
#include "lodepng/lodepng.h"
typedef unsigned int uint;
class Convert : public QObject {
Q_OBJECT
public:
static QStringList acceptedInputs;
static QStringList acceptedOutputs;
QStringList files;
Convert();
~Convert();
/**
* @brief getFileExtension gets the file extension from a path
* @param name the path to the file
* @return string containing the extension| "png", "jpeg"
*/
QString getFileExtension(QString path);
private:
double progress;
int lastEmittedValue;
uint numFiles;
std::vector<uint> jpegSettings;
/**
* @brief writePNG Writes interlaces rgb to a png
* @param filename The path to save the file to
* @param image Image data in the form of {r,g,b,...}
* @param width Width of the image
* @param height Height of the image
*/
void writePNG(const char* filename, std::vector<unsigned char>& image, uint width, uint height);
/**
* @brief writeHeif Writes RGBA image data to heif format
* @param filename The path to save the file to
* @param image RGBA image data
* @param w Width in pixels
* @param h Height in pixels
*/
void writeHeif(const char* filename, std::vector<unsigned char>& image, uint w, uint h);
/**
* @brief writeJpeg Writes RGBA data to a jpeg format
* @param filename The path to save the file to
* @param image RGBA image data
* @param w Width
* @param h Height
* @param jpegQual Quality to save the jpeg in 0-100| 0=highest compression 100=highest quality
*/
void writeJpeg(const char* filename, std::vector<unsigned char>& image, uint w, uint h, int jpegQual);
/**
* @brief parseHeifData Removes the buffer bits from heif data
* @param data The data returned from readHeifData| {r,g,b, ... , buffer, buffer, ...}
* @param w The width of the heif image
* @param h The height of the heif image
* @param the width of the image including buffer data
* @return pure interlaced rgb| {r,g,b,...}
*/
void writeIcon(const char* filename, std::vector<unsigned char>& image, uint w);
std::vector<unsigned char> parseHeifData(const uint8_t* data, int w, int h, int stride);
/**
* @brief readHeifData Reads heif data from a file
* @param pth The path of the heif image
* @param Stride empty int variable to store the stride data
* @param w Empty int variable to store the width data
* @param h Empty int variable to store the height data
* @return array of 24bit interlaced rgb data, with buffers
*/
const uint8_t* readHeifData(const char* pth, int &stride, int &w, int &h);
/**
* @brief readPngData reads data from a png file and saves it as RGBA pixels
* @param pth the path to the file
* @param w Reference to variable for image width
* @param h Regerence to variable for image Height
* @return array of 24bit interlaced rgb data
*/
std::vector<unsigned char> readPngData(const char* pth, int &w, int &h);
/**
* @brief readJpegData reads data from a jpeg file and saves it as RGBA pixels
* @param pth the path to the file
* @param w Reference to variable for image width
* @param h Regerence to variable for image Height
* @return array of 24bit interlaced rgb data
*/
std::vector<unsigned char> readJpegData(const char *pth, int &w, int &h);
/**
* @brief updateProgressBar A wrapper function for the direct signal progressChanged(int), only emits a signal when the progess has increased by atleast 1
* @param change The amount of progress changed
*/
void updateProgressBar(double change);
/**
* @brief getJpegSizeEstimations compresses an image x times and interpolates between those points to estimate the size/quality
* @param image RGBA image data
* @param w Width of the image
* @param h Height of the image
* @param numSamples Number of actually readings to take
* @return Vector with 100 sizes (in bytes) in ascending order
*/
std::vector<uint> getJpegSizeEstimations(std::vector<unsigned char>& image, uint w, uint h, uint numSamples);
template <typename T>
std::vector<unsigned char> toBytes(T num);
void squareImage(std::vector<unsigned char> &image, int &w, int &h);
void resizeImage(std::vector<unsigned char> &image, uint w, uint h, uint nw, uint nh);
signals:
/**
* @brief progressChanged A signal to be used with a GUI object, signals a change in a progress bar
* @param progress the new progress to emit
*/
void progressChanged(int progress);
/**
* @brief finished A signal that is emitted when a work request has been completed
*/
void finished();
/**
* @brief openJpegOptionsMenu requests a jpegOptionsMenu from the GUI thread
* @param sizes Vector of sizes per quality
* @param isChecked Default state of the keepQuality checkbox
*/
void openJpegOptionsMenu(std::vector<uint> sizes, bool isChecked);
/**
* @brief stopWait halts a blocking loop in the thread
*/
void stopWait();
public slots:
/**
* @brief handleConvert Handles the conversion of files
* @param files A list of file paths to be converted
* @param outType The output extension for the files
*/
void handleConvert(QStringList files, QString outType);
/**
* @brief saveJpegSettings Save jpeg settings returned from the gui thread
* @param settings The returned settings
*/
void saveJpegSettings(std::vector<uint> settings);
};
#endif // CONVERT_H