diff options
| author | Alan Third | 2017-08-23 19:53:23 +0100 |
|---|---|---|
| committer | Alan Third | 2017-08-23 19:57:00 +0100 |
| commit | 95130f192b7c00a118ce745efb94cd3d0aaabab0 (patch) | |
| tree | f75c4eaa2948f94f7e2b9c86e8ae6c6341621f0a /src/nsimage.m | |
| parent | 7baa50eca28ff21497b058fa22656bbb4a447d87 (diff) | |
| download | emacs-95130f192b7c00a118ce745efb94cd3d0aaabab0.tar.gz emacs-95130f192b7c00a118ce745efb94cd3d0aaabab0.zip | |
Fix PNGs on macOS (bug#28176)
* src/nsimage.m (ns_load_image): Remove index check.
(EmacsImage::getAnimatedBitmapImageRep): New function.
(EmacsImage::getMetadata): Use getAnimatedBitmapImageRep.
(EmacsImage::setFrame): Use getAnimatedBitmapImageRep and check index
is valid.
Diffstat (limited to 'src/nsimage.m')
| -rw-r--r-- | src/nsimage.m | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/src/nsimage.m b/src/nsimage.m index 94b24a3912c..3c81dea67a9 100644 --- a/src/nsimage.m +++ b/src/nsimage.m | |||
| @@ -106,7 +106,7 @@ ns_load_image (struct frame *f, struct image *img, | |||
| 106 | return 0; | 106 | return 0; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | if (index < 0 || ![eImg setFrame: index]) | 109 | if (![eImg setFrame: index]) |
| 110 | { | 110 | { |
| 111 | add_to_log ("Unable to set index %d for image %s", index, img->spec); | 111 | add_to_log ("Unable to set index %d for image %s", index, img->spec); |
| 112 | return 0; | 112 | return 0; |
| @@ -450,49 +450,63 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 450 | return stippleMask; | 450 | return stippleMask; |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | /* If the image has multiple frames, get a count of them and the | 453 | /* Find the first NSBitmapImageRep which has multiple frames. */ |
| 454 | animation delay, if available. */ | 454 | - (NSBitmapImageRep *)getAnimatedBitmapImageRep |
| 455 | - (Lisp_Object)getMetadata | ||
| 456 | { | 455 | { |
| 457 | Lisp_Object metadata = Qnil; | ||
| 458 | |||
| 459 | for (NSImageRep * r in [self representations]) | 456 | for (NSImageRep * r in [self representations]) |
| 460 | { | 457 | { |
| 461 | if ([r isKindOfClass:[NSBitmapImageRep class]]) | 458 | if ([r isKindOfClass:[NSBitmapImageRep class]]) |
| 462 | { | 459 | { |
| 463 | NSBitmapImageRep * bm = (NSBitmapImageRep *)r; | 460 | NSBitmapImageRep * bm = (NSBitmapImageRep *)r; |
| 464 | int frames = [[bm valueForProperty: NSImageFrameCount] intValue]; | 461 | if ([[bm valueForProperty:NSImageFrameCount] intValue] > 0) |
| 465 | float delay = [[bm valueForProperty: NSImageCurrentFrameDuration] | 462 | return bm; |
| 466 | floatValue]; | ||
| 467 | |||
| 468 | if (frames > 1) | ||
| 469 | metadata = Fcons (Qcount, Fcons (make_number (frames), metadata)); | ||
| 470 | if (delay > 0) | ||
| 471 | metadata = Fcons (Qdelay, Fcons (make_float (delay), metadata)); | ||
| 472 | break; | ||
| 473 | } | 463 | } |
| 474 | } | 464 | } |
| 465 | return nil; | ||
| 466 | } | ||
| 467 | |||
| 468 | /* If the image has multiple frames, get a count of them and the | ||
| 469 | animation delay, if available. */ | ||
| 470 | - (Lisp_Object)getMetadata | ||
| 471 | { | ||
| 472 | Lisp_Object metadata = Qnil; | ||
| 473 | |||
| 474 | NSBitmapImageRep * bm = [self getAnimatedBitmapImageRep]; | ||
| 475 | |||
| 476 | if (bm != nil) | ||
| 477 | { | ||
| 478 | int frames = [[bm valueForProperty:NSImageFrameCount] intValue]; | ||
| 479 | float delay = [[bm valueForProperty:NSImageCurrentFrameDuration] | ||
| 480 | floatValue]; | ||
| 481 | |||
| 482 | if (frames > 1) | ||
| 483 | metadata = Fcons (Qcount, Fcons (make_number (frames), metadata)); | ||
| 484 | if (delay > 0) | ||
| 485 | metadata = Fcons (Qdelay, Fcons (make_float (delay), metadata)); | ||
| 486 | } | ||
| 475 | return metadata; | 487 | return metadata; |
| 476 | } | 488 | } |
| 477 | 489 | ||
| 478 | /* Attempt to set the animation frame to be displayed. */ | 490 | /* Attempt to set the animation frame to be displayed. */ |
| 479 | - (BOOL)setFrame: (unsigned int) index | 491 | - (BOOL)setFrame: (unsigned int) index |
| 480 | { | 492 | { |
| 481 | for (NSImageRep * r in [self representations]) | 493 | NSBitmapImageRep * bm = [self getAnimatedBitmapImageRep]; |
| 494 | |||
| 495 | if (bm != nil) | ||
| 482 | { | 496 | { |
| 483 | if ([r isKindOfClass:[NSBitmapImageRep class]]) | 497 | int frames = [[bm valueForProperty:NSImageFrameCount] intValue]; |
| 484 | { | ||
| 485 | NSBitmapImageRep * bm = (NSBitmapImageRep *)r; | ||
| 486 | if ([[bm valueForProperty: NSImageFrameCount] intValue] <= index) | ||
| 487 | continue; | ||
| 488 | 498 | ||
| 489 | [bm setProperty: NSImageCurrentFrame | 499 | /* If index is invalid, give up. */ |
| 490 | withValue: [NSNumber numberWithUnsignedInt: index]]; | 500 | if (index < 0 || index > frames) |
| 491 | return YES; | 501 | return NO; |
| 492 | } | 502 | |
| 503 | [bm setProperty: NSImageCurrentFrame | ||
| 504 | withValue: [NSNumber numberWithUnsignedInt:index]]; | ||
| 493 | } | 505 | } |
| 494 | 506 | ||
| 495 | return NO; | 507 | /* Setting the frame has succeeded, or the image doesn't have |
| 508 | multiple frames. */ | ||
| 509 | return YES; | ||
| 496 | } | 510 | } |
| 497 | 511 | ||
| 498 | @end | 512 | @end |