-
Notifications
You must be signed in to change notification settings - Fork 0
/
JPEGConverter.cpp
39 lines (33 loc) · 1.2 KB
/
JPEGConverter.cpp
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
#include <JPEGConverter.h>
JPEGConverter::JPEGConverter(QString const &filename): max_size(50 * 1024 * 1024){
QFile file(filename);
file.open(QIODevice::ReadOnly);
tmp = file.readAll();
}
QByteArray JPEGConverter::convertBytesToJPEGBytes(QByteArray const &data){
QByteArray result(tmp);
result += data;
return result;
}
QByteArray JPEGConverter::convertJPEGBytesToBytes(QByteArray const &jpegdata){
return QByteArray(jpegdata.mid(631));
}
void JPEGConverter::encodeFile(QString const &inputFileName, FileToUpload &fileToUpload){
QFile in(inputFileName);
if("" == fileToUpload.sourceFileName){
QFileInfo fi(in.fileName());
fileToUpload.sourceFileName = fi.fileName();
}
if(!in.open(QIODevice::ReadOnly)) return;
in.seek(fileToUpload.offset);
fileToUpload.byteArray = convertBytesToJPEGBytes(in.read(max_size));
++fileToUpload.partNumber;
if(!in.atEnd()) fileToUpload.offset += max_size;
else fileToUpload.offset = -1;
}
bool JPEGConverter::decodeFile(const QString &filename, const QByteArray &array){
QFile in(filename);
if(!in.open(QIODevice::Append)) return false;
in.write(convertJPEGBytesToBytes(array));
return true;
}