Re: Arithmetic coding in Fedora libjpeg (bug #639531)

2010-10-03 Thread Mukund Sivaraman
Hi all

In reply to Gregory Maxwell:
 It's well known around the Internet that to achieve compatibility you
 should be conservative in what you send and liberal in what you
 accept. Applied to JPEG: Use only Huffman coding when encoding ?
 except maybe if you know that all recipients can handle arithmetic
 coding ? but support both encodings when decoding.

Absolutely. This is an excellent argument and I think is sufficient to
justify the inclusion alone.

Thank you everyone for the replies. I did not know earlier that Fedora
was switching to libjpeg-turbo.  I have created a new bug now:

https://bugzilla.redhat.com/show_bug.cgi?id=639672
Add support for decoding arithmetic coded files in libjpeg-turbo

It contains a patch against upstream libjpeg-turbo HEAD, and the patch
has been submitted upstream too:

https://sourceforge.net/tracker/?func=detailaid=3080268group_id=303195atid=1278160

This patch has been tested against some arithmetic coded images.

I wish libjpeg-turbo also accepts to include creating arithmetic coded
images too, as the project is not really going to affect creation of
such images if an application wants to do so.  But this can be saved
for another argument, and doesn't stand in the way of decode support.

Mukund
-- 
devel mailing list
devel@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/devel


Arithmetic coding in Fedora libjpeg (bug #639531)

2010-10-02 Thread Mukund Sivaraman
Arithmetic coding in Fedora libjpeg (bug #639531)

I want libjpeg packages in future Fedora distributions to support
reading arithmetic coded JPEG files.

Huffman coding and arithmetic are two different bit coding methods that
are available in the JPEG standard. Huffman is simpler to implement than
arithmetic coding and historically hasn't suffered from software
patents. Arithmetic coding (as used in JPEG) had been covered by
software patents, but these patents have now apparently expired. [Fedora
legal could check this.]

The vast majority of JPEG files so far used Huffman coding because of
the software patents issue. libjpeg version 7 (one of the forks of the
old IJG software) and newer enable support for arithmetic coding by
default. With older versions of libjpeg (such as the ones bundled by
Fedora up to release 13), support can be added in the form of a
patch. No application code modifications are required.  (I'm not sure if
it's ABI compatible though, but on a re-reading of the libjpeg headers,
it might well be.)

Arithmetic coding is in every case a superior bit coding method than
Huffman, because arithmetic coding doesn't use an integral number of
bits to represent codes like Huffman does. So JPEG files created with
arithmetic coding are always smaller than those created with Huffman
coding.

Software such as jpegtran (as distributed with libjpeg 7 and above) can
losslessly convert Huffman coded images to arithmetic coded and vice
versa. The lossy behavior of JPEG does not happen at this (bit coding)
layer of the format.

The libjpeg package maintainer seems to be satisfied in closing the bug
rather than providing a good rationale for doing so. But I will be the
devil's advocate myself.

You see, .jpg files are assumed to be an ubiquitous file format. They
_just work_ everywhere. If you have a .jpg file, it is understood you
aren't going to have problems when using it. But arithmetic coded files
do not open everywhere. In fact, they rarely work in most applications,
devices, etc. today, because pretty much everyone is using an old
libjpeg with no support for it due to the historical software patents
issue.

As an example, in the context of GIMP creating such files, there were
some comments that people would start losing faith in JPEG if they see
incompatibilites, that such files are crippled JPEGs [sic], that people
who use devices such as digital photo frames will suffer, that I should
instead blog about free software and the evils of software patents, that
this option should never be available in a dialog to the end-user, etc.

* Fedora is not the only software that creates JPEG files. The nearest
  first implementation of a .jpg file creator program is cjpeg which is
  a part of libjpeg (the fork at ijg.org), and even that allows creating
  arithmetic coded files now. It would be arrogance to think that just
  because Fedora creates these files, the world of JPEG is going to
  suffer. Or that if Fedora doesn't do it, nobody else would.

* The situation with arithmetic coding in the context of incompatibility
  with existing embedded decoders is just like H.264 and profiles. The
  iPhone for example does not play all kinds of H.264 files (it supports
  only the baseline profile). But MPEG content creation software does
  allow you to create files that use baseline as well as other
  profiles. It doesn't say Hey, you the user are pretty stupid, so I'm
  not just turning this option off, but I'm not making it available to
  you. It would be arrogance to not provide an option to the end-user,
  just because I think the user may not know what he/she is doing.

* Due to the patents issue, we had to assume that Huffman was the only
  bit coding method of this standard, whereas it isn't so. Arithmetic
  coding has been in the standard all these umpteen years, and some
  people used it. There was always the odd JPEG content that used
  arithmetic coding and which still complied with the standards. These
  are not broken JPEGs.

Also quoting from the bug:
 In any case, there are practical and political reasons not to encourage the
 spread of the arithmetic-coding variant of JPEG.  It's not compatible with 
 most
 implementations and it doesn't offer enough benefit to be worth creating an
 enormous compatibility problem.  So even if the code existed I would resist
 turning it on.  I think the author of libjpeg 8 has made a very serious error
 by adding support for it.

I have replied on the bug about it. Some of the text in my initial bug
description is incorrect, and I have corrected it in this email.

It is not upto Fedora to make political decisions when there is no good
reason for it. This goes against the values of free software.

You shall not create images with arithmetic coding is like saying You
shall not create images of the flying sphagetti monster. It's not up to
Fedora to make this choice for me.

As libjpeg is a shared library on the system, if it can support
arithmetic coding, it should.