fixed picture scaling issues in epub generator

Authored by gassaf on Jun 27 2018, 6:25 PM.



Images don't look blurry in epub files

BUG: 391625

Test Plan

I tested the file mentioned in the bug report. Pictures don't look blurry anymore.

Diff Detail

R223 Okular
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
gassaf created this revision.Jun 27 2018, 6:25 PM
Restricted Application added a project: Okular. · View Herald TranscriptJun 27 2018, 6:25 PM
Restricted Application added a subscriber: okular-devel. · View Herald Transcript
gassaf requested review of this revision.Jun 27 2018, 6:25 PM
gassaf edited the test plan for this revision. (Show Details)Jun 27 2018, 6:31 PM
ngraham added subscribers: aacid, ngraham.

Thanks for the patch!

Unfortunately, I don't think this solves 391625. The jaggedness may be smoothed, but that's just a symptom of the root cause, which is that the source images are appearing in low-resolution and are being scaled up rather than displaying in high resolution and scaling down as required.

You might want to go back and look at the image size calculation itself.

That said, this patch does improve the appearance of low-res images that are scaled up compared to the status quo, so we might want to take it anyway while you keep looking for the root cause of 391625. @aacid, what do you think?

I tried commenting out the two lines (+if clause, so line 88 - 91) and all pictures are looking fine. Except that they are sometimes to big and break layout. So I would argue Okular does load all pictures with the correct solution, but the down-scaling part made them look blurry.

Well, conceptually, reducing the size of a too-large image should never cause blurriness; that should only happen if you have to scale up an image that's too small.

For me, if use your patch but comment out the conditionals, the image is still blurry rather than sharp (though, again, better than it was without your patch):

This implies that the images are being loaded too small in the first place. Could epub_get_data() be returning the wrong size, perhaps?

I did some more tests and epub_get_data() always returned the correct size.

Original image file from ebook:

Screenshot from Okular, build with

/*if(img.height() > maxHeight)
    img = img.scaledToHeight(maxHeight);
if(img.width() > maxWidth)
    img = img.scaledToWidth(maxWidth);*/

So I would argue Okular does load all images with the correct size. HOWEVER if you use Okulars zoom functionality the image gets blurry again:

I don't know for sure what causes this behavior. Maybe this is a QTextDocument issue? I will try to look into this.

@aacid, can you offer any guidance here regarding how we might move forward?

aacid added a comment.Jul 2 2018, 9:02 PM

Is this on a High dpi setup? or a regular screen?

Regular DPI screen with no scaling for me.

gassaf added a comment.Jul 5 2018, 8:19 PM

Same here: Regular DPI without scaling.

I did a quick search in Okular source and everywhere, where the QImage scaled*() function is used, it is called with Qt::SmoothTransformation parameter. Except in the epub generator.

aacid accepted this revision.Jul 28 2018, 9:13 PM

This makes it a bit better so i will commit it, but it is still not as good as it could/should be. See

The top is okular with your patch, the bottom is Ark opening the JPEG inside the epub file, you'll notice that it is much sharper.

This revision is now accepted and ready to land.Jul 28 2018, 9:13 PM
This revision was automatically updated to reflect the committed changes.