diff options
author | DRC <dcommander@users.sourceforge.net> | 2011-08-11 11:18:34 +0000 |
---|---|---|
committer | DRC <dcommander@users.sourceforge.net> | 2011-08-11 11:18:34 +0000 |
commit | cd2c5d46c2a651013a1005a9e42ef77ebfcaf82e (patch) | |
tree | 1c0d6492a93636cf5995fb56916b64c841e6b043 /common/rfb/JpegCompressor.h | |
parent | 0aae4f44cb74620ca6398a531be868f9c1596eca (diff) | |
download | tigervnc-cd2c5d46c2a651013a1005a9e42ef77ebfcaf82e.tar.gz tigervnc-cd2c5d46c2a651013a1005a9e42ef77ebfcaf82e.zip |
Ported encoding optimizations from TurboVNC. The changes to the Tight parameters were determined through extensive low-level profiling (see http://www.virtualgl.org/pmwiki/uploads/About/turbototiger.pdf). The other enhancements involved: (1) porting the solid subrectangle pre-computation code from TightVNC/TurboVNC (it makes a pretty big difference-- see report), (2) encapsulating the JPEG encoder in its own class (this eliminates a buffer copy, and the JPEG buffer is now set to a decent size where it shouldn't ever need to be paged or re-allocated, except in rare corner cases), (3) adding support for last rect. encoding (necessary to support the solid rectangle pre-computation enhancements.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4626 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common/rfb/JpegCompressor.h')
-rw-r--r-- | common/rfb/JpegCompressor.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/common/rfb/JpegCompressor.h b/common/rfb/JpegCompressor.h new file mode 100644 index 00000000..5a9c2fd5 --- /dev/null +++ b/common/rfb/JpegCompressor.h @@ -0,0 +1,87 @@ +/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright (C) 2011 D. R. Commander. All Rights Reserved. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ + +// +// JpegCompressor compresses RGB input into a JPEG image and stores it in +// an underlying MemOutStream +// + +#ifndef __RFB_JPEGCOMPRESSOR_H__ +#define __RFB_JPEGCOMPRESSOR_H__ + +#include <rdr/MemOutStream.h> +#include <rfb/PixelFormat.h> +#include <rfb/Rect.h> + +#include <stdio.h> +extern "C" { +#include <jpeglib.h> +} +#include <setjmp.h> + +namespace rfb { + + typedef struct { + struct jpeg_error_mgr pub; + jmp_buf jmpBuffer; + char lastError[JMSG_LENGTH_MAX]; + } JPEG_ERROR_MGR; + + class JpegCompressor; + + typedef struct { + struct jpeg_destination_mgr pub; + JpegCompressor *instance; + } JPEG_DEST_MGR; + + enum JPEG_SUBSAMP { + SUBSAMP_NONE, + SUBSAMP_422, + SUBSAMP_420 + }; + + class JpegCompressor : public rdr::MemOutStream { + + public: + + JpegCompressor(int bufferLen = 128*1024); + virtual ~JpegCompressor(); + + void compress(rdr::U8 *, const Rect&, const PixelFormat&, int, + JPEG_SUBSAMP); + + void writeBytes(const void*, int); + + inline rdr::U8* getstart() { return start; } + + inline int overrun(int itemSize, int nItems) { + return MemOutStream::overrun(itemSize, nItems); + } + + private: + + struct jpeg_compress_struct cinfo; + JPEG_ERROR_MGR err; + JPEG_DEST_MGR dest; + + }; + +} // end of namespace rfb + +#endif |