/*TODO: Description needed. */
void embPattern_loadExternalColorFile(EmbPattern* p, const char* fileName)
{
    char hasRead = 0;
    EmbReaderWriter* colorFile = 0;
    const char* dotPos = strrchr(fileName, '.');
    char* extractName = 0;

    if(!p) { embLog_error("emb-pattern.c embPattern_loadExternalColorFile(), p argument is null\n"); return; }
    if(!fileName) { embLog_error("emb-pattern.c embPattern_loadExternalColorFile(), fileName argument is null\n"); return; }

    extractName = (char*)malloc(dotPos - fileName + 5);
    if(!extractName) { embLog_error("emb-pattern.c embPattern_loadExternalColorFile(), cannot allocate memory for extractName\n"); return; }
    extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
    extractName[dotPos - fileName] = '\0';
    strcat(extractName,".edr");
    colorFile = embReaderWriter_getByFileName(extractName);
    if(colorFile)
    {
        hasRead = (char)colorFile->reader(p, extractName);
    }
    if(!hasRead)
    {
        free(colorFile);
        extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".rgb");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    if(!hasRead)
    {
        free(colorFile);
        extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".col");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    if(!hasRead)
    {
        free(colorFile);
        extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".inf");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    free(colorFile);
    free(extractName);
}
/*TODO: Description needed. */
void embPattern_loadExternalColorFile(EmbPattern* p, const char* fileName)
{
    /* TODO: pointer safety */
    char hasRead = 0;
    EmbReaderWriter* colorFile = 0;
    const char* dotPos = strrchr(fileName, '.');

    char* extractName = (char*)malloc(dotPos - fileName + 5);
    if(!extractName) return;
    extractName = (char *)memcpy(extractName, fileName, dotPos - fileName);
    extractName[dotPos - fileName] = '\0';
    strcat(extractName,".edr");
    colorFile = embReaderWriter_getByFileName(extractName);
    if(colorFile)
    {
        hasRead = (char)colorFile->reader(p, extractName);
    }
    if(!hasRead)
    {
        free(colorFile);
        extractName = (char *)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".rgb");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    if(!hasRead)
    {
        free(colorFile);
        extractName = (char *)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".col");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    if(!hasRead)
    {
        free(colorFile);
        extractName = (char *)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".inf");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    free(colorFile);
    free(extractName);
}
int embPattern_read(EmbPattern* p, const char* fileName) /* TODO: This doesn't work. Write test case using this convenience function. */
{
    EmbReaderWriter* reader = 0;
    embPattern_free(p);
    p = embPattern_create();
    reader = embReaderWriter_getByFileName(fileName);
    if(reader->reader(p, fileName))
    {
        free(reader);
        return 1;
    }
    free(reader);
    return 0;
}
Exemple #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 embPattern_read(EmbPattern* pattern, const char* fileName) /* TODO: Write test case using this convenience function. */
{
    EmbReaderWriter* reader = 0;
    int result = 0;

    if(!pattern) { embLog_error("emb-pattern.c embPattern_read(), pattern argument is null\n file: %s, line: %u\n", __FILE__, __LINE__); return 0; }
    if(!fileName) { embLog_error("emb-pattern.c embPattern_read(), fileName argument is null\n file: %s, line: %u\n", __FILE__, __LINE__); return 0; }

    reader = embReaderWriter_getByFileName(fileName);
    if(!reader) { embLog_error("emb-pattern.c embPattern_read(), unsupported read file type: %s\n file: %s, line: %u\n", fileName, __FILE__, __LINE__); return 0; }
    result = reader->reader(pattern, fileName);
    free(reader);
    reader = 0;
    return result;
}
int main(int argc, const char* argv[])
{
#ifdef SHORT_WAY
    EmbPattern* p = 0;
    int successful = 0, i = 0;
    if(argc < 3)
    {
        usage();
        exit(0);
    }

    p = embPattern_create();
    if(!p) { embLog_error("libembroidery-convert-main.c main(), cannot allocate memory for p\n"); exit(1); }

    successful = embPattern_read(p, argv[1]);
    if(!successful)
    {
        embLog_error("libembroidery-convert-main.c main(), reading file %s was unsuccessful\n", argv[1]);
        embPattern_free(p);
        exit(1);
    }

    i = 2;
    for(i = 2; i < argc; i++)
    {
        successful = embPattern_write(p, argv[i]);
        if(!successful)
            embLog_error("libembroidery-convert-main.c main(), writing file %s was unsuccessful\n", argv[i]);
    }

    embPattern_free(p);
    return 0;
#else /* LONG_WAY */
    EmbPattern* p = 0;
    EmbReaderWriter* reader = 0, *writer = 0;
    int successful = 0, i = 0;
    if(argc < 3)
    {
        usage();
        exit(0);
    }

    p = embPattern_create();
    if(!p) { embLog_error("libembroidery-convert-main.c main(), cannot allocate memory for p\n"); exit(1); }

    successful = 0;
    reader = embReaderWriter_getByFileName(argv[1]);
    if(!reader)
    {
        successful = 0;
        embLog_error("libembroidery-convert-main.c main(), unsupported read file type: %s\n", argv[1]);
    }
    else
    {
        successful = reader->reader(p, argv[1]);
        if(!successful) embLog_error("libembroidery-convert-main.c main(), reading file was unsuccessful: %s\n", argv[1]);
    }
    free(reader);
    if(!successful)
    {
        embPattern_free(p);
        exit(1);
    }

    i = 2;
    for(i = 2; i < argc; i++)
    {
        writer = embReaderWriter_getByFileName(argv[i]);
        if(!writer)
        {
            embLog_error("libembroidery-convert-main.c main(), unsupported write file type: %s\n", argv[i]);
        }
        else
        {
            successful = writer->writer(p, argv[i]);
            if(!successful)
                embLog_error("libembroidery-convert-main.c main(), writing file %s was unsuccessful\n", argv[i]);
        }
        free(writer);
    }

    embPattern_free(p);
    return 0;
#endif /* SHORT_WAY */

}
Exemple #6
0
/*TODO: Description needed. */
void embPattern_loadExternalColorFile(EmbPattern* p, const char* fileName)
{
#ifdef ARDUINO
    return; /* TODO ARDUINO: This function leaks memory. While it isn't crucial to running the machine, it would be nice use this function, so fix it up. */
#endif /* ARDUINO */

    char hasRead = 0;
    EmbReaderWriter* colorFile = 0;
    const char* dotPos = strrchr(fileName, '.');
    char* extractName = 0;

    if(!p) { embLog_error("emb-pattern.c embPattern_loadExternalColorFile(), p argument is null\n"); return; }
    if(!fileName) { embLog_error("emb-pattern.c embPattern_loadExternalColorFile(), fileName argument is null\n"); return; }

    extractName = (char*)malloc(dotPos - fileName + 5);
    if(!extractName) { embLog_error("emb-pattern.c embPattern_loadExternalColorFile(), cannot allocate memory for extractName\n"); return; }
    extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
    extractName[dotPos - fileName] = '\0';
    strcat(extractName,".edr");
    colorFile = embReaderWriter_getByFileName(extractName);
    if(colorFile)
    {
        hasRead = (char)colorFile->reader(p, extractName);
    }
    if(!hasRead)
    {
        free(colorFile);
        colorFile = 0;
        extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".rgb");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    if(!hasRead)
    {
        free(colorFile);
        colorFile = 0;
        extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".col");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    if(!hasRead)
    {
        free(colorFile);
        colorFile = 0;
        extractName = (char*)memcpy(extractName, fileName, dotPos - fileName);
        extractName[dotPos - fileName] = '\0';
        strcat(extractName,".inf");
        colorFile = embReaderWriter_getByFileName(extractName);
        if(colorFile)
        {
            hasRead = (char)colorFile->reader(p, extractName);
        }
    }
    free(colorFile);
    colorFile = 0;
    free(extractName);
    extractName = 0;
}
const QImage loadThumb(const QString& fileName)
{
    QFile file(fileName);
    if(!file.open(QFile::ReadOnly | QFile::Text))
    {
        //Error opening file
        return QImage();
    }

    //Read
    EmbPattern* p = embPattern_create();
    if(!p) { return QImage(); }
    int readSuccessful = 0;
    QString readError;
    EmbReaderWriter* reader = embReaderWriter_getByFileName(qPrintable(fileName));
    if(!reader)
    {
        readSuccessful = 0;
    }
    else
    {
        readSuccessful = reader->reader(p, qPrintable(fileName));
    }
    free(reader);

    if(readSuccessful)
    {
        QGraphicsScene gscene;
        QPainterPath path;

        if(p->stitchList)
        {
            int previousColor = p->stitchList->stitch.color;

            EmbStitchList* curStitchItem = p->stitchList;
            while(curStitchItem)
            {
                EmbStitch tempStitch = curStitchItem->stitch;
                curStitchItem = curStitchItem->next;
                if((tempStitch.flags & STOP) || (tempStitch.flags & END))
                {
                    if(!path.isEmpty())
                    {
                        EmbColor thisColor = embThread_getAt(p->threadList, previousColor).color;
                        QPen loadPen(qRgb(thisColor.r, thisColor.g, thisColor.b));
                        loadPen.setWidthF(0.35);
                        loadPen.setCapStyle(Qt::RoundCap);
                        loadPen.setJoinStyle(Qt::RoundJoin);
                        gscene.addPath(path, loadPen);
                        previousColor = tempStitch.color;
                        path = QPainterPath();
                    }
                    path.moveTo(tempStitch.xx, -tempStitch.yy);
                }
                else if((tempStitch.flags & JUMP) || (tempStitch.flags & TRIM))
                {
                    path.moveTo(tempStitch.xx, -tempStitch.yy);
                }
                else
                {
                    path.lineTo(tempStitch.xx, -tempStitch.yy);
                }
            }
        }

        QImage sceneImg(gscene.width(), gscene.height(), QImage::Format_ARGB32);
        sceneImg.fill(QColor(0,0,0,0));

        QPainter painter(&sceneImg);
        gscene.render(&painter);
        return sceneImg;
    }
    embPattern_free(p);

    return QImage();
}