Skip to content

This version that is in the current libembroidery of viewing the PES file, is with error does not view correctly, the code that I post here views correctly #231

@fabricocouto

Description

@fabricocouto

This version that is in the current libembroidery of viewing the PES file, is with error does not view correctly, the code that I post here views correctly

image

int stitchNumber = 0;


void* f = file;
unsigned char b[2];
while (fread(b, 1, 2, f) == 2) {
    int val1 = (int)b[0];
    int val2 = (int)b[1];

    int stitchType = NORMAL;
    if (val1 == 0xFF && val2 == 0x00) {
        emb_pattern_addStitchRel(pattern, 0.0, 0.0, END, 1);
        break;
    }
    if (val1 == 0xFE && val2 == 0xB0) {
        (void)fgetc(f);
        emb_pattern_addStitchRel(pattern, 0.0, 0.0, STOP, 1);
        stitchNumber++;
        continue;
    }
    /* High bit set means 12-bit offset, otherwise 7-bit signed delta */
    if (val1 & 0x80) {
        if (val1 & 0x20)
            stitchType = TRIM;
        if (val1 & 0x10)
            stitchType = JUMP;
        val1 = ((val1 & 0x0F) << 8) + val2;

        /* Signed 12-bit arithmetic */
        if (val1 & 0x800) {
            val1 -= 0x1000;
        }

       val2 =  fgetc(f);
    }
    else if (val1 >= 0x40) {
        val1 -= 0x80;
    }
    if (val2 & 0x80) {
        if (val2 & 0x20)
            stitchType = TRIM;
        if (val2 & 0x10)
            stitchType = JUMP;
         val2 = ((val2 & 0x0F) << 8) + fgetc(file);

        /* Signed 12-bit arithmetic */
        if (val2 & 0x800) {
            val2 -= 0x1000;
        }
    }
    else if (val2 >= 0x40) {
        val2 -= 0x80;
    }
    emb_pattern_addStitchRel(pattern, val1 / 10.0, val2 / 10.0, stitchType, 1);
   
}

}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions