Ejemplo n.º 1
0
void 
JB2Dict::set_inherited_dict(const GP<JB2Dict> &dict)
{
  if (shapes.size() > 0)
    G_THROW( ERR_MSG("JB2Image.cant_set") );
  if (inherited_dict)
    G_THROW( ERR_MSG("JB2Image.cant_change") );
  inherited_dict = dict; 
  inherited_shapes = dict->get_shape_count();
  // Make sure that inherited bitmaps are marked as shared
  for (int i=0; i<inherited_shapes; i++)
    {
      JB2Shape &jshp = dict->get_shape(i);
      if (jshp.bits) jshp.bits->share();
    }
}
Ejemplo n.º 2
0
void
JB2Dict::JB2Codec::Decode::code_inherited_shape_count(JB2Dict &jim)
{
  int size=CodeNum(0, BIGPOSITIVE, inherited_shape_count_dist);
    {
      GP<JB2Dict> dict = jim.get_inherited_dict();
      if (!dict && size>0)
        {
          // Call callback function to obtain dictionary
          if (cbfunc)
            dict = (*cbfunc)(cbarg);
          if (dict)
            jim.set_inherited_dict(dict);
        }
      if (!dict && size>0)
        G_THROW( ERR_MSG("JB2Image.need_dict") );
      if (dict && size!=dict->get_shape_count())
        G_THROW( ERR_MSG("JB2Image.bad_dict") );
    }
}
Ejemplo n.º 3
0
void 
cjb2(const GURL &urlin, const GURL &urlout, cjb2opts &opts)
{
  GP<ByteStream> ibs=ByteStream::create(urlin, "rb");
  CCImage rimg;

#if HAVE_TIFF
  if (is_tiff(ibs))
    read_tiff(rimg, ibs, opts);
  else
#endif
    {
      GP<GBitmap> input=GBitmap::create(*ibs);
      rimg.init(input->columns(), input->rows(), opts.dpi);
      rimg.add_bitmap_runs(*input); 
    }
  if (opts.verbose)
    DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cjb2.runs"), 
                         rimg.runs.size() );
  
  // Component analysis
  rimg.make_ccids_by_analysis(); // obtain ccids
  rimg.make_ccs_from_ccids();    // compute cc descriptors
  if (opts.verbose)
    DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cjb2.ccs_before"), 
                         rimg.ccs.size());
  if (opts.losslevel > 0) 
    rimg.erase_tiny_ccs();       // clean
  rimg.merge_and_split_ccs();    // reorganize weird ccs
  rimg.sort_in_reading_order();  // sort cc descriptors
  if (opts.verbose)
    DjVuFormatErrorUTF8( "%s\t%d", ERR_MSG("cjb2.ccs_after"), 
                         rimg.ccs.size());
  
  // Pattern matching
  GP<JB2Image> jimg = rimg.get_jb2image();          // get ``raw'' jb2image
  rimg.runs.empty();                                // save memory
  rimg.ccs.empty();                                 // save memory
  if (opts.losslevel>1)
    tune_jb2image_lossy(jimg, opts.dpi, opts.losslevel);
  else
    tune_jb2image_lossless(jimg);
  if (opts.verbose)
    {
      int nshape=0, nrefine=0;
      for (int i=0; i<jimg->get_shape_count(); i++) {
        if (!jimg->get_shape(i).bits) continue;
        if (jimg->get_shape(i).parent >= 0) nrefine++; 
        nshape++; 
      }
      DjVuFormatErrorUTF8( "%s\t%d\t%d", ERR_MSG("cjb2.shapes"), 
                           nshape, nrefine);
    }
  
  // Code
  GP<ByteStream> obs=ByteStream::create(urlout, "wb");
  GP<IFFByteStream> giff=IFFByteStream::create(obs);
  IFFByteStream &iff=*giff;
  // -- main composite chunk
  iff.put_chunk("FORM:DJVU", 1);
  // -- ``INFO'' chunk
  GP<DjVuInfo> ginfo=DjVuInfo::create();
  DjVuInfo &info=*ginfo;
  info.height = rimg.height;
  info.width = rimg.width;
  info.dpi = opts.dpi;
  iff.put_chunk("INFO");
  info.encode(*iff.get_bytestream());
  iff.close_chunk();
  // -- ``Sjbz'' chunk
  iff.put_chunk("Sjbz");
  jimg->encode(iff.get_bytestream());
  iff.close_chunk();
  // -- terminate main composite chunk
  iff.close_chunk();
  // Finished!
}