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
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
On 2011/02/21 04:18:21, nigeltao wrote:
> Just a bunch of very quick, mostly superficial comments for now. I'll have a
> proper look at the actual algorithm later.
>
> Also, it might be nice to have a writer_test that starts with a test pattern
> image, encodes it, decodes it, and checks that the result is reasonably
similar
> to the original test pattern. image/png/writer_test.go has some code that you
> could re-use for that.
I agree that's a good idea. Can I do that in a separate change?
> Adding R=r since I think Rob was also interested in a JPEG encoder.
>
> http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go
> File src/pkg/image/jpeg/writer.go (right):
>
>
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:12: // "fmt"
> Remove this, as well as the commented out fmt calls below.
Done.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:179: // By spec, 1 <= nbits <= 16
> Can you be more specific about which part of the spec? For example, see the
> comments in image/jpeg/reader.go.
Done.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:460: type UnknownColorModelError string
> var (
> ErrUnknownColorMode = os.NewError("jpeg: unknown color model")
> ErrUnknownSubsamplingMethod = os.NewError("jpeg: unknown subsampling
method")
> )
Done.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:473: subsample int
> These fields need to start with a capital letter to be used outside of the
jpeg
> package.
Good catch. Done.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:522: var e encoder
> We usually use a var ( ... ) block instead of multiple lines starting with
var.
> Same elsewhere in this file.
Not relevant, as code has changed.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:525: e.w = bw
> e.w = bufio.NewWriter(w) and delete the two lines above.
Done.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:540: return UnknownColorModelError("")
> I don't understand this restriction. Can't we encode a paletted image as a
> non-paletted JPEG, since a paletted image implements At(x, y).RGBA()?
Done. Perhaps I've now made it too lenient, although it feels to me that
converting arbitrary images into RGB is reasonable.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:542: e.writeHeader()
> All these write methods should return an os.Error, and if it returs non-nil
you
> should pass it up the call chain.
Done, but with some trepidation. My motivation in originally not doing so was to
rely on the guarantee by bufio.Writer that if a write to the underlying writer
fails, subsequent writes woud be swallowed, but that the err would be available
later, particularly on the Flush call. Relying on this simplifies the code
significantly, because there are now 42 instances of checking e.err, or 19% of
the total number of lines of code (!).
But I discussed this with Andrew Gerrand, and we came to the conclusion that it
was, on balance, the best thing to do, so here it is.
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
On 2011/02/22 19:54:46, r wrote:
> 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#ne...
> src/pkg/image/jpeg/fdct.go:31: for y := 0; y < 8; y++ {
> probably want (or maybe have) a constant for 8, since we have one for 64,
> however 8 is also easy to understand and the code uses 0, 1, 2, 3, 4, 5, 6, 7
> too. maybe just remind with a comment that blockSize is 8*8.
Done (comment). Here, I was following the example of idct.go. Generally I feel
it's most important to be consistent.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/fdct.go#ne...
> src/pkg/image/jpeg/fdct.go:45: tmp3 = b[y*8+3] - b[y*8+4]
> this code is fine for now but you can avoid half of the indexing operations.
Done. Of course, a good compiler would optimize that for you, but in the
meantime...
> http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go
> File src/pkg/image/jpeg/writer.go (right):
>
>
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:24: type encoder struct {
> they're obvious in meaning but still, these fields should have little comments
Done.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:42: bitsDcLuminance = []byte{0, 1, 5, 1, 1, 1, 1,
> 1, 1, 0, 0, 0, 0, 0, 0, 0}
> if you size these guys (you can use [...]) they'll be arrays, not slices, and
> indexing can be more efficient.
> but if you're not sure of the tradeoffs, leave them as is for now.
I tried this, but then passing the sized byte array to e.w.Write() failed,
because that expects a slice. Given the choice, it seems like a better idea not
to allocate a new slice on write, but that's arguable either way. Also see above
wrt good compiler.
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
> src/pkg/image/jpeg/writer.go:211: 0x64, 0x00, 0x64, 0x00, 0x00})
> these should be defined once - no need to reallocate these objects every time
Done.
13 years, 1 month ago
(2011-03-26 23:32:15 UTC)
#7
>
>
>
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
>> src/pkg/image/jpeg/writer.go:42: bitsDcLuminance = []byte{0, 1, 5, 1,
> 1, 1, 1,
>> 1, 1, 0, 0, 0, 0, 0, 0, 0}
>> if you size these guys (you can use [...]) they'll be arrays, not
> slices, and
>> indexing can be more efficient.
>> but if you're not sure of the tradeoffs, leave them as is for now.
>
> I tried this, but then passing the sized byte array to e.w.Write()
> failed, because that expects a slice. Given the choice, it seems like a
> better idea not to allocate a new slice on write, but that's arguable
> either way. Also see above wrt good compiler.
You don't allocate a slice. All that happens is a slice header, on the stack,
gets filled in. It's super cheap.
-rob
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
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 (right):
http://codereview.appspot.com/4186064/diff/2001/src/pkg/image/jpeg/writer.go#...
src/pkg/image/jpeg/writer.go:42: bitsDcLuminance = []byte{0, 1, 5, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0}
On 2011/02/22 19:54:46, r wrote:
> if you size these guys (you can use [...]) they'll be arrays, not slices, and
> indexing can be more efficient.
> but if you're not sure of the tradeoffs, leave them as is for now.
Ok, done. Thanks for the advice re stack allocation.
13 years, 1 month ago
(2011-03-27 01:49:33 UTC)
#11
On 2011/03/27 01:33:30, raph wrote:
> Hello nigeltao, r, r2 (cc: mailto:golang-dev@googlegroups.com),
>
> Please take another look.
Sorry for the clumsiness in using the codereview tool. I had to dig a bit deeper
to figure out how to add files to an existing CL, and separate upload from mail
so I could write meaningful comments. In any case, a roundtrip test is now
added, as per Nigel's request.
Issue 4186064: code review 4186064: image/jpeg: add encoder
Created 13 years, 2 months ago by raph
Modified 13 years, 1 month ago
Reviewers: nigeltao, r, r2
Base URL:
Comments: 42