diff options
| author | Jan Djärv | 2015-05-15 11:31:38 +0200 |
|---|---|---|
| committer | Jan Djärv | 2015-05-15 11:32:22 +0200 |
| commit | 67a878f78f879ce534232408c34dd11f42dd802b (patch) | |
| tree | 6212d267c59134574cec984bcdab81c5285282d6 /src | |
| parent | b1c23fb94072cca7f08ea5f50430916b9ea168e6 (diff) | |
| download | emacs-67a878f78f879ce534232408c34dd11f42dd802b.tar.gz emacs-67a878f78f879ce534232408c34dd11f42dd802b.zip | |
Honor :fore/background for XBM on NS (Bug#14969).
* nsterm.h (EmacsImage): Add xbm_fg, remove initFromSkipXBM,
initFromXBM takes bg, fg args, remove flip arg.
(ns_image_from_XBM): Add bg, fg args.
* image.c (x_create_bitmap_from_data)
(Create_Pixmap_From_Bitmap_Data): ns_image_from_XBM takes bg, fg args.
* nsimage.m (ns_image_from_XBM): Add fg, bg args, pass to initFromXBM.
Remove flip arg.
(initFromSkipXBM): Move code to initFromXBM.
(initFromXBM): Actually set fg and bg, instead of playing alpha games.
Use fg, bg from args (Bug#14969). Remove if (length) section, was always
false.
Remove bit flipping (bitPat, swt), generated incorrect images when
width/height wasn't a multiple of 8.
(setXBMColor:): Modify planes by comparing to saved xbm_fg.
* nsterm.m (ns_draw_fringe_bitmap): initFromXBM takes fg, bg args, remove
flip arg.
Diffstat (limited to 'src')
| -rw-r--r-- | src/image.c | 4 | ||||
| -rw-r--r-- | src/nsimage.m | 95 | ||||
| -rw-r--r-- | src/nsterm.h | 8 | ||||
| -rw-r--r-- | src/nsterm.m | 2 |
4 files changed, 53 insertions, 56 deletions
diff --git a/src/image.c b/src/image.c index 5e4843834c1..d7f48bd81dd 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -233,7 +233,7 @@ x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsi | |||
| 233 | #endif /* HAVE_NTGUI */ | 233 | #endif /* HAVE_NTGUI */ |
| 234 | 234 | ||
| 235 | #ifdef HAVE_NS | 235 | #ifdef HAVE_NS |
| 236 | void *bitmap = ns_image_from_XBM (bits, width, height); | 236 | void *bitmap = ns_image_from_XBM (bits, width, height, 0, 0); |
| 237 | if (!bitmap) | 237 | if (!bitmap) |
| 238 | return -1; | 238 | return -1; |
| 239 | #endif | 239 | #endif |
| @@ -2648,7 +2648,7 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data, | |||
| 2648 | convert_mono_to_color_image (f, img, fg, bg); | 2648 | convert_mono_to_color_image (f, img, fg, bg); |
| 2649 | 2649 | ||
| 2650 | #elif defined (HAVE_NS) | 2650 | #elif defined (HAVE_NS) |
| 2651 | img->pixmap = ns_image_from_XBM (data, img->width, img->height); | 2651 | img->pixmap = ns_image_from_XBM (data, img->width, img->height, fg, bg); |
| 2652 | 2652 | ||
| 2653 | #else | 2653 | #else |
| 2654 | img->pixmap = | 2654 | img->pixmap = |
diff --git a/src/nsimage.m b/src/nsimage.m index f37ad38ad1e..3e90226cbf6 100644 --- a/src/nsimage.m +++ b/src/nsimage.m | |||
| @@ -53,12 +53,13 @@ int image_trace_num = 0; | |||
| 53 | ========================================================================== */ | 53 | ========================================================================== */ |
| 54 | 54 | ||
| 55 | void * | 55 | void * |
| 56 | ns_image_from_XBM (unsigned char *bits, int width, int height) | 56 | ns_image_from_XBM (unsigned char *bits, int width, int height, |
| 57 | unsigned long fg, unsigned long bg) | ||
| 57 | { | 58 | { |
| 58 | NSTRACE (ns_image_from_XBM); | 59 | NSTRACE (ns_image_from_XBM); |
| 59 | return [[EmacsImage alloc] initFromXBM: bits | 60 | return [[EmacsImage alloc] initFromXBM: bits |
| 60 | width: width height: height | 61 | width: width height: height |
| 61 | flip: YES]; | 62 | fg: fg bg: bg]; |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | void * | 65 | void * |
| @@ -204,14 +205,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 204 | 205 | ||
| 205 | 206 | ||
| 206 | - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h | 207 | - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h |
| 207 | flip: (BOOL)flip | 208 | fg: (unsigned long)fg bg: (unsigned long)bg |
| 208 | { | ||
| 209 | return [self initFromSkipXBM: bits width: w height: h flip: flip length: 0]; | ||
| 210 | } | ||
| 211 | |||
| 212 | |||
| 213 | - initFromSkipXBM: (unsigned char *)bits width: (int)w height: (int)h | ||
| 214 | flip: (BOOL)flip length: (int)length; | ||
| 215 | { | 209 | { |
| 216 | int bpr = (w + 7) / 8; | 210 | int bpr = (w + 7) / 8; |
| 217 | unsigned char *planes[5]; | 211 | unsigned char *planes[5]; |
| @@ -226,57 +220,58 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 226 | bytesPerRow: w bitsPerPixel: 0]; | 220 | bytesPerRow: w bitsPerPixel: 0]; |
| 227 | 221 | ||
| 228 | [bmRep getBitmapDataPlanes: planes]; | 222 | [bmRep getBitmapDataPlanes: planes]; |
| 223 | |||
| 224 | if (fg == 0 && bg == 0) | ||
| 225 | bg = 0xffffff; | ||
| 226 | |||
| 229 | { | 227 | { |
| 230 | /* pull bits out to set the (bytewise) alpha mask */ | 228 | /* pull bits out to set the (bytewise) alpha mask */ |
| 231 | int i, j, k; | 229 | int i, j, k; |
| 232 | unsigned char *s = bits; | 230 | unsigned char *s = bits; |
| 231 | unsigned char *rr = planes[0]; | ||
| 232 | unsigned char *gg = planes[1]; | ||
| 233 | unsigned char *bb = planes[2]; | ||
| 233 | unsigned char *alpha = planes[3]; | 234 | unsigned char *alpha = planes[3]; |
| 234 | unsigned char swt[16] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, | 235 | unsigned char fgr = (fg >> 16) & 0xff; |
| 235 | 3, 11, 7, 15}; | 236 | unsigned char fgg = (fg >> 8) & 0xff; |
| 236 | unsigned char c, bitPat; | 237 | unsigned char fgb = fg & 0xff; |
| 237 | 238 | unsigned char bgr = (bg >> 16) & 0xff; | |
| 238 | for (j = 0; j < h; j++) | 239 | unsigned char bgg = (bg >> 8) & 0xff; |
| 239 | for (i = 0; i < bpr; i++) | 240 | unsigned char bgb = bg & 0xff; |
| 241 | unsigned char c; | ||
| 242 | |||
| 243 | int idx = 0; | ||
| 244 | for (j = 0; j < h; ++j) | ||
| 245 | for (i = 0; i < w; ) | ||
| 240 | { | 246 | { |
| 241 | if (length) | 247 | c = *s++; |
| 248 | for (k = 0; i < w && k < 8; ++k, ++i) | ||
| 242 | { | 249 | { |
| 243 | unsigned char s1, s2; | 250 | *alpha++ = 0xff; |
| 244 | while (*s++ != 'x' && s < bits + length); | 251 | if (c & 1) |
| 245 | if (s >= bits + length) | ||
| 246 | { | 252 | { |
| 247 | [bmRep release]; | 253 | *rr++ = fgr; |
| 248 | bmRep = nil; | 254 | *gg++ = fgg; |
| 249 | return nil; | 255 | *bb++ = fgb; |
| 250 | } | 256 | } |
| 251 | #define hexchar(x) ('0' <= (x) && (x) <= '9' ? (x) - '0' : (x) - 'a' + 10) | 257 | else |
| 252 | s1 = *s++; | 258 | { |
| 253 | s2 = *s++; | 259 | *rr++ = bgr; |
| 254 | c = hexchar (s1) * 0x10 + hexchar (s2); | 260 | *gg++ = bgg; |
| 255 | } | 261 | *bb++ = bgb; |
| 256 | else | 262 | } |
| 257 | c = *s++; | 263 | idx++; |
| 258 | 264 | c >>= 1; | |
| 259 | bitPat = flip ? swt[c >> 4] | (swt[c & 0xf] << 4) : c ^ 255; | ||
| 260 | for (k =0; k<8; k++) | ||
| 261 | { | ||
| 262 | *alpha++ = (bitPat & 0x80) ? 0xff : 0; | ||
| 263 | bitPat <<= 1; | ||
| 264 | } | 265 | } |
| 265 | } | 266 | } |
| 266 | } | 267 | } |
| 267 | 268 | ||
| 269 | xbm_fg = fg; | ||
| 268 | [self addRepresentation: bmRep]; | 270 | [self addRepresentation: bmRep]; |
| 269 | |||
| 270 | memset (planes[0], 0, w*h); | ||
| 271 | memset (planes[1], 0, w*h); | ||
| 272 | memset (planes[2], 0, w*h); | ||
| 273 | [self setXBMColor: [NSColor blackColor]]; | ||
| 274 | return self; | 271 | return self; |
| 275 | } | 272 | } |
| 276 | 273 | ||
| 277 | 274 | /* Set color for a bitmap image. */ | |
| 278 | /* Set color for a bitmap image (see initFromSkipXBM). Note that the alpha | ||
| 279 | is used as a mask, so we just memset the entire array. */ | ||
| 280 | - setXBMColor: (NSColor *)color | 275 | - setXBMColor: (NSColor *)color |
| 281 | { | 276 | { |
| 282 | NSSize s = [self size]; | 277 | NSSize s = [self size]; |
| @@ -296,19 +291,21 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 296 | 291 | ||
| 297 | [bmRep getBitmapDataPlanes: planes]; | 292 | [bmRep getBitmapDataPlanes: planes]; |
| 298 | 293 | ||
| 299 | /* we used to just do this, but Cocoa seems to have a bug when rendering | ||
| 300 | an alpha-masked image onto a dark background where it bloats the mask */ | ||
| 301 | /* memset (planes[0..2], r, g, b*0xff, len); */ | ||
| 302 | { | 294 | { |
| 303 | int i, len = s.width*s.height; | 295 | int i, len = s.width*s.height; |
| 304 | int rr = r * 0xff, gg = g * 0xff, bb = b * 0xff; | 296 | int rr = r * 0xff, gg = g * 0xff, bb = b * 0xff; |
| 305 | for (i =0; i<len; i++) | 297 | unsigned char fgr = (xbm_fg >> 16) & 0xff; |
| 306 | if (planes[3][i] != 0) | 298 | unsigned char fgg = (xbm_fg >> 8) & 0xff; |
| 299 | unsigned char fgb = xbm_fg & 0xff; | ||
| 300 | |||
| 301 | for (i = 0; i < len; ++i) | ||
| 302 | if (planes[0][i] == fgr && planes[1][i] == fgg && planes[2][i] == fgb) | ||
| 307 | { | 303 | { |
| 308 | planes[0][i] = rr; | 304 | planes[0][i] = rr; |
| 309 | planes[1][i] = gg; | 305 | planes[1][i] = gg; |
| 310 | planes[2][i] = bb; | 306 | planes[2][i] = bb; |
| 311 | } | 307 | } |
| 308 | xbm_fg = ((rr << 16) & 0xff) + ((gg << 8) & 0xff) + (bb & 0xff); | ||
| 312 | } | 309 | } |
| 313 | 310 | ||
| 314 | return self; | 311 | return self; |
diff --git a/src/nsterm.h b/src/nsterm.h index 9035ee1a328..d8ffd93a71b 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -341,13 +341,12 @@ typedef float EmacsCGFloat; | |||
| 341 | NSBitmapImageRep *bmRep; /* used for accessing pixel data */ | 341 | NSBitmapImageRep *bmRep; /* used for accessing pixel data */ |
| 342 | unsigned char *pixmapData[5]; /* shortcut to access pixel data */ | 342 | unsigned char *pixmapData[5]; /* shortcut to access pixel data */ |
| 343 | NSColor *stippleMask; | 343 | NSColor *stippleMask; |
| 344 | unsigned long xbm_fg; | ||
| 344 | } | 345 | } |
| 345 | + allocInitFromFile: (Lisp_Object)file; | 346 | + allocInitFromFile: (Lisp_Object)file; |
| 346 | - (void)dealloc; | 347 | - (void)dealloc; |
| 347 | - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h | 348 | - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h |
| 348 | flip: (BOOL)flip; | 349 | fg: (unsigned long)fg bg: (unsigned long)bg; |
| 349 | - initFromSkipXBM: (unsigned char *)bits width: (int)w height: (int)h | ||
| 350 | flip: (BOOL)flip length: (int)length; | ||
| 351 | - setXBMColor: (NSColor *)color; | 350 | - setXBMColor: (NSColor *)color; |
| 352 | - initForXPMWithDepth: (int)depth width: (int)width height: (int)height; | 351 | - initForXPMWithDepth: (int)depth width: (int)width height: (int)height; |
| 353 | - (void)setPixmapData; | 352 | - (void)setPixmapData; |
| @@ -864,7 +863,8 @@ extern void syms_of_nsselect (void); | |||
| 864 | 863 | ||
| 865 | /* From nsimage.m, needed in image.c */ | 864 | /* From nsimage.m, needed in image.c */ |
| 866 | struct image; | 865 | struct image; |
| 867 | extern void *ns_image_from_XBM (unsigned char *bits, int width, int height); | 866 | extern void *ns_image_from_XBM (unsigned char *bits, int width, int height, |
| 867 | unsigned long fg, unsigned long bg); | ||
| 868 | extern void *ns_image_for_XPM (int width, int height, int depth); | 868 | extern void *ns_image_for_XPM (int width, int height, int depth); |
| 869 | extern void *ns_image_from_file (Lisp_Object file); | 869 | extern void *ns_image_from_file (Lisp_Object file); |
| 870 | extern bool ns_load_image (struct frame *f, struct image *img, | 870 | extern bool ns_load_image (struct frame *f, struct image *img, |
diff --git a/src/nsterm.m b/src/nsterm.m index 187086cf826..6a4d0a6ad23 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -2317,7 +2317,7 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row, | |||
| 2317 | for (i = 0; i < len; i++) | 2317 | for (i = 0; i < len; i++) |
| 2318 | cbits[i] = ~(bits[i] & 0xff); | 2318 | cbits[i] = ~(bits[i] & 0xff); |
| 2319 | img = [[EmacsImage alloc] initFromXBM: cbits width: 8 height: p->h | 2319 | img = [[EmacsImage alloc] initFromXBM: cbits width: 8 height: p->h |
| 2320 | flip: NO]; | 2320 | fg: 0 bg: 0]; |
| 2321 | bimgs[p->which - 1] = img; | 2321 | bimgs[p->which - 1] = img; |
| 2322 | xfree (cbits); | 2322 | xfree (cbits); |
| 2323 | } | 2323 | } |