forked from Embroidermodder/libembroidery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format-u00.c
60 lines (52 loc) · 1.81 KB
/
format-u00.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
/*! 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 readU00(EmbPattern* pattern, EmbFile* file, const char* fileName)
{
int i;
char dx = 0, dy = 0;
int flags = NORMAL;
char endOfStream = 0;
EmbThread t;
unsigned char b[4];
/* 16 3byte RGB's start @ 0x08 followed by 14 bytes between 0 and 15 with index of color for each color change */
embFile_seek(file, 0x08, SEEK_SET);
for (i = 0; i < 16; i++) {
t.color.r = binaryReadUInt8(file);
t.color.g = binaryReadUInt8(file);
t.color.b = binaryReadUInt8(file);
embPattern_addThread(pattern, t);
}
embFile_seek(file, 0x100, SEEK_SET);
for (i = 0; !endOfStream; i++) {
char negativeX, negativeY;
unsigned char b0 = binaryReadUInt8(file);
unsigned char b1 = binaryReadUInt8(file);
unsigned char b2 = binaryReadUInt8(file);
if (b0 == 0xF8 || b0 == 0x87 || b0 == 0x91) {
break;
}
if ((b0 & 0x0F) == 0) {
flags = NORMAL;
} else if ((b0 & 0x1f) == 1) {
flags = JUMP;
} else if ((b0 & 0x0F) > 0) {
flags = STOP;
}
negativeX = ((b0 & 0x20) > 0);
negativeY = ((b0 & 0x40) > 0);
dx = (char)b2;
dy = (char)b1;
if (negativeX)
dx = (char)-dx;
if (negativeY)
dy = (char)-dy;
embPattern_addStitchRel(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 writeU00(EmbPattern* pattern, EmbFile* file, const char* fileName)
{
return 0; /*TODO: finish WriteU00 */
}