Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

GP< DataPool > DjVuDocument::get_thumbnail ( int  page_num,
bool  dont_decode 
) [virtual]

Returns a {DataPool} containing one chunk TH44# with the encoded thumbnail for the specified page. The function first looks for thumbnails enclosed into the document and if it fails to find one, it decodes the required page and creates the thumbnail on the fly (unless dont_decode# is true).

{ Note:} It may happen that the returned {DataPool} will not contain all the data you need. In this case you will need to install a trigger into the {DataPool} to learn when the data actually arrives.

Reimplemented in DjVuDocEditor.

Definition at line 1278 of file DjVuDocument.cpp.

References DataPool::create(), get_djvu_file(), get_doc_type(), and is_init_complete().

Referenced by DjVuDocEditor::get_thumbnail(), and DjVuDocEditor::init().

   DEBUG_MSG("DjVuDocument::get_thumbnail(): page_num=" << page_num << "\n");

   if (!is_init_complete()) return 0;
       // See if we already have request for this thumbnail pending
      GCriticalSectionLock lock(&threqs_lock);
      for(GPosition pos=threqs_list;pos;++pos)
       GP<ThumbReq> req=threqs_list[pos];
       if (req->page_num==page_num)
          return req->data_pool;    // That's it. Just return it.

      // No pending request for this page... Create one
   GP<ThumbReq> thumb_req=new ThumbReq(page_num, DataPool::create());
      // First try to find predecoded thumbnail
   if (get_doc_type()==INDIRECT || get_doc_type()==BUNDLED)
       // Predecoded thumbnails exist for new formats only
      GPList<DjVmDir::File> files_list=djvm_dir->get_files_list();
      GP<DjVmDir::File> thumb_file;
      int thumb_start=0;
      int page_cnt=-1;
      for(GPosition pos=files_list;pos;++pos)
       GP<DjVmDir::File> f=files_list[pos];
       if (f->is_thumbnails())
       } else if (f->is_page())
       if (page_cnt==page_num) break;
      if (thumb_file)
          // That's the file with the desired thumbnail image
       return thumb_req->data_pool;

      // Apparently we're out of luck and need to decode the requested
      // page (unless it's already done and if it's allowed) and render
      // it into the thumbnail. If dont_decode is true, do not attempt
      // to create this file (because this will result in a request for data)
   GP<DjVuFile> file=get_djvu_file(page_num, dont_decode);
   if (file)

       // I'm locking the flags here to make sure, that DjVuFile will not
       // change its state in between of the checks.
      GSafeFlags & file_flags=file->get_safe_flags();
       GMonitorLock lock(&file_flags);
       if (thumb_req->image_file->is_decode_ok() || !dont_decode)
             // Just add it to the list and call process_threqs(). It
             // will start decoding if necessary
       } else
             // Nothing can be done return ZERO
   } else thumb_req=0;
   if (thumb_req) return thumb_req->data_pool;
   else return 0;

Generated by  Doxygen 1.6.0   Back to index