4 Replies Latest reply: Jun 17, 2010 6:48 AM by 843853 RSS

    Bit-Length codec

    843853
      Hi,
      does anybody know something about the bit-length codec as it is used for the compression of some parts of JT files (Jupiter Tesselation)? There's a public specification for this file format (http://www.plm.automation.siemens.com/it_it/Images/JT_File_Format_Reference_Rev-B_tcm71-62641.pdf) with a description and an example code. But the description is too short and the code doesn't work. It seems that the code is a bad copy and paste junk from the other described codecs.

      Is there maybe a free library wich supports this codec? All my searches were unsuccessful.

      Thanks and best regards, Joe
        • 1. Re: Bit-Length codec
          843853
          TitusTiger76 wrote:
          ... about the bit-length codec as it is used for the compression of some parts of JT files (Jupiter Tesselation)?
          There's a public specification for this file format ([http://www.plm.automation.siemens.com/it_it/Images/JT_File_Format_Reference_Rev-B_tcm71-62641.pdf]) with a description and an example code. But the description is too short and the code doesn't work.
          That is not Java:
          Appendix C: Decoding Algorithms – An Implementation
          This Appendix provides a sample C++ implementation
          • 2. Re: Bit-Length codec
            843853
            Hi,
            yes I know, that the example is in C++. But if this class is ported to Java, it doesn't work. Although the description of the bit-length codec in chapter 8.2.2 provides only a rough description. One last word to the C++ example code: You can see lines like "Int32 iContext = 0; // Probability context number" or "// Scan through each bit either walking the Huffman code tree or accumulating escaped bit values.". This shows, that the Bit-Length class has been created by copy paste from the huffman codec class.

            With other words: I am looking for a good description, which enables me to implement it in Java. A binary library for Java would also be OK (or a working source code).

            Best regards, Joe
            • 3. Re: Bit-Length codec
              843853
              Hi Kaldrill,
              if you know how it works, it's easy. Try this:
              /**
               * Decodes the given bytes by the bitlength algorithm.
               * @param  encodedBytes            List of encoded bytes
               * @param  numberAllOfCodeTextBits Total number of codetext bits expected
               * @param  asSigned                Treat bits in signed mode
               * @return                         Decoded symbols
               */
              public static List<Integer> decompressByBitLength(byte[] encodedBytes, int numberAllOfCodeTextBits, boolean asSigned){
                   BitBuffer encodedBits = new BitBuffer(ByteBuffer.wrap(encodedBytes), numberAllOfCodeTextBits);
              
                   int bitFieldWith = 0;
                   ArrayList<Integer> decodedSymbols = new ArrayList<Integer>();
                   while((encodedBits.getSize() - encodedBits.getPosition()) > 0){
                        if(encodedBits.readAsInt(1, false, false) == 0){
                             // Decode symbol with same bit field length
                             int decodedSymbol = -1;
                             if(bitFieldWith == 0){
                                  decodedSymbol = 0;
                             } else {
                                  decodedSymbol = encodedBits.readAsInt(bitFieldWith, asSigned, false); 
                             }
                             decodedSymbols.add(decodedSymbol);
              
                        } else {
                             // Adjust bit field length
                             int adjustmentBit = encodedBits.readAsInt(1, false, false);
                             do {
                                  if(adjustmentBit == 1){
                                       bitFieldWith += 2;
                                  } else {
                                       bitFieldWith -= 2;
                                  }
                             } while(encodedBits.readAsInt(1, false, false) == adjustmentBit);
              
                             // Decode symbol with new bit field length
                             int decodedSymbol = -1;
                             if(bitFieldWith == 0){
                                  decodedSymbol = 0;
                             } else {
                                  decodedSymbol = encodedBits.readAsInt(bitFieldWith, asSigned, false);
                             }
                             decodedSymbols.add(decodedSymbol);
                        }
                   }
              
                   return decodedSymbols;
              }
              The C++ sample code in the specification didn't work. All what you need is this function and the BitBuffer class of Bartosz Wieczorek.

              Best regards and good luck. The JT specification is really bad. It seems that Siemens doesn't want any other implementations, except their own toolkit.
              • 4. Re: Bit-Length codec
                843853
                Hi MagicJoe and thanks for your help,

                Where can I find the BitBuffer class from Bartosz Wieczorek ? I found one in the preon package but the BitBuffer class is an interface and the DefaultBitBuffer class is different from the class you expect in your code.