1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-13 09:13:07 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
Variable 2d9a582f21
Added an OKHSL Lightness sorting in palette (#1126)
* added a lightness sort system

* static check

* lightness

* formatting

* more formatting

* more formatting
2024-10-26 01:31:52 +03:00
Emmanouil Papadeas aa59f73e65
[skip ci] Update CHANGELOG.md 2024-10-25 21:32:22 +03:00
4 changed files with 37 additions and 3 deletions

View file

@ -15,10 +15,10 @@ Built using Godot 4.3
- Added a new "color replace" mode to the Shading tool, that uses the colors of the palette to apply shading. [#1107](https://github.com/Orama-Interactive/Pixelorama/pull/1107)
- Added a new Erase blend mode. [#1117](https://github.com/Orama-Interactive/Pixelorama/pull/1117)
- It is now possible to change the font, depth and line spacing of 3D text.
- Implemented the ability to change the font of the interface from the properties.
- Implemented the ability to change the font of the interface from the preferences.
- Clipping to selection during export is now possible. [#1113](https://github.com/Orama-Interactive/Pixelorama/pull/1113)
- Added a preference to share options between tools. [#1120](https://github.com/Orama-Interactive/Pixelorama/pull/1120)
- Added an option to quickly center the canvas in the View menu. Mapped to <kbd>Control + C</kbd> by default. [#1123](https://github.com/Orama-Interactive/Pixelorama/pull/1123)
- Added an option to quickly center the canvas in the View menu. Mapped to <kbd>Shift + C</kbd> by default. [#1123](https://github.com/Orama-Interactive/Pixelorama/pull/1123)
- Added hotkeys to switch between tabs. <kbd>Control+Tab</kbd> to go to the next project tab, and <kbd>Control+Shift+Tab</kbd> to go to the previous. [#1109](https://github.com/Orama-Interactive/Pixelorama/pull/1109)
- Added menus next to each of the two mirroring buttons in the Global Tool Options, that allow users to automatically move the symmetry guides to the center of the canvas, or the view center.
- A new Reset category has been added to the Preferences that lets users easily restore certain options.

View file

@ -4,7 +4,7 @@ signal palette_selected(palette_name: String)
signal new_palette_created
signal new_palette_imported
enum SortOptions { NEW_PALETTE, REVERSE, HUE, SATURATION, VALUE, RED, GREEN, BLUE, ALPHA }
enum SortOptions {NEW_PALETTE, REVERSE, HUE, SATURATION, VALUE, LIGHTNESS, RED, GREEN, BLUE, ALPHA}
## Presets for creating a new palette
enum NewPalettePresetType {EMPTY, FROM_CURRENT_PALETTE, FROM_CURRENT_SPRITE, FROM_CURRENT_SELECTION}
## Color options when user creates a new palette from current sprite or selection

View file

@ -287,6 +287,38 @@ func sort(option: Palettes.SortOptions) -> void:
sort_method = func(a: PaletteColor, b: PaletteColor): return a.color.s < b.color.s
Palettes.SortOptions.VALUE:
sort_method = func(a: PaletteColor, b: PaletteColor): return a.color.v < b.color.v
Palettes.SortOptions.LIGHTNESS:
# Code inspired from:
# gdlint: ignore=max-line-length
# https://github.com/bottosson/bottosson.github.io/blob/master/misc/colorpicker/colorconversion.js#L519
sort_method = func(a: PaletteColor, b: PaletteColor):
# function that returns OKHSL lightness
var lum: Callable = func(c: Color):
var l = 0.4122214708 * (c.r) + 0.5363325363 * (c.g) + 0.0514459929 * (c.b)
var m = 0.2119034982 * (c.r) + 0.6806995451 * (c.g) + 0.1073969566 * (c.b)
var s = 0.0883024619 * (c.r) + 0.2817188376 * (c.g) + 0.6299787005 * (c.b)
var l_cr = pow(l, 1 / 3.0)
var m_cr = pow(m, 1 / 3.0)
var s_cr = pow(s, 1 / 3.0)
var oklab_l = 0.2104542553 * l_cr + 0.7936177850 * m_cr - 0.0040720468 * s_cr
# calculating toe
var k_1 = 0.206
var k_2 = 0.03
var k_3 = (1 + k_1) / (1 + k_2)
return (
0.5
* (
k_3 * oklab_l
- k_1
+ sqrt(
(
(k_3 * oklab_l - k_1) * (k_3 * oklab_l - k_1)
+ 4 * k_2 * k_3 * oklab_l
)
)
)
)
return lum.call(a.color.srgb_to_linear()) < lum.call(b.color.srgb_to_linear())
Palettes.SortOptions.RED:
sort_method = func(a: PaletteColor, b: PaletteColor): return a.color.r < b.color.r
Palettes.SortOptions.GREEN:

View file

@ -49,6 +49,8 @@ func _ready() -> void:
sort_button_popup.add_item("Sort by saturation", Palettes.SortOptions.SATURATION)
sort_button_popup.add_item("Sort by value", Palettes.SortOptions.VALUE)
sort_button_popup.add_separator()
sort_button_popup.add_item("Sort by lightness", Palettes.SortOptions.LIGHTNESS)
sort_button_popup.add_separator()
sort_button_popup.add_item("Sort by red", Palettes.SortOptions.RED)
sort_button_popup.add_item("Sort by green", Palettes.SortOptions.GREEN)
sort_button_popup.add_item("Sort by blue", Palettes.SortOptions.BLUE)