HomeUniDoc
...

Package document

Overview ▾

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

Index ▾

type Document
    func DecodeDocument(input bitwise.StreamReader, globals *Globals) (*Document, error)
    func InitEncodeDocument(fullHeaders bool) *Document
    func (d *Document) AddClassifiedPage(bm *bitmap.Bitmap, method classer.Method) (err error)
    func (d *Document) AddGenericPage(bm *bitmap.Bitmap, duplicateLineRemoval bool) (err error)
    func (d *Document) Encode() (data []byte, err error)
    func (d *Document) GetGlobalSegment(i int) (*segments.Header, error)
    func (d *Document) GetNumberOfPages() (uint32, error)
    func (d *Document) GetPage(pageNumber int) (segments.Pager, error)
type EncodingMethod
type Globals
    func (g *Globals) AddSegment(segment *segments.Header)
    func (g *Globals) GetSegment(segmentNumber int) (*segments.Header, error)
    func (g *Globals) GetSegmentByIndex(index int) (*segments.Header, error)
    func (g *Globals) GetSymbolDictionary() (*segments.Header, error)
type Page
    func (p *Page) AddEndOfPageSegment()
    func (p *Page) AddGenericRegion(bm *bitmap.Bitmap, xloc, yloc, template int, tp segments.Type, duplicateLineRemoval bool) error
    func (p *Page) AddPageInformationSegment()
    func (p *Page) Encode(w bitwise.BinaryWriter) (n int, err error)
    func (p *Page) GetBitmap() (bm *bitmap.Bitmap, err error)
    func (p *Page) GetHeight() (int, error)
    func (p *Page) GetResolutionX() (int, error)
    func (p *Page) GetResolutionY() (int, error)
    func (p *Page) GetSegment(number int) (*segments.Header, error)
    func (p *Page) GetWidth() (int, error)
    func (p *Page) String() string

Package files

doc.go document.go globals.go page.go

type Document

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

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

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

EncodingMethod defines the method of encoding for given page,

type EncodingMethod int

enums that defines encoding method.

const (
    GenericEM EncodingMethod = iota
    CorrelationEM
    RankHausEM
)

type Globals

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 (*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

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 (*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 bitwise.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.

Subdirectories

Name Synopsis
..