LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 jpeg implements a JPEG image decoder and encoder. | 5 // Package jpeg implements a JPEG image decoder and encoder. |
6 // | 6 // |
7 // JPEG is defined in ITU-T T.81: http://www.w3.org/Graphics/JPEG/itu-t81.pdf. | 7 // JPEG is defined in ITU-T T.81: http://www.w3.org/Graphics/JPEG/itu-t81.pdf. |
8 package jpeg | 8 package jpeg |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 167 } |
168 hv := d.tmp[7+3*i] | 168 hv := d.tmp[7+3*i] |
169 d.comp[i].h = int(hv >> 4) | 169 d.comp[i].h = int(hv >> 4) |
170 d.comp[i].v = int(hv & 0x0f) | 170 d.comp[i].v = int(hv & 0x0f) |
171 // For color images, we only support 4:4:4, 4:4:0, 4:2:2 or 4:2:
0 chroma | 171 // For color images, we only support 4:4:4, 4:4:0, 4:2:2 or 4:2:
0 chroma |
172 // downsampling ratios. This implies that the (h, v) values for
the Y | 172 // downsampling ratios. This implies that the (h, v) values for
the Y |
173 // component are either (1, 1), (1, 2), (2, 1) or (2, 2), and th
e (h, v) | 173 // component are either (1, 1), (1, 2), (2, 1) or (2, 2), and th
e (h, v) |
174 // values for the Cr and Cb components must be (1, 1). | 174 // values for the Cr and Cb components must be (1, 1). |
175 if i == 0 { | 175 if i == 0 { |
176 if hv != 0x11 && hv != 0x21 && hv != 0x22 && hv != 0x12
{ | 176 if hv != 0x11 && hv != 0x21 && hv != 0x22 && hv != 0x12
{ |
177 » » » » return UnsupportedError("luma downsample ratio") | 177 » » » » return UnsupportedError("luma/chroma downsample
ratio") |
178 } | 178 } |
179 } else if hv != 0x11 { | 179 } else if hv != 0x11 { |
180 » » » return UnsupportedError("chroma downsample ratio") | 180 » » » return UnsupportedError("luma/chroma downsample ratio") |
181 } | 181 } |
182 } | 182 } |
183 return nil | 183 return nil |
184 } | 184 } |
185 | 185 |
186 // Specified in section B.2.4.1. | 186 // Specified in section B.2.4.1. |
187 func (d *decoder) processDQT(n int) error { | 187 func (d *decoder) processDQT(n int) error { |
188 const qtLength = 1 + blockSize | 188 const qtLength = 1 + blockSize |
189 for ; n >= qtLength; n -= qtLength { | 189 for ; n >= qtLength; n -= qtLength { |
190 _, err := io.ReadFull(d.r, d.tmp[0:qtLength]) | 190 _, err := io.ReadFull(d.r, d.tmp[0:qtLength]) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 Width: d.width, | 368 Width: d.width, |
369 Height: d.height, | 369 Height: d.height, |
370 }, nil | 370 }, nil |
371 } | 371 } |
372 return image.Config{}, FormatError("missing SOF marker") | 372 return image.Config{}, FormatError("missing SOF marker") |
373 } | 373 } |
374 | 374 |
375 func init() { | 375 func init() { |
376 image.RegisterFormat("jpeg", "\xff\xd8", Decode, DecodeConfig) | 376 image.RegisterFormat("jpeg", "\xff\xd8", Decode, DecodeConfig) |
377 } | 377 } |
LEFT | RIGHT |