This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Xterm does not color Black to White
- To: gnu-win32 at cygnus dot com
- Subject: Xterm does not color Black to White
- From: "Glynn Leo" <lglynn at hotmail dot com>
- Date: Thu, 21 May 1998 19:32:17 PDT
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#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 <stdio.h>
#include <math.h>
#include <pwd.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xos.h>
#include <X11/Xfuncs.h>
#include <X11/Xfuncproto.h>
#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@cygnus.com" with one line of text: "help".