0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by blackmagic01021
0

Well you could try writing it yourself.

"I did a web search and found a bar program, please write a foo program for me".
is only marginally better than a 1-line begging post
"Please write a foo program for me".

It might look like effort, but it only took you a few more seconds to achieve.

0

Well you could try writing it yourself.

"I did a web search and found a bar program, please write a foo program for me".
is only marginally better than a 1-line begging post
"Please write a foo program for me".

It might look like effort, but it only took you a few more seconds to achieve.

The foo program is-

int image_size_line=((sizeof(package_data.pData)*8)/12)/MFC3XX_ROW_COUNT;
   unsigned long int compressed_data[512*MFC3XX_ROW_COUNT];	
   int size_of_compreesed_buffer=image_size_line*MFC3XX_ROW_COUNT;
   unsigned short int *pusSrcPointer12= reinterpret_cast<LPWORD>(package_data.pData);
	
   if((image_size_line <= 512)&&(image_size_line  >= 372))
	   {
    		
			package_data.cbData=code_riceI(pusSrcPointer12, MFC3XX_ROW_COUNT, image_size_line, 3,compressed_data,size_of_compreesed_buffer); /* OUT: m_rgulLine */
			package_data.pData=pusSrcPointer12;	
			
			
       }

In this program the first argument is the pointer to the raw 12 bit image. The second argument is row number of the image. the third argument is row number, The forth number is the compression depth, the fifth number is the compression buffer where I finally put the data and sixth parameter is the size of the compression buffer.

The program was modified by me like this--------

int CMFC3xxDevice::code_riceI(unsigned short int *pic, const int X, const int Y, const int n,unsigned long int *compressed_data, unsigned long int size_of_compressed_buffer)
{

unsigned short int *picture = pic;
	unsigned long int line[3000];
	memset(line,0,3000*4);
	int linepos = 0;
	int bitpos = 31;
	int number_of_item=0;
	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;
	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;
		}



		number_of_item=number_of_item+(int)(lp-&line[0]);

		memcpy_s((compressed_data+(4*number_of_item)),size_of_compressed_buffer - (4*number_of_item),line,4*(int)(lp-&line[0]) );
		
        
    }
	number_of_item=number_of_item*4;
	return number_of_item;
}

But the function is designed to work for 16 bit image and I need to work it for 12 bit image..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.