forked from mapic91/MpcAsfTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cpp
87 lines (81 loc) · 2.41 KB
/
Utils.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
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
#include "Utils.hpp"
long CharToLong(char* char4)
{
long temp = 0;
temp |= ( ((long)((unsigned char)char4[0]) & (long)0xFF) );
temp |= ( ((long)((unsigned char)char4[1]) & (long)0xFF) << 8 );
temp |= ( ((long)((unsigned char)char4[2]) & (long)0xFF) << 16 );
temp |= ( ((long)((unsigned char)char4[3]) & (long)0xFF) << 24 );
return temp;
}
unsigned char Bit5ToBit8(char value)
{
return Bit5ToBit8((unsigned char)value);
}
unsigned char Bit5ToBit8(unsigned char value)
{
return (unsigned char)((float)value*(float)255/(float)31);
}
unsigned char Bit4ToBit8(unsigned char value)
{
return (unsigned char)((float)value*(float)255/(float)15);
}
unsigned char Bit6ToBit8(unsigned char value)
{
return (unsigned char)((float)value*(float)255/(float)63);
}
void Bit5ToBit8RGB(char* char2, unsigned char *rgb)
{
unsigned char a = (unsigned char)char2[0];
unsigned char b = (unsigned char)char2[1];
unsigned long d = 0;
d = ((d | b) << 8);
d = (d | a);
rgb[0] = (0x1F & d);
rgb[1] = ((0x7E0 & d) >> 5);
rgb[2] = ((0xF800 & d) >> 11);
rgb[0] = Bit5ToBit8(rgb[0]);
rgb[1] = Bit6ToBit8(rgb[1]);
rgb[2] = Bit5ToBit8(rgb[2]);
}
#include "wx/string.h"
#include "wx/msgdlg.h"
FILOCRGBQUAD *RGBAtoFIRGBA(unsigned char *data, bool freeData, long width, long height, long globalWidth, long globalHeight, int offx, int offy)
{
if(data == NULL) return NULL;
long size = globalWidth*globalHeight;
FILOCRGBQUAD *fidata = new FILOCRGBQUAD[size];
if(!fidata)
{
if(freeData) free(data);
return NULL;
}
for(long i = 0; i < size; i++)
{
fidata[i].rgbRed = 0;
fidata[i].rgbGreen = 0;
fidata[i].rgbBlue = 0;
fidata[i].rgbReserved = 0;
}
long offwidth, offheight;
for(long hi = 0; hi < height; hi++)
{
for(long wi = 0; wi < width; wi++)
{
offwidth = wi + offx;
offheight = hi + offy;
if(offwidth >= 0 && offwidth < globalWidth &&
offheight >= 0 && offheight < globalHeight)
{
long index = (hi*width+wi)*4;
long fiIndex = offheight*globalWidth+offwidth;
fidata[fiIndex].rgbRed = data[index];
fidata[fiIndex].rgbGreen = data[index+1];
fidata[fiIndex].rgbBlue = data[index+2];
fidata[fiIndex].rgbReserved = data[index+3];
}
}
}
if(freeData) free(data);
return fidata;
}