summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXDraw.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tkMacOSXDraw.c')
-rw-r--r--macosx/tkMacOSXDraw.c187
1 files changed, 14 insertions, 173 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 02ea812..274a2cd 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -16,7 +16,6 @@
#include "tkMacOSXPrivate.h"
#include "tkMacOSXDebug.h"
-#include "xbytes.h"
#include "tkButton.h"
/*
@@ -45,12 +44,6 @@ static int useThemedFrame = 0;
*/
static void ClipToGC(Drawable d, GC gc, HIShapeRef *clipRgnPtr);
-static CGImageRef CreateCGImageWithXImage(XImage *ximage);
-static CGContextRef GetCGContextForDrawable(Drawable d);
-static void DrawCGImage(Drawable d, GC gc, CGContextRef context, CGImageRef image,
- unsigned long imageForeground, unsigned long imageBackground,
- CGRect imageBounds, CGRect srcBounds, CGRect dstBounds);
-
/*
*----------------------------------------------------------------------
@@ -108,7 +101,7 @@ TkMacOSXInitCGDrawing(
/*
*----------------------------------------------------------------------
*
- * BitmapRepFromDrawableRect
+ * TkMacOSXBitmapRepFromDrawableRect
*
* Extract bitmap data from a MacOSX drawable as an NSBitmapImageRep.
*
@@ -126,7 +119,7 @@ TkMacOSXInitCGDrawing(
*----------------------------------------------------------------------
*/
NSBitmapImageRep*
-BitmapRepFromDrawableRect(
+TkMacOSXBitmapRepFromDrawableRect(
Drawable drawable,
int x,
int y,
@@ -143,7 +136,7 @@ BitmapRepFromDrawableRect(
This means that the MacDrawable is functioning as a Tk Pixmap, so its view
field is NULL.
*/
- cg_context = GetCGContextForDrawable(drawable);
+ cg_context = TkMacOSXGetCGContextForDrawable(drawable);
CGRect image_rect = CGRectMake(x, y, width, height);
cg_image = CGBitmapContextCreateImage( (CGContextRef) cg_context);
sub_cg_image = CGImageCreateWithImageInRect(cg_image, image_rect);
@@ -230,7 +223,7 @@ XCopyArea(
if (srcDraw->flags & TK_IS_PIXMAP) {
img = TkMacOSXCreateCGImageWithDrawable(src);
}else if (TkMacOSXDrawableWindow(src)) {
- bitmap_rep = BitmapRepFromDrawableRect(src, src_x, src_y, width, height);
+ bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src, src_x, src_y, width, height);
if ( bitmap_rep ) {
img = [bitmap_rep CGImage];
}
@@ -239,7 +232,7 @@ XCopyArea(
}
if (img) {
- DrawCGImage(dst, gc, dc.context, img, gc->foreground, gc->background,
+ TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground, gc->background,
CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height),
CGRectMake(src_x, src_y, width, height),
CGRectMake(dest_x, dest_y, width, height));
@@ -339,7 +332,7 @@ XCopyPlane(
CGImageRelease(submask);
CGImageRelease(subimage);
} else {
- DrawCGImage(dst, gc, dc.context, img, gc->foreground, imageBackground,
+ TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground, imageBackground,
CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height),
CGRectMake(src_x, src_y, width, height),
CGRectMake(dest_x, dest_y, width, height));
@@ -360,158 +353,6 @@ XCopyPlane(
/*
*----------------------------------------------------------------------
*
- * TkPutImage --
- *
- * Copies a subimage from an in-memory image to a rectangle of
- * of the specified drawable.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Draws the image on the specified drawable.
- *
- *----------------------------------------------------------------------
- */
-
-int
-TkPutImage(
- unsigned long *colors, /* Unused on Macintosh. */
- int ncolors, /* Unused on Macintosh. */
- Display* display, /* Display. */
- Drawable d, /* Drawable to place image on. */
- GC gc, /* GC to use. */
- XImage* image, /* Image to place. */
- int src_x, /* Source X & Y. */
- int src_y,
- int dest_x, /* Destination X & Y. */
- int dest_y,
- unsigned int width, /* Same width & height for both */
- unsigned int height) /* distination and source. */
-{
- TkMacOSXDrawingContext dc;
-
- display->request++;
- if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) {
- return BadDrawable;
- }
- if (dc.context) {
- CGImageRef img = CreateCGImageWithXImage(image);
-
- if (img) {
- /* If the XImage has big pixels, rescale the source dimensions.*/
- int pp = image->pixelpower;
- DrawCGImage(d, gc, dc.context, img, gc->foreground, gc->background,
- CGRectMake(0, 0, image->width<<pp, image->height<<pp),
- CGRectMake(src_x<<pp, src_y<<pp, width<<pp, height<<pp),
- CGRectMake(dest_x, dest_y, width, height));
- CFRelease(img);
- } else {
- TkMacOSXDbgMsg("Invalid source drawable");
- }
- } else {
- TkMacOSXDbgMsg("Invalid destination drawable");
- }
- TkMacOSXRestoreDrawingContext(&dc);
- return Success;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * CreateCGImageWithXImage --
- *
- * Create CGImage from XImage, copying the image data.
- *
- * Results:
- * CGImage, release after use.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static void ReleaseData(void *info, const void *data, size_t size) {
- ckfree(info);
-}
-
-CGImageRef
-CreateCGImageWithXImage(
- XImage *image)
-{
- CGImageRef img = NULL;
- size_t bitsPerComponent, bitsPerPixel;
- size_t len = image->bytes_per_line * image->height;
- const CGFloat *decode = NULL;
- CGBitmapInfo bitmapInfo;
- CGDataProviderRef provider = NULL;
- char *data = NULL;
- CGDataProviderReleaseDataCallback releaseData = ReleaseData;
-
- if (image->bits_per_pixel == 1) {
- /*
- * BW image
- */
-
- /* Reverses the sense of the bits */
- static const CGFloat decodeWB[2] = {1, 0};
- decode = decodeWB;
-
- bitsPerComponent = 1;
- bitsPerPixel = 1;
- if (image->bitmap_bit_order != MSBFirst) {
- char *srcPtr = image->data + image->xoffset;
- char *endPtr = srcPtr + len;
- char *destPtr = (data = ckalloc(len));
-
- while (srcPtr < endPtr) {
- *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))];
- }
- } else {
- data = memcpy(ckalloc(len), image->data + image->xoffset, len);
- }
- if (data) {
- provider = CGDataProviderCreateWithData(data, data, len, releaseData);
- }
- if (provider) {
- img = CGImageMaskCreate(image->width, image->height, bitsPerComponent,
- bitsPerPixel, image->bytes_per_line, provider, decode, 0);
- }
- } else if (image->format == ZPixmap && image->bits_per_pixel == 32) {
- /*
- * Color image
- */
-
- CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
-
- bitsPerComponent = 8;
- bitsPerPixel = 32;
- bitmapInfo = (image->byte_order == MSBFirst ?
- kCGBitmapByteOrder32Big : kCGBitmapByteOrder32Little) |
- kCGImageAlphaNoneSkipFirst;
- data = memcpy(ckalloc(len), image->data + image->xoffset, len);
- if (data) {
- provider = CGDataProviderCreateWithData(data, data, len, releaseData);
- }
- if (provider) {
- img = CGImageCreate(image->width, image->height, bitsPerComponent,
- bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo,
- provider, decode, 0, kCGRenderingIntentDefault);
- CFRelease(provider);
- }
- if (colorspace) {
- CFRelease(colorspace);
- }
- } else {
- TkMacOSXDbgMsg("Unsupported image type");
- }
- return img;
-}
-
-/*
- *----------------------------------------------------------------------
- *
* TkMacOSXCreateCGImageWithDrawable --
*
* Create a CGImage from the given Drawable.
@@ -530,7 +371,7 @@ TkMacOSXCreateCGImageWithDrawable(
Drawable drawable)
{
CGImageRef img = NULL;
- CGContextRef context = GetCGContextForDrawable(drawable);
+ CGContextRef context = TkMacOSXGetCGContextForDrawable(drawable);
if (context) {
img = CGBitmapContextCreateImage(context);
@@ -649,7 +490,7 @@ TkMacOSXGetNSImageWithBitmap(
/*
*----------------------------------------------------------------------
*
- * GetCGContextForDrawable --
+ * TkMacOSXGetCGContextForDrawable --
*
* Get CGContext for given Drawable, creating one if necessary.
*
@@ -663,10 +504,10 @@ TkMacOSXGetNSImageWithBitmap(
*/
CGContextRef
-GetCGContextForDrawable(
- Drawable d)
+TkMacOSXGetCGContextForDrawable(
+ Drawable drawable)
{
- MacDrawable *macDraw = (MacDrawable *) d;
+ MacDrawable *macDraw = (MacDrawable *) drawable;
if (macDraw && (macDraw->flags & TK_IS_PIXMAP) && !macDraw->context) {
const size_t bitsPerComponent = 8;
@@ -711,7 +552,7 @@ GetCGContextForDrawable(
/*
*----------------------------------------------------------------------
*
- * DrawCGImage --
+ * TkMacOSXDrawCGImage --
*
* Draw CG image into drawable.
*
@@ -725,7 +566,7 @@ GetCGContextForDrawable(
*/
void
-DrawCGImage(
+TkMacOSXDrawCGImage(
Drawable d,
GC gc,
CGContextRef context,
@@ -1625,7 +1466,7 @@ TkMacOSXSetupDrawingContext(
goto end;
}
if (useCG) {
- dc.context = GetCGContextForDrawable(d);
+ dc.context = TkMacOSXGetCGContextForDrawable(d);
}
if (!dc.context || !(macDraw->flags & TK_IS_PIXMAP)) {
isWin = (TkMacOSXDrawableWindow(d) != nil);