1 /************************************************************************ 2 3 S-DD1'algorithm emulation code 4 ------------------------------ 5 6 Author: Andreas Naive 7 Date: August 2003 8 Last update: October 2004 9 10 This code is Public Domain. There is no copyright holded by the author. 11 Said this, the author wish to explicitly emphasize his inalienable moral rights 12 over this piece of intelectual work and the previous research that made it 13 possible, as recognized by most of the copyright laws around the world. 14 15 This code is provided 'as-is', with no warranty, expressed or implied. 16 No responsability is assumed by the author in connection with it. 17 18 The author is greatly indebted with The Dumper, without whose help and 19 patience providing him with real S-DD1 data the research would have never been 20 possible. He also wish to note that in the very beggining of his research, 21 Neviksti had done some steps in the right direction. By last, the author is 22 indirectly indebted to all the people that worked and contributed in the 23 S-DD1 issue in the past. 24 25 An algorithm's documentation is available as a separate document. 26 The implementation is obvious when the algorithm is 27 understood. 28 29 ************************************************************************/ 30 31 #define bool8 uint8 32 33 class SDD1_IM { //Input Manager 34 35 public: SDD1_IM(void)36 SDD1_IM(void) {} 37 void prepareDecomp(uint32 in_buf); 38 uint8 getCodeword(const uint8 code_len); 39 40 private: 41 uint32 byte_ptr; 42 uint8 bit_count; 43 44 }; 45 46 //////////////////////////////////////////////////// 47 48 49 class SDD1_GCD { //Golomb-Code Decoder 50 51 public: 52 SDD1_GCD(SDD1_IM *associatedIM); 53 void getRunCount(uint8 code_num, uint8 *MPScount, bool8 *LPSind); 54 55 private: 56 SDD1_IM *const IM; 57 58 }; 59 60 ////////////////////////////////////////////////////// 61 62 63 class SDD1_BG { // Bits Generator 64 65 public: 66 SDD1_BG(SDD1_GCD *associatedGCD, uint8 code); 67 void prepareDecomp(void); 68 uint8 getBit(bool8 *endOfRun); 69 70 private: 71 SDD1_GCD *const GCD; 72 const uint8 code_num; 73 uint8 MPScount; 74 bool8 LPSind; 75 76 }; 77 78 //////////////////////////////////////////////// 79 80 81 class SDD1_PEM { //Probability Estimation Module 82 83 public: 84 SDD1_PEM(SDD1_BG *associatedBG0, SDD1_BG *associatedBG1, 85 SDD1_BG *associatedBG2, SDD1_BG *associatedBG3, 86 SDD1_BG *associatedBG4, SDD1_BG *associatedBG5, 87 SDD1_BG *associatedBG6, SDD1_BG *associatedBG7); 88 void prepareDecomp(void); 89 uint8 getBit(uint8 context); 90 91 private: 92 struct state { 93 uint8 code_num; 94 uint8 nextIfMPS; 95 uint8 nextIfLPS; 96 }; 97 static const state evolution_table[]; 98 struct SDD1_ContextInfo { 99 uint8 status; 100 uint8 MPS; 101 } contextInfo[32]; 102 SDD1_BG * BG[8]; 103 104 }; 105 106 /////////////////////////////////////////////////// 107 108 109 class SDD1_CM { //Context Model 110 111 public: 112 SDD1_CM(SDD1_PEM *associatedPEM); 113 void prepareDecomp(uint32 first_byte); 114 uint8 getBit(void); 115 116 private: 117 uint8 bitplanesInfo; 118 uint8 contextBitsInfo; 119 uint8 bit_number; 120 uint8 currBitplane; 121 uint16 prevBitplaneBits[8]; 122 SDD1_PEM *const PEM; 123 124 }; 125 126 /////////////////////////////////////////////////// 127 128 129 class SDD1_OL { //Output Logic 130 131 public: 132 SDD1_OL(SDD1_CM *associatedCM); 133 void prepareDecomp(uint32 first_byte, uint16 out_len, uint8 *out_buf); 134 void launch(void); 135 136 private: 137 uint8 bitplanesInfo; 138 uint16 length; 139 uint8 *buffer; 140 SDD1_CM *const CM; 141 142 }; 143 144 ///////////////////////////////////////////////////////// 145 146 147 class SDD1emu { 148 149 public: 150 SDD1emu(void); 151 void decompress(uint32 in_buf, uint16 out_len, uint8 *out_buf); 152 153 private: 154 SDD1_IM IM; 155 SDD1_GCD GCD; 156 SDD1_BG BG0; SDD1_BG BG1; SDD1_BG BG2; SDD1_BG BG3; 157 SDD1_BG BG4; SDD1_BG BG5; SDD1_BG BG6; SDD1_BG BG7; 158 SDD1_PEM PEM; 159 SDD1_CM CM; 160 SDD1_OL OL; 161 162 }; 163 164 #undef bool8 165