* Source/x11/XGServerWindow.m (swapColors): Made code more

explicit and removed additional copy before calling this function.
This function should now do what the comment above it says.
(alphaMaskForImage): Slightly cleaner code.
This commit is contained in:
fredkiefer 2020-02-07 10:13:48 +01:00
parent 022a988e97
commit c79b2a7b09
3 changed files with 98 additions and 69 deletions

View file

@ -1,3 +1,11 @@
2020-92-07 Fred Kiefer <FredKiefer@gmx.de>
* Source/x11/XGServerWindow.m (swapColors): Made code more
explicit and removed additional copy before calling this function.
This function should now do what the comment above it says.
(alphaMaskForImage): Slightly cleaner code.
* Source/x11/XGServerEvent.m: Prevent compiler warning by moving method.
2020-01-31 Sergii Stoian <stoyan255@gmail.com> 2020-01-31 Sergii Stoian <stoyan255@gmail.com>
* Source/x11/XGServerWindow.m (boundsForScreen:): check for number of * Source/x11/XGServerWindow.m (boundsForScreen:): check for number of

View file

@ -343,16 +343,6 @@ posixFileDescriptor: (NSPosixFileDescriptor*)fileDescriptor
return o; return o;
} }
- (void) initializeMouse
{
[self mouseOptionsChanged:nil];
[[NSDistributedNotificationCenter defaultCenter]
addObserver: self
selector: @selector(mouseOptionsChanged:)
name: NSUserDefaultsDidChangeNotification
object: nil];
}
- (void) mouseOptionsChanged: (NSNotification *)aNotif - (void) mouseOptionsChanged: (NSNotification *)aNotif
{ {
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
@ -390,6 +380,16 @@ posixFileDescriptor: (NSPosixFileDescriptor*)fileDescriptor
} }
} }
- (void) initializeMouse
{
[self mouseOptionsChanged: nil];
[[NSDistributedNotificationCenter defaultCenter]
addObserver: self
selector: @selector(mouseOptionsChanged:)
name: NSUserDefaultsDidChangeNotification
object: nil];
}
- (void) processEvent: (XEvent *) event - (void) processEvent: (XEvent *) event
{ {
static int clickCount = 1; static int clickCount = 1;

View file

@ -1459,9 +1459,10 @@ _get_next_prop_new_event(Display *display, XEvent *event, char *arg)
if (generic.rootName == 0) if (generic.rootName == 0)
{ {
const char *str = [[pInfo processName] UTF8String]; const char *str = [[pInfo processName] UTF8String];
int len = strlen(str) +1;
generic.rootName = malloc(strlen(str) + 1); generic.rootName = malloc(len);
strncpy(generic.rootName, str, strlen(str) + 1); strncpy(generic.rootName, str, len);
} }
/* /*
@ -2697,21 +2698,26 @@ static BOOL didCreatePixmaps;
Pixmap Pixmap
alphaMaskForImage(Display *xdpy, Drawable draw, const unsigned char *data, alphaMaskForImage(Display *xdpy, Drawable draw, const unsigned char *data,
int w, int h, int colors, int alpha_treshold) int w, int h, int colors, unsigned int alpha_treshold)
{ {
int j, i;
unsigned char ialpha;
Pixmap pix; Pixmap pix;
int bitmapSize = ((w + 7) >> 3) * h; // (w/8) rounded up times height // (w/8) rounded up times height
char *aData = calloc(1, bitmapSize); int bitmapSize = ((w + 7) >> 3) * h;
char *cData = aData; unsigned char *aData = calloc(1, bitmapSize);
if (colors == 4) if (colors == 4)
{ {
int k; int j, i;
unsigned int ialpha;
unsigned char *cData = aData;
// skip R, G, B
data += 3;
for (j = 0; j < h; j++) for (j = 0; j < h; j++)
{ {
k = 0; int k = 0;
for (i = 0; i < w; i++, k++) for (i = 0; i < w; i++, k++)
{ {
if (k > 7) if (k > 7)
@ -2719,22 +2725,19 @@ alphaMaskForImage(Display *xdpy, Drawable draw, const unsigned char *data,
cData++; cData++;
k = 0; k = 0;
} }
data += 3; // skip R, G, B ialpha = (unsigned int)(*data);
ialpha = (unsigned short)((char)*data++);
if (ialpha > alpha_treshold) if (ialpha > alpha_treshold)
{ {
*cData |= (0x01 << k); *cData |= (0x01 << k);
} }
data += 4;
} }
cData++; cData++;
} }
} }
else else
{ {
for (j = 0; j < bitmapSize; j++) memset(aData, 0xff, bitmapSize);
{
*cData++ = 0xff;
}
} }
pix = XCreatePixmapFromBitmapData(xdpy, draw, (char *)aData, w, h, pix = XCreatePixmapFromBitmapData(xdpy, draw, (char *)aData, w, h,
@ -2747,48 +2750,72 @@ alphaMaskForImage(Display *xdpy, Drawable draw, const unsigned char *data,
// Packed ARGB values are layed out as ARGB on big endian systems // Packed ARGB values are layed out as ARGB on big endian systems
// and as BGRA on little endian systems // and as BGRA on little endian systems
void void
swapColors(unsigned char *image_data, int width, int height, swapColors(unsigned char *image_data, NSBitmapImageRep *rep)
int samples_per_pixel, int bytes_per_row)
{ {
NSInteger x, y; unsigned char *target = image_data;
unsigned char *data; unsigned char *source = [rep bitmapData];
NSInteger width = [rep pixelsWide];
NSInteger height = [rep pixelsHigh];
NSInteger samples_per_pixel = [rep samplesPerPixel];
NSInteger bytes_per_row = [rep bytesPerRow];
unsigned char *r, *g, *b, *a; unsigned char *r, *g, *b, *a;
NSInteger x, y;
data = image_data;
r = data;
g = data + 1;
b = data + 2;
a = data + 3;
for (y = 0; y < height; y++)
{
unsigned char *d = data;
for (x = 0; x < width; x++)
{
#if GS_WORDS_BIGENDIAN #if GS_WORDS_BIGENDIAN
// RGBA -> ARGB // RGBA -> ARGB
unsigned char _d = d[3]; r = target + 1;
*r = _d; g = target + 2;
*g = d[0]; b = target + 3;
*b = d[1]; a = target;
*a = d[2];
#else #else
// RGBA -> BGRA // RGBA -> BGRA
unsigned char _d = d[0]; r = target + 2;
*r = d[2]; g = target + 1;
// *g = d[1]; b = target;
*b = _d; a = target + 3;
// *a = d[3];
#endif #endif
if (samples_per_pixel == 4)
{
for (y = 0; y < height; y++)
{
unsigned char *d = source;
for (x = 0; x < width; x++)
{
*r = d[0];
*g = d[1];
*b = d[2];
*a = d[3];
r += 4; r += 4;
g += 4; g += 4;
b += 4; b += 4;
a += 4; a += 4;
d += samples_per_pixel; d += samples_per_pixel;
} }
data += bytes_per_row; source += bytes_per_row;
}
}
else if (samples_per_pixel == 3)
{
for (y = 0; y < height; y++)
{
unsigned char *d = source;
for (x = 0; x < width; x++)
{
*r = d[0];
*g = d[1];
*b = d[2];
*a = 255;
r += 4;
g += 4;
b += 4;
a += 4;
d += samples_per_pixel;
}
source += bytes_per_row;
}
} }
} }
- (int) _createAppIconPixmaps - (int) _createAppIconPixmaps
{ {
@ -2812,9 +2839,7 @@ swapColors(unsigned char *image_data, int width, int height,
colors = [rep samplesPerPixel]; colors = [rep samplesPerPixel];
rxImage = RCreateXImage(rcontext, rcontext->depth, width, height); rxImage = RCreateXImage(rcontext, rcontext->depth, width, height);
memcpy((char*)rxImage->image->data, [rep bitmapData], width * height * colors); swapColors((unsigned char *)rxImage->image->data, rep);
swapColors((unsigned char *)rxImage->image->data,
width, height, colors, [rep bytesPerRow]);
xIconPixmap = XCreatePixmap(dpy, rcontext->drawable, xIconPixmap = XCreatePixmap(dpy, rcontext->drawable,
width, height, rcontext->depth); width, height, rcontext->depth);
@ -4232,7 +4257,6 @@ xgps_cursor_image(Display *xdpy, Drawable draw, const unsigned char *data,
NSBitmapImageRep *rep; NSBitmapImageRep *rep;
int w, h; int w, h;
int colors; int colors;
const unsigned char *data;
rep = getStandardBitmap(image); rep = getStandardBitmap(image);
if (rep == nil) if (rep == nil)
@ -4252,7 +4276,6 @@ xgps_cursor_image(Display *xdpy, Drawable draw, const unsigned char *data,
w = [rep pixelsWide]; w = [rep pixelsWide];
h = [rep pixelsHigh]; h = [rep pixelsHigh];
colors = [rep samplesPerPixel]; colors = [rep samplesPerPixel];
data = [rep bitmapData];
if (w <= 0 || h <= 0) if (w <= 0 || h <= 0)
{ {
@ -4276,10 +4299,7 @@ xgps_cursor_image(Display *xdpy, Drawable draw, const unsigned char *data,
xcursorImage->yhot = hotp.y; xcursorImage->yhot = hotp.y;
// Copy the data from the image rep to the Xcursor structure // Copy the data from the image rep to the Xcursor structure
memcpy((char*)xcursorImage->pixels, data, w * h * colors); swapColors((unsigned char *)xcursorImage->pixels, rep);
swapColors((unsigned char *)xcursorImage->pixels, w, h,
colors, [rep bytesPerRow]);
cursor = XcursorImageLoadCursor(dpy, xcursorImage); cursor = XcursorImageLoadCursor(dpy, xcursorImage);
XcursorImageDestroy(xcursorImage); XcursorImageDestroy(xcursorImage);
@ -4289,6 +4309,7 @@ xgps_cursor_image(Display *xdpy, Drawable draw, const unsigned char *data,
Pixmap source, mask; Pixmap source, mask;
unsigned int maxw, maxh; unsigned int maxw, maxh;
XColor fg, bg; XColor fg, bg;
const unsigned char *data = [rep bitmapData];
/* FIXME: Handle this better or return an error? */ /* FIXME: Handle this better or return an error? */
XQueryBestCursor(dpy, ROOT, w, h, &maxw, &maxh); XQueryBestCursor(dpy, ROOT, w, h, &maxw, &maxh);