]> Cypherpunks repositories - gostls13.git/commitdiff
image/jpeg: send a correct Start Of Scan (SOS) header.
authorNigel Tao <nigeltao@golang.org>
Tue, 7 Aug 2012 23:57:09 +0000 (09:57 +1000)
committerNigel Tao <nigeltao@golang.org>
Tue, 7 Aug 2012 23:57:09 +0000 (09:57 +1000)
Section B.2.3 of http://www.w3.org/Graphics/JPEG/itu-t81.pdf discusses
the End of spectral selection (Se) byte.

Apparently many JPEG decoders ignore the Se byte (or let it through
with a warning), but some configurations reject them. For example,
http://download.blender.org/source/chest/blender_2.03_tree/jpeg/jcmaster.c
has these lines:

if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);

Fixes #3916.

R=r
CC=golang-dev
https://golang.org/cl/6459052

src/pkg/image/jpeg/writer.go

index 3322c09fe71a81ed685b6146e75082d6ed995ce4..d539b1da90800aeeeb1df69db277082ba15c05c7 100644 (file)
@@ -433,10 +433,12 @@ func scale(dst *block, src *[4]block) {
 //     - component 1 uses DC table 0 and AC table 0 "\x01\x00",
 //     - component 2 uses DC table 1 and AC table 1 "\x02\x11",
 //     - component 3 uses DC table 1 and AC table 1 "\x03\x11",
-//     - padding "\x00\x00\x00".
+//     - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
+//       sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
+//       should be 0x00, 0x3f, 0x00<<4 | 0x00.
 var sosHeader = []byte{
        0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02,
-       0x11, 0x03, 0x11, 0x00, 0x00, 0x00,
+       0x11, 0x03, 0x11, 0x00, 0x3f, 0x00,
 }
 
 // writeSOS writes the StartOfScan marker.