Example #1
0
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
 *  Returns \c true if successful, otherwise returns \c false. */
int readPec(EmbPattern* pattern, const char* fileName)
{
    unsigned int graphicsOffset;
    unsigned char colorChanges;
    int i;
    EmbFile* file = 0;

    if(!pattern) { embLog_error("format-pec.c readPec(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-pec.c readPec(), fileName argument is null\n"); return 0; }

    file = embFile_open(fileName, "rb");
    if(!file)
    {
        embLog_error("format-pec.c readPec(), cannot open %s for reading\n", fileName);
        return 0;
    }

    embFile_seek(file, 0x38, SEEK_SET);
    colorChanges = (unsigned char)binaryReadByte(file);
    for(i = 0; i <= colorChanges; i++)
    {
        embPattern_addThread(pattern, pecThreads[binaryReadByte(file) % 65]);
    }

    /* Get Graphics offset */
    embFile_seek(file, 0x20A, SEEK_SET);

    graphicsOffset = (unsigned int)(binaryReadUInt8(file));
    graphicsOffset |= (binaryReadUInt8(file) << 8);
    graphicsOffset |= (binaryReadUInt8(file) << 16);

    (void)binaryReadByte(file); /* 0x31 */
    (void)binaryReadByte(file); /* 0xFF */
    (void)binaryReadByte(file); /* 0xF0 */
    /* Get X and Y size in .1 mm */
    /* 0x210 */
    binaryReadInt16(file); /* x size */
    binaryReadInt16(file); /* y size */

    binaryReadInt16(file); /* 0x01E0 */
    binaryReadInt16(file); /* 0x01B0 */
    binaryReadInt16(file); /* distance left from start */
    binaryReadInt16(file); /* distance up from start */

    /* Begin Stitch Data */
    /* 0x21C */
    /*unsigned int end = graphicsOffset + 0x208; */
    readPecStitches(pattern, file);

    embFile_close(file);

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
        embPattern_addStitchRel(pattern, 0, 0, END, 1);

    embPattern_flipVertical(pattern);

    return 1;
}
Example #2
0
int readDat(EmbPattern* pattern, const char* fileName)
{
    int fileLength, stitchesRemaining;
    FILE* file = 0;

    file = fopen(fileName, "rb");
    if(!file)
    {
        return 0;
    }
    embPattern_loadExternalColorFile(pattern, fileName);
    fseek(file, 0x00, SEEK_END);
    fileLength = ftell(file);
    fseek(file, 0x02, SEEK_SET);
    stitchesRemaining = binaryReadUInt16(file);
    fseek(file, 0x100, SEEK_SET);

    while(ftell(file)< fileLength)
    {
        int b1 = (int)binaryReadUInt8(file);
        int b2 = (int)binaryReadUInt8(file);
        unsigned char b0 = binaryReadByte(file);

        int stitchType = NORMAL;
        stitchesRemaining--;

        if((b0 & 0x02) == 0) stitchType = TRIM;

        if(b0 == 0x87)
        {
            stitchType = STOP;
        }
        if(b0 == 0xF8)
        {
            break;
        }
        if(b1 >= 0x80)
        {
            b1 = -(b1 & 0x7F);
        }
        if(b2 >= 0x80)
        {
            b2 = -(b2 & 0x7F);
        }
        embPattern_addStitchRel(pattern, b1 / 10.0, b2 / 10.0, stitchType, 1);
    }
    fclose(file);
    embPattern_addStitchRel(pattern, 0, 0, END, 1);
    return 1;
}
Example #3
0
void readPecStitches(EmbPattern* pattern, EmbFile* file)
{
    int stitchNumber = 0;

    if(!pattern) { embLog_error("format-pec.c readPecStitches(), pattern argument is null\n"); return; }
    if(!file) { embLog_error("format-pec.c readPecStitches(), file argument is null\n"); return; }

    while(!embFile_eof(file))
    {
        int val1 = (int)binaryReadUInt8(file);
        int val2 = (int)binaryReadUInt8(file);

        int stitchType = NORMAL;
        if(val1 == 0xFF && val2 == 0x00)
        {
            embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1);
            break;
        }
        if(val1 == 0xFE && val2 == 0xB0)
        {
            (void)binaryReadByte(file);
            embPattern_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 = binaryReadUInt8(file);
        }
        else if(val1 >= 0x40)
        {
            val1 -= 0x80;
        }
        if(val2 & 0x80)
        {
            if(val2 & 0x20) stitchType = TRIM;
            if(val2 & 0x10) stitchType = JUMP;
            val2 = ((val2 & 0x0F) << 8) + binaryReadUInt8(file);

            /* Signed 12-bit arithmetic */
            if(val2 & 0x800)
            {
                val2 -= 0x1000;
            }
        }
        else if(val2 >= 0x40)
        {
            val2 -= 0x80;
        }
        embPattern_addStitchRel(pattern, val1 / 10.0, val2 / 10.0, stitchType, 1);
        stitchNumber++;
    }
}
Example #4
0
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
 *  Returns \c true if successful, otherwise returns \c false. */
int readEmd(EmbPattern* pattern, const char* fileName)
{
    unsigned char b0 = 0, b1 = 0;
    char dx = 0, dy = 0;
    int flags = NORMAL;
    char endOfStream = 0;
    unsigned char jemd0[6];
    int width, height, colors;
    int i;
    FILE* file = 0;

    if(!pattern) { embLog_error("format-emd.c readEmd(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-emd.c readEmd(), fileName argument is null\n"); return 0; }

    file = fopen(fileName, "rb");
    if(!file)
    {
        embLog_error("format-emd.c readEmd(), cannot open %s for reading\n", fileName);
        return 0;
    }

    embPattern_loadExternalColorFile(pattern, fileName);

    binaryReadBytes(file, jemd0, 6);
    width = binaryReadInt16(file);
    height = binaryReadInt16(file);
    colors = binaryReadInt16(file);

    fseek(file, 0x30, SEEK_SET);

    for(i = 0; !endOfStream; i++)
    {
            flags = NORMAL;
            b0 = binaryReadUInt8(file);
            b1 = binaryReadUInt8(file);

            if(b0 == 0x80)
            {
                if(b1 == 0x2A)
                {
                    embPattern_addStitchRel(pattern, 0, 0, STOP, 1);
                    continue;
                }
                else if((b1 == 0x80))
                {
                    b0 = binaryReadUInt8(file);
                    b1 = binaryReadUInt8(file);
                    flags = TRIM;
                }
                else if(b1 == 0xFD)
                {
                    embPattern_addStitchRel(pattern, 0, 0, END, 1);
                    break;
                }
                else
                {
                    continue;
                }
            }
            dx = emdDecode(b0);
            dy = emdDecode(b1);
            embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1);
    }
    embPattern_addStitchRel(pattern, 0, 0, END, 1);
    fclose(file);
    return 1;
}
Example #5
0
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
 *  Returns \c true if successful, otherwise returns \c false. */
int readEmd(EmbPattern* pattern, const char* fileName)
{
    unsigned char b0 = 0, b1 = 0;
    char dx = 0, dy = 0;
    int flags = EM_NORMAL;
    char endOfStream = 0;
    unsigned char jemd0[6]; /* TODO: more descriptive name */
    int width, height, colors;
    int i;
    EmbFile* file = 0;

    if(!pattern) { embLog_error("format-emd.c readEmd(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-emd.c readEmd(), fileName argument is null\n"); return 0; }

    file = embFile_open(fileName, "rb");
    if(!file)
    {
        embLog_error("format-emd.c readEmd(), cannot open %s for reading\n", fileName);
        return 0;
    }

    embPattern_loadExternalColorFile(pattern, fileName);

    binaryReadBytes(file, jemd0, 6); /* TODO: check return value */
    width = binaryReadInt16(file);
    height = binaryReadInt16(file);
    colors = binaryReadInt16(file);

    embFile_seek(file, 0x30, SEEK_SET);

    for(i = 0; !endOfStream; i++)
    {
            flags = EM_NORMAL;
            b0 = binaryReadUInt8(file);
            b1 = binaryReadUInt8(file);

            if(b0 == 0x80)
            {
                if(b1 == 0x2A)
                {
                    embPattern_addStitchRel(pattern, 0, 0, STOP, 1);
                    continue;
                }
                else if(b1 == 0x80)
                {
                    b0 = binaryReadUInt8(file);
                    b1 = binaryReadUInt8(file);
                    flags = TRIM;
                }
                else if(b1 == 0xFD)
                {
                    embPattern_addStitchRel(pattern, 0, 0, END, 1);
                    break;
                }
                else
                {
                    continue;
                }
            }
            dx = emdDecode(b0);
            dy = emdDecode(b1);
            embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1);
    }
    embFile_close(file);

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
        embPattern_addStitchRel(pattern, 0, 0, END, 1);

    return 1;
}
Example #6
0
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
 *  Returns \c true if successful, otherwise returns \c false. */
int readStx(EmbPattern* pattern, const char* fileName)
{
    int i, threadCount;
    unsigned char* gif = 0;
    /* public Bitmap Image; */
    StxThread* stxThreads = 0;
    unsigned char headerBytes[7];
    char* header = 0;
    char filetype[4], version[5];
    int paletteLength, imageLength, something1, stitchDataOffset, something3, threadDescriptionOffset, stitchCount, left, right, colors;
    int val1, val2, val3, val4, val5, val6;

    int vala1, vala2, vala3, vala4, vala5, vala6;
    int bottom,top;
    EmbFile* file = 0;

    if(!pattern) { embLog_error("format-stx.c readStx(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-stx.c readStx(), fileName argument is null\n"); return 0; }

    file = embFile_open(fileName, "rb");
    if(!file)
    {
        embLog_error("format-stx.c readStx(), cannot open %s for reading\n", fileName);
        return 0;
    }

    binaryReadBytes(file, headerBytes, 7);
    header = (char*)headerBytes;

    memcpy(filetype, &header[0], 3);
    memcpy(version, &header[3], 4);
    filetype[3] = '\0';
    version[4] = '\0';
    binaryReadByte(file);
    paletteLength = binaryReadInt32(file);
    imageLength = binaryReadInt32(file);
    something1 = binaryReadInt32(file);
    stitchDataOffset = binaryReadInt32(file);
    something3 = binaryReadInt32(file);
    threadDescriptionOffset = binaryReadInt32(file);
    stitchCount = binaryReadInt32(file);
    colors = binaryReadInt32(file);
    right = binaryReadInt16(file);
    left = binaryReadInt16(file);
    bottom = binaryReadInt16(file);
    top = binaryReadInt16(file);

    gif = (unsigned char*)malloc(imageLength);
    if(!gif) { embLog_error("format-stx.c readStx(), unable to allocate memory for gif\n"); return 0; }
    binaryReadBytes(file, gif, imageLength);
    /*Stream s2 = new MemoryStream(gif); */
    /*Image = new Bitmap(s2); */

    threadCount = binaryReadInt16(file);
    stxThreads = (StxThread*)malloc(sizeof(StxThread) * threadCount);
    if(!stxThreads) { embLog_error("format-stx.c readStx(), unable to allocate memory for stxThreads\n"); return 0; }
    for(i = 0; i < threadCount; i++)
    {
        EmbThread t;
        StxThread st;
        stxReadThread(&st, file);

        t.color.r = st.StxColor.r;
        t.color.g = st.StxColor.g;
        t.color.b = st.StxColor.b;
        t.description = st.ColorName;
        t.catalogNumber = st.ColorCode;
        embPattern_addThread(pattern, t);
        stxThreads[i] = st;
    }

    binaryReadInt32(file);
    binaryReadInt32(file);
    binaryReadInt32(file);
    binaryReadInt16(file);
    binaryReadUInt8(file);

    val1 = binaryReadInt16(file);
    val2 = binaryReadInt16(file);
    val3 = binaryReadInt16(file);
    val4 = binaryReadInt16(file);

    val5 = binaryReadInt16(file); /* 0 */
    val6 = binaryReadInt16(file); /* 0 */

    vala1 = binaryReadInt16(file);
    vala2 = binaryReadInt16(file);
    vala3 = binaryReadInt16(file);
    vala4 = binaryReadInt16(file);
    vala5 = binaryReadInt16(file); /* 0 */
    vala6 = binaryReadInt16(file); /* 0 */

    binaryReadInt32(file); /* 0 */
    binaryReadInt32(file); /* 0 */

    /* br.BaseStream.Position = stitchDataOffset; */
    for(i = 1; i < stitchCount; )
    {
        char b0 = binaryReadByte(file);
        char b1 = binaryReadByte(file);
        if(b0 == -128)
        {
            switch (b1)
            {
                case 1:
                    b0 = binaryReadByte(file);
                    b1 = binaryReadByte(file);
                    /*embPattern_addStitchRel(b0, b1, STOP);*/

                    i++;
                    break;
                case 2:
                    b0 = binaryReadByte(file);
                    b1 = binaryReadByte(file);
                    embPattern_addStitchRel(pattern, b0 / 10.0, b1 / 10.0, JUMP, 1);
                    i++;
                    break;
                case -94:
                    /* NOTE: Is this a syncronize */
                    break;
                default:
                    /*Debugger.Break(); */
                    break;
            }
        }
        else
        {
            embPattern_addStitchRel(pattern, b0 / 10.0, b1 / 10.0, NORMAL, 1);
            i++;
        }
    }
    embFile_close(file);

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
        embPattern_addStitchRel(pattern, 0, 0, END, 1);

    embPattern_flipVertical(pattern);
    return 1;
}
Example #7
0
static int stxReadThread(StxThread* thread, EmbFile* file)
{
    /* TODO: pointer safety */
    int j, colorNameLength, sectionNameLength;
    int somethingsomething, somethingsomething2, somethingelse, numberOfOtherDescriptors;
    char* codeNameBuff = 0;
    char* sectionNameBuff = 0;
    EmbColor col;
    unsigned char whatIsthis;

    int codeLength = binaryReadUInt8(file);
    char* codeBuff = (char*)malloc(codeLength);
    if(!codeBuff) { embLog_error("format-stx.c stxReadThread(), unable to allocate memory for codeBuff\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)codeBuff, codeLength);
    thread->ColorCode = codeBuff;
    colorNameLength = binaryReadUInt8(file);
    codeNameBuff = (char*)malloc(colorNameLength);
    if(!codeNameBuff) { embLog_error("format-stx.c stxReadThread(), unable to allocate memory for codeNameBuff\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)codeNameBuff, colorNameLength);
    thread->ColorName = codeNameBuff;

    col.r = binaryReadUInt8(file);
    col.b = binaryReadUInt8(file);
    col.g = binaryReadUInt8(file);

    whatIsthis = binaryReadUInt8(file);

    sectionNameLength = binaryReadUInt8(file);
    sectionNameBuff = (char*)malloc(sectionNameLength);
    if(!sectionNameBuff) { embLog_error("format-stx.c stxReadThread(), unable to allocate memory for sectionNameBuff\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)sectionNameBuff, sectionNameLength);
    thread->SectionName = sectionNameBuff;

    somethingsomething = binaryReadInt32(file);
    somethingsomething2 = binaryReadInt32(file);
    somethingelse = binaryReadInt32(file);
    numberOfOtherDescriptors = binaryReadInt16(file);

    thread->SubDescriptors = (SubDescriptor*)malloc(sizeof(SubDescriptor) * numberOfOtherDescriptors);
    if(!thread->SubDescriptors) return 0;
    for(j = 0; j < numberOfOtherDescriptors; j++)
    {
        SubDescriptor sd;
        char* subCodeBuff, *subColorNameBuff;
        int subcodeLength, subcolorNameLength;

        sd.SomeNum = binaryReadInt16(file);
        /* Debug.Assert(sd.SomeNum == 1); */
        sd.SomeInt = binaryReadInt32(file);
        subcodeLength = binaryReadUInt8(file);
        subCodeBuff = (char*)malloc(subcodeLength);
        if(!subCodeBuff) { embLog_error("format-stx.c stxReadThread(), unable to allocate memory for subCodeBuff\n"); return 0; }
        binaryReadBytes(file, (unsigned char*)subCodeBuff, subcodeLength);
        sd.ColorCode = subCodeBuff;
        subcolorNameLength = binaryReadUInt8(file);
        subColorNameBuff = (char*)malloc(subcolorNameLength);
        if(!subColorNameBuff) { embLog_error("format-stx.c stxReadThread(), unable to allocate memory for subColorNameBuff\n"); return 0; }
        binaryReadBytes(file, (unsigned char*)subColorNameBuff, subcolorNameLength);
        sd.ColorName = subColorNameBuff;
        sd.SomeOtherInt = binaryReadInt32(file);
        thread->SubDescriptors[j] = sd;
    }
    return 1;
}
Example #8
0
int readShv(EmbPattern* pattern, const char* fileName)
{
    int i;
    char inJump = 0;
    unsigned char fileNameLength, designWidth, designHeight;
    char halfDesignWidth, halfDesignHeight, halfDesignWidth2, halfDesignHeight2;
    char* headerText = "Embroidery disk created using software licensed from Viking Sewing Machines AB, Sweden";
    char dx = 0, dy = 0;
    char numberOfColors;
    unsigned short magicCode;
    int something;
    short left,top,right,bottom;

    char something2, numberOfSections, something3;
    FILE* file = 0;

    file = fopen(fileName, "rb");
    if(!file)
    {
        return 0;
    }

    fseek(file, strlen(headerText), SEEK_SET);
    fileNameLength = binaryReadUInt8(file);
    fseek(file, fileNameLength, SEEK_CUR);
    designWidth = binaryReadUInt8(file);
    designHeight = binaryReadUInt8(file);
    halfDesignWidth = binaryReadUInt8(file);
    halfDesignHeight = binaryReadUInt8(file);
    halfDesignWidth2 = binaryReadUInt8(file);
    halfDesignHeight2 = binaryReadUInt8(file);
    if((designHeight % 2) == 1)
        fseek(file, ((designHeight + 1)*designWidth)/2, SEEK_CUR);
    else
        fseek(file, (designHeight*designWidth)/2, SEEK_CUR);

    numberOfColors = binaryReadUInt8(file);
    magicCode = binaryReadUInt16(file);
    binaryReadByte(file);
    something = binaryReadInt32(file);
    left = binaryReadInt16(file);
    top = binaryReadInt16(file);
    right = binaryReadInt16(file);
    bottom = binaryReadInt16(file);

    something2 = binaryReadByte(file);
    numberOfSections = binaryReadUInt8(file);
    something3 = binaryReadByte(file);

    for(i = 0; i < numberOfColors; i++)
    {
        unsigned char colorNumber;
        binaryReadUInt16(file);
        binaryReadUInt16(file);
        colorNumber = binaryReadUInt8(file);
        embPattern_addThread(pattern, jefThreads[colorNumber]);
        fseek(file, 9, SEEK_CUR);
    }

    fseek(file, -2, SEEK_CUR);
    for(i = 0; !feof(file); i++)
    {
        unsigned char b0, b1;
        int flags;
        if(inJump)
            flags = JUMP;
        else
            flags = NORMAL;

        b0 = binaryReadUInt8(file);
        b1 = binaryReadUInt8(file);
        if(b0 == 0 && b1 == 0 && i > 0) flags = STOP;
        if(b0 == 0x80)
        {
            if(b1 == 3)
            {
                /*embPattern_addStitchRel(pattern, 0, 0, STOP); TODO: review this */
                continue;
            }
            else if(b1 == 0x02)
            {
                inJump = 0;
                continue;
            }
            else if(b1 == 0x01)
            {
                unsigned short sx, sy;
                sx = binaryReadUInt8(file);
                sx = (unsigned short)(sx << 8 | binaryReadUInt8(file));
                sy = binaryReadUInt8(file);
                sy = (unsigned short)(sy << 8 | binaryReadUInt8(file));
                flags = TRIM;
                inJump = 1;
                embPattern_addStitchRel(pattern, shvDecodeShort(sx) / 10.0, shvDecodeShort(sy) / 10.0, flags, 1);
                continue;
            }
        }
        dx = shvDecode(b0);
        dy = shvDecode(b1);
        embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1);
    }
    embPattern_addStitchRel(pattern, 0, 0, END, 1);
    embPattern_flipVertical(pattern);

    fclose(file);
    return 1;
}
Example #9
0
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
 *  Returns \c true if successful, otherwise returns \c false. */
int readU00(EmbPattern* pattern, const char* fileName)
{
    int i;
    char dx = 0, dy = 0;
    int flags = NORMAL;
    char endOfStream = 0;
    EmbFile* file = 0;

    if(!pattern) { embLog_error("format-u00.c readU00(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-u00.c readU00(), fileName argument is null\n"); return 0; }

    file = embFile_open(fileName, "rb");
    if(!file)
    {
        embLog_error("format-u00.c readU00(), cannot open %s for reading\n", fileName);
        return 0;
    }

    /* 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++)
    {
        EmbThread t;
        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);
    }
    embFile_close(file);

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
        embPattern_addStitchRel(pattern, 0, 0, END, 1);

    return 1;
}
/*! Reads a file with the given \a fileName and loads the data into \a pattern.
 *  Returns \c true if successful, otherwise returns \c false. */
int readZsk(EmbPattern* pattern, const char* fileName)
{
    char b[3];
    EmbFile* file = 0;
    int stitchType;
    unsigned char colorNumber;
    if(!pattern) { embLog_error("format-zsk.c readZsk(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-zsk.c readZsk(), fileName argument is null\n"); return 0; }

    file = embFile_open(fileName, "rb");
    if(!file)
    {
        embLog_error("format-zsk.c readZsk(), cannot open %s for reading\n", fileName);
        return 0;
    }

    embFile_seek(file, 0x230, SEEK_SET);
    colorNumber = binaryReadUInt8(file);
    while(colorNumber != 0)
    {
        EmbThread t;
        t.color.r = binaryReadUInt8(file);
        t.color.g = binaryReadUInt8(file);
        t.color.b = binaryReadUInt8(file);
        t.catalogNumber = "";
        t.description = "";
        embPattern_addThread(pattern, t);
        embFile_seek(file, 0x48, SEEK_CUR);
        colorNumber = binaryReadUInt8(file);
    }
    embFile_seek(file, 0x2E, SEEK_CUR);

    while(embFile_read(b, 1, 3, file) == 3)
    {
        stitchType = NORMAL;
		if (b[0] & 0x4)
		{
			b[2] = -b[2];
		}
		if (b[0] & 0x8)
		{
			b[1] = -b[1];
		}
		if (b[0] & 0x02)
		{
			stitchType = JUMP;
		}
        if(b[0] & 0x20)
        {
			if (b[1] == 2)
			{
				stitchType = TRIM;
			}
			else if (b[1] == -1)
			{
				break;
			}
            else
            {
				if (b[2] != 0)
				{
					colorNumber = b[2];
				}
                stitchType = STOP; /* TODO: need to determine what b[1] is used for.*/
                embPattern_changeColor(pattern, colorNumber - 1);
            }
            b[1] = 0;
            b[2] = 0;
        }
        embPattern_addStitchRel(pattern, b[1] / 10.0, b[2] / 10.0, stitchType, 0);
    }
    embFile_close(file);

    /* Check for an END stitch and add one if it is not present */
	if (pattern->lastStitch->stitch.flags != END)
	{
		embPattern_addStitchRel(pattern, 0, 0, END, 1);
	}
    return 1;
}