17
4
Dropbox recently released Lepton (GitHub), a method that losslessly compresses JPEG images round-trip, saving an average of 22%.
Because of the pigeonhole principle, any general compression algorithm cannot be guaranteed to result in a smaller file (general because it doesn't apply to inputs constrained to a specific format). Lepton exploits common characteristics about JPEGs, which if subverted, might pigeonhole it to produce a file larger than the source.
Requirements
Write a program that generates:
- A valid JPEG/JFIF image,
- with a size between 0.5 MB and 1 MB,
- no smaller than 256 × 256 px,
- no larger than 4096 × 4096 px,
- recognizable by Lepton (it can successfully "compress" to a
.lep
image), and - decompresses to an identical
.jpg
(as the input). APPx
,COM
, and other metadata, non-graphical marker sections are restricted in the JPEG (injecting arbitrary amounts of random bytes into the image to asymptotically approach 1:1 compression is lame.)- an
APP0
JFIF marker is permitted but no thumbnail is allowed (should be exactly 16 bytes) - tl;dr If you're not intentionally shoving metadata into an EXIF segment and you disable any sort of thumbnail your language library of choice wants to put into the image, that should be OK.
- an
Post the code and image.
If you want to write a program that produces a Lepton image that when converted yields a JPEG meeting the criteria, that's fine. It must remain identical across arbitrarily many JPEG → Lepton → JPEG → ... cycles.
Scoring
The byte size of the Lepton image divided by the source JPEG image. Higher (worse Lepton compression) is better. Run Lepton with default flags and switches.
Getting Lepton
A 5-second crash-course to build Lepton:
git clone https://github.com/dropbox/lepton.git
cd lepton
./autogen.sh && ./configure && make
# fish shell: ./autogen.sh ;and ./configure ;and make
Then ./lepton --help
should tell you things.
I think this could be retooled to a code golf challenge where you write code that generates an image that fails compression by at least some constant. Actually, it may just suffice to just put an upper bound on the code size that's much smaller than the size to hardcode the jpeg, but big enough for an reasonable program. – xnor – 2016-07-15T08:55:26.687
3Is there any reason to expect that uniformly random pixels aren't the best answer? – feersum – 2016-07-15T14:19:41.157
@feersum you mean just like my example? – Nick T – 2016-07-15T15:26:17.150
1Also, because JPEG is a lossy format, there are many, many ways (e.g. "quality" among other things) to compress a given image. Each JPEG file includes a couple tables that dictate how the rest of the image is decoded, and those tables can basically be whatever. If you save a BMP image in different programs, it'll probably be identical. If you save a JPG in different programs, unless they use the same back-end library, probably not. – Nick T – 2016-07-15T15:38:59.387
2@feersum uniformly random input to a JPEG compressor doesn't result in uniformly random output, and that output is what lepton works on. If you can come up with an input that causes a JPEG compressor to produce uniformly random output, that would probably be useful here and elsewhere. – Sparr – 2016-07-26T01:05:39.533
@Sparr Why would you have to use compression? I don't know anything about JPEG format but I would think there is some tool that allows saving in it without trying to compress it. – feersum – 2016-07-26T01:22:18.420
@feersum most image file formats include a form of compression (PPM and some BMP files being counterexamples to a degree, audio: WAV). Some can be lossless (PNG, GIF, audio: FLAC) or lossy (JPG, audio: MP3). – Nick T – 2016-07-26T03:04:05.567
@feersum you're suggesting saving the jpeg with enough quality/detail that it's lossless? that's doable, but lepton isn't particularly applicable to that situation. – Sparr – 2016-07-26T03:38:24.227
@Sparr that might be good for the challenge. Intentionally inflating the quality is an interesting tack. – Nick T – 2016-07-26T03:44:17.780
Sure you're not missing
./configure
in your steps?./autogen.sh && ./configure && make
? – Zeta – 2016-07-26T08:45:22.443BTW, mozjpeg already did implement arithmetic coding long time ago. – Display Name – 2016-08-22T09:38:48.463