int main(void)
{
	HuffEncoded HuffValue;

	if ((fout = fopen("Encoded.txt", "wb")) == NULL) {
		printf ("Error: Opening output file...\n");
		return -1;
	}

	output.value = 0;
	output.bits  = 0;

	HuffmanEncode(0, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");
	HuffmanEncode(-1, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");
	HuffmanEncode(0, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");
	HuffmanEncode(1, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");
	HuffmanEncode(2, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");

	HuffmanEncode(0, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");
	HuffmanEncode(-2, &HuffValue);
	fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");
	// HuffmanEncode(6096, &HuffValue);
	// fillBits(fout, &HuffValue);
	printf ("Number of bits = %d\n", output.bits);
	printf ("Value = %x\n", output.value);
	printf ("---------------------------------------\n");

	fclose(fout);
	return 0;
}
Example #2
0
void TifWriter::writeLine(char *buffer)
{
	int delta = 1;
	int start = 0;
	if (m_RightToLeft) {
		delta = -1;
		start = m_info.m_lx - 1;
	}
	if (m_bpp == 1)
		fillBits(m_lineBuffer, ((unsigned char *)buffer) + start, m_info.m_lx, delta);
	else if (m_bpp == 8) {
		unsigned char *pix = ((unsigned char *)buffer) + start;
		for (int i = 0; i < m_info.m_lx; i++) {
			unsigned char *b = m_lineBuffer + i;
			b[0] = pix[0];
			pix = pix + delta;
		}
	} else {
		assert(m_bpp == 24 || m_bpp == 32);
		TPixel32 *pix = ((TPixel32 *)buffer) + start;

		if (m_bpp == 32)
			for (int i = 0; i < m_info.m_lx; i++) {
				unsigned char *b = m_lineBuffer + i * 4;
				b[0] = pix->r;
				b[1] = pix->g;
				b[2] = pix->b;
				b[3] = pix->m;
				pix = pix + delta;
			}
		else if (m_bpp == 24)
			for (int i = 0; i < m_info.m_lx; i++) {
				unsigned char *b = m_lineBuffer + i * 3;
				b[0] = pix->r;
				b[1] = pix->g;
				b[2] = pix->b;
				pix = pix + delta;
			}
	}
	TIFFWriteScanline(m_tiff, m_lineBuffer, m_row++, 0);
}