Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CCITTFaxDecode #346

Merged
merged 21 commits into from
Feb 18, 2019
Merged

Implement CCITTFaxDecode #346

merged 21 commits into from
Feb 18, 2019

Conversation

nkryuchkov
Copy link

Relevant to #38 . Added the implementation of the CCITTFaxDecode filter, embedded it within the v3 version. Comes along with the test data

@CLAassistant
Copy link

CLAassistant commented Feb 15, 2019

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Feb 15, 2019

Codecov Report

Merging #346 into v3 will increase coverage by 1.43%.
The diff coverage is 88.43%.

Impacted file tree graph

@@            Coverage Diff            @@
##              v3     #346      +/-   ##
=========================================
+ Coverage   58.4%   59.83%   +1.43%     
=========================================
  Files        145      149       +4     
  Lines      25316    26738    +1422     
=========================================
+ Hits       14785    15999    +1214     
- Misses     10148    10332     +184     
- Partials     383      407      +24
Impacted Files Coverage Δ
pdf/model/colorspace.go 37.51% <ø> (-0.14%) ⬇️
pdf/core/stream.go 44.59% <0%> (ø) ⬆️
pdf/internal/ccittfax/codes.go 100% <100%> (ø)
pdf/internal/ccittfax/decoding_tree.go 100% <100%> (ø)
pdf/core/encoding.go 49.1% <20.6%> (-4.14%) ⬇️
pdf/internal/ccittfax/decode.go 93.23% <93.23%> (ø)
pdf/internal/ccittfax/encoder.go 95.86% <95.86%> (ø)
pdf/model/font.go 61.57% <0%> (-10.28%) ⬇️
pdf/ps/exec.go 77.77% <0%> (-3.71%) ⬇️
pdf/fjson/fielddata.go 82.66% <0%> (-2.67%) ⬇️
... and 44 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2070f8c...cc63340. Read the comment docs.

Copy link

@gunnsth-review gunnsth-review left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I have added a few comments.
It would be nice to add one roundtrip test case which outputs a PDF file with a CCITTFaxDecode encoded image and then loads it, decodes and compares to the original. Can be some very basic image, just defined in code for example.

Reviewed 1 of 12 files at r1, 16 of 21 files at r3, 41 of 44 files at r4, 2 of 4 files at r5.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @nkryuchkov)


pdf/core/encoding.go, line 1636 at r5 (raw file):

// NewCCITTFaxEncoder makes a new CCITTFax encoder.
func NewCCITTFaxEncoder() *CCITTFaxEncoder {
	return &CCITTFaxEncoder{}

Are there any default options that should be set ? or parameters required depending on planned use?


pdf/core/ccittfaxdecode/codes.go, line 6 at r5 (raw file):

 */

package ccittfaxdecode

Place ccittfaxdecode package into pdf/internal/
Should not be necessary to access from outside (other than core.NewCCITTFaxDecoder())


pdf/core/ccittfaxdecode/codes.go, line 17 at r5 (raw file):

	masks         map[int]byte

	eol = code{

Can you provide a reference to where this is defined? A URL would be nice if it can be accessed online


pdf/core/ccittfaxdecode/decode.go, line 14 at r5 (raw file):

var (
	// ErrEOFBCorrupt is returned when the corrupt EOFB (end-of-block) code is found.
	ErrEOFBCorrupt = errors.New("EOFB code is corrupted")

Probably no need to export the errors.


pdf/core/ccittfaxdecode/decode.go, line 29 at r5 (raw file):

	// trees represent the finite state machine for parsing bit sequences and fetching pixel run lengths
	whiteTree = &decodingTreeNode{

Put the tree vars in a separate block (not with the errors).


pdf/core/ccittfaxdecode/decode.go, line 241 at r5 (raw file):

				case v0:
					pixelsRow, a0 = decodeVerticalMode(pixels, pixelsRow, isWhite, a0, 0)

Remove unneccessary empty lines


pdf/core/ccittfaxdecode/decode.go, line 345 at r5 (raw file):

			case v0:
				pixelsRow, a0 = decodeVerticalMode(pixels, pixelsRow, isWhite, a0, 0)

remove unnecessary blank lines


pdf/core/ccittfaxdecode/decode_test.go, line 349 at r5 (raw file):

	}

	tests := []testData{

Specify source of test data. From a reference?


pdf/core/ccittfaxdecode/doc.go, line 6 at r5 (raw file):

 */

// Package ccittfaxdecode defines and implements the Group3 and Group4

Maybe ccittfax would be specific enough?


pdf/core/ccittfaxdecode/encoder.go, line 71 at r5 (raw file):

		encodedRow, bitPos := encodeRow1D(pixels[i], prevBitPos, eol)

remove extra empty line


pdf/core/ccittfaxdecode/encoder.go, line 85 at r5 (raw file):

		// put RTC
		encodedRTC, _ := encodeRTC(prevBitPos)

remove extra empty line (also in below blocks), for related statements there is no need for an extra line


pdf/core/ccittfaxdecode/encoder.go, line 213 at r5 (raw file):

		encoded = e.appendEncodedRow(encoded, encodedRow, prevBitPos)

remove extra empty line


pdf/core/ccittfaxdecode/encoder.go, line 224 at r5 (raw file):

	if e.EndOfBlock {
		// put EOFB
		encodedEOFB, _ := encodeEOFB(prevBitPos)

remove extra empty line


pdf/core/ccittfaxdecode/encoder_test.go, line 23 at r5 (raw file):

	}

	image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)

Is it not enough to import "image/png" ? Typically a blank import _ "image/png" should register the handler?


pdf/model/colorspace.go, line 306 at r5 (raw file):

		rgbSamples = append(rgbSamples, grayVal, grayVal, grayVal)
	}

Seems unnecessary

Add default parameters to the NewCCITTFaxEncoder. Default values
are taken from the PDF specification.
ccittfaxdecode was moved to pdf/internal and renamed to ccittfax.
ccittfax package errors were unexported.
Copy link

@gunnsth-review gunnsth-review left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 60 of 60 files at r6.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@gunnsth gunnsth added this to the v3.0.0-alpha.3 milestone Feb 18, 2019
@gunnsth gunnsth merged commit 65e8637 into unidoc:v3 Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants