void JB2Dict::JB2Codec::Encode::encode_libonly_shape( const GP<JB2Image> &gjim, int shapeno ) { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; // Recursively encode parent shape JB2Shape &jshp = jim.get_shape(shapeno); if (jshp.parent>=0 && shape2lib[jshp.parent]<0) encode_libonly_shape(gjim, jshp.parent); // Test that library shape must be encoded if (shape2lib[shapeno] < 0) { // Code library entry int rectype=(jshp.parent >= 0) ?NEW_MARK_LIBRARY_ONLY:MATCHED_REFINE_LIBRARY_ONLY; code_record(rectype, gjim, &jshp, 0); // Add shape to library add_library(shapeno, jshp); // Check numcoder status if (cur_ncell > CELLCHUNK) { rectype = REQUIRED_DICT_OR_RESET; code_record(rectype, 0, 0); } } }
void JB2Dict::JB2Codec::Decode::code(const GP<JB2Dict> &gjim) { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Dict &jim=*gjim; // ------------------------- // THIS IS THE DECODING PART // ------------------------- int rectype; JB2Shape tmpshape; do { code_record(rectype, gjim, &tmpshape); } while(rectype != END_OF_DATA); if (!gotstartrecordp) G_THROW( ERR_MSG("JB2Image.no_start") ); // cache bounding boxes int nshapes = jim.get_shape_count(); int ishapes = jim.get_inherited_shape_count(); jim.boxes.resize(0, nshapes-ishapes-1); for (int i = ishapes; i < nshapes; i++) jim.boxes[i-ishapes] = libinfo[i]; // compress jim.compress(); }
void JB2Dict::JB2Codec::Encode::code(const GP<JB2Dict> &gjim) { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Dict &jim=*gjim; // ------------------------- // THIS IS THE ENCODING PART // ------------------------- int firstshape = jim.get_inherited_shape_count(); int nshape = jim.get_shape_count(); init_library(jim); // Code headers. int rectype = REQUIRED_DICT_OR_RESET; if (jim.get_inherited_shape_count() > 0) code_record(rectype, gjim, 0); rectype = START_OF_DATA; code_record(rectype, gjim, 0); // Code Comment. rectype = PRESERVED_COMMENT; if (!! jim.comment) code_record(rectype, gjim, 0); // Encode every shape int shapeno; DJVU_PROGRESS_TASK(jb2code,"jb2 encode", nshape-firstshape); for (shapeno=firstshape; shapeno<nshape; shapeno++) { DJVU_PROGRESS_RUN(jb2code, (shapeno-firstshape)|0xff); // Code shape JB2Shape &jshp = jim.get_shape(shapeno); rectype=(jshp.parent >= 0) ?MATCHED_REFINE_LIBRARY_ONLY:NEW_MARK_LIBRARY_ONLY; code_record(rectype, gjim, &jshp); add_library(shapeno, jshp); // Check numcoder status if (cur_ncell > CELLCHUNK) { rectype = REQUIRED_DICT_OR_RESET; code_record(rectype, 0, 0); } } // Code end of data record rectype = END_OF_DATA; code_record(rectype, gjim, 0); gzp=0; }
void JB2Dict::JB2Codec::Decode::code(const GP<JB2Dict> &gjim) { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Dict &jim=*gjim; // ------------------------- // THIS IS THE DECODING PART // ------------------------- int rectype; JB2Shape tmpshape; do { code_record(rectype, gjim, &tmpshape); } while(rectype != END_OF_DATA); if (!gotstartrecordp) G_THROW( ERR_MSG("JB2Image.no_start") ); jim.compress(); }
void JB2Dict::JB2Codec::Encode::code(const GP<JB2Image> &gjim) { if(!gjim) { G_THROW( ERR_MSG("JB2Image.bad_number") ); } JB2Image &jim=*gjim; // ------------------------- // THIS IS THE ENCODING PART // ------------------------- int i; init_library(jim); int firstshape = jim.get_inherited_shape_count(); int nshape = jim.get_shape_count(); int nblit = jim.get_blit_count(); // Initialize shape2lib shape2lib.resize(0,nshape-1); for (i=firstshape; i<nshape; i++) shape2lib[i] = -1; // Determine shapes that go into library (shapeno>=firstshape) // shape2lib is -2 if used by one blit // shape2lib is -3 if used by more than one blit // shape2lib is -4 if used as a parent for (i=0; i<nblit; i++) { JB2Blit *jblt = jim.get_blit(i); int shapeno = jblt->shapeno; if (shapeno < firstshape) continue; if (shape2lib[shapeno] >= -2) shape2lib[shapeno] -= 1; shapeno = jim.get_shape(shapeno).parent; while (shapeno>=firstshape && shape2lib[shapeno]>=-3) { shape2lib[shapeno] = -4; shapeno = jim.get_shape(shapeno).parent; } } // Code headers. int rectype = REQUIRED_DICT_OR_RESET; if (jim.get_inherited_shape_count() > 0) code_record(rectype, gjim, 0, 0); rectype = START_OF_DATA; code_record(rectype, gjim, 0, 0); // Code Comment. rectype = PRESERVED_COMMENT; if (!! jim.comment) code_record(rectype, gjim, 0, 0); // Encode every blit int blitno; DJVU_PROGRESS_TASK(jb2code,"jb2 encode", nblit); for (blitno=0; blitno<nblit; blitno++) { DJVU_PROGRESS_RUN(jb2code, blitno|0xff); JB2Blit *jblt = jim.get_blit(blitno); int shapeno = jblt->shapeno; JB2Shape &jshp = jim.get_shape(shapeno); // Tests if shape exists in library if (shape2lib[shapeno] >= 0) { int rectype = MATCHED_COPY; code_record(rectype, gjim, 0, jblt); } // Avoid coding null shapes/blits else if (jshp.bits) { // Make sure all parents have been coded if (jshp.parent>=0 && shape2lib[jshp.parent]<0) encode_libonly_shape(gjim, jshp.parent); // Allocate library entry when needed #define LIBRARY_CONTAINS_ALL int libraryp = 0; #ifdef LIBRARY_CONTAINS_MARKS // baseline if (jshp.parent >= -1) libraryp = 1; #endif #ifdef LIBRARY_CONTAINS_SHARED // worse if (shape2lib[shapeno] <= -3) libraryp = 1; #endif #ifdef LIBRARY_CONTAINS_ALL // better libraryp = 1; #endif // Test all blit cases if (jshp.parent<-1 && !libraryp) { int rectype = NON_MARK_DATA; code_record(rectype, gjim, &jshp, jblt); } else if (jshp.parent < 0) { int rectype = (libraryp ? NEW_MARK : NEW_MARK_IMAGE_ONLY); code_record(rectype, gjim, &jshp, jblt); } else { int rectype = (libraryp ? MATCHED_REFINE : MATCHED_REFINE_IMAGE_ONLY); code_record(rectype, gjim, &jshp, jblt); } // Add shape to library if (libraryp) add_library(shapeno, jshp); } // Check numcoder status if (cur_ncell > CELLCHUNK) { rectype = REQUIRED_DICT_OR_RESET; code_record(rectype, 0, 0); } } // Code end of data record rectype = END_OF_DATA; code_record(rectype, gjim, 0, 0); gzp=0; }