9fans.net/go@v0.0.5/draw/computil.go (about) 1 package draw 2 3 // Compressed image file parameters. 4 const ( 5 _NMATCH = 3 /* shortest match possible */ 6 _NRUN = (_NMATCH + 31) /* longest match possible */ 7 _NMEM = 1024 /* window size */ 8 _NDUMP = 128 /* maximum length of dump */ 9 _NCBLOCK = 6000 /* size of compressed blocks */ 10 ) 11 12 /* 13 * compressed data are sequences of byte codes. 14 * if the first byte b has the 0x80 bit set, the next (b^0x80)+1 bytes 15 * are data. otherwise, it's two bytes specifying a previous string to repeat. 16 */ 17 18 func twiddlecompressed(buf []byte) { 19 i := 0 20 for i < len(buf) { 21 c := buf[i] 22 i++ 23 if c >= 0x80 { 24 k := int(c) - 0x80 + 1 25 for j := 0; j < k && i < len(buf); j++ { 26 buf[i] ^= 0xFF 27 i++ 28 } 29 } else { 30 i++ 31 } 32 } 33 } 34 35 func compblocksize(r Rectangle, depth int) int { 36 bpl := BytesPerLine(r, depth) 37 bpl = 2 * bpl /* add plenty extra for blocking, etc. */ 38 if bpl < _NCBLOCK { 39 return _NCBLOCK 40 } 41 return bpl 42 }