-[NSImage drawInRect:] screws up if the scale factor ends up being non-integral
| Originator: | wadetregaskis | ||
| Number: | rdar://19762622 | Date Originated: | 8/2/2015 |
| Status: | Open | Resolved: | |
| Product: | OS X | Product Version: | 10.10.2 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
If you take a source image of say 4,000 x 6,000, and try to draw it into a rect of say 50 x 75, it works fine. But, if you try a rect of 51 x 76 (or 51 x 77), it screws up - it offsets the drawn image, within the destination, by some seemingly arbitrary vertical shift (and sometimes wraps the image around from bottom to top, but mostly doesn't).
But, this doesn't always happen - it depends on how you get the original NSImage. e.g. NSImage(fileURLWithPath:) *doesn't* exhibit this issue yet loading it via CIFilter(imageURL:, options:) does.
Steps to Reproduce:
func toNSImage(ciImage : CIImage) -> NSImage {
let rep = NSCIImageRep(CIImage: ciImage)
var nsImage = NSImage(size: ciImage.extent().size)
nsImage.addRepresentation(rep)
return nsImage
}
let url = <path to some NSImage, of 4,000 x 6,000 for this example>
var rawFilter = CIFilter(imageURL: url, options: [:])
rawFilter.setValue("5", forKey: "inputDecoderVersion") // To work around bug in 10.10.2 / RAWUpdate6.02 where version "6" only ever renders a completely black image
let image = toNSImage(rawFilter.outputImage!)
let scaledSize = NSSize(width: 51, height: 77)
let scaledImage = NSImage(size: scaledSize)
scaledImage.lockFocus()
image.drawInRect(NSRect(origin: NSZeroPoint, size: scaledSize))
scaledImage.unlockFocus()
Expected Results:
Drawing the scaled image correctly.
Actual Results:
Not drawing the scaled image correctly.
Workaround:
Turn off image caching for the source image (i.e. image.cacheMode = .Never).
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!