We should probably document this in a page in the documentation. Let start here in making the first attempt - let me know if you need more details.
(EDIT: We now have documented it: GitHub - SketchUp/sketchup-colorize-algorithm: Explanation of SketchUp's colorization algorithm)
SketchUp perform two types of color adjustments:
If you set a material color for a textured material via the Ruby API’s Sketchup::Material.color=
it sets the type to Sketchup::Material::COLORIZE_TINT
.
You can toggle the type using Sketchup::Material.colorize_type=
The UI have a checkbox:
For what is happening on our end:
- Each pixel is processed one by one.
- RGB value is converted to HLS.
Sketchup::Material::COLORIZE_SHIFT
- Adjustment Hue is added to Pixel Hue
- Hue ensured to be within 0-360 range by rolling around.
- Adjustment Saturation is added to Pixel Saturation (clamped to 0.0-1.0).
- Adjustment Lumination is added to Pixel Lumination (clamped to 0.01-1.0).
Sketchup::Material::COLORIZE_TINT
- Pixel Hue is set to Adjustment Hue
- Hue ensured to be within 0-360 range by rolling around.
- Adjustment Saturation is added to Pixel Saturation (clamped to 0.0-1.0).
- Adjustment Lumination is added to Pixel Lumination (clamped to 0.01-1.0).
Converting back to RGB
If the resulting Pixel Saturation is 0.0 the RGB is set to the Pixel Lumination
If not, regular HLS to RGB conversion
Maybe I should write this out into pseudo code or Ruby code…
Btw, I just noticed that the C API is lacking the properties to determine the deltas and colorization types. That will need to be added.