forked from Embroidermodder/libembroidery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-pcm.c
75 lines (67 loc) · 2.47 KB
/
format-pcm.c
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
static const int pcmThreadCount = 65;
static const EmbThread pcmThreads[] = {
{ { 0x00, 0x00, 0x00 }, "PCM Color 1", "" },
{ { 0x00, 0x00, 0x80 }, "PCM Color 2", "" },
{ { 0x00, 0x00, 0xFF }, "PCM Color 3", "" },
{ { 0x00, 0x80, 0x80 }, "PCM Color 4", "" },
{ { 0x00, 0xFF, 0xFF }, "PCM Color 5", "" },
{ { 0x80, 0x00, 0x80 }, "PCM Color 6", "" },
{ { 0xFF, 0x00, 0xFF }, "PCM Color 7", "" },
{ { 0x80, 0x00, 0x00 }, "PCM Color 8", "" },
{ { 0xFF, 0x00, 0x00 }, "PCM Color 9", "" },
{ { 0x00, 0x80, 0x00 }, "PCM Color 10", "" },
{ { 0x00, 0xFF, 0x00 }, "PCM Color 11", "" },
{ { 0x80, 0x80, 0x00 }, "PCM Color 12", "" },
{ { 0xFF, 0xFF, 0x00 }, "PCM Color 13", "" },
{ { 0x80, 0x80, 0x80 }, "PCM Color 14", "" },
{ { 0xC0, 0xC0, 0xC0 }, "PCM Color 15", "" },
{ { 0xFF, 0xFF, 0xFF }, "PCM Color 16", "" }
};
static double pcmDecode(unsigned char a1, unsigned char a2, unsigned char a3)
{
int res = a1 + (a2 << 8) + (a3 << 16);
if (res > 0x7FFFFF) {
return (-((~(res)&0x7FFFFF) - 1));
}
return res;
}
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
* Returns \c true if successful, otherwise returns \c false. */
static int readPcm(EmbPattern* pattern, EmbFile* file, const char* fileName)
{
int i = 0;
unsigned char b[9];
double dx = 0, dy = 0;
int flags = 0, st = 0;
embFile_seek(file, 4, SEEK_SET);
for (i = 0; i < 16; i++) {
int colorNumber;
(void)embFile_getc(file); /* zero */
colorNumber = embFile_getc(file);
embPattern_addThread(pattern, pcmThreads[colorNumber]);
}
st = binaryReadUInt16BE(file);
/* READ STITCH RECORDS */
for (i = 0; i < st; i++) {
flags = NORMAL;
if (embFile_read(b, 1, 9, file) != 9)
break;
if (b[8] & 0x01) {
flags = STOP;
} else if (b[8] & 0x04) {
flags = TRIM;
} else if (b[8] != 0) {
/* TODO: ONLY INTERESTED IN THIS CASE TO LEARN MORE ABOUT THE FORMAT */
}
dx = pcmDecode(b[2], b[1], b[0]);
dy = pcmDecode(b[6], b[5], b[4]);
embPattern_addStitchAbs(pattern, dx / 10.0, dy / 10.0, flags, 1);
}
return 1;
}
/*! Writes the data from \a pattern to a file with the given \a fileName.
* Returns \c true if successful, otherwise returns \c false. */
static int writePcm(EmbPattern* pattern, EmbFile* file, const char* fileName)
{
return 0; /*TODO: finish writePcm */
}