Git Product home page Git Product logo

sweetcorn's Introduction

sweetcorn

Node based CIKernel creation

/Sweetcorn/sweetcorn.png

/Sweetcorn/sweetcornwarp.png

Introduction

Sweetcorn is an OS X app which implements a node based user interface to create Core Image Kernel Language code. The resulting code can be used as the basis for custom Core Image filters for either OS X or iOS. Currently, Sweetcorn creates code for both CIColorKernel and CIWarpKernel based filters.

Usage

Here's a YouTube video of Sweetcorn in action.

When Sweetcorn first launches, it generates a passthrough filter where the red, green and blue input channels are mapped one-to-one to the red, green and blue output channels. To start creating a custom filter, drag a function from the left hand pane into the main workspace.

To create a relationship between two nodes, simply drag from an output and mouseup over an input channel on a target node. Legal drop targets will highlight in magenta. However, Sweetcorn won't allow circular relationships between nodes, invalid drop targets will highlight in red on mouseover.

Nodes (apart from the mandatory input and output nodes) can be deleted with a right click.

Creating a Core Image Filter

The code created by Sweetcorn is displayed in the bottom right panel. For example, a black and white filter may generate:

kernel vec4 color(__sample pixel)
{
  vec3 var_2 = vec3(0.2126, 0.7152, 0.0722); 
  float var_3 = dot(vec3(var_2.r, var_2.g, var_2.b), vec3(pixel.r, pixel.g, pixel.b)); 
  return vec4(var_3, var_3, var_3, 1.0); 
}

That code can be copied and pasted into a new text file (in Xcode, use File -> New -> File... and create an empty file under Other). If the code above is saved to a file named monochrome.cikernel, a CIColorKernel would be created with this code:

lazy var monochromeKernel: CIColorKernel =
{
    let monochromeShaderPath = NSBundle.mainBundle().pathForResource("monochrome", ofType: "cikernel")
    
    guard let path = monochromeShaderPath,
        code = try? String(contentsOfFile: path),
        kernel = CIColorKernel(string: code) else
    {
        fatalError("Unable to build monochrome shader")
    }
    
    return kernel
}()

To generate a filtered CIImage using the kernel, use this following Swift code:

let arguments = [inputImage] // inputImage is of type CIImage
        
let outputImage = monochromeKernel.applyWithExtent(inputImage.extent, 
    arguments: arguments)

If you want to learn more about Core Image filters using custom kernels and how to wrap up this kernel as a fully fledged CIFilter, I heartily recommend my book, Core Image for Swift.

Revision History

  • March 16, 2016 - Added support for saving and opening Sweetcorn project files. This functions are called from the main application menu and the projects are saved as JSON. Some of the functions are quite long, so will refactor. Also needs a step to ensure user doesn't lose data if they don't want to.

  • March 17, 2016 - Added icons. Added length, power, fractional, ceiling and floor functions. Added new vignette project example.

  • April 3, 2016 - Added support for warp kernels, added carnival mirror project. Added reflect, refact and normalize node types. Added refraction example project.

  • April 12, 2016 - Added new node types for RGB -> CMYK -> RGB and HSV -> RGB -> HSV. These node types use a new property includeFunction which embeds functions (for example cmykToRGB and rgbToHSV()) in the code. Embedded the code viewer in a scroll view for long kernels. Added new node type - RGB to luma.

Acknowledgements

The app icon is: Corn by Creative Stall from the Noun Project

sweetcorn's People

Contributors

flexmonkey avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.