Beispiel #1
0
static void ofmReadThreads(EmbFile* file, EmbPattern* p)
{
    int i, numberOfColors, stringLen, numberOfLibraries;
    char* primaryLibraryName = 0;
    char* expandedString = 0;

    if(!file) { embLog_error("format-ofm.c ofmReadThreads(), file argument is null\n"); return; }
    if(!p) { embLog_error("format-ofm.c ofmReadThreads(), p argument is null\n"); return; }

    /* FF FE FF 00 */
    binaryReadInt32(file);

    numberOfColors = binaryReadInt16(file);

    binaryReadInt16(file);
    binaryReadInt16(file);
    stringLen = binaryReadInt16(file);
    expandedString = (char*)malloc(stringLen);
    if(!expandedString) { embLog_error("format-ofm.c ofmReadThreads(), unable to allocate memory for expandedString\n"); return; }
    binaryReadBytes(file, (unsigned char*)expandedString, stringLen); /* TODO: check return value */
    for(i = 0; i < numberOfColors; i++)
    {
        EmbThread thread;
        char colorNumberText[10];
        int threadLibrary = 0, colorNameLength, colorNumber;
        char* colorName = 0;
        int r = binaryReadByte(file);
        int g = binaryReadByte(file);
        int b = binaryReadByte(file);
        binaryReadByte(file);
        threadLibrary = binaryReadInt16(file);
        binaryReadInt16(file);
        colorNumber = binaryReadInt32(file);
        binaryReadByte(file);
        binaryReadInt16(file);
        colorNameLength = binaryReadByte(file);
        colorName = (char*)malloc(colorNameLength * 2);
        if(!colorName) { embLog_error("format-ofm.c ofmReadThreads(), unable to allocate memory for colorName\n"); return; }
        binaryReadBytes(file, (unsigned char*)colorName, colorNameLength*2); /* TODO: check return value */
        binaryReadInt16(file);
     /* itoa(colorNumber, colorNumberText, 10); TODO: never use itoa, it's non-standard, use sprintf: http://stackoverflow.com/questions/5242524/converting-int-to-string-in-c */
        thread.color.r = (unsigned char)r;
        thread.color.g = (unsigned char)g;
        thread.color.b = (unsigned char)b;
        thread.catalogNumber = colorNumberText;
        thread.description = colorName;
        embPattern_addThread(p, thread);
    }
    binaryReadInt16(file);
    primaryLibraryName = ofmReadLibrary(file);
    numberOfLibraries = binaryReadInt16(file);
    for(i = 0; i < numberOfLibraries; i++)
    {
        /*libraries.Add( TODO: review */
        char* libName = ofmReadLibrary(file);
        free(libName);
        libName = 0;
    }
}
Beispiel #2
0
static char* ofmReadLibrary(FILE* file)
{
    int stringLength = 0;
    char* libraryName = 0;
    /* FF FE FF */
    unsigned char leadin[3];
    binaryReadBytes(file, leadin, 3);
    stringLength = binaryReadByte(file);
    libraryName = (char*)malloc(sizeof(char) * stringLength * 2);
    if(!libraryName) { embLog_error("format-ofm.c ofmReadLibrary(), unable to allocate memory for libraryName\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)libraryName, stringLength * 2);
    return libraryName;
}
Beispiel #3
0
static char* ofmReadLibrary(EmbFile* file)
{
    int stringLength = 0;
    char* libraryName = 0;
    /* FF FE FF */
    unsigned char leadIn[3];

    if(!file) { embLog_error("format-ofm.c ofmReadLibrary(), file argument is null\n"); return 0; }

    binaryReadBytes(file, leadIn, 3); /* TODO: check return value */
    stringLength = binaryReadByte(file);
    libraryName = (char*)malloc(sizeof(char) * stringLength * 2);
    if(!libraryName) { embLog_error("format-ofm.c ofmReadLibrary(), unable to allocate memory for libraryName\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)libraryName, stringLength * 2); /* TODO: check return value */
    return libraryName;
}
Beispiel #4
0
static void ofmReadBlockHeader(EmbFile* file)
{
    int val1, val2, val3, val4, val5, val6, val7, val8, val9, val10; /* TODO: determine what these represent */
    unsigned char len;
    char* s = 0;
    unsigned short short1;
    short unknown1 = 0; /* TODO: determine what this represents */
    short unknown2 = 0; /* TODO: determine what this represents */
    int unknown3 = 0;   /* TODO: determine what this represents */

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

    unknown1 = binaryReadInt16(file);
    unknown2 = (short)binaryReadInt32(file);
    unknown3 = binaryReadInt32(file);

    /* int v = binaryReadBytes(3); TODO: review */
    binaryReadInt16(file);
    binaryReadByte(file);
    len = binaryReadByte(file);
    s = (char*)malloc(2 * len);
    if(!s) { embLog_error("format-ofm.c ofmReadBlockHeader(), unable to allocate memory for s\n"); return; }
    binaryReadBytes(file, (unsigned char *)s, 2 * len); /* TODO: check return value */
    val1 = binaryReadInt32(file);   /*  0 */
    val2 = binaryReadInt32(file);   /*  0 */
    val3 = binaryReadInt32(file);   /*  0 */
    val4 = binaryReadInt32(file);   /*  0 */
    val5 = binaryReadInt32(file);   /*  1 */
    val6 = binaryReadInt32(file);   /*  1 */
    val7 = binaryReadInt32(file);   /*  1 */
    val8 = binaryReadInt32(file);   /*  0 */
    val9 = binaryReadInt32(file);   /* 64 */
    val10 = binaryReadInt32(file);  /* 64 */
    short1 = binaryReadInt16(file); /*  0 */
}
Beispiel #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 readOfm(EmbPattern* pattern, const char* fileName)
{
    int unknownCount = 0;
    int key = 0, classNameLength;
    char* s = 0;
    FILE* fileCompound = 0;
    FILE* file = 0;
    bcf_file* bcfFile = 0;

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

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

    bcfFile = (bcf_file*)malloc(sizeof(bcf_file));
    if(!bcfFile) { embLog_error("format-ofm.c readOfm(), unable to allocate memory for bcfFile\n"); return 0; }
    bcfFile_read(fileCompound, bcfFile);
    file = GetFile(bcfFile, fileCompound, "EdsIV Object");
    bcf_file_free(bcfFile);
    bcfFile = 0;
    fseek(file, 0x1C6, SEEK_SET);
    ofmReadThreads(file, pattern);
    fseek(file, 0x110, SEEK_CUR);
    binaryReadInt32(file);
    classNameLength = binaryReadInt16(file);
    s = (char*)malloc(sizeof(char) * classNameLength);
    if(!s) { embLog_error("format-ofm.c readOfm(), unable to allocate memory for s\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)s, classNameLength);
    unknownCount = binaryReadInt16(file); /* unknown count */

    binaryReadInt16(file);
    key = ofmReadClass(file);
    while(1)
    {
        if(key == 0xFEFF)
        {
            break;
        }
        if(key == 0x809C)
        {
            ofmReadExpanded(file, pattern);
        }
        else
        {
            ofmReadColorChange(file, pattern);
        }
        key = binaryReadUInt16(file);
        if(key == 0xFFFF)
        {
            ofmReadClass(file);
        }
    }
    embPattern_addStitchRel(pattern, 0.0, 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 readMit(EmbPattern* pattern, const char* fileName)
{
    unsigned char data[2];
    EmbFile* file = 0;

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

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

    /* embPattern_loadExternalColorFile(pattern, fileName); TODO: review this and uncomment or remove it */

    while(binaryReadBytes(file, data, 2) == 2)
    {
        embPattern_addStitchRel(pattern, mitDecodeStitch(data[0]) / 10.0, mitDecodeStitch(data[1]) / 10.0, NORMAL, 1);
    }

    embFile_close(file);

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

    return 1;
}
Beispiel #7
0
static void ofmReadBlockHeader(FILE* file)
{
    int val1, val2, val3, val4, val5, val6, val7, val8, val9, val10;
    unsigned char len;
    char* s = 0;
    unsigned short short1;
    short unknown1 = binaryReadInt16(file);
    short unknown2 = (short)binaryReadInt32(file);
    int unknown3 = binaryReadInt32(file);
    /* int v = binaryReadBytes(3); TODO: review */
    binaryReadInt16(file);
    binaryReadByte(file);
    len = binaryReadByte(file);
    s = (char*)malloc(2 * len);
    if(!s) { embLog_error("format-ofm.c ofmReadBlockHeader(), unable to allocate memory for s\n"); return; }
    binaryReadBytes(file, (unsigned char *)s, 2 * len);
    val1 = binaryReadInt32(file);   /*  0 */
    val2 = binaryReadInt32(file);   /*  0 */
    val3 = binaryReadInt32(file);   /*  0 */
    val4 = binaryReadInt32(file);   /*  0 */
    val5 = binaryReadInt32(file);   /*  1 */
    val6 = binaryReadInt32(file);   /*  1 */
    val7 = binaryReadInt32(file);   /*  1 */
    val8 = binaryReadInt32(file);   /*  0 */
    val9 = binaryReadInt32(file);   /* 64 */
    val10 = binaryReadInt32(file);  /* 64 */
    short1 = binaryReadInt16(file); /*  0 */
}
static unsigned char* ReadString(FILE* file)
{
    int stringLength = binaryReadInt16BE(file);
    unsigned char* charString = (unsigned char*)malloc(stringLength);
    /* TODO: malloc fail error */
    binaryReadBytes(file, charString, stringLength);
    return charString;
}
Beispiel #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 readNew(EmbPattern* pattern, const char* fileName)
{
    unsigned int stitchCount;
    unsigned char data[3];
    FILE* file = 0;

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

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

    embPattern_loadExternalColorFile(pattern, fileName);
    stitchCount = binaryReadUInt16(file);
    while(binaryReadBytes(file, data, 3) == 3)
    {
        int x = decodeNewStitch(data[0]);
        int y = decodeNewStitch(data[1]);
        int flag = NORMAL;
        char val = data[2];
        if(data[2] & 0x40)
        {
            x = -x;
        }
        if(data[2] & 0x20)
        {
            y = -y;
        }
        if(data[2] & 0x10)
        {
            flag = TRIM;
        }
        if(data[2] & 0x01)
        {
            flag = JUMP;
        }
        if((val & 0x1E) == 0x02)
        {
            flag = STOP;
        }
        /* Unknown values, possibly TRIM
        155 = 1001 1011 = 0x9B
        145 = 1001 0001 = 0x91
        */
        /*val = (data[2] & 0x1C);
        if(val != 0 && data[2] != 0x9B && data[2] != 0x91)
        {
            int z = 1;
        }*/
        embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, flag, 1);
    }
    embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1);
    return 1;
}
Beispiel #10
0
static unsigned char* vp3ReadString(EmbFile* file)
{
    int stringLength = 0;
    unsigned char* charString = 0;
    if(!file) { embLog_error("format-vp3.c vp3ReadString(), file argument is null\n"); return 0; }
    stringLength = binaryReadInt16BE(file);
    charString = (unsigned char*)malloc(stringLength);
    if(!charString) { embLog_error("format-vp3.c vp3ReadString(), cannot allocate memory for charString\n"); return 0; }
    binaryReadBytes(file, charString, stringLength); /* TODO: check return value */
    return charString;
}
Beispiel #11
0
static int ofmReadClass(FILE* file)
{
    int len;
    char* s = 0;
    binaryReadInt16(file);
    len = binaryReadInt16(file);

    s = (char*)malloc(sizeof(char) * len + 1);
    if(!s) { embLog_error("format-ofm.c ofmReadClass(), unable to allocate memory for s\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)s, len);
    s[len] = '\0';
    if(strcmp(s, "CExpStitch") == 0)
            return 0x809C;
    if(strcmp(s, "CColorChange") == 0)
            return 0xFFFF;
    return 0;
}
Beispiel #12
0
static void ofmReadExpanded(FILE* file, EmbPattern* p)
{
    int i, numberOfStitches = 0;

    ofmReadBlockHeader(file);
    numberOfStitches = binaryReadInt32(file);

    for(i = 0; i < numberOfStitches; i++)
    {
        unsigned char stitch[5];
        binaryReadBytes(file, stitch, 5);
        if(stitch[0] == 0)
        {
            embPattern_addStitchAbs(p, ofmDecode(stitch[1], stitch[2]) / 10.0, ofmDecode(stitch[3], stitch[4]) / 10.0, i == 0 ? JUMP : NORMAL, 1);
        }
    }
}
Beispiel #13
0
int readMit(EmbPattern* pattern, const char* fileName)
{
    unsigned char data[2];
    FILE* file = 0;

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

    while(binaryReadBytes(file, data, 2) == 2)
    {
        embPattern_addStitchRel(pattern, decodeMitStitch(data[0]) / 10.0, decodeMitStitch(data[1]) / 10.0, NORMAL, 1);
    }
    embPattern_addStitchRel(pattern, 0.0, 0.0, END, 1);
    return 1;
}
Beispiel #14
0
static void ofmReadExpanded(EmbFile* file, EmbPattern* p)
{
    int i, numberOfStitches = 0;

    if(!file) { embLog_error("format-ofm.c ofmReadExpanded(), file argument is null\n"); return; }
    if(!p) { embLog_error("format-ofm.c ofmReadExpanded(), p argument is null\n"); return; }

    ofmReadBlockHeader(file);
    numberOfStitches = binaryReadInt32(file);

    for(i = 0; i < numberOfStitches; i++)
    {
        unsigned char stitch[5];
        binaryReadBytes(file, stitch, 5); /* TODO: check return value */
        if(stitch[0] == 0)
        {
            embPattern_addStitchAbs(p, ofmDecode(stitch[1], stitch[2]) / 10.0, ofmDecode(stitch[3], stitch[4]) / 10.0, i == 0 ? JUMP : EM_NORMAL, 1);
        }
        else if(stitch[0] == 32)
        {
            embPattern_addStitchAbs(p, ofmDecode(stitch[1], stitch[2]) / 10.0, ofmDecode(stitch[3], stitch[4]) / 10.0, i == 0 ? TRIM : EM_NORMAL, 1);
        }
    }
}
Beispiel #15
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;
}
Beispiel #16
0
int readHus(EmbPattern* pattern, const char* fileName)
{
    int fileLength;
    int magicCode,numberOfStitches,numberOfColors;
    int postitiveXHoopSize,postitiveYHoopSize,negativeXHoopSize,negativeYHoopSize;

    int attributeOffset,xOffset,yOffset;
    unsigned char* attributeData = 0;
    unsigned char* attributeDataDecompressed = 0;

    unsigned char* xData = 0;
    unsigned char* xDecompressed = 0;

    unsigned char* yData = 0;
    unsigned char* yDecompressed = 0;
    unsigned char* stringVal = 0;
    int unknown, i = 0;
    FILE* file = 0;

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

    fseek(file, 0x00, SEEK_END);
    fileLength = ftell(file);
    fseek(file, 0x00, SEEK_SET);

    magicCode = binaryReadInt32(file);
    numberOfStitches = binaryReadInt32(file);
    numberOfColors = binaryReadInt32(file);

    postitiveXHoopSize = binaryReadInt16(file);
    postitiveYHoopSize = binaryReadInt16(file);
    negativeXHoopSize = binaryReadInt16(file);
    negativeYHoopSize = binaryReadInt16(file);

    attributeOffset = binaryReadInt32(file);
    xOffset = binaryReadInt32(file);
    yOffset = binaryReadInt32(file);

    stringVal = (unsigned char*)malloc(sizeof(unsigned char)*8);
    /* TODO: malloc fail error */
    binaryReadBytes(file, stringVal, 8);

    unknown = binaryReadInt16(file);
    for(i = 0; i < numberOfColors; i++)
    {
        int pos = binaryReadInt16(file);
        embPattern_addThread(pattern, husThreads[pos]);
    }

    attributeData = (unsigned char*)malloc(sizeof(unsigned char)*(xOffset - attributeOffset + 1));
    /* TODO: malloc fail error */
    binaryReadBytes(file, attributeData, xOffset - attributeOffset);
    attributeDataDecompressed = husDecompressData(attributeData, xOffset - attributeOffset, numberOfStitches + 1);

    xData = (unsigned char*)malloc(sizeof(unsigned char)*(yOffset - xOffset + 1));
    /* TODO: malloc fail error */
    binaryReadBytes(file, xData, yOffset - xOffset);
    xDecompressed = husDecompressData(xData, yOffset - xOffset, numberOfStitches);

    yData = (unsigned char*)malloc(sizeof(unsigned char)*(fileLength - yOffset + 1));
    /* TODO: malloc fail error */
    binaryReadBytes(file, yData, fileLength - yOffset);
    yDecompressed = husDecompressData(yData, fileLength - yOffset, numberOfStitches);

    for(i = 0; i < numberOfStitches; i++)
    {
        embPattern_addStitchRel(pattern, husDecodeByte(xDecompressed[i]) / 10.0,
                                husDecodeByte(yDecompressed[i]) / 10.0,
                                husDecodeStitchType(attributeDataDecompressed[i]), 1);
    }
    embPattern_addStitchRel(pattern, 0, 0, END, 1);

    if(stringVal) free(stringVal);
    if(xData) free(xData);
    if(xDecompressed) free(xDecompressed);
    if(yData) free(yData);
    if(yDecompressed) free(yDecompressed);
    if(attributeData) free(attributeData);
    if(attributeDataDecompressed) free(attributeDataDecompressed);

	fclose(file);
    return 1;
}
Beispiel #17
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 readVp3(EmbPattern* pattern, const char* fileName)
{
    unsigned char magicString[5];
    unsigned char some;
    unsigned char* softwareVendorString = 0;
    unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18;
    unsigned char* anotherSoftwareVendorString = 0;
    int numberOfColors;
    long colorSectionOffset;
    unsigned char magicCode[6];
    short someShort;
    unsigned char someByte;
    int bytesRemainingInFile;
    unsigned char* fileCommentString = 0; /* some software writes used settings here */
    int hoopConfigurationOffset;
    unsigned char* anotherCommentString = 0;
    int i;
    EmbFile* file = 0;

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

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

    binaryReadBytes(file, magicString, 5); /* %vsm% */ /* TODO: check return value */

    some = binaryReadByte(file); /* 0 */
    softwareVendorString = vp3ReadString(file);
    someShort = binaryReadInt16(file);
    someByte = binaryReadByte(file);
    bytesRemainingInFile = binaryReadInt32(file);
    fileCommentString = vp3ReadString(file);
    hoopConfigurationOffset = (int)embFile_tell(file);

    vp3ReadHoopSection(file);

    anotherCommentString = vp3ReadString(file);

    /* TODO: review v1 thru v18 variables and use emb_unused() if needed */
    v1 = binaryReadByte(file);
    v2 = binaryReadByte(file);
    v3 = binaryReadByte(file);
    v4 = binaryReadByte(file);
    v5 = binaryReadByte(file);
    v6 = binaryReadByte(file);
    v7 = binaryReadByte(file);
    v8 = binaryReadByte(file);
    v9 = binaryReadByte(file);
    v10 = binaryReadByte(file);
    v11 = binaryReadByte(file);
    v12 = binaryReadByte(file);
    v13 = binaryReadByte(file);
    v14 = binaryReadByte(file);
    v15 = binaryReadByte(file);
    v16 = binaryReadByte(file);
    v17 = binaryReadByte(file);
    v18 = binaryReadByte(file);

    binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */ /* TODO: check return value */

    anotherSoftwareVendorString = vp3ReadString(file);

    numberOfColors = binaryReadInt16BE(file);
    embLog_error("format-vp3.c Number of Colors: %d\n", numberOfColors);
    colorSectionOffset = (int)embFile_tell(file);

    for(i = 0; i < numberOfColors; i++)
    {
        EmbThread t;
        char tableSize;
        int startX, startY, offsetToNextColorX, offsetToNextColorY;
        unsigned char* threadColorNumber, *colorName, *threadVendor;
        int unknownThreadString, numberOfBytesInColor;

        embFile_seek(file, colorSectionOffset, SEEK_SET);
        embLog_error("format-vp3.c Color Check Byte #1: 0 == %d\n", binaryReadByte(file));
        embLog_error("format-vp3.c Color Check Byte #2: 5 == %d\n", binaryReadByte(file));
        embLog_error("format-vp3.c Color Check Byte #3: 0 == %d\n", binaryReadByte(file));
        colorSectionOffset = binaryReadInt32BE(file);
        colorSectionOffset += embFile_tell(file);
        startX = binaryReadInt32BE(file);
        startY = binaryReadInt32BE(file);
        embPattern_addStitchAbs(pattern, startX / 1000, -startY / 1000, JUMP, 0);

        tableSize = binaryReadByte(file);
        binaryReadByte(file);
        t.color.r = binaryReadByte(file);
        t.color.g = binaryReadByte(file);
        t.color.b = binaryReadByte(file);
        embPattern_addThread(pattern, t);
        embFile_seek(file, 6*tableSize - 1, SEEK_CUR);

        threadColorNumber = vp3ReadString(file);
        colorName = vp3ReadString(file);
        threadVendor = vp3ReadString(file);

        offsetToNextColorX = binaryReadInt32BE(file);
        offsetToNextColorY = binaryReadInt32BE(file);

        unknownThreadString = binaryReadInt16BE(file);
        embFile_seek(file, unknownThreadString, SEEK_CUR);
        numberOfBytesInColor = binaryReadInt32BE(file);
        embFile_seek(file, 0x3, SEEK_CUR);
        while(embFile_tell(file) < colorSectionOffset - 1)
        {
            int lastFilePosition = embFile_tell(file);

            int x = vp3Decode(binaryReadByte(file));
            int y = vp3Decode(binaryReadByte(file));
            if(x == 0x80)
            {
                switch (y)
                {
                    case 0x00:
                    case 0x03:
                        break;
                    case 0x01:
                        x = vp3DecodeInt16(binaryReadInt16BE(file));
                        y = vp3DecodeInt16(binaryReadInt16BE(file));
                        binaryReadInt16BE(file);
                        embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1);
            }

            if(embFile_tell(file) == lastFilePosition)
            {
                embLog_error("format-vp3.c could not read stitch block in entirety\n");
                return 0;
            }
        }
        if(i + 1 < numberOfColors)
            embPattern_addStitchRel(pattern, 0, 0, STOP, 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);

    embPattern_flipVertical(pattern);

    return 1;
}
Beispiel #18
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;
}
/*! 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 readVip(EmbPattern* pattern, const char* fileName)
{
    int fileLength;
    int i;
    unsigned char prevByte = 0;
    unsigned char *attributeData = 0, *decodedColors = 0, *attributeDataDecompressed = 0;
    unsigned char *xData = 0, *xDecompressed = 0, *yData = 0, *yDecompressed = 0;
    VipHeader header;
    EmbFile* file = 0;

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

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

    embFile_seek(file, 0x0, SEEK_END);
    fileLength = embFile_tell(file);
    embFile_seek(file, 0x00, SEEK_SET);
    header.magicCode = binaryReadInt32(file);
    header.numberOfStitches = binaryReadInt32(file);
    header.numberOfColors = binaryReadInt32(file);

    header.postitiveXHoopSize = binaryReadInt16(file);
    header.postitiveYHoopSize = binaryReadInt16(file);
    header.negativeXHoopSize = binaryReadInt16(file);
    header.negativeYHoopSize = binaryReadInt16(file);

    header.attributeOffset = binaryReadInt32(file);
    header.xOffset = binaryReadInt32(file);
    header.yOffset = binaryReadInt32(file);

    /*stringVal = (unsigned char*)malloc(sizeof(unsigned char)*8); TODO: review this and uncomment or remove
        if(!stringVal) { embLog_error("format-vip.c readVip(), cannot allocate memory for stringVal\n"); return 0; }
     */

    binaryReadBytes(file, header.stringVal, 8); /* TODO: check return value */

    header.unknown = binaryReadInt16(file);

    header.colorLength = binaryReadInt32(file);
    decodedColors = (unsigned char*)malloc(header.numberOfColors*4);
    if(!decodedColors) { embLog_error("format-vip.c readVip(), cannot allocate memory for decodedColors\n"); return 0; }
    for(i = 0; i < header.numberOfColors*4; ++i)
    {
        unsigned char inputByte = binaryReadByte(file);
        unsigned char tmpByte = (unsigned char) (inputByte ^ vipDecodingTable[i]);
        decodedColors[i] = (unsigned char) (tmpByte ^ prevByte);
        prevByte = inputByte;
    }
    for(i = 0; i < header.numberOfColors; i++)
    {
        EmbThread thread;
        int startIndex = i << 2;
        thread.color.r = decodedColors[startIndex];
        thread.color.g = decodedColors[startIndex + 1];
        thread.color.b = decodedColors[startIndex + 2];
        /* printf("%d\n", decodedColors[startIndex + 3]); */
        embPattern_addThread(pattern, thread);
    }
    embFile_seek(file, header.attributeOffset, SEEK_SET);
    attributeData = (unsigned char*)malloc(header.xOffset - header.attributeOffset);
    if(!attributeData) { embLog_error("format-vip.c readVip(), cannot allocate memory for attributeData\n"); return 0; }
    binaryReadBytes(file, attributeData, header.xOffset - header.attributeOffset); /* TODO: check return value */
    attributeDataDecompressed = vipDecompressData(attributeData, header.xOffset - header.attributeOffset, header.numberOfStitches);

    embFile_seek(file, header.xOffset, SEEK_SET);
    xData = (unsigned char*)malloc(header.yOffset - header.xOffset);
    if(!xData) { embLog_error("format-vip.c readVip(), cannot allocate memory for xData\n"); return 0; }
    binaryReadBytes(file, xData, header.yOffset - header.xOffset); /* TODO: check return value */
    xDecompressed = vipDecompressData(xData, header.yOffset - header.xOffset, header.numberOfStitches);

    embFile_seek(file, header.yOffset, SEEK_SET);
    yData = (unsigned char*)malloc(fileLength - header.yOffset);
    if(!yData) { embLog_error("format-vip.c readVip(), cannot allocate memory for yData\n"); return 0; }
    binaryReadBytes(file, yData, fileLength - header.yOffset); /* TODO: check return value */
    yDecompressed = vipDecompressData(yData, fileLength - header.yOffset, header.numberOfStitches);

    for(i = 0; i < header.numberOfStitches; i++)
    {
        embPattern_addStitchRel(pattern,
                                vipDecodeByte(xDecompressed[i]) / 10.0,
                                vipDecodeByte(yDecompressed[i]) / 10.0,
                                vipDecodeStitchType(attributeDataDecompressed[i]), 1);
    }
    embPattern_addStitchRel(pattern, 0, 0, END, 1);

    embFile_close(file);

    free(attributeData);             attributeData = 0;
    free(xData);                     xData = 0;
    free(yData);                     yData = 0;
    free(attributeDataDecompressed); attributeDataDecompressed = 0;
    free(xDecompressed);             xDecompressed = 0;
    free(yDecompressed);             yDecompressed = 0;

    return 1;
}
Beispiel #20
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;
}
Beispiel #21
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;
}
Beispiel #22
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 readJef(EmbPattern* pattern, const char* fileName)
{
    int stitchOffset, formatFlags, numberOfColors, numberOfStitchs;
    int hoopSize, i;
    struct hoop_padding bounds, rectFrom110x110, rectFrom50x50, rectFrom200x140, rect_from_custom;
    int stitchCount;
    char date[8], time[8];
    char dx, dy;
    FILE* file = 0;

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

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

    stitchOffset = binaryReadInt32(file);
    formatFlags = binaryReadInt32(file); /* TODO: find out what this means */

    binaryReadBytes(file, (unsigned char*) date, 8);
    binaryReadBytes(file, (unsigned char*) time, 8);
    numberOfColors = binaryReadInt32(file);
    numberOfStitchs = binaryReadInt32(file);
    hoopSize = binaryReadInt32(file);
    jefSetHoopFromId(pattern, hoopSize);

    bounds.left = binaryReadInt32(file);
    bounds.top = binaryReadInt32(file);
    bounds.right = binaryReadInt32(file);
    bounds.bottom = binaryReadInt32(file);

    rectFrom110x110.left = binaryReadInt32(file);
    rectFrom110x110.top = binaryReadInt32(file);
    rectFrom110x110.right = binaryReadInt32(file);
    rectFrom110x110.bottom = binaryReadInt32(file);

    rectFrom50x50.left = binaryReadInt32(file);
    rectFrom50x50.top = binaryReadInt32(file);
    rectFrom50x50.right = binaryReadInt32(file);
    rectFrom50x50.bottom = binaryReadInt32(file);

    rectFrom200x140.left = binaryReadInt32(file);
    rectFrom200x140.top = binaryReadInt32(file);
    rectFrom200x140.right = binaryReadInt32(file);
    rectFrom200x140.bottom = binaryReadInt32(file);

    rect_from_custom.left = binaryReadInt32(file);
    rect_from_custom.top = binaryReadInt32(file);
    rect_from_custom.right = binaryReadInt32(file);
    rect_from_custom.bottom = binaryReadInt32(file);

    for(i = 0; i < numberOfColors; i++)
    {
        embPattern_addThread(pattern, jefThreads[binaryReadInt32(file) % 79]);
    }
    fseek(file, stitchOffset, SEEK_SET);
    stitchCount = 0;
    while(stitchCount < numberOfStitchs + 100)
    {
        int flags = NORMAL;
        unsigned char b0 = binaryReadByte(file);
        unsigned char b1 = binaryReadByte(file);

        if(b0 == 0x80)
        {
            if(b1 & 0x01)
            {
                b0 = binaryReadByte(file);
                b1 = binaryReadByte(file);
                flags = STOP;
            }
            else if(b1 == 0x02 || b1 == 0x04)
            {
                b0 = binaryReadByte(file);
                b1 = binaryReadByte(file);
                flags = TRIM;
            }
            else if(b1 == 0x10)
            {
                embPattern_addStitchRel(pattern, 0, 0, END, 1);
                break;
            }
        }
        dx = (char)b0;
        dy = (char)b1;
        embPattern_addStitchRel(pattern, dx / 10.0, dy / 10.0, flags, 1);
        stitchCount++;
    }
    fclose(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;
}
Beispiel #23
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 readVp3(EmbPattern* pattern, const char* fileName)
{
    unsigned char magicString[5];
    unsigned char some;
    unsigned char* someString = 0;
    unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18;
    unsigned char* unknownString3 = 0;
    int numberOfColors;
    long colorSectionOffset;
    unsigned char magicCode[6];
    short someShort;
    unsigned char someByte;
    int bytesRemainingInFile;
    unsigned char* unknownByteString = 0;
    int hoopConfigurationOffset;
    unsigned char* unknownString2 = 0;
    int i;
    FILE* file = 0;

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

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

    binaryReadBytes(file, magicString, 5); /* %vsm% */

    some = binaryReadByte(file); /* 0 */
    someString = vp3ReadString(file);
    someShort = binaryReadInt16(file);
    someByte = binaryReadByte(file);
    bytesRemainingInFile = binaryReadInt32(file);
    unknownByteString = vp3ReadString(file);
    hoopConfigurationOffset =(int) ftell(file);

    vp3ReadHoopSection(file);

    unknownString2 = vp3ReadString(file);

    /* TODO: review v1 thru v18 variables and use emb_unused() if needed */
    v1 = binaryReadByte(file);
    v2 = binaryReadByte(file);
    v3 = binaryReadByte(file);
    v4 = binaryReadByte(file);
    v5 = binaryReadByte(file);
    v6 = binaryReadByte(file);
    v7 = binaryReadByte(file);
    v8 = binaryReadByte(file);
    v9 = binaryReadByte(file);
    v10 = binaryReadByte(file);
    v11 = binaryReadByte(file);
    v12 = binaryReadByte(file);
    v13 = binaryReadByte(file);
    v14 = binaryReadByte(file);
    v15 = binaryReadByte(file);
    v16 = binaryReadByte(file);
    v17 = binaryReadByte(file);
    v18 = binaryReadByte(file);

    binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */

    unknownString3 = vp3ReadString(file);

    numberOfColors = binaryReadInt16BE(file);
    colorSectionOffset = (int) ftell(file);

    for(i = 0; i < numberOfColors; i++)
    {
        EmbThread t;
        char tableSize;
        int unknownX, unknownY, unknownX2, unknownY2;
        unsigned char* str1, *str2, *str3;
        int unknownThreadString, numberOfBytesInColor;

        fseek(file, 0x03 + colorSectionOffset, SEEK_SET);
        colorSectionOffset = binaryReadInt32BE(file);
        colorSectionOffset += ftell(file);
        unknownX = binaryReadInt32BE(file);
        unknownY = binaryReadInt32BE(file);
        /* TODO: review commented section below
        pattern.embPattern_addStitchAbsolute(-unknownX / 100, -unknownY/ 100, StitchType.Jump, false);
        fs.Seek(0x08, SeekOrigin.Current);
        */
        tableSize = binaryReadByte(file);
        binaryReadByte(file);
        t.color.r = binaryReadByte(file);
        t.color.g = binaryReadByte(file);
        t.color.b = binaryReadByte(file);
        embPattern_addThread(pattern, t);
        fseek(file, 6*tableSize - 1, SEEK_CUR);

        str1 = vp3ReadString(file);
        str2 = vp3ReadString(file);
        str3 = vp3ReadString(file);

        unknownX2 = binaryReadInt32BE(file);
        unknownY2 = binaryReadInt32BE(file);
        /*fs.Seek(0x02, SeekOrigin.Current); */
        unknownThreadString = binaryReadInt16BE(file);
        fseek(file, unknownThreadString, SEEK_CUR);
        numberOfBytesInColor = binaryReadInt32BE(file);
        fseek(file, 0x3, SEEK_CUR);
        while(ftell(file) < colorSectionOffset - 1)
        {
            int x = vp3Decode(binaryReadByte(file));
            int y = vp3Decode(binaryReadByte(file));
            if(x == 0x80)
            {
                switch (y)
                {
                    case 0x00:
                    case 0x03:
                        break;
                    case 0x01:
                        x = vp3DecodeInt16(binaryReadInt16BE(file));
                        y = vp3DecodeInt16(binaryReadInt16BE(file));
                        binaryReadInt16BE(file);
                        embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1);
            }
        }
        if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1);
    }
    fclose(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;
}
Beispiel #24
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 readInb(EmbPattern* pattern, const char* fileName)
{
    EmbFile* file = 0;
    unsigned char fileDescription[8];
    unsigned char nullVal;
    int stitchCount;
    short width;
    short height;
    short colorCount;
    short unknown3;
    short unknown2;
    short imageWidth;
    short imageHeight;
    unsigned char bytesUnknown[300];
    short nullbyte;
    short left;
    short right;
    short top;
    short bottom;
    int x = 0;
    int y = 0;
    int i;
    int fileLength;

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

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

    embPattern_loadExternalColorFile(pattern, fileName);
    embFile_seek(file, 0, SEEK_END);
    fileLength = embFile_tell(file);
    binaryReadBytes(file, fileDescription, 8);
    nullVal = binaryReadByte(file);
    binaryReadInt16(file);
    stitchCount = binaryReadInt32(file);
    width = binaryReadInt16(file);
    height = binaryReadInt16(file);
    colorCount = binaryReadInt16(file);
    unknown3 = binaryReadInt16(file);
    unknown2 = binaryReadInt16(file);
    imageWidth = binaryReadInt16(file);
    imageHeight = binaryReadInt16(file);
    binaryReadBytes(file, bytesUnknown, 300);
    nullbyte = binaryReadInt16(file);
    left = binaryReadInt16(file);
    right = binaryReadInt16(file);
    top = binaryReadInt16(file);
    bottom = binaryReadInt16(file);
    embFile_seek(file, 0x2000, SEEK_SET);
    /* Calculate stitch count since header has been seen to be blank */
    stitchCount = (int)((fileLength - 0x2000) / 3);
    for(i = 0; i < stitchCount; i++)
    {
        unsigned char type;
        int stitch = NORMAL;
        x = binaryReadByte(file);
        y = binaryReadByte(file);
        type = binaryReadByte(file);
        if((type & 0x40) > 0)
            x = -x;
        if((type & 0x10) > 0)
            y = -y;
        if((type & 1) > 0)
            stitch = STOP;
        if((type & 2) > 0)
            stitch = TRIM;
        embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, stitch, 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);

    embPattern_flipVertical(pattern);

    return 1;
}
Beispiel #25
0
int readVp3(EmbPattern* pattern, const char* fileName)
{
    unsigned char magicString[5];
    unsigned char some;
    unsigned char* someString = 0;
    unsigned char v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18;
    unsigned char* unknownString3 = 0;
    int numberOfColors;
    long colorSectionOffset;
    unsigned char magicCode[6];
    short someShort;
    unsigned char someByte;
    int bytesRemainingInFile;
    unsigned char* unknownByteString = 0;
    int hoopConfigurationOffset;
    unsigned char* unknownString2 = 0;
    int i;
    FILE* file = 0;

    file = fopen(fileName, "rb");
    if(!file)
    {
        /*TODO: set messages here "Error opening VP3 file for read:" */
        return 0;
    }

    binaryReadBytes(file, magicString, 5); /* %vsm% */

    some = binaryReadByte(file); /* 0 */
    someString = ReadString(file);
    someShort = binaryReadInt16(file);
    someByte = binaryReadByte(file);
    bytesRemainingInFile = binaryReadInt32(file);
    unknownByteString = ReadString(file);
    hoopConfigurationOffset =(int) ftell(file);

    vp3ReadHoopSection(file);

    unknownString2 = ReadString(file);

    v1 = binaryReadByte(file);
    v2 = binaryReadByte(file);
    v3 = binaryReadByte(file);
    v4 = binaryReadByte(file);
    v5 = binaryReadByte(file);
    v6 = binaryReadByte(file);
    v7 = binaryReadByte(file);
    v8 = binaryReadByte(file);
    v9 = binaryReadByte(file);
    v10 = binaryReadByte(file);
    v11 = binaryReadByte(file);
    v12 = binaryReadByte(file);
    v13 = binaryReadByte(file);
    v14 = binaryReadByte(file);
    v15 = binaryReadByte(file);
    v16 = binaryReadByte(file);
    v17 = binaryReadByte(file);
    v18 = binaryReadByte(file);

    binaryReadBytes(file, magicCode, 6); /* 0x78 0x78 0x55 0x55 0x01 0x00 */

    unknownString3 = ReadString(file);

    numberOfColors = binaryReadInt16BE(file);
    colorSectionOffset = (int) ftell(file);

    for(i = 0; i < numberOfColors; i++)
    {
        EmbThread t;
        char tableSize;
        int unknownX, unknownY, unknownX2, unknownY2;
        unsigned char* str1, *str2, *str3;
        int unknownThreadString, numberOfBytesInColor;

        fseek(file, 0x03 + colorSectionOffset, SEEK_SET);
        colorSectionOffset = binaryReadInt32BE(file);
        colorSectionOffset += ftell(file);
        unknownX = binaryReadInt32BE(file);
        unknownY = binaryReadInt32BE(file);
        /* TODO: review commented section below
        pattern.embPattern_addStitchAbsolute(-unknownX / 100, -unknownY/ 100, StitchType.Jump, false);
        fs.Seek(0x08, SeekOrigin.Current);
        */
        tableSize = binaryReadByte(file);

        t.color.b = binaryReadByte(file);
        t.color.r = binaryReadByte(file);
        t.color.g = binaryReadByte(file);
        embPattern_addThread(pattern, t);
        fseek(file, 6*tableSize, SEEK_CUR);

        str1 = ReadString(file);
        str2 = ReadString(file);
        str3 = ReadString(file);

        unknownX2 = binaryReadInt32BE(file);
        unknownY2 = binaryReadInt32BE(file);
        /*fs.Seek(0x02, SeekOrigin.Current); */
        unknownThreadString = binaryReadInt16BE(file);
        fseek(file, unknownThreadString, SEEK_CUR);
        numberOfBytesInColor = binaryReadInt32BE(file);
        fseek(file, 0x3, SEEK_CUR);
        while(ftell(file) < colorSectionOffset - 1)
        {
            int x = vp3Decode(binaryReadByte(file));
            int y = vp3Decode(binaryReadByte(file));
            if(x == 0x80)
            {
                switch (y)
                {
                    case 0x00:
                    case 0x03:
                        break;
                    case 0x01:
                        x = vp3DecodeInt16(binaryReadInt16BE(file));
                        y = vp3DecodeInt16(binaryReadInt16BE(file));
                        binaryReadInt16BE(file);
                        embPattern_addStitchRel(pattern, x/ 10.0, y / 10.0, TRIM, 1);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                embPattern_addStitchRel(pattern, x / 10.0, y / 10.0, NORMAL, 1);
            }
        }
        if(i + 1 < numberOfColors) embPattern_addStitchRel(pattern, 0, 0, STOP, 1);
    }
    embPattern_addStitchRel(pattern, 0, 0, END, 1);
    embPattern_flipVertical(pattern);
    fclose(file);
    return 1;
}
Beispiel #26
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 readOfm(EmbPattern* pattern, const char* fileName)
{
    int unknownCount = 0;
    int key = 0, classNameLength;
    char* s = 0;
    EmbFile* fileCompound = 0;
    EmbFile* file = 0;
    bcf_file* bcfFile = 0;

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

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

    bcfFile = (bcf_file*)malloc(sizeof(bcf_file));
    if(!bcfFile) { embLog_error("format-ofm.c readOfm(), unable to allocate memory for bcfFile\n"); return 0; }
    bcfFile_read(fileCompound, bcfFile);
    file = GetFile(bcfFile, fileCompound, "EdsIV Object");
    bcf_file_free(bcfFile);
    bcfFile = 0;
    embFile_seek(file, 0x1C6, SEEK_SET);
    ofmReadThreads(file, pattern);
    embFile_seek(file, 0x110, SEEK_CUR);
    binaryReadInt32(file);
    classNameLength = binaryReadInt16(file);
    s = (char*)malloc(sizeof(char) * classNameLength);
    if(!s) { embLog_error("format-ofm.c readOfm(), unable to allocate memory for s\n"); return 0; }
    binaryReadBytes(file, (unsigned char*)s, classNameLength); /* TODO: check return value */
    unknownCount = binaryReadInt16(file); /* TODO: determine what unknown count represents */

    binaryReadInt16(file);
    key = ofmReadClass(file);
    while(1)
    {
        if(key == 0xFEFF)
        {
            break;
        }
        if(key == 0x809C)
        {
            ofmReadExpanded(file, pattern);
        }
        else
        {
            ofmReadColorChange(file, pattern);
        }
        key = binaryReadUInt16(file);
        if(key == 0xFFFF)
        {
            ofmReadClass(file);
        }
    }

    embFile_close(fileCompound);
    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_flip(pattern, 1, 1);

    return 1;
}
int readVip(EmbPattern* pattern, const char* fileName)
{
    int fileLength, magicCode, numberOfStitches, numberOfColors;
    int i, attributeOffset, xOffset, yOffset, unknown, colorLength;
	unsigned char* stringVal;
    unsigned char prevByte = 0;
	int postitiveXHoopSize,postitiveYHoopSize,negativeXHoopSize,negativeYHoopSize;
    unsigned char *attributeData, *decodedColors, *attributeDataDecompressed;
    unsigned char *xData, *xDecompressed, *yData, *yDecompressed;
    FILE* file = fopen(fileName, "rb");
    if(file == 0)
    {
        /* TODO: set messages here "Error opening VIP file for read:" */
        return 0;
    }
    fseek(file, 0x0, SEEK_END);
    fileLength = ftell(file);
    fseek(file, 0x00, SEEK_SET);
    magicCode = binaryReadInt32(file);
    numberOfStitches = binaryReadInt32(file);
    numberOfColors = binaryReadInt32(file);

    postitiveXHoopSize = binaryReadInt16(file);
    postitiveYHoopSize = binaryReadInt16(file);
    negativeXHoopSize = binaryReadInt16(file);
    negativeYHoopSize = binaryReadInt16(file);

    attributeOffset = binaryReadInt32(file);
    xOffset = binaryReadInt32(file);
    yOffset = binaryReadInt32(file);

    stringVal = (unsigned char*)malloc(sizeof(unsigned char)*8);
    binaryReadBytes(file, stringVal, 8);

    unknown = binaryReadInt16(file);

	colorLength = binaryReadInt32(file);
	decodedColors = (unsigned char *)malloc(numberOfColors*4);
    for(i = 0; i < numberOfColors*4; ++i)
    {
        unsigned char inputByte = binaryReadByte(file);
        unsigned char tmpByte = (unsigned char) (inputByte ^ vipDecodingTable[i]);
        decodedColors[i] = (unsigned char) (tmpByte ^ prevByte);
        prevByte = inputByte;
    }
    for(i = 0; i < numberOfColors; i++)
    {
        EmbThread thread;
        int startIndex = i << 2;
        thread.color.r = decodedColors[startIndex];
        thread.color.g = decodedColors[startIndex + 1];
        thread.color.b = decodedColors[startIndex + 2];
		/* printf("%d\n", decodedColors[startIndex + 3]); */
        embPattern_addThread(pattern, thread);
    }
	fseek(file, attributeOffset, SEEK_SET);
    attributeData = (unsigned char *)malloc(xOffset - attributeOffset);
    binaryReadBytes(file, attributeData, xOffset - attributeOffset);
    attributeDataDecompressed = DecompressData(attributeData, xOffset - attributeOffset, numberOfStitches);

    fseek(file, xOffset, SEEK_SET);
    xData = (unsigned char *)malloc(yOffset - xOffset);
    binaryReadBytes(file, xData, yOffset - xOffset);
    xDecompressed = DecompressData(xData, yOffset - xOffset, numberOfStitches);

    fseek(file, yOffset, SEEK_SET);
    yData = (unsigned char *)malloc(fileLength - yOffset);
    binaryReadBytes(file, yData, fileLength - yOffset);
    yDecompressed = DecompressData(yData, fileLength - yOffset, numberOfStitches);

    for(i = 0; i < numberOfStitches; i++)
    {
        embPattern_addStitchRel(pattern, DecodeByte(xDecompressed[i]) / 10.0,
            DecodeByte(yDecompressed[i]) / 10.0, DecodeStitchType(attributeDataDecompressed[i]), 1);
    }
    embPattern_addStitchRel(pattern, 0, 0, END, 1);
    fclose(file);

    return 1; /*TODO: finish readVip */
}