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

Delta Between Two Patch Sets: src/image/gif/writer.go

Issue 147730043: code review 147730043: image/gif: fix GIF encoding of sub-images. (Closed)
Left Patch Set: Created 9 years, 6 months ago
Right Patch Set: diff -r a92a99ba40fb030955680fc19b1a489548049121 https://code.google.com/p/go/ Created 9 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/image/gif/writer_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package gif 5 package gif
6 6
7 import ( 7 import (
8 "bufio" 8 "bufio"
9 "compress/lzw" 9 "compress/lzw"
10 "errors" 10 "errors"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 // Local Color Table. 226 // Local Color Table.
227 e.writeColorTable(pm.Palette, paddedSize) 227 e.writeColorTable(pm.Palette, paddedSize)
228 228
229 litWidth := paddedSize + 1 229 litWidth := paddedSize + 1
230 if litWidth < 2 { 230 if litWidth < 2 {
231 litWidth = 2 231 litWidth = 2
232 } 232 }
233 e.writeByte(uint8(litWidth)) // LZW Minimum Code Size. 233 e.writeByte(uint8(litWidth)) // LZW Minimum Code Size.
234 234
235 lzww := lzw.NewWriter(blockWriter{e: e}, lzw.LSB, litWidth) 235 lzww := lzw.NewWriter(blockWriter{e: e}, lzw.LSB, litWidth)
236 » _, e.err = lzww.Write(pm.Pix) 236 » if dx := b.Dx(); dx == pm.Stride {
237 » if e.err != nil { 237 » » _, e.err = lzww.Write(pm.Pix)
238 » » lzww.Close() 238 » » if e.err != nil {
239 » » return 239 » » » lzww.Close()
240 » » » return
241 » » }
242 » } else {
243 » » for i, y := 0, b.Min.Y; y < b.Max.Y; i, y = i+pm.Stride, y+1 {
244 » » » _, e.err = lzww.Write(pm.Pix[i : i+dx])
245 » » » if e.err != nil {
246 » » » » lzww.Close()
247 » » » » return
248 » » » }
249 » » }
240 } 250 }
241 lzww.Close() 251 lzww.Close()
242 e.writeByte(0x00) // Block Terminator. 252 e.writeByte(0x00) // Block Terminator.
243 } 253 }
244 254
245 // Options are the encoding parameters. 255 // Options are the encoding parameters.
246 type Options struct { 256 type Options struct {
247 // NumColors is the maximum number of colors used in the image. 257 // NumColors is the maximum number of colors used in the image.
248 // It ranges from 1 to 256. 258 // It ranges from 1 to 256.
249 NumColors int 259 NumColors int
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 pm.Palette = opts.Quantizer.Quantize(make(color.Palette, 0, opts.NumColors), m) 324 pm.Palette = opts.Quantizer.Quantize(make(color.Palette, 0, opts.NumColors), m)
315 } 325 }
316 opts.Drawer.Draw(pm, b, m, image.ZP) 326 opts.Drawer.Draw(pm, b, m, image.ZP)
317 } 327 }
318 328
319 return EncodeAll(w, &GIF{ 329 return EncodeAll(w, &GIF{
320 Image: []*image.Paletted{pm}, 330 Image: []*image.Paletted{pm},
321 Delay: []int{0}, 331 Delay: []int{0},
322 }) 332 })
323 } 333 }
LEFTRIGHT

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