12 lines
39 KiB
Go
Raw Normal View History

JBIG2 Generic Encoder (#264) * Prepared skeleton and basic component implementations for the jbig2 encoding. * Added Bitset. Implemented Bitmap. * Decoder with old Arithmetic Decoder * Partly working arithmetic * Working arithmetic decoder. * MMR patched. * rebuild to apache. * Working generic * Working generic * Decoded full document * Update Jenkinsfile go version [master] (#398) * Update Jenkinsfile go version * Decoded AnnexH document * Minor issues fixed. * Update README.md * Fixed generic region errors. Added benchmark. Added bitmap unpadder. Added Bitmap toImage method. * Fixed endofpage error * Added integration test. * Decoded all test files without errors. Implemented JBIG2Global. * Merged with v3 version * Fixed the EOF in the globals issue * Fixed the JBIG2 ChocolateData Decode * JBIG2 Added license information * Minor fix in jbig2 encoding. * Applied the logging convention * Cleaned unnecessary imports * Go modules clear unused imports * checked out the README.md * Moved trace to Debug. Fixed the build integrate tag in the document_decode_test.go * Initial encoder skeleton * Applied UniPDF Developer Guide. Fixed lint issues. * Cleared documentation, fixed style issues. * Added jbig2 doc.go files. Applied unipdf guide style. * Minor code style changes. * Minor naming and style issues fixes. * Minor naming changes. Style issues fixed. * Review r11 fixes. * Added JBIG2 Encoder skeleton. * Moved Document and Page to jbig2/document package. Created decoder package responsible for decoding jbig2 stream. * Implemented raster functions. * Added raster uni low test funcitons. * Added raster low test functions * untracked files on jbig2-encoder: c869089 Added raster low test functions * index on jbig2-encoder: c869089 Added raster low test functions * Added morph files. * implemented jbig2 encoder basics * JBIG2 Encoder - Generic method * Added jbig2 image encode ttests, black/white image tests * cleaned and tested jbig2 package * unfinished jbig2 classified encoder * jbig2 minor style changes * minor jbig2 encoder changes * prepared JBIG2 Encoder * Style and lint fixes * Minor changes and lints * Fixed shift unsinged value build errors * Minor naming change * Added jbig2 encode, image gondels. Fixed jbig2 decode bug. * Provided jbig2 core.DecodeGlobals function. * Fixed JBIG2Encoder `r6` revision issues. * Removed public JBIG2Encoder document. * Minor style changes * added NewJBIG2Encoder function. * fixed JBIG2Encoder 'r9' revision issues. * Cleared 'r9' commented code. * Updated ACKNOWLEDGEMENETS. Fixed JBIG2Encoder 'r10' revision issues. Co-authored-by: Gunnsteinn Hall <gunnsteinn.hall@gmail.com>
2020-03-27 12:47:41 +01:00
//
2020-08-27 21:45:09 +00:00
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
JBIG2 Generic Encoder (#264) * Prepared skeleton and basic component implementations for the jbig2 encoding. * Added Bitset. Implemented Bitmap. * Decoder with old Arithmetic Decoder * Partly working arithmetic * Working arithmetic decoder. * MMR patched. * rebuild to apache. * Working generic * Working generic * Decoded full document * Update Jenkinsfile go version [master] (#398) * Update Jenkinsfile go version * Decoded AnnexH document * Minor issues fixed. * Update README.md * Fixed generic region errors. Added benchmark. Added bitmap unpadder. Added Bitmap toImage method. * Fixed endofpage error * Added integration test. * Decoded all test files without errors. Implemented JBIG2Global. * Merged with v3 version * Fixed the EOF in the globals issue * Fixed the JBIG2 ChocolateData Decode * JBIG2 Added license information * Minor fix in jbig2 encoding. * Applied the logging convention * Cleaned unnecessary imports * Go modules clear unused imports * checked out the README.md * Moved trace to Debug. Fixed the build integrate tag in the document_decode_test.go * Initial encoder skeleton * Applied UniPDF Developer Guide. Fixed lint issues. * Cleared documentation, fixed style issues. * Added jbig2 doc.go files. Applied unipdf guide style. * Minor code style changes. * Minor naming and style issues fixes. * Minor naming changes. Style issues fixed. * Review r11 fixes. * Added JBIG2 Encoder skeleton. * Moved Document and Page to jbig2/document package. Created decoder package responsible for decoding jbig2 stream. * Implemented raster functions. * Added raster uni low test funcitons. * Added raster low test functions * untracked files on jbig2-encoder: c869089 Added raster low test functions * index on jbig2-encoder: c869089 Added raster low test functions * Added morph files. * implemented jbig2 encoder basics * JBIG2 Encoder - Generic method * Added jbig2 image encode ttests, black/white image tests * cleaned and tested jbig2 package * unfinished jbig2 classified encoder * jbig2 minor style changes * minor jbig2 encoder changes * prepared JBIG2 Encoder * Style and lint fixes * Minor changes and lints * Fixed shift unsinged value build errors * Minor naming change * Added jbig2 encode, image gondels. Fixed jbig2 decode bug. * Provided jbig2 core.DecodeGlobals function. * Fixed JBIG2Encoder `r6` revision issues. * Removed public JBIG2Encoder document. * Minor style changes * added NewJBIG2Encoder function. * fixed JBIG2Encoder 'r9' revision issues. * Cleared 'r9' commented code. * Updated ACKNOWLEDGEMENETS. Fixed JBIG2Encoder 'r10' revision issues. Co-authored-by: Gunnsteinn Hall <gunnsteinn.hall@gmail.com>
2020-03-27 12:47:41 +01:00
2020-11-11 18:48:37 +00:00
package document ;import (_c "encoding/binary";_ee "fmt";_da "github.com/unidoc/unipdf/v3/common";_a "github.com/unidoc/unipdf/v3/internal/bitwise";_edc "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_dac "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_db "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_b "github.com/unidoc/unipdf/v3/internal/jbig2/encoder/classer";_fa "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_ed "io";_e "math";_d "runtime/debug";);func (_ffbg *Page )createPage (_ffdf *_db .PageInformationSegment )error {var _bbbb error ;if !_ffdf .IsStripe ||_ffdf .PageBMHeight !=-1{_bbbb =_ffbg .createNormalPage (_ffdf );}else {_bbbb =_ffbg .createStripedPage (_ffdf );};return _bbbb ;};func (_eec *Document )reachedEOF (_aacd int64 )(bool ,error ){const _gafg ="\u0072\u0065\u0061\u0063\u0068\u0065\u0064\u0045\u004f\u0046";_ ,_cde :=_eec .InputStream .Seek (_aacd ,_ed .SeekStart );if _cde !=nil {_da .Log .Debug ("\u0072\u0065\u0061c\u0068\u0065\u0064\u0045\u004f\u0046\u0020\u002d\u0020\u0064\u002e\u0049\u006e\u0070\u0075\u0074\u0053\u0074\u0072\u0065\u0061\u006d\u002e\u0053\u0065\u0065\u006b\u0020\u0066a\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_cde );return false ,_fa .Wrap (_cde ,_gafg ,"\u0069n\u0070\u0075\u0074\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u0020s\u0065\u0065\u006b\u0020\u0066\u0061\u0069\u006c\u0065\u0064");};_ ,_cde =_eec .InputStream .ReadBits (32);if _cde ==_ed .EOF {return true ,nil ;}else if _cde !=nil {return false ,_fa .Wrap (_cde ,_gafg ,"");};return false ,nil ;};func (_fg *Document )produceClassifiedPages ()(_dgb error ){const _afb ="\u0070\u0072\u006f\u0064uc\u0065\u0043\u006c\u0061\u0073\u0073\u0069\u0066\u0069\u0065\u0064\u0050\u0061\u0067e\u0073";if _fg .Classer ==nil {return nil ;};var (_egd *Page ;_aad bool ;_afg *_db .Header ;);for _dgbb :=1;_dgbb <=int (_fg .NumberOfPages );_dgbb ++{if _egd ,_aad =_fg .Pages [_dgbb ];!_aad {return _fa .Errorf (_afb ,"p\u0061g\u0065\u003a\u0020\u0027\u0025\u0064\u0027\u0020n\u006f\u0074\u0020\u0066ou\u006e\u0064",_dgbb );};if _egd .EncodingMethod ==GenericEM {continue ;};if _afg ==nil {if _afg ,_dgb =_fg .GlobalSegments .GetSymbolDictionary ();_dgb !=nil {return _fa .Wrap (_dgb ,_afb ,"");};};if _dgb =_fg .produceClassifiedPage (_egd ,_afg );_dgb !=nil {return _fa .Wrapf (_dgb ,_afb ,"\u0070\u0061\u0067\u0065\u003a\u0020\u0027\u0025\u0064\u0027",_dgbb );};};return nil ;};func (_gec *Page )GetWidth ()(int ,error ){return _gec .getWidth ()};func _adea (_dge _a .StreamReader ,_ggc *Globals )(*Document ,error ){_acbg :=&Document {Pages :make (map[int ]*Page ),InputStream :_dge ,OrganizationType :_db .OSequential ,NumberOfPagesUnknown :true ,GlobalSegments :_ggc ,_g :9};if _acbg .GlobalSegments ==nil {_acbg .GlobalSegments =&Globals {};};if _fb :=_acbg .mapData ();_fb !=nil {return nil ,_fb ;};return _acbg ,nil ;};func (_bdad *Page )nextSegmentNumber ()uint32 {return _bdad .Document .nextSegmentNumber ()};func _ce (_ac int )int {_acc :=0;_fac :=(_ac &(_ac -1))==0;_ac >>=1;for ;_ac !=0;_ac >>=1{_acc ++;};if _fac {return _acc ;};return _acc +1;};func (_ddd *Page )clearSegmentData (){for _egf :=range _ddd .Segments {_ddd .Segments [_egf ].CleanSegmentData ();};};type Globals struct{Segments []*_db .Header ;};func (_dcae *Page )countRegions ()int {var _bge int ;for _ ,_gdfd :=range _dcae .Segments {switch _gdfd .Type {case 6,7,22,23,38,39,42,43:_bge ++;};};return _bge ;};func DecodeDocument (input _a .StreamReader ,globals *Globals )(*Document ,error ){return _adea (input ,globals );};func (_bgd *Document )produceClassifiedPage (_cc *Page ,_gaf *_db .Header )(_adf error ){const _bdd ="p\u0072\u006f\u0064\u0075ce\u0043l\u0061\u0073\u0073\u0069\u0066i\u0065\u0064\u0050\u0061\u0067\u0065";var _de map[int ]int ;_adb :=_bgd ._bc ;_dbe :=[]*_db .Header {_gaf };if len (_bgd ._eg [_cc .PageNumber ])> 0{_de =map[int ]int {};_aadb ,_dfb :=_bgd .addSymbolDictionary (_cc .PageNumber ,_bgd .Classer .UndilatedTemplates ,_bgd ._eg [_cc .PageNumber ],_de ,false );if _dfb !=nil {return _fa .Wrap (_dfb ,_bdd ,"");};_dbe =append (_dbe ,_a