Hello Everyone,

I am trying to work on omage compression on 12 bit image compression. I am using Rice encoding for 12 bit image. I have a complete program for 16 bit image compression. But I want to convert it to 12 bit image compression.

And I also want to know, how the 12 bit image in represented in a binary form.

Any advice or code wil be very useful.

```
void code_riceI(unsigned short int *pic, const int X, const int Y, const int n, unsigned long int *output_stream, unsigned long int *output_length)
{
//rice codec
//X,Y image size
//n rice coef - k=2^n D = q*k+r, r<k
#define SAVE_FILE 1
unsigned short int *picture = pic;
unsigned long int line[3000];
memset(line,0,3000*4);
int linepos = 0;
int bitpos = 31;
const unsigned int k = 1 << n;
unsigned int tempmask = 0;
for(int i = 0; i < n; i++)
{
tempmask|= 1 << i;
}
const unsigned int mask = tempmask;
unsigned int last1, last2;
unsigned int akt;
int dif[2];
int q,r;
unsigned int sign;
#if SAVE_FILE
FILE *fp;
fp = fopen(fn,"wb");
#endif
for(int y = 0; y < Y; y++)
{
memset(line,0,3000*4);
int linepos = 0;
unsigned long int *lp = &line[linepos];
unsigned long int current_word = 0;
int bitpos = 31;
//first full pix
bitpos-= 10;
current_word|= (last1 = (unsigned long int)(*picture++)) << (bitpos);
//second full pix
bitpos-= 10;
current_word|= (last2 = (unsigned long int)(*picture++)) << (bitpos);
for(int x = 2; x <= X-2; x+=2)
{
//calc difference between two pixels of the same color
akt = ((unsigned long int)(*picture++));
dif[0] = last1 - akt;
last1 = akt;
akt = ((unsigned long int)(*picture++));
dif[1] = last2 - akt;
last2 = akt;
int j = 0;
while(j < 2)
{
//set signs
sign = 0;
int d = dif[j];
//if(d < 0)
//{
// d = -d;
// sign = 1;
//}
sign = d<0;
d = abs(d);
//calc factors
q = d >> n;
r = d & mask;
//bits für q einschreiben
if(q > bitpos)
{
while(q--)
{
if(!bitpos)
{
bitpos = 32;
*lp++ = current_word;
current_word = 0;
}
bitpos--;
current_word|= 1<<bitpos;
}
}
else
{
bitpos-= q;
current_word|=((1<<q)-1)<<bitpos;
}
//0bit
if(!bitpos)
{
bitpos = 32;
*lp++ = current_word;
current_word = 0;
}
bitpos--;
//sign bit
if(!bitpos)
{
bitpos = 32;
*lp++ = current_word;
current_word = 0;
}
bitpos--;
current_word|= sign<<bitpos;
//r bits
if(n > bitpos)
{
int i = n;
while(i--)
{
if(!bitpos)
{
bitpos = 32;
*lp++ = current_word;
current_word = 0;
}
bitpos--;
current_word|= ((r>>i)&1)<<bitpos;
}
}
else
{
bitpos-=n;
current_word|= r<<bitpos;
}
j++;
}
}
//save line
if(bitpos >= 0)
{
bitpos = 0;
*lp++ = current_word;
current_word = 0;
}
#if SAVE_FILE
fwrite(line,4,lp-&line[0],fp);
#endif
}
#if SAVE_FILE
fclose(fp);
#endif
}
```

This is the code for 16 bit image compression.

can you help me to convert it to 12 bit image compression.

Thank you.