-
Notifications
You must be signed in to change notification settings - Fork 0
/
RiffFileDefs.cpp
58 lines (49 loc) · 1.41 KB
/
RiffFileDefs.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "RiffFileDefs.h"
#include <QtCore>
using RiffFileDefs::ByteBuffer;
QString RiffFileDefs::FOURCC2QString(RiffFileDefs::FOURCC d){
char* chars = new char[5];
*(chars+4) = '\0';
memcpy(chars, &d, 4);
return QString::fromAscii(chars);
}
RiffFileDefs::FOURCC RiffFileDefs::QString2FOURCC(QString str){
QByteArray ba = str.toAscii();
char* chars = new char[5];
memcpy(chars, str.toAscii().data(), 5);
qDebug() << str << chars << ba;
RiffFileDefs::FOURCC out;
memcpy(&out, chars, 4);
return out;
}
RiffFileDefs::DWORD RiffFileDefs::QString2DWORD(QString str){
char* chars = new char[5];
memcpy(chars, str.toAscii().data(), 5);
RiffFileDefs::DWORD out;
memcpy(&out, chars, 4);
return out;
}
ByteBuffer* RiffFileDefs::getByteBuffer(char* bytes, DWORD size){
// qDebug() << "asd";
ByteBuffer* bb = new ByteBuffer;
for (DWORD i=0;i<size;i++){
bb->append(*(bytes+i));
}
return bb;
}
int RiffFileDefs::readInt(QFile* file, int sizeOfInt){
char* data = new char [sizeOfInt];
int out = -1;
if (file->read(data, sizeOfInt) == sizeOfInt){
memcpy(&out, data, sizeOfInt);
}
return out;
}
QString RiffFileDefs::readString(QFile* file, int sizeOfString) {
char* data = new char [sizeOfString+1];
if (file->read(data, 4) == 4){
*(data+sizeOfString) = '\0';
return QString(data);
}
return "";
}