Jacek Kucharczyk c582323a8f
JBIG2 Generic Encoder (#264)
* Prepared skeleton and basic component implementations for the jbig2 encoding.

* Added Bitset. Implemented Bitmap.

* Decoder with old Arithmetic Decoder

* Partly working arithmetic

* Working arithmetic decoder.

* MMR patched.

* rebuild to apache.

* Working generic

* Working generic

* Decoded full document

* Update Jenkinsfile go version [master] (#398)

* Update Jenkinsfile go version

* Decoded AnnexH document

* Minor issues fixed.

* Update README.md

* Fixed generic region errors. Added benchmark. Added bitmap unpadder. Added Bitmap toImage method.

* Fixed endofpage error

* Added integration test.

* Decoded all test files without errors. Implemented JBIG2Global.

* Merged with v3 version

* Fixed the EOF in the globals issue

* Fixed the JBIG2 ChocolateData Decode

* JBIG2 Added license information

* Minor fix in jbig2 encoding.

* Applied the logging convention

* Cleaned unnecessary imports

* Go modules clear unused imports

* checked out the README.md

* Moved trace to Debug. Fixed the build integrate tag in the document_decode_test.go

* Initial encoder skeleton

* Applied UniPDF Developer Guide. Fixed lint issues.

* Cleared documentation, fixed style issues.

* Added jbig2 doc.go files. Applied unipdf guide style.

* Minor code style changes.

* Minor naming and style issues fixes.

* Minor naming changes. Style issues fixed.

* Review r11 fixes.

* Added JBIG2 Encoder skeleton.

* Moved Document and Page to jbig2/document package. Created decoder package responsible for decoding jbig2 stream.

* Implemented raster functions.

* Added raster uni low test funcitons.

* Added raster low test functions

* untracked files on jbig2-encoder: c869089 Added raster low test functions

* index on jbig2-encoder: c869089 Added raster low test functions

* Added morph files.

* implemented jbig2 encoder basics

* JBIG2 Encoder - Generic method

* Added jbig2 image encode ttests, black/white image tests

* cleaned and tested jbig2 package

* unfinished jbig2 classified encoder

* jbig2 minor style changes

* minor jbig2 encoder changes

* prepared JBIG2 Encoder

* Style and lint fixes

* Minor changes and lints

* Fixed shift unsinged value build errors

* Minor naming change

* Added jbig2 encode, image gondels. Fixed jbig2 decode bug.

* Provided jbig2 core.DecodeGlobals function.

* Fixed JBIG2Encoder `r6` revision issues.

* Removed public JBIG2Encoder document.

* Minor style changes

* added NewJBIG2Encoder function.

* fixed JBIG2Encoder 'r9' revision issues.

* Cleared 'r9' commented code.

* Updated ACKNOWLEDGEMENETS. Fixed JBIG2Encoder 'r10' revision issues.

Co-authored-by: Gunnsteinn Hall <gunnsteinn.hall@gmail.com>
2020-03-27 11:47:41 +00:00

279 lines
9.4 KiB
Go

/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.md', which is part of this source code package.
*/
package mmr
type mmrCode int
const (
codeP mmrCode = iota
codeH
codeV0
codeVR1
codeVR2
codeVR3
codeVL1
codeVL2
codeVL3
codeExt2D
codeExt1D
)
// Constants used be the MMR decoder.
const (
EOF = -3
invalid = -2
EOL = -1
firstLevelTableSize = 8
firstLevelTablemask = (1 << firstLevelTableSize) - 1
secondLevelTableSize = 5
secondLevelTableMask = (1 << secondLevelTableSize) - 1
)
var (
// modeCodes are predefined codes for the runData.
modeCodes = [][3]int{
{4, 0x1, int(codeP)}, // 0001 pass
{3, 0x1, int(codeH)}, // 001 horizontal
{1, 0x1, int(codeV0)}, // 1 vert 0
{3, 0x3, int(codeVR1)}, // 011 vert r 1
{6, 0x3, int(codeVR2)}, // 000011 ver r2
{7, 0x3, int(codeVR3)}, // 0000011 vertr3
{3, 0x2, int(codeVL1)}, // 010 vert l 1
{6, 0x2, int(codeVL2)}, // 000010 ver 1 2
{7, 0x2, int(codeVL3)}, // 00000010 ver l 3
{10, 0xf, int(codeExt2D)}, // 0000001111
{12, 0xf, int(codeExt1D)}, // 0000000001111
{12, 0x1, int(EOL)}, // 0000000000001
}
// whiteCodes are the 'white' codes for the runData.
whiteCodes = [][3]int{
{4, 0x07, 2}, // 0111
{4, 0x08, 3}, // 1000
{4, 0x0B, 4}, // 1011
{4, 0x0C, 5}, // 1100
{4, 0x0E, 6}, // 1110
{4, 0x0F, 7}, // 1111
{5, 0x12, 128}, // 1001 0
{5, 0x13, 8}, // 1001 1
{5, 0x14, 9}, // 1010 0
{5, 0x1B, 64}, // 1101 1
{5, 0x07, 10}, // 0011 1
{5, 0x08, 11}, // 0100 0
{6, 0x17, 192}, // 0101 11
{6, 0x18, 1664}, // 0110 00
{6, 0x2A, 16}, // 1010 10
{6, 0x2B, 17}, // 1010 11
{6, 0x03, 13}, // 0000 11
{6, 0x34, 14}, // 1101 00
{6, 0x35, 15}, // 1101 01
{6, 0x07, 1}, // 0001 11
{6, 0x08, 12}, // 0010 00
{7, 0x13, 26}, // 0010 011
{7, 0x17, 21}, // 0010 111
{7, 0x18, 28}, // 0011 000
{7, 0x24, 27}, // 0100 100
{7, 0x27, 18}, // 0100 111
{7, 0x28, 24}, // 0101 000
{7, 0x2B, 25}, // 0101 011
{7, 0x03, 22}, // 0000 011
{7, 0x37, 256}, // 0110 111
{7, 0x04, 23}, // 0000 100
{7, 0x08, 20}, // 0001 000
{7, 0xC, 19}, // 0001 100
{8, 0x12, 33}, // 0001 0010
{8, 0x13, 34}, // 0001 0011
{8, 0x14, 35}, // 0001 0100
{8, 0x15, 36}, // 0001 0101
{8, 0x16, 37}, // 0001 0110
{8, 0x17, 38}, // 0001 0111
{8, 0x1A, 31}, // 0001 1010
{8, 0x1B, 32}, // 0001 1011
{8, 0x02, 29}, // 0000 0010
{8, 0x24, 53}, // 0010 0100
{8, 0x25, 54}, // 0010 0101
{8, 0x28, 39}, // 0010 1000
{8, 0x29, 40}, // 0010 1001
{8, 0x2A, 41}, // 0010 1010
{8, 0x2B, 42}, // 0010 1011
{8, 0x2C, 43}, // 0010 1100
{8, 0x2D, 44}, // 0010 1101
{8, 0x03, 30}, // 0000 0011
{8, 0x32, 61}, // 0011 0010
{8, 0x33, 62}, // 0011 0011
{8, 0x34, 63}, // 0011 0100
{8, 0x35, 0}, // 0011 0101
{8, 0x36, 320}, // 0011 0110
{8, 0x37, 384}, // 0011 0111
{8, 0x04, 45}, // 0000 0100
{8, 0x4A, 59}, // 0100 1010
{8, 0x4B, 60}, // 0100 1011
{8, 0x5, 46}, // 0000 0101
{8, 0x52, 49}, // 0101 0010
{8, 0x53, 50}, // 0101 0011
{8, 0x54, 51}, // 0101 0100
{8, 0x55, 52}, // 0101 0101
{8, 0x58, 55}, // 0101 1000
{8, 0x59, 56}, // 0101 1001
{8, 0x5A, 57}, // 0101 1010
{8, 0x5B, 58}, // 0101 1011
{8, 0x64, 448}, // 0110 0100
{8, 0x65, 512}, // 0110 0101
{8, 0x67, 640}, // 0110 0111
{8, 0x68, 576}, // 0110 1000
{8, 0x0A, 47}, // 0000 1010
{8, 0x0B, 48}, // 0000 1011
{9, 0x01, invalid}, // 0000 0000 1
{9, 0x98, 1472}, // 0100 1100 0
{9, 0x99, 1536}, // 0100 1100 1
{9, 0x9A, 1600}, // 0100 1101 0
{9, 0x9B, 1728}, // 0100 1101 1
{9, 0xCC, 704}, // 0110 0110 0
{9, 0xCD, 768}, // 0110 0110 1
{9, 0xD2, 832}, // 0110 1001 0
{9, 0xD3, 896}, // 0110 1001 1
{9, 0xD4, 960}, // 0110 1010 0
{9, 0xD5, 1024}, // 0110 1010 1
{9, 0xD6, 1088}, // 0110 1011 0
{9, 0xD7, 1152}, // 0110 1011 1
{9, 0xD8, 1216}, // 0110 1100 0
{9, 0xD9, 1280}, // 0110 1100 1
{9, 0xDA, 1344}, // 0110 1101 0
{9, 0xDB, 1408}, // 0110 1101 1
{10, 0x01, invalid}, // 0000 0000 01
{11, 0x01, invalid}, // 0000 0000 001
{11, 0x08, 1792}, // 0000 0001 000
{11, 0x0C, 1856}, // 0000 0001 100
{11, 0x0D, 1920}, // 0000 0001 101
{12, 0x00, EOF}, // 0000 0000 0000
{12, 0x01, EOL}, // 0000 0000 0001
{12, 0x12, 1984}, // 0000 0001 0010
{12, 0x13, 2048}, // 0000 0001 0011
{12, 0x14, 2112}, // 0000 0001 0100
{12, 0x15, 2176}, // 0000 0001 0101
{12, 0x16, 2240}, // 0000 0001 0110
{12, 0x17, 2304}, // 0000 0001 0111
{12, 0x1C, 2368}, // 0000 0001 1100
{12, 0x1D, 2432}, // 0000 0001 1101
{12, 0x1E, 2496}, // 0000 0001 1110
{12, 0x1F, 2560},
}
// blackCodes are the 'black' codes used by the runData
blackCodes = [][3]int{
{2, 0x02, 3}, // 10
{2, 0x03, 2}, // 11
{3, 0x02, 1}, // 010
{3, 0x03, 4}, // 011
{4, 0x02, 6}, // 0010
{4, 0x03, 5}, // 0011
{5, 0x03, 7}, // 0001 1
{6, 0x04, 9}, // 0001 00
{6, 0x05, 8}, // 0001 01
{7, 0x04, 10}, // 0000 100
{7, 0x05, 11}, // 0000 101
{7, 0x07, 12}, // 0000 111
{8, 0x04, 13}, // 0000 0100
{8, 0x07, 14}, // 0000 0111
{9, 0x01, invalid}, // 0000 0000 1
{9, 0x18, 15}, // 0000 1100 0
{10, 0x01, invalid}, // 0000 0000 01
{10, 0x17, 16}, // 0000 0101 11
{10, 0x18, 17}, // 0000 0110 00
{10, 0x37, 0}, // 0000 1101 11
{10, 0x08, 18}, // 0000 0010 00
{10, 0x0F, 64}, // 0000 0011 11
{11, 0x01, invalid}, // 0000 0000 001
{11, 0x17, 24}, // 0000 0010 111
{11, 0x18, 25}, // 0000 0011 000
{11, 0x28, 23}, // 0000 0101 000
{11, 0x37, 22}, // 0000 0110 111
{11, 0x67, 19}, // 0000 1100 111
{11, 0x68, 20}, // 0000 1101 000
{11, 0x6C, 21}, // 0000 1101 100
{11, 0x08, 1792}, // 0000 0001 000
{11, 0x0C, 1856}, // 0000 0001 100
{11, 0x0D, 1920}, // 0000 0001 101
{12, 0x00, EOF}, // 0000 0000 0000
{12, 0x01, EOL}, // 0000 0000 0001
{12, 0x12, 1984}, // 0000 0001 0010
{12, 0x13, 2048}, // 0000 0001 0011
{12, 0x14, 2112}, // 0000 0001 0100
{12, 0x15, 2176}, // 0000 0001 0101
{12, 0x16, 2240}, // 0000 0001 0110
{12, 0x17, 2304}, // 0000 0001 0111
{12, 0x1C, 2368}, // 0000 0001 1100
{12, 0x1D, 2432}, // 0000 0001 1101
{12, 0x1E, 2496}, // 0000 0001 1110
{12, 0x1F, 2560}, // 0000 0001 1111
{12, 0x24, 52}, // 0000 0010 0100
{12, 0x27, 55}, // 0000 0010 0111
{12, 0x28, 56}, // 0000 0010 1000
{12, 0x2B, 59}, // 0000 0010 1011
{12, 0x2C, 60}, // 0000 0010 1100
{12, 0x33, 320}, // 0000 0011 0011
{12, 0x34, 384}, // 0000 0011 0100
{12, 0x35, 448}, // 0000 0011 0101
{12, 0x37, 53}, // 0000 0011 0111
{12, 0x38, 54}, // 0000 0011 1000
{12, 0x52, 50}, // 0000 0101 0010
{12, 0x53, 51}, // 0000 0101 0011
{12, 0x54, 44}, // 0000 0101 0100
{12, 0x55, 45}, // 0000 0101 0101
{12, 0x56, 46}, // 0000 0101 0110
{12, 0x57, 47}, // 0000 0101 0111
{12, 0x58, 57}, // 0000 0101 1000
{12, 0x59, 58}, // 0000 0101 1001
{12, 0x5A, 61}, // 0000 0101 1010
{12, 0x5B, 256}, // 0000 0101 1011
{12, 0x64, 48}, // 0000 0110 0100
{12, 0x65, 49}, // 0000 0110 0101
{12, 0x66, 62}, // 0000 0110 0110
{12, 0x67, 63}, // 0000 0110 0111
{12, 0x68, 30}, // 0000 0110 1000
{12, 0x69, 31}, // 0000 0110 1001
{12, 0x6A, 32}, // 0000 0110 1010
{12, 0x6B, 33}, // 0000 0110 1011
{12, 0x6C, 40}, // 0000 0110 1100
{12, 0x6D, 41}, // 0000 0110 1101
{12, 0xC8, 128}, // 0000 1100 1000
{12, 0xC9, 192}, // 0000 1100 1001
{12, 0xCA, 26}, // 0000 1100 1010
{12, 0xCB, 27}, // 0000 1100 1011
{12, 0xCC, 28}, // 0000 1100 1100
{12, 0xCD, 29}, // 0000 1100 1101
{12, 0xD2, 34}, // 0000 1101 0010
{12, 0xD3, 35}, // 0000 1101 0011
{12, 0xD4, 36}, // 0000 1101 0100
{12, 0xD5, 37}, // 0000 1101 0101
{12, 0xD6, 38}, // 0000 1101 0110
{12, 0xD7, 39}, // 0000 1101 0111
{12, 0xDA, 42}, // 0000 1101 1010
{12, 0xDB, 43}, // 0000 1101 1011
{13, 0x4A, 640}, // 0000 0010 0101 0
{13, 0x4B, 704}, // 0000 0010 0101 1
{13, 0x4C, 768}, // 0000 0010 0110 0
{13, 0x4D, 832}, // 0000 0010 0110 1
{13, 0x52, 1280}, // 0000 0010 1001 0
{13, 0x53, 1344}, // 0000 0010 1001 1
{13, 0x54, 1408}, // 0000 0010 1010 0
{13, 0x55, 1472}, // 0000 0010 1010 1
{13, 0x5A, 1536}, // 0000 0010 1101 0
{13, 0x5B, 1600}, // 0000 0010 1101 1
{13, 0x64, 1664}, // 0000 0011 0010 0
{13, 0x65, 1728}, // 0000 0011 0010 1
{13, 0x6C, 512}, // 0000 0011 0110 0
{13, 0x6D, 576}, // 0000 0011 0110 1
{13, 0x72, 896}, // 0000 0011 1001 0
{13, 0x73, 960}, // 0000 0011 1001 1
{13, 0x74, 1024}, // 0000 0011 1010 0
{13, 0x75, 1088}, // 0000 0011 1010 1
{13, 0x76, 1152}, // 0000 0011 1011 0
{13, 0x77, 1216}, // 0000 0011 1011 1
}
)