mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Ensure 90+% test coverage for ccittfaxdecode
This commit is contained in:
parent
f2b25b3eb5
commit
8c4bf0b4ef
22
main.go
22
main.go
@ -8,11 +8,11 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
unicommon "github.com/unidoc/unidoc/common"
|
||||
pdfcontent "github.com/unidoc/unidoc/pdf/contentstream"
|
||||
pdfcore "github.com/unidoc/unidoc/pdf/core"
|
||||
"github.com/unidoc/unidoc/pdf/core/ccittfaxdecode"
|
||||
"github.com/unidoc/unidoc/pdf/creator"
|
||||
pdf "github.com/unidoc/unidoc/pdf/model"
|
||||
)
|
||||
@ -93,7 +93,7 @@ var xObjectImages = 0
|
||||
var inlineImages = 0
|
||||
|
||||
func main() {
|
||||
image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
|
||||
/*image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
|
||||
file, err := os.Open("/home/darkrengarius/go/src/github.com/unidoc/unidoc/pdf/core/ccittfaxdecode/testdata/p3_0.png")
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening file: %v\n", err)
|
||||
@ -104,16 +104,17 @@ func main() {
|
||||
log.Fatalf("Error decoding the image: %v\n", err)
|
||||
}
|
||||
encoder := &ccittfaxdecode.Encoder{
|
||||
BlackIs1: true,
|
||||
Columns: 2560,
|
||||
K: -1,
|
||||
EndOfLine: false,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: false,
|
||||
Rows: 3295,
|
||||
EndOfBlock: true,
|
||||
//Rows: 3295,
|
||||
}
|
||||
encoded := encoder.Encode(pixels)
|
||||
|
||||
f, err := os.Create("/home/darkrengarius/Downloads/K-1-Columns2560-Aligned-Rows3295.gr4")
|
||||
f, err := os.Create("/home/darkrengarius/Downloads/BlackIs1-K-1-Columns2560-EOL-Aligned-EOFB.gr4")
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating file: %v\n", err)
|
||||
}
|
||||
@ -125,9 +126,9 @@ func main() {
|
||||
|
||||
f.Close()
|
||||
|
||||
log.Println()
|
||||
log.Println()*/
|
||||
|
||||
/*var files []string
|
||||
var files []string
|
||||
|
||||
err := filepath.Walk("/home/darkrengarius/Downloads/4111112", func(path string, info os.FileInfo, err error) error {
|
||||
if filepath.Ext(path) == ".png" {
|
||||
@ -139,9 +140,9 @@ func main() {
|
||||
log.Fatalf("Error scanning directory: %v\n", err)
|
||||
}
|
||||
|
||||
if err := imagesToPdf(files, "/home/darkrengarius/Downloads/testCombined4111112.pdf"); err != nil {
|
||||
if err := imagesToPdf(files, "/home/darkrengarius/Downloads/testCombined4111112_2.pdf"); err != nil {
|
||||
log.Fatalf("Error writing images to pdf: %v\n", err)
|
||||
}*/
|
||||
}
|
||||
|
||||
// extract images from pdf to zip
|
||||
inputPath := "/home/darkrengarius/Downloads/testCombined000141.pdf"
|
||||
@ -266,6 +267,7 @@ func imagesToPdf(inputPaths []string, outputPath string) error {
|
||||
encoder.EndOfLine = true
|
||||
encoder.EncodedByteAlign = true
|
||||
encoder.K = -1
|
||||
encoder.BlackIs1 = true
|
||||
img.SetEncoder(encoder)
|
||||
|
||||
img.SetPos(0, 0)
|
||||
|
@ -1133,6 +1133,342 @@ func TestDecode(t *testing.T) {
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-Aligned-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-Aligned-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-Aligned-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K0-Columns2560-Aligned-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-Aligned-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-Aligned-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-Aligned-Rows3295.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K4-Columns2560-Aligned-EOFB.gr3",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-Rows3295.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-Rows3295.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-EOFB.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-Aligned-Rows3295.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-Aligned-EOFB.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOFB.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-Aligned-Rows3295.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
InputFilePath: testDataPath + "BlackIs1-K-1-Columns2560-Aligned-EOFB.gr4",
|
||||
Want: testResult{
|
||||
Pixels: wantPixels,
|
||||
Err: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
@ -151,7 +151,9 @@ func (e *Encoder) encodeG32D(pixels [][]byte) []byte {
|
||||
return encoded
|
||||
}
|
||||
|
||||
func (e *Encoder) encodeG4(pixels [][]byte) []byte {
|
||||
func (e *Encoder) encodeG4(pixelsToEncode [][]byte) []byte {
|
||||
pixels := make([][]byte, len(pixelsToEncode))
|
||||
copy(pixels, pixelsToEncode)
|
||||
pixels = appendWhiteReferenceLine(pixels)
|
||||
|
||||
var encoded []byte
|
||||
@ -390,18 +392,6 @@ func (e *Encoder) appendEncodedRow(encoded, newRow []byte, bitPos int) []byte {
|
||||
return encoded
|
||||
}
|
||||
|
||||
func rightShiftArray(row []byte, shiftAmount int) []byte {
|
||||
for i := len(row) - 1; i >= 0; i-- {
|
||||
row[i] = row[i] >> uint(shiftAmount)
|
||||
|
||||
if i > 0 {
|
||||
row[i] |= row[i-1] << uint(8-shiftAmount)
|
||||
}
|
||||
}
|
||||
|
||||
return row
|
||||
}
|
||||
|
||||
// seekChangingElem gets the position of the changing elem in the row based on
|
||||
// the position of the currElem
|
||||
func seekChangingElem(row []byte, currElem int) int {
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ccittfaxdecode
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
@ -13,6 +15,8 @@ func TestEncode(t *testing.T) {
|
||||
WantFilePath string
|
||||
}
|
||||
|
||||
image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
|
||||
|
||||
pixels, err := getPixels(testDataPath + "p3_0.png")
|
||||
if err != nil {
|
||||
t.Fatalf("Error getting pixels from image: %v\n", err)
|
||||
@ -261,6 +265,272 @@ func TestEncode(t *testing.T) {
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "K-1-Columns2560-Rows3295.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-Aligned-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-Aligned-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-Aligned-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-Aligned-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-EOL-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 0,
|
||||
Columns: 2560,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K0-Columns2560-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-Aligned-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-Aligned-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-Aligned-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-Aligned-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-EOFB.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-EOL-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: 4,
|
||||
Columns: 2560,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K4-Columns2560-Rows3295.gr3",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-Aligned-EOFB.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
Columns: 2560,
|
||||
K: -1,
|
||||
EndOfLine: false,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: false,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-Aligned-Rows3295.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOFB.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-Aligned-EOFB.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EncodedByteAlign: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-Aligned-Rows3295.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
EndOfBlock: true,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-EOFB.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
EndOfLine: true,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-EOL-Rows3295.gr4",
|
||||
},
|
||||
{
|
||||
Encoder: &Encoder{
|
||||
BlackIs1: true,
|
||||
K: -1,
|
||||
Columns: 2560,
|
||||
Rows: 3295,
|
||||
},
|
||||
Pixels: pixels,
|
||||
WantFilePath: testDataPath + "BlackIs1-K-1-Columns2560-Rows3295.gr4",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-Aligned-EOFB.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-Aligned-EOFB.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-Aligned-Rows3295.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-Aligned-Rows3295.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOFB.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOFB.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-Aligned-EOFB.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-Aligned-EOFB.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-Aligned-Rows3295.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-Aligned-Rows3295.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-EOFB.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-EOFB.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-Rows3295.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-EOL-Rows3295.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-Rows3295.gr4
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K-1-Columns2560-Rows3295.gr4
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-Aligned-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-Aligned-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-Aligned-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-Aligned-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-Aligned-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-Aligned-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-Aligned-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-Aligned-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-EOL-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K0-Columns2560-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-Aligned-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-Aligned-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-Aligned-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-Aligned-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-Aligned-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-Aligned-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-Aligned-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-Aligned-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-EOFB.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-EOFB.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-EOL-Rows3295.gr3
vendored
Normal file
Binary file not shown.
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-Rows3295.gr3
vendored
Normal file
BIN
pdf/core/ccittfaxdecode/testdata/BlackIs1-K4-Columns2560-Rows3295.gr3
vendored
Normal file
Binary file not shown.
@ -1792,8 +1792,6 @@ func (this *CCITTFaxEncoder) DecodeBytes(encoded []byte) ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//decoded := make([]byte, int(math.Ceil(float64(float64(len(pixels)*len(pixels[0]))/8.0))))
|
||||
|
||||
var decoded []byte
|
||||
decodedIdx := 0
|
||||
var bitPos byte = 0
|
||||
@ -1806,7 +1804,6 @@ func (this *CCITTFaxEncoder) DecodeBytes(encoded []byte) ([]byte, error) {
|
||||
|
||||
if bitPos == 8 {
|
||||
decoded = append(decoded, currentByte)
|
||||
//decoded[decodedIdx] = currentByte
|
||||
currentByte = 0
|
||||
|
||||
decodedIdx++
|
||||
@ -1814,117 +1811,12 @@ func (this *CCITTFaxEncoder) DecodeBytes(encoded []byte) ([]byte, error) {
|
||||
bitPos = 0
|
||||
}
|
||||
}
|
||||
|
||||
/*if bitPos > 0 {
|
||||
decoded = append(decoded, currentByte)
|
||||
currentByte = 0
|
||||
|
||||
decodedIdx++
|
||||
|
||||
bitPos = 0
|
||||
}*/
|
||||
}
|
||||
|
||||
if bitPos > 0 {
|
||||
decoded = append(decoded, currentByte)
|
||||
//decoded[decodedIdx] = currentByte
|
||||
}
|
||||
|
||||
/*decoded := make([]byte, len(pixels)*len(pixels[0])*3)
|
||||
|
||||
decodedInd := 0
|
||||
for i := range pixels {
|
||||
for j := range pixels[i] {
|
||||
if pixels[i][j] == 1 {
|
||||
decoded[decodedInd] = 255
|
||||
decoded[decodedInd+1] = 255
|
||||
decoded[decodedInd+2] = 255
|
||||
//decoded[decodedInd+3] = 255
|
||||
} else {
|
||||
decoded[decodedInd] = 0
|
||||
decoded[decodedInd+1] = 0
|
||||
decoded[decodedInd+2] = 0
|
||||
//decoded[decodedInd+3] = 255
|
||||
}
|
||||
|
||||
decodedInd += 3
|
||||
}
|
||||
}*/
|
||||
|
||||
/*goimage.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
|
||||
t := goimage.NewRGBA(goimage.Rect(0, 0, len(pixels[0]), len(pixels)))
|
||||
t.Pix = decoded
|
||||
file, err := os.Create("/home/darkrengarius/Downloads/test2222222.png")
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening file: %v\n", err)
|
||||
}
|
||||
defer file.Close()
|
||||
err = png.Encode(file, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}*/
|
||||
|
||||
/*file, err := os.Open("/home/darkrengarius/Downloads/scan223.png")
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening file: %v\n", err)
|
||||
}
|
||||
defer file.Close()
|
||||
img, _, err := goimage.Decode(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bounds := img.Bounds()
|
||||
w, h := bounds.Max.X, bounds.Max.Y
|
||||
for y := 0; y < h; y++ {
|
||||
var row []byte
|
||||
for x := 0; x < w; x++ {
|
||||
r, g, b, _ := img.At(x, y).RGBA()
|
||||
if r == 65535 && g == 65535 && b == 65535 {
|
||||
// append white
|
||||
row = append(row, 1)
|
||||
} else {
|
||||
row = append(row, 0)
|
||||
}
|
||||
}
|
||||
pixels = append(pixels, row)
|
||||
}*/
|
||||
|
||||
/*img := image.NewRGBA(image.Rect(0, 0, len(pixels[0]), len(pixels)))
|
||||
imgPix := 0
|
||||
for i := range pixels {
|
||||
for j := range pixels[i] {
|
||||
//log.Printf("%v: %v\n", i, j)
|
||||
img.Pix[imgPix] = 255 * pixels[i][j]
|
||||
img.Pix[imgPix+1] = 255 * pixels[i][j]
|
||||
img.Pix[imgPix+2] = 255 * pixels[i][j]
|
||||
img.Pix[imgPix+3] = 255
|
||||
imgPix += 4
|
||||
}
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
err := png.Encode(buf, img)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imgData := buf.Bytes()
|
||||
f, err := os.Create("/home/darkrengarius/Downloads/testDecodePdf.png")
|
||||
if err != nil {
|
||||
log.Fatalf("Error writing to file: %v\n", err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.Write(imgData); err != nil {
|
||||
log.Fatalf("Error writing to file: %v\n", err)
|
||||
}*/
|
||||
|
||||
/*arr, err := ccittfaxdecode.NewCCITTFaxDecoder(uint(this.Columns), encoded).Decode()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make([]byte, 0)
|
||||
for i := range arr {
|
||||
result = append(result, arr[i]...)
|
||||
}*/
|
||||
|
||||
return decoded, nil
|
||||
}
|
||||
|
||||
@ -1933,35 +1825,6 @@ func (this *CCITTFaxEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, e
|
||||
}
|
||||
|
||||
func (this *CCITTFaxEncoder) EncodeBytes(data []byte) ([]byte, error) {
|
||||
/*file, err := os.Open("/home/darkrengarius/Downloads/scan223.png")
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening file: %v\n", err)
|
||||
}
|
||||
defer file.Close()
|
||||
img, _, err := image.Decode(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bounds := img.Bounds()
|
||||
w, h := bounds.Max.X, bounds.Max.Y
|
||||
var pixels [][]byte
|
||||
for y := 0; y < h; y++ {
|
||||
var row []byte
|
||||
for x := 0; x < w; x++ {
|
||||
if y == 8 && x == 12 {
|
||||
log.Println()
|
||||
}
|
||||
r, g, b, _ := img.At(x, y).RGBA()
|
||||
if r == 65535 && g == 65535 && b == 65535 {
|
||||
// append white
|
||||
row = append(row, 1)
|
||||
} else {
|
||||
row = append(row, 0)
|
||||
}
|
||||
}
|
||||
pixels = append(pixels, row)
|
||||
}*/
|
||||
|
||||
var pixels [][]byte
|
||||
|
||||
for i := 0; i < len(data); i += 3 * this.Columns {
|
||||
@ -1969,20 +1832,10 @@ func (this *CCITTFaxEncoder) EncodeBytes(data []byte) ([]byte, error) {
|
||||
|
||||
pixel := 0
|
||||
for j := 0; j < 3*this.Columns; j += 3 {
|
||||
|
||||
// TODO: check BlackIs1
|
||||
if data[i+j] == 255 {
|
||||
if this.BlackIs1 {
|
||||
pixelsRow[pixel] = 0
|
||||
} else {
|
||||
pixelsRow[pixel] = 1
|
||||
}
|
||||
pixelsRow[pixel] = 1
|
||||
} else {
|
||||
if this.BlackIs1 {
|
||||
pixelsRow[pixel] = 1
|
||||
} else {
|
||||
pixelsRow[pixel] = 0
|
||||
}
|
||||
pixelsRow[pixel] = 0
|
||||
}
|
||||
|
||||
pixel++
|
||||
@ -2003,9 +1856,6 @@ func (this *CCITTFaxEncoder) EncodeBytes(data []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
return encoder.Encode(pixels), nil
|
||||
|
||||
common.Log.Debug("Error: Attempting to use unsupported encoding %s", this.GetFilterName())
|
||||
return data, ErrNoCCITTFaxDecode
|
||||
}
|
||||
|
||||
// JBIG2Encoder implements JBIG2 encoder/decoder (dummy, for now)
|
||||
|
Loading…
x
Reference in New Issue
Block a user