Skip to content

Commit

Permalink
Added dummy encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilliams97 committed Aug 7, 2017
1 parent 008469d commit 38fa0f1
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pdf/contentstream/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func newEncoderFromInlineImage(inlineImage *ContentStreamInlineImage) (StreamEnc
return newFlateEncoderFromInlineImage(inlineImage, nil)
} else if *filterName == "LZW" {
return newLZWEncoderFromInlineImage(inlineImage, nil)
} else if *filterName == "CCF" {
return NewCCITTFaxEncoder(), nil
} else {
common.Log.Debug("Unsupported inline image encoding filter name : %s", *filterName)
return nil, errors.New("Unsupported inline encoding method")
Expand Down
113 changes: 112 additions & 1 deletion pdf/core/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ package core
// - RunLength
// - ASCII Hex
// - ASCII85
// - CCITT Fax (dummy)
// - JBIG2 (dummy)
// - JPX (dummy)

import (
"bytes"
Expand Down Expand Up @@ -40,6 +43,9 @@ const (
StreamEncodingFilterNameRunLength = "RunLengthDecode"
StreamEncodingFilterNameASCIIHex = "ASCIIHexDecode"
StreamEncodingFilterNameASCII85 = "ASCII85Decode"
StreamEncodingFilterNameCCITTFax = "CCITTFaxDecode"
StreamEncodingFilterNameJBIG2 = "JBIG2Decode"
StreamEncodingFilterNameJPX = "JPXDecode"
StreamEncodingFilterNameRaw = "Raw"
)

Expand Down Expand Up @@ -239,7 +245,7 @@ func (this *FlateEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, erro
common.Log.Trace("FlateDecode stream")
common.Log.Trace("Predictor: %d", this.Predictor)
if this.BitsPerComponent != 8 {
return nil, fmt.Errorf("Invalid BitsPerComponent (only 8 supported)")
return nil, fmt.Errorf("Invalid BitsPerComponent=%d (only 8 supported)", this.BitsPerComponent)
}

outData, err := this.DecodeBytes(streamObj.Stream)
Expand Down Expand Up @@ -1489,6 +1495,111 @@ func (this *RawEncoder) EncodeBytes(data []byte) ([]byte, error) {
return data, nil
}

//
// CCITTFax encoder/decoder (dummy, for now)
//
type CCITTFaxEncoder struct{}

func NewCCITTFaxEncoder() *CCITTFaxEncoder {
return &CCITTFaxEncoder{}
}

func (this *CCITTFaxEncoder) GetFilterName() string {
return StreamEncodingFilterNameCCITTFax
}

func (this *CCITTFaxEncoder) MakeDecodeParams() PdfObject {
return nil
}

// Make a new instance of an encoding dictionary for a stream object.
func (this *CCITTFaxEncoder) MakeStreamDict() *PdfObjectDictionary {
return MakeDict()
}

func (this *CCITTFaxEncoder) DecodeBytes(encoded []byte) ([]byte, error) {
panic(ErrNoCCITTFaxDecode)
return encoded, ErrNoCCITTFaxDecode
}

func (this *CCITTFaxEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) {
panic(ErrNoCCITTFaxDecode)
return streamObj.Stream, ErrNoCCITTFaxDecode
}

func (this *CCITTFaxEncoder) EncodeBytes(data []byte) ([]byte, error) {
panic(ErrNoCCITTFaxDecode)
return data, ErrNoCCITTFaxDecode
}

//
// JBIG2 encoder/decoder (dummy, for now)
//
type JBIG2Encoder struct{}

func NewJBIG2Encoder() *JBIG2Encoder {
return &JBIG2Encoder{}
}

func (this *JBIG2Encoder) GetFilterName() string {
return StreamEncodingFilterNameJBIG2
}

func (this *JBIG2Encoder) MakeDecodeParams() PdfObject {
return nil
}

// Make a new instance of an encoding dictionary for a stream object.
func (this *JBIG2Encoder) MakeStreamDict() *PdfObjectDictionary {
return MakeDict()
}

func (this *JBIG2Encoder) DecodeBytes(encoded []byte) ([]byte, error) {
return encoded, ErrNoJBIG2Decode
}

func (this *JBIG2Encoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) {
return streamObj.Stream, ErrNoJBIG2Decode
}

func (this *JBIG2Encoder) EncodeBytes(data []byte) ([]byte, error) {
return data, ErrNoJBIG2Decode
}

//
// JPX encoder/decoder (dummy, for now)
//
type JPXEncoder struct{}

func NewJPXEncoder() *JPXEncoder {
return &JPXEncoder{}
}

func (this *JPXEncoder) GetFilterName() string {
return StreamEncodingFilterNameJPX
}

func (this *JPXEncoder) MakeDecodeParams() PdfObject {
return nil
}

// Make a new instance of an encoding dictionary for a stream object.
func (this *JPXEncoder) MakeStreamDict() *PdfObjectDictionary {
return MakeDict()
}

func (this *JPXEncoder) DecodeBytes(encoded []byte) ([]byte, error) {
return encoded, ErrNoJPXDecode
}

func (this *JPXEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) {
return streamObj.Stream, ErrNoJPXDecode
}

func (this *JPXEncoder) EncodeBytes(data []byte) ([]byte, error) {
return data, ErrNoJPXDecode
}

//
// Multi encoder: support serial encoding.
//
Expand Down
6 changes: 6 additions & 0 deletions pdf/core/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func NewEncoderFromStream(streamObj *PdfObjectStream) (StreamEncoder, error) {
return NewASCIIHexEncoder(), nil
} else if *method == StreamEncodingFilterNameASCII85 {
return NewASCII85Encoder(), nil
} else if *method == StreamEncodingFilterNameCCITTFax {
return NewCCITTFaxEncoder(), nil
} else if *method == StreamEncodingFilterNameJBIG2 {
return NewJBIG2Encoder(), nil
} else if *method == StreamEncodingFilterNameJPX {
return NewJPXEncoder(), nil
} else {
common.Log.Debug("ERROR: Unsupported encoding method!")
return nil, fmt.Errorf("Unsupported encoding method (%s)", *method)
Expand Down

0 comments on commit 38fa0f1

Please sign in to comment.