diff options
| author | Alan Third | 2019-01-02 21:00:09 +0000 |
|---|---|---|
| committer | Alan Third | 2019-01-10 19:24:20 +0000 |
| commit | a1b7a3f2a3957a399d6c3c7bcffa07ac67da82fc (patch) | |
| tree | 478594bd679f2db099fcb6320750f24fcedf5fc6 /src/nsimage.m | |
| parent | c342b26371480316024e1e5d63cd8b3f035dda69 (diff) | |
| download | emacs-a1b7a3f2a3957a399d6c3c7bcffa07ac67da82fc.tar.gz emacs-a1b7a3f2a3957a399d6c3c7bcffa07ac67da82fc.zip | |
Add native image scaling (bug#33587)
* configure.ac: Test for XRender outside of xft checks.
* src/Makefile.in (XRENDER_LIBS): List XRender libs separately from
xft libs.
* lisp/image.el (image--get-imagemagick-and-warn): Allow resizing if
native scaling is available.
* src/dispextern.h: Add XRender and image scaling stuff.
(struct image): Add XRender Pictures.
* src/image.c (x_create_bitmap_mask):
(image_create_x_image_and_pixmap): Handle XRender Picture.
(scale_image_size):
(compute_image_size): Make available when any form of scaling is
enabled.
(x_set_image_size): New function.
(lookup_image): Set image size.
(x_create_x_image_and_pixmap): Create XRender Picture when necessary.
(x_put_x_image): Handle the case where desired size != actual size.
(free_image): Free XRender Pictures.
(Fimage_scaling_p): New function.
(syms_of_image): Add image-scaling-p.
* src/nsimage.m (ns_load_image): Remove NS specific resizing.
([EmacsImage setSizeFromSpec:]): Remove method.
(ns_image_set_size): New function.
* src/nsterm.m (ns_draw_fringe_bitmap): Cocoa and GNUstep both have
the same compositing functions, so remove unnecessary difference.
* src/xterm.c (x_composite_image): New function.
(x_draw_image_foreground): Use new x_composite_image function.
* doc/lispref/display.texi (Image Descriptors): Document
image-scaling-p and add resizing descriptors.
(ImageMagick Images): Remove resizing descriptors.
Diffstat (limited to 'src/nsimage.m')
| -rw-r--r-- | src/nsimage.m | 68 |
1 files changed, 6 insertions, 62 deletions
diff --git a/src/nsimage.m b/src/nsimage.m index 7879c5891d6..f16910de088 100644 --- a/src/nsimage.m +++ b/src/nsimage.m | |||
| @@ -126,8 +126,6 @@ ns_load_image (struct frame *f, struct image *img, | |||
| 126 | eImg = temp; | 126 | eImg = temp; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | [eImg setSizeFromSpec:XCDR (img->spec)]; | ||
| 130 | |||
| 131 | size = [eImg size]; | 129 | size = [eImg size]; |
| 132 | img->width = size.width; | 130 | img->width = size.width; |
| 133 | img->height = size.height; | 131 | img->height = size.height; |
| @@ -151,6 +149,12 @@ ns_image_height (void *img) | |||
| 151 | return [(id)img size].height; | 149 | return [(id)img size].height; |
| 152 | } | 150 | } |
| 153 | 151 | ||
| 152 | void | ||
| 153 | ns_image_set_size (void *img, int width, int height) | ||
| 154 | { | ||
| 155 | [(EmacsImage *)img setSize:NSMakeSize (width, height)]; | ||
| 156 | } | ||
| 157 | |||
| 154 | unsigned long | 158 | unsigned long |
| 155 | ns_get_pixel (void *img, int x, int y) | 159 | ns_get_pixel (void *img, int x, int y) |
| 156 | { | 160 | { |
| @@ -524,66 +528,6 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 524 | return YES; | 528 | return YES; |
| 525 | } | 529 | } |
| 526 | 530 | ||
| 527 | - (void)setSizeFromSpec: (Lisp_Object) spec | ||
| 528 | { | ||
| 529 | NSSize size = [self size]; | ||
| 530 | Lisp_Object value; | ||
| 531 | double scale = 1, aspect = size.width / size.height; | ||
| 532 | double width = -1, height = -1, max_width = -1, max_height = -1; | ||
| 533 | |||
| 534 | value = Fplist_get (spec, QCscale); | ||
| 535 | if (NUMBERP (value)) | ||
| 536 | scale = XFLOATINT (value) ; | ||
| 537 | |||
| 538 | value = Fplist_get (spec, QCmax_width); | ||
| 539 | if (NUMBERP (value)) | ||
| 540 | max_width = XFLOATINT (value); | ||
| 541 | |||
| 542 | value = Fplist_get (spec, QCmax_height); | ||
| 543 | if (NUMBERP (value)) | ||
| 544 | max_height = XFLOATINT (value); | ||
| 545 | |||
| 546 | value = Fplist_get (spec, QCwidth); | ||
| 547 | if (NUMBERP (value)) | ||
| 548 | { | ||
| 549 | width = XFLOATINT (value) * scale; | ||
| 550 | /* :width overrides :max-width. */ | ||
| 551 | max_width = -1; | ||
| 552 | } | ||
| 553 | |||
| 554 | value = Fplist_get (spec, QCheight); | ||
| 555 | if (NUMBERP (value)) | ||
| 556 | { | ||
| 557 | height = XFLOATINT (value) * scale; | ||
| 558 | /* :height overrides :max-height. */ | ||
| 559 | max_height = -1; | ||
| 560 | } | ||
| 561 | |||
| 562 | if (width <= 0 && height <= 0) | ||
| 563 | { | ||
| 564 | width = size.width * scale; | ||
| 565 | height = size.height * scale; | ||
| 566 | } | ||
| 567 | else if (width > 0 && height <= 0) | ||
| 568 | height = width / aspect; | ||
| 569 | else if (height > 0 && width <= 0) | ||
| 570 | width = height * aspect; | ||
| 571 | |||
| 572 | if (max_width > 0 && width > max_width) | ||
| 573 | { | ||
| 574 | width = max_width; | ||
| 575 | height = max_width / aspect; | ||
| 576 | } | ||
| 577 | |||
| 578 | if (max_height > 0 && height > max_height) | ||
| 579 | { | ||
| 580 | height = max_height; | ||
| 581 | width = max_height * aspect; | ||
| 582 | } | ||
| 583 | |||
| 584 | [self setSize:NSMakeSize(width, height)]; | ||
| 585 | } | ||
| 586 | |||
| 587 | - (instancetype)rotate: (double)rotation | 531 | - (instancetype)rotate: (double)rotation |
| 588 | { | 532 | { |
| 589 | EmacsImage *new_image; | 533 | EmacsImage *new_image; |