venerdì 3 dicembre 2010

libjpeg progres...

Well, beside my previous rant about OVI store, work is going on albeit a bit slowly.

I am struggling a bit with libjpeg... Nothing serious, but i wasted a few hours understanding why libjpeg was showing only 20lines of each jpg... The answer? Easy, look at this code:

void ImageJpeg::initialize()
{
    QFile image_file.setFileName( filename );
    if ( !image_file.open( QIODevice::ReadOnly ) )
    {   // quit on error
        error = true;
        return;
    }
    // Convert QFile to FILE (needed by libjpeg)
    FILE* pFile = fdopen(image_file.handle(), "rb"); // This will be reused in other methods to load jpeg data
    // initialize jibjpeg data structure
    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_decompress(&cinfo);
    // Initliazed must be true whenever we need to destroy cinfo
    initialized = true;
    // Set file in libjpeg
    jpeg_stdio_src(&cinfo, pFile );
    // Read header
    jpeg_read_header(&cinfo, TRUE);
    // set error status
    error = cinfo.err->msg_code == 0;
    return;
}

 Do you see the error? Well, image_file will be closed on function return, leaving the libjpeg to handle a closed stream when reading an image!

Placing image_file in the class (as private attribute) solved the problem...

Update: ok guys, there will not be much more for this week, i guess. Right now, i am fixing some bugs in the readImage function of ImageJpeg, responsible to load a piece of jpeg and scale it properly. It took me a while, specially to filter out all the special cases leading to a segmentation fault (magic of working with raw pointers and C code...), but now it works for any zoom level.

Unfortunately speed (Even if hugely better than using Qt's internal QImageReader) is still not enugh on the phone, so i believe some kind of caching is STILL required. Unless i find a way to skip scanlines in libjpeg... whichi did not, so far.

Nessun commento:

Posta un commento