Skip to content

Commit 24c02a0

Browse files
committed
group 3 decoding
1 parent 8d36e56 commit 24c02a0

15 files changed

+259
-98
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ It provides both an API and a CLI. Supported are all versions up to PDF 1.7 (ISO
1313

1414
## Status
1515

16-
Version: 0.1.16
17-
18-
* Introducing preliminary support for the CCITTFaxDecode filter.
19-
* Supported is the decoding of CCITTGroup 4 compressed data (K < 0) - encoding and group 3 support yet to come.
20-
* pdfcpu now extracts group 4 compressed black and white images to PNG.
21-
* pdfcpu's tiff reader is also supporting group 4 compressed images as of this release.
22-
* #38 extraction of metadata: `pdfcpu extract -mode meta` extracts optional XML metadata.
23-
* Refactored package structure.
24-
* Bugfixes #40, #41.
16+
Version: 0.1.17
17+
18+
* Improved support for the CCITTFaxDecode filter.
19+
* Supported is the decoding of CCITTGroup 4 compressed data (for K<0)
20+
* Supported is also the 1D decoding of CCITTGroup 3 compressed data (for K=0)
21+
* CCITT Group3 2D(mixed) decoding is pending available test images (K>0).
22+
* pdfcpu now extracts group 3 and 4 encoded black and white images to PNG.
23+
* pdfcpu's tiff reader is also supporting CCITT group 3-1D and group 4 encoded images as of this release.
2524

2625
## Motivation
2726

ccitt/ccitt_test.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func compare(t *testing.T, fileName string, img1, img2 image.Image) {
9696
}
9797
}
9898

99-
func testFile(t *testing.T, fileName string, w, h int, inverse, align bool) {
99+
func testFile(t *testing.T, fileName string, mode, w, h int, inverse, align bool) {
100100

101101
f, err := os.Open(fileName)
102102
if err != nil {
@@ -105,8 +105,8 @@ func testFile(t *testing.T, fileName string, w, h int, inverse, align bool) {
105105
}
106106
defer f.Close()
107107

108-
// Read & decode CCITT Group 4 file into buf.
109-
r := NewReader(f, w, inverse, align)
108+
// Read a CCITT encoded file and decode it into buf.
109+
r := NewReader(f, mode, w, inverse, align)
110110
buf, err := ioutil.ReadAll(r)
111111
if err != nil {
112112
t.Errorf("%s: %v", fileName, err)
@@ -126,32 +126,37 @@ func testFile(t *testing.T, fileName string, w, h int, inverse, align bool) {
126126
return
127127
}
128128

129-
// Compare images
129+
// Compare images.
130130
compare(t, fnNoExt, img1, img2)
131131
}
132132

133133
func TestCCITT(t *testing.T) {
134134

135-
// Test Group 4 encoding
136-
137135
for _, tt := range []struct {
138136
fileName string
137+
mode int
139138
w, h int
140139
inverse bool
141140
align bool
142141
}{
143-
{"testdata/amt.gr4", 43, 38, false, false},
144-
{"testdata/lc.gr4", 154, 154, false, false},
145-
{"testdata/do.gr4", 613, 373, true, false}, // <BlackIs1, true>
146-
{"testdata/t6diagram.gr4", 1163, 2433, false, false},
147-
{"testdata/Wonderwall.gr4", 2312, 3307, false, false}, // extracted from pdfcpu/pkg/api/testdata/Wonderwall.pdf
148-
{"testdata/hoare.gr4", 2550, 3300, false, false},
149-
{"testdata/jphys.gr4", 3440, 5200, false, false},
150-
{"testdata/hl.gr4", 2548, 3300, false, true}, // <EncodedByteAlign, true> <EndOfLine, false>
151-
{"testdata/ho2.gr4", 2040, 2640, false, false},
152-
{"testdata/sie.gr4", 3310, 8672, false, false},
142+
143+
// Test Group 3 decoding
144+
{"testdata/scan1.gr3", Group3, 2480, 3508, false, false},
145+
{"testdata/scan2.gr3", Group3, 1656, 2339, false, false},
146+
147+
// // Test Group 4 decoding
148+
{"testdata/amt.gr4", Group4, 43, 38, false, false},
149+
{"testdata/lc.gr4", Group4, 154, 154, false, false},
150+
{"testdata/do.gr4", Group4, 613, 373, true, false}, // <BlackIs1, true>
151+
{"testdata/t6diagram.gr4", Group4, 1163, 2433, false, false},
152+
{"testdata/Wonderwall.gr4", Group4, 2312, 3307, false, false},
153+
{"testdata/hoare.gr4", Group4, 2550, 3300, false, false},
154+
{"testdata/jphys.gr4", Group4, 3440, 5200, false, false},
155+
{"testdata/hl.gr4", Group4, 2548, 3300, false, true}, // <EncodedByteAlign, true>
156+
{"testdata/ho2.gr4", Group4, 2040, 2640, false, false},
157+
{"testdata/sie.gr4", Group4, 3310, 8672, false, false},
153158
} {
154-
testFile(t, tt.fileName, tt.w, tt.h, tt.inverse, tt.align)
159+
testFile(t, tt.fileName, tt.mode, tt.w, tt.h, tt.inverse, tt.align)
155160
}
156161

157162
}

ccitt/codes.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ limitations under the License.
1717
package ccitt
1818

1919
const (
20-
mP = "0001" // pass mode
21-
mH = "001" // horizontal mode
22-
mV0 = "1" // vertical mode, a1 = b1
23-
mVR1 = "011" // vertical mode, a1 = b1 + 1
24-
mVR2 = "000011" // vertical mode, a1 = b1 + 2
25-
mVR3 = "0000011" // vertical mode, a1 = b1 + 3
26-
mVL1 = "010" // vertical mode, a1 = b1 - 1
27-
mVL2 = "000010" // vertical mode, a1 = b1 - 2
28-
mVL3 = "0000010" // vertical mode, a1 = b1 - 3
29-
ext = "0000001111" // extension mode, enter uncompressed mode
30-
eofb = "000000000001000000000001" // end of facsimile block
20+
mP = "0001" // pass mode
21+
mH = "001" // horizontal mode
22+
mV0 = "1" // vertical mode, a1 = b1
23+
mVR1 = "011" // vertical mode, a1 = b1 + 1
24+
mVR2 = "000011" // vertical mode, a1 = b1 + 2
25+
mVR3 = "0000011" // vertical mode, a1 = b1 + 3
26+
mVL1 = "010" // vertical mode, a1 = b1 - 1
27+
mVL2 = "000010" // vertical mode, a1 = b1 - 2
28+
mVL3 = "0000010" // vertical mode, a1 = b1 - 3
29+
ext = "0000001111" // extension mode, enter uncompressed mode
30+
eol = "000000000001" // end of line
31+
eofb = eol + eol // end of facsimile block
3132
)
3233

3334
var codes = []string{mP, mH, mV0, mVR1, mVR2, mVR3, mVL1, mVL2, mVL3, ext, eofb}

0 commit comments

Comments
 (0)