artgillespie / OGImage

OGImage provides a simple abstraction for loading images from the network, processing them, and caching them locally.
https://origami.com
MIT License
36 stars 4 forks source link

Artifacts when scaling certain images #25

Closed sixten closed 11 years ago

sixten commented 11 years ago

Took the library for a test drive in one of our apps, in a collection view that's loading images from the web and displaying thumbnails. In some cases, however, I'm seeing artifacts in the scaled result.

Here's an example of one such image in its original form: logo

And the result: 24432f736d1e50d4aa065d007926a63f 2x

Two possibilities spring to mind: 1. that the original is actually smaller than the target size (120 x 56 pt) and is getting scaled up, and 2. that this image has a transparent background. Or maybe it's something else altogether?

artgillespie commented 11 years ago

Ugh; it never occurred to me that folks might want to scale an image to larger than its original size.

artgillespie commented 11 years ago

Hrm, on the develop branch, this code:

NSURL *imageURL = [NSURL URLWithString:@"https://f.cloud.github.com/assets/7528/927805/5243561a-ffa7-11e2-9776-63733fe2673f.png"];
OGScaledImage *image = [[OGScaledImage alloc] initWithURL:imageURL size:CGSizeMake(120.f, 56.f) cornerRadius:0.f method:OGImageProcessingScale_AspectFit key:nil placeholderImage:[UIImage imageNamed:@"placeholder"]];

Gives me this scaled image, which appears correct:

56f63f049d537b2c7742aa5bf19d7dce 2x

sixten commented 11 years ago

The upscaling is not by choice, really, there just isn't absolute control over what images folks might upload.

The other possibility that occurred to me yesterday: that the artifacts are data leaking from one of the other images. Maybe a buffer that's being allocated, but not cleared before being drawn into, so the old data appears in the parts with alpha transparency? Especially because the garbage in my "after" image greatly resembles this (being loaded by the app at around the same time): logo-1

artgillespie commented 11 years ago

Sure, I make no judgments about design constraints!

Try the issue-25 branch (https://github.com/origamilabs/OGImage/tree/issue-25) -- we weren't filling vImage_Buffers with transparent pixels before processing into them.

sixten commented 11 years ago

So far, so good. Thanks!