2016-05-14 00:35:41 +00:00
|
|
|
#if __ORCAC__
|
|
|
|
#pragma lint -1
|
2015-09-24 00:40:17 +00:00
|
|
|
#pragma noroot
|
2016-05-14 02:44:12 +00:00
|
|
|
segment "VNCview GS";
|
2016-05-14 00:35:41 +00:00
|
|
|
#endif
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#include <window.h>
|
|
|
|
#include <quickdraw.h>
|
|
|
|
#include <qdaux.h>
|
|
|
|
#include <desk.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <resources.h>
|
|
|
|
#include <tcpip.h>
|
|
|
|
#include <menu.h>
|
|
|
|
#include <control.h>
|
|
|
|
#include <misctool.h>
|
|
|
|
#include <scrap.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <event.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "vncsession.h"
|
|
|
|
#include "vncview.h"
|
|
|
|
#include "vncdisplay.h"
|
|
|
|
#include "colortables.h"
|
2016-09-16 03:25:02 +00:00
|
|
|
#include "readtcp.h"
|
2015-09-24 00:40:17 +00:00
|
|
|
#include "hextile.h"
|
|
|
|
|
2016-05-14 00:35:41 +00:00
|
|
|
static unsigned int hexXTiles, hexYTiles; /* For in-process hextile processing */
|
|
|
|
static unsigned int hexXTileNum, hexYTileNum;
|
|
|
|
static unsigned int hexTileWidth, hexTileHeight;
|
|
|
|
static unsigned char hexBackground, hexForeground;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
static BOOLEAN extraByteAdvance;
|
|
|
|
|
|
|
|
/* Used in Hextile encoding */
|
2015-09-24 01:26:03 +00:00
|
|
|
#define Raw 0x01
|
|
|
|
#define BackgroundSpecified 0x02
|
|
|
|
#define ForegroundSpecified 0x04
|
|
|
|
#define AnySubrects 0x08
|
|
|
|
#define SubrectsColoured 0x10
|
|
|
|
|
|
|
|
#define hexWaitingForSubencoding 1
|
|
|
|
#define hexWaitingForMoreInfo 2
|
|
|
|
#define hexWaitingForSubrect 4
|
|
|
|
#define hexWaitingForRawData 8
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-05-14 00:35:41 +00:00
|
|
|
static void HexNextTile (void) {
|
2015-09-24 00:40:17 +00:00
|
|
|
hexXTileNum++;
|
|
|
|
if (hexXTileNum == hexXTiles) {
|
|
|
|
hexYTileNum++;
|
2015-09-24 01:26:03 +00:00
|
|
|
if (hexYTileNum == hexYTiles) { /* Done with this Hextile rect */
|
2015-09-24 00:40:17 +00:00
|
|
|
NextRect();
|
|
|
|
return;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
hexXTileNum = 0;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
hexTileWidth = (hexXTileNum == hexXTiles - 1) ?
|
2015-09-24 01:26:03 +00:00
|
|
|
rectWidth - 16 * (hexXTiles - 1) : 16;
|
2015-09-24 00:40:17 +00:00
|
|
|
hexTileHeight = (hexYTileNum == hexYTiles - 1) ?
|
2015-09-24 01:26:03 +00:00
|
|
|
rectHeight - 16 * (hexYTiles - 1) : 16;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2016-05-29 04:58:04 +00:00
|
|
|
static void HexRawDraw (Origin contentOrigin, int rectWidth, int rectHeight) {
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned int i, j; /* Loop indices */
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned int n = 0;
|
2015-09-24 01:26:03 +00:00
|
|
|
unsigned char *dataPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
unsigned char pixels[128];
|
|
|
|
|
|
|
|
static Rect srcRect = {0,0,0,0};
|
|
|
|
|
2016-09-16 02:40:39 +00:00
|
|
|
dataPtr = readBufferPtr;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
if ((hRez==640 && (rectWidth & 0x03)) || (hRez==320 && (rectWidth & 0x01)))
|
|
|
|
extraByteAdvance = TRUE;
|
|
|
|
else
|
|
|
|
extraByteAdvance = FALSE;
|
|
|
|
|
|
|
|
for (j = 0; j < rectHeight; j++) {
|
2015-09-24 01:26:03 +00:00
|
|
|
for (i = 0; i < rectWidth; i++) {
|
|
|
|
if (hRez == 640) {
|
|
|
|
switch (i & 0x03) {
|
|
|
|
case 0x00: /* pixels 0, 4, 8, ... */
|
|
|
|
pixels[n] = pixTransTbl[ *(dataPtr +
|
|
|
|
(unsigned long) j*rectWidth + i)
|
|
|
|
] & 0xC0;
|
|
|
|
break;
|
|
|
|
case 0x01: /* pixels 1, 5, 9, ... */
|
|
|
|
pixels[n] += pixTransTbl[ *(dataPtr +
|
|
|
|
(unsigned long) j*rectWidth + i)
|
|
|
|
] & 0x30;
|
|
|
|
break;
|
|
|
|
case 0x02: /* pixels 2, 6, 10, ... */
|
|
|
|
pixels[n] += pixTransTbl[ *(dataPtr +
|
|
|
|
(unsigned long) j*rectWidth + i)
|
|
|
|
] & 0x0C;
|
|
|
|
break;
|
|
|
|
case 0x03: /* pixels 3, 7, 11, ... */
|
|
|
|
pixels[n] += pixTransTbl[ *(dataPtr +
|
|
|
|
(unsigned long) j*rectWidth + i)
|
|
|
|
] & 0x03;
|
|
|
|
n++;
|
2015-09-24 01:56:33 +00:00
|
|
|
} /* switch */
|
|
|
|
} /* if */
|
2015-09-24 01:26:03 +00:00
|
|
|
else { /* 320 mode */
|
|
|
|
switch(i & 0x01) {
|
|
|
|
case 0x00: /* pixels 0, 2, 4, ... */
|
|
|
|
pixels[n] = pixTransTbl[ *(dataPtr +
|
|
|
|
(unsigned long) j*rectWidth + i)
|
|
|
|
] & 0xF0;
|
|
|
|
break;
|
|
|
|
case 0x01: /* pixels 1, 3, 5, ... */
|
|
|
|
pixels[n] += pixTransTbl[ *(dataPtr +
|
|
|
|
(unsigned long) j*rectWidth + i)
|
|
|
|
] & 0x0F;
|
|
|
|
n++;
|
2015-09-24 01:56:33 +00:00
|
|
|
} /* switch */
|
|
|
|
} /* else */
|
|
|
|
} /* i loop */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
/* When not ending a line on a byte boundary, the index isn't updated,
|
|
|
|
* so we do it here.
|
|
|
|
*/
|
|
|
|
if (extraByteAdvance)
|
|
|
|
n++;
|
2015-09-24 01:56:33 +00:00
|
|
|
} /* j loop */
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
srcLocInfo.ptrToPixImage = (void *) pixels;
|
|
|
|
srcLocInfo.boundsRect.v2 = rectHeight;
|
|
|
|
/* Since the lines are rounded up to integral numbers of bytes, this
|
|
|
|
* padding must be accounted for here.
|
|
|
|
*/
|
|
|
|
if (hRez == 640) {
|
2015-09-24 01:26:03 +00:00
|
|
|
switch (rectWidth & 0x03) {
|
|
|
|
case 0x00: srcLocInfo.boundsRect.h2 = rectWidth;
|
|
|
|
srcLocInfo.width = rectWidth/4; break;
|
|
|
|
case 0x01: srcLocInfo.boundsRect.h2 = rectWidth+3;
|
|
|
|
srcLocInfo.width = rectWidth/4 + 1; break;
|
|
|
|
case 0x02: srcLocInfo.boundsRect.h2 = rectWidth+2;
|
|
|
|
srcLocInfo.width = rectWidth/4 + 1; break;
|
|
|
|
case 0x03: srcLocInfo.boundsRect.h2 = rectWidth+1;
|
|
|
|
srcLocInfo.width = rectWidth/4 + 1;
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
else { /* hRez == 320 */
|
2015-09-24 01:26:03 +00:00
|
|
|
switch (rectWidth & 0x01) {
|
|
|
|
case 0x00: srcLocInfo.boundsRect.h2 = rectWidth;
|
|
|
|
srcLocInfo.width = rectWidth/2; break;
|
|
|
|
case 0x01: srcLocInfo.boundsRect.h2 = rectWidth+1;
|
|
|
|
srcLocInfo.width = rectWidth/2 + 1;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
srcRect.v2 = hexTileHeight;
|
|
|
|
srcRect.h2 = hexTileWidth;
|
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
PPToPort(&srcLocInfo, &srcRect,
|
2016-05-29 04:58:04 +00:00
|
|
|
rectX + hexXTileNum * 16 - contentOrigin.pt.h,
|
|
|
|
rectY + hexYTileNum * 16 - contentOrigin.pt.v, modeCopy);
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The macros below are used in HexDispatch() */
|
2015-09-24 01:26:03 +00:00
|
|
|
#define HexDispatch_NextTile() do { \
|
2015-09-24 00:40:17 +00:00
|
|
|
HexNextTile(); \
|
2016-05-29 02:59:35 +00:00
|
|
|
DoneWithReadBuffer(); \
|
2015-09-24 00:40:17 +00:00
|
|
|
/* Set up for next time */ \
|
|
|
|
status = hexWaitingForSubencoding; \
|
|
|
|
bytesNeeded = 1; \
|
2015-09-24 01:26:03 +00:00
|
|
|
return; \
|
2015-09-24 01:56:33 +00:00
|
|
|
} while (0)
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
#define HexDispatch_DrawRect(color, X, Y, width, height) do { \
|
|
|
|
SetSolidPenPat((color)); \
|
2016-05-29 04:58:04 +00:00
|
|
|
drawingRect.h1 = rectX + hexXTileNum * 16 + (X) - contentOrigin.pt.h; \
|
|
|
|
drawingRect.v1 = rectY + hexYTileNum * 16 + (Y) - contentOrigin.pt.v; \
|
|
|
|
drawingRect.h2 = rectX + hexXTileNum * 16 + (X) + (width) - contentOrigin.pt.h; \
|
|
|
|
drawingRect.v2 = rectY + hexYTileNum * 16 + (Y) + (height) - contentOrigin.pt.v; \
|
2015-09-24 00:40:17 +00:00
|
|
|
PaintRect(&drawingRect); \
|
2015-09-24 01:56:33 +00:00
|
|
|
} while (0)
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
#define HexDispatch_DrawBackground() \
|
2015-09-24 01:26:03 +00:00
|
|
|
HexDispatch_DrawRect(hexBackground, 0, 0, hexTileWidth, hexTileHeight)
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
void HexDispatch (void) {
|
2015-09-24 01:26:03 +00:00
|
|
|
static unsigned char status = hexWaitingForSubencoding;
|
2015-09-24 00:40:17 +00:00
|
|
|
static unsigned long bytesNeeded = 1;
|
|
|
|
static unsigned char subencoding;
|
|
|
|
static unsigned int numSubrects;
|
|
|
|
int i;
|
|
|
|
/* For use with GetContentOrigin() */
|
2016-05-29 04:58:04 +00:00
|
|
|
Origin contentOrigin;
|
2015-09-24 00:40:17 +00:00
|
|
|
int tileBytes;
|
|
|
|
unsigned int srX, srY, srWidth, srHeight;
|
|
|
|
Rect drawingRect;
|
|
|
|
static unsigned char pixels[128];
|
|
|
|
unsigned char *dataPtr;
|
|
|
|
|
2016-05-29 04:58:04 +00:00
|
|
|
contentOrigin.l = GetContentOrigin(vncWindow);
|
2015-09-24 00:40:17 +00:00
|
|
|
SetPort(vncWindow);
|
|
|
|
|
|
|
|
/* If we don't have the next bit of needed data yet, return. */
|
|
|
|
while (DoReadTCP(bytesNeeded)) {
|
2016-09-16 02:40:39 +00:00
|
|
|
dataPtr = readBufferPtr;
|
|
|
|
/* If we're here, readBufferPtr contains bytesNeeded bytes of data. */
|
2015-09-24 01:26:03 +00:00
|
|
|
switch (status) {
|
|
|
|
case hexWaitingForSubencoding:
|
2015-09-24 00:40:17 +00:00
|
|
|
subencoding = *dataPtr;
|
2015-09-24 01:26:03 +00:00
|
|
|
if (subencoding & Raw) {
|
|
|
|
bytesNeeded = hexTileWidth * hexTileHeight;
|
2015-09-24 00:40:17 +00:00
|
|
|
status = hexWaitingForRawData;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else {
|
|
|
|
bytesNeeded = 0;
|
|
|
|
if (subencoding & BackgroundSpecified)
|
|
|
|
bytesNeeded++;
|
|
|
|
if (subencoding & ForegroundSpecified)
|
|
|
|
bytesNeeded++;
|
|
|
|
if (subencoding & AnySubrects)
|
|
|
|
bytesNeeded++;
|
|
|
|
else if (bytesNeeded == 0) {
|
|
|
|
/* No more data - just draw background */
|
2015-09-24 00:40:17 +00:00
|
|
|
HexDispatch_DrawBackground();
|
2015-09-24 01:26:03 +00:00
|
|
|
HexDispatch_NextTile();
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
status = hexWaitingForMoreInfo;
|
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
break;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
case hexWaitingForRawData:
|
2016-05-29 04:58:04 +00:00
|
|
|
HexRawDraw(contentOrigin, hexTileWidth, hexTileHeight);
|
2015-09-24 00:40:17 +00:00
|
|
|
HexDispatch_NextTile();
|
2015-09-24 01:26:03 +00:00
|
|
|
break;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
case hexWaitingForMoreInfo:
|
2015-09-24 01:26:03 +00:00
|
|
|
if (subencoding & BackgroundSpecified) {
|
|
|
|
hexBackground = pixTransTbl[*(dataPtr++)];
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
if (subencoding & ForegroundSpecified) {
|
2015-09-24 00:40:17 +00:00
|
|
|
hexForeground = pixTransTbl[*(dataPtr++)];
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
if (subencoding & AnySubrects) {
|
|
|
|
numSubrects = *dataPtr;
|
|
|
|
if (numSubrects) {
|
|
|
|
status = hexWaitingForSubrect;
|
|
|
|
bytesNeeded = numSubrects * ((subencoding & SubrectsColoured) ? 3 : 2);
|
|
|
|
break;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else
|
|
|
|
HexDispatch_NextTile();
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
else { /* no subrects */
|
|
|
|
HexDispatch_DrawBackground();
|
2015-09-24 00:40:17 +00:00
|
|
|
HexDispatch_NextTile();
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
2015-09-24 01:26:03 +00:00
|
|
|
case hexWaitingForSubrect: {
|
|
|
|
HexDispatch_DrawBackground();
|
2015-09-24 00:40:17 +00:00
|
|
|
while (numSubrects-- > 0) {
|
2015-09-24 01:26:03 +00:00
|
|
|
if (subencoding & SubrectsColoured) {
|
|
|
|
hexForeground = pixTransTbl[*(dataPtr++)];
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
srX = *dataPtr >> 4;
|
|
|
|
srY = *(dataPtr++) & 0x0F;
|
|
|
|
srWidth = (*dataPtr >> 4) + 1;
|
|
|
|
srHeight = (*(dataPtr++) & 0x0F) + 1;
|
|
|
|
HexDispatch_DrawRect(hexForeground, srX, srY, srWidth, srHeight);
|
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
HexDispatch_NextTile();
|
2015-09-24 01:26:03 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
}
|
2015-09-24 01:26:03 +00:00
|
|
|
}
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Called when we initially get a Hextile rect; set up to process it */
|
|
|
|
void DoHextileRect (void) {
|
2015-09-24 01:26:03 +00:00
|
|
|
hexXTiles = (rectWidth + 15) / 16;
|
2015-09-24 00:40:17 +00:00
|
|
|
hexYTiles = (rectHeight + 15) / 16;
|
|
|
|
|
|
|
|
hexXTileNum = 0;
|
|
|
|
hexYTileNum = 0;
|
|
|
|
|
|
|
|
displayInProgress = TRUE;
|
2015-09-24 01:26:03 +00:00
|
|
|
|
2015-09-24 00:40:17 +00:00
|
|
|
hexTileWidth = (hexYTileNum == hexXTiles - 1) ?
|
2015-09-24 01:26:03 +00:00
|
|
|
rectWidth - 16 * (hexXTiles - 1) : 16;
|
2015-09-24 00:40:17 +00:00
|
|
|
hexTileHeight = (hexYTileNum == hexYTiles - 1) ?
|
2015-09-24 01:26:03 +00:00
|
|
|
rectHeight - 16 * (hexYTiles - 1) : 16;
|
2015-09-24 00:40:17 +00:00
|
|
|
|
|
|
|
/* Set up for Hextile drawing */
|
|
|
|
srcRect.v1 = 0;
|
|
|
|
srcRect.h1 = 0;
|
2015-09-24 01:56:33 +00:00
|
|
|
}
|