]> Cypherpunks repositories - gostls13.git/commit
image/jpeg: decode progressive JPEGs.
authorNigel Tao <nigeltao@golang.org>
Mon, 15 Oct 2012 00:21:20 +0000 (11:21 +1100)
committerNigel Tao <nigeltao@golang.org>
Mon, 15 Oct 2012 00:21:20 +0000 (11:21 +1100)
commit8b624f607f726347dc48a1ec4989deb868890105
treec582191ca51b508473dda9d7dcc10b0bad00bcce
parentf2045aadd9bd09b1d1371ee9bc2817f50d7587fd
image/jpeg: decode progressive JPEGs.

To be clear, this supports decoding the bytes on the wire into an
in-memory image. There is no API change: jpeg.Decode will still not
return until the entire image is decoded.

The code is obviously more complicated, and costs around 10% in
performance on baseline JPEGs. The processSOS code could be cleaned up a
bit, and maybe some of that loss can be reclaimed, but I'll leave that
for follow-up CLs, to keep the diff for this one as small as possible.

Before:
BenchmarkDecode     1000    2855637 ns/op   21.64 MB/s
After:
BenchmarkDecodeBaseline      500    3178960 ns/op   19.44 MB/s
BenchmarkDecodeProgressive      500    4082640 ns/op   15.14 MB/s

Fixes #3976.

The test data was generated by:
# Create intermediate files; cjpeg on Ubuntu 10.04 can't read PNG.
convert video-001.png video-001.bmp
convert video-005.gray.png video-005.gray.pgm
# Create new test files.
cjpeg -quality 100 -sample 1x1,1x1,1x1 -progressive video-001.bmp > video-001.progressive.jpeg
cjpeg -quality 50 -sample 2x2,1x1,1x1 video-001.bmp > video-001.q50.420.jpeg
cjpeg -quality 50 -sample 2x1,1x1,1x1 video-001.bmp > video-001.q50.422.jpeg
cjpeg -quality 50 -sample 1x1,1x1,1x1 video-001.bmp > video-001.q50.444.jpeg
cjpeg -quality 50 -sample 2x2,1x1,1x1 -progressive video-001.bmp > video-001.q50.420.progressive.jpeg
cjpeg -quality 50 -sample 2x1,1x1,1x1 -progressive video-001.bmp > video-001.q50.422.progressive.jpeg
cjpeg -quality 50 -sample 1x1,1x1,1x1 -progressive video-001.bmp > video-001.q50.444.progressive.jpeg
cjpeg -quality 50 video-005.gray.pgm > video-005.gray.q50.jpeg
cjpeg -quality 50 -progressive video-005.gray.pgm > video-005.gray.q50.progressive.jpeg
# Delete intermediate files.
rm video-001.bmp video-005.gray.pgm

R=r
CC=golang-dev
https://golang.org/cl/6684046
15 files changed:
src/pkg/image/decode_test.go
src/pkg/image/jpeg/huffman.go
src/pkg/image/jpeg/reader.go
src/pkg/image/jpeg/reader_test.go [new file with mode: 0644]
src/pkg/image/jpeg/scan.go [new file with mode: 0644]
src/pkg/image/jpeg/writer_test.go
src/pkg/image/testdata/video-001.progressive.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-001.q50.420.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-001.q50.420.progressive.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-001.q50.422.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-001.q50.422.progressive.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-001.q50.444.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-001.q50.444.progressive.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-005.gray.q50.jpeg [new file with mode: 0644]
src/pkg/image/testdata/video-005.gray.q50.progressive.jpeg [new file with mode: 0644]