libopenraw
|
00001 /* -*- tab-width:4; c-basic-offset:4 -*- */ 00002 /* 00003 * libopenraw - nefdiffiterator.cpp 00004 * 00005 * Copyright (C) 2008 Rafael Avila de Espindola. 00006 * 00007 * This library is free software: you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License 00009 * as published by the Free Software Foundation, either version 3 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library. If not, see 00019 * <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 #include "nefdiffiterator.h" 00023 00024 namespace OpenRaw { 00025 namespace Internals { 00026 00027 int NefDiffIterator::get() 00028 { 00029 unsigned int t = m_decoder.decode(m_iter); 00030 unsigned int len = t & 15; 00031 unsigned int shl = t >> 4; 00032 00033 00034 unsigned int bits = m_iter.get(len - shl); 00035 00036 int diff = ((bits << 1) + 1) << shl >> 1; 00037 if ((diff & (1 << (len-1))) == 0) 00038 diff -= (1 << len) - !shl; 00039 00040 return diff; 00041 } 00042 00043 // 00 5 00044 // 010 4 00045 // 011 3 00046 // 100 6 00047 // 101 2 00048 // 110 7 00049 // 1110 1 00050 // 11110 0 00051 // 111110 8 00052 // 1111110 9 00053 // 11111110 11 00054 // 111111110 10 00055 // 1111111110 12 00056 // 1111111111 0 00057 const HuffmanNode NefDiffIterator::Lossy12Bit[] = { 00058 /* 0 */ {0, 6}, /* root */ 00059 /* 1 */ {0, 3}, /* 0 */ 00060 /* 2 */ {1, 5}, /* 00 */ 00061 /* 3 */ {0, 5}, /* 01 */ 00062 /* 4 */ {1, 4}, /* 010 */ 00063 /* 5 */ {1, 3}, /* 011 */ 00064 /* 6 */ {0, 10}, /* 1 */ 00065 /* 7 */ {0, 9}, /* 10 */ 00066 /* 8 */ {1, 6}, /* 100 */ 00067 /* 9 */ {1, 2}, /* 101 */ 00068 /* 10 */ {0, 12}, /* 11 */ 00069 /* 11 */ {1, 7}, /* 110 */ 00070 /* 12 */ {0, 14}, /* 111 */ 00071 /* 13 */ {1, 1}, /* 1110 */ 00072 /* 14 */ {0, 16}, /* 1111 */ 00073 /* 15 */ {1, 0}, /* 11110 */ 00074 /* 16 */ {0, 18}, /* 11111 */ 00075 /* 17 */ {1, 8}, /* 111110 */ 00076 /* 18 */ {0, 20}, /* 111111 */ 00077 /* 19 */ {1, 9}, /* 1111110 */ 00078 /* 20 */ {0, 22}, /* 1111111 */ 00079 /* 21 */ {1, 11}, /* 11111110 */ 00080 /* 22 */ {0, 24}, /* 11111111 */ 00081 /* 23 */ {1, 10}, /* 111111110 */ 00082 /* 24 */ {0, 26}, /* 111111111 */ 00083 /* 25 */ {1, 12}, /* 1111111110 */ 00084 /* 26 */ {1, 0}, /* 1111111111 */ 00085 }; 00086 00087 // 00 7 00088 // 010 6 00089 // 011 8 00090 // 100 5 00091 // 101 9 00092 // 1100 4 00093 // 1101 10 00094 // 11100 3 00095 // 11101 11 00096 // 111100 12 00097 // 111101 2 00098 // 111110 0 00099 // 1111110 1 00100 // 11111110 13 00101 // 11111111 14 00102 const HuffmanNode NefDiffIterator::LossLess14Bit[] = { 00103 /* 0 */ {0, 6}, /* root */ 00104 /* 1 */ {0, 3}, /* 0 */ 00105 /* 2 */ {1, 7}, /* 00 */ 00106 /* 3 */ {0, 5}, /* 01 */ 00107 /* 4 */ {1, 6}, /* 010 */ 00108 /* 5 */ {1, 8}, /* 011 */ 00109 /* 6 */ {0, 10}, /* 1 */ 00110 /* 7 */ {0, 9}, /* 10 */ 00111 /* 8 */ {1, 5}, /* 100 */ 00112 /* 9 */ {1, 9}, /* 101 */ 00113 /* 10 */ {0, 14}, /* 11 */ 00114 /* 11 */ {0, 13}, /* 110 */ 00115 /* 12 */ {1, 4}, /* 1100 */ 00116 /* 13 */ {1, 10}, /* 1101 */ 00117 /* 14 */ {0, 18}, /* 111 */ 00118 /* 15 */ {0, 17}, /* 1110 */ 00119 /* 16 */ {1, 3}, /* 11100 */ 00120 /* 17 */ {1, 11}, /* 11101 */ 00121 /* 18 */ {0, 22}, /* 1111 */ 00122 /* 19 */ {0, 21}, /* 11110 */ 00123 /* 20 */ {1, 12}, /* 111100 */ 00124 /* 21 */ {1, 2}, /* 111101 */ 00125 /* 22 */ {0, 24}, /* 11111 */ 00126 /* 23 */ {1, 0}, /* 111110 */ 00127 /* 24 */ {0, 26}, /* 111111 */ 00128 /* 25 */ {1, 1}, /* 1111110 */ 00129 /* 26 */ {0, 28}, /* 1111111 */ 00130 /* 27 */ {1, 13}, /* 11111110 */ 00131 /* 28 */ {1, 14}, /* 11111111 */ 00132 }; 00133 00134 NefDiffIterator::NefDiffIterator(const HuffmanNode* const t, 00135 const void *p) : 00136 m_iter(p), m_decoder(t) 00137 { 00138 } 00139 00140 } 00141 }