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

Issue 4186064: code review 4186064: image/jpeg: add encoder

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 2 months ago by raph
Modified:
13 years, 1 month ago
Reviewers:
nigeltao, r, r2
CC:
golang-dev
Visibility:
Public.

Description

image/jpeg: add encoder

Patch Set 1 #

Patch Set 2 : diff -r f8d31ca621c6 https://go.googlecode.com/hg/ #

Total comments: 14

Patch Set 3 : diff -r 20b1f499456d https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 20b1f499456d https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 20b1f499456d https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 20b1f499456d https://go.googlecode.com/hg/ #

Total comments: 28
Unified diffs Side-by-side diffs Delta from patch set Stats (+929 lines, -0 lines) Patch
M src/pkg/image/jpeg/Makefile View 1 1 chunk +2 lines, -0 lines 1 comment Download
A src/pkg/image/jpeg/fdct.go View 1 2 1 chunk +140 lines, -0 lines 6 comments Download
A src/pkg/image/jpeg/testdata/images/README View 1 2 3 4 5 1 chunk +5 lines, -0 lines 0 comments Download
A src/pkg/image/jpeg/testdata/images/basn0g08.png View 1 2 3 4 5 Binary file 0 comments Download
A src/pkg/image/jpeg/testdata/images/basn2c08.png View 1 2 3 4 5 Binary file 0 comments Download
A src/pkg/image/jpeg/testdata/images/video-001.png View 1 2 3 4 5 Binary file 0 comments Download
A src/pkg/image/jpeg/writer.go View 1 2 3 1 chunk +673 lines, -0 lines 18 comments Download
A src/pkg/image/jpeg/writer_test.go View 1 2 3 4 5 1 chunk +109 lines, -0 lines 3 comments Download

Messages

Total messages: 12
raph
Hello nigeltao (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 2 months ago (2011-02-21 01:47:19 UTC) #1
nigeltao
Just a bunch of very quick, mostly superficial comments for now. I'll have a proper ...
13 years, 2 months ago (2011-02-21 04:18:21 UTC) #2
r
a few cosmetic things. i haven't dug in yet http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/fdct.go File src/pkg/image/jpeg/fdct.go (right): http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/fdct.go#newcode31 src/pkg/image/jpeg/fdct.go:31: ...
13 years, 2 months ago (2011-02-22 19:54:46 UTC) #3
raph
On 2011/02/21 04:18:21, nigeltao wrote: > Just a bunch of very quick, mostly superficial comments ...
13 years, 1 month ago (2011-03-26 22:29:55 UTC) #4
raph
On 2011/02/22 19:54:46, r wrote: > a few cosmetic things. i haven't dug in yet ...
13 years, 1 month ago (2011-03-26 22:33:38 UTC) #5
raph
Hello nigeltao, r (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 1 month ago (2011-03-26 22:34:45 UTC) #6
r2
> > > http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#newcode42 >> src/pkg/image/jpeg/writer.go:42: bitsDcLuminance = []byte{0, 1, 5, 1, > 1, 1, ...
13 years, 1 month ago (2011-03-26 23:32:15 UTC) #7
raph
Hello nigeltao, r, r2 (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 1 month ago (2011-03-27 00:03:13 UTC) #8
raph
Ok, I'm hoping this is ready now. Still working on writing tests... http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go File src/pkg/image/jpeg/writer.go ...
13 years, 1 month ago (2011-03-27 00:05:18 UTC) #9
raph
Hello nigeltao, r, r2 (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 1 month ago (2011-03-27 01:33:30 UTC) #10
raph
On 2011/03/27 01:33:30, raph wrote: > Hello nigeltao, r, r2 (cc: mailto:golang-dev@googlegroups.com), > > Please ...
13 years, 1 month ago (2011-03-27 01:49:33 UTC) #11
nigeltao
13 years, 1 month ago (2011-03-29 08:40:55 UTC) #12
You could also cut down on the number of intermediate allocations by adding a
few (re-usable) buffers to the encoder struct, but there's more than enough to
chew on for now.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/Makefile
File src/pkg/image/jpeg/Makefile (right):

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/Makefile#...
src/pkg/image/jpeg/Makefile:11: fdct.go\
Please keep this list sorted alphabetically.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go
File src/pkg/image/jpeg/fdct.go (right):

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go#n...
src/pkg/image/jpeg/fdct.go:8: // distribution
Add a trailing full stop to complete the sentence.

Also, can you add a link or a definitive reference to the IJG distribution?

Finally, can you confirm the licensing requirements for the IJG code?

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go#n...
src/pkg/image/jpeg/fdct.go:11: fix_0_298631336 = 2446  /* FIX(0.298631336) */
I'd drop the /* FIX(...) */ comments. They don't seem to add anything above the
constant name.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go#n...
src/pkg/image/jpeg/fdct.go:31: // Pass 1: process rows
Trailing full stop, and again below in many places.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go#n...
src/pkg/image/jpeg/fdct.go:65: // Odd part per figure 8
Figure 8 of what?

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go#n...
src/pkg/image/jpeg/fdct.go:70: z1 = (tmp12 + tmp13) * fix_1_175875602 /*  c3 */
I'd drop the /* c3 */ comments unless you give some context somewhere for what
c3 means.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/fdct.go#n...
src/pkg/image/jpeg/fdct.go:91: // of 8
Move "of 8." to the previous comment line.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go
File src/pkg/image/jpeg/writer.go (right):

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:23: type encoder struct {
Please move the definition of the encoder type to line 178, just above its
methods.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:47: 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
Is it possible to document these magic numbers? Do they come from the JPEG spec?
There isn't an obvious pattern, AFAICT.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:178: // According to Annex C of the spec, Huffman
code lenghts greater than 16 bits
Typo in "lengths".

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:187: e.err = e.w.WriteByte(b)
Rather than having an e.err field, I think it is more idiomatic for all such
methods to return an os.Error.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:218: _, e.err = e.w.Write([]byte{0xff, 0xd8}) //
SOI marker
reader.go already defines const soiMarker = 0xd8. You should be able to replace
quite a few magic numbers in this file with named constants.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:325: func roundDivide(a int, b int) int {
s/a int, b int/a, b int/

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:332: func (e *encoder) writeBlock(b
*[blockSize]int, tab int, last int) int {
Given the number of times you use a [blockSize]int, it might be useful to
declare a "block" type above:
type block [blockSize]int

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:402: FIX_0_299   = 19595
It is possible to harmonize the style used in rgbToYCbCr here and the calcPixel
method in reader.go?

If not, at the very least, these constants' names should start with a lower case
letter so that they are not exported. You can also move them inside the
rgbToYCbCr function.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:414: // Convert one 8x8 color image block to YCbCr
// rgbToYCbCr converts an 8x8 color block to YCbCr.

Doc comments should start with the name of the thing they are documenting, and
end with a full stop. Similarly, the comment for roundDivide above should start
with:

// roundDivide returns a/b rounded to the nearest int, instead of rounded down.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:415: func rgbtoYCbCr(m image.Image, x0 int, y0 int,
yblock *[blockSize]int, cbblock *[blockSize]int, crblock *[blockSize]int) {
s/rgbto/rgbTo/

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:430: // Note: just shifting creates a small error
for proper 16-bit images
What's the error? Do you mean to do something like
r := int((ur + 128) >> 8)?

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:445: var color444SOI = []byte{0xff, 0xda, 0x00,
0x0c, 0x03, 0x01, 0x00, 0x02, 0x11,
Can you add a comment explaining these magic numbers?

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:453: m := e.m
This variable doesn't seem to be pulling its weight. Just use e.m below.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:455: var yblock [blockSize]int
var (
  yblock, cbblock, crblock [blockSize]int
  lasty, lastcr, lastcb int
)

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:507: cbblock[i] = new([blockSize]int)
Why is cbblock a [4]*[blockSize]int and not a [4][blockSize]int (and similarly,
scaleBlock's second argument should become a *[4][blockSize]int)?

If you do the latter, you can still get to the address of an element like
&cbblock[0] to pass to rgbToYCbCr.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:586: if quality <= 0 {
if quality < 1 {

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:605: if val <= 0 {
if val < 1 {

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer.go...
src/pkg/image/jpeg/writer.go:624: e.w = bufio.NewWriter(w)
I wouldn't add buffering if w was already buffered, and *bufio.Writer isn't the
only Writer implementation that is buffered.

I would define a writer interface and check for that, like what
compress/lzw/writer.go does.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer_te...
File src/pkg/image/jpeg/writer_test.go (right):

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer_te...
src/pkg/image/jpeg/writer_test.go:58: "video-001",
I'd drop the basn cases, just use "../testdata/video-001.png" here, and remove
the src/pkg/image/jpeg/testdata/images/* files that you were going to add.

If you want more photographic test images, we could probably use some from
http://code.google.com/speed/webp/gallery.html, but that should be a separate
changelist.

Similarly, we can add grayscale imagery in a separate changelist.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer_te...
src/pkg/image/jpeg/writer_test.go:62: // Also note, exact pixel tolerance should
be readjusted emprically as more test images are added.
Typo in empirically.

http://codereview.appspot.com/4186064/diff/21001/src/pkg/image/jpeg/writer_te...
src/pkg/image/jpeg/writer_test.go:63: var tolerances = []int{16 * 256, 84 * 256}
Wow, 84/256 in chroma-space even at high quality!? How does libjpeg's encoding
compare?
Sign in to reply to this message.

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