Repository navigation
Conversation
| // JPEG/PNG have special handing in PDF export (no recoding, so instead we use a | ||
| // transform to apply the orientation), so it's worth testing that separately. | ||
| `PNG`, ..rotations.map(v => with-rotation("/assets/images/f2t.png", 0x85, v)), | ||
| `JPEG`, ..rotations.map(v => with-rotation("/assets/images/f2t.jpg", 0x31, v)), |
There was a problem hiding this comment.
This exif transform test previously covered both directly embedded JPEGs and transcoded PNGs to exercise both code paths. After this change, PNGs are also directly embedded. I suggest adding another image format (like webp) to this test to catch future regressions. Thoughts?
There was a problem hiding this comment.
Now after the #8898 (comment) fix, the specific PNG used in this test went back to skipping the transform, so it no longer covers the "directly embedding PNG" code path... We might need to add a version of f2t.png without alpha for better coverage.
How about compilation time? I'd expect it's faster as well |
e312efb to
9c3b735
Compare
Great question. I did some very unscientific measurements using a synthetic benchmark:
|
| ) | ||
| } else if let RasterFormat::Exchange(ExchangeFormat::Png) = raster.format() { | ||
| let image_data = krilla::Data::from(raster.data().to_vec()); | ||
| krilla::image::Image::from_png(image_data, interpolate) |
There was a problem hiding this comment.
I have added a new from_png_native constructor: LaurenzV/krilla#435
We should use this, and in case it returns an error drop into the else path. This way, we can avoid decoding the image inside of krilla, which is wasteful since we already have a decoded representation of the image.
There was a problem hiding this comment.
Good idea! Do we want to bump krilla version as part of this PR, or leave this as future improvement for the next routine bump?
... I guess there would be a performance regression if we leave it as-is, that'd be unfortunate.
There was a problem hiding this comment.
Krilla was bumped in #9022, I've applied the fix.
Off-topic, but in my experience zopfli just isn't worth it, especially if you have to resort to lowering other settings (which you do for larger images since zopfli is dreadfully slow). Just |
|
I just realized, will PNG images with exif rotation be handled correctly in the new path? |
@LaurenzV Yes, there is an existing test for that! Which is awesome because I would not have remember otherwise 😂. See the comment here. |
|
Ah whoops, I missed that! |
|
Will this also prevent the decoded image from sticking around in memory? It would certainly improve memory usage for documents with a lot of images. |
|
I think not, but this needs a different on the typst side, not in krilla. |
This is in the typst repo 😅 |
|
Ah yeah I know, just wanted to clarify 😄 |
08a49b7 to
6b913fe
Compare
This PR hooks up the new krilla code path for directly embedding PNGs in PDF without transcoding (LaurenzV/krilla#331). Fixes #7668.
This change is expected to reduce PDF file sizes for documents containing PNGs, though files may end up larger if the input images are poorly compressed. Performance will also improve due to skipping the re-encoding step (see benchmark).
The following PNG types support direct embedding:
The following are not supported due to PDF limitations:
tRNSchunk for transparencyUnsupported images will fall back to transcoding as before.
Testing
image-png-indexedtest has been manually inspected to confirm the embedding is working correctly.oxipng is a good tool for compressing PNGs ahead of time and is also available online via https://squoosh.app