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

Optimize: Use original if smaller than "compressed" #118

Merged
merged 2 commits into from
Jul 11, 2019

Conversation

gunnsth
Copy link
Contributor

@gunnsth gunnsth commented Jul 10, 2019

Addresses #51.


This change is Reviewable

Use the original image rather than the "optimized" image if the original was smaller.
@gunnsth gunnsth requested a review from adrg July 10, 2019 22:40
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.

The logic seems good to me. I left a comment regarding some potential improvements.

newStream.PdfObjectDictionary.Set(core.PdfObjectName("Length"), &ln)
replaceTable[stream] = newStream
images[index].Stream = newStream
if int64(len(streamData)) < img.OrigSize {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The new OrigSize field does not seem necessary as it can be obtained here. Also using continue here does seem suitable instead of adding an additional indentation level to that code block. Maybe we could also add a Debug() log message before continue in order to observe the cases in which this scenario occurs.

originalSize := len(stream.Stream)
if originalSize < len(streamData) {
    continue
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will fix.

@gunnsth gunnsth merged commit 0668159 into unidoc:development Jul 11, 2019
@gunnsth gunnsth deleted the optimize-use-smaller-image branch July 11, 2019 20:24
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.

2 participants