blob: 5a9c2fd58d88b0575a16456f4418e170eab0fc8b [file] [log] [blame]
DRCcd2c5d42011-08-11 11:18:34 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
3 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20//
21// JpegCompressor compresses RGB input into a JPEG image and stores it in
22// an underlying MemOutStream
23//
24
25#ifndef __RFB_JPEGCOMPRESSOR_H__
26#define __RFB_JPEGCOMPRESSOR_H__
27
28#include <rdr/MemOutStream.h>
29#include <rfb/PixelFormat.h>
30#include <rfb/Rect.h>
31
32#include <stdio.h>
33extern "C" {
34#include <jpeglib.h>
35}
36#include <setjmp.h>
37
38namespace rfb {
39
40 typedef struct {
41 struct jpeg_error_mgr pub;
42 jmp_buf jmpBuffer;
43 char lastError[JMSG_LENGTH_MAX];
44 } JPEG_ERROR_MGR;
45
46 class JpegCompressor;
47
48 typedef struct {
49 struct jpeg_destination_mgr pub;
50 JpegCompressor *instance;
51 } JPEG_DEST_MGR;
52
53 enum JPEG_SUBSAMP {
54 SUBSAMP_NONE,
55 SUBSAMP_422,
56 SUBSAMP_420
57 };
58
59 class JpegCompressor : public rdr::MemOutStream {
60
61 public:
62
63 JpegCompressor(int bufferLen = 128*1024);
64 virtual ~JpegCompressor();
65
66 void compress(rdr::U8 *, const Rect&, const PixelFormat&, int,
67 JPEG_SUBSAMP);
68
69 void writeBytes(const void*, int);
70
71 inline rdr::U8* getstart() { return start; }
72
73 inline int overrun(int itemSize, int nItems) {
74 return MemOutStream::overrun(itemSize, nItems);
75 }
76
77 private:
78
79 struct jpeg_compress_struct cinfo;
80 JPEG_ERROR_MGR err;
81 JPEG_DEST_MGR dest;
82
83 };
84
85} // end of namespace rfb
86
87#endif