|
| 1 | +TOOL_IMGEDIT_CMDS = [ |
| 2 | + "mad" |
| 3 | + "colourify" |
| 4 | + "colourmask" |
| 5 | + "invert" |
| 6 | + "invertchan" |
| 7 | + "normal" |
| 8 | + "dup" |
| 9 | + "offset" |
| 10 | + "rotate" |
| 11 | + "crop" |
| 12 | + "blur" |
| 13 | + "premul" |
| 14 | + "agrad" |
| 15 | + // "blend" |
| 16 | + "dds" |
| 17 | + "nocompress" |
| 18 | + "anim" |
| 19 | +] |
| 20 | + |
| 21 | +TOOL_IMGEDIT_CMD_NAMES = [ |
| 22 | + "Multiply & Add" |
| 23 | + "Colourify" // Luminance-based colouring |
| 24 | + "Colour mask" // Lerp between two colours based on alpha |
| 25 | + "Invert" // Inverts all channels |
| 26 | + "Invert channel" // Invert a single channel |
| 27 | + "Generate normalmap" // Generates a normalmap from diffuse |
| 28 | + "Copy channel" // Copies a channel to another |
| 29 | + "Offset" // Offsets the image in pixels |
| 30 | + "Rotate" // Rotates and/or flips the image |
| 31 | + "Crop" |
| 32 | + "Blur" |
| 33 | + "Premultiplied alpha" |
| 34 | + "Alpha gradient" |
| 35 | + // "Blend with" |
| 36 | + "Use DDS" |
| 37 | + "Force no compression" |
| 38 | + "Animation" |
| 39 | +] |
| 40 | + |
| 41 | +TOOL_IMGEDIT_CMD_DEFAULTS = [ |
| 42 | + [[1 1 1] [0 0 0]] // mad |
| 43 | + [[0 0 0]] // colourify |
| 44 | + [[0 0 0] [0 0 0]] // colourmask |
| 45 | + [] // invert |
| 46 | + [0] // invertchan |
| 47 | + [3] // normal |
| 48 | + [0 0] // dup |
| 49 | + [0 0] // offset |
| 50 | + [0] // rotate |
| 51 | + [0 0 -1 -1] // crop |
| 52 | + [1 1] // blur |
| 53 | + [] // premul |
| 54 | + [1 1 0 0] // agrad |
| 55 | + // blend |
| 56 | + [] // dds |
| 57 | + [] // nocompress |
| 58 | + [50 1 2 0 0 0] // anim |
| 59 | +] |
| 60 | + |
| 61 | +tool_imgedit_var = [] |
| 62 | +tool_imgedit_imgpath = "" |
| 63 | +tool_imgedit_cmds = [] |
| 64 | +tool_imgedit_cmd_idxs = [] |
| 65 | +tool_imgedit_numcmds = 0 |
| 66 | + |
| 67 | +tool_imgedit_getcmds = [ |
| 68 | + local _cmd |
| 69 | + |
| 70 | + tool_imgedit_imgpath = (tool_path_striptexcmds $$tool_imgedit_var) |
| 71 | + tool_imgedit_cmds = (tool_path_gettexcmds $$tool_imgedit_var) |
| 72 | + tool_imgedit_numcmds = (listlen $tool_imgedit_cmds) |
| 73 | + tool_imgedit_cmd_idxs = [] |
| 74 | + |
| 75 | + loop i $tool_imgedit_numcmds [ |
| 76 | + _cmd = (at $tool_imgedit_cmds $i) |
| 77 | + |
| 78 | + [tool_imgedit_cmd_tmp_@i] = $_cmd |
| 79 | + |
| 80 | + append tool_imgedit_cmd_idxs (listfind=s $TOOL_IMGEDIT_CMDS (at $_cmd 0)) |
| 81 | + ] |
| 82 | +] |
| 83 | + |
| 84 | +tool_imgedit_apply = [ |
| 85 | + local _cmd _cmds |
| 86 | + |
| 87 | + tool_imgedit_cmds = [] |
| 88 | + _cmds = [] |
| 89 | + |
| 90 | + loop i $tool_imgedit_numcmds [ |
| 91 | + _cmd = $[tool_imgedit_cmd_tmp_@i] |
| 92 | + append tool_imgedit_cmds [[@@_cmd]] |
| 93 | + appendword _cmds (tool_path_maketexcmd $_cmd) |
| 94 | + ] |
| 95 | + |
| 96 | + set $tool_imgedit_var (concatword $_cmds $tool_imgedit_imgpath) |
| 97 | +] |
| 98 | + |
| 99 | +// 1:<index> 2:<direction (-1 left/1 right)> |
| 100 | +tool_imgedit_cmd_shift = [ |
| 101 | + local _min_idx _max_idx _new_idx |
| 102 | + _min_idx = (? (= $arg2 -1) 1 0) |
| 103 | + _max_idx = (- $tool_imgedit_numcmds (? (= $arg2 1) 1 0)) |
| 104 | + _new_idx = (+ $arg1 $arg2) |
| 105 | + |
| 106 | + if (&& [>= $arg1 $_min_idx] [< $arg1 $_max_idx]) [ |
| 107 | + local _tmp |
| 108 | + _tmp = $[tool_imgedit_cmd_tmp_@arg1] |
| 109 | + |
| 110 | + [tool_imgedit_cmd_tmp_@arg1] = $[tool_imgedit_cmd_tmp_@_new_idx] |
| 111 | + [tool_imgedit_cmd_tmp_@_new_idx] = $_tmp |
| 112 | + |
| 113 | + _tmp = (at $tool_imgedit_cmd_idxs $arg1) |
| 114 | + tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs (at $tool_imgedit_cmd_idxs $_new_idx) $arg1 1) |
| 115 | + tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs $_tmp $_new_idx 1) |
| 116 | + ] |
| 117 | +] |
| 118 | + |
| 119 | +// 1:<index> 2:<type idx> |
| 120 | +tool_imgedit_cmd_add = [ |
| 121 | + local _new_cmd _new_args |
| 122 | + _new_cmd = (at $TOOL_IMGEDIT_CMDS $arg2) |
| 123 | + _new_args = (at $TOOL_IMGEDIT_CMD_DEFAULTS $arg2) |
| 124 | + |
| 125 | + if (!=s $_new_args []) [ |
| 126 | + append _new_cmd $_new_args |
| 127 | + ] |
| 128 | + |
| 129 | + looprev i $tool_imgedit_numcmds [ |
| 130 | + if (>= $i $arg1) [ |
| 131 | + [tool_imgedit_cmd_tmp_@(+ $i 1)] = $[tool_imgedit_cmd_tmp_@i] |
| 132 | + ] |
| 133 | + ] |
| 134 | + |
| 135 | + [tool_imgedit_cmd_tmp_@arg1] = [@_new_cmd] |
| 136 | + tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs (concat $arg2 (at $tool_imgedit_cmd_idxs $arg1)) $arg1 1) |
| 137 | + |
| 138 | + tool_imgedit_numcmds = (+ $tool_imgedit_numcmds 1) |
| 139 | +] |
| 140 | + |
| 141 | +// 1:<index> |
| 142 | +tool_imgedit_cmd_remove = [ |
| 143 | + loop i (- $tool_imgedit_numcmds 1) [ |
| 144 | + if (>= $i $arg1) [ |
| 145 | + [tool_imgedit_cmd_tmp_@i] = $[tool_imgedit_cmd_tmp_@(+ $i 1)] |
| 146 | + ] |
| 147 | + ] |
| 148 | + |
| 149 | + tool_imgedit_cmd_idxs = (listsplice $tool_imgedit_cmd_idxs "" $arg1 1) |
| 150 | + tool_imgedit_numcmds = (- $tool_imgedit_numcmds 1) |
| 151 | +] |
| 152 | + |
| 153 | +// 1:<var> |
| 154 | +tool_imgedit_open = [ |
| 155 | + tool_imgedit_var = $arg1 |
| 156 | + tool_imgedit_getcmds |
| 157 | + |
| 158 | + toolpanel_open tool_imgedit center [ |
| 159 | + p_title = "Image editor" |
| 160 | + ] |
| 161 | +] |
0 commit comments