colo icon indicating copy to clipboard operation
colo copied to clipboard

Implement `filter` WIP, using logos

Open Aloso opened this issue 5 years ago • 0 comments

Closes #12

Adds a filter subcommand (f for short) with advanced color editing capabilities. filter expects a list of instructions. Each instruction is either a CSS filter or a color component instruction.

Available CSS filters are:

  • [x] brightness
  • [ ] contrast
  • [ ] grayscale
  • [x] hue-rotate
  • [x] invert
  • [ ] saturate
  • [ ] sepia

These filters work exactly the same as in the CSS filter property. For example, brightness 120% will increase the brightness by 20%. Note that most CSS filters use simple algorithms in the RGB color space, and may produce inadequate results. For better results, modify the color components directly in a suitable color space.

Color components are specified with the syntax <color_space>:<component>. For example, hsl:s specifies the saturation component in the HSL color space. For RGB and HSL, the color space is optional, i.e. r is equivalent to rgb:r, l is equivalent to hsl:l, and so on.

Each CSS filter name or color component is followed by a number. This number can be negative, and it can be written in percent. For color components, the value can be preceded my an operator, which is one of

  • * for multiplication (this must be escaped in some shells)
  • / for division
  • = to replace the value

Examples

# set the red component to 50, increase brightness by 20% and increase the HSV saturation component by 0.3
colo filter r=50, brightness 120%, hsv:s 0.3  -- orange blue 15A

# the above is equivalent to this:
colo filter "r = 50 brightness(120%) hsv:s+0.3"  -- orange blue 15A

As you can see, the format is whitespace insensitive and ignores commas. Values can optionally be wrapped in parentheses, to be fully compatible with the CSS syntax.

Aloso avatar Dec 12 '20 12:12 Aloso