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-09-14 09:32:45 +00:00
package document ;import (_ed "encoding/binary";_g "fmt";_ec "github.com/unidoc/unipdf/v3/common";_cg "github.com/unidoc/unipdf/v3/internal/bitwise";_fb "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_b "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_ecc "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_gg "github.com/unidoc/unipdf/v3/internal/jbig2/encoder/classer";_cd "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_c "io";_a "math";_f "runtime/debug";);func (_cgc *Document )addSymbolDictionary (_cege int ,_fee *_b .Bitmaps ,_cba []int ,_add map[int ]int ,_de bool )(*_ecc .Header ,error ){const _eab ="\u0061\u0064\u0064\u0053ym\u0062\u006f\u006c\u0044\u0069\u0063\u0074\u0069\u006f\u006e\u0061\u0072\u0079";_ba :=&_ecc .SymbolDictionary {};if _bbg :=_ba .InitEncode (_fee ,_cba ,_add ,_de );_bbg !=nil {return nil ,_bbg ;};_be :=&_ecc .Header {Type :_ecc .TSymbolDictionary ,PageAssociation :_cege ,SegmentData :_ba };if _cege ==0{if _cgc .GlobalSegments ==nil {_cgc .GlobalSegments =&Globals {};};_cgc .GlobalSegments .AddSegment (_be );return _be ,nil ;};_cgd ,_gf :=_cgc .Pages [_cege ];if !_gf {return nil ,_cd .Errorf (_eab ,"p\u0061g\u0065\u003a\u0020\u0027\u0025\u0064\u0027\u0020n\u006f\u0074\u0020\u0066ou\u006e\u0064",_cege );};var (_db int ;_fea *_ecc .Header ;);for _db ,_fea =range _cgd .Segments {if _fea .Type ==_ecc .TPageInformation {break ;};};_db ++;_cgd .Segments =append (_cgd .Segments ,nil );copy (_cgd .Segments [_db +1:],_cgd .Segments [_db :]);_cgd .Segments [_db ]=_be ;return _be ,nil ;};func _gcc (_dde _cg .StreamReader ,_gcb *Globals )(*Document ,error ){_cbe :=&Document {Pages :make (map[int ]*Page ),InputStream :_dde ,OrganizationType :_ecc .OSequential ,NumberOfPagesUnknown :true ,GlobalSegments :_gcb ,_fe :9};if _cbe .GlobalSegments ==nil {_cbe .GlobalSegments =&Globals {};};if _afbd :=_cbe .mapData ();_afbd !=nil {return nil ,_afbd ;};return _cbe ,nil ;};func (_degff *Page )getResolutionY ()(int ,error ){const _eceb ="\u0067\u0065\u0074\u0052\u0065\u0073\u006f\u006c\u0075t\u0069\u006f\u006e\u0059";if _degff .ResolutionY !=0{return _degff .ResolutionY ,nil ;};_bffg :=_degff .getPageInformationSegment ();if _bffg ==nil {return 0,_cd .Error (_eceb ,"n\u0069l\u0020\u0070\u0061\u0067\u0065\u0020\u0069\u006ef\u006f\u0072\u006d\u0061ti\u006f\u006e");};_ddd ,_edgag :=_bffg .GetSegmentData ();if _edgag !=nil {return 0,_cd .Wrap (_edgag ,_eceb ,"");};_bgb ,_daa :=_ddd .(*_ecc .PageInformationSegment );if !_daa {return 0,_cd .Errorf (_eceb ,"\u0070\u0061\u0067\u0065\u0020\u0069\u006e\u0066o\u0072\u006d\u0061ti\u006f\u006e\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0020\u0069\u0073\u0020\u006f\u0066\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0074\u0079\u0070\u0065\u003a\u0027%\u0054\u0027",_ddd );};_degff .ResolutionY =_bgb .ResolutionY ;return _degff .ResolutionY ,nil ;};func (_egc *Document )encodeEOFHeader (_ega _cg .BinaryWriter )(_bgg int ,_dgf error ){_fbb :=&_ecc .Header {SegmentNumber :_egc .nextSegmentNumber (),Type :_ecc .TEndOfFile };if _bgg ,_dgf =_fbb .Encode (_ega );_dgf !=nil {return 0,_cd .Wrap (_dgf ,"\u0065n\u0063o\u0064\u0065\u0045\u004f\u0046\u0048\u0065\u0061\u0064\u0065\u0072","");};return _bgg ,nil ;};func (_eccb *Document )produceClassifiedPage (_dc *Page ,_eef *_ecc .Header )(_ad error ){const _ab ="p\u0072\u006f\u0064\u0075ce\u0043l\u0061\u0073\u0073\u0069\u0066i\u0065\u0064\u0050\u0061\u0067\u0065";var _bbd map[int ]int ;_fad :=_eccb ._ce ;_gcg :=[]*_ecc .Header {_eef };if len (_eccb ._fa [_dc .PageNumber ])> 0{_bbd =map[int ]int {};_ebf ,_cf :=_eccb .addSymbolDictionary (_dc .PageNumber ,_eccb .Classer .UndilatedTemplates ,_eccb ._fa [_dc .PageNumber ],_bbd ,false );if _cf !=nil {return _cd .Wrap (_cf ,_ab ,"");};_gcg =append (_gcg ,_ebf );_fad +=len (_eccb ._fa [_dc .PageNumber ]);};_fge :=_eccb ._d [_dc .PageNumber ];_ec .Log .Debug ("P\u0061g\u0065\u003a\u0020\u0027\u0025\u0064\u0027\u0020c\u006f\u006d\u0070\u0073: \u0025\u0076",_dc .PageNumber ,_fge );_dc .addTextRegionSegment (_gcg ,_eccb ._bb ,_bbd ,_eccb ._d [_dc .PageNumber ],_eccb .Classer .