Documenter is the interface used for the document model.
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, error)
}
EncodeInitializer is the interface used to initialize the segments for the encode process.
type EncodeInitializer interface {
// InitEncode initializes the segment for the encode method purpose.
InitEncode()
}
EndOfStripe flags an end of stripe - see 7.4.9.
type EndOfStripe struct {
// contains filtered or unexported fields
}
func (e *EndOfStripe) Init(h *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
func (e *EndOfStripe) LineNumber() int
LineNumber gets the EndOfStripe line number.
GenericRefinementRegion represtents jbig2 generic refinement region segment - 7.4.7.
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 int32
ReferenceDY int32
// contains filtered or unexported fields
}
func (g *GenericRefinementRegion) GetRegionBitmap() (*bitmap.Bitmap, error)
GetRegionBitmap implements Regioner interface.
func (g *GenericRefinementRegion) GetRegionInfo() *RegionSegment
GetRegionInfo implements Regioner interface.
func (g *GenericRefinementRegion) Init(header *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
func (g *GenericRefinementRegion) String() string
String implements the Stringer interface.
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.
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
}
func NewGenericRegion(r bitwise.StreamReader) *GenericRegion
NewGenericRegion creates new GenericRegion segment.
func (g *GenericRegion) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode implements SegmentEncoder interface.
func (g *GenericRegion) GetRegionBitmap() (bm *bitmap.Bitmap, err error)
GetRegionBitmap gets the bitmap for the generic region segment.
func (g *GenericRegion) GetRegionInfo() *RegionSegment
GetRegionInfo implements Regioner interface.
func (g *GenericRegion) Init(h *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
func (g *GenericRegion) InitEncode(bm *bitmap.Bitmap, xLoc, yLoc, template int, duplicateLineRemoval bool) error
InitEncode initializes the generic region for the provided bitmap 'bm', it's 'xLoc', 'yLoc' locations and if it has to remove duplicated lines.
func (g *GenericRegion) Size() int
Size returns the byte size of the generic region.
func (g *GenericRegion) String() string
String implements Stringer interface.
HalftoneRegion is the model for the jbig2 halftone region segment implementation - 7.4.5.1.
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 int8
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 uint32
// Height of the gray-scale image, 7.4.5.1.2.2
HGridHeight uint32
// Horizontal offset of the grid, 7.4.5.1.2.3
HGridX int32
// Vertical offset of the grid, 7.4.5.1.2.4
HGridY int32
// Halftone grid vector, 7.4.5.1.3
// Horizontal coordinate of the halftone grid vector, 7.4.5.1.3.1
HRegionX uint16
// Vertical coordinate of the halftone grod vector, 7.4.5.1.3.2
HRegionY uint16
// 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
}
func (h *HalftoneRegion) GetPatterns() ([]*bitmap.Bitmap, error)
GetPatterns gets the HalftoneRegion patterns.
func (h *HalftoneRegion) GetRegionBitmap() (*bitmap.Bitmap, error)
GetRegionBitmap implements Regioner interface.
func (h *HalftoneRegion) GetRegionInfo() *RegionSegment
GetRegionInfo implements Regioner interface.
func (h *HalftoneRegion) Init(hd *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
Header is the segment header used to define the segment parameters - see 7.2.
type Header struct {
SegmentNumber uint32
Type Type
RetainFlag bool
PageAssociation int
PageAssociationFieldSize bool
RTSegments []*Header
HeaderLength int64
SegmentDataLength uint64
SegmentDataStartOffset uint64
Reader bitwise.StreamReader
SegmentData Segmenter
// RTSNumbers is the list of numbers where the segment is referred to.
RTSNumbers []int
// RetainBits are the flags for the given segment.
RetainBits []uint8
}
func NewHeader(d Documenter, r bitwise.StreamReader, offset int64, organizationType OrganizationType) (*Header, error)
NewHeader creates new segment header for the provided document from the stream reader.
func (h *Header) CleanSegmentData()
CleanSegmentData cleans the segment's data setting its segment data to nil.
func (h *Header) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode encodes the jbi2 header structure to the provided 'w' BinaryWriter.
func (h *Header) GetSegmentData() (Segmenter, error)
GetSegmentData gets the segment's data returning the Segmenter instance.
func (h *Header) String() string
String implements Stringer interface.
OrganizationType is the enum for the stream sequence organization.
type OrganizationType uint8
Organization types defined in D.4.2. - File header bit 0 defines the stream sequence organization.
const (
ORandom OrganizationType = iota
OSequential
)
PageInformationSegment represents the segment type Page Information 7.4.8.
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
DefaultPixelValue uint8
IsLossless bool
// Page striping information, two byte 7.4.8.6
IsStripe bool
MaxStripeSize uint16
// contains filtered or unexported fields
}
func (p *PageInformationSegment) CombinationOperator() bitmap.CombinationOperator
CombinationOperator gets the combination operator used by the page information segment.
func (p *PageInformationSegment) CombinationOperatorOverrideAllowed() bool
CombinationOperatorOverrideAllowed defines if the Page segment has allowed override.
func (p *PageInformationSegment) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode implements SegmentEncoder interface.
func (p *PageInformationSegment) Init(h *Header, r bitwise.StreamReader) (err error)
Init implements Segmenter interface.
func (p *PageInformationSegment) Size() int
Size returns the byte size of the page information segment data. The page information segment is composed of: - bitmap width - 4 bytes - bitmap height - 4 bytes - x resolution - 4 bytes - y resolution - 4 bytes - flags - 1 byte - stripping information - 2 bytes Total 19 bytes
func (p *PageInformationSegment) String() string
String implements Stringer interface.
Pager is the interface used as a Page model.
type Pager interface {
// GetSegment gets the segment Header with the given segment number.
GetSegment(int) (*Header, error)
// GetBitmap gets the decoded bitmap.Bitmap.
GetBitmap() (*bitmap.Bitmap, error)
}
PatternDictionary is the jbig2 model for the pattern dictionary segment - 7.4.4.
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 uint32
// contains filtered or unexported fields
}
func (p *PatternDictionary) GetDictionary() ([]*bitmap.Bitmap, error)
GetDictionary gets the PatternDictionary segment Dictionary bitmaps.
func (p *PatternDictionary) Init(h *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
RegionSegment is the model representing base jbig2 segment region - see 7.4.1.
type RegionSegment struct {
// Region segment bitmap width, 7.4.1.1
BitmapWidth uint32
// Region segment bitmap height, 7.4.1.2
BitmapHeight uint32
// Region segment bitmap X location, 7.4.1.3
XLocation uint32
// Region segment bitmap Y location, 7.4.1.4
YLocation uint32
// Region segment flags, 7.4.1.5
CombinaionOperator bitmap.CombinationOperator
// contains filtered or unexported fields
}
func NewRegionSegment(r bitwise.StreamReader) *RegionSegment
NewRegionSegment creates new Region segment model.
func (r *RegionSegment) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode implements the SegmentEncoder interface.
func (r *RegionSegment) Size() int
Size returns the bytewise size of the region segment.
func (r *RegionSegment) String() string
String implements the Stringer interface.
Regioner is the interface for all JBIG2 region segments.
type Regioner interface {
// GetRegionBitmap decodes and returns a regions content.
GetRegionBitmap() (*bitmap.Bitmap, error)
// GetRegionInfo returns RegionSegment information.
GetRegionInfo() *RegionSegment
}
SegmentEncoder is the interface used for encoding single segment instances.
type SegmentEncoder interface {
// Encode encodes the segment and write into 'w' writer.
Encode(w bitwise.BinaryWriter) (n int, err error)
}
Segmenter is the interface for all data pars of segments.
type Segmenter interface {
// Init initializes the segment from the provided data stream 'r'.
Init(header *Header, r bitwise.StreamReader) error
}
SymbolDictionary is the model for the JBIG2 Symbol Dictionary Segment - see 7.4.2.
type SymbolDictionary struct {
// Symbol Dictionary flags, 7.4.2.1.1
SdrTemplate int8
SdTemplate int8
SdHuffAggInstanceSelection bool
SdHuffBMSizeSelection int8
SdHuffDecodeWidthSelection int8
SdHuffDecodeHeightSelection int8
UseRefinementAggregation bool
IsHuffmanEncoded bool
// Symbol Dictionary AT flags 7.4.2.1.2
SdATX []int8
SdATY []int8
// Symbol Dictionary refinement AT flags 7.4.2.1.3
SdrATX []int8
SdrATY []int8
// Number of exported symbols, 7.4.2.1.4
NumberOfExportedSymbols uint32
// Number of new symbols 7.4.2.1.5
NumberOfNewSymbols uint32
// Further parameters
Header *Header
// contains filtered or unexported fields
}
func (s *SymbolDictionary) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode encodes the symbol dictionary structure into 'w' writer. Returns number of bytes written and the error if occurs.
func (s *SymbolDictionary) GetDictionary() ([]*bitmap.Bitmap, error)
GetDictionary gets the decoded dictionary symbols as a bitmap slice.
func (s *SymbolDictionary) Init(h *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
func (s *SymbolDictionary) InitEncode(symbols *bitmap.Bitmaps, symbolList []int, symbolMap map[int]int, unborderSymbols bool) error
InitEncode initializes the symbol dictionary for the encode method.
func (s *SymbolDictionary) String() string
String implements the Stringer interface.
TableSegment is the model used for user defined Huffman Table Segment - see 7.4.13 and appendix B.
type TableSegment struct {
// contains filtered or unexported fields
}
func (t *TableSegment) HtHigh() int32
HtHigh implements huffman.BasicTabler interface.
func (t *TableSegment) HtLow() int32
HtLow implements huffman.BasicTabler interface.
func (t *TableSegment) HtOOB() int32
HtOOB implements huffman.BasicTabler interface.
func (t *TableSegment) HtPS() int32
HtPS implements huffman.BasicTabler interface.
func (t *TableSegment) HtRS() int32
HtRS implements huffman.BasicTabler interface.
func (t *TableSegment) Init(h *Header, r bitwise.StreamReader) error
Init initializes the table segment. Implements Segmenter interface.
func (t *TableSegment) StreamReader() bitwise.StreamReader
StreamReader implements huffman.BasicTabler interface.
TextRegion is the model for the jbig2 text region segment - see 7.4.1.
type TextRegion struct {
// Region segment information field 7.4.1.
RegionInfo *RegionSegment
// Text Region segment flags 7.4.3.1.1.
SbrTemplate int8
SbDsOffset int8
DefaultPixel int8
CombinationOperator bitmap.CombinationOperator
IsTransposed int8
ReferenceCorner int16
LogSBStrips int16
UseRefinement bool
IsHuffmanEncoded bool
// Text region segment huffman flags 7.4.3.1.2.
SbHuffRSize int8
SbHuffRDY int8
SbHuffRDX int8
SbHuffRDHeight int8
SbHuffRDWidth int8
SbHuffDT int8
SbHuffDS int8
SbHuffFS int8
// Text region refinement AT flags 7.4.3.1.3.
SbrATX []int8
SbrATY []int8
// Number of symbol instances 7.4.3.1.3.
NumberOfSymbolInstances uint32
SbStrips int8
NumberOfSymbols uint32
RegionBitmap *bitmap.Bitmap
Symbols []*bitmap.Bitmap
Header *Header
// contains filtered or unexported fields
}
func (t *TextRegion) Encode(w bitwise.BinaryWriter) (n int, err error)
Encode writes the TextRegion segment data into 'w' binary writer.
func (t *TextRegion) GetRegionBitmap() (*bitmap.Bitmap, error)
GetRegionBitmap implements Regioner interface.
func (t *TextRegion) GetRegionInfo() *RegionSegment
GetRegionInfo implements Regioner interface.
func (t *TextRegion) Init(header *Header, r bitwise.StreamReader) error
Init implements Segmenter interface.
func (t *TextRegion) InitEncode(globalSymbolsMap, localSymbolsMap map[int]int, comps []int, inLL *bitmap.Points, symbols *bitmap.Bitmaps, classIDs *basic.IntSlice, boxes *bitmap.Boxes, width, height, symBits int)
InitEncode initializes text region for the Encode method.
func (t *TextRegion) String() string
String implements the Stringer interface.
Type defines the jbig2 segment type - see 7.3.
type Type int
Enumerate segment type definitions.
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
)
func (k Type) String() string
String implements Stringer interface.