From: lglynn AT hotmail DOT com (Glynn Leo) Subject: Xterm does not color Black to White 22 May 1998 07:56:36 -0700 Message-ID: <19980522023222.14556.qmail.cygnus.gnu-win32@hotmail.com> Content-Type: text/plain To: gnu-win32 AT cygnus DOT com Here is a followup on my Previous email I've compiled the following gcc -I//d/usr/X1R6.3/include test.c -lX11 -L//d/usr/X11R6.3/lib Now when I run it Japanese NT Windows with Macro Images X-Server I get a Window and it is coloring pixel to pixel from White to Black Now I transport it over to other NT Windows etc. I get the Window but it is NOT coloring pixel to pixel from Black to White Any suggestions why ? thanx leo /* test.c */ #include #include #include #include #include #define IMAGE_WIDTH 360 #define IMAGE_HEIGHT 240 typedef struct allocated_color { unsigned char R, G, B; struct allocated_color* pNext; unsigned long pixel; } tAllocatedColor; typedef struct s__window { Display* pDisplay; int screen; Window window; GC gc; int imageWidth; int imageHeight; XImage* pImage; char* pImageData; XImage* pSinglePixelImage; Colormap colorMap; tAllocatedColor* pColors; } ts_window; ts_window* s_createWindow(char* pWindowName, char* pDisplayName, int imageWidth, int imageHeight); void s_windowSetPointRGB(ts_window* pWindow, int xPos, int yPos, unsigned char R, unsigned char G, unsigned char B); void s_windowRefresh(ts_window* pWindow); void s_windowClose(ts_window* pWindow); #include #include #include #include #include #include #include #include #include #include #include #include #define IMAGE_WIDTH 360 #define IMAGE_HEIGHT 240 #define SCREEN_HORIZ_CENTER 600 #define SCREEN_VERT_CENTER 400 #define WINDOW_SPACING 20 Display *display; Atom delw; main() { FILE* pFile; int currRow = 0; int currCol = 0; int R, G, B; ts_window* pWindow; pFile = fopen("rgb", "r"); pWindow = s_createWindow("rgb_test", ":0.0", IMAGE_WIDTH, IMAGE_HEIGHT ); while (fscanf(pFile, "%d %d %d", &R, &G, &B) == 3) { s_windowSetPointRGB(pWindow, currCol, currRow, R, G, B); currCol++; if (currCol == IMAGE_WIDTH) { currRow++; currCol = 0; } printf("%d, %d\n", currRow, currCol); } s_windowRefresh(pWindow); fclose(pFile); } #if 1 ts_window* ScreateWindow(char* pWindowName, char* pDisplayName, int imageWidth, int imageHeight); #define IMAGE_WIDTH 360 #define IMAGE_HEIGHT 240 XTextProperty wName, iName; ts_window* s_createWindow(char* pWindowName, char* pDisplayName, int imageWidth, int imageHeight ) { struct passwd *pw; XrmValue value; char *str_type[20]; XVisualInfo vtmp, *vinfo; int n = 1; ts_window* pReturnValue ; ts_window tmpValue ; Window mainWin ; XGCValues gcValues; char myDisplayName[256]; Display *display; Visual *visual; Bool useColor = True; Colormap colormap; int screen_num; char pWindowBanner[256]; XEvent ev; GC gc; XImage* pImage; char* pImageData; XImage* pSinglePixelImage; Colormap colorMap; tAllocatedColor* pColors; int currRow, currCol; char* pSinglePixelImageData; pReturnValue = (ts_window*)malloc(sizeof(ts_window)); myDisplayName[0] = '\0'; myDisplayName[255] = '\0'; if (!(display = XOpenDisplay(myDisplayName))) { exit(1); } screen_num = DefaultScreen(display); visual = DefaultVisual(display, screen_num); colormap = DefaultColormap(display, screen_num); vtmp.visualid = XVisualIDFromVisual(visual); mainWin = XCreateSimpleWindow(display, RootWindow(display, screen_num), 10,10, IMAGE_WIDTH, IMAGE_HEIGHT, 4, BlackPixel(display, screen_num), WhitePixel(display, screen_num) ); XSelectInput(display, mainWin, StructureNotifyMask); sprintf(pWindowBanner, "%s %d", "d_", 1); XSetStandardProperties(display, mainWin, pWindowBanner, pWindowBanner, None, NULL, 0, 0); XMapRaised(display, mainWin); XNextEvent(display, &ev); XSelectInput(display, mainWin, NoEventMask); /* Now, create the graphics context for the window */ gcValues.foreground = BlackPixel(display, screen_num); gcValues.background = WhitePixel(display, screen_num); gc = XCreateGC(display, RootWindow(display, screen_num), (GCForeground | GCBackground), &gcValues); /* Get the default colormap */ colorMap = DefaultColormap(display, screen_num); pImageData = (char*)malloc(imageWidth * imageHeight); pImage = XCreateImage(display, None, 8, ZPixmap, 0, pImageData, imageWidth, imageHeight, 8, 0); pSinglePixelImageData = (char*)malloc(1); pSinglePixelImage = XCreateImage(display, None, 8, ZPixmap, 0, pSinglePixelImageData, 1, 1, 8, 0); imageWidth = imageWidth; imageHeight = imageHeight; pColors = NULL; pReturnValue->pDisplay = display ; pReturnValue->screen = screen_num; pReturnValue->window = mainWin ; pReturnValue->gc = gc; pReturnValue->imageWidth = imageWidth ; pReturnValue->imageHeight = imageHeight ; pReturnValue->pImage = pImage; pReturnValue->pSinglePixelImage = pSinglePixelImage ; pReturnValue->colorMap = colorMap ; pReturnValue->pColors = pColors ; for (currRow = 0; currRow < imageHeight; currRow++) for (currCol = 0; currCol < imageWidth; currCol++) s_windowSetPointRGB(pReturnValue, currCol, currRow, 0, 0, 0); s_windowRefresh(pReturnValue); return(pReturnValue); } void s_windowSetPointRGB(ts_window* pWindow, int xPos, int yPos, unsigned char R, unsigned char G, unsigned char B) { XColor color; tAllocatedColor* currColor; for(currColor = pWindow->pColors; ((currColor != NULL) && ((currColor->R != R) | (currColor->G != G) | (currColor->B != B))); currColor = currColor->pNext); if (currColor == NULL) { color.red = R << 8; color.green = G << 8; color.blue = B << 8; color.flags = DoRed | DoGreen | DoBlue; XAllocColor(pWindow->pDisplay, pWindow->colorMap, &color); currColor = (tAllocatedColor*)malloc(sizeof(tAllocatedColor)); currColor->pNext = pWindow->pColors; pWindow->pColors = currColor; currColor->R = R; currColor->G = G; currColor->B = B; currColor->pixel = color.pixel; } else color.pixel = currColor->pixel; /* XPutPixel(pWindow->pImage, xPos, yPos, color.pixel); */ XPutImage(pWindow->pDisplay, pWindow->window, pWindow->gc, pWindow->pImage, xPos, yPos, xPos, yPos, 1, 1); } void s_windowRefresh(ts_window* pWindow) { XPutImage(pWindow->pDisplay, pWindow->window, pWindow->gc, pWindow->pImage, 0, 0, 0, 0, pWindow->imageWidth, pWindow->imageHeight); } static void freeAllocatedColor(tAllocatedColor* pColor) { if (pColor != NULL) { if (pColor->pNext != NULL) freeAllocatedColor(pColor->pNext); free(pColor); } } void s_windowClose(ts_window* pWindow) { XEvent xEvent; XSelectInput(pWindow->pDisplay, pWindow->window, StructureNotifyMask); XUnmapWindow(pWindow->pDisplay, pWindow->window); /* ...and wait for the unmap */ do { XNextEvent(pWindow->pDisplay, &xEvent); } while ((xEvent.type != UnmapNotify) || (xEvent.xmap.event != pWindow->window)); XDestroyWindow(pWindow->pDisplay, pWindow->window); free(pWindow->pImageData); freeAllocatedColor(pWindow->pColors); free(pWindow); } #endif ______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".