Browse Source

Bump golang.org/x/image from 0.0.0-20180708004352-c73c2afc3b81 to 0.5.0

Bumps [golang.org/x/image](https://github.com/golang/image) from 0.0.0-20180708004352-c73c2afc3b81 to 0.5.0.
- [Release notes](https://github.com/golang/image/releases)
- [Commits](https://github.com/golang/image/commits/v0.5.0)

---
updated-dependencies:
- dependency-name: golang.org/x/image
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
dependabot[bot] 1 year ago
parent
commit
349700b554

+ 1 - 1
go.mod

@@ -12,7 +12,7 @@ require (
 
 require (
 	github.com/vladimirok5959/golang-ctrlc v1.0.2 // indirect
-	golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 // indirect
+	golang.org/x/image v0.5.0 // indirect
 	google.golang.org/appengine v1.4.0 // indirect
 )
 

+ 25 - 1
go.sum

@@ -15,9 +15,33 @@ github.com/vladimirok5959/golang-server-static v1.0.2 h1:pNR+vy+z2g73ETyx+50WxM4
 github.com/vladimirok5959/golang-server-static v1.0.2/go.mod h1:NN4wQ3UjLdeQA14S8REpAjtXZxMS1o8Fs7XxomDP1Q4=
 github.com/vladimirok5959/golang-worker v1.0.0 h1:Qu29qWnpy0eXn4dKMd5mEjH+by1o7JWErvcIkMhNQ50=
 github.com/vladimirok5959/golang-worker v1.0.0/go.mod h1:WQitGjRYwCuS1/AoOQvHHbvYXCqR+FSzFW0LsunkBy4=
-golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI=
+github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
+golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
+golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
+golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

+ 0 - 1
vendor/github.com/go-sql-driver/mysql/appengine.go

@@ -6,7 +6,6 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this file,
 // You can obtain one at http://mozilla.org/MPL/2.0/.
 
-//go:build appengine
 // +build appengine
 
 package mysql

+ 0 - 1
vendor/github.com/go-sql-driver/mysql/connection_go18.go

@@ -6,7 +6,6 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this file,
 // You can obtain one at http://mozilla.org/MPL/2.0/.
 
-//go:build go1.8
 // +build go1.8
 
 package mysql

+ 2 - 2
vendor/github.com/go-sql-driver/mysql/utils_go17.go

@@ -6,8 +6,8 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this file,
 // You can obtain one at http://mozilla.org/MPL/2.0/.
 
-//go:build go1.7 && !go1.8
-// +build go1.7,!go1.8
+// +build go1.7
+// +build !go1.8
 
 package mysql
 

+ 0 - 1
vendor/github.com/go-sql-driver/mysql/utils_go18.go

@@ -6,7 +6,6 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this file,
 // You can obtain one at http://mozilla.org/MPL/2.0/.
 
-//go:build go1.8
 // +build go1.8
 
 package mysql

+ 0 - 1
vendor/github.com/vladimirok5959/golang-ctrlc/ctrlc/platform_other.go

@@ -1,4 +1,3 @@
-//go:build !windows
 // +build !windows
 
 package ctrlc

+ 0 - 1
vendor/github.com/vladimirok5959/golang-ctrlc/ctrlc/platform_windows.go

@@ -1,4 +1,3 @@
-//go:build windows
 // +build windows
 
 package ctrlc

+ 0 - 3
vendor/golang.org/x/image/AUTHORS

@@ -1,3 +0,0 @@
-# This source code refers to The Go Authors for copyright purposes.
-# The master list of authors is in the main Go distribution,
-# visible at http://tip.golang.org/AUTHORS.

+ 0 - 3
vendor/golang.org/x/image/CONTRIBUTORS

@@ -1,3 +0,0 @@
-# This source code was written by the Go contributors.
-# The master list of contributors is in the main Go distribution,
-# visible at http://tip.golang.org/CONTRIBUTORS.

+ 75 - 29
vendor/golang.org/x/image/bmp/reader.go

@@ -85,7 +85,7 @@ func decodeRGB(r io.Reader, c image.Config, topDown bool) (image.Image, error) {
 
 // decodeNRGBA reads a 32 bit-per-pixel BMP image from r.
 // If topDown is false, the image rows will be read bottom-up.
-func decodeNRGBA(r io.Reader, c image.Config, topDown bool) (image.Image, error) {
+func decodeNRGBA(r io.Reader, c image.Config, topDown, allowAlpha bool) (image.Image, error) {
 	rgba := image.NewNRGBA(image.Rect(0, 0, c.Width, c.Height))
 	if c.Width == 0 || c.Height == 0 {
 		return rgba, nil
@@ -102,6 +102,9 @@ func decodeNRGBA(r io.Reader, c image.Config, topDown bool) (image.Image, error)
 		for i := 0; i < len(p); i += 4 {
 			// BMP images are stored in BGRA order rather than RGBA order.
 			p[i+0], p[i+2] = p[i+2], p[i+0]
+			if !allowAlpha {
+				p[i+3] = 0xFF
+			}
 		}
 	}
 	return rgba, nil
@@ -110,7 +113,7 @@ func decodeNRGBA(r io.Reader, c image.Config, topDown bool) (image.Image, error)
 // Decode reads a BMP image from r and returns it as an image.Image.
 // Limitation: The file must be 8, 24 or 32 bits per pixel.
 func Decode(r io.Reader) (image.Image, error) {
-	c, bpp, topDown, err := decodeConfig(r)
+	c, bpp, topDown, allowAlpha, err := decodeConfig(r)
 	if err != nil {
 		return nil, err
 	}
@@ -120,7 +123,7 @@ func Decode(r io.Reader) (image.Image, error) {
 	case 24:
 		return decodeRGB(r, c, topDown)
 	case 32:
-		return decodeNRGBA(r, c, topDown)
+		return decodeNRGBA(r, c, topDown, allowAlpha)
 	}
 	panic("unreachable")
 }
@@ -129,27 +132,41 @@ func Decode(r io.Reader) (image.Image, error) {
 // decoding the entire image.
 // Limitation: The file must be 8, 24 or 32 bits per pixel.
 func DecodeConfig(r io.Reader) (image.Config, error) {
-	config, _, _, err := decodeConfig(r)
+	config, _, _, _, err := decodeConfig(r)
 	return config, err
 }
 
-func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown bool, err error) {
-	// We only support those BMP images that are a BITMAPFILEHEADER
-	// immediately followed by a BITMAPINFOHEADER.
+func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown bool, allowAlpha bool, err error) {
+	// We only support those BMP images with one of the following DIB headers:
+	// - BITMAPINFOHEADER (40 bytes)
+	// - BITMAPV4HEADER (108 bytes)
+	// - BITMAPV5HEADER (124 bytes)
 	const (
-		fileHeaderLen = 14
-		infoHeaderLen = 40
+		fileHeaderLen   = 14
+		infoHeaderLen   = 40
+		v4InfoHeaderLen = 108
+		v5InfoHeaderLen = 124
 	)
 	var b [1024]byte
-	if _, err := io.ReadFull(r, b[:fileHeaderLen+infoHeaderLen]); err != nil {
-		return image.Config{}, 0, false, err
+	if _, err := io.ReadFull(r, b[:fileHeaderLen+4]); err != nil {
+		if err == io.EOF {
+			err = io.ErrUnexpectedEOF
+		}
+		return image.Config{}, 0, false, false, err
 	}
 	if string(b[:2]) != "BM" {
-		return image.Config{}, 0, false, errors.New("bmp: invalid format")
+		return image.Config{}, 0, false, false, errors.New("bmp: invalid format")
 	}
 	offset := readUint32(b[10:14])
-	if readUint32(b[14:18]) != infoHeaderLen {
-		return image.Config{}, 0, false, ErrUnsupported
+	infoLen := readUint32(b[14:18])
+	if infoLen != infoHeaderLen && infoLen != v4InfoHeaderLen && infoLen != v5InfoHeaderLen {
+		return image.Config{}, 0, false, false, ErrUnsupported
+	}
+	if _, err := io.ReadFull(r, b[fileHeaderLen+4:fileHeaderLen+infoLen]); err != nil {
+		if err == io.EOF {
+			err = io.ErrUnexpectedEOF
+		}
+		return image.Config{}, 0, false, false, err
 	}
 	width := int(int32(readUint32(b[18:22])))
 	height := int(int32(readUint32(b[22:26])))
@@ -157,21 +174,29 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b
 		height, topDown = -height, true
 	}
 	if width < 0 || height < 0 {
-		return image.Config{}, 0, false, ErrUnsupported
+		return image.Config{}, 0, false, false, ErrUnsupported
 	}
-	// We only support 1 plane, 8 or 24 bits per pixel and no compression.
+	// We only support 1 plane and 8, 24 or 32 bits per pixel and no
+	// compression.
 	planes, bpp, compression := readUint16(b[26:28]), readUint16(b[28:30]), readUint32(b[30:34])
+	// if compression is set to BI_BITFIELDS, but the bitmask is set to the default bitmask
+	// that would be used if compression was set to 0, we can continue as if compression was 0
+	if compression == 3 && infoLen > infoHeaderLen &&
+		readUint32(b[54:58]) == 0xff0000 && readUint32(b[58:62]) == 0xff00 &&
+		readUint32(b[62:66]) == 0xff && readUint32(b[66:70]) == 0xff000000 {
+		compression = 0
+	}
 	if planes != 1 || compression != 0 {
-		return image.Config{}, 0, false, ErrUnsupported
+		return image.Config{}, 0, false, false, ErrUnsupported
 	}
 	switch bpp {
 	case 8:
-		if offset != fileHeaderLen+infoHeaderLen+256*4 {
-			return image.Config{}, 0, false, ErrUnsupported
+		if offset != fileHeaderLen+infoLen+256*4 {
+			return image.Config{}, 0, false, false, ErrUnsupported
 		}
 		_, err = io.ReadFull(r, b[:256*4])
 		if err != nil {
-			return image.Config{}, 0, false, err
+			return image.Config{}, 0, false, false, err
 		}
 		pcm := make(color.Palette, 256)
 		for i := range pcm {
@@ -179,19 +204,40 @@ func decodeConfig(r io.Reader) (config image.Config, bitsPerPixel int, topDown b
 			// Every 4th byte is padding.
 			pcm[i] = color.RGBA{b[4*i+2], b[4*i+1], b[4*i+0], 0xFF}
 		}
-		return image.Config{ColorModel: pcm, Width: width, Height: height}, 8, topDown, nil
+		return image.Config{ColorModel: pcm, Width: width, Height: height}, 8, topDown, false, nil
 	case 24:
-		if offset != fileHeaderLen+infoHeaderLen {
-			return image.Config{}, 0, false, ErrUnsupported
+		if offset != fileHeaderLen+infoLen {
+			return image.Config{}, 0, false, false, ErrUnsupported
 		}
-		return image.Config{ColorModel: color.RGBAModel, Width: width, Height: height}, 24, topDown, nil
+		return image.Config{ColorModel: color.RGBAModel, Width: width, Height: height}, 24, topDown, false, nil
 	case 32:
-		if offset != fileHeaderLen+infoHeaderLen {
-			return image.Config{}, 0, false, ErrUnsupported
+		if offset != fileHeaderLen+infoLen {
+			return image.Config{}, 0, false, false, ErrUnsupported
 		}
-		return image.Config{ColorModel: color.RGBAModel, Width: width, Height: height}, 32, topDown, nil
-	}
-	return image.Config{}, 0, false, ErrUnsupported
+		// 32 bits per pixel is possibly RGBX (X is padding) or RGBA (A is
+		// alpha transparency). However, for BMP images, "Alpha is a
+		// poorly-documented and inconsistently-used feature" says
+		// https://source.chromium.org/chromium/chromium/src/+/bc0a792d7ebc587190d1a62ccddba10abeea274b:third_party/blink/renderer/platform/image-decoders/bmp/bmp_image_reader.cc;l=621
+		//
+		// That goes on to say "BITMAPV3HEADER+ have an alpha bitmask in the
+		// info header... so we respect it at all times... [For earlier
+		// (smaller) headers we] ignore alpha in Windows V3 BMPs except inside
+		// ICO files".
+		//
+		// "Ignore" means to always set alpha to 0xFF (fully opaque):
+		// https://source.chromium.org/chromium/chromium/src/+/bc0a792d7ebc587190d1a62ccddba10abeea274b:third_party/blink/renderer/platform/image-decoders/bmp/bmp_image_reader.h;l=272
+		//
+		// Confusingly, "Windows V3" does not correspond to BITMAPV3HEADER, but
+		// instead corresponds to the earlier (smaller) BITMAPINFOHEADER:
+		// https://source.chromium.org/chromium/chromium/src/+/bc0a792d7ebc587190d1a62ccddba10abeea274b:third_party/blink/renderer/platform/image-decoders/bmp/bmp_image_reader.cc;l=258
+		//
+		// This Go package does not support ICO files and the (infoLen >
+		// infoHeaderLen) condition distinguishes BITMAPINFOHEADER (40 bytes)
+		// vs later (larger) headers.
+		allowAlpha = infoLen > infoHeaderLen
+		return image.Config{ColorModel: color.RGBAModel, Width: width, Height: height}, 32, topDown, allowAlpha, nil
+	}
+	return image.Config{}, 0, false, false, ErrUnsupported
 }
 
 func init() {

+ 795 - 0
vendor/golang.org/x/image/ccitt/reader.go

@@ -0,0 +1,795 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:generate go run gen.go
+
+// Package ccitt implements a CCITT (fax) image decoder.
+package ccitt
+
+import (
+	"encoding/binary"
+	"errors"
+	"image"
+	"io"
+	"math/bits"
+)
+
+var (
+	errIncompleteCode          = errors.New("ccitt: incomplete code")
+	errInvalidBounds           = errors.New("ccitt: invalid bounds")
+	errInvalidCode             = errors.New("ccitt: invalid code")
+	errInvalidMode             = errors.New("ccitt: invalid mode")
+	errInvalidOffset           = errors.New("ccitt: invalid offset")
+	errMissingEOL              = errors.New("ccitt: missing End-of-Line")
+	errRunLengthOverflowsWidth = errors.New("ccitt: run length overflows width")
+	errRunLengthTooLong        = errors.New("ccitt: run length too long")
+	errUnsupportedMode         = errors.New("ccitt: unsupported mode")
+	errUnsupportedSubFormat    = errors.New("ccitt: unsupported sub-format")
+	errUnsupportedWidth        = errors.New("ccitt: unsupported width")
+)
+
+// Order specifies the bit ordering in a CCITT data stream.
+type Order uint32
+
+const (
+	// LSB means Least Significant Bits first.
+	LSB Order = iota
+	// MSB means Most Significant Bits first.
+	MSB
+)
+
+// SubFormat represents that the CCITT format consists of a number of
+// sub-formats. Decoding or encoding a CCITT data stream requires knowing the
+// sub-format context. It is not represented in the data stream per se.
+type SubFormat uint32
+
+const (
+	Group3 SubFormat = iota
+	Group4
+)
+
+// AutoDetectHeight is passed as the height argument to NewReader to indicate
+// that the image height (the number of rows) is not known in advance.
+const AutoDetectHeight = -1
+
+// Options are optional parameters.
+type Options struct {
+	// Align means that some variable-bit-width codes are byte-aligned.
+	Align bool
+	// Invert means that black is the 1 bit or 0xFF byte, and white is 0.
+	Invert bool
+}
+
+// maxWidth is the maximum (inclusive) supported width. This is a limitation of
+// this implementation, to guard against integer overflow, and not anything
+// inherent to the CCITT format.
+const maxWidth = 1 << 20
+
+func invertBytes(b []byte) {
+	for i, c := range b {
+		b[i] = ^c
+	}
+}
+
+func reverseBitsWithinBytes(b []byte) {
+	for i, c := range b {
+		b[i] = bits.Reverse8(c)
+	}
+}
+
+// highBits writes to dst (1 bit per pixel, most significant bit first) the
+// high (0x80) bits from src (1 byte per pixel). It returns the number of bytes
+// written and read such that dst[:d] is the packed form of src[:s].
+//
+// For example, if src starts with the 8 bytes [0x7D, 0x7E, 0x7F, 0x80, 0x81,
+// 0x82, 0x00, 0xFF] then 0x1D will be written to dst[0].
+//
+// If src has (8 * len(dst)) or more bytes then only len(dst) bytes are
+// written, (8 * len(dst)) bytes are read, and invert is ignored.
+//
+// Otherwise, if len(src) is not a multiple of 8 then the final byte written to
+// dst is padded with 1 bits (if invert is true) or 0 bits. If inverted, the 1s
+// are typically temporary, e.g. they will be flipped back to 0s by an
+// invertBytes call in the highBits caller, reader.Read.
+func highBits(dst []byte, src []byte, invert bool) (d int, s int) {
+	// Pack as many complete groups of 8 src bytes as we can.
+	n := len(src) / 8
+	if n > len(dst) {
+		n = len(dst)
+	}
+	dstN := dst[:n]
+	for i := range dstN {
+		src8 := src[i*8 : i*8+8]
+		dstN[i] = ((src8[0] & 0x80) >> 0) |
+			((src8[1] & 0x80) >> 1) |
+			((src8[2] & 0x80) >> 2) |
+			((src8[3] & 0x80) >> 3) |
+			((src8[4] & 0x80) >> 4) |
+			((src8[5] & 0x80) >> 5) |
+			((src8[6] & 0x80) >> 6) |
+			((src8[7] & 0x80) >> 7)
+	}
+	d, s = n, 8*n
+	dst, src = dst[d:], src[s:]
+
+	// Pack up to 7 remaining src bytes, if there's room in dst.
+	if (len(dst) > 0) && (len(src) > 0) {
+		dstByte := byte(0)
+		if invert {
+			dstByte = 0xFF >> uint(len(src))
+		}
+		for n, srcByte := range src {
+			dstByte |= (srcByte & 0x80) >> uint(n)
+		}
+		dst[0] = dstByte
+		d, s = d+1, s+len(src)
+	}
+	return d, s
+}
+
+type bitReader struct {
+	r io.Reader
+
+	// readErr is the error returned from the most recent r.Read call. As the
+	// io.Reader documentation says, when r.Read returns (n, err), "always
+	// process the n > 0 bytes returned before considering the error err".
+	readErr error
+
+	// order is whether to process r's bytes LSB first or MSB first.
+	order Order
+
+	// The high nBits bits of the bits field hold upcoming bits in MSB order.
+	bits  uint64
+	nBits uint32
+
+	// bytes[br:bw] holds bytes read from r but not yet loaded into bits.
+	br    uint32
+	bw    uint32
+	bytes [1024]uint8
+}
+
+func (b *bitReader) alignToByteBoundary() {
+	n := b.nBits & 7
+	b.bits <<= n
+	b.nBits -= n
+}
+
+// nextBitMaxNBits is the maximum possible value of bitReader.nBits after a
+// bitReader.nextBit call, provided that bitReader.nBits was not more than this
+// value before that call.
+//
+// Note that the decode function can unread bits, which can temporarily set the
+// bitReader.nBits value above nextBitMaxNBits.
+const nextBitMaxNBits = 31
+
+func (b *bitReader) nextBit() (uint64, error) {
+	for {
+		if b.nBits > 0 {
+			bit := b.bits >> 63
+			b.bits <<= 1
+			b.nBits--
+			return bit, nil
+		}
+
+		if available := b.bw - b.br; available >= 4 {
+			// Read 32 bits, even though b.bits is a uint64, since the decode
+			// function may need to unread up to maxCodeLength bits, putting
+			// them back in the remaining (64 - 32) bits. TestMaxCodeLength
+			// checks that the generated maxCodeLength constant fits.
+			//
+			// If changing the Uint32 call, also change nextBitMaxNBits.
+			b.bits = uint64(binary.BigEndian.Uint32(b.bytes[b.br:])) << 32
+			b.br += 4
+			b.nBits = 32
+			continue
+		} else if available > 0 {
+			b.bits = uint64(b.bytes[b.br]) << (7 * 8)
+			b.br++
+			b.nBits = 8
+			continue
+		}
+
+		if b.readErr != nil {
+			return 0, b.readErr
+		}
+
+		n, err := b.r.Read(b.bytes[:])
+		b.br = 0
+		b.bw = uint32(n)
+		b.readErr = err
+
+		if b.order != MSB {
+			reverseBitsWithinBytes(b.bytes[:b.bw])
+		}
+	}
+}
+
+func decode(b *bitReader, decodeTable [][2]int16) (uint32, error) {
+	nBitsRead, bitsRead, state := uint32(0), uint64(0), int32(1)
+	for {
+		bit, err := b.nextBit()
+		if err != nil {
+			if err == io.EOF {
+				err = errIncompleteCode
+			}
+			return 0, err
+		}
+		bitsRead |= bit << (63 - nBitsRead)
+		nBitsRead++
+
+		// The "&1" is redundant, but can eliminate a bounds check.
+		state = int32(decodeTable[state][bit&1])
+		if state < 0 {
+			return uint32(^state), nil
+		} else if state == 0 {
+			// Unread the bits we've read, then return errInvalidCode.
+			b.bits = (b.bits >> nBitsRead) | bitsRead
+			b.nBits += nBitsRead
+			return 0, errInvalidCode
+		}
+	}
+}
+
+// decodeEOL decodes the 12-bit EOL code 0000_0000_0001.
+func decodeEOL(b *bitReader) error {
+	nBitsRead, bitsRead := uint32(0), uint64(0)
+	for {
+		bit, err := b.nextBit()
+		if err != nil {
+			if err == io.EOF {
+				err = errMissingEOL
+			}
+			return err
+		}
+		bitsRead |= bit << (63 - nBitsRead)
+		nBitsRead++
+
+		if nBitsRead < 12 {
+			if bit&1 == 0 {
+				continue
+			}
+		} else if bit&1 != 0 {
+			return nil
+		}
+
+		// Unread the bits we've read, then return errMissingEOL.
+		b.bits = (b.bits >> nBitsRead) | bitsRead
+		b.nBits += nBitsRead
+		return errMissingEOL
+	}
+}
+
+type reader struct {
+	br        bitReader
+	subFormat SubFormat
+
+	// width is the image width in pixels.
+	width int
+
+	// rowsRemaining starts at the image height in pixels, when the reader is
+	// driven through the io.Reader interface, and decrements to zero as rows
+	// are decoded. Alternatively, it may be negative if the image height is
+	// not known in advance at the time of the NewReader call.
+	//
+	// When driven through DecodeIntoGray, this field is unused.
+	rowsRemaining int
+
+	// curr and prev hold the current and previous rows. Each element is either
+	// 0x00 (black) or 0xFF (white).
+	//
+	// prev may be nil, when processing the first row.
+	curr []byte
+	prev []byte
+
+	// ri is the read index. curr[:ri] are those bytes of curr that have been
+	// passed along via the Read method.
+	//
+	// When the reader is driven through DecodeIntoGray, instead of through the
+	// io.Reader interface, this field is unused.
+	ri int
+
+	// wi is the write index. curr[:wi] are those bytes of curr that have
+	// already been decoded via the decodeRow method.
+	//
+	// What this implementation calls wi is roughly equivalent to what the spec
+	// calls the a0 index.
+	wi int
+
+	// These fields are copied from the *Options (which may be nil).
+	align  bool
+	invert bool
+
+	// atStartOfRow is whether we have just started the row. Some parts of the
+	// spec say to treat this situation as if "wi = -1".
+	atStartOfRow bool
+
+	// penColorIsWhite is whether the next run is black or white.
+	penColorIsWhite bool
+
+	// seenStartOfImage is whether we've called the startDecode method.
+	seenStartOfImage bool
+
+	// truncated is whether the input is missing the final 6 consecutive EOL's
+	// (for Group3) or 2 consecutive EOL's (for Group4). Omitting that trailer
+	// (but otherwise padding to a byte boundary, with either all 0 bits or all
+	// 1 bits) is invalid according to the spec, but happens in practice when
+	// exporting from Adobe Acrobat to TIFF + CCITT. This package silently
+	// ignores the format error for CCITT input that has been truncated in that
+	// fashion, returning the full decoded image.
+	//
+	// Detecting trailer truncation (just after the final row of pixels)
+	// requires knowing which row is the final row, and therefore does not
+	// trigger if the image height is not known in advance.
+	truncated bool
+
+	// readErr is a sticky error for the Read method.
+	readErr error
+}
+
+func (z *reader) Read(p []byte) (int, error) {
+	if z.readErr != nil {
+		return 0, z.readErr
+	}
+	originalP := p
+
+	for len(p) > 0 {
+		// Allocate buffers (and decode any start-of-image codes), if
+		// processing the first or second row.
+		if z.curr == nil {
+			if !z.seenStartOfImage {
+				if z.readErr = z.startDecode(); z.readErr != nil {
+					break
+				}
+				z.atStartOfRow = true
+			}
+			z.curr = make([]byte, z.width)
+		}
+
+		// Decode the next row, if necessary.
+		if z.atStartOfRow {
+			if z.rowsRemaining < 0 {
+				// We do not know the image height in advance. See if the next
+				// code is an EOL. If it is, it is consumed. If it isn't, the
+				// bitReader shouldn't advance along the bit stream, and we
+				// simply decode another row of pixel data.
+				//
+				// For the Group4 subFormat, we may need to align to a byte
+				// boundary. For the Group3 subFormat, the previous z.decodeRow
+				// call (or z.startDecode call) has already consumed one of the
+				// 6 consecutive EOL's. The next EOL is actually the second of
+				// 6, in the middle, and we shouldn't align at that point.
+				if z.align && (z.subFormat == Group4) {
+					z.br.alignToByteBoundary()
+				}
+
+				if err := z.decodeEOL(); err == errMissingEOL {
+					// No-op. It's another row of pixel data.
+				} else if err != nil {
+					z.readErr = err
+					break
+				} else {
+					if z.readErr = z.finishDecode(true); z.readErr != nil {
+						break
+					}
+					z.readErr = io.EOF
+					break
+				}
+
+			} else if z.rowsRemaining == 0 {
+				// We do know the image height in advance, and we have already
+				// decoded exactly that many rows.
+				if z.readErr = z.finishDecode(false); z.readErr != nil {
+					break
+				}
+				z.readErr = io.EOF
+				break
+
+			} else {
+				z.rowsRemaining--
+			}
+
+			if z.readErr = z.decodeRow(z.rowsRemaining == 0); z.readErr != nil {
+				break
+			}
+		}
+
+		// Pack from z.curr (1 byte per pixel) to p (1 bit per pixel).
+		packD, packS := highBits(p, z.curr[z.ri:], z.invert)
+		p = p[packD:]
+		z.ri += packS
+
+		// Prepare to decode the next row, if necessary.
+		if z.ri == len(z.curr) {
+			z.ri, z.curr, z.prev = 0, z.prev, z.curr
+			z.atStartOfRow = true
+		}
+	}
+
+	n := len(originalP) - len(p)
+	if z.invert {
+		invertBytes(originalP[:n])
+	}
+	return n, z.readErr
+}
+
+func (z *reader) penColor() byte {
+	if z.penColorIsWhite {
+		return 0xFF
+	}
+	return 0x00
+}
+
+func (z *reader) startDecode() error {
+	switch z.subFormat {
+	case Group3:
+		if err := z.decodeEOL(); err != nil {
+			return err
+		}
+
+	case Group4:
+		// No-op.
+
+	default:
+		return errUnsupportedSubFormat
+	}
+
+	z.seenStartOfImage = true
+	return nil
+}
+
+func (z *reader) finishDecode(alreadySeenEOL bool) error {
+	numberOfEOLs := 0
+	switch z.subFormat {
+	case Group3:
+		if z.truncated {
+			return nil
+		}
+		// The stream ends with a RTC (Return To Control) of 6 consecutive
+		// EOL's, but we should have already just seen an EOL, either in
+		// z.startDecode (for a zero-height image) or in z.decodeRow.
+		numberOfEOLs = 5
+
+	case Group4:
+		autoDetectHeight := z.rowsRemaining < 0
+		if autoDetectHeight {
+			// Aligning to a byte boundary was already handled by reader.Read.
+		} else if z.align {
+			z.br.alignToByteBoundary()
+		}
+		// The stream ends with two EOL's. If the first one is missing, and we
+		// had an explicit image height, we just assume that the trailing two
+		// EOL's were truncated and return a nil error.
+		if err := z.decodeEOL(); err != nil {
+			if (err == errMissingEOL) && !autoDetectHeight {
+				z.truncated = true
+				return nil
+			}
+			return err
+		}
+		numberOfEOLs = 1
+
+	default:
+		return errUnsupportedSubFormat
+	}
+
+	if alreadySeenEOL {
+		numberOfEOLs--
+	}
+	for ; numberOfEOLs > 0; numberOfEOLs-- {
+		if err := z.decodeEOL(); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func (z *reader) decodeEOL() error {
+	return decodeEOL(&z.br)
+}
+
+func (z *reader) decodeRow(finalRow bool) error {
+	z.wi = 0
+	z.atStartOfRow = true
+	z.penColorIsWhite = true
+
+	if z.align {
+		z.br.alignToByteBoundary()
+	}
+
+	switch z.subFormat {
+	case Group3:
+		for ; z.wi < len(z.curr); z.atStartOfRow = false {
+			if err := z.decodeRun(); err != nil {
+				return err
+			}
+		}
+		err := z.decodeEOL()
+		if finalRow && (err == errMissingEOL) {
+			z.truncated = true
+			return nil
+		}
+		return err
+
+	case Group4:
+		for ; z.wi < len(z.curr); z.atStartOfRow = false {
+			mode, err := decode(&z.br, modeDecodeTable[:])
+			if err != nil {
+				return err
+			}
+			rm := readerMode{}
+			if mode < uint32(len(readerModes)) {
+				rm = readerModes[mode]
+			}
+			if rm.function == nil {
+				return errInvalidMode
+			}
+			if err := rm.function(z, rm.arg); err != nil {
+				return err
+			}
+		}
+		return nil
+	}
+
+	return errUnsupportedSubFormat
+}
+
+func (z *reader) decodeRun() error {
+	table := blackDecodeTable[:]
+	if z.penColorIsWhite {
+		table = whiteDecodeTable[:]
+	}
+
+	total := 0
+	for {
+		n, err := decode(&z.br, table)
+		if err != nil {
+			return err
+		}
+		if n > maxWidth {
+			panic("unreachable")
+		}
+		total += int(n)
+		if total > maxWidth {
+			return errRunLengthTooLong
+		}
+		// Anything 0x3F or below is a terminal code.
+		if n <= 0x3F {
+			break
+		}
+	}
+
+	if total > (len(z.curr) - z.wi) {
+		return errRunLengthOverflowsWidth
+	}
+	dst := z.curr[z.wi : z.wi+total]
+	penColor := z.penColor()
+	for i := range dst {
+		dst[i] = penColor
+	}
+	z.wi += total
+	z.penColorIsWhite = !z.penColorIsWhite
+
+	return nil
+}
+
+// The various modes' semantics are based on determining a row of pixels'
+// "changing elements": those pixels whose color differs from the one on its
+// immediate left.
+//
+// The row above the first row is implicitly all white. Similarly, the column
+// to the left of the first column is implicitly all white.
+//
+// For example, here's Figure 1 in "ITU-T Recommendation T.6", where the
+// current and previous rows contain black (B) and white (w) pixels. The a?
+// indexes point into curr, the b? indexes point into prev.
+//
+//                 b1 b2
+//                 v  v
+// prev: BBBBBwwwwwBBBwwwww
+// curr: BBBwwwwwBBBBBBwwww
+//          ^    ^     ^
+//          a0   a1    a2
+//
+// a0 is the "reference element" or current decoder position, roughly
+// equivalent to what this implementation calls reader.wi.
+//
+// a1 is the next changing element to the right of a0, on the "coding line"
+// (the current row).
+//
+// a2 is the next changing element to the right of a1, again on curr.
+//
+// b1 is the first changing element on the "reference line" (the previous row)
+// to the right of a0 and of opposite color to a0.
+//
+// b2 is the next changing element to the right of b1, again on prev.
+//
+// The various modes calculate a1 (and a2, for modeH):
+//  - modePass calculates that a1 is at or to the right of b2.
+//  - modeH    calculates a1 and a2 without considering b1 or b2.
+//  - modeV*   calculates a1 to be b1 plus an adjustment (between -3 and +3).
+
+const (
+	findB1 = false
+	findB2 = true
+)
+
+// findB finds either the b1 or b2 value.
+func (z *reader) findB(whichB bool) int {
+	// The initial row is a special case. The previous row is implicitly all
+	// white, so that there are no changing pixel elements. We return b1 or b2
+	// to be at the end of the row.
+	if len(z.prev) != len(z.curr) {
+		return len(z.curr)
+	}
+
+	i := z.wi
+
+	if z.atStartOfRow {
+		// a0 is implicitly at -1, on a white pixel. b1 is the first black
+		// pixel in the previous row. b2 is the first white pixel after that.
+		for ; (i < len(z.prev)) && (z.prev[i] == 0xFF); i++ {
+		}
+		if whichB == findB2 {
+			for ; (i < len(z.prev)) && (z.prev[i] == 0x00); i++ {
+			}
+		}
+		return i
+	}
+
+	// As per figure 1 above, assume that the current pen color is white.
+	// First, walk past every contiguous black pixel in prev, starting at a0.
+	oppositeColor := ^z.penColor()
+	for ; (i < len(z.prev)) && (z.prev[i] == oppositeColor); i++ {
+	}
+
+	// Then walk past every contiguous white pixel.
+	penColor := ^oppositeColor
+	for ; (i < len(z.prev)) && (z.prev[i] == penColor); i++ {
+	}
+
+	// We're now at a black pixel (or at the end of the row). That's b1.
+	if whichB == findB2 {
+		// If we're looking for b2, walk past every contiguous black pixel
+		// again.
+		oppositeColor := ^penColor
+		for ; (i < len(z.prev)) && (z.prev[i] == oppositeColor); i++ {
+		}
+	}
+
+	return i
+}
+
+type readerMode struct {
+	function func(z *reader, arg int) error
+	arg      int
+}
+
+var readerModes = [...]readerMode{
+	modePass: {function: readerModePass},
+	modeH:    {function: readerModeH},
+	modeV0:   {function: readerModeV, arg: +0},
+	modeVR1:  {function: readerModeV, arg: +1},
+	modeVR2:  {function: readerModeV, arg: +2},
+	modeVR3:  {function: readerModeV, arg: +3},
+	modeVL1:  {function: readerModeV, arg: -1},
+	modeVL2:  {function: readerModeV, arg: -2},
+	modeVL3:  {function: readerModeV, arg: -3},
+	modeExt:  {function: readerModeExt},
+}
+
+func readerModePass(z *reader, arg int) error {
+	b2 := z.findB(findB2)
+	if (b2 < z.wi) || (len(z.curr) < b2) {
+		return errInvalidOffset
+	}
+	dst := z.curr[z.wi:b2]
+	penColor := z.penColor()
+	for i := range dst {
+		dst[i] = penColor
+	}
+	z.wi = b2
+	return nil
+}
+
+func readerModeH(z *reader, arg int) error {
+	// The first iteration finds a1. The second finds a2.
+	for i := 0; i < 2; i++ {
+		if err := z.decodeRun(); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func readerModeV(z *reader, arg int) error {
+	a1 := z.findB(findB1) + arg
+	if (a1 < z.wi) || (len(z.curr) < a1) {
+		return errInvalidOffset
+	}
+	dst := z.curr[z.wi:a1]
+	penColor := z.penColor()
+	for i := range dst {
+		dst[i] = penColor
+	}
+	z.wi = a1
+	z.penColorIsWhite = !z.penColorIsWhite
+	return nil
+}
+
+func readerModeExt(z *reader, arg int) error {
+	return errUnsupportedMode
+}
+
+// DecodeIntoGray decodes the CCITT-formatted data in r into dst.
+//
+// It returns an error if dst's width and height don't match the implied width
+// and height of CCITT-formatted data.
+func DecodeIntoGray(dst *image.Gray, r io.Reader, order Order, sf SubFormat, opts *Options) error {
+	bounds := dst.Bounds()
+	if (bounds.Dx() < 0) || (bounds.Dy() < 0) {
+		return errInvalidBounds
+	}
+	if bounds.Dx() > maxWidth {
+		return errUnsupportedWidth
+	}
+
+	z := reader{
+		br:        bitReader{r: r, order: order},
+		subFormat: sf,
+		align:     (opts != nil) && opts.Align,
+		invert:    (opts != nil) && opts.Invert,
+		width:     bounds.Dx(),
+	}
+	if err := z.startDecode(); err != nil {
+		return err
+	}
+
+	width := bounds.Dx()
+	for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
+		p := (y - bounds.Min.Y) * dst.Stride
+		z.curr = dst.Pix[p : p+width]
+		if err := z.decodeRow(y+1 == bounds.Max.Y); err != nil {
+			return err
+		}
+		z.curr, z.prev = nil, z.curr
+	}
+
+	if err := z.finishDecode(false); err != nil {
+		return err
+	}
+
+	if z.invert {
+		for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
+			p := (y - bounds.Min.Y) * dst.Stride
+			invertBytes(dst.Pix[p : p+width])
+		}
+	}
+
+	return nil
+}
+
+// NewReader returns an io.Reader that decodes the CCITT-formatted data in r.
+// The resultant byte stream is one bit per pixel (MSB first), with 1 meaning
+// white and 0 meaning black. Each row in the result is byte-aligned.
+//
+// A negative height, such as passing AutoDetectHeight, means that the image
+// height is not known in advance. A negative width is invalid.
+func NewReader(r io.Reader, order Order, sf SubFormat, width int, height int, opts *Options) io.Reader {
+	readErr := error(nil)
+	if width < 0 {
+		readErr = errInvalidBounds
+	} else if width > maxWidth {
+		readErr = errUnsupportedWidth
+	}
+
+	return &reader{
+		br:            bitReader{r: r, order: order},
+		subFormat:     sf,
+		align:         (opts != nil) && opts.Align,
+		invert:        (opts != nil) && opts.Invert,
+		width:         width,
+		rowsRemaining: height,
+		readErr:       readErr,
+	}
+}

+ 972 - 0
vendor/golang.org/x/image/ccitt/table.go

@@ -0,0 +1,972 @@
+// generated by "go run gen.go". DO NOT EDIT.
+
+package ccitt
+
+// Each decodeTable is represented by an array of [2]int16's: a binary tree.
+// Each array element (other than element 0, which means invalid) is a branch
+// node in that tree. The root node is always element 1 (the second element).
+//
+// To walk the tree, look at the next bit in the bit stream, using it to select
+// the first or second element of the [2]int16. If that int16 is 0, we have an
+// invalid code. If it is positive, go to that branch node. If it is negative,
+// then we have a leaf node, whose value is the bitwise complement (the ^
+// operator) of that int16.
+//
+// Comments above each decodeTable also show the same structure visually. The
+// "b123" lines show the 123'rd branch node. The "=XXXXX" lines show an invalid
+// code. The "=v1234" lines show a leaf node with value 1234. When reading the
+// bit stream, a 0 or 1 bit means to go up or down, as you move left to right.
+//
+// For example, in modeDecodeTable, branch node b005 is three steps up from the
+// root node, meaning that we have already seen "000". If the next bit is "0"
+// then we move to branch node b006. Otherwise, the next bit is "1", and we
+// move to the leaf node v0000 (also known as the modePass constant). Indeed,
+// the bits that encode modePass are "0001".
+//
+// Tables 1, 2 and 3 come from the "ITU-T Recommendation T.6: FACSIMILE CODING
+// SCHEMES AND CODING CONTROL FUNCTIONS FOR GROUP 4 FACSIMILE APPARATUS"
+// specification:
+//
+// https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.6-198811-I!!PDF-E&type=items
+
+// modeDecodeTable represents Table 1 and the End-of-Line code.
+//
+//	                   +=XXXXX
+//	b009             +-+
+//	                 | +=v0009
+//	b007           +-+
+//	               | | +=v0008
+//	b010           | +-+
+//	               |   +=v0005
+//	b006         +-+
+//	             | | +=v0007
+//	b008         | +-+
+//	             |   +=v0004
+//	b005       +-+
+//	           | +=v0000
+//	b003     +-+
+//	         | +=v0001
+//	b002   +-+
+//	       | | +=v0006
+//	b004   | +-+
+//	       |   +=v0003
+//	b001 +-+
+//	       +=v0002
+var modeDecodeTable = [...][2]int16{
+	0:  {0, 0},
+	1:  {2, ^2},
+	2:  {3, 4},
+	3:  {5, ^1},
+	4:  {^6, ^3},
+	5:  {6, ^0},
+	6:  {7, 8},
+	7:  {9, 10},
+	8:  {^7, ^4},
+	9:  {0, ^9},
+	10: {^8, ^5},
+}
+
+// whiteDecodeTable represents Tables 2 and 3 for a white run.
+//
+//	                     +=XXXXX
+//	b059               +-+
+//	                   | |     +=v1792
+//	b096               | |   +-+
+//	                   | |   | | +=v1984
+//	b100               | |   | +-+
+//	                   | |   |   +=v2048
+//	b094               | | +-+
+//	                   | | | |   +=v2112
+//	b101               | | | | +-+
+//	                   | | | | | +=v2176
+//	b097               | | | +-+
+//	                   | | |   | +=v2240
+//	b102               | | |   +-+
+//	                   | | |     +=v2304
+//	b085               | +-+
+//	                   |   |   +=v1856
+//	b098               |   | +-+
+//	                   |   | | +=v1920
+//	b095               |   +-+
+//	                   |     |   +=v2368
+//	b103               |     | +-+
+//	                   |     | | +=v2432
+//	b099               |     +-+
+//	                   |       | +=v2496
+//	b104               |       +-+
+//	                   |         +=v2560
+//	b040             +-+
+//	                 | | +=v0029
+//	b060             | +-+
+//	                 |   +=v0030
+//	b026           +-+
+//	               | |   +=v0045
+//	b061           | | +-+
+//	               | | | +=v0046
+//	b041           | +-+
+//	               |   +=v0022
+//	b016         +-+
+//	             | |   +=v0023
+//	b042         | | +-+
+//	             | | | | +=v0047
+//	b062         | | | +-+
+//	             | | |   +=v0048
+//	b027         | +-+
+//	             |   +=v0013
+//	b008       +-+
+//	           | |     +=v0020
+//	b043       | |   +-+
+//	           | |   | | +=v0033
+//	b063       | |   | +-+
+//	           | |   |   +=v0034
+//	b028       | | +-+
+//	           | | | |   +=v0035
+//	b064       | | | | +-+
+//	           | | | | | +=v0036
+//	b044       | | | +-+
+//	           | | |   | +=v0037
+//	b065       | | |   +-+
+//	           | | |     +=v0038
+//	b017       | +-+
+//	           |   |   +=v0019
+//	b045       |   | +-+
+//	           |   | | | +=v0031
+//	b066       |   | | +-+
+//	           |   | |   +=v0032
+//	b029       |   +-+
+//	           |     +=v0001
+//	b004     +-+
+//	         | |     +=v0012
+//	b030     | |   +-+
+//	         | |   | |   +=v0053
+//	b067     | |   | | +-+
+//	         | |   | | | +=v0054
+//	b046     | |   | +-+
+//	         | |   |   +=v0026
+//	b018     | | +-+
+//	         | | | |     +=v0039
+//	b068     | | | |   +-+
+//	         | | | |   | +=v0040
+//	b047     | | | | +-+
+//	         | | | | | | +=v0041
+//	b069     | | | | | +-+
+//	         | | | | |   +=v0042
+//	b031     | | | +-+
+//	         | | |   |   +=v0043
+//	b070     | | |   | +-+
+//	         | | |   | | +=v0044
+//	b048     | | |   +-+
+//	         | | |     +=v0021
+//	b009     | +-+
+//	         |   |     +=v0028
+//	b049     |   |   +-+
+//	         |   |   | | +=v0061
+//	b071     |   |   | +-+
+//	         |   |   |   +=v0062
+//	b032     |   | +-+
+//	         |   | | |   +=v0063
+//	b072     |   | | | +-+
+//	         |   | | | | +=v0000
+//	b050     |   | | +-+
+//	         |   | |   | +=v0320
+//	b073     |   | |   +-+
+//	         |   | |     +=v0384
+//	b019     |   +-+
+//	         |     +=v0010
+//	b002   +-+
+//	       | |     +=v0011
+//	b020   | |   +-+
+//	       | |   | |   +=v0027
+//	b051   | |   | | +-+
+//	       | |   | | | | +=v0059
+//	b074   | |   | | | +-+
+//	       | |   | | |   +=v0060
+//	b033   | |   | +-+
+//	       | |   |   |     +=v1472
+//	b086   | |   |   |   +-+
+//	       | |   |   |   | +=v1536
+//	b075   | |   |   | +-+
+//	       | |   |   | | | +=v1600
+//	b087   | |   |   | | +-+
+//	       | |   |   | |   +=v1728
+//	b052   | |   |   +-+
+//	       | |   |     +=v0018
+//	b010   | | +-+
+//	       | | | |     +=v0024
+//	b053   | | | |   +-+
+//	       | | | |   | | +=v0049
+//	b076   | | | |   | +-+
+//	       | | | |   |   +=v0050
+//	b034   | | | | +-+
+//	       | | | | | |   +=v0051
+//	b077   | | | | | | +-+
+//	       | | | | | | | +=v0052
+//	b054   | | | | | +-+
+//	       | | | | |   +=v0025
+//	b021   | | | +-+
+//	       | | |   |     +=v0055
+//	b078   | | |   |   +-+
+//	       | | |   |   | +=v0056
+//	b055   | | |   | +-+
+//	       | | |   | | | +=v0057
+//	b079   | | |   | | +-+
+//	       | | |   | |   +=v0058
+//	b035   | | |   +-+
+//	       | | |     +=v0192
+//	b005   | +-+
+//	       |   |     +=v1664
+//	b036   |   |   +-+
+//	       |   |   | |   +=v0448
+//	b080   |   |   | | +-+
+//	       |   |   | | | +=v0512
+//	b056   |   |   | +-+
+//	       |   |   |   |   +=v0704
+//	b088   |   |   |   | +-+
+//	       |   |   |   | | +=v0768
+//	b081   |   |   |   +-+
+//	       |   |   |     +=v0640
+//	b022   |   | +-+
+//	       |   | | |     +=v0576
+//	b082   |   | | |   +-+
+//	       |   | | |   | | +=v0832
+//	b089   |   | | |   | +-+
+//	       |   | | |   |   +=v0896
+//	b057   |   | | | +-+
+//	       |   | | | | |   +=v0960
+//	b090   |   | | | | | +-+
+//	       |   | | | | | | +=v1024
+//	b083   |   | | | | +-+
+//	       |   | | | |   | +=v1088
+//	b091   |   | | | |   +-+
+//	       |   | | | |     +=v1152
+//	b037   |   | | +-+
+//	       |   | |   |     +=v1216
+//	b092   |   | |   |   +-+
+//	       |   | |   |   | +=v1280
+//	b084   |   | |   | +-+
+//	       |   | |   | | | +=v1344
+//	b093   |   | |   | | +-+
+//	       |   | |   | |   +=v1408
+//	b058   |   | |   +-+
+//	       |   | |     +=v0256
+//	b011   |   +-+
+//	       |     +=v0002
+//	b001 +-+
+//	       |     +=v0003
+//	b012   |   +-+
+//	       |   | | +=v0128
+//	b023   |   | +-+
+//	       |   |   +=v0008
+//	b006   | +-+
+//	       | | |   +=v0009
+//	b024   | | | +-+
+//	       | | | | | +=v0016
+//	b038   | | | | +-+
+//	       | | | |   +=v0017
+//	b013   | | +-+
+//	       | |   +=v0004
+//	b003   +-+
+//	         |   +=v0005
+//	b014     | +-+
+//	         | | |   +=v0014
+//	b039     | | | +-+
+//	         | | | | +=v0015
+//	b025     | | +-+
+//	         | |   +=v0064
+//	b007     +-+
+//	           | +=v0006
+//	b015       +-+
+//	             +=v0007
+var whiteDecodeTable = [...][2]int16{
+	0:   {0, 0},
+	1:   {2, 3},
+	2:   {4, 5},
+	3:   {6, 7},
+	4:   {8, 9},
+	5:   {10, 11},
+	6:   {12, 13},
+	7:   {14, 15},
+	8:   {16, 17},
+	9:   {18, 19},
+	10:  {20, 21},
+	11:  {22, ^2},
+	12:  {^3, 23},
+	13:  {24, ^4},
+	14:  {^5, 25},
+	15:  {^6, ^7},
+	16:  {26, 27},
+	17:  {28, 29},
+	18:  {30, 31},
+	19:  {32, ^10},
+	20:  {^11, 33},
+	21:  {34, 35},
+	22:  {36, 37},
+	23:  {^128, ^8},
+	24:  {^9, 38},
+	25:  {39, ^64},
+	26:  {40, 41},
+	27:  {42, ^13},
+	28:  {43, 44},
+	29:  {45, ^1},
+	30:  {^12, 46},
+	31:  {47, 48},
+	32:  {49, 50},
+	33:  {51, 52},
+	34:  {53, 54},
+	35:  {55, ^192},
+	36:  {^1664, 56},
+	37:  {57, 58},
+	38:  {^16, ^17},
+	39:  {^14, ^15},
+	40:  {59, 60},
+	41:  {61, ^22},
+	42:  {^23, 62},
+	43:  {^20, 63},
+	44:  {64, 65},
+	45:  {^19, 66},
+	46:  {67, ^26},
+	47:  {68, 69},
+	48:  {70, ^21},
+	49:  {^28, 71},
+	50:  {72, 73},
+	51:  {^27, 74},
+	52:  {75, ^18},
+	53:  {^24, 76},
+	54:  {77, ^25},
+	55:  {78, 79},
+	56:  {80, 81},
+	57:  {82, 83},
+	58:  {84, ^256},
+	59:  {0, 85},
+	60:  {^29, ^30},
+	61:  {^45, ^46},
+	62:  {^47, ^48},
+	63:  {^33, ^34},
+	64:  {^35, ^36},
+	65:  {^37, ^38},
+	66:  {^31, ^32},
+	67:  {^53, ^54},
+	68:  {^39, ^40},
+	69:  {^41, ^42},
+	70:  {^43, ^44},
+	71:  {^61, ^62},
+	72:  {^63, ^0},
+	73:  {^320, ^384},
+	74:  {^59, ^60},
+	75:  {86, 87},
+	76:  {^49, ^50},
+	77:  {^51, ^52},
+	78:  {^55, ^56},
+	79:  {^57, ^58},
+	80:  {^448, ^512},
+	81:  {88, ^640},
+	82:  {^576, 89},
+	83:  {90, 91},
+	84:  {92, 93},
+	85:  {94, 95},
+	86:  {^1472, ^1536},
+	87:  {^1600, ^1728},
+	88:  {^704, ^768},
+	89:  {^832, ^896},
+	90:  {^960, ^1024},
+	91:  {^1088, ^1152},
+	92:  {^1216, ^1280},
+	93:  {^1344, ^1408},
+	94:  {96, 97},
+	95:  {98, 99},
+	96:  {^1792, 100},
+	97:  {101, 102},
+	98:  {^1856, ^1920},
+	99:  {103, 104},
+	100: {^1984, ^2048},
+	101: {^2112, ^2176},
+	102: {^2240, ^2304},
+	103: {^2368, ^2432},
+	104: {^2496, ^2560},
+}
+
+// blackDecodeTable represents Tables 2 and 3 for a black run.
+//
+//	                     +=XXXXX
+//	b017               +-+
+//	                   | |     +=v1792
+//	b042               | |   +-+
+//	                   | |   | | +=v1984
+//	b063               | |   | +-+
+//	                   | |   |   +=v2048
+//	b029               | | +-+
+//	                   | | | |   +=v2112
+//	b064               | | | | +-+
+//	                   | | | | | +=v2176
+//	b043               | | | +-+
+//	                   | | |   | +=v2240
+//	b065               | | |   +-+
+//	                   | | |     +=v2304
+//	b022               | +-+
+//	                   |   |   +=v1856
+//	b044               |   | +-+
+//	                   |   | | +=v1920
+//	b030               |   +-+
+//	                   |     |   +=v2368
+//	b066               |     | +-+
+//	                   |     | | +=v2432
+//	b045               |     +-+
+//	                   |       | +=v2496
+//	b067               |       +-+
+//	                   |         +=v2560
+//	b013             +-+
+//	                 | |     +=v0018
+//	b031             | |   +-+
+//	                 | |   | |   +=v0052
+//	b068             | |   | | +-+
+//	                 | |   | | | | +=v0640
+//	b095             | |   | | | +-+
+//	                 | |   | | |   +=v0704
+//	b046             | |   | +-+
+//	                 | |   |   |   +=v0768
+//	b096             | |   |   | +-+
+//	                 | |   |   | | +=v0832
+//	b069             | |   |   +-+
+//	                 | |   |     +=v0055
+//	b023             | | +-+
+//	                 | | | |     +=v0056
+//	b070             | | | |   +-+
+//	                 | | | |   | | +=v1280
+//	b097             | | | |   | +-+
+//	                 | | | |   |   +=v1344
+//	b047             | | | | +-+
+//	                 | | | | | |   +=v1408
+//	b098             | | | | | | +-+
+//	                 | | | | | | | +=v1472
+//	b071             | | | | | +-+
+//	                 | | | | |   +=v0059
+//	b032             | | | +-+
+//	                 | | |   |   +=v0060
+//	b072             | | |   | +-+
+//	                 | | |   | | | +=v1536
+//	b099             | | |   | | +-+
+//	                 | | |   | |   +=v1600
+//	b048             | | |   +-+
+//	                 | | |     +=v0024
+//	b018             | +-+
+//	                 |   |     +=v0025
+//	b049             |   |   +-+
+//	                 |   |   | |   +=v1664
+//	b100             |   |   | | +-+
+//	                 |   |   | | | +=v1728
+//	b073             |   |   | +-+
+//	                 |   |   |   +=v0320
+//	b033             |   | +-+
+//	                 |   | | |   +=v0384
+//	b074             |   | | | +-+
+//	                 |   | | | | +=v0448
+//	b050             |   | | +-+
+//	                 |   | |   |   +=v0512
+//	b101             |   | |   | +-+
+//	                 |   | |   | | +=v0576
+//	b075             |   | |   +-+
+//	                 |   | |     +=v0053
+//	b024             |   +-+
+//	                 |     |     +=v0054
+//	b076             |     |   +-+
+//	                 |     |   | | +=v0896
+//	b102             |     |   | +-+
+//	                 |     |   |   +=v0960
+//	b051             |     | +-+
+//	                 |     | | |   +=v1024
+//	b103             |     | | | +-+
+//	                 |     | | | | +=v1088
+//	b077             |     | | +-+
+//	                 |     | |   | +=v1152
+//	b104             |     | |   +-+
+//	                 |     | |     +=v1216
+//	b034             |     +-+
+//	                 |       +=v0064
+//	b010           +-+
+//	               | |   +=v0013
+//	b019           | | +-+
+//	               | | | |     +=v0023
+//	b052           | | | |   +-+
+//	               | | | |   | | +=v0050
+//	b078           | | | |   | +-+
+//	               | | | |   |   +=v0051
+//	b035           | | | | +-+
+//	               | | | | | |   +=v0044
+//	b079           | | | | | | +-+
+//	               | | | | | | | +=v0045
+//	b053           | | | | | +-+
+//	               | | | | |   | +=v0046
+//	b080           | | | | |   +-+
+//	               | | | | |     +=v0047
+//	b025           | | | +-+
+//	               | | |   |     +=v0057
+//	b081           | | |   |   +-+
+//	               | | |   |   | +=v0058
+//	b054           | | |   | +-+
+//	               | | |   | | | +=v0061
+//	b082           | | |   | | +-+
+//	               | | |   | |   +=v0256
+//	b036           | | |   +-+
+//	               | | |     +=v0016
+//	b014           | +-+
+//	               |   |     +=v0017
+//	b037           |   |   +-+
+//	               |   |   | |   +=v0048
+//	b083           |   |   | | +-+
+//	               |   |   | | | +=v0049
+//	b055           |   |   | +-+
+//	               |   |   |   | +=v0062
+//	b084           |   |   |   +-+
+//	               |   |   |     +=v0063
+//	b026           |   | +-+
+//	               |   | | |     +=v0030
+//	b085           |   | | |   +-+
+//	               |   | | |   | +=v0031
+//	b056           |   | | | +-+
+//	               |   | | | | | +=v0032
+//	b086           |   | | | | +-+
+//	               |   | | | |   +=v0033
+//	b038           |   | | +-+
+//	               |   | |   |   +=v0040
+//	b087           |   | |   | +-+
+//	               |   | |   | | +=v0041
+//	b057           |   | |   +-+
+//	               |   | |     +=v0022
+//	b020           |   +-+
+//	               |     +=v0014
+//	b008         +-+
+//	             | |   +=v0010
+//	b015         | | +-+
+//	             | | | +=v0011
+//	b011         | +-+
+//	             |   |     +=v0015
+//	b027         |   |   +-+
+//	             |   |   | |     +=v0128
+//	b088         |   |   | |   +-+
+//	             |   |   | |   | +=v0192
+//	b058         |   |   | | +-+
+//	             |   |   | | | | +=v0026
+//	b089         |   |   | | | +-+
+//	             |   |   | | |   +=v0027
+//	b039         |   |   | +-+
+//	             |   |   |   |   +=v0028
+//	b090         |   |   |   | +-+
+//	             |   |   |   | | +=v0029
+//	b059         |   |   |   +-+
+//	             |   |   |     +=v0019
+//	b021         |   | +-+
+//	             |   | | |     +=v0020
+//	b060         |   | | |   +-+
+//	             |   | | |   | | +=v0034
+//	b091         |   | | |   | +-+
+//	             |   | | |   |   +=v0035
+//	b040         |   | | | +-+
+//	             |   | | | | |   +=v0036
+//	b092         |   | | | | | +-+
+//	             |   | | | | | | +=v0037
+//	b061         |   | | | | +-+
+//	             |   | | | |   | +=v0038
+//	b093         |   | | | |   +-+
+//	             |   | | | |     +=v0039
+//	b028         |   | | +-+
+//	             |   | |   |   +=v0021
+//	b062         |   | |   | +-+
+//	             |   | |   | | | +=v0042
+//	b094         |   | |   | | +-+
+//	             |   | |   | |   +=v0043
+//	b041         |   | |   +-+
+//	             |   | |     +=v0000
+//	b016         |   +-+
+//	             |     +=v0012
+//	b006       +-+
+//	           | |   +=v0009
+//	b012       | | +-+
+//	           | | | +=v0008
+//	b009       | +-+
+//	           |   +=v0007
+//	b004     +-+
+//	         | | +=v0006
+//	b007     | +-+
+//	         |   +=v0005
+//	b002   +-+
+//	       | | +=v0001
+//	b005   | +-+
+//	       |   +=v0004
+//	b001 +-+
+//	       | +=v0003
+//	b003   +-+
+//	         +=v0002
+var blackDecodeTable = [...][2]int16{
+	0:   {0, 0},
+	1:   {2, 3},
+	2:   {4, 5},
+	3:   {^3, ^2},
+	4:   {6, 7},
+	5:   {^1, ^4},
+	6:   {8, 9},
+	7:   {^6, ^5},
+	8:   {10, 11},
+	9:   {12, ^7},
+	10:  {13, 14},
+	11:  {15, 16},
+	12:  {^9, ^8},
+	13:  {17, 18},
+	14:  {19, 20},
+	15:  {^10, ^11},
+	16:  {21, ^12},
+	17:  {0, 22},
+	18:  {23, 24},
+	19:  {^13, 25},
+	20:  {26, ^14},
+	21:  {27, 28},
+	22:  {29, 30},
+	23:  {31, 32},
+	24:  {33, 34},
+	25:  {35, 36},
+	26:  {37, 38},
+	27:  {^15, 39},
+	28:  {40, 41},
+	29:  {42, 43},
+	30:  {44, 45},
+	31:  {^18, 46},
+	32:  {47, 48},
+	33:  {49, 50},
+	34:  {51, ^64},
+	35:  {52, 53},
+	36:  {54, ^16},
+	37:  {^17, 55},
+	38:  {56, 57},
+	39:  {58, 59},
+	40:  {60, 61},
+	41:  {62, ^0},
+	42:  {^1792, 63},
+	43:  {64, 65},
+	44:  {^1856, ^1920},
+	45:  {66, 67},
+	46:  {68, 69},
+	47:  {70, 71},
+	48:  {72, ^24},
+	49:  {^25, 73},
+	50:  {74, 75},
+	51:  {76, 77},
+	52:  {^23, 78},
+	53:  {79, 80},
+	54:  {81, 82},
+	55:  {83, 84},
+	56:  {85, 86},
+	57:  {87, ^22},
+	58:  {88, 89},
+	59:  {90, ^19},
+	60:  {^20, 91},
+	61:  {92, 93},
+	62:  {^21, 94},
+	63:  {^1984, ^2048},
+	64:  {^2112, ^2176},
+	65:  {^2240, ^2304},
+	66:  {^2368, ^2432},
+	67:  {^2496, ^2560},
+	68:  {^52, 95},
+	69:  {96, ^55},
+	70:  {^56, 97},
+	71:  {98, ^59},
+	72:  {^60, 99},
+	73:  {100, ^320},
+	74:  {^384, ^448},
+	75:  {101, ^53},
+	76:  {^54, 102},
+	77:  {103, 104},
+	78:  {^50, ^51},
+	79:  {^44, ^45},
+	80:  {^46, ^47},
+	81:  {^57, ^58},
+	82:  {^61, ^256},
+	83:  {^48, ^49},
+	84:  {^62, ^63},
+	85:  {^30, ^31},
+	86:  {^32, ^33},
+	87:  {^40, ^41},
+	88:  {^128, ^192},
+	89:  {^26, ^27},
+	90:  {^28, ^29},
+	91:  {^34, ^35},
+	92:  {^36, ^37},
+	93:  {^38, ^39},
+	94:  {^42, ^43},
+	95:  {^640, ^704},
+	96:  {^768, ^832},
+	97:  {^1280, ^1344},
+	98:  {^1408, ^1472},
+	99:  {^1536, ^1600},
+	100: {^1664, ^1728},
+	101: {^512, ^576},
+	102: {^896, ^960},
+	103: {^1024, ^1088},
+	104: {^1152, ^1216},
+}
+
+const maxCodeLength = 13
+
+// Each encodeTable is represented by an array of bitStrings.
+
+// bitString is a pair of uint32 values representing a bit code.
+// The nBits low bits of bits make up the actual bit code.
+// Eg. bitString{0x0004, 8} represents the bitcode "00000100".
+type bitString struct {
+	bits  uint32
+	nBits uint32
+}
+
+// modeEncodeTable represents Table 1 and the End-of-Line code.
+var modeEncodeTable = [...]bitString{
+	0: {0x0001, 4}, // "0001"
+	1: {0x0001, 3}, // "001"
+	2: {0x0001, 1}, // "1"
+	3: {0x0003, 3}, // "011"
+	4: {0x0003, 6}, // "000011"
+	5: {0x0003, 7}, // "0000011"
+	6: {0x0002, 3}, // "010"
+	7: {0x0002, 6}, // "000010"
+	8: {0x0002, 7}, // "0000010"
+	9: {0x0001, 7}, // "0000001"
+}
+
+// whiteEncodeTable2 represents Table 2 for a white run.
+var whiteEncodeTable2 = [...]bitString{
+	0:  {0x0035, 8}, // "00110101"
+	1:  {0x0007, 6}, // "000111"
+	2:  {0x0007, 4}, // "0111"
+	3:  {0x0008, 4}, // "1000"
+	4:  {0x000b, 4}, // "1011"
+	5:  {0x000c, 4}, // "1100"
+	6:  {0x000e, 4}, // "1110"
+	7:  {0x000f, 4}, // "1111"
+	8:  {0x0013, 5}, // "10011"
+	9:  {0x0014, 5}, // "10100"
+	10: {0x0007, 5}, // "00111"
+	11: {0x0008, 5}, // "01000"
+	12: {0x0008, 6}, // "001000"
+	13: {0x0003, 6}, // "000011"
+	14: {0x0034, 6}, // "110100"
+	15: {0x0035, 6}, // "110101"
+	16: {0x002a, 6}, // "101010"
+	17: {0x002b, 6}, // "101011"
+	18: {0x0027, 7}, // "0100111"
+	19: {0x000c, 7}, // "0001100"
+	20: {0x0008, 7}, // "0001000"
+	21: {0x0017, 7}, // "0010111"
+	22: {0x0003, 7}, // "0000011"
+	23: {0x0004, 7}, // "0000100"
+	24: {0x0028, 7}, // "0101000"
+	25: {0x002b, 7}, // "0101011"
+	26: {0x0013, 7}, // "0010011"
+	27: {0x0024, 7}, // "0100100"
+	28: {0x0018, 7}, // "0011000"
+	29: {0x0002, 8}, // "00000010"
+	30: {0x0003, 8}, // "00000011"
+	31: {0x001a, 8}, // "00011010"
+	32: {0x001b, 8}, // "00011011"
+	33: {0x0012, 8}, // "00010010"
+	34: {0x0013, 8}, // "00010011"
+	35: {0x0014, 8}, // "00010100"
+	36: {0x0015, 8}, // "00010101"
+	37: {0x0016, 8}, // "00010110"
+	38: {0x0017, 8}, // "00010111"
+	39: {0x0028, 8}, // "00101000"
+	40: {0x0029, 8}, // "00101001"
+	41: {0x002a, 8}, // "00101010"
+	42: {0x002b, 8}, // "00101011"
+	43: {0x002c, 8}, // "00101100"
+	44: {0x002d, 8}, // "00101101"
+	45: {0x0004, 8}, // "00000100"
+	46: {0x0005, 8}, // "00000101"
+	47: {0x000a, 8}, // "00001010"
+	48: {0x000b, 8}, // "00001011"
+	49: {0x0052, 8}, // "01010010"
+	50: {0x0053, 8}, // "01010011"
+	51: {0x0054, 8}, // "01010100"
+	52: {0x0055, 8}, // "01010101"
+	53: {0x0024, 8}, // "00100100"
+	54: {0x0025, 8}, // "00100101"
+	55: {0x0058, 8}, // "01011000"
+	56: {0x0059, 8}, // "01011001"
+	57: {0x005a, 8}, // "01011010"
+	58: {0x005b, 8}, // "01011011"
+	59: {0x004a, 8}, // "01001010"
+	60: {0x004b, 8}, // "01001011"
+	61: {0x0032, 8}, // "00110010"
+	62: {0x0033, 8}, // "00110011"
+	63: {0x0034, 8}, // "00110100"
+}
+
+// whiteEncodeTable3 represents Table 3 for a white run.
+var whiteEncodeTable3 = [...]bitString{
+	0:  {0x001b, 5},  // "11011"
+	1:  {0x0012, 5},  // "10010"
+	2:  {0x0017, 6},  // "010111"
+	3:  {0x0037, 7},  // "0110111"
+	4:  {0x0036, 8},  // "00110110"
+	5:  {0x0037, 8},  // "00110111"
+	6:  {0x0064, 8},  // "01100100"
+	7:  {0x0065, 8},  // "01100101"
+	8:  {0x0068, 8},  // "01101000"
+	9:  {0x0067, 8},  // "01100111"
+	10: {0x00cc, 9},  // "011001100"
+	11: {0x00cd, 9},  // "011001101"
+	12: {0x00d2, 9},  // "011010010"
+	13: {0x00d3, 9},  // "011010011"
+	14: {0x00d4, 9},  // "011010100"
+	15: {0x00d5, 9},  // "011010101"
+	16: {0x00d6, 9},  // "011010110"
+	17: {0x00d7, 9},  // "011010111"
+	18: {0x00d8, 9},  // "011011000"
+	19: {0x00d9, 9},  // "011011001"
+	20: {0x00da, 9},  // "011011010"
+	21: {0x00db, 9},  // "011011011"
+	22: {0x0098, 9},  // "010011000"
+	23: {0x0099, 9},  // "010011001"
+	24: {0x009a, 9},  // "010011010"
+	25: {0x0018, 6},  // "011000"
+	26: {0x009b, 9},  // "010011011"
+	27: {0x0008, 11}, // "00000001000"
+	28: {0x000c, 11}, // "00000001100"
+	29: {0x000d, 11}, // "00000001101"
+	30: {0x0012, 12}, // "000000010010"
+	31: {0x0013, 12}, // "000000010011"
+	32: {0x0014, 12}, // "000000010100"
+	33: {0x0015, 12}, // "000000010101"
+	34: {0x0016, 12}, // "000000010110"
+	35: {0x0017, 12}, // "000000010111"
+	36: {0x001c, 12}, // "000000011100"
+	37: {0x001d, 12}, // "000000011101"
+	38: {0x001e, 12}, // "000000011110"
+	39: {0x001f, 12}, // "000000011111"
+}
+
+// blackEncodeTable2 represents Table 2 for a black run.
+var blackEncodeTable2 = [...]bitString{
+	0:  {0x0037, 10}, // "0000110111"
+	1:  {0x0002, 3},  // "010"
+	2:  {0x0003, 2},  // "11"
+	3:  {0x0002, 2},  // "10"
+	4:  {0x0003, 3},  // "011"
+	5:  {0x0003, 4},  // "0011"
+	6:  {0x0002, 4},  // "0010"
+	7:  {0x0003, 5},  // "00011"
+	8:  {0x0005, 6},  // "000101"
+	9:  {0x0004, 6},  // "000100"
+	10: {0x0004, 7},  // "0000100"
+	11: {0x0005, 7},  // "0000101"
+	12: {0x0007, 7},  // "0000111"
+	13: {0x0004, 8},  // "00000100"
+	14: {0x0007, 8},  // "00000111"
+	15: {0x0018, 9},  // "000011000"
+	16: {0x0017, 10}, // "0000010111"
+	17: {0x0018, 10}, // "0000011000"
+	18: {0x0008, 10}, // "0000001000"
+	19: {0x0067, 11}, // "00001100111"
+	20: {0x0068, 11}, // "00001101000"
+	21: {0x006c, 11}, // "00001101100"
+	22: {0x0037, 11}, // "00000110111"
+	23: {0x0028, 11}, // "00000101000"
+	24: {0x0017, 11}, // "00000010111"
+	25: {0x0018, 11}, // "00000011000"
+	26: {0x00ca, 12}, // "000011001010"
+	27: {0x00cb, 12}, // "000011001011"
+	28: {0x00cc, 12}, // "000011001100"
+	29: {0x00cd, 12}, // "000011001101"
+	30: {0x0068, 12}, // "000001101000"
+	31: {0x0069, 12}, // "000001101001"
+	32: {0x006a, 12}, // "000001101010"
+	33: {0x006b, 12}, // "000001101011"
+	34: {0x00d2, 12}, // "000011010010"
+	35: {0x00d3, 12}, // "000011010011"
+	36: {0x00d4, 12}, // "000011010100"
+	37: {0x00d5, 12}, // "000011010101"
+	38: {0x00d6, 12}, // "000011010110"
+	39: {0x00d7, 12}, // "000011010111"
+	40: {0x006c, 12}, // "000001101100"
+	41: {0x006d, 12}, // "000001101101"
+	42: {0x00da, 12}, // "000011011010"
+	43: {0x00db, 12}, // "000011011011"
+	44: {0x0054, 12}, // "000001010100"
+	45: {0x0055, 12}, // "000001010101"
+	46: {0x0056, 12}, // "000001010110"
+	47: {0x0057, 12}, // "000001010111"
+	48: {0x0064, 12}, // "000001100100"
+	49: {0x0065, 12}, // "000001100101"
+	50: {0x0052, 12}, // "000001010010"
+	51: {0x0053, 12}, // "000001010011"
+	52: {0x0024, 12}, // "000000100100"
+	53: {0x0037, 12}, // "000000110111"
+	54: {0x0038, 12}, // "000000111000"
+	55: {0x0027, 12}, // "000000100111"
+	56: {0x0028, 12}, // "000000101000"
+	57: {0x0058, 12}, // "000001011000"
+	58: {0x0059, 12}, // "000001011001"
+	59: {0x002b, 12}, // "000000101011"
+	60: {0x002c, 12}, // "000000101100"
+	61: {0x005a, 12}, // "000001011010"
+	62: {0x0066, 12}, // "000001100110"
+	63: {0x0067, 12}, // "000001100111"
+}
+
+// blackEncodeTable3 represents Table 3 for a black run.
+var blackEncodeTable3 = [...]bitString{
+	0:  {0x000f, 10}, // "0000001111"
+	1:  {0x00c8, 12}, // "000011001000"
+	2:  {0x00c9, 12}, // "000011001001"
+	3:  {0x005b, 12}, // "000001011011"
+	4:  {0x0033, 12}, // "000000110011"
+	5:  {0x0034, 12}, // "000000110100"
+	6:  {0x0035, 12}, // "000000110101"
+	7:  {0x006c, 13}, // "0000001101100"
+	8:  {0x006d, 13}, // "0000001101101"
+	9:  {0x004a, 13}, // "0000001001010"
+	10: {0x004b, 13}, // "0000001001011"
+	11: {0x004c, 13}, // "0000001001100"
+	12: {0x004d, 13}, // "0000001001101"
+	13: {0x0072, 13}, // "0000001110010"
+	14: {0x0073, 13}, // "0000001110011"
+	15: {0x0074, 13}, // "0000001110100"
+	16: {0x0075, 13}, // "0000001110101"
+	17: {0x0076, 13}, // "0000001110110"
+	18: {0x0077, 13}, // "0000001110111"
+	19: {0x0052, 13}, // "0000001010010"
+	20: {0x0053, 13}, // "0000001010011"
+	21: {0x0054, 13}, // "0000001010100"
+	22: {0x0055, 13}, // "0000001010101"
+	23: {0x005a, 13}, // "0000001011010"
+	24: {0x005b, 13}, // "0000001011011"
+	25: {0x0064, 13}, // "0000001100100"
+	26: {0x0065, 13}, // "0000001100101"
+	27: {0x0008, 11}, // "00000001000"
+	28: {0x000c, 11}, // "00000001100"
+	29: {0x000d, 11}, // "00000001101"
+	30: {0x0012, 12}, // "000000010010"
+	31: {0x0013, 12}, // "000000010011"
+	32: {0x0014, 12}, // "000000010100"
+	33: {0x0015, 12}, // "000000010101"
+	34: {0x0016, 12}, // "000000010110"
+	35: {0x0017, 12}, // "000000010111"
+	36: {0x001c, 12}, // "000000011100"
+	37: {0x001d, 12}, // "000000011101"
+	38: {0x001e, 12}, // "000000011110"
+	39: {0x001f, 12}, // "000000011111"
+}
+
+// COPY PASTE table.go BEGIN
+
+const (
+	modePass = iota // Pass
+	modeH           // Horizontal
+	modeV0          // Vertical-0
+	modeVR1         // Vertical-Right-1
+	modeVR2         // Vertical-Right-2
+	modeVR3         // Vertical-Right-3
+	modeVL1         // Vertical-Left-1
+	modeVL2         // Vertical-Left-2
+	modeVL3         // Vertical-Left-3
+	modeExt         // Extension
+)
+
+// COPY PASTE table.go END

+ 102 - 0
vendor/golang.org/x/image/ccitt/writer.go

@@ -0,0 +1,102 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ccitt
+
+import (
+	"encoding/binary"
+	"io"
+)
+
+type bitWriter struct {
+	w io.Writer
+
+	// order is whether to process w's bytes LSB first or MSB first.
+	order Order
+
+	// The high nBits bits of the bits field hold encoded bits to be written to w.
+	bits  uint64
+	nBits uint32
+
+	// bytes[:bw] holds encoded bytes not yet written to w.
+	// Overflow protection is ensured by using a multiple of 8 as bytes length.
+	bw    uint32
+	bytes [1024]uint8
+}
+
+// flushBits copies 64 bits from b.bits to b.bytes. If b.bytes is then full, it
+// is written to b.w.
+func (b *bitWriter) flushBits() error {
+	binary.BigEndian.PutUint64(b.bytes[b.bw:], b.bits)
+	b.bits = 0
+	b.nBits = 0
+	b.bw += 8
+	if b.bw < uint32(len(b.bytes)) {
+		return nil
+	}
+	b.bw = 0
+	if b.order != MSB {
+		reverseBitsWithinBytes(b.bytes[:])
+	}
+	_, err := b.w.Write(b.bytes[:])
+	return err
+}
+
+// close finalizes a bitcode stream by writing any
+// pending bits to bitWriter's underlying io.Writer.
+func (b *bitWriter) close() error {
+	// Write any encoded bits to bytes.
+	if b.nBits > 0 {
+		binary.BigEndian.PutUint64(b.bytes[b.bw:], b.bits)
+		b.bw += (b.nBits + 7) >> 3
+	}
+
+	if b.order != MSB {
+		reverseBitsWithinBytes(b.bytes[:b.bw])
+	}
+
+	// Write b.bw bytes to b.w.
+	_, err := b.w.Write(b.bytes[:b.bw])
+	return err
+}
+
+// alignToByteBoundary rounds b.nBits up to a multiple of 8.
+// If all 64 bits are used, flush them to bitWriter's bytes.
+func (b *bitWriter) alignToByteBoundary() error {
+	if b.nBits = (b.nBits + 7) &^ 7; b.nBits == 64 {
+		return b.flushBits()
+	}
+	return nil
+}
+
+// writeCode writes a variable length bitcode to b's underlying io.Writer.
+func (b *bitWriter) writeCode(bs bitString) error {
+	bits := bs.bits
+	nBits := bs.nBits
+	if 64-b.nBits >= nBits {
+		// b.bits has sufficient room for storing nBits bits.
+		b.bits |= uint64(bits) << (64 - nBits - b.nBits)
+		b.nBits += nBits
+		if b.nBits == 64 {
+			return b.flushBits()
+		}
+		return nil
+	}
+
+	// Number of leading bits that fill b.bits.
+	i := 64 - b.nBits
+
+	// Fill b.bits then flush and write remaining bits.
+	b.bits |= uint64(bits) >> (nBits - i)
+	b.nBits = 64
+
+	if err := b.flushBits(); err != nil {
+		return err
+	}
+
+	nBits -= i
+	b.bits = uint64(bits) << (64 - nBits)
+	b.nBits = nBits
+	return nil
+}

+ 16 - 0
vendor/golang.org/x/image/tiff/consts.go

@@ -42,11 +42,16 @@ const (
 	tCompression               = 259
 	tPhotometricInterpretation = 262
 
+	tFillOrder = 266
+
 	tStripOffsets    = 273
 	tSamplesPerPixel = 277
 	tRowsPerStrip    = 278
 	tStripByteCounts = 279
 
+	tT4Options = 292 // CCITT Group 3 options, a set of 32 flag bits.
+	tT6Options = 293 // CCITT Group 4 options, a set of 32 flag bits.
+
 	tTileWidth      = 322
 	tTileLength     = 323
 	tTileOffsets    = 324
@@ -112,22 +117,33 @@ const (
 	mRGB
 	mRGBA
 	mNRGBA
+	mCMYK
 )
 
 // CompressionType describes the type of compression used in Options.
 type CompressionType int
 
+// Constants for supported compression types.
 const (
 	Uncompressed CompressionType = iota
 	Deflate
+	LZW
+	CCITTGroup3
+	CCITTGroup4
 )
 
 // specValue returns the compression type constant from the TIFF spec that
 // is equivalent to c.
 func (c CompressionType) specValue() uint32 {
 	switch c {
+	case LZW:
+		return cLZW
 	case Deflate:
 		return cDeflate
+	case CCITTGroup3:
+		return cG3
+	case CCITTGroup4:
+		return cG4
 	}
 	return cNone
 }

+ 30 - 0
vendor/golang.org/x/image/tiff/fuzz.go

@@ -0,0 +1,30 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build gofuzz
+// +build gofuzz
+
+package tiff
+
+import "bytes"
+
+func Fuzz(data []byte) int {
+	cfg, err := DecodeConfig(bytes.NewReader(data))
+	if err != nil {
+		return 0
+	}
+	if cfg.Width*cfg.Height > 1e6 {
+		return 0
+	}
+	img, err := Decode(bytes.NewReader(data))
+	if err != nil {
+		return 0
+	}
+	var w bytes.Buffer
+	err = Encode(&w, img, nil)
+	if err != nil {
+		panic(err)
+	}
+	return 1
+}

+ 4 - 4
vendor/golang.org/x/image/tiff/lzw/reader.go

@@ -3,8 +3,8 @@
 // license that can be found in the LICENSE file.
 
 // Package lzw implements the Lempel-Ziv-Welch compressed data format,
-// described in T. A. Welch, ``A Technique for High-Performance Data
-// Compression'', Computer, 17(6) (June 1984), pp 8-19.
+// described in T. A. Welch, A Technique for High-Performance Data
+// Compression, Computer, 17(6) (June 1984), pp 8-19.
 //
 // In particular, it implements LZW as used by the TIFF file format, including
 // an "off by one" algorithmic difference when compared to standard LZW.
@@ -30,7 +30,7 @@ Aldus "off by one" algorithm.
 
 The Go code doesn't read (invalid) TIFF files written by old versions of
 libtiff, but the LZW algorithm in this package still differs from the one in
-Go's standard package library to accomodate this "off by one" in valid TIFFs.
+Go's standard package library to accommodate this "off by one" in valid TIFFs.
 */
 
 import (
@@ -178,7 +178,7 @@ loop:
 			break loop
 		case code <= d.hi:
 			c, i := code, len(d.output)-1
-			if code == d.hi {
+			if code == d.hi && d.last != decoderInvalidCode {
 				// code == hi is a special case which expands to the last expansion
 				// followed by the head of the last expansion. To find the head, we walk
 				// the prefix chain until we find a literal code.

+ 79 - 9
vendor/golang.org/x/image/tiff/reader.go

@@ -17,6 +17,7 @@ import (
 	"io/ioutil"
 	"math"
 
+	"golang.org/x/image/ccitt"
 	"golang.org/x/image/tiff/lzw"
 )
 
@@ -37,6 +38,52 @@ func (e UnsupportedError) Error() string {
 
 var errNoPixels = FormatError("not enough pixel data")
 
+const maxChunkSize = 10 << 20 // 10M
+
+// safeReadtAt is a verbatim copy of internal/saferio.ReadDataAt from the
+// standard library, which is used to read data from a reader using a length
+// provided by untrusted data, without allocating the entire slice ahead of time
+// if it is large (>maxChunkSize). This allows us to avoid allocating giant
+// slices before learning that we can't actually read that much data from the
+// reader.
+func safeReadAt(r io.ReaderAt, n uint64, off int64) ([]byte, error) {
+	if int64(n) < 0 || n != uint64(int(n)) {
+		// n is too large to fit in int, so we can't allocate
+		// a buffer large enough. Treat this as a read failure.
+		return nil, io.ErrUnexpectedEOF
+	}
+
+	if n < maxChunkSize {
+		buf := make([]byte, n)
+		_, err := r.ReadAt(buf, off)
+		if err != nil {
+			// io.SectionReader can return EOF for n == 0,
+			// but for our purposes that is a success.
+			if err != io.EOF || n > 0 {
+				return nil, err
+			}
+		}
+		return buf, nil
+	}
+
+	var buf []byte
+	buf1 := make([]byte, maxChunkSize)
+	for n > 0 {
+		next := n
+		if next > maxChunkSize {
+			next = maxChunkSize
+		}
+		_, err := r.ReadAt(buf1[:next], off)
+		if err != nil {
+			return nil, err
+		}
+		buf = append(buf, buf1[:next]...)
+		n -= next
+		off += int64(next)
+	}
+	return buf, nil
+}
+
 type decoder struct {
 	r         io.ReaderAt
 	byteOrder binary.ByteOrder
@@ -81,8 +128,7 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
 	}
 	if datalen := lengths[datatype] * count; datalen > 4 {
 		// The IFD contains a pointer to the real value.
-		raw = make([]byte, datalen)
-		_, err = d.r.ReadAt(raw, int64(d.byteOrder.Uint32(p[8:12])))
+		raw, err = safeReadAt(d.r, uint64(datalen), int64(d.byteOrder.Uint32(p[8:12])))
 	} else {
 		raw = p[8 : 8+datalen]
 	}
@@ -110,7 +156,7 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err error) {
 	return u, nil
 }
 
-// parseIFD decides whether the the IFD entry in p is "interesting" and
+// parseIFD decides whether the IFD entry in p is "interesting" and
 // stows away the data in the decoder. It returns the tag number of the
 // entry and an error, if any.
 func (d *decoder) parseIFD(p []byte) (int, error) {
@@ -129,7 +175,10 @@ func (d *decoder) parseIFD(p []byte) (int, error) {
 		tTileOffsets,
 		tTileByteCounts,
 		tImageLength,
-		tImageWidth:
+		tImageWidth,
+		tFillOrder,
+		tT4Options,
+		tT6Options:
 		val, err := d.ifdUint(p)
 		if err != nil {
 			return 0, err
@@ -400,6 +449,9 @@ func newDecoder(r io.Reader) (*decoder, error) {
 
 	p := make([]byte, 8)
 	if _, err := d.r.ReadAt(p, 0); err != nil {
+		if err == io.EOF {
+			err = io.ErrUnexpectedEOF
+		}
 		return nil, err
 	}
 	switch string(p[0:4]) {
@@ -420,8 +472,9 @@ func newDecoder(r io.Reader) (*decoder, error) {
 	numItems := int(d.byteOrder.Uint16(p[0:2]))
 
 	// All IFD entries are read in one chunk.
-	p = make([]byte, ifdLen*numItems)
-	if _, err := d.r.ReadAt(p, ifdOffset+2); err != nil {
+	var err error
+	p, err = safeReadAt(d.r, uint64(ifdLen*numItems), ifdOffset+2)
+	if err != nil {
 		return nil, err
 	}
 
@@ -441,7 +494,8 @@ func newDecoder(r io.Reader) (*decoder, error) {
 	d.config.Height = int(d.firstVal(tImageLength))
 
 	if _, ok := d.features[tBitsPerSample]; !ok {
-		return nil, FormatError("BitsPerSample tag missing")
+		// Default is 1 per specification.
+		d.features[tBitsPerSample] = []uint{1}
 	}
 	d.bpp = d.firstVal(tBitsPerSample)
 	switch d.bpp {
@@ -539,6 +593,13 @@ func DecodeConfig(r io.Reader) (image.Config, error) {
 	return d.config, nil
 }
 
+func ccittFillOrder(tiffFillOrder uint) ccitt.Order {
+	if tiffFillOrder == 2 {
+		return ccitt.LSB
+	}
+	return ccitt.MSB
+}
+
 // Decode reads a TIFF image from r and returns it as an image.Image.
 // The type of Image returned depends on the contents of the TIFF.
 func Decode(r io.Reader) (img image.Image, err error) {
@@ -641,9 +702,18 @@ func Decode(r io.Reader) (img image.Image, err error) {
 				if b, ok := d.r.(*buffer); ok {
 					d.buf, err = b.Slice(int(offset), int(n))
 				} else {
-					d.buf = make([]byte, n)
-					_, err = d.r.ReadAt(d.buf, offset)
+					d.buf, err = safeReadAt(d.r, uint64(n), offset)
 				}
+			case cG3:
+				inv := d.firstVal(tPhotometricInterpretation) == pWhiteIsZero
+				order := ccittFillOrder(d.firstVal(tFillOrder))
+				r := ccitt.NewReader(io.NewSectionReader(d.r, offset, n), order, ccitt.Group3, blkW, blkH, &ccitt.Options{Invert: inv, Align: false})
+				d.buf, err = ioutil.ReadAll(r)
+			case cG4:
+				inv := d.firstVal(tPhotometricInterpretation) == pWhiteIsZero
+				order := ccittFillOrder(d.firstVal(tFillOrder))
+				r := ccitt.NewReader(io.NewSectionReader(d.r, offset, n), order, ccitt.Group4, blkW, blkH, &ccitt.Options{Invert: inv, Align: false})
+				d.buf, err = ioutil.ReadAll(r)
 			case cLZW:
 				r := lzw.NewReader(io.NewSectionReader(d.r, offset, n), lzw.MSB, 8)
 				d.buf, err = ioutil.ReadAll(r)

+ 3 - 0
vendor/golang.org/x/image/tiff/writer.go

@@ -8,6 +8,7 @@ import (
 	"bytes"
 	"compress/zlib"
 	"encoding/binary"
+	"errors"
 	"image"
 	"io"
 	"sort"
@@ -338,6 +339,8 @@ func Encode(w io.Writer, m image.Image, opt *Options) error {
 		}
 	case cDeflate:
 		dst = zlib.NewWriter(&buf)
+	default:
+		return errors.New("tiff: unsupported compression")
 	}
 
 	pr := uint32(prNone)

+ 0 - 1
vendor/google.golang.org/appengine/cloudsql/cloudsql_classic.go

@@ -2,7 +2,6 @@
 // Use of this source code is governed by the Apache 2.0
 // license that can be found in the LICENSE file.
 
-//go:build appengine
 // +build appengine
 
 package cloudsql

+ 0 - 1
vendor/google.golang.org/appengine/cloudsql/cloudsql_vm.go

@@ -2,7 +2,6 @@
 // Use of this source code is governed by the Apache 2.0
 // license that can be found in the LICENSE file.
 
-//go:build !appengine
 // +build !appengine
 
 package cloudsql

+ 3 - 2
vendor/modules.txt

@@ -22,9 +22,10 @@ github.com/vladimirok5959/golang-server-static/static
 # github.com/vladimirok5959/golang-worker v1.0.0
 ## explicit; go 1.13
 github.com/vladimirok5959/golang-worker/worker
-# golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81
-## explicit
+# golang.org/x/image v0.5.0
+## explicit; go 1.12
 golang.org/x/image/bmp
+golang.org/x/image/ccitt
 golang.org/x/image/tiff
 golang.org/x/image/tiff/lzw
 # google.golang.org/appengine v1.4.0