Settled NSBitmapImageRep TODOs on the Mac OS X backend.

This commit is contained in:
Pietro Gagliardi 2014-08-10 13:19:42 -04:00
parent 09a1239d94
commit 0b3f6570ac
3 changed files with 12 additions and 6 deletions

View File

@ -51,9 +51,12 @@ func areaView_drawRect(self C.id, rect C.struct_xrect, data unsafe.Pointer) {
return
}
i := a.handler.Paint(cliprect)
C.drawImage(
success := C.drawImage(
unsafe.Pointer(pixelData(i)), C.intptr_t(i.Rect.Dx()), C.intptr_t(i.Rect.Dy()), C.intptr_t(i.Stride),
C.intptr_t(cliprect.Min.X), C.intptr_t(cliprect.Min.Y))
if success == C.NO {
panic("error drawing into Area (exactly what is unknown)")
}
}
func parseModifiers(e C.id) (m Modifiers) {

View File

@ -112,10 +112,11 @@ id newArea(void *goarea)
return (id) a;
}
void drawImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride, intptr_t xdest, intptr_t ydest)
BOOL drawImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride, intptr_t xdest, intptr_t ydest)
{
unsigned char *planes[1]; // NSBitmapImageRep wants an array of planes; we have one plane
NSBitmapImageRep *bitmap;
BOOL success;
planes[0] = (unsigned char *) pixels;
bitmap = [[NSBitmapImageRep alloc]
@ -126,18 +127,20 @@ void drawImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride, i
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace // TODO NSDeviceRGBColorSpace?
// NSCalibratedRGBColorSpace changes the colors; let's not
// thanks to JtRip in irc.freenode.net/#macdev
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0 // this is where the flag for placing alpha first would go if alpha came first; the default is alpha last, which is how we're doing things (otherwise the docs say "Color planes are arranged in the standard order—for example, red before green before blue for RGB color."); this is also where the flag for non-premultiplied colors would go if we used it (the default is alpha-premultiplied)
bytesPerRow:toNSInteger(stride)
bitsPerPixel:32];
// TODO this CAN fali; check error
[bitmap drawInRect:NSMakeRect((CGFloat) xdest, (CGFloat) ydest, (CGFloat) width, (CGFloat) height)
success = [bitmap drawInRect:NSMakeRect((CGFloat) xdest, (CGFloat) ydest, (CGFloat) width, (CGFloat) height)
fromRect:NSZeroRect // draw whole image
operation:NSCompositeSourceOver
fraction:1.0
respectFlipped:YES
hints:nil];
[bitmap release];
return success;
}
uintptr_t modifierFlags(id e)

View File

@ -100,7 +100,7 @@ extern struct xrect frame(id);
/* area_darwin.h */
extern Class getAreaClass(void);
extern id newArea(void *);
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
extern BOOL drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
extern uintptr_t modifierFlags(id);
extern struct xpoint getTranslatedEventPoint(id, id);
extern intptr_t buttonNumber(id);