JPG images are recompressed with lower quality when embedded

Bug #871563 reported by Wy4wB on 2011-10-10
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Krzysztof Kosinski

Bug Description

Dear Sir:

I report trouble with pasting with JPG file.

It occur with JPG file but not with PNG file.

When I copy and paste JPG file into Inkscape, the JPG image become very rough.
It seems as if several pixels are gethered into one pixel, in other words,
it is displeyed with low resolution.

This trouble doesn't occured with PNG files.

Both JPG and PNG files are generated from GIMP xcf fils. The size of files are 615x108, 41.7 kb, 254x254 dpi.

It occured with TIF file with large image (1392x1040, 1.4 MB, 254x254dpi), but it didn't occur with
Tif file with small image (615x108, 130 kb, 254x254 dpi).

I might have no trouble if I prepare PNG files for Inkscape. But I want Inkscape developers
to fix this problem. Please contact me, if you need sample files.

I really prefer Inkscape, and use Inkscape in the University for education and research.
My students and laboratory menbers, too.

I wish Inkscape and Inkscape community for further success and expansion.

Os: Windows 7 ultimate (64 bit)
Inkscape: Inkscape 0.48.2 r9819
locale: japan

Sincerely yours,

Yasunori Fukumoto, PhD
<email address hidden>

su_v (suv-lp) on 2011-10-10
tags: added: clipboard win32
su_v (suv-lp) on 2011-10-14
tags: added: bitmap importing
removed: win32
su_v (suv-lp) wrote :

Reproduced with Inkscape 0.48.2 and 0.48+devel r10675 on Mac OS X 10.5.8 (i386)
using the test image provided in related forum topic:

Extensions>Images>Embed vs Drag/drop-embed of jpeg

su_v (suv-lp) wrote :

1) save the JPEG and SVG into the same folder (relative image link)
2) open the SVG file in Inkscape
3) zoom in to 800% and compare the variants:
   left: linked
   center: embedded on import
   right: embedded with extension

su_v (suv-lp) on 2011-10-14
Changed in inkscape:
importance: Undecided → Medium
status: New → Confirmed
su_v (suv-lp) on 2012-03-18
summary: - JPG pasting in trouble with resolution
+ JPG images are recompressed with lower quality when embedded
su_v (suv-lp) wrote :

Related (or partially duplicate) report:
Bug #958371 “Inkscape does not actually embed the image files given”

This is quite bad. The effect is even worse with saturated colors where the chroma subsampling effects are more visible.
I'm attaching a screenshot showing the problem. It's quite evident and it's really difficult to miss it in this example.

I know this problem has been around for a while, but I think it's quite serious, maybe enough to consider it as a blocker for 0.49.
It may not sound as a big deal, but this bug has something that makes it worse: It can easily go unnoticed and affects quality.
Sometimes the effect isn't evident when the artwork is zoomed or the image is small in the document, and the user could easily miss the detrimental effect of the recompression in the image quality until it's too late.

For someone like me, a graphic designer using inkscape for his job, this is as bad as the cairo downscaling bug or any crasher. It results in quality loss, and that's something unacceptable for a desiger/artist.
Inkscape, as a program for artists and designers, should ensure image quality, therefore this bug should be marked as a high importance issue, although it doesn't makes the program crash or loose data.

ScislaC (scislac) on 2013-03-25
tags: added: blocker
jazzynico (jazzynico) on 2013-03-25
Changed in inkscape:
importance: Medium → High
status: Confirmed → Triaged
milestone: none → 0.49
John Smith (john-smithi) wrote :

This patch sets the quality to 100 for embedded jpeg's.
Resultant files are much larger due to lack of jpeg compression.

Would a user preference for the quality be useful ?

Changed in inkscape:
assignee: nobody → John Smith (john-smithi)
status: Triaged → In Progress
John Smith (john-smithi) wrote :

Patch with user preference : Bitmap->Bitmap import quality.
Shall we assume the default quality should be 100 (Best quality) ?

FYI - The current jpeg import quality appears to be 75 - which seems to give about 4:1 compression on photo like images.

jazzynico (jazzynico) wrote :

Or even better, reuse the code from src/extension/internal/image-resolution.cpp to detect the correct resolution?
(code added to fix, "png resolution not imported", but also deals with JFIF and EXIF data)

Note that we already have two options (Default import resolution and Override file resolution) that could be reused as default for bitmap embedding as well.

jazzynico (jazzynico) wrote :

Correcting myself:

> Or even better, reuse the code from src/extension/internal/image-resolution.cpp to detect the correct resolution?

...detect the correct compression.

> Note that we already have two options (Default import resolution and Override file resolution) that could be reused as default for bitmap embedding as well.

Of course we can't since we're not dealing with resolution but quality...

Sorry for my misunderstanding.

John Smith (john-smithi) wrote :

Committed as r12325.

The default jpeg import quality is now 100% (no compression).
New user preference Bitmap->Bitmap import quality

Changed in inkscape:
status: In Progress → Fix Committed
su_v (suv-lp) wrote :

Testing new option with Inkscape 0.48+devel r12325 on OS X 10.7.5:
Maybe these console warnings could be silenced when embedding a non-JPEG image (i.e. if format = "png")?
> (inkscape:944): GdkPixbuf-WARNING **: Unrecognized parameter (quality) passed to PNG saver.

Unrelated question: is a JPEG image with uppercase file suffix '*.JPG' or '*.JPEG' not recognized as JPEG image only on OS X, or does a JPEG image with an uppercase suffix get embedded as PNG data on other platforms, too?

Thanks for the fix. It solves the problem, although I wonder what's the need of re-compressing the jpg file.
Does the 100% compression means that the svg will have an uncompressed image embedded? That means that the image will need more disk space after embedded but won't have better quality, so it doesn't seem to make much sense.
GIMP used to have a problem with JPGs several years ago (there was a default setting that was too destructive and just opening and saving over the same file destroyed its quality). They fixed that reading the quality setting for the file, and applying the same quality parameter if the quality setting in the file was higher than the default setting in the program.
Can't we have the same?
Apart from that, I'd like to ask about chroma subsampling in these jpeg. 4:2:2 or 4:2:0 are too destructive to be used for this purpose, and even opening and re-saving a file with the same quality setting but one of these subsampling settings result in visible artifacts.
I'd suggest to use 4:4:4 (no chroma subsampling) if the imported jpgs have to be re-compressed.
If re-compressing can't be avoided, a quality setting of 98 with 4:4:4 subsampling seems to be a better default than 100%. It will make files smaller and keep the quality very high (digital cameras save jpg at 95~98)

Krzysztof Kosinski (tweenk) wrote :

Recompressing can be avoided by using the function cairo_surface_set_mime_data().

ScislaC (scislac) wrote :

Since there was a better solution proposed by Krzysztof, I put back to confirmed as we really would prefer something that doesn't recompress at all if it's not outright desired.

Changed in inkscape:
status: Fix Committed → Confirmed
assignee: John Smith (john-smithi) → nobody
Changed in inkscape:
assignee: nobody → Krzysztof Kosinski (tweenk)
Krzysztof Kosinski (tweenk) wrote :

Should be fixed in r12516.

Inkscape will no longer recompress any images. This applies to both embedding and PDF output.

Changed in inkscape:
status: Confirmed → Fix Committed
Kris (kris-degussem) on 2013-09-14
tags: removed: blocker
Bryce Harrington (bryce) on 2015-02-21
Changed in inkscape:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers