mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-12 16:53:07 +00:00
Compare commits
9 commits
fede2d8e6f
...
b87a8e2ab8
Author | SHA1 | Date | |
---|---|---|---|
|
b87a8e2ab8 | ||
|
e6c4a72158 | ||
|
1dcb696c35 | ||
|
d580523c6e | ||
|
11da07b9ac | ||
|
7cf87ac142 | ||
|
bd7d3b19cc | ||
|
996a234d0d | ||
|
77f6bcf07b |
|
@ -8,7 +8,7 @@ var image: ImageExtended:
|
||||||
set = image_changed
|
set = image_changed
|
||||||
|
|
||||||
|
|
||||||
func _init(_image: ImageExtended, _opacity := 1.0) -> void:
|
func _init(_image := ImageExtended.new(), _opacity := 1.0) -> void:
|
||||||
image_texture = ImageTexture.new()
|
image_texture = ImageTexture.new()
|
||||||
image = _image # Set image and call setter
|
image = _image # Set image and call setter
|
||||||
opacity = _opacity
|
opacity = _opacity
|
||||||
|
@ -20,7 +20,7 @@ func image_changed(value: ImageExtended) -> void:
|
||||||
image_texture.set_image(image)
|
image_texture.set_image(image)
|
||||||
|
|
||||||
|
|
||||||
func get_content():
|
func get_content() -> ImageExtended:
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,17 +34,19 @@ func set_content(content, texture: ImageTexture = null) -> void:
|
||||||
image_texture.update(image)
|
image_texture.update(image)
|
||||||
|
|
||||||
|
|
||||||
func create_empty_content():
|
func create_empty_content() -> ImageExtended:
|
||||||
var empty_image := Image.create(
|
var empty := Image.create(image.get_width(), image.get_height(), false, image.get_format())
|
||||||
image.get_size().x, image.get_size().y, false, Image.FORMAT_RGBA8
|
var new_image := ImageExtended.new()
|
||||||
)
|
new_image.copy_from_custom(empty, image.is_indexed)
|
||||||
return empty_image
|
return new_image
|
||||||
|
|
||||||
|
|
||||||
func copy_content():
|
func copy_content() -> ImageExtended:
|
||||||
var copy_image := Image.create_from_data(
|
var tmp_image := Image.create_from_data(
|
||||||
image.get_width(), image.get_height(), false, Image.FORMAT_RGBA8, image.get_data()
|
image.get_width(), image.get_height(), false, image.get_format(), image.get_data()
|
||||||
)
|
)
|
||||||
|
var copy_image := ImageExtended.new()
|
||||||
|
copy_image.copy_from_custom(tmp_image, image.is_indexed)
|
||||||
return copy_image
|
return copy_image
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,9 @@ func select_palette(_name: String, convert_to_rgb := true) -> void:
|
||||||
|
|
||||||
## Updates [member palette] to contain the colors of [member current_palette].
|
## Updates [member palette] to contain the colors of [member current_palette].
|
||||||
func update_palette() -> void:
|
func update_palette() -> void:
|
||||||
if palette.size() != current_palette.colors.size():
|
if palette.size() != current_palette.colors_max:
|
||||||
palette.resize(current_palette.colors.size())
|
palette.resize(current_palette.colors_max)
|
||||||
|
palette.fill(TRANSPARENT)
|
||||||
for i in current_palette.colors:
|
for i in current_palette.colors:
|
||||||
palette[i] = current_palette.colors[i].color
|
palette[i] = current_palette.colors[i].color
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ func update_palette() -> void:
|
||||||
func convert_indexed_to_rgb() -> void:
|
func convert_indexed_to_rgb() -> void:
|
||||||
if not is_indexed:
|
if not is_indexed:
|
||||||
return
|
return
|
||||||
var palette_image := Palettes.current_palette.convert_to_image()
|
var palette_image := Palettes.current_palette.convert_to_image(false)
|
||||||
var palette_texture := ImageTexture.create_from_image(palette_image)
|
var palette_texture := ImageTexture.create_from_image(palette_image)
|
||||||
var shader_image_effect := ShaderImageEffect.new()
|
var shader_image_effect := ShaderImageEffect.new()
|
||||||
var indices_texture := ImageTexture.create_from_image(indices_image)
|
var indices_texture := ImageTexture.create_from_image(indices_image)
|
||||||
|
@ -98,7 +99,7 @@ func convert_indexed_to_rgb() -> void:
|
||||||
func convert_rgb_to_indexed() -> void:
|
func convert_rgb_to_indexed() -> void:
|
||||||
if not is_indexed:
|
if not is_indexed:
|
||||||
return
|
return
|
||||||
var palette_image := Palettes.current_palette.convert_to_image()
|
var palette_image := Palettes.current_palette.convert_to_image(false)
|
||||||
var palette_texture := ImageTexture.create_from_image(palette_image)
|
var palette_texture := ImageTexture.create_from_image(palette_image)
|
||||||
var params := {
|
var params := {
|
||||||
"palette_texture": palette_texture, "rgb_texture": ImageTexture.create_from_image(self)
|
"palette_texture": palette_texture, "rgb_texture": ImageTexture.create_from_image(self)
|
||||||
|
|
|
@ -25,7 +25,7 @@ var colors_max := 0
|
||||||
|
|
||||||
|
|
||||||
class PaletteColor:
|
class PaletteColor:
|
||||||
var color := Color.TRANSPARENT
|
var color := Color(0, 0, 0, 0)
|
||||||
var index := -1
|
var index := -1
|
||||||
|
|
||||||
func _init(init_color := Color.BLACK, init_index := -1) -> void:
|
func _init(init_color := Color.BLACK, init_index := -1) -> void:
|
||||||
|
@ -358,9 +358,11 @@ static func strip_unvalid_characters(string_to_strip: String) -> String:
|
||||||
return regex.sub(string_to_strip, "", true)
|
return regex.sub(string_to_strip, "", true)
|
||||||
|
|
||||||
|
|
||||||
func convert_to_image() -> Image:
|
func convert_to_image(crop_image := true) -> Image:
|
||||||
var image := Image.create(colors_max, 1, false, Image.FORMAT_RGBA8)
|
var image := Image.create(colors_max, 1, false, Image.FORMAT_RGBA8)
|
||||||
for i in colors_max:
|
for i in colors_max:
|
||||||
if colors.has(i):
|
if colors.has(i):
|
||||||
image.set_pixel(i, 0, colors[i].color)
|
image.set_pixel(i, 0, Color(colors[i].color.to_html()))
|
||||||
|
if crop_image:
|
||||||
|
image.copy_from(image.get_region(image.get_used_rect()))
|
||||||
return image
|
return image
|
||||||
|
|
|
@ -252,6 +252,7 @@ func _on_ColorPicker_color_changed(color: Color) -> void:
|
||||||
== Palettes.current_palette_get_selected_color_index(MOUSE_BUTTON_RIGHT)
|
== Palettes.current_palette_get_selected_color_index(MOUSE_BUTTON_RIGHT)
|
||||||
):
|
):
|
||||||
Tools.assign_color(color, MOUSE_BUTTON_RIGHT)
|
Tools.assign_color(color, MOUSE_BUTTON_RIGHT)
|
||||||
|
Palettes.current_palette_set_color(edited_swatch_index, edited_swatch_color)
|
||||||
|
|
||||||
|
|
||||||
## Saves edited swatch to palette file when color selection dialog is closed
|
## Saves edited swatch to palette file when color selection dialog is closed
|
||||||
|
|
|
@ -14,7 +14,7 @@ vec4 swap_color(vec4 color) {
|
||||||
|
|
||||||
int n_of_colors = textureSize(palette_texture, 0).x;
|
int n_of_colors = textureSize(palette_texture, 0).x;
|
||||||
int color_index = find_index(color, n_of_colors, palette_texture);
|
int color_index = find_index(color, n_of_colors, palette_texture);
|
||||||
return texture(palette_texture, vec2(float(color_index) / float(n_of_colors), 0.0));
|
return texelFetch(palette_texture, ivec2(color_index, 0), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
|
|
|
@ -2,8 +2,7 @@ int find_index(vec4 color, int n_of_colors, sampler2D palette_texture) {
|
||||||
int color_index = 0;
|
int color_index = 0;
|
||||||
float smaller_distance = distance(color, texture(palette_texture, vec2(0.0)));
|
float smaller_distance = distance(color, texture(palette_texture, vec2(0.0)));
|
||||||
for (int i = 0; i <= n_of_colors; i++) {
|
for (int i = 0; i <= n_of_colors; i++) {
|
||||||
vec2 uv = vec2(float(i) / float(n_of_colors), 0.0);
|
vec4 palette_color = texelFetch(palette_texture, ivec2(i, 0), 0);
|
||||||
vec4 palette_color = texture(palette_texture, uv);
|
|
||||||
float dist = distance(color, palette_color);
|
float dist = distance(color, palette_color);
|
||||||
if (dist < smaller_distance) {
|
if (dist < smaller_distance) {
|
||||||
smaller_distance = dist;
|
smaller_distance = dist;
|
||||||
|
|
|
@ -7,16 +7,16 @@ uniform sampler2D palette_texture : filter_nearest;
|
||||||
uniform sampler2D indices_texture : filter_nearest;
|
uniform sampler2D indices_texture : filter_nearest;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
float index = texture(indices_texture, UV).r;
|
float index = texture(indices_texture, UV).r * 255.0;
|
||||||
if (index <= EPSILON) { // If index is zero, make it transparent
|
if (index <= EPSILON) { // If index is zero, make it transparent
|
||||||
COLOR = vec4(0.0);
|
COLOR = vec4(0.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
float n_of_colors = float(textureSize(palette_texture, 0).x);
|
float n_of_colors = float(textureSize(palette_texture, 0).x);
|
||||||
index -= 1.0 / 255.0;
|
index -= 1.0;
|
||||||
float index_normalized = ((index * 255.0)) / n_of_colors;
|
float index_normalized = index / n_of_colors;
|
||||||
if (index_normalized + EPSILON < 1.0) {
|
if (index < n_of_colors) {
|
||||||
COLOR = texture(palette_texture, vec2(index_normalized + EPSILON, 0.0));
|
COLOR = texelFetch(palette_texture, ivec2(int(index), 0), 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// If index is bigger than the size of the palette, make it transparent.
|
// If index is bigger than the size of the palette, make it transparent.
|
||||||
|
|
|
@ -8,7 +8,7 @@ uniform sampler2D palette_texture : filter_nearest;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
vec4 color = texture(rgb_texture, UV);
|
vec4 color = texture(rgb_texture, UV);
|
||||||
if (color.a <= 0.01) {
|
if (color.a <= 0.0001) {
|
||||||
COLOR.r = 0.0;
|
COLOR.r = 0.0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -421,7 +421,6 @@ func _setup_color_mode_submenu(item: String) -> void:
|
||||||
color_mode_submenu.add_radio_check_item("RGBA", ColorModes.RGBA)
|
color_mode_submenu.add_radio_check_item("RGBA", ColorModes.RGBA)
|
||||||
color_mode_submenu.set_item_checked(ColorModes.RGBA, true)
|
color_mode_submenu.set_item_checked(ColorModes.RGBA, true)
|
||||||
color_mode_submenu.add_radio_check_item("Indexed", ColorModes.INDEXED)
|
color_mode_submenu.add_radio_check_item("Indexed", ColorModes.INDEXED)
|
||||||
color_mode_submenu.hide_on_checkable_item_selection = false
|
|
||||||
|
|
||||||
color_mode_submenu.id_pressed.connect(_color_mode_submenu_id_pressed)
|
color_mode_submenu.id_pressed.connect(_color_mode_submenu_id_pressed)
|
||||||
image_menu.add_child(color_mode_submenu)
|
image_menu.add_child(color_mode_submenu)
|
||||||
|
|
Loading…
Reference in a new issue