segments

package
v0.0.0-...-fb73569 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Documenter

type Documenter interface {
	// GetPage gets the page at given page number.
	GetPage(int) (Pager, error)

	// GetGlobalSegment gets the global segment header at given segment number.
	GetGlobalSegment(int) *Header
}

Documenter is the interface used for the document model.

type EndOfStripe

type EndOfStripe struct {
	// contains filtered or unexported fields
}

EndOfStripe flags an end of stripe - see 7.4.9.

func (*EndOfStripe) Init

func (e *EndOfStripe) Init(h *Header, r reader.StreamReader) error

Init implements Segmenter interface.

func (*EndOfStripe) LineNumber

func (e *EndOfStripe) LineNumber() int

LineNumber gets the EndOfStripe line number.

type GenericRefinementRegion

type GenericRefinementRegion struct {

	// Region segment information flags 7.4.1.
	RegionInfo *RegionSegment

	// Generic refinement region segment flags 7.4.7.2.
	IsTPGROn   bool
	TemplateID int8

	Template templater

	// Generic refinement region segment AT flags 7.4.7.3.
	GrAtX []int8
	GrAtY []int8

	// Decoded data as pixel values (use row stride/width to wrap line).
	RegionBitmap *bitmap.Bitmap

	// Variables for decoding.
	ReferenceBitmap *bitmap.Bitmap
	ReferenceDX     int
	ReferenceDY     int
	// contains filtered or unexported fields
}

GenericRefinementRegion represtents jbig2 generic refinement region segment - 7.4.7.

func (*GenericRefinementRegion) GetRegionBitmap

func (g *GenericRefinementRegion) GetRegionBitmap() (*bitmap.Bitmap, error)

GetRegionBitmap implements Regioner interface.

func (*GenericRefinementRegion) GetRegionInfo

func (g *GenericRefinementRegion) GetRegionInfo() *RegionSegment

GetRegionInfo implements Regioner interface.

func (*GenericRefinementRegion) Init

Init implements Segmenter interface.

func (*GenericRefinementRegion) String

func (g *GenericRefinementRegion) String() string

String implements the Stringer interface.

type GenericRegion

type GenericRegion struct {
	DataHeaderOffset int64
	DataHeaderLength int64
	DataOffset       int64
	DataLength       int64

	// Region segment information field, 7.4.1
	RegionSegment *RegionSegment

	// Generic region segment flags, 7.4.6.2
	UseExtTemplates bool
	IsTPGDon        bool
	GBTemplate      byte
	IsMMREncoded    bool

	UseMMR bool

	// Generic region segment AT flags, 7.4.6.3
	GBAtX        []int8
	GBAtY        []int8
	GBAtOverride []bool

	// Bitmap is the decoded generic region image.
	Bitmap *bitmap.Bitmap
	// contains filtered or unexported fields
}

GenericRegion represents a generic region segment. Parsing is done as described in 7.4.5. Decoding procedure is done as described in 6.2.5.7 and 7.4.6.4.

func NewGenericRegion

func NewGenericRegion(
	r reader.StreamReader,
) *GenericRegion

NewGenericRegion creates new GenericRegion segment.

func (*GenericRegion) GetRegionBitmap

func (g *GenericRegion) GetRegionBitmap() (bm *bitmap.Bitmap, err error)

GetRegionBitmap gets the bitmap for the generic region segment.

func (*GenericRegion) GetRegionInfo

func (g *GenericRegion) GetRegionInfo() *RegionSegment

GetRegionInfo implements Regioner interface.

func (*GenericRegion) Init

func (g *GenericRegion) Init(h *Header, r reader.StreamReader) error

Init implements Segmenter interface.

func (*GenericRegion) String

func (g *GenericRegion) String() string

String implements Stringer interface

type HalftoneRegion

type HalftoneRegion struct {
	DataHeaderOffset int64
	DataHeaderLength int64
	DataOffset       int64
	DataLength       int64

	// Region segment information field, 7.4.1.
	RegionSegment *RegionSegment

	// Halftone segment information field, 7.4.5.1.1.
	HDefaultPixel       int
	CombinationOperator bitmap.CombinationOperator
	HSkipEnabled        bool
	HTemplate           byte
	IsMMREncoded        bool

	// Halftone grid position and size, 7.4.5.1.2
	// Width of the gray-scale image, 7.4.5.1.2.1
	HGridWidth int
	// Height of the gray-scale image, 7.4.5.1.2.2
	HGridHeight int
	// Horizontal offset of the grid, 7.4.5.1.2.3
	HGridX int
	// Vertical offset of the grid, 7.4.5.1.2.4
	HGridY int

	// Halftone grid vector, 7.4.5.1.3
	// Horizontal coordinate of the halftone grid vector, 7.4.5.1.3.1
	HRegionX int
	// Vertical coordinate of the halftone grod vector, 7.4.5.1.3.2
	HRegionY int

	// Decoded data
	HalftoneRegionBitmap *bitmap.Bitmap

	// Previously decoded data from other regions or dictionaries, stored to use as patterns in this region.
	Patterns []*bitmap.Bitmap
	// contains filtered or unexported fields
}

HalftoneRegion is the model for the jbig2 halftone region segment implementation - 7.4.5.1.

func (*HalftoneRegion) GetPatterns

func (h *HalftoneRegion) GetPatterns() ([]*bitmap.Bitmap, error)

GetPatterns gets the HalftoneRegion patterns.

func (*HalftoneRegion) GetRegionBitmap

func (h *HalftoneRegion) GetRegionBitmap() (*bitmap.Bitmap, error)

GetRegionBitmap implements Regioner interface.

func (*HalftoneRegion) GetRegionInfo

func (h *HalftoneRegion) GetRegionInfo() *RegionSegment

GetRegionInfo implements Regioner interface.

func (*HalftoneRegion) Init

func (h *HalftoneRegion) Init(hd *Header, r reader.StreamReader) error

Init implements Segmenter interface.

type Header struct {
	SegmentNumber            uint32
	Type                     Type
	RetainFlag               bool
	PageAssociation          int
	PageAssociationFieldSize bool
	RTSegments               []*Header
	HeaderLength             int64
	SegmentDataLength        uint64
	SegmentDataStartOffset   uint64
	Reader                   reader.StreamReader
	SegmentData              Segmenter
	RTSNumbers               []int
}

Header is the segment header used to define the segment parameters - see 7.2.

func NewHeader

func NewHeader(
	d Documenter, r reader.StreamReader,
	offset int64, organizationType OrganizationType,
) (*Header, error)

NewHeader creates new segment header for the provided document from the stream reader.

func (*Header) CleanSegmentData

func (h *Header) CleanSegmentData()

CleanSegmentData cleans the segment's data setting it's segment data to nil.

func (*Header) GetSegmentData

func (h *Header) GetSegmentData() (Segmenter, error)

GetSegmentData gets the segment's data returning the Segmenter instance.

func (*Header) String

func (h *Header) String() string

String implements Stringer interface.

type OrganizationType

type OrganizationType uint8

OrganizationType is the enum for the stream sequence organization.

const (
	ORandom OrganizationType = iota
	OSequential
)

Organization types defined in D.4.2. - File header bit 0 defines the stream sequence organisation.

type PageInformationSegment

type PageInformationSegment struct {

	// Page bitmap height, four byte, 7.4.8.1
	PageBMHeight int

	// Page bitmap width, four byte, 7.4.8.1
	PageBMWidth int

	// Page X resolution, four byte 7.4.8.3
	ResolutionX int

	// Page Y resolution, four byte 7.4.8.4
	ResolutionY int

	// Page striping information, two byte 7.4.8.6
	IsStripe      bool
	MaxStripeSize uint16
	// contains filtered or unexported fields
}

PageInformationSegment represents the segment type Page Information 7.4.8.

func (*PageInformationSegment) CombinationOperator

func (p *PageInformationSegment) CombinationOperator() bitmap.CombinationOperator

CombinationOperator gets the combination operator used by the page information segment.

func (*PageInformationSegment) CombinationOperatorOverrideAllowed

func (p *PageInformationSegment) CombinationOperatorOverrideAllowed() bool

CombinationOperatorOverrideAllowed defines if the Page segment has allowed override.

func (*PageInformationSegment) DefaultPixelValue

func (p *PageInformationSegment) DefaultPixelValue() uint8

DefaultPixelValue returns page segment default pixel.

func (*PageInformationSegment) Init

Init implements Segmenter interface.

func (*PageInformationSegment) String

func (p *PageInformationSegment) String() string

String implements Stringer interface.

type Pager

type Pager interface {
	// GetSegment gets the segment Header with the given segment number.
	GetSegment(int) *Header

	// GetBitmap gets the decoded bitmap.Bitmap.
	GetBitmap() (*bitmap.Bitmap, error)
}

Pager is the interface used as a Page model.

type PatternDictionary

type PatternDictionary struct {
	DataHeaderOffset int64
	DataHeaderLength int64
	DataOffset       int64
	DataLength       int64

	GBAtX []int8
	GBAtY []int8

	// Flags 7.4.4.1.1
	IsMMREncoded bool
	HDTemplate   byte

	// Width of the patterns in the pattern dictionary
	HdpWidth byte
	// Height of the patterns in the pattern dictionary
	HdpHeight byte

	// Decoded bitmaps stored to be used by segments that refer to it
	Patterns []*bitmap.Bitmap

	// Largest gray-scale value 7.4.4.1.4
	GrayMax int
	// contains filtered or unexported fields
}

PatternDictionary is the jbig2 model for the pattern dictionary segment - 7.4.4.

func (*PatternDictionary) GetDictionary

func (p *PatternDictionary) GetDictionary() ([]*bitmap.Bitmap, error)

GetDictionary gets the PatternDictionary segment Dictionary bitmaps.

func (*PatternDictionary) Init

Init implements Segmenter interface.

type RegionSegment

type RegionSegment struct {

	// Region segment bitmap width, 7.4.1.1
	BitmapWidth int

	// Region segment bitmap height, 7.4.1.2
	BitmapHeight int

	// Region segment bitmap X location, 7.4.1.3
	XLocation int

	// Region segment bitmap Y location, 7.4.1.4
	YLocation int

	// Region segment flags, 7.4.1.5
	CombinaionOperator bitmap.CombinationOperator
	// contains filtered or unexported fields
}

RegionSegment is the model representing base jbig2 segment region - see 7.4.1.

func NewRegionSegment

func NewRegionSegment(r reader.StreamReader) *RegionSegment

NewRegionSegment creates new Region segment model.

func (*RegionSegment) String

func (r *RegionSegment) String() string

String implements the Stringer interface.

type Regioner

type Regioner interface {
	// GetRegionBitmap decodes and returns a regions content.
	GetRegionBitmap() (*bitmap.Bitmap, error)

	// GetRegionInfo returns RegionSegment information.
	GetRegionInfo() *RegionSegment
}

Regioner is the interface for all JBIG2 region segments.

type Segmenter

type Segmenter interface {
	// Init initializes the segment from the provided data stream 'r'.
	Init(header *Header, r reader.StreamReader) error
}

Segmenter is the interface for all data pars of segments.

type SymbolDictionary

type SymbolDictionary struct {

	// Further parameters
	Header *Header
	// contains filtered or unexported fields
}

SymbolDictionary is the model for the JBIG2 Symbol Dictionary Segment - see 7.4.2.

func (*SymbolDictionary) GetDictionary

func (s *SymbolDictionary) GetDictionary() ([]*bitmap.Bitmap, error)

GetDictionary gets the decoded dictionary symbols as a bitmap slice.

func (*SymbolDictionary) Init

Init implements Segmenter interface.

func (*SymbolDictionary) IsHuffmanEncoded

func (s *SymbolDictionary) IsHuffmanEncoded() bool

IsHuffmanEncoded defines if the segment is encoded using huffman tables.

func (*SymbolDictionary) NumberOfExportedSymbols

func (s *SymbolDictionary) NumberOfExportedSymbols() int

NumberOfExportedSymbols defines how many symbols are being exported by this SymbolDictionary.

func (*SymbolDictionary) NumberOfNewSymbols

func (s *SymbolDictionary) NumberOfNewSymbols() int

NumberOfNewSymbols returns the amount of new symbols defined by the Symbol Dictionary.

func (*SymbolDictionary) String

func (s *SymbolDictionary) String() string

String implements the Stringer interface.

func (*SymbolDictionary) UseRefinementAggregation

func (s *SymbolDictionary) UseRefinementAggregation() bool

UseRefinementAggregation defines if the SymbolDictionary uses refinement aggregation.

type TableSegment

type TableSegment struct {
	// contains filtered or unexported fields
}

TableSegment is the model used for user defined Huffman Table Segment - see 7.4.13 and appendix B.

func (*TableSegment) HtHigh

func (t *TableSegment) HtHigh() int

HtHigh implements huffman.BasicTabler interface.

func (*TableSegment) HtLow

func (t *TableSegment) HtLow() int

HtLow implements huffman.BasicTabler interface.

func (*TableSegment) HtOOB

func (t *TableSegment) HtOOB() int

HtOOB implements huffman.BasicTabler interface.

func (*TableSegment) HtPS

func (t *TableSegment) HtPS() int

HtPS implements huffman.BasicTabler interface.

func (*TableSegment) HtRS

func (t *TableSegment) HtRS() int

HtRS implements huffman.BasicTabler interface.

func (*TableSegment) Init

func (t *TableSegment) Init(h *Header, r reader.StreamReader) error

Init initializes the table segment. Implements Segmenter interface.

func (*TableSegment) StreamReader

func (t *TableSegment) StreamReader() reader.StreamReader

StreamReader implements huffman.BasicTabler interface.

type TextRegion

type TextRegion struct {
	Header *Header
	// contains filtered or unexported fields
}

TextRegion is the model for the jbig2 text region segment - see 7.4.1.

func (*TextRegion) GetRegionBitmap

func (t *TextRegion) GetRegionBitmap() (*bitmap.Bitmap, error)

GetRegionBitmap implements Regioner interface.

func (*TextRegion) GetRegionInfo

func (t *TextRegion) GetRegionInfo() *RegionSegment

GetRegionInfo implements Regioner interface.

func (*TextRegion) Init

func (t *TextRegion) Init(header *Header, r reader.StreamReader) error

Init implements Segmenter interface.

func (*TextRegion) String

func (t *TextRegion) String() string

String implements the Stringer interface.

type Type

type Type int

Type defines the jbig2 segment type - see 7.3.

const (
	TSymbolDictionary                         Type = 0
	TIntermediateTextRegion                   Type = 4
	TImmediateTextRegion                      Type = 6
	TImmediateLosslessTextRegion              Type = 7
	TPatternDictionary                        Type = 16
	TIntermediateHalftoneRegion               Type = 20
	TImmediateHalftoneRegion                  Type = 22
	TImmediateLosslessHalftoneRegion          Type = 23
	TIntermediateGenericRegion                Type = 36
	TImmediateGenericRegion                   Type = 38
	TImmediateLosslessGenericRegion           Type = 39
	TIntermediateGenericRefinementRegion      Type = 40
	TImmediateGenericRefinementRegion         Type = 42
	TImmediateLosslessGenericRefinementRegion Type = 43
	TPageInformation                          Type = 48
	TEndOfPage                                Type = 49
	TEndOfStrip                               Type = 50
	TEndOfFile                                Type = 51
	TProfiles                                 Type = 52
	TTables                                   Type = 53
	TExtension                                Type = 62
	TBitmap                                   Type = 70
)

Enumerate segment type definitions.

func (Type) String

func (k Type) String() string

String implements Stringer interface.

Jump to

Keyboard shortcuts

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