After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 627413 - jifmux causes broken jpeg images at least with some rgb pixel format
jifmux causes broken jpeg images at least with some rgb pixel format
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
unspecified
Other Linux
: Normal blocker
: 0.10.20
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2010-08-19 19:00 UTC by Filippo Argiolas
Modified: 2010-08-21 19:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
broken jifmux output (60.27 KB, image/jpeg)
2010-08-19 19:01 UTC, Filippo Argiolas
  Details
jpegdec: Prevent crash when reading image with problems (912 bytes, patch)
2010-08-19 21:31 UTC, Thiago Sousa Santos
committed Details | Review
jifmux: Avoid recombining RGB jpegs (2.26 KB, patch)
2010-08-20 14:42 UTC, Thiago Sousa Santos
committed Details | Review

Description Filippo Argiolas 2010-08-19 19:00:29 UTC
Sorry, I don't have the time right now to do further testing.
I was trying a Cheese patch to save images with appsrc ! jpegenc ! jifmux ! filesink and found out that jifmux causes broken colors with some rgb cap.
Will try to better nail down broken formats tomorrow, here's a pipeline that reproduces the issue here:

gst-launch-0.10 -e videotestsrc num-buffe ! "video/x-raw-rgb, bpp=(int)24, depth=(int)24, endianness=(int)4321, red_mask=(int)16711680, green_mask=(int)65280, blue_mask=(int)255, width=(int)640, height=(int)480, framerate=(fraction)30/1" ! jpegenc ! jifmux ! filesink location=broken-jifmux-test.jpg

The same without jifmux outputs a perfectly fine image while this gives the broken colors you can see in the attached image
Comment 1 Filippo Argiolas 2010-08-19 19:01:12 UTC
Created attachment 168312 [details]
broken jifmux output
Comment 2 Thiago Sousa Santos 2010-08-19 19:57:58 UTC
Just reproduced this. Assigning to me.
Comment 3 Thiago Sousa Santos 2010-08-19 21:11:06 UTC
It only happens with RGB and if xmp tags are written.
Comment 4 Thiago Sousa Santos 2010-08-19 21:31:52 UTC
Created attachment 168330 [details] [review]
jpegdec: Prevent crash when reading image with problems

This is not the fix for jifmux, but these broken images would make
jpegdec crash if they were used with: filesrc ! jpegparse ! jpegdec ! ...

This patch fixes it.
Comment 5 Filippo Argiolas 2010-08-20 07:54:51 UTC
I have very little knowledge of jpeg so forgive me if I'm saying something silly.

It seems that jpegenc gives RGB data to libjpeg without any conversion and just sets the colorspace to RGB.
After some googling, as far as I can tell, it seems JFIF mandates image data to be YCbCr (CCIR 601).
So jifmux just adds its headers around the rgb compressed data and when you give the file to a decoder it expects it to be YCbCr and gives those wrong colors.
Comment 6 Filippo Argiolas 2010-08-20 09:19:31 UTC
After some more googling (see e.g. http://freedesktop.org/wiki/Software/libjpeg, Special Markers section), it seems that the key to get a correct colorspace is the presence of APP0 and APP14 markers.
APP14 is written by libjpeg when colorspace is RGB. APP0 when colorspace is YCbCr or grayscale.
With jifmux APP0 is always written no matter what the colorspace is (I guess it's needed by JFIF format). APP14 is preserved too but APP0 seems to have precedence at least in the decoder used by eog (I guess libjpeg). Even putting APP14 first doesn't change anything, while commenting out the line that adds APP0 from gstjifmux.c gives correct colors.
Comment 7 Thiago Sousa Santos 2010-08-20 11:37:53 UTC
Yes, I've been playing with these markers yesterday and it seems you're right:

"The color space to be used is YCbCr as defined by CCIR 601 (256 levels). The RGB
components calculated by linear conversion from YCbCr shall not be gamma corrected
(gamma = 1.0). If only one component is used, that component shall be Y."
From the JFIF spec.

We need something on image/jpeg caps to detect and prevent that.
Comment 8 Thiago Sousa Santos 2010-08-20 14:42:04 UTC
Created attachment 168409 [details] [review]
jifmux: Avoid recombining RGB jpegs

JFIF only allows YUV as colorspace, when we receive an RGB jpeg,
we should just push it forward without adding the JFIF marker.

Fixes #627413

This patch fixes the problem, but it doesn't add the JFIF marker
to the output buffer. I left it like that because it is the
default behavior when parsing the image fails.
Comment 9 Thiago Sousa Santos 2010-08-20 14:49:39 UTC
Setting to blocker as it crashes jpegdec.
Comment 10 Sebastian Dröge (slomo) 2010-08-21 19:10:24 UTC
commit 407f6158871691f8442d903874e64873d43fdca6
Author: Thiago Santos <thiago.sousa.santos@collabora.co.uk>
Date:   Fri Aug 20 11:09:19 2010 -0300

    jifmux: Avoid recombining RGB jpegs
    
    JFIF only allows YUV as colorspace, when we receive an RGB jpeg,
    we should just push it forward without adding the JFIF marker.
    
    Fixes #627413