diff options
| author | YAMAMOTO Mitsuharu | 2008-05-02 09:39:23 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2008-05-02 09:39:23 +0000 |
| commit | b03daa516d099def94c68b22009a94e148b94969 (patch) | |
| tree | 91c9d4c1c51dd9cb3c3b5a70b91ffe8fc5d2f942 /src | |
| parent | f5d13fd80a641339af86e00ba518ea2d5a6367f2 (diff) | |
| download | emacs-b03daa516d099def94c68b22009a94e148b94969.tar.gz emacs-b03daa516d099def94c68b22009a94e148b94969.zip | |
(mac_cg_color_space_rgb) [USE_CG_DRAWING]:
Make variable non-static.
(XDrawLine, XCreatePixmap, XCreatePixmapFromBitmapData, XFreePixmap)
[USE_MAC_IMAGE_IO]: Add implementations for Image I/O support.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macterm.c | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/macterm.c b/src/macterm.c index 1efa2667f15..0023c8988a0 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -316,7 +316,7 @@ extern void mac_flush_display_optional P_ ((struct frame *)); | |||
| 316 | static int max_fringe_bmp = 0; | 316 | static int max_fringe_bmp = 0; |
| 317 | static CGImageRef *fringe_bmp = 0; | 317 | static CGImageRef *fringe_bmp = 0; |
| 318 | 318 | ||
| 319 | static CGColorSpaceRef mac_cg_color_space_rgb; | 319 | CGColorSpaceRef mac_cg_color_space_rgb; |
| 320 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 | 320 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 |
| 321 | static CGColorRef mac_cg_color_black; | 321 | static CGColorRef mac_cg_color_black; |
| 322 | #endif | 322 | #endif |
| @@ -400,6 +400,44 @@ XDrawLine (display, p, gc, x1, y1, x2, y2) | |||
| 400 | GC gc; | 400 | GC gc; |
| 401 | int x1, y1, x2, y2; | 401 | int x1, y1, x2, y2; |
| 402 | { | 402 | { |
| 403 | #if USE_MAC_IMAGE_IO | ||
| 404 | CGContextRef context; | ||
| 405 | XImagePtr ximg = p; | ||
| 406 | CGColorSpaceRef color_space; | ||
| 407 | CGImageAlphaInfo alpha_info; | ||
| 408 | CGFloat gx1 = x1, gy1 = y1, gx2 = x2, gy2 = y2; | ||
| 409 | |||
| 410 | if (y1 != y2) | ||
| 411 | gx1 += 0.5f, gx2 += 0.5f; | ||
| 412 | if (x1 != x2) | ||
| 413 | gy1 += 0.5f, gy2 += 0.5f; | ||
| 414 | |||
| 415 | if (ximg->bits_per_pixel == 32) | ||
| 416 | { | ||
| 417 | color_space = mac_cg_color_space_rgb; | ||
| 418 | alpha_info = kCGImageAlphaNoneSkipFirst; | ||
| 419 | } | ||
| 420 | else | ||
| 421 | { | ||
| 422 | color_space = NULL; | ||
| 423 | alpha_info = kCGImageAlphaOnly; | ||
| 424 | } | ||
| 425 | if (color_space == NULL) | ||
| 426 | return; | ||
| 427 | context = CGBitmapContextCreate (ximg->data, ximg->width, | ||
| 428 | ximg->height, 8, | ||
| 429 | ximg->bytes_per_line, color_space, | ||
| 430 | alpha_info); | ||
| 431 | if (ximg->bits_per_pixel == 32) | ||
| 432 | CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND (context, gc); | ||
| 433 | else | ||
| 434 | CGContextSetGrayStrokeColor (context, gc->xgcv.foreground / 255.0f, 1.0); | ||
| 435 | CGContextMoveToPoint (context, gx1, gy1); | ||
| 436 | CGContextAddLineToPoint (context, gx2, gy2); | ||
| 437 | CGContextClosePath (context); | ||
| 438 | CGContextStrokePath (context); | ||
| 439 | CGContextRelease (context); | ||
| 440 | #else | ||
| 403 | CGrafPtr old_port; | 441 | CGrafPtr old_port; |
| 404 | GDHandle old_gdh; | 442 | GDHandle old_gdh; |
| 405 | 443 | ||
| @@ -429,6 +467,7 @@ XDrawLine (display, p, gc, x1, y1, x2, y2) | |||
| 429 | UnlockPixels (GetGWorldPixMap (p)); | 467 | UnlockPixels (GetGWorldPixMap (p)); |
| 430 | 468 | ||
| 431 | SetGWorld (old_port, old_gdh); | 469 | SetGWorld (old_port, old_gdh); |
| 470 | #endif | ||
| 432 | } | 471 | } |
| 433 | 472 | ||
| 434 | 473 | ||
| @@ -639,6 +678,17 @@ XCreatePixmap (display, w, width, height, depth) | |||
| 639 | unsigned int width, height; | 678 | unsigned int width, height; |
| 640 | unsigned int depth; | 679 | unsigned int depth; |
| 641 | { | 680 | { |
| 681 | #if USE_MAC_IMAGE_IO | ||
| 682 | XImagePtr ximg; | ||
| 683 | |||
| 684 | ximg = xmalloc (sizeof (*ximg)); | ||
| 685 | ximg->width = width; | ||
| 686 | ximg->height = height; | ||
| 687 | ximg->bits_per_pixel = depth == 1 ? 8 : 32; | ||
| 688 | ximg->bytes_per_line = width * (ximg->bits_per_pixel / 8); | ||
| 689 | ximg->data = xmalloc (ximg->bytes_per_line * height); | ||
| 690 | return ximg; | ||
| 691 | #else | ||
| 642 | Pixmap pixmap; | 692 | Pixmap pixmap; |
| 643 | Rect r; | 693 | Rect r; |
| 644 | QDErr err; | 694 | QDErr err; |
| @@ -659,6 +709,7 @@ XCreatePixmap (display, w, width, height, depth) | |||
| 659 | if (err != noErr) | 709 | if (err != noErr) |
| 660 | return NULL; | 710 | return NULL; |
| 661 | return pixmap; | 711 | return pixmap; |
| 712 | #endif | ||
| 662 | } | 713 | } |
| 663 | 714 | ||
| 664 | 715 | ||
| @@ -673,6 +724,34 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 673 | { | 724 | { |
| 674 | Pixmap pixmap; | 725 | Pixmap pixmap; |
| 675 | BitMap bitmap; | 726 | BitMap bitmap; |
| 727 | #if USE_MAC_IMAGE_IO | ||
| 728 | CGDataProviderRef provider; | ||
| 729 | CGImageRef image_mask; | ||
| 730 | CGContextRef context; | ||
| 731 | |||
| 732 | pixmap = XCreatePixmap (display, w, width, height, depth); | ||
| 733 | if (pixmap == NULL) | ||
| 734 | return NULL; | ||
| 735 | |||
| 736 | mac_create_bitmap_from_bitmap_data (&bitmap, data, width, height); | ||
| 737 | provider = CGDataProviderCreateWithData (NULL, bitmap.baseAddr, | ||
| 738 | bitmap.rowBytes * height, NULL); | ||
| 739 | image_mask = CGImageMaskCreate (width, height, 1, 1, bitmap.rowBytes, | ||
| 740 | provider, NULL, 0); | ||
| 741 | CGDataProviderRelease (provider); | ||
| 742 | |||
| 743 | context = CGBitmapContextCreate (pixmap->data, width, height, 8, | ||
| 744 | pixmap->bytes_per_line, | ||
| 745 | mac_cg_color_space_rgb, | ||
| 746 | kCGImageAlphaNoneSkipFirst); | ||
| 747 | |||
| 748 | CG_SET_FILL_COLOR (context, fg); | ||
| 749 | CGContextFillRect (context, CGRectMake (0, 0, width, height)); | ||
| 750 | CG_SET_FILL_COLOR (context, bg); | ||
| 751 | CGContextDrawImage (context, CGRectMake (0, 0, width, height), image_mask); | ||
| 752 | CGContextRelease (context); | ||
| 753 | CGImageRelease (image_mask); | ||
| 754 | #else | ||
| 676 | CGrafPtr old_port; | 755 | CGrafPtr old_port; |
| 677 | GDHandle old_gdh; | 756 | GDHandle old_gdh; |
| 678 | static GC gc = NULL; | 757 | static GC gc = NULL; |
| @@ -701,6 +780,7 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 701 | #endif /* not TARGET_API_MAC_CARBON */ | 780 | #endif /* not TARGET_API_MAC_CARBON */ |
| 702 | UnlockPixels (GetGWorldPixMap (pixmap)); | 781 | UnlockPixels (GetGWorldPixMap (pixmap)); |
| 703 | SetGWorld (old_port, old_gdh); | 782 | SetGWorld (old_port, old_gdh); |
| 783 | #endif | ||
| 704 | mac_free_bitmap (&bitmap); | 784 | mac_free_bitmap (&bitmap); |
| 705 | 785 | ||
| 706 | return pixmap; | 786 | return pixmap; |
| @@ -712,7 +792,16 @@ XFreePixmap (display, pixmap) | |||
| 712 | Display *display; | 792 | Display *display; |
| 713 | Pixmap pixmap; | 793 | Pixmap pixmap; |
| 714 | { | 794 | { |
| 795 | #if USE_MAC_IMAGE_IO | ||
| 796 | if (pixmap) | ||
| 797 | { | ||
| 798 | if (pixmap->data) | ||
| 799 | xfree (pixmap->data); | ||
| 800 | xfree (pixmap); | ||
| 801 | } | ||
| 802 | #else | ||
| 715 | DisposeGWorld (pixmap); | 803 | DisposeGWorld (pixmap); |
| 804 | #endif | ||
| 716 | } | 805 | } |
| 717 | 806 | ||
| 718 | 807 | ||