/* 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
supportsContinuousUpdates(false),
customCompressLevel(false), compressLevel(2),
noJpeg(false), qualityLevel(-1), fineQualityLevel(-1),
- subsampling(SUBSAMP_UNDEFINED), name_(0),
+ subsampling(subsampleUndefined), name_(0),
currentEncoding_(encodingRaw), verStrPos(0)
{
setName("");
noJpeg = true;
qualityLevel = -1;
fineQualityLevel = -1;
- subsampling = SUBSAMP_UNDEFINED;
+ subsampling = subsampleUndefined;
currentEncoding_ = encodingRaw;
for (int i = nEncodings-1; i >= 0; i--) {
noJpeg = false;
fineQualityLevel = encodings[i] - pseudoEncodingFineQualityLevel0;
} else if (encodings[i] >= pseudoEncodingSubsamp1X &&
- encodings[i] <= pseudoEncodingSubsampGray) {
+ encodings[i] <= pseudoEncodingSubsamp16X) {
noJpeg = false;
- subsampling = (JPEG_SUBSAMP)(encodings[i] - pseudoEncodingSubsamp1X);
+ switch (encodings[i]) {
+ case pseudoEncodingSubsamp1X:
+ subsampling = subsampleNone;
+ break;
+ case pseudoEncodingSubsampGray:
+ subsampling = subsampleGray;
+ break;
+ case pseudoEncodingSubsamp2X:
+ subsampling = subsample2X;
+ break;
+ case pseudoEncodingSubsamp4X:
+ subsampling = subsample4X;
+ break;
+ case pseudoEncodingSubsamp8X:
+ subsampling = subsample8X;
+ break;
+ case pseudoEncodingSubsamp16X:
+ subsampling = subsample16X;
+ break;
+ }
}
}
}
// 0 = JPEG quality 15, 4:2:0 subsampling (ratio ~= 100:1)
const TIGHT_CONF TightEncoder::conf[10] = {
- { 65536, 2048, 6, 0, 0, 0, 4, 24, 15, SUBSAMP_420 }, // 0
- { 65536, 2048, 6, 1, 1, 1, 8, 24, 29, SUBSAMP_420 }, // 1
- { 65536, 2048, 8, 3, 3, 2, 24, 96, 41, SUBSAMP_420 }, // 2
- { 65536, 2048, 12, 5, 5, 2, 32, 96, 42, SUBSAMP_422 }, // 3
- { 65536, 2048, 12, 6, 7, 3, 32, 96, 62, SUBSAMP_422 }, // 4
- { 65536, 2048, 12, 7, 8, 4, 32, 96, 77, SUBSAMP_422 }, // 5
- { 65536, 2048, 16, 7, 8, 5, 32, 96, 79, SUBSAMP_NONE }, // 6
- { 65536, 2048, 16, 8, 9, 6, 64, 96, 86, SUBSAMP_NONE }, // 7
- { 65536, 2048, 24, 9, 9, 7, 64, 96, 92, SUBSAMP_NONE }, // 8
- { 65536, 2048, 32, 9, 9, 9, 96, 96,100, SUBSAMP_NONE } // 9
+ { 65536, 2048, 6, 0, 0, 0, 4, 24, 15, subsample4X }, // 0
+ { 65536, 2048, 6, 1, 1, 1, 8, 24, 29, subsample4X }, // 1
+ { 65536, 2048, 8, 3, 3, 2, 24, 96, 41, subsample4X }, // 2
+ { 65536, 2048, 12, 5, 5, 2, 32, 96, 42, subsample2X }, // 3
+ { 65536, 2048, 12, 6, 7, 3, 32, 96, 62, subsample2X }, // 4
+ { 65536, 2048, 12, 7, 8, 4, 32, 96, 77, subsample2X }, // 5
+ { 65536, 2048, 16, 7, 8, 5, 32, 96, 79, subsampleNone }, // 6
+ { 65536, 2048, 16, 8, 9, 6, 64, 96, 86, subsampleNone }, // 7
+ { 65536, 2048, 24, 9, 9, 7, 64, 96, 92, subsampleNone }, // 8
+ { 65536, 2048, 32, 9, 9, 9, 96, 96,100, subsampleNone } // 9
};
const int TightEncoder::defaultCompressLevel = 2;
jpegSubsampling = conf[level].jpegSubsampling;
} else {
jpegQuality = -1;
- jpegSubsampling = SUBSAMP_UNDEFINED;
+ jpegSubsampling = subsampleUndefined;
}
}
-void TightEncoder::setFineQualityLevel(int quality, JPEG_SUBSAMP subsampling)
+void TightEncoder::setFineQualityLevel(int quality, int subsampling)
{
- if (quality >= 1 && quality <= 100) {
- jpegQuality = quality;
- }
- if (subsampling >= SUBSAMP_NONE && subsampling <= SUBSAMP_GRAY) {
- jpegSubsampling = subsampling;
- }
+ jpegQuality = quality;
+ jpegSubsampling = subsampling;
}
bool TightEncoder::checkSolidTile(Rect& r, rdr::U32* colorPtr,
sr.setXYWH(dx, dy, dw, dh);
if (checkSolidTile(sr, &colorValue, false)) {
- if (jpegSubsampling == SUBSAMP_GRAY && jpegQuality != -1) {
+ if (jpegSubsampling == subsampleGray && jpegQuality != -1) {
Colour rgb;
serverpf.rgbFromPixel(colorValue, NULL, &rgb);
rdr::U32 lum = ((257 * rgb.r) + (504 * rgb.g) + (98 * rgb.b)