Pixel-Composer/scripts/node_jpeg/node_jpeg.gml

99 lines
2.9 KiB
Text
Raw Normal View History

2024-06-09 09:56:22 +02:00
function Node_JPEG(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "JPEG";
2024-08-08 06:57:51 +02:00
inputs[0] = nodeValue_Surface("Surface in", self);
2024-06-09 09:56:22 +02:00
2024-08-08 06:57:51 +02:00
inputs[1] = nodeValue_Bool("Active", self, true);
2024-06-09 09:56:22 +02:00
active_index = 1;
2024-08-08 06:57:51 +02:00
inputs[2] = nodeValue_Int("Patch Size", self, 8)
.setValidator(VV_min(1));
2024-06-09 09:56:22 +02:00
2024-08-08 06:57:51 +02:00
inputs[3] = nodeValue_Float("Compression", self, 10);
2024-06-09 09:56:22 +02:00
2024-08-08 06:57:51 +02:00
inputs[4] = nodeValue_Int("Reconstruction", self, 8)
.setValidator(VV_min(0));
2024-06-09 09:56:22 +02:00
2024-08-08 06:57:51 +02:00
inputs[5] = nodeValue_Surface("Mask", self);
2024-06-09 09:56:22 +02:00
2024-08-08 06:57:51 +02:00
inputs[6] = nodeValue_Float("Mix", self, 1)
2024-06-09 09:56:22 +02:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-08 06:57:51 +02:00
inputs[7] = nodeValue_Toggle("Channel", self, 0b1111, { data: array_create(4, THEME.inspector_channel) });
2024-06-09 09:56:22 +02:00
__init_mask_modifier(5); // inputs 8, 9
2024-08-08 06:57:51 +02:00
inputs[10] = nodeValue_Enum_Scroll("Transformation", self, 0, [ "Cosine", "Zigzag", "Smooth Zigzag", "Step" ]);
2024-06-09 10:35:02 +02:00
2024-08-08 06:57:51 +02:00
inputs[11] = nodeValue_Rotation("Phase", self, 0);
2024-06-09 10:35:02 +02:00
2024-08-08 06:57:51 +02:00
inputs[12] = nodeValue_Bool("Deconstruct Only", self, false)
2024-06-09 10:35:02 +02:00
2024-08-08 06:57:51 +02:00
inputs[13] = nodeValue_Bool("Reconstruct All", self, false)
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone);
2024-06-09 09:56:22 +02:00
input_display_list = [ 1,
["Surface", false], 0, 5, 6, 7,
["Effects", false], 2, 3, 13, 4, 10, 11, 12,
2024-06-09 09:56:22 +02:00
];
temp_surface = array_create(2);
attribute_surface_depth();
static step = function() { #region
__step_mask_modifier();
var _reall = getSingleValue(13);
2024-08-08 06:57:51 +02:00
inputs[4].setVisible(!_reall);
2024-06-09 09:56:22 +02:00
} #endregion
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2024-06-09 10:35:02 +02:00
var _surf = _data[0];
var _patc = _data[2];
var _comp = _data[3];
var _recn = _data[4];
var _tran = _data[10];
var _phas = _data[11];
var _recon = _data[12];
var _reall = _data[13];
2024-06-09 09:56:22 +02:00
var _dim = surface_get_dimension(_surf);
for( var i = 0; i < 2; i++ ) temp_surface[i] = surface_verify(temp_surface[i], _dim[0], _dim[1], surface_rgba16float);
2024-06-09 10:35:02 +02:00
if(!_recon) {
surface_set_shader(temp_surface[0], sh_jpeg_dct);
shader_set_f("dimension", _dim);
shader_set_i("patch", _patc);
shader_set_f("compression", _comp);
shader_set_f("phase", degtorad(_phas));
shader_set_i("transform", _tran);
draw_surface_safe(_surf);
surface_reset_shader();
}
2024-06-09 09:56:22 +02:00
surface_set_shader(temp_surface[1], sh_jpeg_recons);
shader_set_f("dimension", _dim);
shader_set_i("patch", _patc);
shader_set_i("reconstruct", _reall? _patc : _recn);
2024-06-09 10:35:02 +02:00
shader_set_f("phase", degtorad(_phas));
shader_set_i("transform", _tran);
2024-06-09 09:56:22 +02:00
2024-06-09 10:35:02 +02:00
draw_surface_safe(_recon? _surf : temp_surface[0]);
2024-06-09 09:56:22 +02:00
surface_reset_shader();
surface_set_shader(_outSurf);
draw_surface_safe(temp_surface[1]);
surface_reset_shader();
__process_mask_modifier(_data);
_outSurf = mask_apply(_data[0], _outSurf, _data[5], _data[6]);
_outSurf = channel_apply(_data[0], _outSurf, _data[7]);
return _outSurf;
} #endregion
}