Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(337)

Issue 164056: code review 164056: Basic image/jpeg decoder. (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 3 months ago by nigeltao
Modified:
15 years, 3 months ago
Reviewers:
CC:
r, golang-dev, rsc
Visibility:
Public.

Description

Basic image/jpeg decoder. This is not a complete JPEG implementation (e.g. it does not handle progressive JPEGs or restart markers), but I was able to take a photo with my phone, and view the resultant JPEG in pure Go. The decoder is simple, but slow. The Huffman decoder in particular should be easily improvable, but optimization is left to future changelists. Being able to inline functions in the inner loop should also help performance. The output is not pixel-for-pixel identical to libjpeg, although identical behavior isn't necessarily a goal, since JPEG is a lossy codec. There are at least two reasons for the discrepancy. First, the inverse DCT algorithm used is the same as Plan9's src/cmd/jpg, which has different rounding errors from libjpeg's default IDCT implementation. Note that libjpeg actually has three different IDCT implementations: one floating point, and two fixed point. Out of those four, Plan9's seemed the simplest to understand, partly because it has no #ifdef's or C macros. Second, for 4:2:2 or 4:2:0 chroma sampling, this implementation does nearest neighbor upsampling, compared to libjpeg's triangle filter (e.g. see h2v1_fancy_upsample in jdsample.c). The difference from the first reason is typically zero, but sometimes 1 (out of 256) in YCbCr space, or double that in RGB space. The difference from the second reason can be as large as 8/256 in YCbCr space, in regions of steep chroma gradients. Informal eyeballing suggests that the net difference is typically imperceptible, though.

Patch Set 1 #

Patch Set 2 : code review 164056: Basic image/jpeg decoder. #

Total comments: 16

Patch Set 3 : code review 164056: Basic image/jpeg decoder. #

Patch Set 4 : code review 164056: Basic image/jpeg decoder. #

Total comments: 6

Patch Set 5 : code review 164056: Basic image/jpeg decoder. #

Total comments: 22

Patch Set 6 : code review 164056: Basic image/jpeg decoder. #

Total comments: 6

Patch Set 7 : code review 164056: Basic image/jpeg decoder. #

Patch Set 8 : code review 164056: Basic image/jpeg decoder. #

Patch Set 9 : code review 164056: Basic image/jpeg decoder. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+787 lines, -0 lines) Patch
M src/pkg/Makefile View 1 2 3 4 5 6 2 chunks +2 lines, -0 lines 0 comments Download
A src/pkg/image/jpeg/Makefile View 1 chunk +13 lines, -0 lines 0 comments Download
A src/pkg/image/jpeg/huffman.go View 1 2 3 4 5 6 1 chunk +190 lines, -0 lines 0 comments Download
A src/pkg/image/jpeg/idct.go View 1 2 3 4 5 6 1 chunk +190 lines, -0 lines 0 comments Download
A src/pkg/image/jpeg/reader.go View 1 2 3 4 5 6 7 8 1 chunk +392 lines, -0 lines 0 comments Download

Messages

Total messages: 14
nigeltao
Hello r, rsc (cc: golang-dev@googlegroups.com), I'd like you to review the following change.
15 years, 3 months ago (2009-12-01 07:11:03 UTC) #1
r
nice code a few quick comments from pass 1 http://codereview.appspot.com/164056/diff/7/1008 File src/pkg/image/jpeg/huffman.go (right): http://codereview.appspot.com/164056/diff/7/1008#newcode33 src/pkg/image/jpeg/huffman.go:33: ...
15 years, 3 months ago (2009-12-02 00:44:02 UTC) #2
nigeltao
http://codereview.appspot.com/164056/diff/7/1008 File src/pkg/image/jpeg/huffman.go (right): http://codereview.appspot.com/164056/diff/7/1008#newcode33 src/pkg/image/jpeg/huffman.go:33: minCode, maxCode [maxCodeLength]int; // min/max codes of length i, ...
15 years, 3 months ago (2009-12-02 12:08:49 UTC) #3
rsc
regarding idct.go. the code may be via plan 9's jpg but is not of plan ...
15 years, 3 months ago (2009-12-02 19:30:19 UTC) #4
nigeltao
On 2009/12/02 19:30:19, rsc wrote: > please use this header in the file: Done.
15 years, 3 months ago (2009-12-02 23:17:15 UTC) #5
rsc
a few small nits. i am leaving the real review for r. http://codereview.appspot.com/164056/diff/22/1022 File src/pkg/image/jpeg/huffman.go ...
15 years, 3 months ago (2009-12-02 23:25:57 UTC) #6
r2
nigel, have you addressed rsc's comments and uploaded?
15 years, 3 months ago (2009-12-07 23:15:55 UTC) #7
nigeltao
http://codereview.appspot.com/164056/diff/7/1010 File src/pkg/image/jpeg/reader.go (right): http://codereview.appspot.com/164056/diff/7/1010#newcode374 src/pkg/image/jpeg/reader.go:374: case (marker >= 0xe0 && marker <= 0xef) || ...
15 years, 3 months ago (2009-12-07 23:27:59 UTC) #8
r
another round http://codereview.appspot.com/164056/diff/22/1024 File src/pkg/image/jpeg/reader.go (right): http://codereview.appspot.com/164056/diff/22/1024#newcode7 src/pkg/image/jpeg/reader.go:7: // The JPEG specification (ISO/IEC 10918-1:1994, ITU-T ...
15 years, 3 months ago (2009-12-07 23:40:23 UTC) #9
nigeltao
http://codereview.appspot.com/164056/diff/22/1024 File src/pkg/image/jpeg/reader.go (right): http://codereview.appspot.com/164056/diff/22/1024#newcode7 src/pkg/image/jpeg/reader.go:7: // The JPEG specification (ISO/IEC 10918-1:1994, ITU-T T.81) is ...
15 years, 3 months ago (2009-12-08 13:45:12 UTC) #10
r
http://codereview.appspot.com/164056/diff/3007/2015 File src/pkg/image/jpeg/idct.go (right): http://codereview.appspot.com/164056/diff/3007/2015#newcode187 src/pkg/image/jpeg/idct.go:187: for i := 0; i < blockSize; i++ { ...
15 years, 3 months ago (2009-12-14 02:29:39 UTC) #11
nigeltao
Sync'ed and uploaded. The diff might look large because there's no more semi-colons, but nothing's ...
15 years, 3 months ago (2009-12-16 12:18:47 UTC) #12
r
LGTM
15 years, 3 months ago (2009-12-16 22:19:17 UTC) #13
nigeltao
15 years, 3 months ago (2009-12-16 23:35:04 UTC) #14
*** Submitted as http://code.google.com/p/go/source/detail?r=5b81b7a58de1 ***

Basic image/jpeg decoder.

This is not a complete JPEG implementation (e.g. it does not handle
progressive JPEGs or restart markers), but I was able to take a photo
with my phone, and view the resultant JPEG in pure Go.

The decoder is simple, but slow. The Huffman decoder in particular
should be easily improvable, but optimization is left to future
changelists. Being able to inline functions in the inner loop should
also help performance.

The output is not pixel-for-pixel identical to libjpeg, although
identical behavior isn't necessarily a goal, since JPEG is a lossy
codec. There are at least two reasons for the discrepancy.

First, the inverse DCT algorithm used is the same as Plan9's
src/cmd/jpg, which has different rounding errors from libjpeg's
default IDCT implementation. Note that libjpeg actually has three
different IDCT implementations: one floating point, and two fixed
point. Out of those four, Plan9's seemed the simplest to understand,
partly because it has no #ifdef's or C macros.

Second, for 4:2:2 or 4:2:0 chroma sampling, this implementation does
nearest neighbor upsampling, compared to libjpeg's triangle filter
(e.g. see h2v1_fancy_upsample in jdsample.c).

The difference from the first reason is typically zero, but sometimes
1 (out of 256) in YCbCr space, or double that in RGB space. The
difference from the second reason can be as large as 8/256 in YCbCr
space, in regions of steep chroma gradients. Informal eyeballing
suggests that the net difference is typically imperceptible, though.

R=r
CC=golang-dev, rsc
http://codereview.appspot.com/164056
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b