aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsimage.m
diff options
context:
space:
mode:
authorAlan Third2019-12-06 16:49:25 +0000
committerAlan Third2019-12-10 20:38:21 +0000
commit9546a2a0d6653a7d930cda722f5babbebb0a1d0c (patch)
tree11b17204fb9b2e11899f3298bee2f70483586341 /src/nsimage.m
parent33a37360defdc08a5d8eeabffef96f8571d3b608 (diff)
downloademacs-9546a2a0d6653a7d930cda722f5babbebb0a1d0c.tar.gz
emacs-9546a2a0d6653a7d930cda722f5babbebb0a1d0c.zip
Fix XBM files on NS (bug#26133)
Reinstate some of the functionality removed in commit 67a878f78f879ce534232408c34dd11f42dd802b. * src/nsimage.m (ns_image_from_XBM): Use new reverseBytes argument. ([EmacsImage initFromXBM:width:height:fg:bg:reverseBytes:]): Add ability to reverse the contents of each byte for use with XBMs, while still working with fringe bitmaps. * src/nsterm.h ([EmacsImage initFromXBM:width:height:fg:bg:reverseBytes:]): Modified function definition. * src/nsterm.m (ns_draw_fringe_bitmap): Use new reverseBytes argument.
Diffstat (limited to 'src/nsimage.m')
-rw-r--r--src/nsimage.m17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/nsimage.m b/src/nsimage.m
index e1408c77f58..25d3b2299cb 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -52,7 +52,7 @@ ns_image_from_XBM (char *bits, int width, int height,
52 NSTRACE ("ns_image_from_XBM"); 52 NSTRACE ("ns_image_from_XBM");
53 return [[EmacsImage alloc] initFromXBM: (unsigned char *) bits 53 return [[EmacsImage alloc] initFromXBM: (unsigned char *) bits
54 width: width height: height 54 width: width height: height
55 fg: fg bg: bg]; 55 fg: fg bg: bg reverseBytes: YES];
56} 56}
57 57
58void * 58void *
@@ -228,7 +228,8 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
228/* Create image from monochrome bitmap. If both FG and BG are 0 228/* Create image from monochrome bitmap. If both FG and BG are 0
229 (black), set the background to white and make it transparent. */ 229 (black), set the background to white and make it transparent. */
230- (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h 230- (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
231 fg: (unsigned long)fg bg: (unsigned long)bg 231 fg: (unsigned long)fg bg: (unsigned long)bg
232 reverseBytes: (BOOL)reverse
232{ 233{
233 unsigned char *planes[5]; 234 unsigned char *planes[5];
234 unsigned char bg_alpha = 0xff; 235 unsigned char bg_alpha = 0xff;
@@ -252,6 +253,8 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
252 253
253 { 254 {
254 /* Pull bits out to set the (bytewise) alpha mask. */ 255 /* Pull bits out to set the (bytewise) alpha mask. */
256 unsigned char swt[16] = {0, 8, 4, 12, 2, 10, 6, 14,
257 1, 9, 5, 13, 3, 11, 7, 15};
255 int i, j, k; 258 int i, j, k;
256 unsigned char *s = bits; 259 unsigned char *s = bits;
257 unsigned char *rr = planes[0]; 260 unsigned char *rr = planes[0];
@@ -266,11 +269,18 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
266 unsigned char bgb = bg & 0xff; 269 unsigned char bgb = bg & 0xff;
267 unsigned char c; 270 unsigned char c;
268 271
269 int idx = 0;
270 for (j = 0; j < h; ++j) 272 for (j = 0; j < h; ++j)
271 for (i = 0; i < w; ) 273 for (i = 0; i < w; )
272 { 274 {
273 c = *s++; 275 c = *s++;
276
277 /* XBM files have the bits in reverse order within each byte
278 as compared to our fringe bitmaps. This function deals
279 with both so has to be able to handle the bytes in either
280 order. */
281 if (reverse)
282 c = swt[c >> 4] | (swt[c & 0xf] << 4);
283
274 for (k = 0; i < w && k < 8; ++k, ++i) 284 for (k = 0; i < w && k < 8; ++k, ++i)
275 { 285 {
276 if (c & 0x80) 286 if (c & 0x80)
@@ -287,7 +297,6 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
287 *bb++ = bgb; 297 *bb++ = bgb;
288 *alpha++ = bg_alpha; 298 *alpha++ = bg_alpha;
289 } 299 }
290 idx++;
291 c <<= 1; 300 c <<= 1;
292 } 301 }
293 } 302 }