Logo Search packages:      
Sourcecode: djvulibre version File versions

int DjVuDocEditor::generate_thumbnails ( int  thumb_size,
int  page_num 
)

Generates thumbnails for the specified page, if and only if it does not have a thumbnail yet. If you want to regenerate thumbnails for all pages, call {remove_thumbnails}() prior to calling this function.

Parameters:
thumb_size The size of the thumbnails in pixels. DjVu viewer is able to rescale the thumbnail images if necessary, so this parameter affects thumbnails quality only. 128 is a good number.
page_num The page number to genate the thumbnail for.

Definition at line 1685 of file DjVuDocEditor.cpp.

References IWEncoderParms::bytes, GMapTemplate< KTYPE, VTYPE, TI >::contains(), DataPool::create(), ByteStream::create(), GPixmap::create(), IW44Image::create_encode(), IWEncoderParms::decibels, DjVuDocument::get_page(), DjVmDir::get_pages_num(), page_to_id(), IWEncoderParms::slices, and GPixel::WHITE.

Referenced by generate_thumbnails().

{
   DEBUG_MSG("DjVuDocEditor::generate_thumbnails(): doing it\n");
   DEBUG_MAKE_INDENT(3);

   if(page_num<(djvm_dir->get_pages_num()))
   {
      const GUTF8String id(page_to_id(page_num));
      if (!thumb_map.contains(id))
        {
          const GP<DjVuImage> dimg(get_page(page_num, true));
         
          GRect rect(0, 0, thumb_size, dimg->get_height()*thumb_size/dimg->get_width());
          GP<GPixmap> pm=dimg->get_pixmap(rect, rect, get_thumbnails_gamma());
          if (!pm)
            {
              const GP<GBitmap> bm(dimg->get_bitmap(rect, rect, sizeof(int)));
              if (bm) 
                pm = GPixmap::create(*bm);
              else
                pm = GPixmap::create(rect.height(), rect.width(), &GPixel::WHITE);
            }
          // Store and compress the pixmap
          const GP<IW44Image> iwpix(IW44Image::create_encode(*pm));
          const GP<ByteStream> gstr(ByteStream::create());
          IWEncoderParms parms;
          parms.slices=97;
          parms.bytes=0;
          parms.decibels=0;
          iwpix->encode_chunk(gstr, parms);
          gstr->seek(0L);
          thumb_map[id]=DataPool::create(gstr);
        }
      ++page_num;
   }
   else
   {
     page_num = -1;
   }
   return page_num;
}


Generated by  Doxygen 1.6.0   Back to index