[cotvnc-cvs-commit] cotvnc/Source ZRLEEncodingReader.h,NONE,1.1 ZRLEEncodingReader.m,NONE,1.1 FrameB
Project superseded by http://chicken.sourceforge.net/
Brought to you by:
smeger
Update of /cvsroot/cotvnc/cotvnc/Source In directory sc8-pr-cvs1:/tmp/cvs-serv25468 Modified Files: FrameBufferUpdateReader.h FrameBufferUpdateReader.m HextileEncodingReader.h TightEncodingReader.h TightEncodingReader.m ZlibEncodingReader.h ZlibEncodingReader.m rfbproto.h ProfileManager.m RFBProtocol.m Added Files: ZRLEEncodingReader.h ZRLEEncodingReader.m Log Message: - Added ZRLE Encoding. - Added ZlibHex Encoding. - Added JPEG subencoding for Tight encoding (currently disabled) --- NEW FILE: ZRLEEncodingReader.h --- // // ZRLEEncodingReader.h // Chicken of the VNC // // Created by Helmut Maierhofer on Thu Nov 07 2002. // Copyright (c) 2002 Helmut Maierhofer. All rights reserved. // #import <Foundation/Foundation.h> #import "ZlibEncodingreader.h" @interface ZRLEEncodingReader : ZlibEncodingReader { NSRect tile; FrameBufferColor palette[128]; } - (void)setUncompressedData:(unsigned char*)data length:(int)length; @end --- NEW FILE: ZRLEEncodingReader.m --- // // ZRLEEncodingReader.m // Chicken of the VNC // // Created by Helmut Maierhofer on Thu Nov 07 2002. // Copyright (c) 2002 Helmut Maierhofer. All rights reserved. // #import "ZRLEEncodingReader.h" #import "RFBConnection.h" #define TILE_WIDTH 64 #define TILE_HEIGHT 64 @implementation ZRLEEncodingReader - (void)setUncompressedData:(unsigned char*)data length:(int)length { int i, y, samples, samplesPerByte, shift; unsigned cPixelSize = [frameBuffer tightBytesPerPixel]; unsigned char subEncoding, index, b; FrameBufferPaletteIndex tileBuffer[TILE_HEIGHT * TILE_WIDTH]; FrameBufferPaletteIndex* current, *eol; for(tile.origin.y = frame.origin.y; tile.origin.y < frame.origin.y+frame.size.height; tile.origin.y += TILE_HEIGHT) { tile.size.height = MIN(TILE_HEIGHT, (frame.origin.y + frame.size.height - tile.origin.y)); for(tile.origin.x = frame.origin.x; tile.origin.x < frame.origin.x+frame.size.width; tile.origin.x += TILE_WIDTH) { tile.size.width = MIN(TILE_WIDTH, (frame.origin.x + frame.size.width - tile.origin.x)); subEncoding = *data++; // NSLog(@"Subencoding = %d\n", subEncoding); if(subEncoding == 0) { // raw pixels [frameBuffer putRect:tile fromTightData:data]; data += (int)(cPixelSize * tile.size.width * tile.size.height); continue; } if(subEncoding == 1) { [frameBuffer fillRect:tile tightPixel:data]; data += cPixelSize; continue; } if(subEncoding <= 16) { for(i=0; i<subEncoding; i++) { [frameBuffer fillColor:palette + i fromTightPixel:data]; data += cPixelSize; } current = tileBuffer; y = tile.size.height; switch(subEncoding - 2) { case 0: samplesPerByte = 8; break; case 1: case 2: samplesPerByte = 4; break; default:samplesPerByte = 2; break; } shift = 8 / samplesPerByte; while(y--) { samples = 0; eol = current + (int)tile.size.width; while(current < eol) { if(samples == 0) { index = *data++; samples = samplesPerByte; } *current++ = index >> (8 - shift); index <<= shift; samples--; } } [frameBuffer putRect:tile withColors:tileBuffer fromPalette:palette]; continue; } if(subEncoding == 128) { y = 0; while(y < (tile.size.width * tile.size.height)) { [frameBuffer fillColor:palette fromTightPixel:data]; data += cPixelSize; i = 1; do { b = *data++; i += b; } while(b == 0xff); [frameBuffer putRun:palette ofLength:i at:tile pixelOffset:y]; y += i; } continue; } if(subEncoding >= 130) { for(i=0; i<(subEncoding - 128); i++) { [frameBuffer fillColor:palette + i fromTightPixel:data]; data += cPixelSize; } y = 0; while(y < (tile.size.width * tile.size.height)) { index = *data++; if(index < 128) { [frameBuffer putRun:palette + index ofLength:1 at:tile pixelOffset:y]; y++; continue; } index &= 0x7f; i = 1; do { b = *data++; i += b; } while(b == 0xff); [frameBuffer putRun:palette + index ofLength:i at:tile pixelOffset:y]; y += i; } continue; } [connection terminateConnection:[NSString stringWithFormat:@"ZlibHex unknown subencoding %d encountered\n", subEncoding]]; return; } } [target performSelector:action withObject:self]; } @end Index: FrameBufferUpdateReader.h =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/FrameBufferUpdateReader.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FrameBufferUpdateReader.h 25 Nov 2002 23:13:39 -0000 1.2 --- FrameBufferUpdateReader.h 26 Nov 2002 10:41:53 -0000 1.3 *************** *** 33,36 **** --- 33,38 ---- id tightEncodingReader; id zlibEncodingReader; + id zrleEncodingReader; + id zlibHexEncodingReader; id connection; NSRect currentRect; Index: FrameBufferUpdateReader.m =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/FrameBufferUpdateReader.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FrameBufferUpdateReader.m 25 Nov 2002 23:13:39 -0000 1.2 --- FrameBufferUpdateReader.m 26 Nov 2002 10:41:53 -0000 1.3 *************** *** 30,33 **** --- 30,35 ---- #import "TightEncodingReader.h" #import "ZlibEncodingReader.h" + #import "ZRLEEncodingReader.h" + #import "ZlibHexEncodingReader.h" @implementation FrameBufferUpdateReader *************** *** 48,51 **** --- 50,55 ---- tightEncodingReader = [[TightEncodingReader alloc] initTarget:self action:@selector(didRect:)]; zlibEncodingReader = [[ZlibEncodingReader alloc] initTarget:self action:@selector(didRect:)]; + zrleEncodingReader = [[ZRLEEncodingReader alloc] initTarget:self action:@selector(didRect:)]; + zlibHexEncodingReader = [[ZlibHexEncodingReader alloc] initTarget:self action:@selector(didRect:)]; rectHeaderReader = [[ByteBlockReader alloc] initTarget:self action:@selector(setRect:) size:12]; connection = [target topTarget]; *************** *** 72,75 **** --- 76,81 ---- [tightEncodingReader setFrameBuffer:aBuffer]; [zlibEncodingReader setFrameBuffer:aBuffer]; + [zrleEncodingReader setFrameBuffer:aBuffer]; + [zlibHexEncodingReader setFrameBuffer:aBuffer]; } *************** *** 85,88 **** --- 91,96 ---- [rectHeaderReader release]; [zlibEncodingReader release]; + [zrleEncodingReader release]; + [zlibHexEncodingReader release]; [super dealloc]; } *************** *** 141,144 **** --- 149,158 ---- theReader = tightEncodingReader; break; + case rfbEncodingZlibHex: + theReader = zlibHexEncodingReader; + break; + case rfbEncodingZRLE: + theReader = zrleEncodingReader; + break; } if(theReader == nil) { Index: HextileEncodingReader.h =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/HextileEncodingReader.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** HextileEncodingReader.h 16 Oct 2002 02:58:34 -0000 1.1.1.1 --- HextileEncodingReader.h 26 Nov 2002 10:41:53 -0000 1.2 *************** *** 40,42 **** --- 40,47 ---- } + - (void)nextTile; + - (void)drawSubColorRects:(NSData*)data; + - (void)drawSubRects:(NSData*)data; + - (void)drawRawTile:(NSData*)data; + @end Index: TightEncodingReader.h =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/TightEncodingReader.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TightEncodingReader.h 25 Nov 2002 23:13:39 -0000 1.2 --- TightEncodingReader.h 26 Nov 2002 10:41:53 -0000 1.3 *************** *** 23,26 **** --- 23,31 ---- #import <zlib.h> + #undef SUPPORT_JPEG + #ifdef SUPPORT_JPEG + #import "/sw/include/jpeglib.h" + #endif + #define NUM_ZSTREAMS 4 #define Z_BUFSIZE 4096 *************** *** 53,56 **** --- 58,64 ---- int zBufPos; id connection; + #ifdef SUPPORT_JPEG + struct jpeg_source_mgr jpegSrcManager; + #endif } Index: TightEncodingReader.m =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/TightEncodingReader.m,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TightEncodingReader.m 25 Nov 2002 23:13:39 -0000 1.3 --- TightEncodingReader.m 26 Nov 2002 10:41:53 -0000 1.4 *************** *** 28,31 **** --- 28,67 ---- #import "RFBConnection.h" + #ifdef SUPPORT_JPEG + + static void JpegInitSource(j_decompress_ptr cinfo) + { + } + + static boolean JpegFillInputBuffer(j_decompress_ptr cinfo) + { + return YES; + } + + static void JpegSkipInputData(j_decompress_ptr cinfo, long num_bytes) + { + if (num_bytes > 0 && num_bytes <= cinfo->src->bytes_in_buffer) { + cinfo->src->next_input_byte += (size_t) num_bytes; + cinfo->src->bytes_in_buffer -= (size_t) num_bytes; + } + } + + static void JpegTermSource(j_decompress_ptr cinfo) + { + } + + static void JpegSetSrcManager(j_decompress_ptr cinfo, CARD8* compressedData, int compressedLen) + { + cinfo->src->init_source = JpegInitSource; + cinfo->src->fill_input_buffer = JpegFillInputBuffer; + cinfo->src->skip_input_data = JpegSkipInputData; + cinfo->src->resync_to_restart = jpeg_resync_to_restart; + cinfo->src->term_source = JpegTermSource; + cinfo->src->next_input_byte = compressedData; + cinfo->src->bytes_in_buffer = compressedLen; + } + + #endif + @implementation TightEncodingReader *************** *** 97,102 **** return; } if(cntl > rfbTightMaxSubencoding) { ! [connection terminateConnection:@"Tight encoding: bad subencoding value received.\n"]; return; } --- 133,144 ---- return; } + #ifdef SUPPORT_JPEG + if(cntl == rfbTightJpeg) { + [target setReader:zipLengthReader]; + return; + } + #endif if(cntl > rfbTightMaxSubencoding) { ! [connection terminateConnection:@"Tight encoding: bad subencoding value received.\n"]; return; } *************** *** 187,190 **** --- 229,239 ---- } #endif + #ifdef SUPPORT_JPEG + if(cntl == rfbTightJpeg) { + [zippedDataReader setBufferSize:[zl unsignedIntValue]]; + [target setReader:zippedDataReader]; + return; + } + #endif streamId = cntl & 0x03; stream = zStream + streamId; *************** *** 225,228 **** --- 274,313 ---- #ifdef COLLECT_STATS bytesTransferred += [data length]; + #endif + #ifdef SUPPORT_JPEG + if(cntl == rfbTightJpeg) { + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPROW rowPointer[1]; + unsigned char* buffer; + NSRect r; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + cinfo.src = &jpegSrcManager; + JpegSetSrcManager(&cinfo, (char*)[data bytes], [data length]); + jpeg_read_header(&cinfo, TRUE); + cinfo.out_color_space = JCS_RGB; + jpeg_start_decompress(&cinfo); + if(cinfo.output_width != frame.size.width || cinfo.output_height != frame.size.height || cinfo.output_components != 3) { + [connection terminateConnection:[NSString stringWithFormat:@"Tight Encoding: Wrong JPEG data received.\n"]]; + jpeg_destroy_decompress(&cinfo); + return; + } + buffer = malloc(3 * frame.size.width); + rowPointer[0] = (JSAMPROW)buffer; + r = frame; + r.size.height = 1; + while(cinfo.output_scanline < cinfo.output_height) { + jpeg_read_scanlines(&cinfo, rowPointer, 1); + [frameBuffer putRect:r fromRGBBytes:buffer]; + r.origin.y += 1; + } + free(buffer); + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + [target performSelector:action withObject:self]; + return; + } #endif stream = zStream + (cntl & 0x03); Index: ZlibEncodingReader.h =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/ZlibEncodingReader.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ZlibEncodingReader.h 25 Nov 2002 23:13:39 -0000 1.1 --- ZlibEncodingReader.h 26 Nov 2002 10:41:53 -0000 1.2 *************** *** 15,19 **** unsigned char* pixels; unsigned int capacity; - BOOL streamInited; id numBytesReader; id pixelReader; --- 15,18 ---- *************** *** 21,24 **** --- 20,25 ---- z_stream stream; } + + - (void)setUncompressedData:(unsigned char*)data length:(int)length; @end Index: ZlibEncodingReader.m =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/ZlibEncodingReader.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ZlibEncodingReader.m 25 Nov 2002 23:13:39 -0000 1.1 --- ZlibEncodingReader.m 26 Nov 2002 10:41:53 -0000 1.2 *************** *** 17,20 **** --- 17,22 ---- - (id)initTarget:(id)aTarget action:(SEL)anAction { + int inflateResult; + [super initTarget:aTarget action:anAction]; capacity = 4096; *************** *** 23,26 **** --- 25,32 ---- pixelReader = [[ByteBlockReader alloc] initTarget:self action:@selector(setCompressedData:)]; connection = [aTarget topTarget]; + inflateResult = inflateInit(&stream); + if (inflateResult != Z_OK) { + [connection terminateConnection:[NSString stringWithFormat:@"Zlib encoding: inflateInit: %s.\n", stream.msg]]; + } return self; } *************** *** 28,31 **** --- 34,38 ---- - (void)dealloc { + free(pixels); [numBytesReader release]; [pixelReader release]; *************** *** 61,72 **** stream.avail_out = capacity; stream.data_type = Z_BINARY; - if(!streamInited) { - inflateResult = inflateInit(&stream); - if (inflateResult != Z_OK) { - [connection terminateConnection:[NSString stringWithFormat:@"Zlib encoding: inflateInit: %s.\n", stream.msg]]; - return; - } - streamInited = YES; - } inflateResult = inflate(&stream, Z_SYNC_FLUSH); if(inflateResult == Z_NEED_DICT ) { --- 68,71 ---- *************** *** 78,81 **** --- 77,85 ---- return; } + [self setUncompressedData:pixels length:capacity - stream.avail_out]; + } + + - (void)setUncompressedData:(unsigned char*)data length:(int)length + { [frameBuffer putRect:frame fromData:pixels]; [target performSelector:action withObject:self]; Index: rfbproto.h =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/rfbproto.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** rfbproto.h 16 Oct 2002 02:58:42 -0000 1.1.1.1 --- rfbproto.h 26 Nov 2002 10:41:53 -0000 1.2 *************** *** 305,308 **** --- 305,309 ---- #define rfbEncodingTight 7 #define rfbEncodingZlibHex 8 + #define rfbEncodingZRLE 16 /* *************** *** 310,314 **** * 0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels; * 0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data; ! * 0xFFFFFF20 .. 0xFFFFFFEF -- not allocated yet; * 0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels. */ --- 311,317 ---- * 0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels; * 0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data; ! * 0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions; ! * 0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet; ! * 0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor; * 0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels. */ *************** *** 328,331 **** --- 331,347 ---- #define rfbEncodingRichCursor 0xFFFFFF11 + #define rfbEncodingLastRect 0xFFFFFF20 + + #define rfbEncodingQualityLevel0 0xFFFFFFE0 + #define rfbEncodingQualityLevel1 0xFFFFFFE1 + #define rfbEncodingQualityLevel2 0xFFFFFFE2 + #define rfbEncodingQualityLevel3 0xFFFFFFE3 + #define rfbEncodingQualityLevel4 0xFFFFFFE4 + #define rfbEncodingQualityLevel5 0xFFFFFFE5 + #define rfbEncodingQualityLevel6 0xFFFFFFE6 + #define rfbEncodingQualityLevel7 0xFFFFFFE7 + #define rfbEncodingQualityLevel8 0xFFFFFFE8 + #define rfbEncodingQualityLevel9 0xFFFFFFE9 + /***************************************************************************** *************** *** 465,468 **** --- 481,486 ---- #define rfbHextileAnySubrects (1 << 3) #define rfbHextileSubrectsColoured (1 << 4) + #define rfbHextileZlibRaw (1 << 5) + #define rfbHextileZlibHex (1 << 6) #define rfbHextilePackXY(x,y) (((x) << 4) | (y)) *************** *** 480,483 **** --- 498,502 ---- #define rfbTightExplicitFilter 0x04 #define rfbTightFill 0x08 + #define rfbTightJpeg 0x09 #define rfbTightMaxSubencoding 0x08 Index: ProfileManager.m =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/ProfileManager.m,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ProfileManager.m 25 Nov 2002 23:13:39 -0000 1.2 --- ProfileManager.m 26 Nov 2002 10:41:53 -0000 1.3 *************** *** 20,24 **** #define PROFILES @"ConnectProfiles" ! #define NUMENCODINGS 6 static const NSString* encodingNames[NUMENCODINGS] = { --- 20,24 ---- #define PROFILES @"ConnectProfiles" ! #define NUMENCODINGS 8 static const NSString* encodingNames[NUMENCODINGS] = { *************** *** 28,32 **** @"Raw", @"Tight", ! @"Zlib" }; --- 28,34 ---- @"Raw", @"Tight", ! @"Zlib", ! @"ZRLE", ! @"ZlibHex" }; *************** *** 37,41 **** rfbEncodingRaw, rfbEncodingTight, ! rfbEncodingZlib }; --- 39,45 ---- rfbEncodingRaw, rfbEncodingTight, ! rfbEncodingZlib, ! rfbEncodingZRLE, ! rfbEncodingZlibHex }; Index: RFBProtocol.m =================================================================== RCS file: /cvsroot/cotvnc/cotvnc/Source/RFBProtocol.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** RFBProtocol.m 16 Oct 2002 02:58:42 -0000 1.1.1.1 --- RFBProtocol.m 26 Nov 2002 10:41:53 -0000 1.2 *************** *** 46,50 **** int i; rfbSetEncodingsMsg msg; ! CARD32 enc[16]; numberOfEncodings = l; --- 46,50 ---- int i; rfbSetEncodingsMsg msg; ! CARD32 enc[64]; numberOfEncodings = l; *************** *** 63,67 **** Profile* profile = [target profile]; CARD16 i, l = [profile numberOfEnabledEncodings]; ! CARD32 enc[16]; for(i=0; i<l; i++) { --- 63,67 ---- Profile* profile = [target profile]; CARD16 i, l = [profile numberOfEnabledEncodings]; ! CARD32 enc[64]; for(i=0; i<l; i++) { |