Recolor

smile.pictures.Recolor
object Recolor

Recolors a picture with a function on packed ARGB colors, as a bitmap's color operation does, while keeping the picture's shapes where the function lets it.

The result's pixels are always exactly those of the picture rendered with the given settings and transformed pixel by pixel, which is what picture.toBitmap(settings).transformARGB(f, settings) gives, or for a bitmap that only its own operations have placed, its own pixels for the settings transformed, as bitmap.transformARGB(f, settings) gives. The function is called exactly as there, once for each pixel of that render, row by row, top row first.

Recoloring goes in four steps:

  1. Observe. While the function is called, a table of what it gave for each color is kept, along with whether it ever gave two answers for one color. A picture that is only a bitmap of pixels, holds an animation or covers no whole pixel falls back whatever the function gives, so for it no table is kept.
  2. Fall back. The result is a bitmap of the pixels alone when the function did that, when the picture paints with a color that no pixel showed it, when the table has more than 4096 colors, when the picture is only a bitmap of pixels, when it holds an animation, when it covers no whole pixel, or when the rebuilt picture would nest more than 8 pictures deep inside bitmaps of pictures. An SVG picture's document is not recolored, so a picture that shows one falls back too, at the verification below, whenever the function changes a color the document shows.
  3. Rebuild. Otherwise the picture is rebuilt with the colors of its fills, strokes, text, gradient stops and bitmap pixels replaced through the table. A mask lends only its opacity, so it stays as it is. When the function gave transparent pixels a visible color, a rectangle of that color goes behind the picture, on the pixels of its frame. The rebuilt picture is clipped to that frame, the whole pixels of the render.
  4. Verify. The rebuilt picture is rendered with the same settings. When its pixels are the observed ones, the result is a bitmap of the rebuilt picture whose checkpoint is the observed pixels for the settings, which an output with those settings takes and replays any later operation on. Any other output renders the rebuilt picture, a Direct one at its own scale. Otherwise the result is the bitmap of the pixels alone.

Attributes

Source
Recolor.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Recolor.type

Members list

Value members

Concrete methods

def apply(picture: Element, f: Int => Int, settings: RenderSettings): Bitmap

Recolors picture with f.

Recolors picture with f.

Value parameters

f

A function from a packed ARGB pixel to its replacement.

settings

The settings the picture is rendered with, whose pixels f transforms. A bitmap that only its own operations have placed is its own pixels, computed with these settings, as a bitmap's color operations compute them.

Attributes

Returns

A bitmap whose pixels are the transformed ones, anchored where the picture is.

Source
Recolor.scala