Thursday, July 9, 2020

#1 2020-05-26 11:57:05 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 282

CoreImage filter reference: Composite Operation.

Handlers of Composite Operation, many of this are used in Adobe PS.

Total: 27 different BlendMode but it could be some do the same things.

Framework: CoreImage

Thanks to Shane Stanley for his help.

Applescript:

use framework "CoreImage"

(*
   Core Image Filter Reference of Composite Operation
   made by Fredrik with help from Shane Stanley.
   
   The handlers args: inputImage, inputBackgroundImage
   
   Many of this BlendMode are used in Adobe Photoshop.
*)


(*
   Adds color components to achieve a brightening effect.
*)

-- CIFilter AdditionCompositing Protocol
on ciFilterAdditionCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIAdditionCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterAdditionCompositing

(*
   Uses the luminance values of the background with the hue
   and saturation values of the source image.    
*)

-- CIFilter ColorBlendMode Protocol
on ciFilterColorBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIColorBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterColorBlendMode

(*
   Darkens the background image samples to reflect the source image samples.
*)

-- CIFilter ColorBurnBlendMode Protocol
on ciFilterColorBurnBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIColorBurnBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterColorBurnBlendMode

(*
   Brightens the background image samples to reflect the source image samples.
*)

-- CIFilter ColorDodgeBlendMode Protocol
on ciFilterColorDodgeBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIColorDodgeBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterColorDodgeBlendMode

(*
   Creates composite image samples by choosing the darker samples (from either the source
   image or the background).
*)

-- CIFilter DarkenBlendMode Protocol
on ciFilterDarkenBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIDarkenBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterDarkenBlendMode

(*
   Subtracts either the source image sample color from the background image sample color,
   or the reverse, depending on which sample has the greater brightness value.
*)

-- CIFilter DifferenceBlendMode Protocol
on ciFilterDifferenceBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIDifferenceBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterDifferenceBlendMode

(*
   Divides the background image sample color from the source image sample color.
*)

-- CIFilter DivideBlendMode Protocol
on ciFilterDivideBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIDivideBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterDivideBlendMode

(*
   Produces an effect similar to that produced by the CIDifferenceBlendMode
   filter but with lower contrast.
*)

-- CIFilter ExclusionBlendMode Protocol
on ciFilterExclusionBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIExclusionBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterExclusionBlendMode

(*
   Either multiplies or screens colors, depending on the source image sample color.
*)

-- CIFilter HardLightBlendMode Protocol
on ciFilterHardLightBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIHardLightBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterHardLightBlendMode

(*
   Uses the luminance and saturation values of the background image
   with the hue of the input image.
*)

-- CIFilter HueBlendMode Protocol
on ciFilterHueBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIHueBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterHueBlendMode

(*
   Creates composite image samples by choosing the lighter samples
   (either from the source image or the background).
*)

-- CIFilter LightenBlendMode Protocol
on ciFilterLightenBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CILightenBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterLightenBlendMode

(*
   Darkens the background image samples to reflect the source image samples
   while also increasing contrast.
*)

-- CIFilter LinearBurnBlendMode Protocol
on ciFilterLinearBurnBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CILinearBurnBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterLinearBurnBlendMode

(*
   Brightens the background image samples to reflect the source image
   samples while also increasing contrast.
*)

-- CIFilter LinearDodgeBlendMode Protocol
on ciFilterLinearDodgeBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CILinearDodgeBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterLinearDodgeBlendMode

(*
   Uses the hue and saturation of the background image with the luminance
   of the input image.
*)

-- CIFilter LuminosityBlendMode Protocol
on ciFilterLuminosityBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CILuminosityBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterLuminosityBlendMode

(*
   Computes the maximum value, by color component, of two input images
   and creates an output image using the maximum values.
*)

-- CIFilter MaximumCompositing Protocol
on ciFilterMaximumCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIMaximumCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterMaximumCompositing

(*
   Computes the minimum value, by color component, of two input images
   and creates an output image using the minimum values.
*)

-- CIFilter MinimumCompositing Protocol
on ciFilterMinimumCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIMinimumCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterMinimumCompositing

(*
   Multiplies the input image samples with the background image samples.
*)

-- CIFilter MultiplyBlendMode Protocol
on ciFilterMultiplyBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIMultiplyBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterMultiplyBlendMode

(*
   Multiplies the color component of two input images and creates an output image
   using the multiplied values.
*)

-- CIFilter MultiplyCompositing Protocol
on ciFilterMultiplyCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIMultiplyCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterMultiplyCompositing

(*
   Either multiplies or screens the input image samples with the background
   image samples, depending on the background color.
*)

-- CIFilter OverlayBlendMode Protocol
on ciFilterOverlayBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIOverlayBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterOverlayBlendMode

(*
   Conditionally replaces background image samples with source image samples
   depending on the brightness of the source image samples.
*)

-- CIFilter PinLightBlendMode Protocol
on ciFilterPinLightBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIPinLightBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterPinLightBlendMode

(*
   Uses the luminance and hue values of the background image with the saturation
   of the input image.
*)

-- CIFilter SaturationBlendMode Protocol
on ciFilterSaturationBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISaturationBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSaturationBlendMode

(*
   Multiplies the inverse of the input image samples with the inverse of
   the background image samples.
*)

-- CIFilter ScreenBlendMode Protocol
on ciFilterScreenBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIScreenBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterScreenBlendMode

(*
   Either darkens or lightens colors, depending on the input image sample color.
*)

-- CIFilter SoftLightBlendMode Protocol
on ciFilterSoftLightBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISoftLightBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSoftLightBlendMode

(*
   Places the input image over the background image, then uses the luminance
   of the background image to determine what to show.
*)

-- CIFilter SourceAtopCompositing Protocol
on ciFilterSourceAtopCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISourceAtopCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSourceAtopCompositing

(*
   Uses the background image to define what to leave in the input image,
   effectively cropping the input image.
*)

-- CIFilter SourceInCompositing Protocol
on ciFilterSourceInCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISourceInCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSourceInCompositing

(*
   Uses the background image to define what to take out of the input image.
*)

-- CIFilter SourceOutCompositing Protocol
on ciFilterSourceOutCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISourceOutCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSourceOutCompositing

(*
   Places the input image over the input background image.
*)

-- CIFilter SourceOverCompositing Protocol
on ciFilterSourceOverCompositing(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISourceOverCompositing" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSourceOverCompositing

(*
   Subtracts the background image sample color from the source image sample color.
*)

-- CIFilter SubtractBlendMode Protocol
on ciFilterSubtractBlendMode(inputImageData, inputBackgroundImageData)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISubtractBlendMode" withInputParameters:{inputImage:inputImageData, inputBackgroundImage:inputBackgroundImageData})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSubtractBlendMode


I  have skied the highest mountain without logic, and still its the imagination that take me anywhere. Its the desire of something that matters for any knowledge I have or could learn.

Offline

 

#2 2020-06-18 11:43:32 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 282

Re: CoreImage filter reference: Composite Operation.

Core Image Framework, method: representationUsingType
https://developer.apple.com/documentati … guage=objc

EDIT 2020-06-19
Method: representationUsingType:properties:

Formats the receiver’s image data using the specified storage type and properties and returns it in a data object.


inputData = Core Image Object, outPath = Path to write file, formatType = The format to use.

Applescript:

-- NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType
on saveImageDataToFormat(inputData, outPath, formatType)
   set imageRep to current application's NSBitmapImageRep's alloc()'s initWithCIImage:inputData
   if (formatType = "BMP") then
       set imageData to (imageRep's representationUsingType:(current application's NSBMPFileType) |properties|:(missing value))
   else if (formatType = "GIF") then -- include Alpha channel
       set imageData to (imageRep's representationUsingType:(current application's NSGIFFileType) |properties|:(missing value))
   else if (formatType = "JPEG") then
       set imageData to (imageRep's representationUsingType:(current application's NSJPEGFileType) |properties|:(missing value))
   else if (formatType = "PNG") then -- include Alpha channel
       set imageData to (imageRep's representationUsingType:(current application's NSPNGFileType) |properties|:(missing value))
   else if (formatType = "TIFF") then -- include Alpha channel
       set imageData to (imageRep's representationUsingType:(current application's NSTIFFFileType) |properties|:(missing value))
   else
       error number 128
   end if
   imageData's writeToFile:outPath atomically:true
end saveImageDataToFormat

Last edited by Fredrik71 (2020-06-19 03:28:41 pm)


I  have skied the highest mountain without logic, and still its the imagination that take me anywhere. Its the desire of something that matters for any knowledge I have or could learn.

Offline

 

#3 2020-06-18 06:25:19 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6399

Re: CoreImage filter reference: Composite Operation.

Fredrik71 wrote:

This handler return NSBitmapImageRep object created from Core Image Object.



Are you sure you posted the right handler?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#4 2020-06-19 03:25:11 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 282

Re: CoreImage filter reference: Composite Operation.

Shane Stanley wrote:

Are you sure you posted the right handler?



You are right, it was wrong...

Method: representationUsingType:properties:

Formats the receiver’s image data using the specified storage type and properties and returns it in a data object.



Method: initWithCIImage:

Returns an NSBitmapImageRep object created from a Core Image object.


I  have skied the highest mountain without logic, and still its the imagination that take me anywhere. Its the desire of something that matters for any knowledge I have or could learn.

Offline

 

#5 2020-06-29 07:25:41 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 282

Re: CoreImage filter reference: Composite Operation.

In this example I have use 3 different CIFilters: CISepiaTone, CIHueAdjust and CIColorControls

Params: SepiaTone Intensity, Hue Angle, ColorControls: Saturation, Brightness and Contrast.

Applescript:

use framework "Foundation"
use framework "CoreImage"
use scripting additions

property outputFileName : "outputFilter.tif"
property sepiaToneIntensity : 1.25
property hueAdjustAngle : 3.5

set theInputImage to (choose file)
set theOutputImage to POSIX path of ((path to desktop as text) & outputFileName)
set theCIImage to current application's CIImage's imageWithContentsOfURL:theInputImage

set theCIImage to ciFilterSepiaTone(theCIImage, sepiaToneIntensity)
set theCIImage to ciFilterHueAdjust(theCIImage, hueAdjustAngle)
set theCIImage to ciFilterColorControls(theCIImage, 1.0, 0.0, 1.0)

saveImageDataToTiff(theCIImage, theOutputImage)

on ciFilterSepiaTone(inputImageData, inputIntensityValue)
   set theCIFilter to (current application's CIFilter's filterWithName:"CISepiaTone" withInputParameters:{inputImage:inputImageData, inputIntensity:inputIntensityValue})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterSepiaTone

on ciFilterHueAdjust(inputImageData, inputAngleValue)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIHueAdjust" withInputParameters:{inputImage:inputImageData, inputAngle:inputAngleValue})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterHueAdjust

on ciFilterColorControls(inputImageData, inputSaturationValue, inputBrightnessValue, inputContrastValue)
   set theCIFilter to (current application's CIFilter's filterWithName:"CIColorControls" withInputParameters:{inputImage:inputImageData, inputSaturation:inputSaturationValue, inputBrightness:inputBrightnessValue, inputContrast:inputContrastValue})
   set theCIImage to (theCIFilter's valueForKey:(current application's kCIOutputImageKey))
end ciFilterColorControls

on saveImageDataToTiff(inputData, outPath)
   -- Returns an NSBitmapImageRep object created from a Core Image object.
   set imageRep to current application's NSBitmapImageRep's alloc()'s initWithCIImage:inputData
   set imageData to imageRep's TIFFRepresentation()
   imageData's writeToFile:outPath atomically:true
end saveImageDataToTiff


I  have skied the highest mountain without logic, and still its the imagination that take me anywhere. Its the desire of something that matters for any knowledge I have or could learn.

Offline

 

#6 2020-07-01 04:01:34 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 282

Re: CoreImage filter reference: Composite Operation.

Here is example to show that Apple do not update the reference guide for Core Image Filters.

This code will count and display properties of Core Image category CICategoryBlur.

On my system Mojave count 13 filters.


If we check the reference guide of Core Image Filters
https://developer.apple.com/library/arc … index.html
Apple only include reference of 8 filters in the category CICategoryBlur

I have read in this forum its very common case that Apple could update something or exchange
but never include a reference to it.

They do include a html link in attribute string but they forgot to update the website.

Applescript:

use framework "CoreImage"

set theList to current application's CIFilter's filterNamesInCategory:"CICategoryBlur"
log (count items of theList)
repeat with filterName in theList
   log "Filter: " & filterName as text
   set theProps to (current application's CIFilter's filterWithName:filterName)'s attributes()'s |description|() as text
   log "Properties: " & theProps
end repeat

Last edited by Fredrik71 (2020-07-01 04:02:45 am)


I  have skied the highest mountain without logic, and still its the imagination that take me anywhere. Its the desire of something that matters for any knowledge I have or could learn.

Offline

 

#7 2020-07-01 05:40:22 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6399

Re: CoreImage filter reference: Composite Operation.

When in doubt, it's worth checking the header files. They often contain useful nuggets. To search them quickly, in Xcode type command-shift-O, which is open quickly.

In this case there's no extra info in CIFilter.h, but if you're running Xcode 11 you can see the new class methods introduced in 10.15 in CIFilterBuiltins.h.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#8 2020-07-01 06:33:41 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 282

Re: CoreImage filter reference: Composite Operation.

Hi Shane.

I have xcode on my sdd with Catalina OS... but not on my main computer harddisk. (256GB only)
But I have use the tool class-dump to get information sometimes.

I also realised today the html link of reference filters in previous message give a nice overview
but are not maintain like this html link are.
https://developer.apple.com/documentati … test_minor

with the option: &changes=latest_minor in the html string I could see more.

Regards.


I  have skied the highest mountain without logic, and still its the imagination that take me anywhere. Its the desire of something that matters for any knowledge I have or could learn.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)