/* Utilities and defines for using XPM without X on Haiku Copyright (C) 2021 Free Software Foundation, Inc. This file is part of GNU Emacs. GNU Emacs is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. GNU Emacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ #include #include #include #include #include "dispextern.h" #include "haiku_support.h" #define FOR_MSW #include "xpm_be.h" #undef FOR_MSW /* Defined in haikufns.c. */ extern int haiku_get_color (const char *name, Emacs_Color *color); extern unsigned long haiku_get_pixel (haiku bitmap, int x, int y); extern void haiku_put_pixel (haiku bitmap, int x, int y, unsigned long pixel); Visual * XDefaultVisual (Display *dpy, Screen *screen) { return NULL; } Screen * XDefaultScreen (Display *d) { return NULL; } int XDefaultDepth (Display *display, Screen *screen) { return 24; } Colormap * XDefaultColormap (Display *display, Screen *screen) { return NULL; } int XParseColor (Display *d, Colormap *cmap, char *name, XColor *color) { int r, g, b; int okay; if (name == NULL) return (0); Emacs_Color ecol; okay = !haiku_get_color (name, &ecol); if (okay) { r = ecol.red / 256; g = ecol.green / 256; b = ecol.blue / 256; } if (okay) { color->red = (uint8_t) r; color->green = (uint8_t) g; color->blue = (uint8_t) b; color->pixel = ((color->red << 16) | (color->green << 8) | color->blue); return 1; } else return 0; } int XAllocColor (Display *d, Colormap cmap, XColor *color) { return 1; } void XQueryColors (Display *display, Colormap *colormap, XColor *xcolors, int ncolors) { for (int i = 0; i < ncolors; ++i) { xcolors[i].red = xcolors[i].pixel >> 16 & 0xff; xcolors[i].green = xcolors[i].pixel >> 8 & 0xff; xcolors[i].blue = xcolors[i].pixel & 0xff; } } XImage * XCreateImage (Display *d, Visual *v, int depth, int format, int x, int y, int width, int height, int pad, int foo) { XImage *img = (XImage *) malloc (sizeof (XImage)); if (img) { img->bitmap = BBitmap_new (width + 1, height + 1, depth == 1); img->width = width + 1; img->height = height + 1; img->depth = depth == 1 ? 1 : 32; } return img; } int XFreeColors (Display *d, Colormap cmap, Pixel *pixels, int npixels, unsigned long planes) { return 0; } void XImageFree (XImage *img) { if (img) free (img); } void XDestroyImage (XImage *img) { if (img) { BBitmap_free (img->bitmap); XImageFree (img); } } void * boundCheckingMalloc (long size) { return malloc (size); } void * boundCheckingCalloc (long n, long s) { return calloc (n, s); } void * boundCheckingRealloc (void *p, long s) { return realloc (p, s); } void XPutPixel (XImage *img, int x, int y, unsigned long p) { if (img->depth == 1) haiku_put_pixel (img->bitmap, x, y, p); else haiku_put_pixel (img->bitmap, x, y, p | ((unsigned long) 255) << 24); } unsigned long XGetPixel (XImage *img, int x, int y) { return haiku_get_pixel (img->bitmap, x, y); }