-
Notifications
You must be signed in to change notification settings - Fork 256
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
JBIG2 Generic Encoder #264
Conversation
* Update Jenkinsfile go version
…Added Bitmap toImage method.
Codecov Report
@@ Coverage Diff @@
## development #264 +/- ##
==============================================
- Coverage 59.09% 52.39% -6.7%
==============================================
Files 192 235 +43
Lines 36884 45287 +8403
==============================================
+ Hits 21795 23727 +1932
- Misses 12318 18527 +6209
- Partials 2771 3033 +262
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks very good for the most part. I noticed two breaking changes in the JBIG2Encoder
struct which should be sorted out.
} | ||
|
||
// NewJBIG2Encoder returns a new instance of JBIG2Encoder. | ||
func NewJBIG2Encoder() *JBIG2Encoder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can only remove public functions in major releases of the package. So we have to keep it for now. Maybe adjust it to reflect the newly introduced functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're definitely right. I'm reverting that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't forget to bring back the NewJBIG2Encoder
function.
core/encoding_jbig2.go
Outdated
|
||
/** | ||
|
||
JBIG2Encoder/Decoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the same style for section separators which are already used in the library, at least in the non-internal packages.
//
// JBIG2Encoder/Decoder
//
} | ||
|
||
// UpdateParams updates the parameter values of the encoder. | ||
func (enc *JBIG2Encoder) UpdateParams(params *PdfObjectDictionary) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the body of this method be empty? It wasn't before:
func (enc *JBIG2Encoder) UpdateParams(params *PdfObjectDictionary) {
if decode := params.Get("Decode"); decode != nil {
enc.setChocolateData(decode)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check? empty or not?
core/encoding_jbig2.go
Outdated
} | ||
} | ||
|
||
func (d *JBIG2Document) updateParameters() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is only used once and has only a line of code. Is it expected to grow in the future or be called from multiple places? If not, maybe it can be removed.
The same applies for the initializeIfNeeded
method of the document.
core/encoding_jbig2.go
Outdated
|
||
*/ | ||
|
||
func autoThresholdTriangle(histogram [256]int) uint8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these util functions could be moved somewhere in the internal jbig2
package.
core/encoding.go
Outdated
@@ -1903,8 +1902,8 @@ func (enc *CCITTFaxEncoder) DecodeBytes(encoded []byte) ([]byte, error) { | |||
EndOfBlock: enc.EndOfBlock, | |||
BlackIs1: enc.BlackIs1, | |||
DamagedRowsBeforeError: enc.DamagedRowsBeforeError, | |||
Rows: enc.Rows, | |||
EncodedByteAlign: enc.EncodedByteAlign, | |||
Rows: enc.Rows, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not appear formatted with gofmt
. Please make sure you run gofmt
on the file.
common/logging.go
Outdated
@@ -57,6 +59,8 @@ func (DummyLogger) IsLogLevel(level LogLevel) bool { | |||
// LogLevel is the verbosity level for logging. | |||
type LogLevel int | |||
|
|||
// defines log level enum where the most important logs have the lowest values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please start comments with capital letter and end them with .
where possible, especially in non-internal package source files.
core/encoding_jbig2.go
Outdated
type JBIG2Encoder struct { | ||
JBIG2Document | ||
// Globals are the JBIG2 global segments. | ||
Globals *document.Globals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a breaking change as the the field was Globals jbig2.Globals
previously. Breaking changes are only possible when releasing major versions of the package.
Before:
type Globals map[int]*segments.Header
Now:
type Globals struct {
Segments []*segments.Header
}
common/logging.go
Outdated
// output writes `format`, `args` log message prefixed by the source file name, line and `prefix` | ||
func (l ConsoleLogger) output(f *os.File, prefix string, format string, args ...interface{}) { | ||
//noinspection GoUnhandledErrorResult | ||
func (l WriterLogger) output(f io.Writer, prefix string, format string, args ...interface{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method seems to be identical to the one in the ConsoleLogger
struct. It may be better to make it a standalone function and call it from both loggers.
core/encoding_jbig2.go
Outdated
|
||
*/ | ||
|
||
// JBIG2Image is the image structure used by the jbig2 encoder. It's Data must be in a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo: It's
instead of Its
. Might be good to go through the encoding_jbig2.go
file and check the method documentation comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 126 files reviewed, 8 unresolved discussions (waiting on @adrg)
common/logging.go, line 62 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
Please start comments with capital letter and end them with
.
where possible, especially in non-internal package source files.
Done.
common/logging.go, line 230 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
This method seems to be identical to the one in the
ConsoleLogger
struct. It may be better to make it a standalone function and call it from both loggers.
Done.
core/encoding.go, line 1905 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
This does not appear formatted with
gofmt
. Please make sure you rungofmt
on the file.
Done.
core/encoding_jbig2.go, line 42 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
Please use the same style for section separators which are already used in the library, at least in the non-internal packages.
// // JBIG2Encoder/Decoder //
Done.
core/encoding_jbig2.go, line 58 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
This seems to be a breaking change as the the field was
Globals jbig2.Globals
previously. Breaking changes are only possible when releasing major versions of the package.Before:
type Globals map[int]*segments.Header
Now:
type Globals struct { Segments []*segments.Header }
Hmm. Field Globals
in the *JBIG2Encoder
are obtainable only as a result from the internal functions - and were created on the run of Decode method. This little change is very important in the Encoder context. I will make some workaround that converts jbig2.Globals
into *document.Globals
internally.
core/encoding_jbig2.go, line 165 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
Should the body of this method be empty? It wasn't before:
func (enc *JBIG2Encoder) UpdateParams(params *PdfObjectDictionary) { if decode := params.Get("Decode"); decode != nil { enc.setChocolateData(decode) } }
This Decode
Parameter - Chocolate Data concept - was solved by the #159. This results of these functions were no longer used by the *JBIG2Encoder
. Thus the content of this method could be empty now.
core/encoding_jbig2.go, line 304 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
This method is only used once and has only a line of code. Is it expected to grow in the future or be called from multiple places? If not, maybe it can be removed.
The same applies for theinitializeIfNeeded
method of the document.
It was expected at the beginning. Right now it doesn't look like it would be needed anytime again. It can be removed.
core/encoding_jbig2.go, line 464 at r6 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
I think these util functions could be moved somewhere in the internal
jbig2
package.
Good Idea. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 3 of 14 files at r7.
Reviewable status: 3 of 126 files reviewed, 8 unresolved discussions (waiting on @adrg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 112 of 127 files at r5, 11 of 14 files at r7.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @adrg)
common/logging.go
Outdated
output(f, prefix, format, args) | ||
} | ||
|
||
func output(f io.Writer, prefix string, format string, args ...interface{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the name of this function should be changed to something a bit more suggestive. As part of a struct, it did provide some context. Maybe logToWriter
or logOutput
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 123 of 126 files reviewed, 9 unresolved discussions (waiting on @adrg and @kucjac)
common/logging.go, line 225 at r8 (raw file):
Previously, adrg (Adrian-George Bostan) wrote…
I think the name of this function should be changed to something a bit more suggestive. As part of a struct, it did provide some context. Maybe
logToWriter
orlogOutput
or something like that.
Done. logToWriter
looks good to me and in fact it is more suggestive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good. Thank you for addressing the review requested changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 112 of 127 files at r5, 11 of 14 files at r7, 1 of 2 files at r8, 2 of 2 files at r9.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @adrg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. I added a few comments. Can you please go through.
Can you also update our ACKNOWLEDGEMENTS.md file?
common/logging.go
Outdated
func (l ConsoleLogger) Trace(format string, args ...interface{}) { | ||
if l.LogLevel >= LogLevelTrace { | ||
prefix := "[TRACE] " | ||
l.output(os.Stdout, prefix, format, args...) | ||
} | ||
} | ||
|
||
// output writes `format`, `args` log message prefixed by the source file name, line and `prefix` | ||
//noinspection GoUnhandledErrorResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the "noinspection" comment, seems to be for some linter that we are not using.
common/logging.go
Outdated
func (l ConsoleLogger) Warning(format string, args ...interface{}) { | ||
if l.LogLevel >= LogLevelWarning { | ||
prefix := "[WARNING] " | ||
l.output(os.Stdout, prefix, format, args...) | ||
} | ||
} | ||
|
||
// Notice logs 'Notice' message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be // Note logs notice messages.
No need to put 'Notice' into quotes. Same for other comment similar.
(Error, Warning, Debug, Trace)
Sometimes variable names are put into ticks
https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide#12-doc-comments
but not usually function names
} | ||
|
||
// UpdateParams updates the parameter values of the encoder. | ||
func (enc *JBIG2Encoder) UpdateParams(params *PdfObjectDictionary) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check? empty or not?
core/encoding_jbig2.go
Outdated
globalsStream, ok := globals.(*PdfObjectStream) | ||
if !ok { | ||
err = errors.Error(processName, "jbig2.Globals stream should be an Object Stream") | ||
//noinspection GoNilness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove those noinspection comments?
At the moment we just try to minimize golint output but not commenting on each single deviation.
go.mod
Outdated
@@ -12,3 +12,5 @@ require ( | |||
golang.org/x/text v0.3.2 | |||
golang.org/x/tools v0.0.0-20190606174628-0139d5756a7d // indirect | |||
) | |||
|
|||
go 1.13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this? Or check what is the oldest version that works?
I think go 1.11 should work.
internal/jbig2/document/document.go
Outdated
} | ||
|
||
// func (d *Document) uniteTemplatesWithIndexes(firstTempIndex, secondTempIndex int) error { | ||
// if len(d.Classer.Pixat) < firstTempIndex || len(d.Classer.Pixat) < secondTempIndex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove commented code
// t.Run("PDFMode", func(t *testing.T) { | ||
// scales := []int{2, 4} | ||
// for _, scale := range scales { | ||
// t.Run(fmt.Sprintf("SinglePageX%d", scale), func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented code or add explanation if there is reason to keep
internal/jbig2/document/page.go
Outdated
// Then the function writes it's encoded data into 'w' writer. | ||
// func (p *Page) encodeSegment(w writer.BinaryWriter, segmentNumber int) (n int, err error) { | ||
// const processName = "encodeSegment" | ||
// // get the segment for given 'segmentNumber' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code, remove or add reason to keep
internal/jbig2/document/page.go
Outdated
|
||
// firstSegmentNumber gets the number of the first segment in the page. | ||
// func (p *Page) firstSegmentNumber() (first uint32, err error) { | ||
// const processName = "firstSegmentNumber" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code, remove or document reason to keep
|
||
// // iterate over all symbols in the list | ||
// for i := 0; i < len(s.symbolList); { | ||
// height, err := s.bmHeight(i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code: remove or document reason to keep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @gunnsth)
go.mod, line 16 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Can you remove this? Or check what is the oldest version that works?
I think go 1.11 should work.
go 1.11 should be fine as it was the first version that supports modules. Done
common/logging.go, line 105 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Should be // Note logs notice messages.
No need to put 'Notice' into quotes. Same for other comment similar.
(Error, Warning, Debug, Trace)
Sometimes variable names are put into ticks
https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide#12-doc-comments
but not usually function names
Done.
common/logging.go, line 138 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Remove the "noinspection" comment, seems to be for some linter that we are not using.
Done.
core/encoding_jbig2.go, line 165 at r6 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
check? empty or not?
It should be empty now.
core/encoding_jbig2.go, line 273 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Can you remove those noinspection comments?
At the moment we just try to minimize golint output but not commenting on each single deviation.
Done. Sure. I will remove all noinsepction comments.
internal/jbig2/bitmap/bitmap_test.go, line 992 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Add TODO for adding this test?
Done. Removed that test.
internal/jbig2/bitmap/combine.go, line 80 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
with the ...?
Done.
internal/jbig2/bitmap/components.go, line 270 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
should be empty newline above the function.
Need to run goimports ?
Done.
internal/jbig2/bitmap/components_test.go, line 1291 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Can we remove the commented code?
Typically we don't keep commented code unless for some reason, which should be indicated.
Done. This part of the code was the development part of the Classified Encoder that didn't pass the tests or compile well. Moved to separate branch for future development and remove from this PR.
internal/jbig2/document/document.go, line 786 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
can remove commented code
Done. This part of the code was the development part of the Classified Encoder that didn't pass the tests or compile well. Moved to separate branch for future development and remove from this PR.
internal/jbig2/document/page.go, line 403 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
commented code, remove or add reason to keep
Done. This part of the code was the development part of the Classified Encoder that didn't pass the tests or compile well. Moved to separate branch for future development and remove from this PR.
internal/jbig2/document/page.go, line 418 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
commented code, remove or document reason to keep
Done. This part of the code was the development part of the Classified Encoder that didn't pass the tests or compile well. Moved to separate branch for future development and remove from this PR.
internal/jbig2/document/document_test.go, line 687 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
remove commented code or add explanation if there is reason to keep
Done. This part of the code was the development part of the Classified Encoder that didn't pass the tests or compile well. Moved to separate branch for future development and remove from this PR.
internal/jbig2/document/segments/symbol-dictionary.go, line 293 at r9 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
commented code: remove or document reason to keep
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 59 files at r2, 2 of 57 files at r4, 1 of 127 files at r5, 15 of 15 files at r10.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @kucjac)
common/logging.go, line 178 at r10 (raw file):
} // Warning logs 'warning' message.
Check comments for this set of log functions too Error, Warning, Notice etc
core/encoding_jbig2.go, line 165 at r6 (raw file):
Previously, kucjac (Jacek Kucharczyk) wrote…
It should be empty now.
Can you add a comment like // Empty but necessary to implement interface X or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 124 of 127 files reviewed, 1 unresolved discussion (waiting on @gunnsth)
common/logging.go, line 178 at r10 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Check comments for this set of log functions too Error, Warning, Notice etc
Done.
core/encoding_jbig2.go, line 165 at r6 (raw file):
Previously, gunnsth (Gunnsteinn Hall) wrote…
Can you add a comment like // Empty but necessary to implement interface X or something like that?
Done. Good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 127 files at r5, 3 of 3 files at r11.
Reviewable status:complete! all files reviewed, all discussions resolved
This Pull Request provide JBIG2 lossless encoder for the bi-level image compression.
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)