Remove full support for colour maps

Gets rid of a loooot of code and complexity.

Colour map clients are still supported through an
automatically generated map, but we lose the ability to
develop a client or server that uses colour maps
internally.
diff --git a/win/rfb_win32/DIBSectionBuffer.cxx b/win/rfb_win32/DIBSectionBuffer.cxx
index 0c266b0..e2b0d64 100644
--- a/win/rfb_win32/DIBSectionBuffer.cxx
+++ b/win/rfb_win32/DIBSectionBuffer.cxx
@@ -31,13 +31,11 @@
 DIBSectionBuffer::DIBSectionBuffer(HWND window_)
   : bitmap(0), window(window_), device(0) {
   memset(&format, 0, sizeof(format));
-  memset(palette, 0, sizeof(palette));
 }
 
 DIBSectionBuffer::DIBSectionBuffer(HDC device_)
   : bitmap(0), window(0), device(device_) {
   memset(&format, 0, sizeof(format));
-  memset(palette, 0, sizeof(palette));
 }
 
 DIBSectionBuffer::~DIBSectionBuffer() {
@@ -51,19 +49,10 @@
     vlog.debug("pixel format unchanged by setPF()");
     return;
   }
+  if (!pf.trueColour)
+    throw rfb::Exception("palette format not supported");
   format = pf;
   recreateBuffer();
-  if ((pf.bpp <= 8) && pf.trueColour) {
-    vlog.info("creating %d-bit TrueColour palette", pf.depth);
-    for (int i=0; i < (1<<(pf.depth)); i++) {
-      rdr::U16 r, g, b;
-      pf.rgbFromPixel(i, NULL, &r, &g, &b);
-      palette[i].r = r;
-      palette[i].g = g;
-      palette[i].b = b;
-    }
-    refreshPalette();
-  }
 }
 
 void DIBSectionBuffer::setSize(int w, int h) {
@@ -77,20 +66,6 @@
 }
 
 
-// * copyPaletteToDIB MUST NEVER be called on a truecolour DIB! *
-
-void copyPaletteToDIB(Colour palette[256], HDC wndDC, HBITMAP dib) {
-  BitmapDC dibDC(wndDC, dib);
-  RGBQUAD rgb[256];
-  for (unsigned int i=0;i<256;i++) {
-    rgb[i].rgbRed = palette[i].r >> 8;
-    rgb[i].rgbGreen = palette[i].g >> 8;
-    rgb[i].rgbBlue = palette[i].b >> 8;
-  }
-  if (!SetDIBColorTable(dibDC, 0, 256, (RGBQUAD*) rgb))
-    throw rdr::SystemException("unable to SetDIBColorTable", GetLastError());
-}
-
 inline void initMaxAndShift(DWORD mask, int* max, int* shift) {
   for ((*shift) = 0; (mask & 1) == 0; (*shift)++) mask >>= 1;
   (*max) = (rdr::U16)mask;
@@ -103,9 +78,7 @@
   if (width_ && height_ && (format.depth != 0)) {
     BitmapInfo bi;
     memset(&bi, 0, sizeof(bi));
-    // *** wrong?
-    UINT iUsage = format.trueColour ? DIB_RGB_COLORS : DIB_PAL_COLORS;
-    // ***
+    UINT iUsage = DIB_RGB_COLORS;
     bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
     bi.bmiHeader.biBitCount = format.bpp;
     bi.bmiHeader.biSizeImage = (format.bpp / 8) * width_ * height_;
@@ -140,15 +113,11 @@
 
     // Copy the contents across
     if (device) {
-      if (format.bpp <= 8)
-        copyPaletteToDIB(palette, device, new_bitmap);
       BitmapDC src_dev(device, bitmap);
       BitmapDC dest_dev(device, new_bitmap);
       BitBlt(dest_dev, 0, 0, width_, height_, src_dev, 0, 0, SRCCOPY);
     } else {
       WindowDC wndDC(window);
-      if (format.bpp <= 8)
-        copyPaletteToDIB(palette, wndDC, new_bitmap);
       BitmapDC src_dev(wndDC, bitmap);
       BitmapDC dest_dev(wndDC, new_bitmap);
       BitBlt(dest_dev, 0, 0, width_, height_, src_dev, 0, 0, SRCCOPY);
@@ -164,7 +133,6 @@
 
   if (new_bitmap) {
     int bpp, depth;
-    bool trueColour;
     int redMax, greenMax, blueMax;
     int redShift, greenShift, blueShift;
 
@@ -189,46 +157,24 @@
 
     // Calculate the PixelFormat for the DIB
     bpp = depth = ds.dsBm.bmBitsPixel;
-    trueColour = format.trueColour || format.bpp > 8;
 
-    if (trueColour) {
-      // Get the truecolour format used by the DIBSection
-      initMaxAndShift(ds.dsBitfields[0], &redMax, &redShift);
-      initMaxAndShift(ds.dsBitfields[1], &greenMax, &greenShift);
-      initMaxAndShift(ds.dsBitfields[2], &blueMax, &blueShift);
+    // Get the truecolour format used by the DIBSection
+    initMaxAndShift(ds.dsBitfields[0], &redMax, &redShift);
+    initMaxAndShift(ds.dsBitfields[1], &greenMax, &greenShift);
+    initMaxAndShift(ds.dsBitfields[2], &blueMax, &blueShift);
 
-      // Calculate the effective depth
-      depth = 0;
-      Pixel bits = ds.dsBitfields[0] | ds.dsBitfields[1] | ds.dsBitfields[2];
-      while (bits) {
-        depth++;
-        bits = bits >> 1;
-      }
-      if (depth > bpp)
-        throw Exception("Bad DIBSection format (depth exceeds bpp)");
+    // Calculate the effective depth
+    depth = 0;
+    Pixel bits = ds.dsBitfields[0] | ds.dsBitfields[1] | ds.dsBitfields[2];
+    while (bits) {
+      depth++;
+      bits = bits >> 1;
     }
+    if (depth > bpp)
+      throw Exception("Bad DIBSection format (depth exceeds bpp)");
 
-    format = PixelFormat(bpp, depth, false, trueColour,
+    format = PixelFormat(bpp, depth, false, true,
                          redMax, greenMax, blueMax,
                          redShift, greenShift, blueShift);
-
-    if (!trueColour) {
-      // Set the DIBSection's palette
-      refreshPalette();
-    }
   }
 }
-
-void DIBSectionBuffer::refreshPalette() {
-  if (format.bpp > 8) {
-    vlog.error("refresh palette called for truecolor DIB");
-    return;
-  }
-  vlog.debug("refreshing palette");
-  if (device)
-    copyPaletteToDIB(palette, device, bitmap);
-  else
-    copyPaletteToDIB(palette, WindowDC(window), bitmap);
-}
-
-
diff --git a/win/rfb_win32/DIBSectionBuffer.h b/win/rfb_win32/DIBSectionBuffer.h
index ad1a310..1a9ef13 100644
--- a/win/rfb_win32/DIBSectionBuffer.h
+++ b/win/rfb_win32/DIBSectionBuffer.h
@@ -28,7 +28,6 @@
 #include <windows.h>
 #include <rfb/PixelBuffer.h>
 #include <rfb/Region.h>
-#include <rfb/ColourMap.h>
 #include <rfb/Exception.h>
 
 namespace rfb {
@@ -39,7 +38,7 @@
     // -=- DIBSectionBuffer
     //
 
-    class DIBSectionBuffer : public FullFramePixelBuffer, ColourMap {
+    class DIBSectionBuffer : public FullFramePixelBuffer {
     public:
       DIBSectionBuffer(HWND window);
       DIBSectionBuffer(HDC device);
@@ -50,29 +49,11 @@
 
       virtual int getStride() const {return stride;}
 
-      virtual ColourMap* getColourMap() const {return (ColourMap*)this;}
-
-      // - ColourMap interface
-      virtual void lookup(int index, int* r, int *g, int* b) {
-        *r = palette[index].r;
-        *g = palette[index].g;
-        *b = palette[index].b;
-      }
-  
-      // Custom colourmap interface
-      void setColour(int index, int r, int g, int b) {
-        palette[index].r = r;
-        palette[index].g = g;
-        palette[index].b = b;
-      }
-      void refreshPalette();
-
       // *** virtual void copyRect(const Rect &dest, const Point &move_by_delta);
     public:
       HBITMAP bitmap;
     protected:
       void recreateBuffer();
-      Colour palette[256];
       int stride;
       HWND window;
       HDC device;
diff --git a/win/rfb_win32/DeviceFrameBuffer.cxx b/win/rfb_win32/DeviceFrameBuffer.cxx
index cc9bbca..33b1be5 100644
--- a/win/rfb_win32/DeviceFrameBuffer.cxx
+++ b/win/rfb_win32/DeviceFrameBuffer.cxx
@@ -79,10 +79,6 @@
 
   // Configure the cursor buffer
   cursorBm.setPF(format);
-
-  // Set up a palette if required
-  if (!format.trueColour)
-    updateColourMap();
 }
 
 DeviceFrameBuffer::~DeviceFrameBuffer() {
@@ -134,37 +130,6 @@
 }
 
 
-void copyDevicePaletteToDIB(HDC dc, DIBSectionBuffer* dib) {
-  // - Fetch the system palette for the framebuffer
-  PALETTEENTRY syspalette[256];
-  UINT entries = ::GetSystemPaletteEntries(dc, 0, 256, syspalette);
-
-  if (entries == 0) {
-    vlog.info("resorting to standard 16 color palette");
-    for (unsigned int i=0;i<256;i++) {
-      int v = (i%16) >= 8 ? 127 : 255;
-      syspalette[i].peRed = i & 1 ? v : 0;
-      syspalette[i].peGreen = i & 2 ? v : 0;
-      syspalette[i].peBlue = i & 4 ? v : 0;
-    }
-  } else {
-    vlog.info("framebuffer has %u palette entries", entries);
-  }
-
-  // - Update the bitmap's stored copy of the palette
-  for (unsigned int i=0;i<256;i++) {
-    int r, g, b;
-    r = (syspalette[i].peRed << 8) + 0x80;
-    g = (syspalette[i].peGreen << 8) + 0x80;
-    b = (syspalette[i].peBlue << 8) + 0x80;
-    dib->setColour(i, r, g, b);
-  }
-
-  // - Update the DIB section to use the palette
-  dib->refreshPalette();
-}
-
-
 void DeviceFrameBuffer::setCursor(HCURSOR hCursor, VNCServer* server)
 {
   // - If hCursor is null then there is no cursor - clear the old one
@@ -211,10 +176,6 @@
     // Configure the cursor bitmap
     cursorBm.setSize(cursor.width(), cursor.height());
 
-    // Copy the palette into it if required
-    if (format.bpp <= 8)
-      copyDevicePaletteToDIB(device, &cursorBm);
-
     // Draw the cursor into the bitmap
     BitmapDC dc(device, cursorBm.bitmap);
     if (!DrawIconEx(dc, 0, 0, hCursor, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT))
@@ -231,7 +192,7 @@
 
     bool doOutline = false;
     if (!iconInfo.hbmColor) {
-      Pixel xorColour = format.pixelFromRGB((rdr::U16)0, (rdr::U16)0, (rdr::U16)0, cursorBm.getColourMap());
+      Pixel xorColour = format.pixelFromRGB((rdr::U16)0, (rdr::U16)0, (rdr::U16)0);
       for (int y = 0; y < cursor.height(); y++) {
         for (int x = 0; x < cursor.width(); x++) {
           int byte = y * maskInfo.bmWidthBytes + x / 8;
@@ -269,7 +230,7 @@
     if (doOutline) {
       vlog.debug("drawing cursor outline!");
       memcpy(cursor.data, cursorBm.data, cursor.dataLen());
-      cursor.drawOutline(format.pixelFromRGB((rdr::U16)0xffff, (rdr::U16)0xffff, (rdr::U16)0xffff, cursorBm.getColourMap()));
+      cursor.drawOutline(format.pixelFromRGB((rdr::U16)0xffff, (rdr::U16)0xffff, (rdr::U16)0xffff));
       memcpy(cursorBm.data, cursor.data, cursor.dataLen());
     }
 
@@ -279,10 +240,3 @@
     vlog.error("%s", e.str());
   }
 }
-
-
-void
-DeviceFrameBuffer::updateColourMap() {
-  if (!format.trueColour)
-    copyDevicePaletteToDIB(device, this);
-}
diff --git a/win/rfb_win32/DeviceFrameBuffer.h b/win/rfb_win32/DeviceFrameBuffer.h
index 7718c33..8e280f8 100644
--- a/win/rfb_win32/DeviceFrameBuffer.h
+++ b/win/rfb_win32/DeviceFrameBuffer.h
@@ -79,7 +79,6 @@
       // - DeviceFrameBuffer specific methods
 
       void setCursor(HCURSOR c, VNCServer* server);
-      void updateColourMap();
 
       // Set whether grabRect should ignore errors or throw exceptions
       // Only set this if you are sure you'll capture the errors some other way!
diff --git a/win/rfb_win32/SDisplay.cxx b/win/rfb_win32/SDisplay.cxx
index 6d0c924..26a7bbc 100644
--- a/win/rfb_win32/SDisplay.cxx
+++ b/win/rfb_win32/SDisplay.cxx
@@ -350,12 +350,6 @@
     vlog.debug("desktop format changed");
     recreatePixelBuffer();
     break;
-  case WMMonitor::Notifier::DisplayColourMapChanged:
-    vlog.debug("desktop colormap changed");
-    pb->updateColourMap();
-    if (server)
-      server->setColourMapEntries();
-    break;
   default:
     vlog.error("unknown display event received");
   }
diff --git a/win/rfb_win32/WMNotifier.cxx b/win/rfb_win32/WMNotifier.cxx
index 20a5445..159daca 100644
--- a/win/rfb_win32/WMNotifier.cxx
+++ b/win/rfb_win32/WMNotifier.cxx
@@ -46,12 +46,6 @@
       notifier->notifyDisplayEvent(Notifier::DisplayPixelFormatChanged);
     }
     break;
-	case WM_SYSCOLORCHANGE:
-  case WM_PALETTECHANGED:
-    if (notifier) {
-      notifier->notifyDisplayEvent(Notifier::DisplayColourMapChanged);
-    }
-    break;
   };
   return MsgWindow::processMessage(msg, wParam, lParam);
 }
diff --git a/win/rfb_win32/WMNotifier.h b/win/rfb_win32/WMNotifier.h
index a760964..ada45d0 100644
--- a/win/rfb_win32/WMNotifier.h
+++ b/win/rfb_win32/WMNotifier.h
@@ -44,7 +44,7 @@
 
       class Notifier {
       public:
-        typedef enum {DisplaySizeChanged, DisplayColourMapChanged,
+        typedef enum {DisplaySizeChanged,
           DisplayPixelFormatChanged} DisplayEventType;
         virtual void notifyDisplayEvent(DisplayEventType evt) = 0;
       };