@@ -42,86 +42,86 @@ if jit ~= nil then
4242 } Pixel;
4343 ]])
4444
45- local function get_left(cdata, w, h)
46- for x = 0, w - 1 do for y = 0, h - 1 do
45+ local function get_left(cdata, w, h, top, bottom )
46+ for x = 0, w - 1 do for y = top, bottom do
4747 if (cdata + x + y * w).a ~= 0 then return x end
4848 end end
4949 return -1
5050 end
5151
52- local function get_right(cdata, w, h)
53- for x = w - 1, 0, -1 do for y = 0, h - 1 do
52+ local function get_right(cdata, w, h, top, bottom )
53+ for x = w - 1, 0, -1 do for y = top, bottom do
5454 if (cdata + x + y * w).a ~= 0 then return x end
5555 end end
5656 return -1
5757 end
5858
59- local function get_top(cdata, w, h, left, right )
60- for y = 0, h - 1 do for x = left, right do
59+ local function get_top(cdata, w, h)
60+ for y = 0, h - 1 do for x = 0, w - 1 do
6161 if (cdata + x + y * w).a ~= 0 then return y end
6262 end end
6363 return -1
6464 end
6565
66- local function get_bottom(cdata, w, h, left, right )
67- for y = h - 1, 0, -1 do for x = left, right do
66+ local function get_bottom(cdata, w, h)
67+ for y = h - 1, 0, -1 do for x = 0, w - 1 do
6868 if (cdata + x + y * w).a ~= 0 then return y end
6969 end end
7070 return -1
7171 end
7272
7373 local data, _, _ = obj.getpixeldata()
7474 local cdata = ffi.cast("Pixel*", data)
75- left = get_left (cdata, w, h)
76- if left == -1 then
75+ top = get_top (cdata, w, h)
76+ if top == -1 then
7777 return
7878 end
79- right = get_right (cdata, w, h)
80- top = get_top (cdata, w, h, left, right )
81- bottom = get_bottom (cdata, w, h, left, right )
79+ bottom = get_bottom (cdata, w, h)
80+ left = get_left (cdata, w, h, top, bottom )
81+ right = get_right (cdata, w, h, top, bottom )
8282
8383else
8484
8585 -- Lua
86- local function get_left(w, h)
87- for x = 0, w - 1 do for y = 0, h - 1 do
86+ local function get_left(w, h, top, bottom )
87+ for x = 0, w - 1 do for y = top, bottom do
8888 local col, a = obj.getpixel(x, y, "col")
8989 if a ~= 0 then return x end
9090 end end
9191 return -1
9292 end
9393
94- local function get_right(w, h)
95- for x = w - 1, 0, -1 do for y = 0, h - 1 do
94+ local function get_right(w, h, top, bottom )
95+ for x = w - 1, 0, -1 do for y = top, bottom do
9696 local col, a = obj.getpixel(x, y, "col")
9797 if a ~= 0 then return x end
9898 end end
9999 return -1
100100 end
101101
102- local function get_top(w, h, left, right )
103- for y = 0, h - 1 do for x = left, right do
102+ local function get_top(w, h)
103+ for y = 0, h - 1 do for x = 0, w - 1 do
104104 local col, a = obj.getpixel(x, y, "col")
105105 if a ~= 0 then return y end
106106 end end
107107 return -1
108108 end
109109
110- local function get_bottom(w, h, left, right )
111- for y = h - 1, 0, -1 do for x = left, right do
110+ local function get_bottom(w, h)
111+ for y = h - 1, 0, -1 do for x = 0, w - 1 do
112112 local col, a = obj.getpixel(x, y, "col")
113113 if a ~= 0 then return y end
114114 end end
115115 return -1
116116 end
117117
118- left = get_left (w, h)
119- if left == -1 then
118+ top = get_top (w, h)
119+ if top == -1 then
120120 return
121121 end
122- right = get_right (w, h)
123- top = get_top (w, h, left, right )
124- bottom = get_bottom (w, h, left, right )
122+ bottom = get_bottom (w, h)
123+ left = get_left (w, h, top, bottom )
124+ right = get_right (w, h, top, bottom )
125125end
126126
127127obj.effect("クリッピング", "上", top + crop[1], "下", h - bottom - 1 + crop[2], "左", left + crop[3], "右", w - right - 1 + crop[4], "中心の位置を変更", chk)
0 commit comments