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 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;
}
Example #2
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;
}