summaryrefslogtreecommitdiffstats
path: root/common/rfb/JpegCompressor.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/rfb/JpegCompressor.cxx')
-rw-r--r--common/rfb/JpegCompressor.cxx51
1 files changed, 24 insertions, 27 deletions
diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx
index c1ef3c7d..960bd378 100644
--- a/common/rfb/JpegCompressor.cxx
+++ b/common/rfb/JpegCompressor.cxx
@@ -1,5 +1,6 @@
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright (C) 2011 D. R. Commander. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -33,6 +34,15 @@ extern "C" {
using namespace rfb;
//
+// Special formats that libjpeg can have optimised code paths for
+//
+
+static const PixelFormat pfRGBX(32, 24, false, true, 255, 255, 255, 0, 8, 16);
+static const PixelFormat pfBGRX(32, 24, false, true, 255, 255, 255, 16, 8, 0);
+static const PixelFormat pfXRGB(32, 24, false, true, 255, 255, 255, 8, 16, 24);
+static const PixelFormat pfXBGR(32, 24, false, true, 255, 255, 255, 24, 16, 8);
+
+//
// Error manager implmentation for the JPEG library
//
@@ -166,33 +176,20 @@ void JpegCompressor::compress(const rdr::U8 *buf, int stride, const Rect& r,
pixelsize = 3;
#ifdef JCS_EXTENSIONS
- // Try to have libjpeg read directly from our native format
- if(pf.is888()) {
- int redShift, greenShift, blueShift;
-
- if(pf.bigEndian) {
- redShift = 24 - pf.redShift;
- greenShift = 24 - pf.greenShift;
- blueShift = 24 - pf.blueShift;
- } else {
- redShift = pf.redShift;
- greenShift = pf.greenShift;
- blueShift = pf.blueShift;
- }
-
- if(redShift == 0 && greenShift == 8 && blueShift == 16)
- cinfo->in_color_space = JCS_EXT_RGBX;
- if(redShift == 16 && greenShift == 8 && blueShift == 0)
- cinfo->in_color_space = JCS_EXT_BGRX;
- if(redShift == 24 && greenShift == 16 && blueShift == 8)
- cinfo->in_color_space = JCS_EXT_XBGR;
- if(redShift == 8 && greenShift == 16 && blueShift == 24)
- cinfo->in_color_space = JCS_EXT_XRGB;
-
- if (cinfo->in_color_space != JCS_RGB) {
- srcBuf = (rdr::U8 *)buf;
- pixelsize = 4;
- }
+ // Try to have libjpeg output directly to our native format
+ // libjpeg can only handle some "standard" formats
+ if (pfRGBX.equal(pf))
+ cinfo->in_color_space = JCS_EXT_RGBX;
+ else if (pfBGRX.equal(pf))
+ cinfo->in_color_space = JCS_EXT_BGRX;
+ else if (pfXRGB.equal(pf))
+ cinfo->in_color_space = JCS_EXT_XRGB;
+ else if (pfXBGR.equal(pf))
+ cinfo->in_color_space = JCS_EXT_XBGR;
+
+ if (cinfo->in_color_space != JCS_RGB) {
+ srcBuf = (rdr::U8 *)buf;
+ pixelsize = 4;
}
#endif