Closed smhk closed 4 years ago
Hi, @smhk. I think you are onto something, I saw similar suggestions before.
There is already one built-in mechanism to do that which is ImageProcessing
. I think what you could do is implement a custom processor (or use the anonymous one with a closure) to perform this operation and then save the result in a dictionary or something else. Then the processors can return the original image without modification (yes, not ideal). Keep in mind, this won't work with the recently added on-disk cache for processed images (isDataCachingForProcessedImagesEnabled
option).
and I guess some sort of callback to deliver the calculated value
If you'd like this value to be calculated after you display an image, then I would suggest implementing it separately from Nuke. All you need is cache, which can be simply a dictionary, and a way to re-use tasks for calculating the average color.
As for adding areaAverageColor
to Nuke, this might be another good candidate for addition. I'm not sure where to draw the line which ones should and should not be added. This seems like something that many apps need. But if I were using a framework like this, I would've never assumed it had this kind of feature. My first step would've been to look elsewhere. Nuke only has the most basic image processors and a way to create custom ones, as complex as the user needs.
Here's an interesting thing, I load many images form the net:
Fantastic. Eacgh image is loaded many places in the app or on the same screen. No problem for Nuke.
Often these days you want a "dominant" color for use in shadows or borders. (Good online example: lokeshdhakar.com/projects/color-thief/ )
For this you have CIAreaAverage or perhaps CIAreaHistogram. Importantly, CIKMeans is coming soon, too, which will be the go-to choice.
For each of these images, once the image is downloaded (by Nuke), in many places I run some processing:
(The code for areaAverageColor is below.)
Would there be some way in the Nuke pipeline, that
For each of the 100s of images,
I want it to calculate .areaAverageColor
If I load the same image dozens of times, it knows to calculate .areaAverageColor only once
and I guess some sort of callback to deliver the calculated value (eg,
func nuke_display(colorFound: CGColor?) { self.image.shadowColor = colorFound }
or the like)
Does this already exist in Nuke or would it be a good idea?
Perhaps the ideas of picking out a built-in color should be built-right-in (much as say blur is immediately available).
Nuke == awesome