speed up un-cached directories

embedded thumbnails will be used for the first pass when cached thumbnails are not found.
This commit is contained in:
Steve Herrell
2010-10-29 12:06:17 +02:00
parent 7ce062cfc3
commit b25d03e6ea
18 changed files with 397 additions and 59 deletions

View File

@@ -259,6 +259,75 @@ int ImageIO::loadPNG (Glib::ustring fname) {
extern jmp_buf jpeg_jmp_buf;
extern "C" {
void jpeg_memory_src (jpeg_decompress_struct* cinfo, const char* buffer, int bufsize);
}
int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
{
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
cinfo.err = my_jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_memory_src (&cinfo,buffer,bufsize);
if (pl) {
pl->setProgressStr ("Loading JPEG file...");
pl->setProgress (0.0);
}
setup_read_icc_profile (&cinfo);
if (!setjmp(jpeg_jmp_buf)) {
jpeg_memory_src (&cinfo,buffer,bufsize);
jpeg_read_header(&cinfo, TRUE);
unsigned int proflen;
delete loadedProfileData;
loadedProfileData = NULL;
bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength);
if (hasprofile)
embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength);
else
embProfile = NULL;
jpeg_start_decompress(&cinfo);
int width = cinfo.output_width;
int height = cinfo.output_height;
allocate (width, height);
unsigned char *row=new unsigned char[width*3];
while (cinfo.output_scanline < height) {
if (jpeg_read_scanlines(&cinfo,&row,1) < 1) {
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
delete [] row;
return IMIO_READERROR;
}
setScanline (cinfo.output_scanline-1, row, 8);
if (pl && !(cinfo.output_scanline%100))
pl->setProgress ((double)(cinfo.output_scanline)/cinfo.output_height);
}
delete [] row;
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
if (pl) {
pl->setProgressStr ("Ready.");
pl->setProgress (1.0);
}
return IMIO_SUCCESS;
}
else {
jpeg_destroy_decompress(&cinfo);
return IMIO_READERROR;
}
}
int ImageIO::loadJPEG (Glib::ustring fname) {
FILE *file=g_fopen(fname.c_str(),"rb");