Esempio n. 1
0
int
vncEncodeTight::SendGradientRect(BYTE *dest, int w, int h)
{
	const int streamId = 3;
	int len;

	if (m_remoteformat.bitsPerPixel == 8)
		return SendFullColorRect(dest, w, h);

	if (m_prevRowBuf == NULL)
		m_prevRowBuf = new int [2048*3];

	m_hdrBuffer[m_hdrBufferBytes++] = (streamId | rfbTightExplicitFilter) << 4;
	m_hdrBuffer[m_hdrBufferBytes++] = rfbTightFilterGradient;

	if (m_usePixelFormat24) {
		FilterGradient24(m_buffer, w, h);
		len = 3;
	} else if (m_remoteformat.bitsPerPixel == 32) {
		FilterGradient32((CARD32 *)m_buffer, w, h);
		len = 4;
	} else {
		FilterGradient16((CARD16 *)m_buffer, w, h);
		len = 2;
	}

	return CompressData(dest, streamId, w * h * len,
						m_conf[m_compresslevel].gradientZlibLevel,
						Z_FILTERED);
}
Esempio n. 2
0
int main(int argc,char **argv)
{
	if(argc!=1&&argc!=7)
	{
		fprintf(stderr,"Usage: %s <inputfile >outputfile [typeshift literalshift lengthshift1 lengthshift2 offsetshift1 offsetshift2]\n",argv[0]);
		exit(1);
	}

	uint32_t size;
	uint8_t *file=AllocAndReadFile(stdin,&size);

	int typeshift=4,literalshift=2,lengthshift1=4,lengthshift2=4,offsetshift1=4,offsetshift2=4;
	if(argc==7)
	{
		typeshift=atoi(argv[1]);
		literalshift=atoi(argv[2]);
		lengthshift1=atoi(argv[3]);
		lengthshift2=atoi(argv[4]);
		offsetshift1=atoi(argv[5]);
		offsetshift2=atoi(argv[6]);
	}

	fputc(size&0xff,stdout);
	fputc((size>>8)&0xff,stdout);
	fputc((size>>16)&0xff,stdout);
	fputc((size>>24)&0xff,stdout);

	fputc((offsetshift1<<4)|offsetshift2,stdout);
	fputc((lengthshift1<<4)|lengthshift2,stdout);
	fputc((typeshift<<4)|literalshift,stdout);

	CompressData(stdout,file,size,typeshift,literalshift,lengthshift1,lengthshift2,offsetshift1,offsetshift2);
}
Esempio n. 3
0
int ScanLineZipBlock::WriteCurrentBlockToFile()const
{
	/* first line of block */
	int line =
		( (m_currentLine-1)/NumLinesInBlock() ) * NumLinesInBlock();
	
	/* number of lines in current block to write */
	int numlines = m_currentLine - line;
	int datasize = m_linesize * numlines;
	
	/* first line of block in file */
	line += m_firstline;
	
	char *data_compressed = (char*) malloc( datasize );
	int datasize_compressed =
		CompressData(m_data, datasize, data_compressed);

	fwrite(&line, sizeof(line), 1, m_file);
	fwrite(&datasize_compressed, sizeof(datasize_compressed), 1, m_file);
	fwrite(data_compressed, 1, datasize_compressed, m_file);
	
	free(data_compressed);

	return IMF_ERROR_NOERROR;
}
Esempio n. 4
0
void reply_data( SUser* user )
{
    PRUserData rep;
    bccopy( rep, user->ext );

    rep.data.size = CompressData( user->data, rep.data.data );

    local::write( local::access, rep );
}
Esempio n. 5
0
int
vncEncodeTight::SendMonoRect(BYTE *dest, int w, int h)
{
	const int streamId = 1;
	int paletteLen, dataLen;
	CARD8 paletteBuf[8];

	// Prepare tight encoding header.
	dataLen = (w + 7) / 8;
	dataLen *= h;

	m_hdrBuffer[m_hdrBufferBytes++] = (streamId | rfbTightExplicitFilter) << 4;
	m_hdrBuffer[m_hdrBufferBytes++] = rfbTightFilterPalette;
	m_hdrBuffer[m_hdrBufferBytes++] = 1;

	// Prepare palette, convert image.
	switch (m_remoteformat.bitsPerPixel) {
	case 32:
		EncodeMonoRect32((CARD8 *)m_buffer, w, h);

		((CARD32 *)paletteBuf)[0] = m_monoBackground;
		((CARD32 *)paletteBuf)[1] = m_monoForeground;

		if (m_usePixelFormat24) {
			Pack24(paletteBuf, 2);
			paletteLen = 6;
		} else
			paletteLen = 8;

		memcpy(&m_hdrBuffer[m_hdrBufferBytes], paletteBuf, paletteLen);
		m_hdrBufferBytes += paletteLen;
		break;

	case 16:
		EncodeMonoRect16((CARD8 *)m_buffer, w, h);

		((CARD16 *)paletteBuf)[0] = (CARD16)m_monoBackground;
		((CARD16 *)paletteBuf)[1] = (CARD16)m_monoForeground;

		memcpy(&m_hdrBuffer[m_hdrBufferBytes], paletteBuf, 4);
		m_hdrBufferBytes += 4;
		break;

	default:
		EncodeMonoRect8((CARD8 *)m_buffer, w, h);

		m_hdrBuffer[m_hdrBufferBytes++] = (BYTE)m_monoBackground;
		m_hdrBuffer[m_hdrBufferBytes++] = (BYTE)m_monoForeground;
	}

	return CompressData(dest, streamId, dataLen,
						m_conf[m_compresslevel].monoZlibLevel,
						Z_DEFAULT_STRATEGY);
}
Esempio n. 6
0
int
vncEncodeTight::SendIndexedRect(BYTE *dest, int w, int h)
{
	const int streamId = 2;
	int i, entryLen;
	CARD8 paletteBuf[256*4];

	// Prepare tight encoding header.
	m_hdrBuffer[m_hdrBufferBytes++] = (streamId | rfbTightExplicitFilter) << 4;
	m_hdrBuffer[m_hdrBufferBytes++] = rfbTightFilterPalette;
	m_hdrBuffer[m_hdrBufferBytes++] = (BYTE)(m_paletteNumColors - 1);

	// Prepare palette, convert image.
	switch (m_remoteformat.bitsPerPixel) {
	case 32:
		EncodeIndexedRect32((CARD8 *)m_buffer, w * h);

		for (i = 0; i < m_paletteNumColors; i++) {
			((CARD32 *)paletteBuf)[i] =
				m_palette.entry[i].listNode->rgb;
		}
		if (m_usePixelFormat24) {
			Pack24(paletteBuf, m_paletteNumColors);
			entryLen = 3;
		} else
			entryLen = 4;

		memcpy(&m_hdrBuffer[m_hdrBufferBytes], paletteBuf,
			   m_paletteNumColors * entryLen);
		m_hdrBufferBytes += m_paletteNumColors * entryLen;
		break;

	case 16:
		EncodeIndexedRect16((CARD8 *)m_buffer, w * h);

		for (i = 0; i < m_paletteNumColors; i++) {
			((CARD16 *)paletteBuf)[i] =
				(CARD16)m_palette.entry[i].listNode->rgb;
		}

		memcpy(&m_hdrBuffer[m_hdrBufferBytes], paletteBuf,
			   m_paletteNumColors * 2);
		m_hdrBufferBytes += m_paletteNumColors * 2;
		break;

	default:
		return -1;				// Should never happen.
	}

	return CompressData(dest, streamId, w * h,
						m_conf[m_compresslevel].idxZlibLevel,
						Z_DEFAULT_STRATEGY);
}
Esempio n. 7
0
	/**
	 * Compresses the raw lightmap data to a buffer for writing over Swarm
	 */
	void FLightMapData2D::Compress(int32 DebugSampleIndex)
	{
		// make sure the data has been quantized already
		Quantize(DebugSampleIndex);

		// calculate the uncompressed size
		UncompressedDataSize = sizeof(FQuantizedLightSampleData) * QuantizedData.Num();

		// compress the array
		CompressData((uint8*)QuantizedData.GetData(), UncompressedDataSize, CompressedData, CompressedDataSize);

		// we no longer need the source data now that we're compressed
		QuantizedData.Empty();
	}
Esempio n. 8
0
	void FSignedDistanceFieldShadowMapData2D::Compress(int32 DebugSampleIndex)
	{
		// Make sure the data has been quantized already
		Quantize(DebugSampleIndex);

		// Calculate the uncompressed size
		UncompressedDataSize = sizeof(FQuantizedSignedDistanceFieldShadowSampleData) * QuantizedData.Num();

		// Compress the array
		CompressData((uint8*)QuantizedData.GetData(), UncompressedDataSize, CompressedData, CompressedDataSize);

		// Discard the source data now that we're compressed
		QuantizedData.Empty();
	}
Esempio n. 9
0
int
vncEncodeTight::SendFullColorRect(BYTE *dest, int w, int h)
{
	const int streamId = 0;
	int len;

	m_hdrBuffer[m_hdrBufferBytes++] = 0x00;

	if (m_usePixelFormat24) {
		Pack24(m_buffer, w * h);
		len = 3;
	} else
		len = m_remoteformat.bitsPerPixel / 8;

	return CompressData(dest, streamId, w * h * len,
						m_conf[m_compresslevel].rawZlibLevel,
						Z_DEFAULT_STRATEGY);
}
Esempio n. 10
0
void CALLBACK FrameBuff(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime)
{
	BYTE	*bytes;
	BYTE	*compressed;
	LONG	len;
	LONG	compressedLen;

	UNREFERENCED_PARAMETER(hwnd);
	UNREFERENCED_PARAMETER(dwTime);
	UNREFERENCED_PARAMETER(timerId);
	UNREFERENCED_PARAMETER(uMsg);
	bytes = GetScreenBitmap(&len);
	compressed = CompressData(bytes, len, &compressedLen);
	GlobalFree(bytes);
	/*
	Current protocol (to improve ^^):

	Step 1) We send the compressed bitmap size
	Step 2) We send the compressed bitmap
	*/
	WriteInt32ToSocket(cfg.ClientSocket, (int)compressedLen);
	WriteBytesToSocket(cfg.ClientSocket, compressed, compressedLen);
	free(compressed);
}
void ParseFiles(FILE *outfile, char *folder, int compression)
{
	int i=0, x=0;
	
	for(i=0; i<filecount; i++)
	{
		FILE *infile = NULL;
		unsigned char *buffer = NULL, *output = NULL;
		char *path = (char*)calloc(MAX_PATH+1,sizeof(char));
		int complen = 0, size = 0;
		
		memset(path,'\0',MAX_PATH+1);
		
		strcpy(path,folder);
		strcat(path,"\\");
		strcat(path,fileinfo[i].name);
		
		infile = fopen(path,"rb");
		fseek(infile,0,SEEK_END);
		size = ftell(infile);
		rewind(infile);
		
		buffer = (unsigned char*)calloc(size, sizeof(unsigned char));
		fread(buffer,1,size,infile);
		
		output = CompressData(buffer,size,&fileinfo[i].size, compression);
		
		if(i>0)
			fileinfo[i].offset = fileinfo[i-1].offset+fileinfo[i-1].size;
		
		printf("%-52s %08x %08x %08x\n",path,fileinfo[i].offset,fileinfo[i].size,size);
		
		for(x=0; x<fileinfo[i].size; x++)
			output[x] ^= scrkey[x&0xff];
			
		if(pckhead.extraencrypt == 1)
		{
			for(x=0; x<fileinfo[i].size; x++)
				output[x] ^= key2[x&0x0f];
		}
		
		//memcpy(outbuffer+buffsize,output,fileinfo[i].size);
		fwrite(output, 1, fileinfo[i].size, outfile);
		
		free(path);
		
		if(buffer == output)
		{
			free(buffer);
			output = NULL;
		}
		else
		{
			
			if(buffer != NULL)
				free(buffer);
		
			if(output != NULL)
				free(output);
		}
			
		fclose(infile);
	}
}