blob: 779e73b1d1ef7fd49cf70c4a1cd5e77f5f9c814e (
plain)
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
|
#include "Adapter.h"
#include "emb-pattern.h"
#include "PMR\Embroidery\AnalyzeInput.pb-c.h"
#include "PMR\Embroidery\AnalyzeOutput.pb-c.h"
#include "PMR\Embroidery\EmbroideryFile.pb-c.h"
#include "PMR\Embroidery\Stitch.pb-c.h"
#include "PMR\Embroidery\StitchFlag.pb-c.h"
#include "PMR\Embroidery\StitchColor.pb-c.h"
#include "PMR\Embroidery\Extents.pb-c.h"
Adapter::Adapter()
{
}
Adapter::~Adapter()
{
}
size_t Adapter::AnalyzeEmbroideryFile(uint8_t * input_buffer, size_t input_buffer_size, uint8_t *& output_buffer)
{
//Unpack input...
AnalyzeInput *input = analyze_input__unpack(NULL, input_buffer_size, input_buffer);
//Initialize Output...
AnalyzeOutput output = ANALYZE_OUTPUT__INIT;
EmbPattern* p = embPattern_create();
int ok = embPattern_read(p, input->filepath);
if (ok)
{
int stitchCount = embStitchList_count(p->stitchList);
int colorCount = embThreadList_count(p->threadList);
EmbroideryFile embroideryFile;
embroideryFile.colorcount = colorCount;
embroideryFile.stitchcount = stitchCount;
embroideryFile.colors = (StitchColor**)malloc(sizeof(StitchColor*) * colorCount);
embroideryFile.stitches = (Stitch**)malloc(sizeof(Stitch*) * stitchCount);
for (size_t i = 0; i < colorCount; i++)
{
StitchColor color;
color.red = (int)p->threadList[i].thread.color.r;
color.green = (int)p->threadList[i].thread.color.g;
color.blue = (int)p->threadList[i].thread.color.b;
embroideryFile.colors[i] = &color;
}
for (size_t i = 0; i < stitchCount; i++)
{
EmbStitch intStitch = p->stitchList[i].stitch;
Stitch outStitch;
outStitch.xx = intStitch.xx;
outStitch.yy = intStitch.yy;
outStitch.flag = (StitchFlag)intStitch.flags;
outStitch.colorindex = intStitch.color;
embroideryFile.stitches[i] = &outStitch;
}
output.embroideryfile = &embroideryFile;
}
//Pack output...
output_buffer = (uint8_t*)malloc(analyze_output__get_packed_size(&output));
return analyze_output__pack(&output, output_buffer);
}
|