ccitt: rename fooTable vars to fooDecodeTable
Upcoming commits will also implement an encoder, not just a decoder, and
they might want to generate fooEncodeTable vars.
Change-Id: Ib02548a912a7354f00dace580151fbcfc405be8f
Reviewed-on: https://go-review.googlesource.com/c/image/+/178417
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/ccitt/gen.go b/ccitt/gen.go
index c4d4bc9..0245f66 100644
--- a/ccitt/gen.go
+++ b/ccitt/gen.go
@@ -26,12 +26,12 @@
w := &bytes.Buffer{}
w.WriteString(header)
w.WriteString(headerComment)
- write(w, build(modeCodes[:], 0), "modeTable",
- "// modeTable represents Table 1 and the End-of-Line code.\n")
- write(w, build(whiteCodes[:], 0), "whiteTable",
- "// whiteTable represents Tables 2 and 3 for a white run.\n")
- write(w, build(blackCodes[:], 0), "blackTable",
- "// blackTable represents Tables 2 and 3 for a black run.\n")
+ write(w, build(modeCodes[:], 0), "modeDecodeTable",
+ "// modeDecodeTable represents Table 1 and the End-of-Line code.\n")
+ write(w, build(whiteCodes[:], 0), "whiteDecodeTable",
+ "// whiteDecodeTable represents Tables 2 and 3 for a white run.\n")
+ write(w, build(blackCodes[:], 0), "blackDecodeTable",
+ "// blackDecodeTable represents Tables 2 and 3 for a black run.\n")
writeMaxCodeLength(w, modeCodes[:], whiteCodes[:], blackCodes[:])
finish(w, "table.go")
}
@@ -51,9 +51,9 @@
`
const headerComment = `
-// Each table 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).
+// 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
@@ -61,16 +61,16 @@
// then we have a leaf node, whose value is the bitwise complement (the ^
// operator) of that int16.
//
-// Comments above each table 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.
+// 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 modeTable, 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".
+// 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"
diff --git a/ccitt/reader.go b/ccitt/reader.go
index bd856a1..ef353dc 100644
--- a/ccitt/reader.go
+++ b/ccitt/reader.go
@@ -107,7 +107,7 @@
}
}
-func decode(b *bitReader, table [][2]int16) (uint32, error) {
+func decode(b *bitReader, decodeTable [][2]int16) (uint32, error) {
nBitsRead, bitsRead, state := uint32(0), uint32(0), int32(1)
for {
bit, err := b.nextBit()
@@ -117,7 +117,7 @@
bitsRead |= bit << nBitsRead
nBitsRead++
// The "&1" is redundant, but can eliminate a bounds check.
- state = int32(table[state][bit&1])
+ state = int32(decodeTable[state][bit&1])
if state < 0 {
return uint32(^state), nil
} else if state == 0 {
diff --git a/ccitt/reader_test.go b/ccitt/reader_test.go
index 8564d28..a1b9451 100644
--- a/ccitt/reader_test.go
+++ b/ccitt/reader_test.go
@@ -37,7 +37,7 @@
}
}
-func testTable(t *testing.T, table [][2]int16, codes []code, values []uint32) {
+func testDecodeTable(t *testing.T, decodeTable [][2]int16, codes []code, values []uint32) {
// Build a map from values to codes.
m := map[uint32]string{}
for _, code := range codes {
@@ -74,7 +74,7 @@
}
finalValue := values[len(values)-1]
for {
- v, err := decode(r, table)
+ v, err := decode(r, decodeTable)
if err != nil {
t.Fatalf("after got=%d: %v", got, err)
}
@@ -90,8 +90,8 @@
}
}
-func TestModeTable(t *testing.T) {
- testTable(t, modeTable[:], modeCodes, []uint32{
+func TestModeDecodeTable(t *testing.T) {
+ testDecodeTable(t, modeDecodeTable[:], modeCodes, []uint32{
modePass,
modeV0,
modeV0,
@@ -107,42 +107,42 @@
})
}
-func TestWhiteTable(t *testing.T) {
- testTable(t, whiteTable[:], whiteCodes, []uint32{
+func TestWhiteDecodeTable(t *testing.T) {
+ testDecodeTable(t, whiteDecodeTable[:], whiteCodes, []uint32{
0, 1, 256, 7, 128, 3, 2560,
})
}
-func TestBlackTable(t *testing.T) {
- testTable(t, blackTable[:], blackCodes, []uint32{
+func TestBlackDecodeTable(t *testing.T) {
+ testDecodeTable(t, blackDecodeTable[:], blackCodes, []uint32{
63, 64, 63, 64, 64, 63, 22, 1088, 2048, 7, 6, 5, 4, 3, 2, 1, 0,
})
}
-func TestInvalidCode(t *testing.T) {
+func TestDecodeInvalidCode(t *testing.T) {
// The bit stream is:
// 1 010 000000011011
// Packing that LSB-first gives:
// 0b_1101_1000_0000_0101
src := []byte{0x05, 0xD8}
- table := modeTable[:]
+ decodeTable := modeDecodeTable[:]
r := &bitReader{
r: bytes.NewReader(src),
}
// "1" decodes to the value 2.
- if v, err := decode(r, table); v != 2 || err != nil {
+ if v, err := decode(r, decodeTable); v != 2 || err != nil {
t.Fatalf("decode #0: got (%v, %v), want (2, nil)", v, err)
}
// "010" decodes to the value 6.
- if v, err := decode(r, table); v != 6 || err != nil {
+ if v, err := decode(r, decodeTable); v != 6 || err != nil {
t.Fatalf("decode #0: got (%v, %v), want (6, nil)", v, err)
}
// "00000001" is an invalid code.
- if v, err := decode(r, table); v != 0 || err != errInvalidCode {
+ if v, err := decode(r, decodeTable); v != 0 || err != errInvalidCode {
t.Fatalf("decode #0: got (%v, %v), want (0, %v)", v, err, errInvalidCode)
}
diff --git a/ccitt/table.go b/ccitt/table.go
index 6a8cfe1..29d0ea4 100644
--- a/ccitt/table.go
+++ b/ccitt/table.go
@@ -2,9 +2,9 @@
package ccitt
-// Each table 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).
+// 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
@@ -12,16 +12,16 @@
// then we have a leaf node, whose value is the bitwise complement (the ^
// operator) of that int16.
//
-// Comments above each table 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.
+// 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 modeTable, 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".
+// 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"
@@ -29,7 +29,7 @@
//
// https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.6-198811-I!!PDF-E&type=items
-// modeTable represents Table 1 and the End-of-Line code.
+// modeDecodeTable represents Table 1 and the End-of-Line code.
//
// +=XXXXX
// b015 +-+
@@ -62,7 +62,7 @@
// | +=v0003
// b001 +-+
// +=v0002
-var modeTable = [...][2]int16{
+var modeDecodeTable = [...][2]int16{
0: {0, 0},
1: {2, ^2},
2: {3, 4},
@@ -81,7 +81,7 @@
15: {0, ^10},
}
-// whiteTable represents Tables 2 and 3 for a white run.
+// whiteDecodeTable represents Tables 2 and 3 for a white run.
//
// +=XXXXX
// b059 +-+
@@ -292,7 +292,7 @@
// | +=v0006
// b015 +-+
// +=v0007
-var whiteTable = [...][2]int16{
+var whiteDecodeTable = [...][2]int16{
0: {0, 0},
1: {2, 3},
2: {4, 5},
@@ -400,7 +400,7 @@
104: {^2496, ^2560},
}
-// blackTable represents Tables 2 and 3 for a black run.
+// blackDecodeTable represents Tables 2 and 3 for a black run.
//
// +=XXXXX
// b017 +-+
@@ -611,7 +611,7 @@
// | +=v0003
// b003 +-+
// +=v0002
-var blackTable = [...][2]int16{
+var blackDecodeTable = [...][2]int16{
0: {0, 0},
1: {2, 3},
2: {4, 5},