-- ハーディング(パカパカチェック)除去支援プラグイン 2018/02/09 by Cocot. --track0:検出閾値,0,127,20,1 --track1:無視輝度,1,100,100,1 --track2:修正輝度,20,100,100,1 --track3:自動補正,0,1,0,1 --check0:ヒストグラム表示,1 --dialog:処理間引きpixel,local skip=25;Hist表示位置,local histpos={0,0};Hist透過度(%),local alpha=100;センタリング/chk,local centering=1 local threshold = obj.track0 local ignore = obj.track1 local target = obj.track2 local automatic = obj.track3 local showhist = obj.check0 local top = -obj.screen_h/2 + histpos[2] local left = -obj.screen_w/2 + histpos[1] local pixels = obj.screen_w * obj.screen_h -- ヒストグラムの最大値 local max = math.floor(255 * ignore / 100) -- ヒストグラム初期化 local histgram = {} for Y = 0, 255 do histgram[Y] = 0 end -- ヒストグラム作成 local width = obj.screen_w if skip < 1 then skip = 25 end for pixel = 0, pixels - 1, skip + 1 do x = pixel % width y = math.floor(pixel / width) local r, g, b, a = obj.getpixel(x, y, "rgb") local Y = math.floor(0.299 * r + 0.587 * g + 0.114 * b) histgram[Y] = histgram[Y] + 1 end -- ハーディングチェック local harding = max for Y = max, 0, -1 do if histgram[Y] >= threshold then harding = Y break end end if harding == 0 then harding = 255 end -- 真っ黒の時は未補正とする local newvalue = 255 * target / harding if newvalue > 200 then newvalue = 200 end if automatic == 1 then -- 輝度と彩度を自動で調整する obj.effect("色調補正", "輝度", newvalue, "彩度" , newvalue) end if centering == 1 then obj.draw(-obj.x,-obj.y) else obj.draw() end if showhist then -- ヒストグラムの背景 obj.load("figure", "四角形", 0x404040, 64) obj.drawpoly(left,top,0, left+255,top,0, left+255,top+161,0, left,top+161,0, 0,0, 255,0, 255,255, 0,255, alpha/100) -- ヒストグラムを描画 local graph_bottom = top + 127 local x1, x2, x3, x4, y1, y2, y3, y4 for Y = 0, 255 do x1 = left + Y x2 = x1 + 1 x3 = x2 x4 = x1 y1 = graph_bottom - histgram[Y] if y1 < graph_bottom - 127 then y1 = graph_bottom - 127 end y2 = y1 y3 = graph_bottom + 1 y4 = y3 obj.load("figure", "四角形", 0xffffff, 256) obj.setoption("blend", 1) obj.drawpoly(x1,y1,0, x2,y2,0, x3,y3,0, x4,y4,0, 0,0, 255,0, 255,255, 0,255, 1) end -- 無視輝度を描画 x1 = left + max +1 x2 = left + 256 x3 = x2 x4 = x1 y1 = top y2 = y1 y3 = top + 127 y4 = y3 obj.load("figure", "四角形", 0x808080, 128) obj.setoption("blend", 3) obj.drawpoly(x1,y1,0, x2,y2,0, x3,y3,0, x4,y4,0, 0,0, 255,0, 255,255, 0,255, 1) -- 閾値ライン表示 x1 = left x2 = x1 + harding x3 = x2 x4 = left x5 = x1 + 255 y1 = graph_bottom - threshold y2 = y1 y3 = y1 + 1 y4 = y3 obj.load("figure", "四角形", 0xff0000, 1) obj.setoption("blend", 0) obj.drawpoly(x1,y1,0, x2,y2,0, x2,y3,0, x4,y4,0, 0,0, 0,0, 0,0, 0,0, 1) obj.load("figure", "四角形", 0x00d0ff, 1) obj.drawpoly(x2,y1,0, x5,y2,0, x5,y3,0, x2,y4,0, 0,0, 0,0, 0,0, 0,0, 1) -- 補正ゲージ表示 x1 = left x2 = x1 + harding + 1 x3 = x2 x4 = left y1 = top + 129 y2 = y1 y3 = y1 + 16 y4 = y3 obj.load("figure", "四角形", 0xffffff, 256) obj.drawpoly(x1,y1,0, x2,y2,0, x3,y3,0, x4,y4,0, 0,0, 255,0, 255,255, 0,255, 1) -- 補正値表示 obj.setfont("Arial", 16, 1, 0x000000, 0xffffff) obj.load("text", math.floor(harding / 2.55 + 0.5).."% × "..math.floor(newvalue + 0.5).."% = "..math.floor(harding / 2.55 * newvalue / 100 + 0.5).."%") obj.draw(left + 128, top + 137) -- 補正目盛表示 for i = 0, 9 do x1 = left + i * 25.5 x2 = x1 + 1 x3 = x2 x4 = x1 y1 = top + 137 y2 = y1 y3 = y1 + 8 y4 = y3 brush = 0xff0000 if i == 5 then brush = 0x00d0ff end obj.load("figure", "四角形", brush, 8) obj.drawpoly(x1,y1,0, x2,y2,0, x3,y3,0, x4,y4,0, 0,0, 0,7, 7,7, 0,7, 1) end -- 補正後目盛表示 for i = 1, 10 do x1 = i * 25.5 / newvalue * 100 if x1 >= 255 then break else x1 = left + x1 end x2 = x1 + 1 x3 = x2 x4 = x1 y1 = graph_bottom - threshold - 4 y2 = y1 y3 = y1 + 10 if i == 10 then y3 = graph_bottom + 6 end y4 = y3 brush = 0xff0000 if i == 5 or i == 10 then brush = 0x00d0ff end obj.load("figure", "四角形", brush, 8) obj.drawpoly(x1,y1,0, x2,y2,0, x3,y3,0, x4,y4,0, 0,0, 0,7, 7,7, 0,7, 1) end -- 時刻表示 obj.setfont("Arial", 16 , 0, 0xffffff, 0xffffff) obj.load("text", string.format("%02d:%02d:%02d %d", obj.frame / obj.framerate / 60 % 60, obj.frame / obj.framerate % 60, obj.frame % obj.framerate, obj.frame + 1)) obj.draw(left + 128, top + 153) end