mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 14:44:42 -04:00
Update gdgifexporter (#299)
This commit is contained in:
parent
da656df5b7
commit
e171e2ee65
5 changed files with 55 additions and 24 deletions
|
@ -1,7 +1,20 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func setup(image: Image, colors: Array) -> PoolByteArray:
|
||||
var _shader: Shader
|
||||
|
||||
|
||||
func get_indexed_datas(image: Image, colors: Array) -> PoolByteArray:
|
||||
_shader = preload("./lookup_color.shader")
|
||||
return _convert(image, colors)
|
||||
|
||||
|
||||
func get_similar_indexed_datas(image: Image, colors: Array) -> PoolByteArray:
|
||||
_shader = preload("./lookup_similar.shader")
|
||||
return _convert(image, colors)
|
||||
|
||||
|
||||
func _convert(image: Image, colors: Array) -> PoolByteArray:
|
||||
var vp = VisualServer.viewport_create()
|
||||
var canvas = VisualServer.canvas_create()
|
||||
VisualServer.viewport_attach_canvas(vp, canvas)
|
||||
|
@ -18,13 +31,13 @@ func setup(image: Image, colors: Array) -> PoolByteArray:
|
|||
texture.create_from_image(image)
|
||||
VisualServer.canvas_item_add_texture_rect(ci_rid, Rect2(Vector2(0, 0), image.get_size()), texture)
|
||||
|
||||
var shader = preload("./lookup_similar.shader")
|
||||
var mat_rid = VisualServer.material_create()
|
||||
VisualServer.material_set_shader(mat_rid, shader.get_rid())
|
||||
VisualServer.material_set_shader(mat_rid, _shader.get_rid())
|
||||
var lut = Image.new()
|
||||
lut.create(256, 1, false, Image.FORMAT_RGB8)
|
||||
lut.fill(Color8(colors[0][0], colors[0][1], colors[0][2]))
|
||||
lut.lock()
|
||||
for i in 256:
|
||||
for i in colors.size():
|
||||
lut.set_pixel(i, 0, Color8(colors[i][0], colors[i][1], colors[i][2]))
|
||||
var lut_tex = ImageTexture.new()
|
||||
lut_tex.create_from_image(lut)
|
||||
|
@ -35,5 +48,11 @@ func setup(image: Image, colors: Array) -> PoolByteArray:
|
|||
VisualServer.viewport_set_vflip(vp, true)
|
||||
VisualServer.force_draw(false)
|
||||
image = VisualServer.texture_get_data(VisualServer.viewport_get_texture(vp))
|
||||
|
||||
VisualServer.free_rid(vp)
|
||||
VisualServer.free_rid(canvas)
|
||||
VisualServer.free_rid(ci_rid)
|
||||
VisualServer.free_rid(mat_rid)
|
||||
|
||||
image.convert(Image.FORMAT_R8)
|
||||
return image.get_data()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue