#endif /* !USE_CAIRO */
#endif /* HAVE_X_WINDOWS */
-#ifdef USE_CAIRO
-#define GET_PIXEL image_pix_context_get_pixel
-#define PUT_PIXEL image_pix_container_put_pixel
-#define NO_PIXMAP 0
-
-#define PIX_MASK_RETAIN 0
-#define PIX_MASK_DRAW 255
-
+#if defined(USE_CAIRO) || defined(HAVE_NS)
#define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
#define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
#define RED16_FROM_ULONG(color) (RED_FROM_ULONG (color) * 0x101)
#define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG (color) * 0x101)
#define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG (color) * 0x101)
+#endif
+
+#ifdef USE_CAIRO
+#define GET_PIXEL image_pix_context_get_pixel
+#define PUT_PIXEL image_pix_container_put_pixel
+#define NO_PIXMAP 0
+
+#define PIX_MASK_RETAIN 0
+#define PIX_MASK_DRAW 255
static unsigned long image_alloc_image_color (struct frame *, struct image *,
Lisp_Object, unsigned long);
ns_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
NSColor *col;
- EmacsCGFloat r, g, b, alpha;
/* Must block_input, because ns_lisp_to_color does block/unblock_input
which means that col may be deallocated in its unblock_input if there
[f->output_data.ns->foreground_color release];
f->output_data.ns->foreground_color = col;
- [col getRed: &r green: &g blue: &b alpha: &alpha];
- FRAME_FOREGROUND_PIXEL (f) =
- ARGB_TO_ULONG ((unsigned long) (alpha * 0xff),
- (unsigned long) (r * 0xff),
- (unsigned long) (g * 0xff),
- (unsigned long) (b * 0xff));
+ FRAME_FOREGROUND_PIXEL (f) = [col unsignedLong];
if (FRAME_NS_VIEW (f))
{
struct face *face;
NSColor *col;
NSView *view = FRAME_NS_VIEW (f);
- EmacsCGFloat r, g, b, alpha;
+ EmacsCGFloat alpha;
block_input ();
if (ns_lisp_to_color (arg, &col))
[f->output_data.ns->background_color release];
f->output_data.ns->background_color = col;
- [col getRed: &r green: &g blue: &b alpha: &alpha];
- FRAME_BACKGROUND_PIXEL (f) =
- ARGB_TO_ULONG ((unsigned long) (alpha * 0xff),
- (unsigned long) (r * 0xff),
- (unsigned long) (g * 0xff),
- (unsigned long) (b * 0xff));
+ FRAME_BACKGROUND_PIXEL (f) = [col unsignedLong];
+ alpha = [col alphaComponent];
if (view != nil)
{
+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (NSColor *)colorUsingDefaultColorSpace;
-
+- (unsigned long)unsignedLong;
@end
int height, width, depth;
};
-/* This maps between emacs color indices and NSColor objects. */
-struct ns_color_table
-{
- ptrdiff_t size;
- ptrdiff_t avail;
-#ifdef __OBJC__
- NSColor **colors;
- NSMutableSet *empty_indices;
-#else
- void **items;
- void *availIndices;
-#endif
-};
-#define NS_COLOR_CAPACITY 256
-
-#define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
-#define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
-
-#define ALPHA_FROM_ULONG(color) ((color) >> 24)
-#define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
-#define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
-#define BLUE_FROM_ULONG(color) ((color) & 0xff)
-
-/* Do not change `* 0x101' in the following lines to `<< 8'. If
- changed, image masks in 1-bit depth will not work. */
-#define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
-#define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
-#define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
-
#ifdef NS_IMPL_GNUSTEP
/* this extends font backend font */
struct nsfont_info
ptrdiff_t bitmaps_size;
ptrdiff_t bitmaps_last;
- struct ns_color_table *color_table;
+#ifdef __OBJC__
+ NSMutableArray *color_table;
+#else
+ void *color_table;
+#endif
/* DPI resolution of this screen */
double resx, resy;
return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]];
}
++ (NSColor *)colorWithUnsignedLong:(unsigned long)c
+ hasAlpha:(BOOL)alpha
+{
+ EmacsCGFloat a = (double)((c >> 24) & 0xff) / 255.0;
+ EmacsCGFloat r = (double)((c >> 16) & 0xff) / 255.0;
+ EmacsCGFloat g = (double)((c >> 8) & 0xff) / 255.0;
+ EmacsCGFloat b = (double)(c & 0xff) / 255.0;
+
+ return [NSColor colorForEmacsRed:r green:g blue:b
+ alpha:(alpha ? a : (EmacsCGFloat)1.0)];
+}
+
+- (unsigned long)unsignedLong
+{
+ EmacsCGFloat r, g, b, a;
+ [self getRed:&r green:&g blue:&b alpha:&a];
+
+ return (((unsigned long) (a * 255)) << 24)
+ | (((unsigned long) (r * 255)) << 16)
+ | (((unsigned long) (g * 255)) << 8)
+ | ((unsigned long) (b * 255));
+}
+
@end
/* ==========================================================================
NSColor *
ns_lookup_indexed_color (unsigned long idx, struct frame *f)
{
- struct ns_color_table *color_table = FRAME_DISPLAY_INFO (f)->color_table;
- if (idx < 1 || idx >= color_table->avail)
+ NSMutableArray *color_table = FRAME_DISPLAY_INFO (f)->color_table;
+ if (idx < 1 || idx >= [color_table count])
return nil;
- return color_table->colors[idx];
+ return [color_table objectAtIndex:idx];
}
unsigned long
ns_index_color (NSColor *color, struct frame *f)
{
- struct ns_color_table *color_table = FRAME_DISPLAY_INFO (f)->color_table;
- ptrdiff_t idx;
- ptrdiff_t i;
+ NSMutableArray *color_table = FRAME_DISPLAY_INFO (f)->color_table;
- if (!color_table->colors)
- {
- color_table->size = NS_COLOR_CAPACITY;
- color_table->avail = 1; /* skip idx=0 as marker */
- color_table->colors = xmalloc (color_table->size * sizeof (NSColor *));
- color_table->colors[0] = nil;
- color_table->empty_indices = [[NSMutableSet alloc] init];
- }
+ /* An index of 0 appears to be special in some way, so insert a
+ dummy object. */
+ if ([color_table count] == 0)
+ [color_table addObject:[NSNull null]];
/* Do we already have this color? */
- for (i = 1; i < color_table->avail; i++)
- if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
- return i;
-
- if ([color_table->empty_indices count] > 0)
- {
- NSNumber *index = [color_table->empty_indices anyObject];
- [color_table->empty_indices removeObject: index];
- idx = [index unsignedLongValue];
- }
- else
- {
- if (color_table->avail == color_table->size)
- color_table->colors =
- xpalloc (color_table->colors, &color_table->size, 1,
- min (ULONG_MAX, PTRDIFF_MAX), sizeof *color_table->colors);
- idx = color_table->avail++;
- }
+ if ([color_table containsObject:color])
+ return [color_table indexOfObject:color];
- color_table->colors[idx] = color;
- [color retain];
- /* fprintf(stderr, "color_table: allocated %d\n",idx); */
- return idx;
+ [color_table addObject:color];
+ return [color_table count] - 1;
}
NSColor *col;
col = ns_lookup_indexed_color (idx, f);
- EmacsCGFloat r, g, b, a;
- [col getRed: &r green: &g blue: &b alpha: &a];
-
- return ARGB_TO_ULONG((unsigned long) (a * 255),
- (unsigned long) (r * 255),
- (unsigned long) (g * 255),
- (unsigned long) (b * 255));
+ return [col unsignedLong];
}
void
color_def->blue = b * 65535;
if (setPixel == YES)
- color_def->pixel
- = ARGB_TO_ULONG((unsigned long) (a * 255),
- (unsigned long) (r * 255),
- (unsigned long) (g * 255),
- (unsigned long) (b * 255));
+ color_def->pixel = [(NSColor *)col unsignedLong];
}
bool
&& ![NSCalibratedWhiteColorSpace isEqualToString:
NSColorSpaceFromDepth (depth)];
dpyinfo->n_planes = NSBitsPerPixelFromDepth (depth);
- dpyinfo->color_table = xmalloc (sizeof *dpyinfo->color_table);
- dpyinfo->color_table->colors = NULL;
+ dpyinfo->color_table = [[NSMutableArray array] retain];
dpyinfo->root_window = 42; /* A placeholder. */
dpyinfo->highlight_frame = dpyinfo->ns_focus_frame = NULL;
dpyinfo->n_fonts = 0;
ns_delete_display (struct ns_display_info *dpyinfo)
{
/* TODO... */
+ [dpyinfo->color_table release];
}
name = XCAR (color);
c = XFIXNUM (XCDR (color));
[cl setColor:
- [NSColor colorForEmacsRed: RED_FROM_ULONG (c) / 255.0
- green: GREEN_FROM_ULONG (c) / 255.0
- blue: BLUE_FROM_ULONG (c) / 255.0
- alpha: 1.0]
+ [NSColor colorWithUnsignedLong:c hasAlpha:NO]
forKey: [NSString stringWithLispString: name]];
}