static bool supportedFormat(const QPixmap *pixmap) { int depth = pixmap->depth(); Visual *visual = (Visual*)pixmap->x11Info().visual(); if (ImageByteOrder(pixmap->x11Info().display()) != LSBFirst) return false; // Assume this means the pixmap is ARGB32 if (pixmap->hasAlphaChannel()) return true; // 24/34 bit x8a8r8g8b8 if ((depth == 24 || depth == 32) && visual->red_mask == 0x00ff0000 && visual->green_mask == 0x0000ff00 && visual->blue_mask == 0x000000ff) { return true; } // 16 bit r5g6b5 if (depth == 16 && visual->red_mask == 0xf800 && visual->green_mask == 0x07e0 && visual->blue_mask == 0x001f) { return true; } return false; }
Picture PreviewCursor::createPicture(const XcursorImage *image) const { Display *dpy = QPaintDevice::x11AppDisplay(); XImage ximage; ximage.width = image->width; ximage.height = image->height; ximage.xoffset = 0; ximage.format = ZPixmap; ximage.data = reinterpret_cast< char * >(image->pixels); ximage.byte_order = ImageByteOrder(dpy); ximage.bitmap_unit = 32; ximage.bitmap_bit_order = ximage.byte_order; ximage.bitmap_pad = 32; ximage.depth = 32; ximage.bits_per_pixel = 32; ximage.bytes_per_line = image->width * 4; ximage.red_mask = 0x00ff0000; ximage.green_mask = 0x0000ff00; ximage.blue_mask = 0x000000ff; ximage.obdata = 0; XInitImage(&ximage); Pixmap pix = XCreatePixmap(dpy, DefaultRootWindow(dpy), ximage.width, ximage.height, 32); GC gc = XCreateGC(dpy, pix, 0, NULL); XPutImage(dpy, pix, gc, &ximage, 0, 0, 0, 0, ximage.width, ximage.height); XFreeGC(dpy, gc); XRenderPictFormat *fmt = XRenderFindStandardFormat(dpy, PictStandardARGB32); Picture pict = XRenderCreatePicture(dpy, pix, fmt, 0, NULL); XFreePixmap(dpy, pix); return pict; }
boolean xf_pre_connect(freerdp* instance) { xfInfo* xfi; rdpSettings* settings; xfi = (xfInfo*) xzalloc(sizeof(xfInfo)); SET_XFI(instance, xfi); xfi->instance = instance; settings = instance->settings; settings->order_support[NEG_DSTBLT_INDEX] = True; settings->order_support[NEG_PATBLT_INDEX] = True; settings->order_support[NEG_SCRBLT_INDEX] = True; settings->order_support[NEG_OPAQUE_RECT_INDEX] = True; settings->order_support[NEG_DRAWNINEGRID_INDEX] = False; settings->order_support[NEG_MULTIDSTBLT_INDEX] = False; settings->order_support[NEG_MULTIPATBLT_INDEX] = False; settings->order_support[NEG_MULTISCRBLT_INDEX] = False; settings->order_support[NEG_MULTIOPAQUERECT_INDEX] = True; settings->order_support[NEG_MULTI_DRAWNINEGRID_INDEX] = False; settings->order_support[NEG_LINETO_INDEX] = True; settings->order_support[NEG_POLYLINE_INDEX] = True; settings->order_support[NEG_MEMBLT_INDEX] = True; settings->order_support[NEG_MEM3BLT_INDEX] = False; settings->order_support[NEG_SAVEBITMAP_INDEX] = True; settings->order_support[NEG_GLYPH_INDEX_INDEX] = True; settings->order_support[NEG_FAST_INDEX_INDEX] = True; settings->order_support[NEG_FAST_GLYPH_INDEX] = True; settings->order_support[NEG_POLYGON_SC_INDEX] = False; settings->order_support[NEG_POLYGON_CB_INDEX] = False; settings->order_support[NEG_ELLIPSE_SC_INDEX] = False; settings->order_support[NEG_ELLIPSE_CB_INDEX] = False; freerdp_chanman_pre_connect(GET_CHANMAN(instance), instance); xfi->display = XOpenDisplay(NULL); if (xfi->display == NULL) { printf("xf_pre_connect: failed to open display: %s\n", XDisplayName(NULL)); return False; } xf_kbd_init(xfi); xfi->xfds = ConnectionNumber(xfi->display); xfi->screen_number = DefaultScreen(xfi->display); xfi->screen = ScreenOfDisplay(xfi->display, xfi->screen_number); xfi->depth = DefaultDepthOfScreen(xfi->screen); xfi->big_endian = (ImageByteOrder(xfi->display) == MSBFirst); xfi->decoration = True; xfi->mouse_motion = True; return True; }
int graphics_setup (void) { char *display_name = 0; const char *keycodes; display = XOpenDisplay (display_name); if (display == 0) { write_log ("Can't connect to X server %s\n", XDisplayName (display_name)); return 0; } shmavail = shm_available (); dgaavail = dga_available (); vidmodeavail = vid_mode_available (); { int local_byte_order; int x = 0x04030201; char *y=(char*)&x; local_byte_order = y[0] == 0x04 ? MSBFirst : LSBFirst; if (ImageByteOrder(display) != local_byte_order) inverse_byte_order = 1; } screen = XDefaultScreen (display); rootwin = XRootWindow (display, screen); if (!get_best_visual (display, screen, &visualInfo)) return 0; vis = visualInfo.visual; bitdepth = visualInfo.depth; if (!(bit_unit = get_visual_bit_unit (&visualInfo, bitdepth))) return 0; write_log ("X11GFX: Initialized.\n"); rawkeys_available = 0; #ifdef USE_XKB keycodes = get_xkb_keycodes (display); if (keycodes) { /* We only support xfree86 keycodes for now */ if (strncmp (keycodes, "xfree86", 7) == 0) { rawkeys_available = 1; raw_keyboard = uaekey_make_default_kbr (x11pc_keymap); write_log ("X11GFX: Keyboard uses xfree86 keycodes\n"); } } #endif return 1; }
/** * Choose the pixel format for the given visual. * This will tell the gallium driver how to pack pixel data into * drawing surfaces. */ static GLuint choose_pixel_format(XMesaVisual v) { boolean native_byte_order = (host_byte_order() == ImageByteOrder(v->display)); if ( GET_REDMASK(v) == 0x0000ff && GET_GREENMASK(v) == 0x00ff00 && GET_BLUEMASK(v) == 0xff0000 && v->BitsPerPixel == 32) { if (native_byte_order) { /* no byteswapping needed */ return PIPE_FORMAT_R8G8B8A8_UNORM; } else { return PIPE_FORMAT_A8B8G8R8_UNORM; } } else if ( GET_REDMASK(v) == 0xff0000 && GET_GREENMASK(v) == 0x00ff00 && GET_BLUEMASK(v) == 0x0000ff && v->BitsPerPixel == 32) { if (native_byte_order) { /* no byteswapping needed */ return PIPE_FORMAT_B8G8R8A8_UNORM; } else { return PIPE_FORMAT_A8R8G8B8_UNORM; } } else if ( GET_REDMASK(v) == 0x0000ff00 && GET_GREENMASK(v) == 0x00ff0000 && GET_BLUEMASK(v) == 0xff000000 && v->BitsPerPixel == 32) { if (native_byte_order) { /* no byteswapping needed */ return PIPE_FORMAT_A8R8G8B8_UNORM; } else { return PIPE_FORMAT_B8G8R8A8_UNORM; } } else if ( GET_REDMASK(v) == 0xf800 && GET_GREENMASK(v) == 0x07e0 && GET_BLUEMASK(v) == 0x001f && native_byte_order && v->BitsPerPixel == 16) { /* 5-6-5 RGB */ return PIPE_FORMAT_B5G6R5_UNORM; } return PIPE_FORMAT_NONE; }
int DX_FillResolutions (uae_u16 *ppixel_format) { Screen *scr = ScreenOfDisplay (display, screen); int i, count = 0; int w = WidthOfScreen (scr); int h = HeightOfScreen (scr); int emulate_chunky = 0; if (ImageByteOrder (display) == LSBFirst) { picasso_vidinfo.rgbformat = (bit_unit == 8 ? RGBFB_CHUNKY : bitdepth == 15 && bit_unit == 16 ? RGBFB_R5G5B5PC : bitdepth == 16 && bit_unit == 16 ? RGBFB_R5G6B5PC : bit_unit == 24 ? RGBFB_B8G8R8 : bit_unit == 32 ? RGBFB_B8G8R8A8 : RGBFB_NONE); } else { picasso_vidinfo.rgbformat = (bit_unit == 8 ? RGBFB_CHUNKY : bitdepth == 15 && bit_unit == 16 ? RGBFB_R5G5B5 : bitdepth == 16 && bit_unit == 16 ? RGBFB_R5G6B5 : bit_unit == 24 ? RGBFB_R8G8B8 : bit_unit == 32 ? RGBFB_A8R8G8B8 : RGBFB_NONE); } *ppixel_format = 1 << picasso_vidinfo.rgbformat; if (visualInfo.VI_CLASS == TrueColor && (bit_unit == 16 || bit_unit == 32)) *ppixel_format |= RGBFF_CHUNKY, emulate_chunky = 1; #if defined USE_DGA_EXTENSION && defined USE_VIDMODE_EXTENSION if (dgaavail && vidmodeavail) { for (i = 0; i < vidmodecount && count < MAX_PICASSO_MODES; i++) { int j; for (j = 0; j <= emulate_chunky && count < MAX_PICASSO_MODES; j++) { DisplayModes[count].res.width = allmodes[i]->hdisplay; DisplayModes[count].res.height = allmodes[i]->vdisplay; DisplayModes[count].depth = j == 1 ? 1 : bit_unit >> 3; DisplayModes[count].refresh = 75; count++; } } } else #endif { for (i = 0; i < MAX_SCREEN_MODES && count < MAX_PICASSO_MODES; i++) {
static void gdk_imlib_set_fast_render(ImlibData * id, Display * disp) { /* Turn off fastrender if there is an endianess diff between */ /* client and Xserver in all but 24 bit mode */ int byt, bit; byt = ImageByteOrder(id->x.disp); /* LSBFirst | MSBFirst */ bit = BitmapBitOrder(id->x.disp); /* LSBFirst | MSBFirst */ id->x.byte_order = byt; id->x.bit_order = bit; /* We ignore this for now in the fastrend */ /* if little endian && server big */ if (htonl(1) != 1 && byt == MSBFirst) id->fastrend = 0; /* if big endian && server little */ if (htonl(1) == 1 && byt == LSBFirst) id->fastrend = 0; }
void InitOutput(ScreenInfo *screenInfo, int argc, char *argv[]) { int i, j; xnestOpenDisplay(argc, argv); screenInfo->imageByteOrder = ImageByteOrder(xnestDisplay); screenInfo->bitmapScanlineUnit = BitmapUnit(xnestDisplay); screenInfo->bitmapScanlinePad = BitmapPad(xnestDisplay); screenInfo->bitmapBitOrder = BitmapBitOrder(xnestDisplay); screenInfo->numPixmapFormats = 0; for (i = 0; i < xnestNumPixmapFormats; i++) for (j = 0; j < xnestNumDepths; j++) if ((xnestPixmapFormats[i].depth == 1) || (xnestPixmapFormats[i].depth == xnestDepths[j])) { screenInfo->formats[screenInfo->numPixmapFormats].depth = xnestPixmapFormats[i].depth; screenInfo->formats[screenInfo->numPixmapFormats].bitsPerPixel = xnestPixmapFormats[i].bits_per_pixel; screenInfo->formats[screenInfo->numPixmapFormats].scanlinePad = xnestPixmapFormats[i].scanline_pad; screenInfo->numPixmapFormats++; break; } xnestWindowPrivateIndex = AllocateWindowPrivateIndex(); xnestGCPrivateIndex = AllocateGCPrivateIndex(); xnestFontPrivateIndex = AllocateFontPrivateIndex(); if (!xnestNumScreens) xnestNumScreens = 1; for (i = 0; i < xnestNumScreens; i++) AddScreen(xnestOpenScreen, argc, argv); xnestNumScreens = screenInfo->numScreens; xnestDoFullGeneration = xnestFullGeneration; }
/* This function gets the X Display and global info about it. Everything is stored in our object and will be cleaned when the object is disposed. Note here that caps for supported format are generated without any window or image creation */ GstXContext * ximageutil_xcontext_get (GstElement * parent, const gchar * display_name) { GstXContext *xcontext = NULL; XPixmapFormatValues *px_formats = NULL; gint nb_formats = 0, i; xcontext = g_new0 (GstXContext, 1); xcontext->disp = XOpenDisplay (display_name); GST_DEBUG_OBJECT (parent, "opened display %p", xcontext->disp); if (!xcontext->disp) { g_free (xcontext); return NULL; } xcontext->screen = DefaultScreenOfDisplay (xcontext->disp); xcontext->screen_num = DefaultScreen (xcontext->disp); xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num); xcontext->root = DefaultRootWindow (xcontext->disp); xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num); xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num); xcontext->depth = DefaultDepthOfScreen (xcontext->screen); xcontext->width = DisplayWidth (xcontext->disp, xcontext->screen_num); xcontext->height = DisplayHeight (xcontext->disp, xcontext->screen_num); xcontext->widthmm = DisplayWidthMM (xcontext->disp, xcontext->screen_num); xcontext->heightmm = DisplayHeightMM (xcontext->disp, xcontext->screen_num); xcontext->caps = NULL; GST_DEBUG_OBJECT (parent, "X reports %dx%d pixels and %d mm x %d mm", xcontext->width, xcontext->height, xcontext->widthmm, xcontext->heightmm); ximageutil_calculate_pixel_aspect_ratio (xcontext); /* We get supported pixmap formats at supported depth */ px_formats = XListPixmapFormats (xcontext->disp, &nb_formats); if (!px_formats) { XCloseDisplay (xcontext->disp); g_free (xcontext); return NULL; } /* We get bpp value corresponding to our running depth */ for (i = 0; i < nb_formats; i++) { if (px_formats[i].depth == xcontext->depth) xcontext->bpp = px_formats[i].bits_per_pixel; } XFree (px_formats); xcontext->endianness = (ImageByteOrder (xcontext->disp) == LSBFirst) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; #ifdef HAVE_XSHM /* Search for XShm extension support */ if (XShmQueryExtension (xcontext->disp) && ximageutil_check_xshm_calls (xcontext)) { xcontext->use_xshm = TRUE; GST_DEBUG ("ximageutil is using XShm extension"); } else { xcontext->use_xshm = FALSE; GST_DEBUG ("ximageutil is not using XShm extension"); } #endif /* HAVE_XSHM */ /* our caps system handles 24/32bpp RGB as big-endian. */ if ((xcontext->bpp == 24 || xcontext->bpp == 32) && xcontext->endianness == G_LITTLE_ENDIAN) { xcontext->endianness = G_BIG_ENDIAN; xcontext->r_mask_output = GUINT32_TO_BE (xcontext->visual->red_mask); xcontext->g_mask_output = GUINT32_TO_BE (xcontext->visual->green_mask); xcontext->b_mask_output = GUINT32_TO_BE (xcontext->visual->blue_mask); if (xcontext->bpp == 24) { xcontext->r_mask_output >>= 8; xcontext->g_mask_output >>= 8; xcontext->b_mask_output >>= 8; }
int main(int argc, char **argv) { Atom atomWMDeleteWindow; int screenNumber; Screen *screen; Window window; XWindowAttributes windowAttributes; Colormap colormap; PaletteInfo paletteInfo; Image image; XImage *xImage; int x, y; int captureFrame; XEvent event; bool sizeChanged; // ProgramExit initialization display = NULL; v4l = -1; captureBuf = NULL; on_exit(ProgramExit, NULL); // Get command line options magnification = 1; if (argc > 1) { magnification = atoi(argv[1]); } // end if magnification = max(1, magnification); printf("Magnification is %i\n", magnification); // Open display if ((display = XOpenDisplay(NULL)) == NULL) { // NULL for DISPLAY printf("Error: XOpenDisplay() failed\n"); exit(1); } // end if screenNumber = DefaultScreen(display); screen = XScreenOfDisplay(display, screenNumber); // Obtain WM protocols atom for ClientMessage exit event if ((atomWMDeleteWindow = XInternAtom(display, AtomWMDeleteWindowName, True)) == None) { printf("Error: %s atom does not exist\n", AtomWMDeleteWindowName); exit(1); } // end if // Create window, inheriting depth and visual from root window window = XCreateSimpleWindow( display, RootWindowOfScreen(screen), 0, // x 0, // y 640, // width 480, // height 0, // border width BlackPixelOfScreen(screen), // border BlackPixelOfScreen(screen) // background ); XStoreName(display, window, "V4L RGB Test"); XGetWindowAttributes(display, window, &windowAttributes); if (((windowAttributes.depth == 8) && (windowAttributes.visual->c_class != PseudoColor)) || ((windowAttributes.depth > 8) && (windowAttributes.visual->c_class != TrueColor))) { printf("Error: Visual not supported\n"); exit(1); } // end if // Create PseudoColor HI240 colormap, if needed if (windowAttributes.depth == 8) { colormap = XCreateColormap(display, window, windowAttributes.visual, AllocAll); paletteInfo.display = display; paletteInfo.colormap = colormap; Hi240BuildPalette((ulong) 0x10000, (Hi240StorePaletteEntry *) StoreColormapEntry, &paletteInfo); XSetWindowColormap(display, window, colormap); } // end if // Create image if (image.Create( display, window, // Defines visual, depth MaxImageWidth, MaxImageHeight, True // MITSHM ) < 0) { printf("Error: image.Create() failed\n"); exit(1); } // end if image.Clear(); #if (1) printf("\nDisplay:\n"); printf("Image byte order = %s\n", ByteOrderName(ImageByteOrder(display))); printf("Bitmap unit = %i\n", BitmapUnit(display)); printf("Bitmap bit order = %s\n", ByteOrderName(BitmapBitOrder(display))); printf("Bitmap pad = %i\n", BitmapPad(display)); printf("\nWindow:\n"); printf("Depth = %i\n", windowAttributes.depth); printf("Visual ID = 0x%02x\n", windowAttributes.visual->visualid); printf("Visual class = %s\n", VisualClassName(windowAttributes.visual->c_class)); printf("Red mask = 0x%08lx\n", windowAttributes.visual->red_mask); printf("Green mask = 0x%08lx\n", windowAttributes.visual->green_mask); printf("Blue mask = 0x%08lx\n", windowAttributes.visual->blue_mask); printf("Bits per R/G/B = %i\n", windowAttributes.visual->bits_per_rgb); // log2 # colors xImage = image.X(); printf("\nImage:\n"); printf("Image byte order = %s\n", ByteOrderName(xImage->byte_order)); printf("Bitmap unit = %i\n", xImage->bitmap_unit); printf("Bitmap bit order = %s\n", ByteOrderName(xImage->bitmap_bit_order)); printf("Bitmap pad = %i\n", xImage->bitmap_pad); printf("Depth = %i\n", xImage->depth); printf("Red mask = 0x%08lx\n", xImage->red_mask); printf("Green mask = 0x%08lx\n", xImage->green_mask); printf("Blue mask = 0x%08lx\n", xImage->blue_mask); printf("Bits per pixel = %i\n", xImage->bits_per_pixel); // ZPixmap printf("Bytes per line = %i\n", xImage->bytes_per_line); printf("IsShared = %s\n", image.IsShared() ? "True" : "False"); printf("HasSharedPixmap = %s\n", image.HasSharedPixmap() ? "True" : "False"); #endif // V4L stuff if ((v4l = open(BigPictureDevice, O_RDWR)) < 0) { printf("Error: Can't open %s: %s\n", BigPictureDevice, strerror(errno)); exit(1); } // end if if (V4LMGetMMInfo(v4l, &v4lMMInfo) < 0) { printf("Error: V4LMGetMMInfo: %s\n", strerror(errno)); exit(1); } // end if #if (0) printf("Capture buffer size = %i\n", v4lMMInfo.size); printf("Capture buffer frames = %i\n", v4lMMInfo.frames); #endif if (v4lMMInfo.frames < 2) { printf("Error: V4LMGetMMInfo: frames < 2\n"); exit(1); } // end if if ((captureBuf = (bits8 *) mmap(0, v4lMMInfo.size, PROT_READ | PROT_WRITE, MAP_SHARED, v4l, 0)) == MAP_FAILED) { printf("Error: mmap(): %s\n", strerror(errno)); exit(1); } // end if if (V4LSetSource(v4l, BigPictureCompositeSource, VIDEO_MODE_NTSC) < 0) { printf("Error: V4LSetSource: %s\n", strerror(errno)); exit(1); } // end if if (V4LGetCaps(v4l, &v4lCaps) < 0) { printf("Error: V4LGetCaps: %s\n", strerror(errno)); exit(1); } // end if // Select V4L RGB capture format to exactly match image/visual (no LUTs!) if ((captureFormat = XImageCaptureFormat(image.X())) < 0) { printf("Error: No match for visual/image\n"); exit(1); } // end if // Initialize capture size based on window size windowWidth = windowAttributes.width; windowHeight = windowAttributes.height;; WindowResize(v4l, windowWidth, windowHeight, magnification); // Does V4LMSetFormat(). // Initialize picture attributes to mid-range V4LSetBrightness(v4l, 65535 / 2); V4LSetContrast(v4l, 65535 / 2); V4LSetSaturation(v4l, 65535 / 2); V4LSetHue(v4l, 65535 / 2); // Ready to start: Display window, select events, and initiate capture sequence XMapRaised(display, window); XSetWMProtocols(display, window, &atomWMDeleteWindow, 1); XSelectInput(display, window, StructureNotifyMask | ExposureMask); captureFrame = 0; if (V4LMCapture(v4l, captureFrame) < 0) { printf("Error: V4LMCapture: %s\n", strerror(errno)); exit(1); } // end if while (1) { if (XPending(display) > 0) { XNextEvent(display, &event); switch (event.type) { case ClientMessage: // From WM if (event.xclient.data.l[0] == atomWMDeleteWindow) { exit(0); } // end if break; case ConfigureNotify: sizeChanged = false; if (event.xconfigure.width != windowWidth) { sizeChanged = true; windowWidth = event.xconfigure.width; } // end if if (event.xconfigure.height != windowHeight) { sizeChanged = true; windowHeight = event.xconfigure.height; } // end if if (sizeChanged) { image.Clear(); XClearWindow(display, window); WindowResize(v4l, windowWidth, windowHeight, magnification); } // end if break; case Expose: if (event.xexpose.count == 0) { Put(window, image); } // end if break; } // end switch } else { // Wait for this frame if (V4LMSync(v4l, captureFrame) < 0) { printf("Error: V4LMSync: %s\n", strerror(errno)); exit(1); } // end if // Start capture for next frame if (V4LMCapture(v4l, 1 - captureFrame) < 0) { printf("Error: V4LMCapture: %s\n", strerror(errno)); exit(1); } // end if Draw(image, captureBuf + v4lMMInfo.offsets[captureFrame], magnification); Put(window, image); captureFrame = 1 - captureFrame; // 0<->1 } // endif } // end while printf("Error: Fell out of event loop!\n"); exit(1); } // end main
void check_AfterStep_dirtree ( char * ashome, Bool create_non_conf ) { char *fullfilename; /* Create missing directories & put there defaults */ if (CheckDir (ashome) != 0) { CheckOrCreate (ashome); #if defined(DO_SEND_POSTCARD) /*&& defined(HAVE_POPEN) */ /* send some info to sasha @ aftercode.net */ { FILE *p; char *filename = make_file_name(ashome, ".postcard"); /*p = popen ("mail -s \"AfterStep installation info\" [email protected]", "w");*/ p = fopen( filename, "wt" ); free(filename); if (p) { fprintf( p, "AfterStep_Version=\"%s\";\n", VERSION ); fprintf( p, "CanonicalBuild=\"%s\";\n", CANONICAL_BUILD ); fprintf( p, "CanonicalOS=\"%s\";\n", CANONICAL_BUILD_OS ); fprintf( p, "CanonicalCPU=\"%s\";\n", CANONICAL_BUILD_CPU ); fprintf( p, "CanonicalVendor=\"%s\";\n", CANONICAL_BUILD_VENDOR ); if( dpy ) { fprintf (p, "X_DefaultScreenNumber=%d;\n", DefaultScreen (dpy)); fprintf (p, "X_NumberOfScreens=%d;\n", ScreenCount (dpy)); fprintf (p, "X_Display=\"%s\";\n", DisplayString (dpy)); fprintf (p, "X_ProtocolVersion=%d.%d;\n", ProtocolVersion (dpy), ProtocolRevision (dpy)); fprintf (p, "X_Vendor=\"%s\";\n", ServerVendor (dpy)); fprintf (p, "X_VendorRelease=%d;\n", VendorRelease (dpy)); if (strstr(ServerVendor (dpy), "XFree86")) { int vendrel = VendorRelease(dpy); fprintf(p, "X_XFree86Version="); if (vendrel < 336) { fprintf(p, "%d.%d.%d", vendrel / 100, (vendrel / 10) % 10, vendrel % 10); } else if (vendrel < 3900) { fprintf(p, "%d.%d", vendrel / 1000, (vendrel / 100) % 10); if (((vendrel / 10) % 10) || (vendrel % 10)) { fprintf(p, ".%d", (vendrel / 10) % 10); if (vendrel % 10) fprintf(p, ".%d", vendrel % 10); } } else if (vendrel < 40000000) { fprintf(p, "%d.%d", vendrel/1000, (vendrel/10) % 10); if (vendrel % 10) fprintf(p, ".%d", vendrel % 10); } else { fprintf(p, "%d.%d.%d", vendrel/10000000,(vendrel/100000)%100, (vendrel/1000)%100); if (vendrel % 1000) fprintf(p, ".%d", vendrel % 1000); } fprintf(p, ";\n"); } if( ASDefaultScrWidth > 0 ) { fprintf( p, "AS_Screen=%ld;\n", ASDefaultScr->screen ); fprintf( p, "AS_RootGeometry=%dx%d;\n", ASDefaultScrWidth, ASDefaultScrHeight ); } if( ASDefaultVisual ) { fprintf( p, "AS_Visual=0x%lx;\n", ASDefaultVisual->visual_info.visualid ); fprintf( p, "AS_Colordepth=%d;\n", ASDefaultVisual->visual_info.depth ); fprintf( p, "AS_RedMask=0x%lX;\n", ASDefaultVisual->visual_info.red_mask ); fprintf( p, "AS_GreenMask=0x%lX;\n", ASDefaultVisual->visual_info.green_mask ); fprintf( p, "AS_BlueMask=0x%lX;\n", ASDefaultVisual->visual_info.blue_mask ); fprintf( p, "AS_ByteOrdering=%s;\n", (ImageByteOrder(ASDefaultVisual->dpy)==MSBFirst)?"MSBFirst":"LSBFirst" ); } } fclose(p); /*pclose (p);*/ /*p = popen ("mail -s \"AfterStep installation info\" [email protected]", "w");*/ } } #endif } fullfilename = make_file_name (ashome, AFTER_SAVE); CheckOrCreateFile (fullfilename); free( fullfilename ); #if 0 fullfilename = make_file_name (ashome, THEME_FILE_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, LOOK_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, FEEL_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, THEME_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, COLORSCHEME_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, BACK_DIR); CheckOrCreate(fullfilename); free( fullfilename ); #endif fullfilename = make_file_name (ashome, DESKTOP_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, ICON_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, FONT_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, TILE_DIR); CheckOrCreate(fullfilename); free( fullfilename ); fullfilename = make_file_name (ashome, WEBCACHE_DIR); CheckOrCreate(fullfilename); free( fullfilename ); if( create_non_conf ) { char *postcard_fname ; FILE *f ; fullfilename = make_file_name (ashome, AFTER_NONCF); /* legacy non-configurable dir: */ CheckOrCreate(fullfilename); postcard_fname = make_file_name( fullfilename, "send_postcard.sh" ); free( fullfilename ); f = fopen( postcard_fname, "wt" ); if( f ) { fprintf( f, "#!/bin/sh\n\n" ); fprintf( f, "if [ -r %s/.postcard ] \nthen echo -n \nelse rm %s \nexit\nfi\n", ashome, postcard_fname ); fprintf( f, "x-terminal-emulator -e \"%s/tools/postcard.sh\"\n", AFTER_SHAREDIR ); fprintf( f, "if [ -r %s/.postcard ] \nthen echo -n \nelse rm %s \nfi\n", ashome, postcard_fname ); fclose( f ); } chmod (postcard_fname, 0700); free(postcard_fname); } char *cachefilename = make_file_name(ashome, THUMBNAILS_DIR); CheckOrCreate(cachefilename); extern void set_asimage_thumbnails_cache_dir(const char*); set_asimage_thumbnails_cache_dir(cachefilename); free( cachefilename ); }
void _gdk_visual_init (GdkScreen *screen) { static const gint possible_depths[8] = { 32, 30, 24, 16, 15, 8, 4, 1 }; static const GdkVisualType possible_types[6] = { GDK_VISUAL_DIRECT_COLOR, GDK_VISUAL_TRUE_COLOR, GDK_VISUAL_PSEUDO_COLOR, GDK_VISUAL_STATIC_COLOR, GDK_VISUAL_GRAYSCALE, GDK_VISUAL_STATIC_GRAY }; GdkScreenX11 *screen_x11; XVisualInfo *visual_list; XVisualInfo visual_template; GdkVisualPrivate *temp_visual; Visual *default_xvisual; GdkVisualPrivate **visuals; int nxvisuals; int nvisuals; int i, j; g_return_if_fail (GDK_IS_SCREEN (screen)); screen_x11 = GDK_SCREEN_X11 (screen); nxvisuals = 0; visual_template.screen = screen_x11->screen_num; visual_list = XGetVisualInfo (screen_x11->xdisplay, VisualScreenMask, &visual_template, &nxvisuals); visuals = g_new (GdkVisualPrivate *, nxvisuals); for (i = 0; i < nxvisuals; i++) visuals[i] = g_object_new (GDK_TYPE_VISUAL, NULL); default_xvisual = DefaultVisual (screen_x11->xdisplay, screen_x11->screen_num); nvisuals = 0; for (i = 0; i < nxvisuals; i++) { visuals[nvisuals]->screen = screen; if (visual_list[i].depth >= 1) { #ifdef __cplusplus switch (visual_list[i].c_class) #else /* __cplusplus */ switch (visual_list[i].class) #endif /* __cplusplus */ { case StaticGray: visuals[nvisuals]->visual.type = GDK_VISUAL_STATIC_GRAY; break; case GrayScale: visuals[nvisuals]->visual.type = GDK_VISUAL_GRAYSCALE; break; case StaticColor: visuals[nvisuals]->visual.type = GDK_VISUAL_STATIC_COLOR; break; case PseudoColor: visuals[nvisuals]->visual.type = GDK_VISUAL_PSEUDO_COLOR; break; case TrueColor: visuals[nvisuals]->visual.type = GDK_VISUAL_TRUE_COLOR; break; case DirectColor: visuals[nvisuals]->visual.type = GDK_VISUAL_DIRECT_COLOR; break; } visuals[nvisuals]->visual.depth = visual_list[i].depth; visuals[nvisuals]->visual.byte_order = (ImageByteOrder(screen_x11->xdisplay) == LSBFirst) ? GDK_LSB_FIRST : GDK_MSB_FIRST; visuals[nvisuals]->visual.red_mask = visual_list[i].red_mask; visuals[nvisuals]->visual.green_mask = visual_list[i].green_mask; visuals[nvisuals]->visual.blue_mask = visual_list[i].blue_mask; visuals[nvisuals]->visual.colormap_size = visual_list[i].colormap_size; visuals[nvisuals]->visual.bits_per_rgb = visual_list[i].bits_per_rgb; visuals[nvisuals]->xvisual = visual_list[i].visual; if ((visuals[nvisuals]->visual.type == GDK_VISUAL_TRUE_COLOR) || (visuals[nvisuals]->visual.type == GDK_VISUAL_DIRECT_COLOR)) { gdk_visual_decompose_mask (visuals[nvisuals]->visual.red_mask, &visuals[nvisuals]->visual.red_shift, &visuals[nvisuals]->visual.red_prec); gdk_visual_decompose_mask (visuals[nvisuals]->visual.green_mask, &visuals[nvisuals]->visual.green_shift, &visuals[nvisuals]->visual.green_prec); gdk_visual_decompose_mask (visuals[nvisuals]->visual.blue_mask, &visuals[nvisuals]->visual.blue_shift, &visuals[nvisuals]->visual.blue_prec); } else { visuals[nvisuals]->visual.red_mask = 0; visuals[nvisuals]->visual.red_shift = 0; visuals[nvisuals]->visual.red_prec = 0; visuals[nvisuals]->visual.green_mask = 0; visuals[nvisuals]->visual.green_shift = 0; visuals[nvisuals]->visual.green_prec = 0; visuals[nvisuals]->visual.blue_mask = 0; visuals[nvisuals]->visual.blue_shift = 0; visuals[nvisuals]->visual.blue_prec = 0; } nvisuals += 1; } } if (visual_list) XFree (visual_list); for (i = 0; i < nvisuals; i++) { for (j = i+1; j < nvisuals; j++) { if (visuals[j]->visual.depth >= visuals[i]->visual.depth) { if ((visuals[j]->visual.depth == 8) && (visuals[i]->visual.depth == 8)) { if (visuals[j]->visual.type == GDK_VISUAL_PSEUDO_COLOR) { temp_visual = visuals[j]; visuals[j] = visuals[i]; visuals[i] = temp_visual; } else if ((visuals[i]->visual.type != GDK_VISUAL_PSEUDO_COLOR) && visuals[j]->visual.type > visuals[i]->visual.type) { temp_visual = visuals[j]; visuals[j] = visuals[i]; visuals[i] = temp_visual; } } else if ((visuals[j]->visual.depth > visuals[i]->visual.depth) || ((visuals[j]->visual.depth == visuals[i]->visual.depth) && (visuals[j]->visual.type > visuals[i]->visual.type))) { temp_visual = visuals[j]; visuals[j] = visuals[i]; visuals[i] = temp_visual; } } } } for (i = 0; i < nvisuals; i++) { if (default_xvisual->visualid == visuals[i]->xvisual->visualid) screen_x11->system_visual = visuals[i]; /* For now, we only support 8888 ARGB for the "rgba visual". * Additional formats (like ABGR) could be added later if they * turn up. */ if (visuals[i]->visual.depth == 32 && (visuals[i]->visual.red_mask == 0xff0000 && visuals[i]->visual.green_mask == 0x00ff00 && visuals[i]->visual.blue_mask == 0x0000ff)) { screen_x11->rgba_visual = GDK_VISUAL (visuals[i]); } } #ifdef G_ENABLE_DEBUG if (_gdk_debug_flags & GDK_DEBUG_MISC) for (i = 0; i < nvisuals; i++) g_message ("visual: %s: %d", visual_names[visuals[i]->visual.type], visuals[i]->visual.depth); #endif /* G_ENABLE_DEBUG */ screen_x11->navailable_depths = 0; for (i = 0; i < G_N_ELEMENTS (possible_depths); i++) { for (j = 0; j < nvisuals; j++) { if (visuals[j]->visual.depth == possible_depths[i]) { screen_x11->available_depths[screen_x11->navailable_depths++] = visuals[j]->visual.depth; break; } } } if (screen_x11->navailable_depths == 0) g_error ("unable to find a usable depth"); screen_x11->navailable_types = 0; for (i = 0; i < G_N_ELEMENTS (possible_types); i++) { for (j = 0; j < nvisuals; j++) { if (visuals[j]->visual.type == possible_types[i]) { screen_x11->available_types[screen_x11->navailable_types++] = visuals[j]->visual.type; break; } } } for (i = 0; i < nvisuals; i++) gdk_visual_add ((GdkVisual*) visuals[i]); if (screen_x11->navailable_types == 0) g_error ("unable to find a usable visual type"); screen_x11->visuals = visuals; screen_x11->nvisuals = nvisuals; }
uint2 MCScreenDC::getbyteorder() { return ImageByteOrder(dpy); }
long PngReadFileToPixmap (Display* display, Window window, GC gc, char* filename, Pixmap* pixmap, long* w, long* h) { int red_mask, green_mask, blue_mask; int red_shift, green_shift, blue_shift; int start_shift, msb_flag; unsigned int start_mask, udat; XWindowAttributes win_attr; FILE* ifile; long display_depth; png_byte sig[8]; png_infop info_ptr; png_structp png_ptr; png_uint_32 png_width; png_uint_32 png_height; int png_depth; int png_color_type; png_uint_32 png_row_bytes; png_uint_32 png_channels; long rwidth; long rheight; long components; unsigned char* buf; png_byte** png_row_ptrs; long vwidth; long vheight; long stretched; XImage* image; Visual* visual; Pixmap pix; int i; char* data1; unsigned char r,g,b; long ptr = 0; long ptr2 = 0; long j; red_mask = green_mask = blue_mask = 0; red_shift = green_shift = blue_shift = 0; ifile = fopen(filename,"r"); if (ifile == NULL){ return -1; } display_depth = XDefaultDepth(display,XDefaultScreen(display)); fread(sig, 1, 8, ifile); if (png_sig_cmp(sig, 0, 8)){ fclose(ifile); return -1; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL); if (png_ptr == NULL){ fclose(ifile); return -1; } info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL){ png_destroy_read_struct(&png_ptr, NULL, NULL); fclose(ifile); return -1; } png_init_io(png_ptr, ifile); png_set_sig_bytes(png_ptr, 8); png_read_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &png_width, &png_height, &png_depth, &png_color_type, NULL, NULL, NULL); if (png_depth == 16){ png_set_strip_16(png_ptr); } png_row_bytes = png_get_rowbytes(png_ptr, info_ptr); png_channels = png_get_channels(png_ptr, info_ptr); if (png_depth < 8){ if (png_color_type == PNG_COLOR_TYPE_GRAY ){ png_set_expand_gray_1_2_4_to_8(png_ptr); png_row_bytes = png_width; }else{ png_set_expand(png_ptr); png_row_bytes = png_width; png_row_bytes = png_width * 3; png_channels = 3; } } if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)){ png_set_expand(png_ptr); png_row_bytes = png_width; } if (png_color_type == PNG_COLOR_TYPE_GRAY || png_color_type == PNG_COLOR_TYPE_GRAY_ALPHA){ png_set_gray_to_rgb(png_ptr); png_row_bytes = png_width; } if (png_color_type == PNG_COLOR_TYPE_PALETTE){ png_set_palette_to_rgb(png_ptr); png_row_bytes = png_width * 3; png_channels = 3; } rwidth = png_width; rheight = png_height; components = png_channels; /* possible integer overflow? */ assert ((int) png_row_bytes > 0); assert ((int) png_height > 0); assert (((int)png_row_bytes) * ((int)png_height) * sizeof(png_byte) > 0); buf = rxvt_malloc(png_row_bytes * png_height * sizeof(png_byte)); if (buf == NULL){ rxvt_msg (DBG_ERROR, DBG_IMAGES, "png read error: out of memory..\n"); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(ifile); return -1; } /* possible integer overflow? */ assert ((int) png_height > 0); assert (sizeof(png_bytep) * ((int)png_height) > 0); png_row_ptrs = rxvt_malloc (sizeof(png_bytep)*png_height); if (png_row_ptrs == NULL){ rxvt_msg (DBG_ERROR, DBG_IMAGES, "png read error: out of memory..\n"); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); fclose(ifile); return -1; } for(i = 0; i < (int)png_height; i++){ png_row_ptrs[i] = (png_byte*)(buf + i * png_row_bytes); } png_read_image(png_ptr, png_row_ptrs); png_read_end(png_ptr,NULL); rxvt_free(png_row_ptrs); vwidth = *w; vheight = *h; stretched =0; if (*w == 0 || *h == 0){ *w = rwidth; *h = rheight; }else{ if ((long)((double)rwidth * vheight/vwidth) < rheight){ *w = (long)((double)vheight * rwidth/rheight); }else{ *h = (long)((double)vwidth * rheight/rwidth); } stretched = 1; } vwidth = *w; vheight = *h; image = 0; visual = XDefaultVisual(display,XDefaultScreen(display)); if (display_depth >16){ image = XCreateImage(display,visual, display_depth, ZPixmap,0,0,vwidth,vheight,32,0); }else if (display_depth >8){ image = XCreateImage(display,visual, display_depth, ZPixmap,0,0,vwidth,vheight,16,0); }else{ image = XCreateImage(display,visual, display_depth, ZPixmap,0,0,vwidth,vheight,8,0); } msb_flag = (ImageByteOrder(display) == MSBFirst)?1:0; if (XGetWindowAttributes(display, RootWindow(display, DefaultScreen(display)), &win_attr) == 0) { fclose(ifile); return -1; } if ((win_attr.depth == 24) || (win_attr.depth == 16)) { unsigned int n; if (win_attr.depth == 24) { start_shift = 24; start_mask = 0x80000000; }else{ start_shift = 8; start_mask = 0x8000; } red_mask = win_attr.visual->red_mask; red_shift = start_shift; n = start_mask; while (!(n & red_mask)) { n >>= 1; red_shift--; } green_mask = win_attr.visual->green_mask; green_shift = start_shift; n = start_mask; while (!(n & green_mask)) { n >>= 1; green_shift--; } blue_mask = win_attr.visual->blue_mask; blue_shift = start_shift; n = start_mask; while (!(n & blue_mask)) { n >>= 1; blue_shift--; } }
static Bool init_x11( char * error_buf ) { /*XXX*/ /* Namely, support for -display host:0.0 etc. */ XrmQuark common_quarks_list[20]; /*XXX change number of elements if necessary */ XrmQuarkList ql = common_quarks_list; XGCValues gcv; char *common_quarks = "String." "Blinkinvisibletime.blinkinvisibletime." "Blinkvisibletime.blinkvisibletime." "Clicktimeframe.clicktimeframe." "Doubleclicktimeframe.doubleclicktimeframe." "Wheeldown.wheeldown." "Wheelup.wheelup." "Submenudelay.submenudelay." "Scrollfirst.scrollfirst." "Scrollnext.scrollnext"; char * atom_names[AI_count] = { "RESOLUTION_X", "RESOLUTION_Y", "PIXEL_SIZE", "SPACING", "RELATIVE_WEIGHT", "FOUNDRY", "AVERAGE_WIDTH", "CHARSET_REGISTRY", "CHARSET_ENCODING", "CREATE_EVENT", "WM_DELETE_WINDOW", "WM_PROTOCOLS", "WM_TAKE_FOCUS", "_NET_WM_STATE", "_NET_WM_STATE_SKIP_TASKBAR", "_NET_WM_STATE_MAXIMIZED_VERT", "_NET_WM_STATE_MAXIMIZED_HORZ", "_NET_WM_NAME", "_NET_WM_ICON_NAME", "UTF8_STRING", "TARGETS", "INCR", "PIXEL", "FOREGROUND", "BACKGROUND", "_MOTIF_WM_HINTS", "_NET_WM_STATE_MODAL", "_NET_SUPPORTED", "_NET_WM_STATE_MAXIMIZED_HORIZ", "text/plain;charset=UTF-8", "_NET_WM_STATE_STAYS_ON_TOP", "_NET_CURRENT_DESKTOP", "_NET_WORKAREA", "_NET_WM_STATE_ABOVE" }; char hostname_buf[256], *hostname = hostname_buf; guts. click_time_frame = 200; guts. double_click_time_frame = 200; guts. visible_timeout = 500; guts. invisible_timeout = 500; guts. insert = true; guts. last_time = CurrentTime; guts. ri_head = guts. ri_tail = 0; DISP = XOpenDisplay( do_display); if (!DISP) { char * disp = getenv("DISPLAY"); snprintf( error_buf, 256, "Error: Can't open display '%s'", do_display ? do_display : (disp ? disp : "")); free( do_display); do_display = nil; return false; } free( do_display); do_display = nil; XSetErrorHandler( x_error_handler); guts.main_error_handler = x_error_handler; (void)x_io_error_handler; XCHECKPOINT; guts.connection = ConnectionNumber( DISP); { struct sockaddr name; unsigned int l = sizeof( name); guts. local_connection = getsockname( guts.connection, &name, &l) >= 0 && l == 0; } #ifdef HAVE_X11_EXTENSIONS_SHAPE_H if ( XShapeQueryExtension( DISP, &guts.shape_event, &guts.shape_error)) { guts. shape_extension = true; } else { guts. shape_extension = false; } #else guts. shape_extension = false; #endif #ifdef USE_MITSHM if ( !do_no_shmem && XShmQueryExtension( DISP)) { guts. shared_image_extension = true; guts. shared_image_completion_event = XShmGetEventBase( DISP) + ShmCompletion; } else { guts. shared_image_extension = false; guts. shared_image_completion_event = -1; } #else guts. shared_image_extension = false; guts. shared_image_completion_event = -1; #endif guts. randr_extension = false; #ifdef HAVE_X11_EXTENSIONS_XRANDR_H { int dummy; if ( XRRQueryExtension( DISP, &dummy, &dummy)) guts. randr_extension = true; } #endif #ifdef HAVE_X11_EXTENSIONS_XRENDER_H { int dummy; if ( XRenderQueryExtension( DISP, &dummy, &dummy)) guts. render_extension = true; } #endif #ifdef HAVE_X11_EXTENSIONS_XCOMPOSITE_H { int dummy; if (XQueryExtension(DISP, COMPOSITE_NAME, &guts.composite_opcode, &dummy, &dummy)) guts. composite_extension = true; } #endif XrmInitialize(); guts.db = get_database(); XrmStringToQuarkList( common_quarks, common_quarks_list); guts.qString = *ql++; guts.qBlinkinvisibletime = *ql++; guts.qblinkinvisibletime = *ql++; guts.qBlinkvisibletime = *ql++; guts.qblinkvisibletime = *ql++; guts.qClicktimeframe = *ql++; guts.qclicktimeframe = *ql++; guts.qDoubleclicktimeframe = *ql++; guts.qdoubleclicktimeframe = *ql++; guts.qWheeldown = *ql++; guts.qwheeldown = *ql++; guts.qWheelup = *ql++; guts.qwheelup = *ql++; guts.qSubmenudelay = *ql++; guts.qsubmenudelay = *ql++; guts.qScrollfirst = *ql++; guts.qscrollfirst = *ql++; guts.qScrollnext = *ql++; guts.qscrollnext = *ql++; guts. mouse_buttons = XGetPointerMapping( DISP, guts. buttons_map, 256); XCHECKPOINT; guts. limits. request_length = XMaxRequestSize( DISP); guts. limits. XDrawLines = guts. limits. request_length - 3; guts. limits. XFillPolygon = guts. limits. request_length - 4; guts. limits. XDrawSegments = (guts. limits. request_length - 3) / 2; guts. limits. XDrawRectangles = (guts. limits. request_length - 3) / 2; guts. limits. XFillRectangles = (guts. limits. request_length - 3) / 2; guts. limits. XFillArcs = guts. limits. XDrawArcs = (guts. limits. request_length - 3) / 3; XCHECKPOINT; SCREEN = DefaultScreen( DISP); /* XXX - return code? */ guts. root = RootWindow( DISP, SCREEN); guts. displaySize. x = DisplayWidth( DISP, SCREEN); guts. displaySize. y = DisplayHeight( DISP, SCREEN); XQueryBestCursor( DISP, guts. root, guts. displaySize. x, /* :-) */ guts. displaySize. y, &guts. cursor_width, &guts. cursor_height); XCHECKPOINT; TAILQ_INIT( &guts.paintq); TAILQ_INIT( &guts.peventq); TAILQ_INIT( &guts.bitmap_gc_pool); TAILQ_INIT( &guts.screen_gc_pool); TAILQ_INIT( &guts.argb_gc_pool); guts. currentFocusTime = CurrentTime; guts. windows = hash_create(); guts. menu_windows = hash_create(); guts. ximages = hash_create(); gcv. graphics_exposures = false; guts. menugc = XCreateGC( DISP, guts. root, GCGraphicsExposures, &gcv); guts. resolution. x = 25.4 * guts. displaySize. x / DisplayWidthMM( DISP, SCREEN) + .5; guts. resolution. y = 25.4 * DisplayHeight( DISP, SCREEN) / DisplayHeightMM( DISP, SCREEN) + .5; guts. depth = DefaultDepth( DISP, SCREEN); guts. idepth = get_idepth(); if ( guts.depth == 1) guts. qdepth = 1; else if ( guts.depth <= 4) guts. qdepth = 4; else if ( guts.depth <= 8) guts. qdepth = 8; else guts. qdepth = 24; guts. byte_order = ImageByteOrder( DISP); guts. bit_order = BitmapBitOrder( DISP); if ( BYTEORDER == LSB32 || BYTEORDER == LSB64) guts. machine_byte_order = LSBFirst; else if ( BYTEORDER == MSB32 || BYTEORDER == MSB64) guts. machine_byte_order = MSBFirst; else { sprintf( error_buf, "UAA_001: weird machine byte order: %08x", BYTEORDER); return false; } XInternAtoms( DISP, atom_names, AI_count, 0, guts. atoms); guts. null_pointer = nilHandle; guts. pointer_invisible_count = 0; guts. files = plist_create( 16, 16); prima_rebuild_watchers(); guts. wm_event_timeout = 100; guts. menu_timeout = 200; guts. scroll_first = 200; guts. scroll_next = 50; apc_timer_create( CURSOR_TIMER); apc_timer_set_timeout(CURSOR_TIMER, 2); apc_timer_create( MENU_TIMER); apc_timer_set_timeout( MENU_TIMER, guts. menu_timeout); apc_timer_create( MENU_UNFOCUS_TIMER); apc_timer_set_timeout( MENU_UNFOCUS_TIMER, 50); if ( !prima_init_clipboard_subsystem( error_buf)) return false; if ( !prima_init_color_subsystem( error_buf)) return false; if ( !prima_init_font_subsystem( error_buf)) return false; #ifdef WITH_GTK2 if (!prima_gtk_init()) return false; #endif bzero( &guts. cursor_gcv, sizeof( guts. cursor_gcv)); guts. cursor_gcv. cap_style = CapButt; guts. cursor_gcv. function = GXcopy; gethostname( hostname, 256); hostname[255] = '\0'; XStringListToTextProperty((char **)&hostname, 1, &guts. hostname); guts. net_wm_maximization = prima_wm_net_state_read_maximization( guts. root, NET_SUPPORTED); if ( do_sync) XSynchronize( DISP, true); return true; }
//-------------------------------------------------------------------------------------------------// bool GLXGLSupport::loadIcon(const std::string &name, Pixmap *pixmap, Pixmap *bitmap) { Image image; int width, height; char* imageData; if (! Ogre::ResourceGroupManager::getSingleton().resourceExists(ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, name)) return false; try { // Try to load image image.load(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if(image.getFormat() != PF_A8R8G8B8) { // Image format must be RGBA return false; } width = image.getWidth(); height = image.getHeight(); imageData = (char*)image.getData(); } catch(Exception &e) { // Could not find image; never mind return false; } int bitmapLineLength = (width + 7) / 8; int pixmapLineLength = 4 * width; char* bitmapData = (char*)malloc(bitmapLineLength * height); char* pixmapData = (char*)malloc(pixmapLineLength * height); int sptr = 0, dptr = 0; for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { if (ImageByteOrder(mXDisplay) == MSBFirst) { pixmapData[dptr + 0] = 0; pixmapData[dptr + 1] = imageData[sptr + 0]; pixmapData[dptr + 2] = imageData[sptr + 1]; pixmapData[dptr + 3] = imageData[sptr + 2]; } else { pixmapData[dptr + 3] = 0; pixmapData[dptr + 2] = imageData[sptr + 0]; pixmapData[dptr + 1] = imageData[sptr + 1]; pixmapData[dptr + 0] = imageData[sptr + 2]; } if(((unsigned char)imageData[sptr + 3])<128) { bitmapData[y*bitmapLineLength+(x>>3)] &= ~(1<<(x&7)); } else { bitmapData[y*bitmapLineLength+(x>>3)] |= 1<<(x&7); } sptr += 4; dptr += 4; }
/* Renders a scaled, cropped version of the RGBA XImage onto the window. */ static void draw_image (Display *dpy, Window window, Visual *v, GC gc, int w, int h, int depth, XImage *in) { XImage *out; int x, y, w2, h2, xoff, yoff; double xs, ys, s; unsigned long crpos=0, cgpos=0, cbpos=0, capos=0; /* bitfield positions */ unsigned long srpos=0, sgpos=0, sbpos=0; unsigned long srmsk=0, sgmsk=0, sbmsk=0; unsigned long srsiz=0, sgsiz=0, sbsiz=0; # ifdef HAVE_JWXYZ // BlackPixel has alpha: 0xFF000000. unsigned long black = BlackPixelOfScreen (DefaultScreenOfDisplay (dpy)); #else unsigned long black = 0; # endif xs = in->width / (double) w; ys = in->height / (double) h; s = (xs > ys ? ys : xs); w2 = in->width / s; h2 = in->height / s; xoff = (w - w2) / 2; yoff = (h - h2) / 2; /* Create a new image in the depth and bit-order of the server. */ out = XCreateImage (dpy, v, depth, ZPixmap, 0, 0, w, h, 8, 0); out->bitmap_bit_order = in->bitmap_bit_order; out->byte_order = in->byte_order; out->bitmap_bit_order = BitmapBitOrder (dpy); out->byte_order = ImageByteOrder (dpy); out->data = (char *) malloc (out->height * out->bytes_per_line); if (!out->data) abort(); /* Find the server's color masks. We could cache this and just do it once, but it's a small number of instructions compared to the per-pixel operations happening next. */ srmsk = out->red_mask; sgmsk = out->green_mask; sbmsk = out->blue_mask; if (!(srmsk && sgmsk && sbmsk)) abort(); /* No server color masks? */ decode_mask (srmsk, &srpos, &srsiz); decode_mask (sgmsk, &sgpos, &sgsiz); decode_mask (sbmsk, &sbpos, &sbsiz); /* 'in' is RGBA in client endianness. Convert to what the server wants. */ if (bigendian()) crpos = 24, cgpos = 16, cbpos = 8, capos = 0; else crpos = 0, cgpos = 8, cbpos = 16, capos = 24; /* Iterate the destination rectangle and pull in the corresponding scaled and cropped source pixel, or black. Nearest-neighbor is fine. */ for (y = 0; y < out->height; y++) { int iy = (out->height - y - yoff - 1) * s; for (x = 0; x < out->width; x++) { int ix = (x - xoff) * s; unsigned long p = (ix >= 0 && ix < in->width && iy >= 0 && iy < in->height ? XGetPixel (in, ix, iy) : black); /* unsigned char a = (p >> capos) & 0xFF; */ unsigned char b = (p >> cbpos) & 0xFF; unsigned char g = (p >> cgpos) & 0xFF; unsigned char r = (p >> crpos) & 0xFF; XPutPixel (out, x, y, ((r << srpos) | (g << sgpos) | (b << sbpos) | black)); } } XPutImage (dpy, window, gc, out, 0, 0, 0, 0, out->width, out->height); XDestroyImage (out); }
static int _ggi_xshm_create_ximage(struct ggi_visual *vis) { char target[GGI_MAX_APILEN]; ggi_mode tm; ggi_x_priv *priv; int err, i; XShmSegmentInfo *myshminfo; size_t shmsize; err = GGI_OK; priv = GGIX_PRIV(vis); DPRINT_MODE("X: MIT-SHM: Creating shared MIT-SHM buffer\n"); _ggi_xshm_free_ximage(vis); priv->priv = calloc(1, sizeof(XShmSegmentInfo)); if (!priv->priv) return GGI_ENOMEM; myshminfo = priv->priv; priv->ximage = XShmCreateImage(priv->disp, priv->vilist[priv->viidx].vi->visual, (unsigned)priv->vilist[priv->viidx].vi->depth, ZPixmap, /* format */ NULL, /* data */ myshminfo, /* shm object */ (unsigned)LIBGGI_VIRTX(vis), (unsigned)(LIBGGI_VIRTY(vis) * LIBGGI_MODE(vis)->frames)); if (priv->ximage == NULL) { DPRINT("XShmCreateImage() failed."); err = GGI_ENOMEM; goto err0; } shmsize = priv->ximage->bytes_per_line * LIBGGI_VIRTY(vis) * LIBGGI_MODE(vis)->frames; DPRINT_MODE("X: MIT-SHM: Try to shmget() a buffer of %lu (0x%lx) size bytes\n", shmsize, shmsize); myshminfo->shmid = shmget(IPC_PRIVATE, shmsize, IPC_CREAT | 0777); if (myshminfo->shmid == -1) { DPRINT("shmget() failed.\n"); priv->fb = NULL; err = GGI_ENOMEM; goto err1; } priv->fb = shmat(myshminfo->shmid,0,0); if (priv->fb == (void *)-1) { DPRINT("shmat() failed.\n"); priv->fb = NULL; err = GGI_ENOMEM; goto err1; } myshminfo->shmaddr = priv->ximage->data = (char *)priv->fb; DPRINT_MODE("X: MIT-SHM: shmat success at %p.\n", priv->fb); myshminfo->readOnly = False; ggLock(_ggi_global_lock); /* Entering protected section */ shmerror = 0; DPRINT_MODE("X: MIT-SHM: install error handler\n"); oldshmerrorhandler = XSetErrorHandler(shmerrorhandler); DPRINT_MODE("X: MIT-SHM: Attach shm to display\n"); XShmAttach(priv->disp, myshminfo); XSync(priv->disp, 0); DPRINT_MODE("X: MIT-SHM: restore error handler\n"); XSetErrorHandler(oldshmerrorhandler); if (shmerror) { ggUnlock(_ggi_global_lock); /* Exiting protected section */ DPRINT("can not access XSHM.\n"); err = GGI_ENOMEM; goto err2; } else { /* Take the shmid away so noone else can get it. */ shmctl(myshminfo->shmid, IPC_RMID, 0); DPRINT_MODE("X: MIT-SHM: ShmImage allocated\n"); } ggUnlock(_ggi_global_lock); /* Exiting protected section */ err = _ggi_create_dbs(vis); if (err) goto err3; /* We assume LIBGGI_MODE(vis) structure has already been filled out */ memcpy(&tm, LIBGGI_MODE(vis), sizeof(ggi_mode)); /* Make sure we do not fail due to physical size constraints, * which are meaningless on a memory visual. */ tm.size.x = tm.size.y = GGI_AUTO; i = 0; memset(target, '\0', sizeof(target)); i += snprintf(target, sizeof(target), "display-memory:-pixfmt="); _ggi_build_pixfmtstr(vis, target + i, sizeof(target) - i, 1); i = strlen(target); snprintf(target + i, sizeof(target) - i, ":-layout=%iplb%i:-physz=%i,%i:pointer", priv->ximage->bytes_per_line * LIBGGI_VIRTY(vis), priv->ximage->bytes_per_line, LIBGGI_MODE(vis)->size.x, LIBGGI_MODE(vis)->size.y); err = _ggi_openslave(vis, target, &tm); if (err) goto err3; priv->ximage->byte_order = ImageByteOrder(priv->disp); priv->ximage->bitmap_bit_order = BitmapBitOrder(priv->disp); vis->opdisplay->flush = GGI_XSHM_flush_ximage_child; DPRINT_MODE("X: MIT-SHM: XSHMImage and slave visual %p share buffer at %p\n", priv->slave, priv->fb); return GGI_OK; err3: fprintf(stderr, "XSHM extension failed to initialize. Retry with -noshm\n"); _ggi_xshm_free_ximage(vis); return err; err2: XShmDetach(priv->disp, myshminfo); shmdt(priv->fb); priv->fb = NULL; err1: XDestroyImage(priv->ximage); priv->ximage = NULL; err0: fprintf(stderr, "XSHM extension failed to initialize. Retry with -noshm\n"); return err; }
int XImageByteOrder(Display *dpy) { return (ImageByteOrder(dpy)); }