document

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2023 License: AGPL-3.0, AGPL-3.0-only Imports: 13 Imported by: 0

Documentation

Overview

Package document provides jbig2 encoding primitives used for encoding and decoding purpose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	// Pages contains all pages of this document.
	Pages map[int]*Page
	// NumberOfPagesUnknown defines if the amout 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 wether extended Template is used.
	GBUseExtTemplate bool
	// SubInputStream is the source data stream wrapped into a SubInputStream.
	InputStream reader.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
}

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.

func DecodeDocument

func DecodeDocument(input reader.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

func InitEncodeDocument(fullHeaders bool) *Document

InitEncodeDocument initializes the jbig2 document for the encoding process.

func (*Document) AddClassifiedPage

func (d *Document) AddClassifiedPage(bm *bitmap.Bitmap, method classer.Method) (err error)

AddClassifiedPage adds the bitmap page with a classification 'method'.

func (*Document) AddGenericPage

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 (*Document) Encode

func (d *Document) Encode() (data []byte, err error)

Encode encodes the given document and stores into 'w' writer.

func (*Document) GetGlobalSegment

func (d *Document) GetGlobalSegment(i int) (*segments.Header, error)

GetGlobalSegment implements segments.Documenter interface.

func (*Document) GetNumberOfPages

func (d *Document) GetNumberOfPages() (uint32, error)

GetNumberOfPages gets the amount of Pages in the given document.

func (*Document) GetPage

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.

type EncodingMethod

type EncodingMethod int

EncodingMethod defines the method of encoding for given page,

const (
	GenericEM EncodingMethod = iota
	CorrelationEM
	RankHausEM
)

enums that defines encoding method.

type Globals

type Globals struct {
	Segments []*segments.Header
}

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.

func (*Globals) AddSegment

func (g *Globals) AddSegment(segment *segments.Header)

AddSegment adds the segment to the globals store.

func (*Globals) GetSegment

func (g *Globals) GetSegment(segmentNumber int) (*segments.Header, error)

GetSegment gets the global segment header.

func (*Globals) GetSegmentByIndex

func (g *Globals) GetSegmentByIndex(index int) (*segments.Header, error)

GetSegmentByIndex gets segments header by 'index' in the Globals.

func (*Globals) GetSymbolDictionary

func (g *Globals) GetSymbolDictionary() (*segments.Header, error)

GetSymbolDictionary gets global symbol dictionary.

type Page

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
}

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.

func (*Page) AddEndOfPageSegment

func (p *Page) AddEndOfPageSegment()

AddEndOfPageSegment adds the end of page segment.

func (*Page) AddGenericRegion

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 (*Page) AddPageInformationSegment

func (p *Page) AddPageInformationSegment()

AddPageInformationSegment adds the page information segment to the page segments.

func (*Page) Encode

func (p *Page) Encode(w writer.BinaryWriter) (n int, err error)

Encode encodes segments into provided 'w' writer.

func (*Page) GetBitmap

func (p *Page) GetBitmap() (bm *bitmap.Bitmap, err error)

GetBitmap implements segments.Pager interface.

func (*Page) GetHeight

func (p *Page) GetHeight() (int, error)

GetHeight gets the page height.

func (*Page) GetResolutionX

func (p *Page) GetResolutionX() (int, error)

GetResolutionX gets the 'x' resolution of the page.

func (*Page) GetResolutionY

func (p *Page) GetResolutionY() (int, error)

GetResolutionY gets the 'y' resolution of the page.

func (*Page) GetSegment

func (p *Page) GetSegment(number int) (*segments.Header, error)

GetSegment implements segments.Pager interface.

func (*Page) GetWidth

func (p *Page) GetWidth() (int, error)

GetWidth gets the page width.

func (*Page) String

func (p *Page) String() string

String implements Stringer interface.

Directories

Path Synopsis
Package segments provides jbig2 segments models used in the jbig2 document decoding process.
Package segments provides jbig2 segments models used in the jbig2 document decoding process.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL