pipeline

package
v0.0.0-...-b22b293 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2016 License: MIT Imports: 10 Imported by: 0

README

The Image Processing Pipeline

An image processing pipeline is the representation of an ordered list of operations, and is a complete description of the processed result for any particular original image.

Pipelines are identified by the parameters that describe them, for example, a parameter list saturation=10,width=500 will correspond to the following pipeline:

Pipeline {
	Resize {
		Width: 500,
	},
	Adjust {
		Saturation: 10,
	},
}

The above is a complete description of the manipulations required for processing an image. Also, note that the order of parameters does not affect the final order of operations, and thus a pipeline can be identified by more than one parameter lists.

Parameters are comma-separated key-value assignments, for example width=500,fit=crop. Certain parameters have additional constraints on their values, as described below.

Operations

Operations are the building blocks of the image processing pipeline, and are defined as sets of related image manipulation tasks, e.g. resizing, adjusting colors etc.

What follows is a reference list of all available operations, along with a list of parameters relevant to each one.

Resize

The resize operation handles any manipulation of the image's dimensions, including clipping and cropping. The parameters relevant to this operation are:

Name Description Accepted Values Default Value
width Image width. If 0, calculate from height 0 ... infinity 0
height Image height. If 0, calculate from width 0 ... infinity 0
fit Fit mode for resized image crop clip
width and height

These parameters accept any integer value, but negative numbers and values that are equal or exceed the original image's resolution result in the original image being returned.

fit

Determines the way in which the image will attempt fit the constraints imposed by the pipeline. Supported fit modes and their additional options include:

  • clip: Attempts to resize image so that resulting image dimensions are smaller or equal to the pipeline constraints. So, for an image of size 1000x500 and a pipeline of width=500,height=200, the resulting image will be of size 400x200. This is the default.
  • crop: Attempts resize image to the exact size requested, cropping any additional parts of the image. Supports the following colon-separated options:
    • top, bottom, left, right, center, which define the center of gravity for the cropped image. So, for the above example and a fit of fit=crop:bottom, the top 50 pixels of the image would be cropped. Default is center.
    • point, which defines the center of gravity for a cropped image as X and Y pixel co-ordinates. For example, the center point of focus for the above example would be expressed by a pipeline of fit=crop:point:500:250.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation interface {
	Process(*C.ico_image) error
}

An Operation represents a set of related image manipulation tasks, e.g. resizing cropping. The results of processing an operation against a specific image are guaranteed to be deterministic.

func NewResize

func NewResize(p *Params) (Operation, error)

NewResize attempts to initialize a resize operation from the parameters provided. Width and/or height parameters have to be provided, otherwise the resize operation is skipped.

type Params

type Params map[string]string

Params represents a list of pipeline parameters, indexed under their unique name. Parameter values may contain a prefix, which is typically removed when unpacking to a destination structure.

func Parse

func Parse(params string) (*Params, error)

Parse slices the parameter string provided and returns a Params instance, allowing for processing on individual parameters. Returns an error if parsing fails for any reason.

func (*Params) Unpack

func (p *Params) Unpack(dest interface{}) error

Unpack stores the partially parsed parameter list in the destination structure.

type Pipeline

type Pipeline struct {
	// contains filtered or unexported fields
}

A Pipeline represents all data required for converting an image from its original format to the processed result.

func New

func New(params string) (*Pipeline, error)

New parses the parameter list provided and initializes a Pipeline and supporting list of Operations stored within.

func (*Pipeline) Error

func (p *Pipeline) Error() error

Error returns the last error generated by the pipeline, if any.

func (*Pipeline) Process

func (p *Pipeline) Process(img *image.Image) error

Process applies the set of operations defined for the pipeline against the provided image data. An error is returned if processing fails at any point, otherwise the image provided is modified in-place and nil is returned.

type Resize

type Resize struct {
	Width  int64 `key:"width"`
	Height int64 `key:"height"`
	Fit    struct {
		Kind string `key:"fit" default:"clip" valid:"crop"`
		Crop struct {
			Gravity string `key:"fit=crop" default:"center" valid:"top|bottom|left|right|point"`
			Point   struct {
				X int64 `key:"fit=crop:point" index:"0"`
				Y int64 `key:"fit=crop:point" index:"1"`
			}
		}
	}
}

Resize is an operation for manipulating image dimensions, including clipping, cropping and focusing within images.

func (*Resize) Process

func (r *Resize) Process(img *C.ico_image) error

Process applies the pre-defined constraints for this operation onto the image provided, changing the data in-place and freeing any additional allocations made automatically. Returns an error if processing fails for any reason.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL