Document is the jbig2 document model containing pages and global segments. By creating new document with method New or NewWithGlobals all the jbig2 encoded data segment headers are decoded. In order to decode whole document, all of it's pages should be decoded using GetBitmap method. PDF encoded documents should contains only one Page with the number 1.
type Document struct { // Pages contains all pages of this document. Pages map[int]*Page // NumberOfPagesUnknown defines if the amount of the pages is known. NumberOfPagesUnknown bool // NumberOfPages - D.4.3 - Number of pages field (4 bytes). Only presented if NumberOfPagesUnknown is true. NumberOfPages uint32 // GBUseExtTemplate defines whether extended Template is used. GBUseExtTemplate bool // InputStream is the source data stream. InputStream bitwise.StreamReader // GlobalSegments contains all segments that aren't associated with a page. GlobalSegments *Globals // OrganizationType is the document segment organization. OrganizationType segments.OrganizationType // Encoder variables // Classer is the document encoding classifier. Classer *classer.Classer // XRes and YRes are the PPI for the x and y direction. XRes, YRes int // FullHeaders is a flag that defines if the encoder should produce full JBIG2 files. FullHeaders bool // CurrentSegmentNumber current symbol number. CurrentSegmentNumber uint32 // AverageTemplates are the grayed templates. AverageTemplates *bitmap.Bitmaps BaseIndexes []int Refinement bool RefineLevel int EncodeGlobals bool // contains filtered or unexported fields }
func DecodeDocument(input bitwise.StreamReader, globals *Globals) (*Document, error)
DecodeDocument decodes provided document based on the provided 'input' data stream and with optional Global defined segments 'globals'.
func InitEncodeDocument(fullHeaders bool) *Document
InitEncodeDocument initializes the jbig2 document for the encoding process.
func (d *Document) AddClassifiedPage(bm *bitmap.Bitmap, method classer.Method) (err error)
AddClassifiedPage adds the bitmap page with a classification 'method'.
func (d *Document) AddGenericPage(bm *bitmap.Bitmap, duplicateLineRemoval bool) (err error)
AddGenericPage creates the jbig2 page based on the provided bitmap. The data provided
func (d *Document) Encode() (data []byte, err error)
Encode encodes the given document and stores into 'w' writer.
func (d *Document) GetGlobalSegment(i int) (*segments.Header, error)
GetGlobalSegment implements segments.Documenter interface.
func (d *Document) GetNumberOfPages() (uint32, error)
GetNumberOfPages gets the amount of Pages in the given document.
func (d *Document) GetPage(pageNumber int) (segments.Pager, error)
GetPage implements segments.Documenter interface. NOTE: in order to decode all document images, get page by page (page numeration starts from '1') and decode them by calling 'GetBitmap' method.
EncodingMethod defines the method of encoding for given page,
type EncodingMethod int
enums that defines encoding method.
const ( GenericEM EncodingMethod = iota CorrelationEM RankHausEM )
Globals store segments that aren't associated to a page. If the data is embedded in another format, for example PDF, this segments might be stored separately in the file. These segments will be decoded on demand, all results are stored in the document.
type Globals struct { Segments []*segments.Header }
func (g *Globals) AddSegment(segment *segments.Header)
AddSegment adds the segment to the globals store.
func (g *Globals) GetSegment(segmentNumber int) (*segments.Header, error)
GetSegment gets the global segment header.
func (g *Globals) GetSegmentByIndex(index int) (*segments.Header, error)
GetSegmentByIndex gets segments header by 'index' in the Globals.
func (g *Globals) GetSymbolDictionary() (*segments.Header, error)
GetSymbolDictionary gets global symbol dictionary.
Page represents JBIG2 Page structure. It contains all the included segments header definitions mapped to their number relation to the document and the resultant page bitmap. NOTE: page numeration starts from 1 and the association to 0'th page means the segments are associated to global segments.
type Page struct { // Segments relation of the page number to their structures. Segments []*segments.Header // PageNumber defines this page number. PageNumber int // Bitmap represents the page image. Bitmap *bitmap.Bitmap // Page parameters FinalHeight int FinalWidth int ResolutionX int ResolutionY int IsLossless bool // Document is a relation to page's document Document *Document // FirstSegmentNumber defines first segment number for given page FirstSegmentNumber int // EncodingMethod defines EncodingMethod EncodingMethod BlackIsOne bool }
func (p *Page) AddEndOfPageSegment()
AddEndOfPageSegment adds the end of page segment.
func (p *Page) AddGenericRegion(bm *bitmap.Bitmap, xloc, yloc, template int, tp segments.Type, duplicateLineRemoval bool) error
AddGenericRegion adds the generic region to the page context. 'bm' - bitmap containing data to encode 'xloc' - x location of the generic region 'yloc' - y location of the generic region 'template' - generic region template 'tp' - is the generic region type 'duplicateLineRemoval' - is the flag that defines if the generic region segment should remove duplicated lines
func (p *Page) AddPageInformationSegment()
AddPageInformationSegment adds the page information segment to the page segments.
func (p *Page) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode encodes segments into provided 'w' writer.
func (p *Page) GetBitmap() (bm *bitmap.Bitmap, err error)
GetBitmap implements segments.Pager interface.
func (p *Page) GetHeight() (int, error)
GetHeight gets the page height.
func (p *Page) GetResolutionX() (int, error)
GetResolutionX gets the 'x' resolution of the page.
func (p *Page) GetResolutionY() (int, error)
GetResolutionY gets the 'y' resolution of the page.
func (p *Page) GetSegment(number int) (*segments.Header, error)
GetSegment implements segments.Pager interface.
func (p *Page) GetWidth() (int, error)
GetWidth gets the page width.
func (p *Page) String() string
String implements Stringer interface.
Name | Synopsis |
---|---|
.. |