DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 1 | /* 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 | |
Pierre Ossman | 9144ae0 | 2011-09-07 11:35:04 +0000 | [diff] [blame] | 32 | struct jpeg_compress_struct; |
| 33 | |
| 34 | struct JPEG_ERROR_MGR; |
| 35 | struct JPEG_DEST_MGR; |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 36 | |
| 37 | namespace rfb { |
| 38 | |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 39 | enum JPEG_SUBSAMP { |
DRC | b4a8323 | 2011-08-19 04:57:18 +0000 | [diff] [blame] | 40 | SUBSAMP_UNDEFINED = -1, |
| 41 | SUBSAMP_NONE = 0, |
| 42 | SUBSAMP_420, |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 43 | SUBSAMP_422, |
DRC | b4a8323 | 2011-08-19 04:57:18 +0000 | [diff] [blame] | 44 | SUBSAMP_GRAY |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | class JpegCompressor : public rdr::MemOutStream { |
| 48 | |
| 49 | public: |
| 50 | |
| 51 | JpegCompressor(int bufferLen = 128*1024); |
| 52 | virtual ~JpegCompressor(); |
| 53 | |
Pierre Ossman | 654e3f9 | 2012-01-30 13:53:11 +0000 | [diff] [blame] | 54 | void compress(const rdr::U8 *, int, const Rect&, const PixelFormat&, int, |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 55 | JPEG_SUBSAMP); |
| 56 | |
| 57 | void writeBytes(const void*, int); |
| 58 | |
| 59 | inline rdr::U8* getstart() { return start; } |
| 60 | |
| 61 | inline int overrun(int itemSize, int nItems) { |
| 62 | return MemOutStream::overrun(itemSize, nItems); |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | |
Pierre Ossman | 9144ae0 | 2011-09-07 11:35:04 +0000 | [diff] [blame] | 67 | struct jpeg_compress_struct *cinfo; |
| 68 | |
| 69 | struct JPEG_ERROR_MGR *err; |
| 70 | struct JPEG_DEST_MGR *dest; |
DRC | cd2c5d4 | 2011-08-11 11:18:34 +0000 | [diff] [blame] | 71 | |
| 72 | }; |
| 73 | |
| 74 | } // end of namespace rfb |
| 75 | |
| 76 | #endif |