8000 Optimizer fix for the CCITTFax Encoder. ISS #243. Fixes JBIG2 i386 architecture compile issue. by kucjac · Pull Request #297 · unidoc/unipdf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Optimizer fix for the CCITTFax Encoder. ISS #243. Fixes JBIG2 i386 architecture compile issue. #297

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

Merged
merged 7 commits into from
Apr 8, 2020

Conversation

kucjac
Copy link
Contributor
@kucjac kucjac commented Apr 7, 2020

This pull request fixes issue #243. Optimizer were panicing as the CCITTFax Encoder Columns were not updated with the UpdateParams method.

All DecodeParams updated only Width and Height whereas CCITTFax required 'Columns' and 'Rows' to be set. Currently *model.XObjImage.getParamsDict() as well as *model.Image GetParamsDict() functions updates Width, Height, Columns and Rows.

This PR provide also integration tests for the optimized files. All .pdf files in the directory defined by environment variable: UNIDOC_OPTIMIZE_TESTDATA are optimized with the maximum PPI of 100. Then the hash value of optimized files are kept in the golden file.


This change is Reviewable

@codecov
Copy link
codecov bot commented Apr 7, 2020

Codecov Report

Merging #297 into development will increase coverage by 9.89%.
The diff coverage is 100.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #297      +/-   ##
===============================================
+ Coverage        52.34%   62.23%   +9.89%     
===============================================
  Files              235      235              
  Lines            45395    45395              
===============================================
+ Hits             23760    28251    +4491     
+ Misses           18583    16498    -2085     
+ Partials          3052      646    -2406     
Impacted Files Coverage Δ
core/encoding.go 59.27% <100.00%> (+17.67%) ⬆️
internal/jbig2/encoder/arithmetic/encoder.go 68.94% <100.00%> (+5.26%) ⬆️
model/optimize/image_ppi.go 75.38% <100.00%> (+15.68%) ⬆️
internal/jbig2/bitmap/testhelpers.go 34.36% <0.00%> (+0.88%) ⬆️
internal/jbig2/writer/writer.go 51.45% <0.00%> (+0.97%) ⬆️
creator/division.go 89.13% <0.00%> (+1.08%) ⬆️
model/sighandler/sighandler_rsa_sha1.go 5.68% <0.00%> (+1.13%) ⬆️
creator/invoice.go 89.63% <0.00%> (+1.20%) ⬆️
internal/transform/matrix.go 50.00% <0.00%> (+1.35%) ⬆️
annotator/form_field.go 14.78% <0.00%> (+1.40%) ⬆️
... and 155 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 c169f00...c415b18. Read the comment docs.

@gunnsth gunnsth requested a review from adrg April 7, 2020 13:52
Copy link
Collaborator
@adrg adrg left a comment

Choose a reason for hiding this comment

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

Looks good overall. I left one suggestion regarding the handling of the update parameters.

model/image.go Outdated
@@ -98,7 +98,9 @@ func (img *Image) ConvertToBinary() error {
func (img *Image) GetParamsDict() *core.PdfObjectDictionary {
params := core.MakeDict()
params.Set("Width", core.MakeInteger(img.Width))
params.Set("Columns", core.MakeInteger(img.Width))
Copy link
Collaborator
@adrg adrg Apr 7, 2020

Choose a reason for hiding this comment

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

I think it would be better to handle this scenario in the UpdateParams method of the CCITTFaxEncoder, instead of adding more keys here and in the getParamsDict method of the XObjectImage. This way, we have the handling in one place and we can update the encoders in a generic manner as well.

Something like this should work:

func (enc *CCITTFaxEncoder) UpdateParams(params *PdfObjectDictionary) {
        // ...
	if columns, err := GetNumberAsInt64(params.Get("Columns")); err == nil {
		enc.Columns = int(columns)
	} else if columns, err = GetNumberAsInt64(params.Get("Width")); err == nil {
		enc.Columns = int(columns)
	}
        //...
	if rows, err := GetNumberAsInt64(params.Get("Rows")); err == nil {
		enc.Rows = int(rows)
	} else if rows, err = GetNumberAsInt64(params.Get("Height")); err == nil {
		enc.Rows = int(rows)
	}
        //...
}

FlateEncoder also has Columns, but it handles Width in the UpdateParams method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, good idea.

@kucjac kucjac changed the title Optimizer fix for the CCITTFax Encoder. ISS #243. Optimizer fix for the CCITTFax Encoder. ISS #243. Fixes JBIG2 i386 architecture compile issue. Apr 8, 2020
@kucjac
Copy link
Contributor Author
kucjac commented Apr 8, 2020

Added 386 architecture to the .travis/cross_build.sh. Also fixed JBIG2 build error on i386 arch.

Copy link
Contributor
@gunnsth gunnsth left a comment

Choose a reason for hiding this comment

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

LGTM

@gunnsth gunnsth merged commit ad0b31e into unidoc:development Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0