LookupTables - Serabe/rinzelight GitHub Wiki

Theory

What is a lookup table?

An image can be seen as an array of shorts. Each pixel is represented by four numbers, one for each channel: red, green, blue and alpha. Each number ranges from zero to (quantum-range).

Rinzelight lookup tables are based on Java LookupOp. A lookup table is just a collection of arrays, one for each channel, such that if the current value of the pixel is x, then the returned value is arr[x].

Types of lookup tables.

There are two types of lookup tables:

  • Single sample lookup table: this lookup table is just an array that will be used for all channel. Since it will be used for alpha too, you may need to use multisample-lookup-table for using it correctly.
  • Multisample lookup table: this one is composed of four arrays, one for each sample or channel in the image.

Take a look at multisample-lookup-table

Practice

Creating a lookup table from a function.

The function rinzelight.effects.lookup-tables/lookup-table-from given a function f retrieves an array with f applied to the index.

Example
(def brighten (lookup-table-from (fn [x] (/ (+ (quantum-range) x) 2))))

Creating a multisample lookup table from simple lookup tables.

Using a simple channel lookup table is not adviced since it will be used for the alpha channel as well. Most of the times, you will use the predefined straight lookup table for opacity channel.

multisample-lookup-table helps in creating multisample lookup table. If only one simple lookup tables lt is supplied, then it will return a multisample lookup table that applies lt to the red, green and blue channels, while using straight for handling the opacity. If it is used on three simple lookup tables, they will considered them as the ones for red, green and blue, respectively, and will apply straight to alpha channel. When used on four parameters, they will combined them into a two dimensional array.

Creating a multisample lookup table from a pixel function.

There are two rules for this function:

1. Don’t use it.
2. Really, just don’t.

Applying a lookup table.

rinzelight.effects.lookup-tables/apply-lookup-table applies a lookuptable lt to an image img. You may use rendering hints just by adding them at the end.

Example

(def img (read-image "samples/northern-ligths"))
(apply-lookup-table img (multisample-lookup-table better-brighten) antialiasing-on rendering-quality)

Sample images after applying default lookuptable

brighten

better-brighten

invert

posterize

straight

zero

⚠️ **GitHub.com Fallback** ⚠️