Exemplo n.º 1
0
Arquivo: gfx.cpp Projeto: hnkien/sdk
bool GfxProc::savefa(string *localfilepath, GfxProc::meta_t type, string *localdstpath)
{
    if (!isgfx(localfilepath)
            // (this assumes that the width of the largest dimension is max)
            || !readbitmap(NULL, localfilepath, dimensions[sizeof dimensions/sizeof dimensions[0]-1][0]))
    {
        return false;
    }

    string jpeg;
    bool success = resizebitmap(dimensions[type][0], dimensions[type][1], &jpeg);
    freebitmap();

    if (!success)
    {
        return false;
    }

    FileAccess *f = client->fsaccess->newfileaccess();
    client->fsaccess->unlinklocal(localdstpath);
    if (!f->fopen(localdstpath, false, true))
    {
        delete f;
        return false;
    }

    if (!f->fwrite((const byte*)jpeg.data(), jpeg.size(), 0))
    {
        delete f;
        return false;
    }

    delete f;
    return true;
}
Exemplo n.º 2
0
Arquivo: gfx.cpp Projeto: meganz/sdk
bool GfxProc::savefa(string *localfilepath, int width, int height, string *localdstpath)
{
    if (!isgfx(localfilepath))
    {
        return false;
    }

    mutex.lock();
    if (!readbitmap(NULL, localfilepath, width > height ? width : height))
    {
        mutex.unlock();
        return false;
    }

    int w = width;
    int h = height;
    if (this->w < w && this->h < h)
    {
        LOG_debug << "Skipping upsizing of local preview";
        w = this->w;
        h = this->h;
    }

    string jpeg;
    bool success = resizebitmap(w, h, &jpeg);
    freebitmap();
    mutex.unlock();

    if (!success)
    {
        return false;
    }

    FileAccess *f = client->fsaccess->newfileaccess();
    client->fsaccess->unlinklocal(localdstpath);
    if (!f->fopen(localdstpath, false, true))
    {
        delete f;
        return false;
    }

    if (!f->fwrite((const byte*)jpeg.data(), unsigned(jpeg.size()), 0))
    {
        delete f;
        return false;
    }

    delete f;
    return true;
}
Exemplo n.º 3
0
// load bitmap image, generate all designated sizes, attach to specified upload/node handle
// FIXME: move to a worker thread to keep the engine nonblocking
int GfxProc::gendimensionsputfa(FileAccess* fa, string* localfilename, handle th, SymmCipher* key, int missing)
{
    int numputs = 0;

    if (isgfx(localfilename))
    {
        // (this assumes that the width of the largest dimension is max)
        if (readbitmap(fa, localfilename, dimensions[sizeof dimensions/sizeof dimensions[0]-1][0]))
        {
            string* jpeg = NULL;

            // successively downscale the original image
            for (int i = sizeof dimensions/sizeof dimensions[0]; i--; )
            {
                if (!jpeg)
                {
                    jpeg = new string;
                }

                if (missing & (1 << i) && resizebitmap(dimensions[i][0], dimensions[i][1], jpeg))
                {
                    // store the file attribute data - it will be attached to the file
                    // immediately if the upload has already completed; otherwise, once
                    // the upload completes
                    client->putfa(th, (meta_t)i, key, jpeg);
                    numputs++;

                    jpeg = NULL;
                }
            }

            if (jpeg)
            {
                delete jpeg;
            }

            freebitmap();
        }
    }
    
    return numputs;
}