bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fast drawMechanism for 8-bit PseudoColor


From: Paul Secchia
Subject: Fast drawMechanism for 8-bit PseudoColor
Date: Wed, 11 Aug 2004 15:26:35 -0400

2004-08-11 14:25:40.132 Converter[1011] WARNING - XGServer is unable to
use a fast algorithm for writing to the display on this host - perhaps
you'd like to adjust the code to work ... and submit a patch.

So here's a patch.

Three files need to be patched relative to gnustep-back-0.9.0:
    Headers/x11/XGServer.h
    Source/x11/XGServer.m
    Source/xlib/XGBitmap.m

A patchfile is attached.

Also, a utility to install StandardColormaps RGB_DEFAULT_MAP and
RGB_BEST_MAP is included.
RGB_BEST_MAP is needed to enable the drawMechanism.
1 source file stdcmaps.c and a GNU style makefile comprise the utility.
The utility should be run before launching any GNUstep application,
preferably in the session startup script.

The source file and the makefile are attached.

*** Headers/x11/XGServer.0.h    Thu Jul 31 19:57:10 2003
--- Headers/x11/XGServer.h      Tue Aug 10 15:11:27 2004
***************
*** 42,47 ****
--- 42,48 ----
    XGDM_FAST16,
    XGDM_FAST32,
    XGDM_FAST32_BGR,
+   XGDM_FAST8,
    XGDM_PORTABLE
  } XGDrawMechanism;
  
*** Source/x11/XGServer.0.m     Sat Aug  2 07:35:47 2003
--- Source/x11/XGServer.m       Tue Aug 10 15:27:21 2004
***************
*** 241,246 ****
--- 241,265 ----
          drawMechanism = XGDM_PORTABLE;
        }
      }
+   else if (rcontext->depth == 8)
+     {
+       drawMechanism = XGDM_FAST8;
+       r = 2;
+       g = 3;
+       b = 1;
+       testColor.pixel = (((r << 3) + g) << 2) + b;
+       XQueryColor(rcontext->dpy, rcontext->cmap, &testColor);
+       if (((testColor.red >> 13) != r)
+       || ((testColor.green >> 13) != g)
+       || ((testColor.blue >> 14) != b))
+       {
+         NSLog(@"WARNING - XGServer is unable to use the "
+           @"fast algorithm for writing to an 8-bit display on "
+           @"this host - the most likely reason being "
+           @"the StandardColormap RGB_BEST_MAP has not been installed.");
+         drawMechanism = XGDM_PORTABLE;
+       }
+     }
    else
      {
        NSLog(@"WARNING - XGServer is unable to use a "
*** Source/xlib/XGBitmap.0.m    Sat Sep 20 23:19:17 2003
--- Source/xlib/XGBitmap.m      Tue Aug 10 15:18:52 2004
***************
*** 119,125 ****
    if (drawMechanism == XGDM_FAST15
        || drawMechanism == XGDM_FAST16
        || drawMechanism == XGDM_FAST32
!       || drawMechanism == XGDM_FAST32_BGR)
      {
        VARIABLES_DECLARATION;
        unsigned        row;
--- 119,126 ----
    if (drawMechanism == XGDM_FAST15
        || drawMechanism == XGDM_FAST16
        || drawMechanism == XGDM_FAST32
!       || drawMechanism == XGDM_FAST32_BGR
!       || drawMechanism == XGDM_FAST8)
      {
        VARIABLES_DECLARATION;
        unsigned        row;
***************
*** 138,143 ****
--- 139,147 ----
        case XGDM_FAST32_BGR:
          InitRGBShiftsAndMasks(0,8,8,8,16,8,0,8);
          break;
+       case XGDM_FAST8:
+         InitRGBShiftsAndMasks(5,3,2,3,0,2,0,8);
+         break;
        default:
          NSLog(@"Huh? Backend confused about XGDrawMechanism");
          //Try something.  With a bit of luck we see
***************
*** 877,883 ****
      if (drawMechanism == XGDM_FAST15
        || drawMechanism == XGDM_FAST16
        || drawMechanism == XGDM_FAST32
!       || drawMechanism == XGDM_FAST32_BGR)
        {
        VARIABLES_DECLARATION;
        unsigned        row;
--- 881,888 ----
      if (drawMechanism == XGDM_FAST15
        || drawMechanism == XGDM_FAST16
        || drawMechanism == XGDM_FAST32
!       || drawMechanism == XGDM_FAST32_BGR
!       || drawMechanism == XGDM_FAST8)
        {
        VARIABLES_DECLARATION;
        unsigned        row;
***************
*** 896,901 ****
--- 901,909 ----
          case XGDM_FAST32_BGR:
            InitRGBShiftsAndMasks(0,8,8,8,16,8,0,8);
            break;
+         case XGDM_FAST8:
+           InitRGBShiftsAndMasks(5,3,2,3,0,2,0,8);
+           break;
          default:
            NSLog(@"Huh? Backend confused about XGDrawMechanism");
            //Try something.  With a bit of luck we see
***************
*** 1159,1165 ****
    if (drawMechanism == XGDM_FAST15
        || drawMechanism == XGDM_FAST16
        || drawMechanism == XGDM_FAST32
!       || drawMechanism == XGDM_FAST32_BGR)
      {
        VARIABLES_DECLARATION;
        unsigned        row;
--- 1167,1174 ----
    if (drawMechanism == XGDM_FAST15
        || drawMechanism == XGDM_FAST16
        || drawMechanism == XGDM_FAST32
!       || drawMechanism == XGDM_FAST32_BGR
!       || drawMechanism == XGDM_FAST8)
      {
        VARIABLES_DECLARATION;
        unsigned        row;
***************
*** 1177,1182 ****
--- 1186,1194 ----
          break;
        case XGDM_FAST32_BGR:
          InitRGBShiftsAndMasks(0,8,8,8,16,8,0,8);
+         break;
+       case XGDM_FAST8:
+         InitRGBShiftsAndMasks(5,3,2,3,0,2,0,8);
          break;
        default:
          NSLog(@"Huh? Backend confused about XGDrawMechanism");
#include <unistd.h>
#include <stdio.h>

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xmu/Xmu.h>

int install(Display *dpy, int screen)
{
  XVisualInfo *vinfo, templ;
  int nret, status = 0;

  templ.screen = screen;
  templ.depth = 8;
  templ.class = PseudoColor;
  vinfo = XGetVisualInfo(dpy, VisualScreenMask|VisualDepthMask|VisualClassMask, 
&templ, &nret);

  if (vinfo && !XmuLookupStandardColormap(dpy, screen, vinfo->visualid, 8,
                                          XA_RGB_DEFAULT_MAP, True, True)) {
    fprintf(stderr, "Unable to install RGB_DEFAULT_MAP.\n");
    status += 1;
  }

  if (vinfo && !XmuLookupStandardColormap(dpy, screen, vinfo->visualid, 8,
                                          XA_RGB_BEST_MAP, True, True)) {
    fprintf(stderr, "Unable to install RGB_BEST_MAP.\n");
    status += 2;
  }

  if (vinfo) XFree(vinfo);

  return status;
}

int uninstall(Display *dpy, int screen)
{
  XmuDeleteStandardColormap(dpy, screen, XA_RGB_BEST_MAP);
  XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP);
  return 0;
}

int main(int argc, char **argv)
{
  Display *dpy;
  int screen, status;
  extern char *optarg;
  int ch, uflag = 0;
  char *display_name = NULL;

  while ((ch = getopt(argc, argv, "ud:")) != -1)
    switch (ch) {
    case 'u':
      uflag = 1;
      break;
    case 'd':
      display_name = optarg;
      break;
    case '?':
    default:
      fprintf(stderr, "Usage: %s [-d <X Display>] [-u]\n", argv[0]);
      return 5;
    }

  dpy = XOpenDisplay(display_name);
  if (!dpy) {
    fprintf(stderr, "Unable to connect to X Server.\n");
    return 4;
  }

  screen = DefaultScreen(dpy);

  status = uflag ? uninstall(dpy, screen) : install(dpy, screen);

  XCloseDisplay(dpy);
  return status;
}
INSTALL_DIR = /usr/X11R6/bin

INCLUDES = -I/usr/X11R6/include

LIBS = -L/usr/X11R6/lib -lXmu -lXt -lSM -lICE -lXext -lX11

CFLAGS = $(INCLUDES)

all: stdcmaps

stdcmaps: stdcmaps.o
        $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

install: stdcmaps
        cp stdcmaps $(INSTALL_DIR)
        strip $(INSTALL_DIR)/stdcmaps

clean:
        rm -f *.o stdcmaps

reply via email to

[Prev in Thread] Current Thread [Next in Thread]