// Copyright (c) 2008, WEST, Polytechnic Institute of NYU. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of WEST, Polytechnic Institute of NYU. nor the names // of its contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Author: Torsten Suel, Jiangong Zhang, Jinru He // // If you have any questions or problems about our codes, please contact: // jhe@cis.poly.edu // // //#include "rice_coding2.h" //#include /*rc_rice_coding2() { // TODO Auto-generated constructor stub cnum[0] = 0; cnum[1] = 1; cnum[2] = 2; cnum[3] = 3; cnum[4] = 4; cnum[5] = 5; cnum[6] = 6; cnum[7] = 7; cnum[8] = 8; cnum[9] = 9; cnum[10] = 10; cnum[11] = 11; cnum[12] = 12; cnum[13] = 13; cnum[14] = 16; cnum[15] = 20; cnum[16] = 32; }*/ #define coding_type 3 #define block_size 128 static int cnum[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,20,32 }; /*rc_~rice_coding2() { // TODO Auto-generated destructor stub }*/ /*int rc_get_type() { return coding_type; } void rc_set_size(int size) { this->block_size = size; }*/ //void pack(unsigned int *v, unsigned int b, unsigned int n, unsigned int *w); #include "../bitpack.h" #include "rc.h" void setBit(unsigned char *buf, unsigned int *bp, unsigned int val) { unsigned int bPtr; unsigned int w; bPtr = (*bp)&7; if (bPtr == 0) buf[(*bp)>>3] = 0; if (val == 1) buf[(*bp)>>3] |= (1< 0) { s = ((bits * block_size)>>5); for (i = 0; i < s; i++) w[i] = 0; for (i = 0; i < block_size; i++) out[i] = (*buf)[i] & ((1u<>bits); val > 0; val--) setBit((unsigned char *)(w), &bp, 1); setBit((unsigned char *)(w), &bp, 0); } w += (bp>>5); if (bp&31) w += 1; } *buf += block_size; return w; } unsigned char *rcenc32(unsigned* input, int size, unsigned* output) { int i,s, f = 0; int fres; unsigned int bb = 0; unsigned int bp; int m = 0; //block_size = size; for (i = 0, bb = 0; i < block_size; i++) { //printf("%d\n", input[i]); bb += input[i]; } bb = 100 * (bb / block_size) / 100; //printf("bb=%d, ", bb); int b; for (b = 0; bb > 0; bb = (bb>>1)) b++; if (b > 0) b--; //cout << b << endl; for (fres = 0; cnum[fres] < b; fres++);//{printf("%d, %d\n", cnum[fres], fres);} b = cnum[fres]; //printf("b:%d, f:%d\n", b,fres); unsigned* tmp = input; unsigned* tmp2 = output+1; tmp2 = rc_turbo_rice_encode(tmp2, &tmp, b); *output = (unsigned)((b<<6)|fres); return tmp2;// - output; } unsigned char *rc_turbo_rice_decode(unsigned int *w, unsigned int *buf, unsigned int bits, unsigned int flag) { unsigned int i; unsigned char b; unsigned char *ww; unsigned int val; //(unpack[flag])(buf, *w, block_size); w = bitunpack32(w, block_size, (unsigned char *)buf, flag); //*w += ((bits * block_size)>>5); if (bits < 32) { i = 0; ww = (unsigned char *)(w); val = 1<>2); if (i & 3) w += 1; } return w; } unsigned char *rcdec32(unsigned* input, int size, unsigned* output) { unsigned* tmp = input; int flag = (*tmp)&0x3f; int b = ((*tmp)>>6); tmp++; return rc_turbo_rice_decode(tmp, output, b, flag); //return tmp; // - input; }