4.1.1.2 Example 2

The following example shows a network dump of an image compressed using ClearCodec. The width of the bitmap is 78, and the height is 17. ClearCodec returned 144 bytes after compressing this image.

 COMPRESSED BITMAP DATA (144 bytes):
 00000000 00 0d 00 00 00 00 00 00 00 00 82 00 00 00 00 00  ................
 00000010 00 00 4e 00 11 00 75 00 00 00 02 0e ff ff ff 00  ..N...u.........
 00000020 00 00 db ff ff 00 3a 90 ff b6 66 66 b6 ff b6 66  ......:...ff...f
 00000030 00 90 db ff 00 00 3a db 90 3a 3a 90 db 66 00 00  ......:..::..f..
 00000040 ff ff b6 64 64 64 11 04 11 4c 11 4c 11 4c 11 4c  ...ddd...L.L.L.L
 00000050 11 4c 00 47 13 00 01 01 04 00 01 00 00 47 16 00  .L.G.........G..
 00000060 11 02 00 47 29 00 11 01 00 49 0a 00 01 00 04 00  ...G)....I......
 00000070 01 00 00 4a 0a 00 09 00 01 00 00 47 05 00 01 01  ...J.......G....
 00000080 1c 00 01 00 11 4c 11 4c 11 4c 00 47 0d 4d 00 4d  .....L.L.L.G.M.M
  
 Decoding the CLEARCODEC_BITMAP_STREAM header:
 00 -> CLEARCODEC_BITMAP_STREAM::flags = 0
 0d -> CLEARCODEC_BITMAP_STREAM::seqNumber = 13
  
 Decoding the CLEARCODEC_COMPOSITE_PAYLOAD header:
 00 00 00 00 -> CLEARCODEC_COMPOSITE_PAYLOAD::residualByteCount = 0
 00 00 00 00 -> CLEARCODEC_COMPOSITE_PAYLOAD::bandsByteCount = 0
 82 00 00 00 -> CLEARCODEC_COMPOSITE_PAYLOAD::subcodecByteCount = 130 bytes
  
 SUBCODEC DATA (130 bytes):
 00000000 00 00 00 00 4e 00 11 00 75 00 00 00 02 0e ff ff  ....N...u.......
 00000010 ff 00 00 00 db ff ff 00 3a 90 ff b6 66 66 b6 ff  ........:...ff..
 00000020 b6 66 00 90 db ff 00 00 3a db 90 3a 3a 90 db 66  .f......:..::..f
 00000030 00 00 ff ff b6 64 64 64 11 04 11 4c 11 4c 11 4c  .....ddd...L.L.L
 00000040 11 4c 11 4c 00 47 13 00 01 01 04 00 01 00 00 47  .L.L.G.........G
 00000050 16 00 11 02 00 47 29 00 11 01 00 49 0a 00 01 00  .....G)....I....
 00000060 04 00 01 00 00 4a 0a 00 09 00 01 00 00 47 05 00  .....J.......G..
 00000070 01 01 1c 00 01 00 11 4c 11 4c 11 4c 00 47 0d 4d  .......L.L.L.G.M
 00000080 00 4d                                            .M
  
 Decoding the first subcodec header:
 00 00 -> CLEARCODEC_SUBCODEC::xStart = 0
 00 00 -> CLEARCODEC_SUBCODEC::yStart = 0
 4e 00 -> CLEARCODEC_SUBCODEC::width = 78
 11 00 -> CLEARCODEC_SUBCODEC::height = 17
 75 00 00 00 -> CLEARCODEC_SUBCODEC::bitmapDataByteCount = 117
 02 -> CLEARCODEC_SUBCODEC::subCodecId = CLEARCODEC_SUBCODEC_RLEX(0x02)
  
 SUBCODEC_RLEX DATA (117 bytes):
 00000000 0e ff ff ff 00 00 00 db ff ff 00 3a 90 ff b6 66  ...........:...f
 00000010 66 b6 ff b6 66 00 90 db ff 00 00 3a db 90 3a 3a  f...f......:..::
 00000020 90 db 66 00 00 ff ff b6 64 64 64 11 04 11 4c 11  ..f.....ddd...L.
 00000030 4c 11 4c 11 4c 11 4c 00 47 13 00 01 01 04 00 01  L.L.L.L.G.......
 00000040 00 00 47 16 00 11 02 00 47 29 00 11 01 00 49 0a  ..G.....G)....I.
 00000050 00 01 00 04 00 01 00 00 4a 0a 00 09 00 01 00 00  ........J.......
 00000060 47 05 00 01 01 1c 00 01 00 11 4c 11 4c 11 4c 00  G.........L.L.L.
 00000070 47 0d 4d 00 4d                                   G.M.M
  
 0e -> CLEARCODEC_SUBCODEC_RLEX::paletteCount = 14
  
 ff ff ff -> paletteEntries[0]  = (blue = 0xff, green = 0xff, red = 0xff) 
 00 00 00 -> paletteEntries[1]  = (blue = 0x00, green = 0x00, red = 0x00)
 db ff ff -> paletteEntries[2]  = (blue = 0xdb, green = 0xff, red = 0xff)
 00 3a 90 -> paletteEntries[3]  = (blue = 0x00, green = 0x3a, red = 0x90)
 ff b6 66 -> paletteEntries[4]  = (blue = 0xff, green = 0xb6, red = 0x66)
 66 b6 ff -> paletteEntries[5]  = (blue = 0x66, green = 0xb6, red = 0xff)
 b6 66 00 -> paletteEntries[6]  = (blue = 0xb6, green = 0x66, red = 0x00)
 90 db ff -> paletteEntries[7]  = (blue = 0x90, green = 0xdb, red = 0xff)
 00 00 3a -> paletteEntries[8]  = (blue = 0x00, green = 0x00, red = 0x3a)
 db 90 3a -> paletteEntries[9]  = (blue = 0xdb, green = 0x90, red = 0x3a)
 3a 90 db -> paletteEntries[10] = (blue = 0x3a, green = 0x90, red = 0xdb)
 66 00 00 -> paletteEntries[11] = (blue = 0x66, green = 0x00, red = 0x00)
 ff ff b6 -> paletteEntries[12] = (blue = 0xff, green = 0xff, red = 0xb6)
 64 64 64 -> paletteEntries[13] = (blue = 0x64, green = 0x64, red = 0x64)

The minimum number of bits required to represent the largest palette index (indexes range from 0 to 13 in this case) is floor(log2(13)) + 1 = 4. This means that all indexes are represented using 4 bits, and the remaining 4 bits in the byte are used for the suite depth.

 Decoding the first SUBCODEC_RLEX_SEGMENT:
 11 -> Encoded stop index (least significant 4 bits) and suite depth (most significant 4 bits)
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::stopIndex = 0x01 
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::suiteDepth = 0x01
 04 -> CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor1 = 4
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor2 is not present
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor3 is not present
  
 Using the above values, the following sequence of palette indexes is decoded:
 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  
 Using the palette entries, the sequence of palette indexes is translated into the following pixel sequence (RGB format):
 ffffff, ffffff, ffffff, ffffff, ffffff, 000000

The decoded pixels are written into the target image starting in the top-left corner and progressing from left to right and then top to bottom.

 Decoding the second RLEX_SEGMENT:
 11 -> Encoded stop index (least significant 4 bits) and suite depth (most significant 4 bits)
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::stopIndex = 0x01 
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::suiteDepth = 0x01
 4c -> CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor1 = 76
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor2 is not present
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor3 is not present
  
 Using the above values, the following sequence of palette indexes is decoded: 
 0x00, 0x00, ... [76 total], 0x00, 0x01

In a similar fashion, the next thirteen SUBCODEC_RLEX_SEGMENT structures are processed.

 Finally, decoding the sixteenth RLEX_SEGMENT:
 29 -> Encoded stop index (least significant 4 bits) and suite depth (most significant 4 bits)
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::stopIndex = 0x09 
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::suiteDepth = 0x02
 0 -> CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor1 = 0
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor2 is not present
 CLEARCODEC_SUBCODEC_RLEX_SEGMENT::runLengthFactor3 is not present
  
 Using the above values, the following sequence of palette indexes is decoded: 
 0x07, 0x08, 0x09
  
 Using the palette entries, the sequence of palette indexes is translated into the following pixel sequence (RGB format):
 ffdb90, 3a0000, 3a90db

In a similar fashion, the remaining SUBCODEC_RLEX_SEGMENTS in the packet are decoded until there is no more data left in the SUBCODEC_RLEX DATA payload, at which point subcodec decoding is complete.