Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fabricocouto opened this issue Nov 20, 2024 · 0 comments
Assignees
Labels

Comments

@fabricocouto
Copy link
Contributor

fabricocouto commented Nov 20, 2024

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);
   
}

}

@robin-swift robin-swift self-assigned this Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants