Mercurial > hg > Applications > TightVNC_orginal
diff src/main/java/com/glavsoft/drawing/ColorDecoder.java @ 52:472a9bcacb21 draft default tip
TightVNC 2.7.1.0
author | you@cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 07 Aug 2013 19:01:17 +0900 |
parents | 4689cc86d6cb |
children |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/drawing/ColorDecoder.java Tue Jul 03 13:20:49 2012 +0900 +++ b/src/main/java/com/glavsoft/drawing/ColorDecoder.java Wed Aug 07 19:01:17 2013 +0900 @@ -1,4 +1,4 @@ -// Copyright (C) 2010, 2011 GlavSoft LLC. +// Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. // All rights reserved. // //------------------------------------------------------------------------- @@ -29,14 +29,15 @@ import com.glavsoft.transport.Reader; public class ColorDecoder { - protected byte redShift; + protected byte redShift; protected byte greenShift; protected byte blueShift; public short redMax; public short greenMax; public short blueMax; - private final int bytesPerPixel; - private final int bytesPerPixelSignificant; + public final int bytesPerPixel; + public final int bytesPerCPixel; + public final int bytesPerPixelTight; private final byte[] buff; private int startShift; @@ -44,7 +45,7 @@ private int addShiftItem; private final boolean isTightSpecific; - public ColorDecoder(PixelFormat pf) { + public ColorDecoder(PixelFormat pf) { redShift = pf.redShift; greenShift = pf.greenShift; blueShift = pf.blueShift; @@ -52,7 +53,14 @@ greenMax = pf.greenMax; blueMax = pf.blueMax; bytesPerPixel = pf.bitsPerPixel / 8; - bytesPerPixelSignificant = 24 == pf.depth && 32 == pf.bitsPerPixel ? 3 : bytesPerPixel; + final long significant = redMax << redShift | greenMax << greenShift | blueMax << blueShift; + bytesPerCPixel = pf.depth <= 24 // as in RFB +// || 32 == pf.depth) // UltraVNC use this... :( + && 32 == pf.bitsPerPixel + && ((significant & 0x00ff000000L) == 0 || (significant & 0x000000ffL) == 0) + ? 3 + : bytesPerPixel; + bytesPerPixelTight = 24 == pf.depth && 32 == pf.bitsPerPixel ? 3 : bytesPerPixel; buff = new byte[bytesPerPixel]; if (0 == pf.bigEndianFlag) { startShift = 0; @@ -63,7 +71,7 @@ startShiftCompact = Math.max(0, pf.depth - 8); addShiftItem = -8; } - isTightSpecific = 4==bytesPerPixel && 3==bytesPerPixelSignificant && + isTightSpecific = 4==bytesPerPixel && 3==bytesPerPixelTight && 255 == redMax && 255 == greenMax && 255 == blueMax; } @@ -72,11 +80,11 @@ } protected int readCompactColor(Reader reader) throws TransportException { - return getCompactColor(reader.readBytes(buff, 0, bytesPerPixelSignificant), 0); + return getCompactColor(reader.readBytes(buff, 0, bytesPerCPixel), 0); } protected int readTightColor(Reader reader) throws TransportException { - return getTightColor(reader.readBytes(buff, 0, bytesPerPixelSignificant), 0); + return getTightColor(reader.readBytes(buff, 0, bytesPerPixelTight), 0); } protected int convertColor(int rawColor) { @@ -92,7 +100,7 @@ comp[2] = (byte) (rawColor >> blueShift & blueMax); } - protected int getTightColor(byte[] bytes, int offset) { + public int getTightColor(byte[] bytes, int offset) { return convertColor(getRawTightColor(bytes, offset)); } @@ -100,7 +108,7 @@ if (isTightSpecific) return (bytes[offset++] & 0xff)<<16 | (bytes[offset++] & 0xff)<<8 | - bytes[offset++] & 0xff; + bytes[offset] & 0xff; else return getRawColor(bytes, offset); } @@ -123,7 +131,7 @@ int shift = startShiftCompact; int item = addShiftItem; int rawColor = (bytes[offset++] & 0xff)<<shift; - for (int i=1; i<bytesPerPixelSignificant; ++i) { + for (int i=1; i< bytesPerCPixel; ++i) { rawColor |= (bytes[offset++] & 0xff)<<(shift+=item); } return convertColor(rawColor);