Re: Concurrent loading of images ?
Re: Concurrent loading of images ?
- Subject: Re: Concurrent loading of images ?
- From: Gabriel Zachmann via Cocoa-dev <email@hidden>
- Date: Mon, 18 May 2020 13:52:35 +0200
Thanks a lot for your response!
I have tried the CILanczosScaleTransform filter for downsizing. I have computed
the scale factor exactly such that the new image has an extent not larger than
the view.
(Below is my code)
But the performance was worse, at least with the software renderer.
With the hardware renderer (kCIContextUseSoftwareRenderer: @NO), performance
was as before, but visual artifacts were still much worse than without any
downsizing.
If you are curious: here is a video showing the performance
https://owncloud.informatik.uni-bremen.de/index.php/s/wJRkK8Ek2HTp32a
(The video was made with the software renderer.)
So, right now, I am using this code:
NSDictionary * imageOpts = @{
(id)kCGImageSourceCreateThumbnailWithTransform: (id)kCFBooleanTrue, // takes
care of EXIF orientation, too
(id)kCGImageSourceCreateThumbnailFromImageIfAbsent: (id)kCFBooleanTrue,
(id)kCGImageSourceCreateThumbnailFromImageAlways: (id)kCFBooleanTrue,
(id)kCGImageSourceShouldCacheImmediately:
(id)kCFBooleanTrue,
(id)kCGImageSourceThumbnailMaxPixelSize:
@(8192) };
CGImageRef newImageRef = CGImageSourceCreateThumbnailAtIndex( new_image, 0,
(__bridge
CFDictionaryRef) imageOpts );
There is still a bit of stuttering.
Maybe, it would help to create the CALayer for the new images in the background
thread and add it to the layer hierarchy, but I haven't explored this option
yet.
Maybe it would not help, because, maybe, at that point some process in the
foreground would kick in again, over which I would not have control.
Best regards, Gabriel
Encl.:
Just for your reference, this is my code for downsizing using the Lanczos
filter:
CIContext * ciContext = [CIContext contextWithOptions:
@{kCIContextUseSoftwareRenderer: @NO} ]; // TODO: als inst.var.
machen!
// TODO: evtl im context kCIContextPriorityRequestLow und
useSoftwareRenderer=FALSE angeben?
CIFilter * resizeFilter = [CIFilter filterWithName:
@"CILanczosScaleTransform" ];
[resizeFilter setValue: orientedimage forKey: kCIInputImageKey];
[resizeFilter setValue: @(scale) forKey: kCIInputScaleKey ];
[resizeFilter setValue: @(aspect) forKey:kCIInputAspectRatioKey ];
CIImage * resizedImage = resizeFilter.outputImage;
CGImageRef newImageRef = [ciContext createCGImage: resizedImage fromRect:
resizedImage.extent];
>
> Since this stutter does not occur when cycling back through images that have
> already been assigned to the layer, it’s possible that if the size of the
> CGImageRef does not match the size of the CALayer, there may be some kind of
> render occuring, especially if the image is being scaled to fit the layer.
> Do images much larger than the CALayer stutter more?
>
> Also, if you’re resizing, you’ll want to use CIImage’s
> CILanczosScaleTransform filter. Simply scaling a using a transform will give
> you a much blurrier image.
>
> Jim Crate
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden