⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encodecodeword.h

📁 一个简单而且快速的无损压缩算法。包含源代码实现
💻 H
字号:
#include "bppmask.h"
#include "bigendian.h"

/* UWAGA fullbytes podaje wynik w bajtach, ale funkcja dziala slowami */
/* czyli i compressedrow i fullbytes jest wielokrotnoscia 4, bitsused<32 */

#define ENCODE_START(compressedrow, fullbytes, bitsused)													\
{																											\
	unsigned int bitword=0;				/* kompletowane slowo */											\	unsigned int * writeptr=(unsigned int *)(compressedrow+*fullbytes);										\
										/* indeks miejsca w buforze na slowo po skompletowaniu */			\
	unsigned int emptybits; /* ile bitow w bitword jest jeszcze nie zapisane */								\
																											\
	assert(((*fullbytes) % 4)==0);																			\
							/* konieczne, dla inicjalizacji writeptr i inicjalizacji w ciele funkcji */		\
	assert((((BYTE *)NULL-compressedrow) % 4) == 0);														\
							/* bufor zapisu zaczyna sie od wielokrotnosci 4-ch bajtow */					\
	if(*bitsused)																							\
	{																										\
		assert(*bitsused<32);																				\
		BE_LOAD_WORD(writeptr, bitword);																	\
		assert(!(bitword & bppmask[32-*bitsused])); /* czy niezapisane bity rzeczywiscie puste*/			\
	}																										\
	emptybits=32-*bitsused;																					\
	assert(emptybits!=0);

#define ENCODE(codeword, bits)																				\
	{																										\
		assert( bits<=32 );																					\
		assert( bits!=0 );																					\
		assert( !(codeword & ~bppmask[bits]) );																\
																											\
		if (emptybits>bits) /* zmiesci sie i nie zajmie calosci, przes. w lewo i OR */						\
		{																									\
			emptybits-=bits;																				\
			bitword|=codeword<<emptybits;																	\
		}																									\
		else	/* zajmie calosc, lub wiecej, konieczny zapis */											\
		{																									\
			const unsigned int fullbits=bits-emptybits; /* ile bitow sie nie zmiesci */						\
			const unsigned int towrite=bitword|(codeword>>fullbits);										\
																											\
			assert(codeword==(codeword>>0));																\
			emptybits=32-fullbits;																			\
			if(fullbits)																					\
				bitword=codeword<<emptybits;																\
			else																							\
				bitword=0;																					\
																											\
			BE_STORE_WORD(writeptr++, towrite);																\
		}																									\
																											\
		assert(emptybits!=0);																				\
		assert(emptybits<=32);																				\
		assert((bitword&bppmask[emptybits])==0);															\
	}


#define ENCODE_STOP(compressedrow, fullbytes, bitsused)														\
	if(emptybits!=32)																						\
		BE_STORE_WORD(writeptr, bitword);																	\
																											\
	*fullbytes=(unsigned int)((BYTE*)writeptr-compressedrow);												\
	*bitsused=32-emptybits;																					\
																											\
	assert(!*bitsused || !(bitword & bppmask[emptybits]));													\
		/* czy niezapisane bity rzeczywiscie puste */														\
}

#if 0
/* wersja po wstepnej optymalizacji, moze polaczenie tego z kodowaniem */
/* da wyrazny speedup */
void encodecodewords(const thecodeword precompressedrow[], BYTE compressedrow[], 
					 const unsigned int width, 
					 unsigned int * fullbytes, unsigned int * bitsused)
{
	unsigned int i;			/* indeks kodowanego slowa */

	ENCODE_START(compressedrow, fullbytes, bitsused);

	for(i=0; i<width; i++)
		ENCODE(precompressedrow[i].codeword, precompressedrow[i].codewordlen);

	ENCODE_STOP(compressedrow, fullbytes, bitsused);
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -