summaryrefslogtreecommitdiff
path: root/src/pkg/image/jpeg/huffman.go
AgeCommit message (Collapse)AuthorFilesLines
2015-01-15Imported Upstream version 1.4upstream/1.4Tianon Gravi1-219/+0
2014-06-19Imported Upstream version 1.3upstream/1.3Michael Stapelberg1-0/+6
2013-03-04Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304Michael Stapelberg1-16/+42
2012-04-06Imported Upstream version 1upstream/1Ondřej Surý1-8/+5
2011-09-13Imported Upstream version 60upstream/60Ondřej Surý1-0/+190
2011-09-13Imported Upstream version 60Ondřej Surý1-190/+0
2009-12-17Basic image/jpeg decoder.Nigel Tao1-0/+190
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