├── AvsPmod macros ├── (De)focus.py ├── Bookmarks to frame.py ├── Change RGB WP curr frame brace.py ├── Change RGB WP curr frame_paste.py ├── Insert WP brace from curr to end.py ├── Insert WP brace from last bk to end.py ├── Insert current frame +1.py ├── Insert current frame -1 .py ├── Insert last bookmark frame -1 plus newline last bk.py ├── Insert last bookmark frame -1 plus newline last bk_match start brace.py ├── Insert last bookmark frame -1.py ├── Insert last bookmark frame.py ├── Insert last bookmark frame_match start brace.py ├── Insert new braces WP - curr - focus - paste.py ├── Insert new braces WP - curr - focus.py ├── Jump to selected frame.py ├── Jump to selected frame_no refresh.py ├── Mouse select frames around top 2xh.py ├── Mouse select frames around top.py ├── Only Insert new braces WP - curr - focus - paste.py └── Readme.txt ├── C_Auto_Gamma_x64.dll ├── C_Auto_Gamma_x64 ├── Function definition.txt ├── auto_gamma.c ├── avisynth_c.h ├── avs │ ├── alignment.h │ ├── capi.h │ ├── config.h │ ├── cpuid.h │ ├── minmax.h │ ├── types.h │ └── win.h ├── functions_c.h └── lib │ ├── AviSynth_x64.exp │ ├── AviSynth_x64.lib │ ├── AviSynth_x86.exp │ └── AviSynth_x86.lib ├── C_Circle_Warp_x64.dll ├── C_Circle_Warp_x64 ├── Function definition ├── circle_warp.c └── functions_c.h ├── C_Linear_Gamma_x64.dll ├── C_Linear_Gamma_x64 ├── functions_c.h └── linear_gamma.c ├── C_Luma_Smooth_x64.dll ├── C_Luma_Smooth_x64 ├── Function_definition.txt └── luma_smooth.c ├── C_Manual_WP_x64.dll ├── C_RGB_Dither_x64.dll ├── C_RGB_Dither_x64 ├── Function_definition.txt ├── functions_c.h └── rgb_dither.c ├── C_Saturation_percentiles_x64.dll ├── C_Saturation_percentiles_x64 ├── Function definition.txt ├── functions_c.h └── saturation_percentiles.c ├── Colour space XYZ.xlsx ├── Helper files ├── Iframe list gen.html ├── WP brace change generator.html ├── WP frames list gen.html ├── WP_brace_RGB_gamma_conv.html ├── WP_edits fix.html └── backup_style.dat ├── Manual WP ├── Function definition.txt ├── functions_c.h ├── white_point.c └── xyY_funcs.h └── Uniform dither.hlsl /AvsPmod macros/(De)focus.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | wnd = avsp.GetWindow() 4 | script = wnd.currentScript 5 | 6 | curr=avsp.GetFrameNumber() 7 | bk=curr 8 | txt=avsp.GetText(index=None, clean=False) 9 | txl=txt.splitlines() 10 | txl.reverse() 11 | swt=0; 12 | for x in range(len(txl)): 13 | y=re.findall('.*\s+focusser\s*=\s*\d{1}',txl[x]) 14 | if len(y)>0: #if find match 15 | ys=y[0].split('=') 16 | pos = script.GetSelectionEnd() 17 | if str(ys[1]).strip()=='0': 18 | avsp.SetText(txt.replace(y[0], 'global focusser = 1')) 19 | swt=1 20 | else: 21 | avsp.SetText(txt.replace(y[0], 'global focusser = 0')) 22 | swt=0 23 | script.GotoPos(pos) 24 | break 25 | 26 | txt=avsp.GetText(index=None, clean=False) 27 | txl=txt.splitlines() 28 | txl.reverse() 29 | 30 | for x in range(len(txl)): 31 | y=re.findall('.*\s+focus_frame\s*=\s*\d{1,}',txl[x]) 32 | if len(y)>0: #if find match 33 | ff=int(y[0].split('=')[1].strip()) 34 | if swt==1: 35 | avsp.SetText(txt.replace(y[0], 'global focus_frame = '+str(curr))) 36 | break 37 | 38 | 39 | bookmarks = avsp.GetBookmarkList() 40 | 41 | if bookmarks: 42 | bookmarks = list(set(bookmarks)) 43 | bookmarks.sort(reverse=True) 44 | for k in range(len(bookmarks)): 45 | if bookmarks[k] <= curr: 46 | bk=bookmarks[k] #curr := last bookmark if there are any 47 | break 48 | 49 | txt=avsp.GetText(index=None, clean=False) 50 | txl=txt.splitlines() 51 | txl.reverse() 52 | 53 | for x in range(len(txl)): 54 | y=re.findall('.*\s+last_bk\s*=\s*\d{1,}',txl[x]) 55 | if len(y)>0: #if find match 56 | ff=int(y[0].split('=')[1].strip()) 57 | posi=len(txl)-x 58 | if swt==1: 59 | avsp.SetText(txt.replace(y[0], 'global last_bk = '+str(bk))) 60 | break 61 | 62 | if swt==0: 63 | txt=avsp.GetText(index=None, clean=False) 64 | txl=txt.splitlines() 65 | txl.reverse() 66 | 67 | for x in range(len(txl)): 68 | y=re.findall('.*\s+focus_frame\s*=\s*\d{1,}',txl[x]) 69 | if len(y)>0: #if find match 70 | ff=int(y[0].split('=')[1].strip()) 71 | posi=len(txl)-x 72 | avsp.ShowVideoFrame(framenum=ff , index=None, forceRefresh=True) 73 | script.GotoLine(posi) 74 | break 75 | else: 76 | avsp.ShowVideoFrame(framenum=ff , index=None, forceRefresh=True) 77 | script.GotoLine(posi) 78 | -------------------------------------------------------------------------------- /AvsPmod macros/Bookmarks to frame.py: -------------------------------------------------------------------------------- 1 | import codecs 2 | import os.path 3 | 4 | # run in thread 5 | try: 6 | bookmarks = avsp.GetBookmarkList(title=True) 7 | except TypeError: 8 | bookmarks = avsp.GetBookmarkList() 9 | bookmarks.sort() 10 | filename = avsp.GetSaveFilename( 11 | title=_('Save bookmarks list as...'), 12 | default=os.path.splitext( 13 | avsp.GetScriptFilename(propose='general', only='base'))[0], 14 | filefilter = '|'.join((_('Text files') + ' (*.txt)|*.txt', 15 | _('All files') + ' (*.*)|*.*'))) 16 | if not filename: 17 | return 18 | fps = avsp.GetVideoFramerate() 19 | text = [] 20 | chapter = 1 21 | for item in bookmarks: 22 | if type(item) is int: 23 | bookmark = item 24 | 25 | else: 26 | bookmark, title = item 27 | 28 | timecode = '%d\n' % (bookmark) 29 | 30 | text += [timecode] 31 | 32 | f = codecs.open(filename, 'w', 'utf-8') 33 | f.writelines(text) 34 | f.close() -------------------------------------------------------------------------------- /AvsPmod macros/Change RGB WP curr frame brace.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | import ctypes as ct 4 | 5 | class GetPoint(ct.Structure): 6 | _fields_ = [("x", ct.c_long), ("y", ct.c_long)] 7 | 8 | def get_mousepos(): 9 | pt = GetPoint() 10 | ct.windll.user32.GetCursorPos(ct.byref(pt)) 11 | return int(pt.x), int(pt.y) 12 | 13 | wnd = avsp.GetWindow() 14 | script = wnd.currentScript 15 | w, h = script.AVI.Width, script.AVI.Height 16 | dc = wx.ClientDC(wnd.videoWindow) 17 | dc.SetDeviceOrigin(wnd.xo, wnd.yo) 18 | try: # DoPrepareDC causes NameError in wx2.9.1 and fixed in wx2.9.2 19 | wnd.videoWindow.DoPrepareDC(dc) 20 | except: 21 | wnd.videoWindow.PrepareDC(dc) 22 | zoomfactor = wnd.zoomfactor 23 | if zoomfactor != 1: 24 | dc.SetUserScale(zoomfactor, zoomfactor) 25 | xpos,ypos = wnd.videoWindow.ScreenToClient(get_mousepos()) 26 | x = dc.DeviceToLogicalX(xpos) 27 | y = dc.DeviceToLogicalY(ypos) 28 | 29 | rgb = dc.GetPixel(x, y) 30 | R,G,B = rgb.Get() 31 | 32 | # Source - https://gist.github.com/line0/11328940 33 | 34 | curr=avsp.GetFrameNumber() 35 | 36 | sw=0 37 | cg=0 38 | txt=avsp.GetText(index=None, clean=False) 39 | txl=txt.splitlines() 40 | txl.reverse() 41 | 42 | for x in range(len(txl)): 43 | y=re.findall('.*\s+focusser\s*=\s*\d{1}',txl[x]) 44 | if len(y)>0: #if find match 45 | ys=y[0].split('=') 46 | if str(ys[1]).strip()!='0': 47 | cg=1 48 | break 49 | 50 | for x in range(len(txl)): 51 | y=re.findall('.*\s+focus_frame\s*=\s*\d{1,}',txl[x]) 52 | if len(y)>0: #if find match 53 | ff=int(y[0].split('=')[1].strip()) 54 | if cg==1: 55 | curr=ff 56 | break 57 | 58 | for x in range(len(txl)): 59 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 60 | if len(y)>0: #if find match 61 | ys=y[0].split(',') 62 | st=int(ys[3].strip()) 63 | ed=int(ys[4].strip()) 64 | if curr >= st and curr<=ed: 65 | sw=1 66 | elif curr >= st and ed==0: 67 | sw=1 68 | 69 | if sw==1: 70 | p1='{'+str(R)+', '+str(G)+', '+str(B)+', '+str(st)+','+str(ed)+','+ys[5]+','+ys[6] 71 | p2=txt.replace(y[0], p1) 72 | avsp.SetText(p2) 73 | script.GotoLine(len(txl)-x) 74 | avsp.WriteToScrap(str(st)+' - '+str(ed)+' -> '+str(R)+','+str(G)+','+str(B)+'\n', pos=-1) 75 | avsp.ShowVideoFrame(forceRefresh=True) 76 | break -------------------------------------------------------------------------------- /AvsPmod macros/Change RGB WP curr frame_paste.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | import ctypes as ct 4 | 5 | wnd = avsp.GetWindow() 6 | script = wnd.currentScript 7 | 8 | wx.TheClipboard.Open() 9 | pasteText = wx.TextDataObject('') 10 | if wx.TheClipboard.GetData(pasteText): 11 | pasteText = pasteText.GetText() 12 | # Source - https://gist.github.com/line0/11328940 13 | 14 | curr=avsp.GetFrameNumber() 15 | 16 | sw=0 17 | cg=0 18 | txt=avsp.GetText(index=None, clean=False) 19 | txl=txt.splitlines() 20 | txl.reverse() 21 | 22 | for x in range(len(txl)): 23 | y=re.findall('.*\s+focusser\s*=\s*\d{1}',txl[x]) 24 | if len(y)>0: #if find match 25 | ys=y[0].split('=') 26 | if str(ys[1]).strip()!='0': 27 | cg=1 28 | break 29 | 30 | for x in range(len(txl)): 31 | y=re.findall('.*\s+focus_frame\s*=\s*\d{1,}',txl[x]) 32 | if len(y)>0: #if find match 33 | ff=int(y[0].split('=')[1].strip()) 34 | if cg==1: 35 | curr=ff 36 | break 37 | 38 | for x in range(len(txl)): 39 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 40 | if len(y)>0: #if find match 41 | ys=y[0].split(',') 42 | st=int(ys[3].strip()) 43 | ed=int(ys[4].strip()) 44 | if curr >= st and curr<=ed: 45 | sw=1 46 | elif curr >= st and ed==0: 47 | sw=1 48 | 49 | if sw==1: 50 | p1='{'+pasteText+', '+str(st)+','+str(ed)+','+ys[5]+','+ys[6] 51 | p2=txt.replace(y[0], p1) 52 | avsp.SetText(p2) 53 | script.GotoLine(len(txl)-x) 54 | avsp.WriteToScrap(str(st)+' - '+str(ed)+' -> '+pasteText+'\n', pos=-1) 55 | avsp.ShowVideoFrame(forceRefresh=True) 56 | break -------------------------------------------------------------------------------- /AvsPmod macros/Insert WP brace from curr to end.py: -------------------------------------------------------------------------------- 1 | curr=avsp.GetFrameNumber() 2 | frms=avsp.GetVideoFramecount(index=None)-1 3 | avsp.InsertText('\n{-1,-1,-1 ,%i,%i,0.312727,0.329023}'%(curr,frms),pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert WP brace from last bk to end.py: -------------------------------------------------------------------------------- 1 | curr=avsp.GetFrameNumber() 2 | frms=avsp.GetVideoFramecount(index=None)-1 3 | bookmarks = avsp.GetBookmarkList() 4 | #wnd.zoomfactor = 0.9 5 | if bookmarks: 6 | bookmarks = list(set(bookmarks)) 7 | bookmarks.sort(reverse=True) 8 | for k in range(len(bookmarks)): 9 | if bookmarks[k] <= curr: 10 | curr=bookmarks[k] #curr := last bookmark if there are any 11 | break 12 | 13 | avsp.InsertText('\n{-1,-1,-1 ,%i,%i,0.312727,0.329023}'%(curr,frms),pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert current frame +1.py: -------------------------------------------------------------------------------- 1 | curr_1=avsp.GetFrameNumber()+1 2 | avsp.InsertText('%i' % curr_1,pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert current frame -1 .py: -------------------------------------------------------------------------------- 1 | curr_1=avsp.GetFrameNumber()-1 2 | curr_1 = 0 if curr_1<=0 else curr_1 3 | avsp.InsertText('%i' % curr_1,pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert last bookmark frame -1 plus newline last bk.py: -------------------------------------------------------------------------------- 1 | bookmarks = avsp.GetBookmarkList() 2 | curr=avsp.GetFrameNumber() 3 | if bookmarks: 4 | bookmarks = list(set(bookmarks)) 5 | bookmarks.sort(reverse=True) 6 | for k in range(len(bookmarks)): 7 | if bookmarks[k] <= curr: 8 | curr=bookmarks[k] 9 | break 10 | curr_bk = curr 11 | curr = 0 if curr==0 else curr-1 12 | avsp.InsertText('%i\n%i '%(curr,curr_bk),pos=None) 13 | else: 14 | curr = 0 if curr==0 else curr-1 15 | avsp.InsertText('%i\n%i '%(curr,curr_bk),pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert last bookmark frame -1 plus newline last bk_match start brace.py: -------------------------------------------------------------------------------- 1 | import re 2 | bookmarks = avsp.GetBookmarkList() 3 | curr=avsp.GetFrameNumber() 4 | found=0 5 | txt=avsp.GetText(index=None, clean=False) 6 | txl=txt.splitlines() 7 | txl.reverse() 8 | 9 | if bookmarks: 10 | bookmarks = list(set(bookmarks)) 11 | bookmarks.sort(reverse=True) 12 | for k in range(len(bookmarks)): 13 | if bookmarks[k] <= curr: 14 | curr=bookmarks[k] 15 | break 16 | curr_bk = curr 17 | curr = 0 if curr==0 else curr-1 18 | else: 19 | curr = 0 if curr==0 else curr-1 20 | 21 | for x in range(len(txl)): 22 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 23 | if len(y)>0: #if find match 24 | ys=y[0].split(',') 25 | if ys[3].strip()==str(curr_bk): 26 | found=1 27 | break 28 | 29 | if found==0: 30 | avsp.InsertText('%i\n%i '%(curr,curr_bk),pos=None) 31 | else: 32 | avsp.InsertText('%i\n%i [WP]'%(curr,curr_bk),pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert last bookmark frame -1.py: -------------------------------------------------------------------------------- 1 | bookmarks = avsp.GetBookmarkList() 2 | curr=avsp.GetFrameNumber() 3 | if bookmarks: 4 | bookmarks = list(set(bookmarks)) 5 | bookmarks.sort(reverse=True) 6 | for k in range(len(bookmarks)): 7 | if bookmarks[k] <= curr: 8 | curr=bookmarks[k] 9 | break 10 | curr = 0 if curr==0 else curr-1 11 | avsp.InsertText('%i'%curr,pos=None) 12 | else: 13 | curr = 0 if curr==0 else curr-1 14 | avsp.InsertText('%i'%curr,pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert last bookmark frame.py: -------------------------------------------------------------------------------- 1 | bookmarks = avsp.GetBookmarkList() 2 | curr=avsp.GetFrameNumber() 3 | if bookmarks: 4 | bookmarks = list(set(bookmarks)) 5 | bookmarks.sort(reverse=True) 6 | for k in range(len(bookmarks)): 7 | if bookmarks[k] <= curr: 8 | curr=bookmarks[k] 9 | break 10 | avsp.InsertText('%i' % curr,pos=None) 11 | else: 12 | avsp.InsertText('%i' % curr,pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert last bookmark frame_match start brace.py: -------------------------------------------------------------------------------- 1 | import re 2 | bookmarks = avsp.GetBookmarkList() 3 | curr=avsp.GetFrameNumber() 4 | found=0 5 | txt=avsp.GetText(index=None, clean=False) 6 | txl=txt.splitlines() 7 | txl.reverse() 8 | 9 | if bookmarks: 10 | bookmarks = list(set(bookmarks)) 11 | bookmarks.sort(reverse=True) 12 | for k in range(len(bookmarks)): 13 | if bookmarks[k] <= curr: 14 | curr=bookmarks[k] 15 | break 16 | 17 | for x in range(len(txl)): 18 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 19 | if len(y)>0: #if find match 20 | ys=y[0].split(',') 21 | if ys[3].strip()==str(curr): 22 | found=1 23 | break 24 | 25 | if found==0: 26 | avsp.InsertText('%i'%curr,pos=None) 27 | else: 28 | avsp.InsertText('%i [WP]'%curr,pos=None) -------------------------------------------------------------------------------- /AvsPmod macros/Insert new braces WP - curr - focus - paste.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | 4 | wnd = avsp.GetWindow() 5 | script = wnd.currentScript 6 | 7 | wx.TheClipboard.Open() 8 | pasteText = wx.TextDataObject('') 9 | if wx.TheClipboard.GetData(pasteText): 10 | pasteText = pasteText.GetText() 11 | # Source - https://gist.github.com/line0/11328940 12 | 13 | curr=avsp.GetFrameNumber() 14 | bookmarks = avsp.GetBookmarkList() 15 | #wnd.zoomfactor = 1 16 | if bookmarks: 17 | bookmarks = list(set(bookmarks)) 18 | bookmarks.sort(reverse=True) 19 | for k in range(len(bookmarks)): 20 | if bookmarks[k] <= curr: 21 | curr=bookmarks[k] #curr := last bookmark if there are any 22 | break 23 | 24 | frms=avsp.GetVideoFramecount(index=None)-1 25 | bookmarks = avsp.GetBookmarkList() 26 | cg=0 27 | txt=avsp.GetText(index=None, clean=False) 28 | txl=txt.splitlines() 29 | txl.reverse() 30 | 31 | for x in range(len(txl)): 32 | y=re.findall('.*\s+focusser\s*=\s*\d{1}',txl[x]) 33 | if len(y)>0: #if find match 34 | ys=y[0].split('=') 35 | if str(ys[1]).strip()!='0': 36 | cg=1 37 | break 38 | 39 | for x in range(len(txl)): 40 | y=re.findall('.*\s+last_bk\s*=\s*\d{1,}',txl[x]) 41 | if len(y)>0: #if find match 42 | ff=int(y[0].split('=')[1].strip()) 43 | if cg==1: 44 | curr=ff 45 | frms=0 46 | break 47 | 48 | for x in range(len(txl)): 49 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 50 | if len(y)>0: #if find match 51 | ys=y[0].split(',') 52 | x2=x+1 if x0: 56 | p1=str(ys[0])+','+str(ys[1])+','+str(ys[2])+','+str(ys[3])+','+str(curr-1)+','+str(ys[5])+','+str(ys[6]) 57 | p2='{'+pasteText+', '+str(curr)+','+str(frms)+',0.312727,0.329023}' 58 | if str(ys[3]).strip()==str(curr).strip(): 59 | p3=txt.replace(y[0], p2) 60 | else: 61 | p3=txt.replace(y[0], p1+'\n'+p2) 62 | 63 | avsp.SetText(p3) 64 | script.GotoLine(len(txl)-x) 65 | avsp.WriteToScrap('On brace from '+str(curr).strip()+' -> '+pasteText+'\n', pos=-1) 66 | avsp.ShowVideoFrame(forceRefresh=True) 67 | break 68 | -------------------------------------------------------------------------------- /AvsPmod macros/Insert new braces WP - curr - focus.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | import ctypes as ct 4 | 5 | class GetPoint(ct.Structure): 6 | _fields_ = [("x", ct.c_long), ("y", ct.c_long)] 7 | 8 | def get_mousepos(): 9 | pt = GetPoint() 10 | ct.windll.user32.GetCursorPos(ct.byref(pt)) 11 | return int(pt.x), int(pt.y) 12 | 13 | wnd = avsp.GetWindow() 14 | script = wnd.currentScript 15 | w, h = script.AVI.Width, script.AVI.Height 16 | dc = wx.ClientDC(wnd.videoWindow) 17 | dc.SetDeviceOrigin(wnd.xo, wnd.yo) 18 | try: # DoPrepareDC causes NameError in wx2.9.1 and fixed in wx2.9.2 19 | wnd.videoWindow.DoPrepareDC(dc) 20 | except: 21 | wnd.videoWindow.PrepareDC(dc) 22 | zoomfactor = wnd.zoomfactor 23 | if zoomfactor != 1: 24 | dc.SetUserScale(zoomfactor, zoomfactor) 25 | xpos,ypos = wnd.videoWindow.ScreenToClient(get_mousepos()) 26 | x = dc.DeviceToLogicalX(xpos) 27 | y = dc.DeviceToLogicalY(ypos) 28 | 29 | rgb = dc.GetPixel(x, y) 30 | R,G,B = rgb.Get() 31 | 32 | # Source - https://gist.github.com/line0/11328940 33 | 34 | curr=avsp.GetFrameNumber() 35 | bookmarks = avsp.GetBookmarkList() 36 | 37 | if bookmarks: 38 | bookmarks = list(set(bookmarks)) 39 | bookmarks.sort(reverse=True) 40 | for k in range(len(bookmarks)): 41 | if bookmarks[k] <= curr: 42 | curr=bookmarks[k] #curr := last bookmark if there are any 43 | break 44 | 45 | frms=avsp.GetVideoFramecount(index=None)-1 46 | bookmarks = avsp.GetBookmarkList() 47 | cg=0 48 | txt=avsp.GetText(index=None, clean=False) 49 | txl=txt.splitlines() 50 | txl.reverse() 51 | 52 | for x in range(len(txl)): 53 | y=re.findall('.*\s+focusser\s*=\s*\d{1}',txl[x]) 54 | if len(y)>0: #if find match 55 | ys=y[0].split('=') 56 | if str(ys[1]).strip()!='0': 57 | cg=1 58 | break 59 | 60 | for x in range(len(txl)): 61 | y=re.findall('.*\s+last_bk\s*=\s*\d{1,}',txl[x]) 62 | if len(y)>0: #if find match 63 | ff=int(y[0].split('=')[1].strip()) 64 | if cg==1: 65 | curr=ff 66 | frms=0 67 | break 68 | 69 | for x in range(len(txl)): 70 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 71 | if len(y)>0: #if find match 72 | ys=y[0].split(',') 73 | x2=x+1 if x0: 77 | p1=str(ys[0])+','+str(ys[1])+','+str(ys[2])+','+str(ys[3])+','+str(curr-1)+','+str(ys[5])+','+str(ys[6]) 78 | p2='{'+str(R)+', '+str(G)+', '+str(B)+', '+str(curr)+','+str(frms)+',0.312727,0.329023}' 79 | if str(ys[3]).strip()==str(curr).strip(): 80 | p3=txt.replace(y[0], p2) 81 | else: 82 | p3=txt.replace(y[0], p1+'\n'+p2) 83 | 84 | avsp.SetText(p3) 85 | script.GotoLine(len(txl)-x) 86 | avsp.WriteToScrap('On brace from '+str(curr).strip()+' -> '+str(R)+','+str(G)+','+str(B)+'\n', pos=-1) 87 | avsp.ShowVideoFrame(forceRefresh=True) 88 | break 89 | -------------------------------------------------------------------------------- /AvsPmod macros/Jump to selected frame.py: -------------------------------------------------------------------------------- 1 | fr=avsp.GetSelectedText(index=None) 2 | if not fr: 3 | avsp.ShowVideoFrame(framenum=None, index=None, forceRefresh=True) 4 | else: 5 | avsp.ShowVideoFrame(framenum= int(fr), index=None, forceRefresh=True) -------------------------------------------------------------------------------- /AvsPmod macros/Jump to selected frame_no refresh.py: -------------------------------------------------------------------------------- 1 | fr=avsp.GetSelectedText(index=None) 2 | if not not fr: 3 | avsp.ShowVideoFrame(framenum= int(fr), index=None, forceRefresh=False) -------------------------------------------------------------------------------- /AvsPmod macros/Mouse select frames around top 2xh.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | import ctypes as ct 4 | 5 | Xstart = 0 6 | Xend = 1.0/3.0 7 | #Frames around top covers the first third of the output width 8 | 9 | Ystart = 0 10 | Yend = 1 11 | #Frames around top covers the whole output height 12 | 13 | class GetPoint(ct.Structure): 14 | _fields_ = [("x", ct.c_long), ("y", ct.c_long)] 15 | 16 | def get_mousepos(): 17 | pt = GetPoint() 18 | ct.windll.user32.GetCursorPos(ct.byref(pt)) 19 | return int(pt.x), int(pt.y) 20 | 21 | wnd = avsp.GetWindow() 22 | script = wnd.currentScript 23 | w, h = script.AVI.Width, script.AVI.Height 24 | dc = wx.ClientDC(wnd.videoWindow) 25 | dc.SetDeviceOrigin(wnd.xo, wnd.yo) 26 | try: # DoPrepareDC causes NameError in wx2.9.1 and fixed in wx2.9.2 27 | wnd.videoWindow.DoPrepareDC(dc) 28 | except: 29 | wnd.videoWindow.PrepareDC(dc) 30 | zoomfactor = wnd.zoomfactor 31 | if zoomfactor != 1: 32 | dc.SetUserScale(zoomfactor, zoomfactor) 33 | xpos,ypos = wnd.videoWindow.ScreenToClient(get_mousepos()) 34 | x = dc.DeviceToLogicalX(xpos) 35 | y = dc.DeviceToLogicalY(ypos) 36 | 37 | rgb = dc.GetPixel(x, y) 38 | R,G,B = rgb.Get() 39 | 40 | # Source - https://gist.github.com/line0/11328940 41 | 42 | curr=avsp.GetFrameNumber() 43 | frms=avsp.GetVideoFramecount(index=None)-1 44 | 45 | f_x=float(x) 46 | f_y=float(y) 47 | f_w=float(w) 48 | f_h=float(h) 49 | 50 | fat_w=Xend-Xstart 51 | fat_h=Yend-Ystart 52 | 53 | normX=f_x/f_w #0-1 54 | normY=f_y/f_h #0-1 55 | 56 | if normX >= Xstart and normX <= Xend and normY >= Ystart and normY <= Yend: 57 | normX_fat=(normX-Xstart)/fat_w 58 | normY_fat=(normY-Ystart)/fat_h 59 | 60 | x_ix=0.0 61 | 62 | if normX_fat <= 0.2: 63 | x_ix = 0.0 64 | elif normX_fat <= 0.4: 65 | x_ix = 1.0 66 | elif normX_fat <= 0.6: 67 | x_ix = 2.0 68 | elif normX_fat <= 0.8: 69 | x_ix = 3.0 70 | else: 71 | x_ix = 4.0 72 | 73 | y_ix=0.0 74 | 75 | if normY_fat <= 1.0/11.0: 76 | y_ix = 0.0 77 | elif normY_fat <= 2.0/11.0: 78 | y_ix = 1.0 79 | elif normY_fat <= 3.0/11.0: 80 | y_ix = 2.0 81 | elif normY_fat <= 4.0/11.0: 82 | y_ix = 3.0 83 | elif normY_fat <= 5.0/11.0: 84 | y_ix = 4.0 85 | elif normY_fat <= 6.0/11.0: 86 | y_ix = 5.0 87 | elif normY_fat <= 7.0/11.0: 88 | y_ix = 6.0 89 | elif normY_fat <= 8.0/11.0: 90 | y_ix = 7.0 91 | elif normY_fat <= 9.0/11.0: 92 | y_ix = 8.0 93 | elif normY_fat <= 10.0/11.0: 94 | y_ix = 9.0 95 | else: 96 | y_ix = 10.0 97 | 98 | fr=round(y_ix*5+x_ix-9+float(curr)) 99 | fr=0 if fr<0 else fr 100 | fr=frms if fr>frms else fr 101 | fr=int(fr) 102 | avsp.ShowVideoFrame(framenum= fr, index=None, forceRefresh=False) 103 | avsp.WriteToScrap('Jumped to: '+str(fr)+'\n', pos=-1) -------------------------------------------------------------------------------- /AvsPmod macros/Mouse select frames around top.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | import ctypes as ct 4 | 5 | Xstart = 0 6 | Xend = 1.0/2.0 7 | #Frames around top covers the first third of the output width 8 | 9 | Ystart = 0 10 | Yend = 0.5 11 | #Frames around top covers the whole output height 12 | 13 | class GetPoint(ct.Structure): 14 | _fields_ = [("x", ct.c_long), ("y", ct.c_long)] 15 | 16 | def get_mousepos(): 17 | pt = GetPoint() 18 | ct.windll.user32.GetCursorPos(ct.byref(pt)) 19 | return int(pt.x), int(pt.y) 20 | 21 | wnd = avsp.GetWindow() 22 | script = wnd.currentScript 23 | w, h = script.AVI.Width, script.AVI.Height 24 | dc = wx.ClientDC(wnd.videoWindow) 25 | dc.SetDeviceOrigin(wnd.xo, wnd.yo) 26 | try: # DoPrepareDC causes NameError in wx2.9.1 and fixed in wx2.9.2 27 | wnd.videoWindow.DoPrepareDC(dc) 28 | except: 29 | wnd.videoWindow.PrepareDC(dc) 30 | zoomfactor = wnd.zoomfactor 31 | if zoomfactor != 1: 32 | dc.SetUserScale(zoomfactor, zoomfactor) 33 | xpos,ypos = wnd.videoWindow.ScreenToClient(get_mousepos()) 34 | x = dc.DeviceToLogicalX(xpos) 35 | y = dc.DeviceToLogicalY(ypos) 36 | 37 | rgb = dc.GetPixel(x, y) 38 | R,G,B = rgb.Get() 39 | 40 | # Source - https://gist.github.com/line0/11328940 41 | 42 | curr=avsp.GetFrameNumber() 43 | frms=avsp.GetVideoFramecount(index=None)-1 44 | 45 | f_x=float(x) 46 | f_y=float(y) 47 | f_w=float(w) 48 | f_h=float(h) 49 | 50 | fat_w=Xend-Xstart 51 | fat_h=Yend-Ystart 52 | 53 | normX=f_x/f_w #0-1 54 | normY=f_y/f_h #0-1 55 | 56 | if normX >= Xstart and normX <= Xend and normY >= Ystart and normY <= Yend: 57 | normX_fat=(normX-Xstart)/fat_w 58 | normY_fat=(normY-Ystart)/fat_h 59 | 60 | x_ix=0.0 61 | 62 | if normX_fat <= 0.2: 63 | x_ix = 0.0 64 | elif normX_fat <= 0.4: 65 | x_ix = 1.0 66 | elif normX_fat <= 0.6: 67 | x_ix = 2.0 68 | elif normX_fat <= 0.8: 69 | x_ix = 3.0 70 | else: 71 | x_ix = 4.0 72 | 73 | y_ix=0.0 74 | 75 | if normY_fat <= 0.2: 76 | y_ix = 0.0 77 | elif normY_fat <= 0.4: 78 | y_ix = 1.0 79 | elif normY_fat <= 0.6: 80 | y_ix = 2.0 81 | elif normY_fat <= 0.8: 82 | y_ix = 3.0 83 | else: 84 | y_ix = 4.0 85 | 86 | fr=round(y_ix*5+x_ix-4+float(curr)) 87 | fr=0 if fr<0 else fr 88 | fr=frms if fr>frms else fr 89 | fr=int(fr) 90 | avsp.ShowVideoFrame(framenum= fr, index=None, forceRefresh=False) 91 | avsp.WriteToScrap('Jumped to: '+str(fr)+'\n', pos=-1) -------------------------------------------------------------------------------- /AvsPmod macros/Only Insert new braces WP - curr - focus - paste.py: -------------------------------------------------------------------------------- 1 | import re 2 | import wx 3 | 4 | wnd = avsp.GetWindow() 5 | script = wnd.currentScript 6 | 7 | wx.TheClipboard.Open() 8 | pasteText = wx.TextDataObject('') 9 | if wx.TheClipboard.GetData(pasteText): 10 | pasteText = pasteText.GetText() 11 | # Source - https://gist.github.com/line0/11328940 12 | 13 | curr=avsp.GetFrameNumber() 14 | bookmarks = avsp.GetBookmarkList() 15 | #wnd.zoomfactor = 1 16 | if bookmarks: 17 | bookmarks = list(set(bookmarks)) 18 | bookmarks.sort(reverse=True) 19 | for k in range(len(bookmarks)): 20 | if bookmarks[k] <= curr: 21 | curr=bookmarks[k] #curr := last bookmark if there are any 22 | break 23 | 24 | frms=avsp.GetVideoFramecount(index=None)-1 25 | bookmarks = avsp.GetBookmarkList() 26 | cg=0 27 | txt=avsp.GetText(index=None, clean=False) 28 | txl=txt.splitlines() 29 | txl.reverse() 30 | 31 | for x in range(len(txl)): 32 | y=re.findall('.*\s+focusser\s*=\s*\d{1}',txl[x]) 33 | if len(y)>0: #if find match 34 | ys=y[0].split('=') 35 | if str(ys[1]).strip()!='0': 36 | cg=1 37 | break 38 | 39 | for x in range(len(txl)): 40 | y=re.findall('.*\s+last_bk\s*=\s*\d{1,}',txl[x]) 41 | if len(y)>0: #if find match 42 | ff=int(y[0].split('=')[1].strip()) 43 | if cg==1: 44 | curr=ff 45 | frms=0 46 | break 47 | 48 | for x in range(len(txl)): 49 | y=re.findall('{\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\-{0,1}\d{1,5}\s*,\s*\d+\s*,\s*\d+\s*,\s*\d+\.*\d*\s*,\s*\d+\.*\d*\s*}',txl[x]) 50 | if len(y)>0: #if find match 51 | ys=y[0].split(',') 52 | x2=x+1 if x0: 56 | p2='{'+pasteText+', '+str(curr)+','+str(frms)+',0.312727,0.329023}' 57 | if str(ys[3]).strip()==str(curr).strip(): 58 | p3=txt.replace(y[0], p2) 59 | else: 60 | p3=txt.replace(y[0], y[0]+'\n'+p2) 61 | 62 | avsp.SetText(p3) 63 | script.GotoLine(len(txl)-x) 64 | avsp.WriteToScrap('On brace from '+str(curr).strip()+' -> '+pasteText+'\n', pos=-1) 65 | avsp.ShowVideoFrame(forceRefresh=True) 66 | break 67 | -------------------------------------------------------------------------------- /AvsPmod macros/Readme.txt: -------------------------------------------------------------------------------- 1 | Bookmarks to frame.py - Save a .txt list of the frame numbers of the bookmarks. 2 | 3 | Insert last bookmark frame.py - Inserts the last bookmark's frame number, or if there are no bookmarks: the current frame's number. 4 | 5 | Jump to selected frame(_no refresh).py - Select text containing a number and it will jump to that number frame with or without refreshing, if nothing is selected it will just refresh or do nothing. Jump to selected frame.py can replace 'Refresh preview' in AvsPmod. 6 | 7 | Insert new braces WP - curr - focus.py - Adds brace and changes previous brace depending on the position of the last bookmark, and sets the latest brace to the RGB valuse that the cursor was over when the macro was triggered. Also checks the script for 'focusser' and 'last_bk' (for use with De(focus).py and focusOnFrame {function}). N.B. this macro needs at least 2 braces already there to work. 8 | 9 | Only Insert new braces WP - curr - focus - paste.py - Same as above, except does not change the previous brace. 10 | 11 | Mouse select frames around top.py - Set X/Ystart and X/Yend to specify what part of the of the video preview is covered by the framesAroundTop function, then you can place the cursor over the frame you want to jump to and trgger the macro to jumps to that frame. 12 | 13 | Change RGB WP curr frame brace.py - Changes RGB value for the brace that contains the current frame (or focus_frame if focusser = 1) to the RGB value that the cursor is over. 14 | 15 | Change RGB WP curr frame brace_paste.py - Changes RGB value for the brace that contains the current frame (or focus_frame if focusser = 1) to what is in the clipboard (should be an RGB triplet). 16 | 17 | Insert last bookmark frame_match start brace.py & Insert last bookmark frame -1 plus newline last bk_match start brace.py - Insert the last bookmarked frame plus a space, or, last bookmarked frame - 1 + new line + last bookmarked frame, and adds " [WP]" if the last bookmarked frame is a start frame for a brace of Manual_WP or just a space if not. 18 | 19 | Mouse select frames around top 2xh.py - Same as "Mouse select frames around top.py", but for use with "twoXh_framesAroundTop". 20 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Auto_Gamma_x64.dll -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/Function definition.txt: -------------------------------------------------------------------------------- 1 | ( 2 | clip clip, 3 | float "a"=0.250 (0.00 to 6.00 by 0.001), 4 | float "l"=0.000 (0.00 to 1.00 by 0.001), 5 | float "h"=1.000 (0.00 to 1.00 by 0.001), 6 | int "crush"=0 (0 to 2 by 1), 7 | bool "limitedRange"=False, 8 | int "mode"=0 (0 to 12 by 1), 9 | int "linear"=0 (0 to 12 by 1), 10 | bool "sixtyFour"=false 11 | ) 12 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/auto_gamma.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "..\avisynth_c.h" 7 | #include "functions_c.h" 8 | 9 | typedef struct Auto_Gamma { 10 | double* use_R; 11 | double* use_G; 12 | double* use_B; 13 | double a; 14 | double l; 15 | double h; 16 | int crush; 17 | int limitedRange; 18 | int mode; 19 | int linear; 20 | int sixtyFour; 21 | int pxels; 22 | } Auto_Gamma; 23 | 24 | /* 25 | //DEBUG FILE STUFF 26 | 27 | char* d_file_path="C:\\Program Files (x86)\\~AvsPmod\\plugins\\C_Auto_Gamma_x64\\debug.txt"; 28 | 29 | void makeFile(char* f_name){ 30 | 31 | FILE *fptr; 32 | 33 | fptr = fopen(f_name,"w"); 34 | 35 | if(fptr == NULL){ 36 | exit(1); 37 | } 38 | 39 | fclose(fptr); 40 | } 41 | 42 | void appendFormattedToFile(char* f_name, const char * format, ...) 43 | { 44 | FILE * fptr; 45 | 46 | fptr = fopen (f_name,"a"); 47 | 48 | va_list args; 49 | va_start (args, format); 50 | vfprintf (fptr, format, args); 51 | va_end (args); 52 | 53 | fclose (fptr); 54 | 55 | return 0; 56 | }*/ 57 | 58 | AVS_VideoFrame * AVSC_CC Auto_Gamma_get_frame (AVS_FilterInfo * p, int n) 59 | { 60 | AVS_VideoFrame * src; 61 | Auto_Gamma* params = (Auto_Gamma*) p->user_data; 62 | src = avs_get_frame(p->child, n); 63 | 64 | int row_size, height, src_pitch,x, y,lmr,crs,lnr,mde,sxf; 65 | BYTE* srcp; 66 | const BYTE* rrcp; 67 | double a,lw,hi,runTot_r,runTot_g,runTot_b,bOG,gOG,rOG,gamma_high,gamma_low,R,G,B,counter; 68 | 69 | a=params->a; 70 | lw=params->l; 71 | hi=params->h; 72 | crs=params->crush; 73 | lmr=params->limitedRange; 74 | mde=params->mode; 75 | lnr=params->linear; 76 | sxf=params->sixtyFour; 77 | 78 | avs_make_writable(p->env, &src); 79 | 80 | srcp = avs_get_write_ptr(src); 81 | rrcp = avs_get_read_ptr(src); 82 | src_pitch = avs_get_pitch(src); 83 | row_size = avs_get_row_size(src); 84 | height = avs_get_height(src); 85 | 86 | runTot_r=0; 87 | runTot_g=0; 88 | runTot_b=0; 89 | counter=0; 90 | int p_ix=0; 91 | 92 | for (y=0; y 0.0404482362771082 )?fastPrecisePow(fabs((rOG+0.055)*rcpOFiveFive),2.4):rOG*rcpTwelveNineTwo; 106 | gOG=(gOG > 0.0404482362771082 )?fastPrecisePow(fabs((gOG+0.055)*rcpOFiveFive),2.4):gOG*rcpTwelveNineTwo; 107 | bOG=(bOG > 0.0404482362771082 )?fastPrecisePow(fabs((bOG+0.055)*rcpOFiveFive),2.4):bOG*rcpTwelveNineTwo; 108 | }else if(lnr==8){ 109 | rOG=fastPrecisePow(rOG,invTwoSix); 110 | gOG=fastPrecisePow(gOG,invTwoSix); 111 | bOG=fastPrecisePow(bOG,invTwoSix); 112 | }else if (lnr==5){ 113 | rOG=fastPrecisePow(rOG,2.2); 114 | gOG=fastPrecisePow(gOG,2.2); 115 | bOG=fastPrecisePow(bOG,2.2); 116 | }else if (lnr==12){ 117 | rOG=fastPrecisePow(rOG,rcpTwoFour); 118 | gOG=fastPrecisePow(gOG,rcpTwoFour); 119 | bOG=fastPrecisePow(bOG,rcpTwoFour); 120 | }else if (lnr==11){ 121 | rOG=fastPrecisePow(rOG,2.4); 122 | gOG=fastPrecisePow(gOG,2.4); 123 | bOG=fastPrecisePow(bOG,2.4); 124 | }else if(lnr==3){ 125 | rOG=(rOG < recBetaLin )?rcpFourFive*rOG:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-rOG)),rcpTxFourFive); 126 | gOG=(gOG < recBetaLin )?rcpFourFive*gOG:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-gOG)),rcpTxFourFive); 127 | bOG=(bOG < recBetaLin )?rcpFourFive*bOG:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-bOG)),rcpTxFourFive); 128 | }else if(lnr==2){ 129 | rOG=(rOG> 0.00313066844250063)?1.055 * fastPrecisePow(rOG,rcpTwoFour) - 0.055:12.92 *rOG; 130 | gOG=(gOG> 0.00313066844250063)?1.055 * fastPrecisePow(gOG,rcpTwoFour) - 0.055:12.92 *gOG; 131 | bOG=(bOG> 0.00313066844250063)?1.055 * fastPrecisePow(bOG,rcpTwoFour) - 0.055:12.92 *bOG; 132 | }else if(lnr==7){ 133 | rOG=fastPrecisePow(rOG,2.6); 134 | gOG=fastPrecisePow(gOG,2.6); 135 | bOG=fastPrecisePow(bOG,2.6); 136 | }else if(lnr==6){ 137 | rOG=fastPrecisePow(rOG,invTwoTwo); 138 | gOG=fastPrecisePow(gOG,invTwoTwo); 139 | B=fastPrecisePow(bOG,invTwoTwo); 140 | }else if(lnr==4){ 141 | rOG=(rOG< recBeta)?4.5*rOG:recAlpha*fastPrecisePow(rOG,0.45)-(recAlpha-1); 142 | gOG=(gOG< recBeta)?4.5*gOG:recAlpha*fastPrecisePow(gOG,0.45)-(recAlpha-1); 143 | bOG=(bOG< recBeta)?4.5*bOG:recAlpha*fastPrecisePow(bOG,0.45)-(recAlpha-1); 144 | }else if (lnr==9){ 145 | rOG=(rOG>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(rOG-HLG_c)*rcp_HLG_a)+HLG_b):rOG*rOG*third; 146 | gOG=(gOG>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(gOG-HLG_c)*rcp_HLG_a)+HLG_b):gOG*gOG*third; 147 | bOG=(bOG>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(bOG-HLG_c)*rcp_HLG_a)+HLG_b):bOG*bOG*third; 148 | }else if (lnr==10){ 149 | rOG=(rOG > rcpTwelve)?HLG_a*log(12.0*rOG-HLG_b)+HLG_c:root_three*fastPrecisePow(rOG,0.5); 150 | gOG=(gOG > rcpTwelve)?HLG_a*log(12.0*gOG-HLG_b)+HLG_c:root_three*fastPrecisePow(gOG,0.5); 151 | bOG=(bOG > rcpTwelve)?HLG_a*log(12.0*bOG-HLG_b)+HLG_c:root_three*fastPrecisePow(bOG,0.5); 152 | } 153 | 154 | rOG=lerp(lw,hi,rOG); 155 | gOG=lerp(lw,hi,gOG); 156 | bOG=lerp(lw,hi,bOG); 157 | 158 | if(mde==1){ 159 | runTot_r+=rOG*0.2124132; 160 | runTot_g+=gOG*0.7010437; 161 | runTot_b+=bOG*0.0865432; 162 | }else if(mde==2){ 163 | runTot_r+=rOG*0.2220379; 164 | runTot_g+=gOG*0.7066384; 165 | runTot_b+=bOG*0.0713236; 166 | }else if(mde==5){ //DCI-P3 167 | runTot_r+=rOG*0.209491677912731; 168 | runTot_g+=gOG*0.721595254161044; 169 | runTot_b+=bOG*0.068913067926226; 170 | }else if(mde==6){ 171 | runTot_r+=rOG*0.2290036; 172 | runTot_g+=gOG*0.691726725; 173 | runTot_b+=bOG*0.079269675; 174 | }else if ((mde==4)||(mde==11)){ 175 | runTot_r+=rOG*0.26272171736164; 176 | runTot_g+=gOG*0.677989275502262; 177 | runTot_b+=bOG*0.059289007136098; 178 | }else if (mde==7){ //Original NTSC 179 | runTot_r+=rOG*0.2896886; 180 | runTot_g+=gOG*0.6056356; 181 | runTot_b+=bOG*0.1046758; 182 | }else if (mde==8){ //Rec 601 D93 183 | runTot_r+=rOG*0.1767506; 184 | runTot_g+=gOG*0.7072321; 185 | runTot_b+=bOG*0.1160173; 186 | }else if (mde==9){ //Rec 709 D93 187 | runTot_r+=rOG*0.1799632; 188 | runTot_g+=gOG*0.7231169; 189 | runTot_b+=bOG*0.0969199; 190 | }else if (mde==10){ //DCI-P3 D60/ACES 191 | runTot_r+=rOG*0.23762331020788; 192 | runTot_g+=gOG*0.689170669198985; 193 | runTot_b+=bOG*0.073206020593136; 194 | }else if(mde==12){ //Original NTSC D65 195 | runTot_r+=rOG*0.2896886; 196 | runTot_g+=gOG*0.6056356; 197 | runTot_b+=bOG*0.1046758; 198 | }else{ 199 | runTot_r+=rOG*0.2126729; 200 | runTot_g+=gOG*0.7151522; 201 | runTot_b+=bOG*0.072175; 202 | } 203 | 204 | 205 | params->use_R[p_ix]=rOG; 206 | params->use_G[p_ix]=gOG; 207 | params->use_B[p_ix]=bOG; 208 | 209 | counter+=1; 210 | 211 | x=(sxf==1)?x+7:x+3; 212 | p_ix++; 213 | } 214 | rrcp+=src_pitch; 215 | } 216 | p_ix=0; 217 | 218 | 219 | double mxMean[3]={runTot_r/counter,runTot_g/counter,runTot_b/counter}; 220 | 221 | double avg=(mxMean[0]+mxMean[1]+mxMean[2])*third; 222 | gamma_high=a; 223 | 224 | if(avg==1 || a==0){ 225 | gamma_low=1; 226 | }else{ 227 | double lt=(avg-(avg*fastPrecisePow(avg,a)))/(1-avg); 228 | 229 | gamma_low=(lt<=0)?1:log(lt)/log(avg); 230 | } 231 | 232 | //appendFormattedToFile(d_file_path, "%f & %f\n",gamma_low, gamma_high); 233 | 234 | ///////////////ACTUALLY DRAW PIXELS/////////////////////////////////////// 235 | for (y=0; yuse_R[p_ix]; 239 | double og_G=params->use_G[p_ix]; 240 | double og_B=params->use_B[p_ix]; 241 | 242 | double og_RGB[3]={og_R,og_G,og_B}; 243 | 244 | double og_Y=LinRGB2Y(og_RGB, mde); 245 | 246 | double nw_R=(gamma_high==1 && gamma_low==1)?og_R:lerp(fastPrecisePow(og_R,gamma_low),fastPrecisePow(og_R,gamma_high),og_R); 247 | double nw_G=(gamma_high==1 && gamma_low==1)?og_G:lerp(fastPrecisePow(og_G,gamma_low),fastPrecisePow(og_G,gamma_high),og_G); 248 | double nw_B=(gamma_high==1 && gamma_low==1)?og_B:lerp(fastPrecisePow(og_B,gamma_low),fastPrecisePow(og_B,gamma_high),og_B); 249 | 250 | double nw_RGB[3]={nw_R,nw_G,nw_B}; 251 | 252 | double nw_Y=LinRGB2Y(nw_RGB, mde); 253 | 254 | R=nw_RGB[0]; 255 | G=nw_RGB[1]; 256 | B=nw_RGB[2]; 257 | 258 | if (crs==0 && nw_Yuser_data; 298 | free(params); 299 | } 300 | 301 | AVS_Value AVSC_CC create_Auto_Gamma (AVS_ScriptEnvironment * env,AVS_Value args, void * dg) 302 | { 303 | AVS_Value v; 304 | AVS_FilterInfo * fi; 305 | AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); 306 | Auto_Gamma *params = (Auto_Gamma*)malloc(sizeof(Auto_Gamma)); 307 | 308 | if (!params) 309 | return avs_void; 310 | params->a = avs_defined(avs_array_elt(args, 1))?avs_as_float(avs_array_elt(args, 1)):0.25; 311 | params->l = avs_defined(avs_array_elt(args, 2))?avs_as_float(avs_array_elt(args, 2)):0; 312 | params->h = avs_defined(avs_array_elt(args, 3))?avs_as_float(avs_array_elt(args, 3)):1; 313 | params->crush = avs_defined(avs_array_elt(args, 4))?avs_as_int(avs_array_elt(args, 4)):0; 314 | params->limitedRange= avs_defined(avs_array_elt(args, 5))?avs_as_bool(avs_array_elt(args, 5)):false; 315 | params->mode = avs_defined(avs_array_elt(args, 6))?avs_as_int(avs_array_elt(args, 6)):0; 316 | params->linear= avs_defined(avs_array_elt(args, 7))?avs_as_int(avs_array_elt(args, 7)):0; 317 | 318 | if ((params->l>1 || params->l<0)||(params->h>1 || params->h<0)){ 319 | return avs_new_value_error ("h and l must be between 0 and 1!"); 320 | }if ((params->mode<0)||(params->mode>12)){ 321 | return avs_new_value_error ("Allowed modes are between 0 and 12!"); 322 | } else if ((params->linear<0)||(params->linear>12)){ 323 | return avs_new_value_error ("Allowed linear values are between 0 and 12!"); 324 | }else{ 325 | if (!((avs_is_rgb32(&fi->vi))||(avs_is_rgb64(&fi->vi)))) { 326 | return avs_new_value_error ("Input video must be in RGB32 OR RGB64 format!"); 327 | } else { 328 | 329 | if(avs_defined(avs_array_elt(args, 8))){ 330 | params->sixtyFour =avs_as_bool(avs_array_elt(args, 8)); 331 | }else{ 332 | params->sixtyFour = (avs_is_rgb64(&fi->vi))?true:false; 333 | } 334 | params->pxels=fi->vi.height*fi->vi.width; 335 | 336 | params->use_R = (double*)malloc( params->pxels* sizeof(double)); 337 | params->use_G= (double*)malloc( params->pxels* sizeof(double)); 338 | params->use_B= (double*)malloc( params->pxels* sizeof(double)); 339 | 340 | //DEBUG FILE 341 | //makeFile(d_file_path); 342 | 343 | fi->user_data = (void*) params; 344 | fi->get_frame = Auto_Gamma_get_frame; 345 | v = avs_new_value_clip(new_clip); 346 | fi->free_filter = free_Auto_Gamma; 347 | } 348 | } 349 | avs_release_clip(new_clip); 350 | return v; 351 | } 352 | 353 | 354 | const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env) 355 | { 356 | avs_add_function(env, "Auto_Gamma", "c[a]f[l]f[h]f[crush]i[limitedRange]b[mode]i[linear]i[sixtyFour]b", create_Auto_Gamma, 0); 357 | return "Auto_Gamma C plugin"; 358 | } 359 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/alignment.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_ALIGNMENT_H 34 | #define AVS_ALIGNMENT_H 35 | 36 | // Functions and macros to help work with alignment requirements. 37 | 38 | // Tells if a number is a power of two. 39 | #define IS_POWER2(n) ((n) && !((n) & ((n) - 1))) 40 | 41 | // Tells if the pointer "ptr" is aligned to "align" bytes. 42 | #define IS_PTR_ALIGNED(ptr, align) (((uintptr_t)ptr & ((uintptr_t)(align-1))) == 0) 43 | 44 | // Rounds up the number "n" to the next greater multiple of "align" 45 | #define ALIGN_NUMBER(n, align) (((n) + (align)-1) & (~((align)-1))) 46 | 47 | // Rounds up the pointer address "ptr" to the next greater multiple of "align" 48 | #define ALIGN_POINTER(ptr, align) (((uintptr_t)(ptr) + (align)-1) & (~(uintptr_t)((align)-1))) 49 | 50 | #ifdef __cplusplus 51 | 52 | #include 53 | #include 54 | #include 55 | #include "config.h" 56 | 57 | #if defined(MSVC) && _MSC_VER<1400 58 | // needed for VS2013, otherwise C++11 'alignas' works 59 | #define avs_alignas(x) __declspec(align(x)) 60 | #else 61 | // assumes C++11 support 62 | #define avs_alignas(x) alignas(x) 63 | #endif 64 | 65 | template 66 | static bool IsPtrAligned(T* ptr, size_t align) 67 | { 68 | assert(IS_POWER2(align)); 69 | return (bool)IS_PTR_ALIGNED(ptr, align); 70 | } 71 | 72 | template 73 | static T AlignNumber(T n, T align) 74 | { 75 | assert(IS_POWER2(align)); 76 | return ALIGN_NUMBER(n, align); 77 | } 78 | 79 | template 80 | static T* AlignPointer(T* ptr, size_t align) 81 | { 82 | assert(IS_POWER2(align)); 83 | return (T*)ALIGN_POINTER(ptr, align); 84 | } 85 | 86 | extern "C" 87 | { 88 | #else 89 | #include 90 | #endif // __cplusplus 91 | 92 | // Returns a new buffer that is at least the size "nbytes". 93 | // The buffer will be aligned to "align" bytes. 94 | // Returns NULL on error. On successful allocation, 95 | // the returned buffer must be freed using "avs_free". 96 | inline void* avs_malloc(size_t nbytes, size_t align) 97 | { 98 | if (!IS_POWER2(align)) 99 | return NULL; 100 | 101 | size_t offset = sizeof(void*) + align - 1; 102 | 103 | void *orig = malloc(nbytes + offset); 104 | if (orig == NULL) 105 | return NULL; 106 | 107 | void **aligned = (void**)(((uintptr_t)orig + (uintptr_t)offset) & (~(uintptr_t)(align-1))); 108 | aligned[-1] = orig; 109 | return aligned; 110 | } 111 | 112 | // Buffers allocated using "avs_malloc" must be freed 113 | // using "avs_free" instead of "free". 114 | inline void avs_free(void *ptr) 115 | { 116 | // Mirroring free()'s semantic requires us to accept NULLs 117 | if (ptr == NULL) 118 | return; 119 | 120 | free(((void**)ptr)[-1]); 121 | } 122 | 123 | #ifdef __cplusplus 124 | } // extern "C" 125 | 126 | // The point of these undef's is to force using the template functions 127 | // if we are in C++ mode. For C, the user can rely only on the macros. 128 | #undef IS_PTR_ALIGNED 129 | #undef ALIGN_NUMBER 130 | #undef ALIGN_POINTER 131 | 132 | #endif // __cplusplus 133 | 134 | #endif //AVS_ALIGNMENT_H 135 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/capi.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_CAPI_H 34 | #define AVS_CAPI_H 35 | 36 | #include "config.h" 37 | 38 | #ifdef AVS_POSIX 39 | // this is also defined in avs/posix.h 40 | #ifndef AVS_HAIKU 41 | #define __declspec(x) 42 | #endif 43 | #endif 44 | 45 | #ifdef __cplusplus 46 | # define EXTERN_C extern "C" 47 | #else 48 | # define EXTERN_C 49 | #endif 50 | 51 | #ifdef AVS_WINDOWS 52 | #ifdef BUILDING_AVSCORE 53 | # if defined(GCC) && defined(X86_32) 54 | # define AVSC_CC 55 | # else // MSVC builds and 64-bit GCC 56 | # ifndef AVSC_USE_STDCALL 57 | # define AVSC_CC __cdecl 58 | # else 59 | # define AVSC_CC __stdcall 60 | # endif 61 | # endif 62 | #else // needed for programs that talk to AviSynth+ 63 | # ifndef AVSC_WIN32_GCC32 // see comment below 64 | # ifndef AVSC_USE_STDCALL 65 | # define AVSC_CC __cdecl 66 | # else 67 | # define AVSC_CC __stdcall 68 | # endif 69 | # else 70 | # define AVSC_CC 71 | # endif 72 | #endif 73 | # else 74 | # define AVSC_CC 75 | #endif 76 | 77 | // On 64-bit Windows, there's only one calling convention, 78 | // so there is no difference between MSVC and GCC. On 32-bit, 79 | // this isn't true. The convention that GCC needs to use to 80 | // even build AviSynth+ as 32-bit makes anything that uses 81 | // it incompatible with 32-bit MSVC builds of AviSynth+. 82 | // The AVSC_WIN32_GCC32 define is meant to provide a user 83 | // switchable way to make builds of FFmpeg to test 32-bit 84 | // GCC builds of AviSynth+ without having to screw around 85 | // with alternate headers, while still default to the usual 86 | // situation of using 32-bit MSVC builds of AviSynth+. 87 | 88 | // Hopefully, this situation will eventually be resolved 89 | // and a broadly compatible solution will arise so the 90 | // same 32-bit FFmpeg build can handle either MSVC or GCC 91 | // builds of AviSynth+. 92 | 93 | #define AVSC_INLINE static __inline 94 | 95 | #ifdef BUILDING_AVSCORE 96 | #ifdef AVS_WINDOWS 97 | # ifndef AVS_STATIC_LIB 98 | # define AVSC_EXPORT __declspec(dllexport) 99 | # else 100 | # define AVSC_EXPORT 101 | # endif 102 | # define AVSC_API(ret, name) EXTERN_C AVSC_EXPORT ret AVSC_CC name 103 | #else 104 | # define AVSC_EXPORT EXTERN_C 105 | # define AVSC_API(ret, name) EXTERN_C ret AVSC_CC name 106 | #endif 107 | #else 108 | # define AVSC_EXPORT EXTERN_C __declspec(dllexport) 109 | # ifndef AVS_STATIC_LIB 110 | # define AVSC_IMPORT __declspec(dllimport) 111 | # else 112 | # define AVSC_IMPORT 113 | # endif 114 | # ifndef AVSC_NO_DECLSPEC 115 | # define AVSC_API(ret, name) EXTERN_C AVSC_IMPORT ret AVSC_CC name 116 | # else 117 | # define AVSC_API(ret, name) typedef ret (AVSC_CC *name##_func) 118 | # endif 119 | #endif 120 | 121 | #endif //AVS_CAPI_H 122 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/config.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_CONFIG_H 34 | #define AVS_CONFIG_H 35 | 36 | // Undefine this to get cdecl calling convention 37 | #define AVSC_USE_STDCALL 1 38 | 39 | // NOTE TO PLUGIN AUTHORS: 40 | // Because FRAME_ALIGN can be substantially higher than the alignment 41 | // a plugin actually needs, plugins should not use FRAME_ALIGN to check for 42 | // alignment. They should always request the exact alignment value they need. 43 | // This is to make sure that plugins work over the widest range of AviSynth 44 | // builds possible. 45 | #define FRAME_ALIGN 64 46 | 47 | #if defined(_M_AMD64) || defined(__x86_64) 48 | # define X86_64 49 | #elif defined(_M_IX86) || defined(__i386__) 50 | # define X86_32 51 | // VS2017 introduced _M_ARM64 52 | #elif defined(_M_ARM64) || defined(__aarch64__) 53 | # define ARM64 54 | #elif defined(_M_ARM) || defined(__arm__) 55 | # define ARM32 56 | #elif defined(__PPC64__) 57 | # define PPC64 58 | #elif defined(_M_PPC) || defined(__PPC__) || defined(__POWERPC__) 59 | # define PPC32 60 | #elif defined(__riscv) 61 | # define RISCV 62 | #elif defined(__sparc_v9__) 63 | # define SPARC 64 | #else 65 | # error Unsupported CPU architecture. 66 | #endif 67 | 68 | // VC++ LLVM-Clang-cl MinGW-Gnu 69 | // MSVC x x 70 | // MSVC_PURE x 71 | // CLANG x 72 | // GCC x 73 | 74 | #if defined(__clang__) 75 | // Check clang first. clang-cl also defines __MSC_VER 76 | // We set MSVC because they are mostly compatible 77 | # define CLANG 78 | #if defined(_MSC_VER) 79 | # define MSVC 80 | # define AVS_FORCEINLINE __attribute__((always_inline)) 81 | #else 82 | # define AVS_FORCEINLINE __attribute__((always_inline)) inline 83 | #endif 84 | #elif defined(_MSC_VER) 85 | # define MSVC 86 | # define MSVC_PURE 87 | # define AVS_FORCEINLINE __forceinline 88 | #elif defined(__GNUC__) 89 | # define GCC 90 | # define AVS_FORCEINLINE __attribute__((always_inline)) inline 91 | #elif defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER) 92 | // Intel C++ Compilers with MSVC command line interface will not appear here rather at _MSC_VER 93 | # define AVS_FORCEINLINE inline 94 | # undef __forceinline 95 | # define __forceinline inline 96 | #else 97 | # error Unsupported compiler. 98 | # define AVS_FORCEINLINE inline 99 | # undef __forceinline 100 | # define __forceinline inline 101 | #endif 102 | 103 | #if defined(_WIN32) 104 | # define AVS_WINDOWS 105 | #elif defined(__linux__) 106 | # define AVS_LINUX 107 | # define AVS_POSIX 108 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 109 | # define AVS_BSD 110 | # define AVS_POSIX 111 | #elif defined(__APPLE__) 112 | # define AVS_MACOS 113 | # define AVS_POSIX 114 | #elif defined(__HAIKU__) 115 | # define AVS_HAIKU 116 | # define AVS_POSIX 117 | #else 118 | # error Operating system unsupported. 119 | #endif 120 | 121 | // useful warnings disabler macros for supported compilers 122 | 123 | #if defined(_MSC_VER) 124 | #define DISABLE_WARNING_PUSH __pragma(warning( push )) 125 | #define DISABLE_WARNING_POP __pragma(warning( pop )) 126 | #define DISABLE_WARNING(warningNumber) __pragma(warning( disable : warningNumber )) 127 | 128 | #define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE DISABLE_WARNING(4101) 129 | #define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(4505) 130 | // other warnings you want to deactivate... 131 | 132 | #elif defined(__GNUC__) || defined(__clang__) 133 | #define DO_PRAGMA(X) _Pragma(#X) 134 | #define DISABLE_WARNING_PUSH DO_PRAGMA(GCC diagnostic push) 135 | #define DISABLE_WARNING_POP DO_PRAGMA(GCC diagnostic pop) 136 | #define DISABLE_WARNING(warningName) DO_PRAGMA(GCC diagnostic ignored #warningName) 137 | 138 | #define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE DISABLE_WARNING(-Wunused-variable) 139 | #define DISABLE_WARNING_UNREFERENCED_FUNCTION DISABLE_WARNING(-Wunused-function) 140 | // other warnings you want to deactivate... 141 | 142 | #else 143 | #define DISABLE_WARNING_PUSH 144 | #define DISABLE_WARNING_POP 145 | #define DISABLE_WARNING_UNREFERENCED_LOCAL_VARIABLE 146 | #define DISABLE_WARNING_UNREFERENCED_FUNCTION 147 | // other warnings you want to deactivate... 148 | 149 | #endif 150 | 151 | #if defined(AVS_WINDOWS) && defined(_USING_V110_SDK71_) 152 | // Windows XP does not have proper initialization for 153 | // thread local variables. 154 | // Use workaround instead __declspec(thread) 155 | #define XP_TLS 156 | #endif 157 | 158 | #ifndef MSVC 159 | // GCC and Clang can be used on big endian systems, MSVC can't. 160 | # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 161 | # define AVS_ENDIANNESS "little" 162 | # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 163 | # define AVS_ENDIANNESS "big" 164 | # else 165 | # define AVS_ENDIANNESS "middle" 166 | # endif 167 | #else 168 | #define AVS_ENDIANNESS "little" 169 | #endif 170 | 171 | #endif //AVS_CONFIG_H 172 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/cpuid.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifndef AVSCORE_CPUID_H 33 | #define AVSCORE_CPUID_H 34 | 35 | // For GetCPUFlags. These are backwards-compatible with those in VirtualDub. 36 | // ending with SSE4_2 37 | // For emulation see https://software.intel.com/en-us/articles/intel-software-development-emulator 38 | enum { 39 | /* oldest CPU to support extension */ 40 | CPUF_FORCE = 0x01, // N/A 41 | CPUF_FPU = 0x02, // 386/486DX 42 | CPUF_MMX = 0x04, // P55C, K6, PII 43 | CPUF_INTEGER_SSE = 0x08, // PIII, Athlon 44 | CPUF_SSE = 0x10, // PIII, Athlon XP/MP 45 | CPUF_SSE2 = 0x20, // PIV, K8 46 | CPUF_3DNOW = 0x40, // K6-2 47 | CPUF_3DNOW_EXT = 0x80, // Athlon 48 | CPUF_X86_64 = 0xA0, // Hammer (note: equiv. to 3DNow + SSE2, which 49 | // only Hammer will have anyway) 50 | CPUF_SSE3 = 0x100, // PIV+, K8 Venice 51 | CPUF_SSSE3 = 0x200, // Core 2 52 | CPUF_SSE4 = 0x400, 53 | CPUF_SSE4_1 = 0x400, // Penryn, Wolfdale, Yorkfield 54 | CPUF_AVX = 0x800, // Sandy Bridge, Bulldozer 55 | CPUF_SSE4_2 = 0x1000, // Nehalem 56 | // AVS+ 57 | CPUF_AVX2 = 0x2000, // Haswell 58 | CPUF_FMA3 = 0x4000, 59 | CPUF_F16C = 0x8000, 60 | CPUF_MOVBE = 0x10000, // Big Endian move 61 | CPUF_POPCNT = 0x20000, 62 | CPUF_AES = 0x40000, 63 | CPUF_FMA4 = 0x80000, 64 | 65 | CPUF_AVX512F = 0x100000, // AVX-512 Foundation. 66 | CPUF_AVX512DQ = 0x200000, // AVX-512 DQ (Double/Quad granular) Instructions 67 | CPUF_AVX512PF = 0x400000, // AVX-512 Prefetch 68 | CPUF_AVX512ER = 0x800000, // AVX-512 Exponential and Reciprocal 69 | CPUF_AVX512CD = 0x1000000, // AVX-512 Conflict Detection 70 | CPUF_AVX512BW = 0x2000000, // AVX-512 BW (Byte/Word granular) Instructions 71 | CPUF_AVX512VL = 0x4000000, // AVX-512 VL (128/256 Vector Length) Extensions 72 | CPUF_AVX512IFMA = 0x8000000, // AVX-512 IFMA integer 52 bit 73 | CPUF_AVX512VBMI = 0x10000000,// AVX-512 VBMI 74 | }; 75 | 76 | #ifdef BUILDING_AVSCORE 77 | int GetCPUFlags(); 78 | void SetMaxCPU(int new_flags); 79 | #endif 80 | 81 | #endif // AVSCORE_CPUID_H 82 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/minmax.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifndef AVSCORE_MINMAX_H 33 | #define AVSCORE_MINMAX_H 34 | 35 | template 36 | T min(T v1, T v2) 37 | { 38 | return v1 < v2 ? v1 : v2; 39 | } 40 | 41 | template 42 | T max(T v1, T v2) 43 | { 44 | return v1 > v2 ? v1 : v2; 45 | } 46 | 47 | template 48 | T clamp(T n, T min, T max) 49 | { 50 | n = n > max ? max : n; 51 | return n < min ? min : n; 52 | } 53 | 54 | #endif // AVSCORE_MINMAX_H 55 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/types.h: -------------------------------------------------------------------------------- 1 | // Avisynth C Interface Version 0.20 2 | // Copyright 2003 Kevin Atkinson 3 | 4 | // This program is free software; you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation; either version 2 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program; if not, write to the Free Software 16 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 17 | // http://www.gnu.org/copyleft/gpl.html . 18 | // 19 | // As a special exception, I give you permission to link to the 20 | // Avisynth C interface with independent modules that communicate with 21 | // the Avisynth C interface solely through the interfaces defined in 22 | // avisynth_c.h, regardless of the license terms of these independent 23 | // modules, and to copy and distribute the resulting combined work 24 | // under terms of your choice, provided that every copy of the 25 | // combined work is accompanied by a complete copy of the source code 26 | // of the Avisynth C interface and Avisynth itself (with the version 27 | // used to produce the combined work), being distributed under the 28 | // terms of the GNU General Public License plus this exception. An 29 | // independent module is a module which is not derived from or based 30 | // on Avisynth C Interface, such as 3rd-party filters, import and 31 | // export plugins, or graphical user interfaces. 32 | 33 | #ifndef AVS_TYPES_H 34 | #define AVS_TYPES_H 35 | 36 | // Define all types necessary for interfacing with avisynth.dll 37 | #include 38 | #include 39 | #ifdef __cplusplus 40 | #include 41 | #include 42 | #else 43 | #include 44 | #include 45 | #endif 46 | 47 | // Raster types used by VirtualDub & Avisynth 48 | typedef uint32_t Pixel32; 49 | typedef uint8_t BYTE; 50 | 51 | // Audio Sample information 52 | typedef float SFLOAT; 53 | 54 | #endif //AVS_TYPES_H 55 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/avs/win.h: -------------------------------------------------------------------------------- 1 | // This program is free software; you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation; either version 2 of the License, or 4 | // (at your option) any later version. 5 | // 6 | // This program is distributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | // 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program; if not, write to the Free Software 13 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit 14 | // http://www.gnu.org/copyleft/gpl.html . 15 | // 16 | // Linking Avisynth statically or dynamically with other modules is making a 17 | // combined work based on Avisynth. Thus, the terms and conditions of the GNU 18 | // General Public License cover the whole combination. 19 | // 20 | // As a special exception, the copyright holders of Avisynth give you 21 | // permission to link Avisynth with independent modules that communicate with 22 | // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license 23 | // terms of these independent modules, and to copy and distribute the 24 | // resulting combined work under terms of your choice, provided that 25 | // every copy of the combined work is accompanied by a complete copy of 26 | // the source code of Avisynth (the version of Avisynth used to produce the 27 | // combined work), being distributed under the terms of the GNU General 28 | // Public License plus this exception. An independent module is a module 29 | // which is not derived from or based on Avisynth, such as 3rd-party filters, 30 | // import and export plugins, or graphical user interfaces. 31 | 32 | #ifndef AVSCORE_WIN_H 33 | #define AVSCORE_WIN_H 34 | 35 | // Whenever you need windows headers, start by including this file, then the rest. 36 | 37 | // WWUUT? We require XP now? 38 | #if !defined(NTDDI_VERSION) && !defined(_WIN32_WINNT) 39 | #define NTDDI_VERSION 0x05020000 40 | #define _WIN32_WINNT 0x0502 41 | #endif 42 | 43 | #define WIN32_LEAN_AND_MEAN 44 | #define STRICT 45 | #if !defined(NOMINMAX) 46 | #define NOMINMAX 47 | #endif 48 | 49 | #include 50 | 51 | // Provision for UTF-8 max 4 bytes per code point 52 | #define AVS_MAX_PATH MAX_PATH*4 53 | 54 | #endif // AVSCORE_WIN_H 55 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/functions_c.h: -------------------------------------------------------------------------------- 1 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 2 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 3 | #define lerp(a,b,t) ((1 - (t)) * (a) + (t) * (b) ) 4 | #include "C:\Program Files (x86)\~AvsPmod\plugins\C_White_Point_x64\C_White_Point\xyY_funcs.h" 5 | -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/lib/AviSynth_x64.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Auto_Gamma_x64/lib/AviSynth_x64.exp -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/lib/AviSynth_x64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Auto_Gamma_x64/lib/AviSynth_x64.lib -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/lib/AviSynth_x86.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Auto_Gamma_x64/lib/AviSynth_x86.exp -------------------------------------------------------------------------------- /C_Auto_Gamma_x64/lib/AviSynth_x86.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Auto_Gamma_x64/lib/AviSynth_x86.lib -------------------------------------------------------------------------------- /C_Circle_Warp_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Circle_Warp_x64.dll -------------------------------------------------------------------------------- /C_Circle_Warp_x64/Function definition: -------------------------------------------------------------------------------- 1 | ( 2 | clip clip, 3 | float "expn"=0.312727 (0 to 3 by 0.0001), 4 | bool "sixtyFour" = false, 5 | ) 6 | -------------------------------------------------------------------------------- /C_Circle_Warp_x64/circle_warp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "..\avisynth_c.h" 5 | #include "functions_c.h" 6 | 7 | typedef struct Circle_Warp { 8 | double expn; 9 | int sixtyFour; 10 | } Circle_Warp; 11 | 12 | AVS_VideoFrame * AVSC_CC Circle_Warp_get_frame (AVS_FilterInfo * p, int n) 13 | { 14 | AVS_VideoFrame *src, *dst; 15 | double xp; 16 | BYTE* srcp; 17 | BYTE* dstp; 18 | Circle_Warp* params = (Circle_Warp*) p->user_data; 19 | xp=params->expn; 20 | 21 | src = avs_get_frame(p->child, n); 22 | if(xp!=1){ 23 | int row_size, height, src_pitch,dst_pitch,sxf,wdt; 24 | srcp = avs_get_read_ptr(src); 25 | src_pitch = avs_get_pitch(src); 26 | row_size = avs_get_row_size(src); 27 | height = avs_get_height(src); 28 | wdt=p->vi.width; 29 | 30 | 31 | dst = avs_new_video_frame(p->env, &p->vi); 32 | dst_pitch = avs_get_pitch(dst); 33 | dstp = avs_get_write_ptr(dst); 34 | dst->height=height; 35 | dst->row_size=row_size; 36 | 37 | sxf=params->sixtyFour; 38 | 39 | 40 | 41 | int** rds = malloc(wdt * sizeof(int*)); // rows 42 | for (int r = 0; r < wdt; ++r) { 43 | rds[r] = malloc(height * sizeof(int)); // columns 44 | } 45 | 46 | int** grs = malloc(wdt * sizeof(int*)); // rows 47 | for (int r = 0; r < wdt; ++r) { 48 | grs[r] = malloc(height * sizeof(int)); // columns 49 | } 50 | 51 | int** bls = malloc(wdt * sizeof(int*)); // rows 52 | for (int r = 0; r < wdt; ++r) { 53 | bls[r] = malloc(height * sizeof(int)); // columns 54 | } 55 | 56 | 57 | int xarr=0; 58 | 59 | for (int y=0; yuser_data; 144 | free(params); 145 | } 146 | 147 | AVS_Value AVSC_CC create_Circle_Warp (AVS_ScriptEnvironment * env, 148 | AVS_Value args, void * dg) 149 | { 150 | AVS_Value v; 151 | AVS_FilterInfo * fi; 152 | AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); 153 | Circle_Warp *params = (Circle_Warp*)malloc(sizeof(Circle_Warp)); 154 | 155 | if (!params) 156 | return avs_void; 157 | 158 | params->expn= avs_defined(avs_array_elt(args, 1))?avs_as_float(avs_array_elt(args, 1)):1; 159 | 160 | if (!((avs_is_rgb32(&fi->vi))||(avs_is_rgb64(&fi->vi)))) { 161 | return avs_new_value_error ("Input video must be in RGB32 OR RGB64 format!"); 162 | } else { 163 | 164 | if(avs_defined(avs_array_elt(args, 2))){ 165 | params->sixtyFour =avs_as_bool(avs_array_elt(args, 2)); 166 | }else{ 167 | params->sixtyFour = (avs_is_rgb64(&fi->vi))?true:false; 168 | } 169 | 170 | fi->user_data = (void*) params; 171 | 172 | fi->get_frame = Circle_Warp_get_frame; 173 | 174 | v = avs_new_value_clip(new_clip); 175 | fi->free_filter = free_Circle_Warp; 176 | 177 | avs_release_clip(new_clip); 178 | return v; 179 | } 180 | } 181 | 182 | const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env) 183 | { 184 | avs_add_function(env, "Circle_Warp", "c[expn]f[sixtyFour]b", create_Circle_Warp, 0); 185 | return "Circle_Warp C plugin"; 186 | } 187 | -------------------------------------------------------------------------------- /C_Circle_Warp_x64/functions_c.h: -------------------------------------------------------------------------------- 1 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 2 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 3 | 4 | static inline double dist(double x1, double x2, double y1, double y2){ 5 | return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); 6 | } 7 | 8 | void adjCenDist(int w, int h, double cd[2], double madr[3],double cen[2]){ 9 | double d_w=(double)(w); 10 | double d_h=(double)(h); 11 | cen[0]=0.5*(d_w-1); 12 | cen[1]=0.5*(d_h-1); 13 | double brd[4]={0.5, d_w-0.5, d_h-0.5,0.5}; 14 | double ds[4]={-1,-1,-1,-1}; 15 | double ds1[4]={-1,-1,-1,-1}; 16 | 17 | int flag=0; 18 | double m=0; 19 | double b=0; 20 | 21 | if(cd[0]==cen[0]){ 22 | flag++; 23 | ds[2]=fabs(brd[2]-cen[1]); //te 24 | ds[3]=fabs(brd[3]-cen[1]); //be 25 | } 26 | 27 | if(cd[1]==cen[1]){ 28 | flag++; 29 | ds[0]=fabs(brd[0]-cen[0]); //le 30 | ds[1]=fabs(brd[1]-cen[0]); //re 31 | } 32 | 33 | if(flag==0){ 34 | m=(cd[1]-cen[1])/(cd[0]-cen[0]); 35 | b=-cd[0]*m+cd[1]; 36 | ds[0]=m*brd[0]+b; 37 | ds[1]=m*brd[1]+b; 38 | ds[2]=(brd[2]-b)/m; 39 | ds[3]=(brd[3]-b)/m; 40 | 41 | ds1[0]=dist(cen[0],brd[0],cen[1],ds[0]); //le 42 | ds1[1]=dist(cen[0],brd[1],cen[1],ds[1]); //re 43 | ds1[2]=dist(cen[0],ds[2],cen[1],brd[2]); //te 44 | ds1[3]=dist(cen[0],ds[3],cen[1],brd[3]); //be 45 | } 46 | 47 | flag=0; 48 | 49 | for(int i=0; i<4; i++){ 50 | if(ds1[i]!=-1){ 51 | flag++; 52 | if(flag==1){ 53 | madr[0]=ds1[i]; 54 | }else{ 55 | madr[0]=(ds1[i] (y)) ? (x) : (y)) 2 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 3 | #define lerp(a,b,t) ((1 - (t)) * (a) + (t) * (b) ) 4 | #define rcptwoFiveFive 1.0/255.0 5 | #define rcpTwoFour 1.0/2.4 6 | #define rcptHiBit 1.0/65535.0 7 | #define third 1.0/3.0 8 | #define rcpOFiveFive 1.0/1.055 9 | #define rcpTwelveNineTwo 1.0/12.92 10 | #define rcpFourFive 1.0/4.5 11 | #define recAlpha 1.09929682680944 12 | #define rcpRecAlpha 1.0/1.09929682680944 13 | #define recBeta 0.018053968510807 14 | #define recBetaLin 0.004011993002402 15 | #define rcpTxFourFive 10.0/4.5 16 | #define invTwoTwo 5.0/11.0 17 | #define invTwoSix 5.0/13.0 18 | #define root_three 1.732050807568877 19 | #define rcpTwelve 1.0/12.0 20 | #define HLG_a 0.17883277 21 | #define rcp_HLG_a 1.0/0.17883277 22 | #define HLG_b 0.28466892 23 | #define HLG_c 0.55991073 24 | #define euler_e 2.718281828459045 25 | 26 | inline double fastPrecisePow(double a, double b) { 27 | //added support for negative exponents 28 | int neg_b=0; 29 | 30 | if(b==0){ 31 | return 1.0; 32 | }else if(b<0){ 33 | neg_b=1; 34 | b=fabs(b); 35 | } 36 | // calculate approximation with fraction of the exponent 37 | int e = (int) b; 38 | union { 39 | double d; 40 | int x[2]; 41 | } u = { a }; 42 | u.x[1] = (int)((b - e) * (u.x[1] - 1072632447) + 1072632447); 43 | u.x[0] = 0; 44 | 45 | // exponentiation by squaring with the exponent's integer part 46 | // double r = u.d makes everything much slower, not sure why 47 | double r = 1.0; 48 | while (e) { 49 | if (e & 1) { 50 | r *= a; 51 | } 52 | a *= a; 53 | e >>= 1; 54 | } 55 | 56 | double res= r * u.d; 57 | 58 | if(neg_b==0){ 59 | return res; 60 | }else{ 61 | return 1.0/res; 62 | } 63 | 64 | } 65 | //Source: https://martin.ankerl.com/2012/01/25/optimized-approximative-fastPrecisePow-in-c-and-cpp/ 66 | -------------------------------------------------------------------------------- /C_Linear_Gamma_x64/linear_gamma.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "..\avisynth_c.h" 5 | #include "functions_c.h" 6 | 7 | typedef struct Linear_Gamma { 8 | int linear; 9 | int approx; 10 | int sixtyFour; 11 | } Linear_Gamma; 12 | 13 | AVS_VideoFrame * AVSC_CC Linear_Gamma_get_frame (AVS_FilterInfo * p, int n) 14 | { 15 | AVS_VideoFrame * src; 16 | Linear_Gamma* params = (Linear_Gamma*) p->user_data; 17 | 18 | src = avs_get_frame(p->child, n); 19 | 20 | int row_size, height, src_pitch,x, y,lnr,sxf,aprx; 21 | BYTE* srcp; 22 | double bOG,gOG,rOG,R,G,B; 23 | 24 | 25 | lnr=params->linear; 26 | aprx=params->approx; 27 | sxf=params->sixtyFour; 28 | 29 | avs_make_writable(p->env, &src); 30 | 31 | srcp = avs_get_write_ptr(src); 32 | src_pitch = avs_get_pitch(src); 33 | row_size = avs_get_row_size(src); 34 | height = avs_get_height(src); 35 | 36 | ///////////////ACTUALLY DRAW PIXELS/////////////////////////////////////// 37 | for (y=0; y 0.0404482362771082 )?fastPrecisePow(fabs((rOG+0.055)*rcpOFiveFive),2.4):rOG*rcpTwelveNineTwo; 54 | G=(gOG > 0.0404482362771082 )?fastPrecisePow(fabs((gOG+0.055)*rcpOFiveFive),2.4):gOG*rcpTwelveNineTwo; 55 | B=(bOG > 0.0404482362771082 )?fastPrecisePow(fabs((bOG+0.055)*rcpOFiveFive),2.4):bOG*rcpTwelveNineTwo; 56 | }else if(lnr==8){ 57 | R=fastPrecisePow(rOG,invTwoSix); 58 | G=fastPrecisePow(gOG,invTwoSix); 59 | B=fastPrecisePow(bOG,invTwoSix); 60 | }else if (lnr==5){ 61 | R=fastPrecisePow(rOG,2.2); 62 | G=fastPrecisePow(gOG,2.2); 63 | B=fastPrecisePow(bOG,2.2); 64 | }else if (lnr==12){ 65 | R=fastPrecisePow(rOG,rcpTwoFour); 66 | G=fastPrecisePow(gOG,rcpTwoFour); 67 | B=fastPrecisePow(bOG,rcpTwoFour); 68 | }else if (lnr==11){ 69 | R=fastPrecisePow(rOG,2.4); 70 | G=fastPrecisePow(gOG,2.4); 71 | B=fastPrecisePow(bOG,2.4); 72 | }else if(lnr==3){ 73 | R=(rOG < recBetaLin )?rcpFourFive*rOG:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-rOG)),rcpTxFourFive); 74 | G=(gOG < recBetaLin )?rcpFourFive*gOG:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-gOG)),rcpTxFourFive); 75 | B=(bOG < recBetaLin )?rcpFourFive*bOG:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-bOG)),rcpTxFourFive); 76 | }else if(lnr==2){ 77 | R=(rOG> 0.00313066844250063)?1.055 * fastPrecisePow(rOG,rcpTwoFour) - 0.055:12.92 *rOG; 78 | G=(gOG> 0.00313066844250063)?1.055 * fastPrecisePow(gOG,rcpTwoFour) - 0.055:12.92 *gOG; 79 | B=(bOG> 0.00313066844250063)?1.055 * fastPrecisePow(bOG,rcpTwoFour) - 0.055:12.92 *bOG; 80 | }else if(lnr==7){ 81 | R=fastPrecisePow(rOG,2.6); 82 | G=fastPrecisePow(gOG,2.6); 83 | B=fastPrecisePow(bOG,2.6); 84 | }else if(lnr==6){ 85 | R=fastPrecisePow(rOG,invTwoTwo); 86 | G=fastPrecisePow(gOG,invTwoTwo); 87 | B=fastPrecisePow(bOG,invTwoTwo); 88 | }else if(lnr==4){ 89 | R=(rOG< recBeta)?4.5*rOG:recAlpha*fastPrecisePow(rOG,0.45)-(recAlpha-1); 90 | G=(gOG< recBeta)?4.5*gOG:recAlpha*fastPrecisePow(gOG,0.45)-(recAlpha-1); 91 | B=(bOG< recBeta)?4.5*bOG:recAlpha*fastPrecisePow(bOG,0.45)-(recAlpha-1); 92 | }else if (lnr==9){ 93 | R=(rOG>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(rOG-HLG_c)*rcp_HLG_a)+HLG_b):rOG*rOG*third; 94 | G=(gOG>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(gOG-HLG_c)*rcp_HLG_a)+HLG_b):gOG*gOG*third; 95 | B=(bOG>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(bOG-HLG_c)*rcp_HLG_a)+HLG_b):bOG*bOG*third; 96 | }else if (lnr==10){ 97 | R=(rOG > rcpTwelve)?HLG_a*log(12.0*rOG-HLG_b)+HLG_c:root_three*fastPrecisePow(rOG,0.5); 98 | G=(gOG > rcpTwelve)?HLG_a*log(12.0*gOG-HLG_b)+HLG_c:root_three*fastPrecisePow(gOG,0.5); 99 | B=(bOG > rcpTwelve)?HLG_a*log(12.0*bOG-HLG_b)+HLG_c:root_three*fastPrecisePow(bOG,0.5); 100 | } 101 | 102 | }else{ 103 | 104 | if (lnr==1){ 105 | R=(rOG > 0.0404482362771082 )?pow(fabs((rOG+0.055)*rcpOFiveFive),2.4):rOG*rcpTwelveNineTwo; 106 | G=(gOG > 0.0404482362771082 )?pow(fabs((gOG+0.055)*rcpOFiveFive),2.4):gOG*rcpTwelveNineTwo; 107 | B=(bOG > 0.0404482362771082 )?pow(fabs((bOG+0.055)*rcpOFiveFive),2.4):bOG*rcpTwelveNineTwo; 108 | }else if(lnr==8){ 109 | R=pow(rOG,invTwoSix); 110 | G=pow(gOG,invTwoSix); 111 | B=pow(bOG,invTwoSix); 112 | }else if (lnr==5){ 113 | R=pow(rOG,2.2); 114 | G=pow(gOG,2.2); 115 | B=pow(bOG,2.2); 116 | }else if (lnr==12){ 117 | R=pow(rOG,rcpTwoFour); 118 | G=pow(gOG,rcpTwoFour); 119 | B=pow(bOG,rcpTwoFour); 120 | }else if (lnr==11){ 121 | R=pow(rOG,2.4); 122 | G=pow(gOG,2.4); 123 | B=pow(bOG,2.4); 124 | }else if(lnr==3){ 125 | R=(rOG < recBetaLin )?rcpFourFive*rOG:pow(-1*(rcpRecAlpha*(1-recAlpha-rOG)),rcpTxFourFive); 126 | G=(gOG < recBetaLin )?rcpFourFive*gOG:pow(-1*(rcpRecAlpha*(1-recAlpha-gOG)),rcpTxFourFive); 127 | B=(bOG < recBetaLin )?rcpFourFive*bOG:pow(-1*(rcpRecAlpha*(1-recAlpha-bOG)),rcpTxFourFive); 128 | }else if(lnr==2){ 129 | R=(rOG> 0.00313066844250063)?1.055 * pow(rOG,rcpTwoFour) - 0.055:12.92 *rOG; 130 | G=(gOG> 0.00313066844250063)?1.055 * pow(gOG,rcpTwoFour) - 0.055:12.92 *gOG; 131 | B=(bOG> 0.00313066844250063)?1.055 * pow(bOG,rcpTwoFour) - 0.055:12.92 *bOG; 132 | }else if(lnr==7){ 133 | R=pow(rOG,2.6); 134 | G=pow(gOG,2.6); 135 | B=pow(bOG,2.6); 136 | }else if(lnr==6){ 137 | R=pow(rOG,invTwoTwo); 138 | G=pow(gOG,invTwoTwo); 139 | B=pow(bOG,invTwoTwo); 140 | }else if(lnr==4){ 141 | R=(rOG< recBeta)?4.5*rOG:recAlpha*pow(rOG,0.45)-(recAlpha-1); 142 | G=(gOG< recBeta)?4.5*gOG:recAlpha*pow(gOG,0.45)-(recAlpha-1); 143 | B=(bOG< recBeta)?4.5*bOG:recAlpha*pow(bOG,0.45)-(recAlpha-1); 144 | }else if (lnr==9){ 145 | R=(rOG>0.5)?rcpTwelve*(pow(euler_e,(rOG-HLG_c)*rcp_HLG_a)+HLG_b):rOG*rOG*third; 146 | G=(gOG>0.5)?rcpTwelve*(pow(euler_e,(gOG-HLG_c)*rcp_HLG_a)+HLG_b):gOG*gOG*third; 147 | B=(bOG>0.5)?rcpTwelve*(pow(euler_e,(bOG-HLG_c)*rcp_HLG_a)+HLG_b):bOG*bOG*third; 148 | }else if (lnr==10){ 149 | R=(rOG > rcpTwelve)?HLG_a*log(12.0*rOG-HLG_b)+HLG_c:root_three*pow(rOG,0.5); 150 | G=(gOG > rcpTwelve)?HLG_a*log(12.0*gOG-HLG_b)+HLG_c:root_three*pow(gOG,0.5); 151 | B=(bOG > rcpTwelve)?HLG_a*log(12.0*bOG-HLG_b)+HLG_c:root_three*pow(bOG,0.5); 152 | } 153 | 154 | } 155 | 156 | int wp_b=MAX(MIN(round(B*255),255),0); 157 | int wp_g=MAX(MIN(round(G*255),255),0); 158 | int wp_r=MAX(MIN(round(R*255),255),0); 159 | 160 | srcp[x] =wp_b; //blue : blue 161 | srcp[x+1] =(sxf==1)?wp_b:wp_g; // blue : green 162 | srcp[x+2] =(sxf==1)? wp_g:wp_r; // green: red 163 | srcp[x+3] =(sxf==1)? wp_g:srcp[x+3]; //green : self 164 | srcp[x+4] =(sxf==1)? wp_r:srcp[x+4]; //red : self 165 | srcp[x+5] =(sxf==1)? wp_r:srcp[x+5]; //red : self 166 | 167 | x=(sxf==1)?x+7:x+3; 168 | 169 | } 170 | srcp += src_pitch; 171 | } 172 | 173 | return src; 174 | } 175 | 176 | void AVSC_CC free_Linear_Gamma(AVS_FilterInfo* fi) 177 | { 178 | Linear_Gamma* params = (Linear_Gamma*) fi->user_data; 179 | free(params); 180 | } 181 | 182 | AVS_Value AVSC_CC create_Linear_Gamma (AVS_ScriptEnvironment * env,AVS_Value args, void * dg) 183 | { 184 | AVS_Value v; 185 | AVS_FilterInfo * fi; 186 | AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); 187 | Linear_Gamma *params = (Linear_Gamma*)malloc(sizeof(Linear_Gamma)); 188 | 189 | if (!params) 190 | return avs_void; 191 | 192 | 193 | params->linear= avs_defined(avs_array_elt(args, 1))?avs_as_int(avs_array_elt(args, 1)):1; 194 | params->approx= avs_defined(avs_array_elt(args, 2))?avs_as_bool(avs_array_elt(args, 2)):true; 195 | 196 | if ((params->linear<1)||(params->linear>12)){ 197 | return avs_new_value_error ("Allowed linear values are between 1 and 12!"); 198 | }else{ 199 | if (!((avs_is_rgb32(&fi->vi))||(avs_is_rgb64(&fi->vi)))) { 200 | return avs_new_value_error ("Input video must be in RGB32 OR RGB64 format!"); 201 | } else { 202 | 203 | if(avs_defined(avs_array_elt(args, 3))){ 204 | params->sixtyFour =avs_as_bool(avs_array_elt(args, 3)); 205 | }else{ 206 | params->sixtyFour = (avs_is_rgb64(&fi->vi))?true:false; 207 | } 208 | fi->user_data = (void*) params; 209 | fi->get_frame = Linear_Gamma_get_frame; 210 | v = avs_new_value_clip(new_clip); 211 | fi->free_filter = free_Linear_Gamma; 212 | } 213 | } 214 | avs_release_clip(new_clip); 215 | return v; 216 | } 217 | 218 | const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env) 219 | { 220 | avs_add_function(env, "Linear_Gamma", "c[linear]i[approx]b[sixtyFour]b", create_Linear_Gamma, 0); 221 | return "Linear_Gamma C plugin"; 222 | } 223 | -------------------------------------------------------------------------------- /C_Luma_Smooth_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Luma_Smooth_x64.dll -------------------------------------------------------------------------------- /C_Luma_Smooth_x64/Function_definition.txt: -------------------------------------------------------------------------------- 1 | ( 2 | clip clip, 3 | int "surr"=3 (1 to 25 by 1), 4 | float "var"=0.01 (0 to 0.2 by 0.00001), 5 | float "smooth"=0.2 (0 to 1 by 0.001), 6 | bool "debug"=false, 7 | bool "sixtyFour"=false 8 | ) 9 | -------------------------------------------------------------------------------- /C_Luma_Smooth_x64/luma_smooth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "..\avisynth_c.h" 6 | 7 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 8 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 9 | #define lerp(a,b,t) ((1 - (t)) * (a) + (t) * (b) ) 10 | #define rcptwoFiveFive 1.0/255.0 11 | #define rcptHiBit 1.0/65535.0 12 | 13 | typedef struct Luma_Smooth { 14 | int surr; 15 | double var; 16 | double smooth; 17 | int debug; 18 | int sixtyFour; 19 | double *ys; 20 | double *out_ys; 21 | double *rs; 22 | double *gs; 23 | double *bs; 24 | int** nbrsl; 25 | //int** nbrs_rankl; 26 | int pxels; 27 | int surr_p; 28 | } Luma_Smooth; 29 | 30 | AVS_VideoFrame * AVSC_CC Luma_Smooth_get_frame (AVS_FilterInfo * p, int n) 31 | { 32 | AVS_VideoFrame *src, *dst; 33 | double vr, smo; 34 | int l_sur,surr_pl,wdt,pxls,sxf,dbg,row_size, height, src_pitch,dst_pitch; 35 | BYTE* srcp; 36 | BYTE* dstp; 37 | Luma_Smooth* params = (Luma_Smooth*) p->user_data; 38 | 39 | vr=params->var; 40 | smo=params->smooth; 41 | l_sur=params->surr; 42 | surr_pl=params->surr_p; 43 | dbg=params->debug; 44 | 45 | src = avs_get_frame(p->child, n); 46 | 47 | srcp = avs_get_read_ptr(src); 48 | src_pitch = avs_get_pitch(src); 49 | row_size = avs_get_row_size(src); 50 | height = avs_get_height(src); 51 | 52 | wdt=p->vi.width; 53 | 54 | pxls=params->pxels; 55 | 56 | dst = avs_new_video_frame(p->env, &p->vi); 57 | dst_pitch = avs_get_pitch(dst); 58 | dstp = avs_get_write_ptr(dst); 59 | dst->height=height; 60 | dst->row_size=row_size; 61 | 62 | sxf=params->sixtyFour; 63 | 64 | double *ys=params->ys; 65 | double *out_ys=params->out_ys; 66 | double *rs=params->rs; 67 | double *gs=params->gs; 68 | double *bs=params->bs; 69 | 70 | for (int r = 0; r < params->pxels; ++r) { 71 | memset(params->nbrsl[r],-1,sizeof(params->nbrsl[r][0])*(1+params->surr_p)); 72 | } 73 | 74 | /*for (int r = 0; r < params->pxels; ++r) { 75 | memset(params->nbrs_rankl[r],-1,sizeof(params->nbrs_rankl[r][0])*(1+params->surr_p)); 76 | }*/ 77 | 78 | int** nbrsl=params->nbrsl; 79 | // int** nbrs_rankl=params->nbrs_rankl; 80 | 81 | 82 | 83 | int p_ix=0; 84 | int xarr=0; 85 | 86 | for (int y=0; y=0)&&(i=0)&&(k0){ 158 | variance=s/cnt; 159 | 160 | if(varianceuser_data; 213 | free(params); 214 | } 215 | 216 | AVS_Value AVSC_CC create_Luma_Smooth (AVS_ScriptEnvironment * env, 217 | AVS_Value args, void * dg) 218 | { 219 | AVS_Value v; 220 | AVS_FilterInfo * fi; 221 | AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); 222 | Luma_Smooth *params = (Luma_Smooth*)malloc(sizeof(Luma_Smooth)); 223 | 224 | if (!params) 225 | return avs_void; 226 | 227 | params->surr= avs_defined(avs_array_elt(args, 1))?avs_as_int(avs_array_elt(args, 1)):3; 228 | params->var= avs_defined(avs_array_elt(args, 2))?avs_as_float(avs_array_elt(args, 2)):0.14; 229 | params->smooth= avs_defined(avs_array_elt(args, 3))?avs_as_float(avs_array_elt(args, 3)):0.11; 230 | params->debug= avs_defined(avs_array_elt(args,4))?avs_as_bool(avs_array_elt(args, 4)):false; 231 | 232 | if ((params->surr<1)||(params->surr>MAX(fi->vi.width-1,fi->vi.height-1))) { 233 | return avs_new_value_error ("'surr' must be between 1 and MAX(video_width-1,video_height-1)!"); 234 | } 235 | 236 | if (params->var<0) { 237 | return avs_new_value_error ("'var' must be >=0!"); 238 | } 239 | 240 | if ((params->smooth<0)||(params->smooth>1)) { 241 | return avs_new_value_error ("'smooth' must be between 0 and 1!"); 242 | } 243 | 244 | if (!((avs_is_rgb32(&fi->vi))||(avs_is_rgb64(&fi->vi)))) { 245 | return avs_new_value_error ("Input video must be in RGB32 OR RGB64 format!"); 246 | } else { 247 | 248 | if(avs_defined(avs_array_elt(args, 5))){ 249 | params->sixtyFour =avs_as_bool(avs_array_elt(args, 5)); 250 | }else{ 251 | params->sixtyFour = (avs_is_rgb64(&fi->vi))?true:false; 252 | } 253 | 254 | params->pxels=fi->vi.width*fi->vi.height; 255 | params->surr_p=1+((4* params->surr)*(params->surr+1)); 256 | 257 | params->ys = (double*)malloc( params->pxels* sizeof(double)); 258 | params->out_ys = (double*)malloc( params->pxels* sizeof(double)); 259 | 260 | params->rs = (double*)malloc( params->pxels* sizeof(double)); 261 | params->gs = (double*)malloc( params->pxels* sizeof(double)); 262 | params->bs = (double*)malloc( params->pxels* sizeof(double)); 263 | 264 | params->nbrsl = malloc(params->pxels * sizeof(int*)); // rows 265 | for (int r = 0; r < params->pxels; ++r) { 266 | params->nbrsl[r] = malloc((1+params->surr_p) * sizeof(int)); // columns 267 | memset(params->nbrsl[r],-1,sizeof(params->nbrsl[r][0])*(1+params->surr_p)); 268 | } 269 | 270 | /*params->nbrs_rankl = malloc(params->pxels * sizeof(int*)); // rows 271 | for (int r = 0; r < params->pxels; ++r) { 272 | params->nbrs_rankl[r] = malloc((1+params->surr_p) * sizeof(int)); // columns 273 | memset(params->nbrs_rankl[r],-1,sizeof(params->nbrs_rankl[r][0])*(1+params->surr_p)); 274 | }*/ 275 | 276 | fi->user_data = (void*) params; 277 | 278 | fi->get_frame = Luma_Smooth_get_frame; 279 | 280 | v = avs_new_value_clip(new_clip); 281 | fi->free_filter = free_Luma_Smooth; 282 | 283 | avs_release_clip(new_clip); 284 | return v; 285 | } 286 | } 287 | 288 | const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env) 289 | { 290 | avs_add_function(env, "Luma_Smooth", "c[surr]i[var]f[smooth]f[debug]b[sixtyFour]b", create_Luma_Smooth, 0); 291 | return "Luma_Smooth C plugin"; 292 | } 293 | 294 | -------------------------------------------------------------------------------- /C_Manual_WP_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Manual_WP_x64.dll -------------------------------------------------------------------------------- /C_RGB_Dither_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_RGB_Dither_x64.dll -------------------------------------------------------------------------------- /C_RGB_Dither_x64/Function_definition.txt: -------------------------------------------------------------------------------- 1 | ( 2 | clip clip, 3 | float "sdv"=1.8, 4 | float "dark"=0.5 (0 to 1 by 0.0001), 5 | ) 6 | -------------------------------------------------------------------------------- /C_RGB_Dither_x64/functions_c.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 4 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 5 | #define lerp(a,b,t) ((1 - (t)) * (a) + (t) * (b) ) 6 | #define rcptwoFiveFive 1.0/255.0 7 | #define rcptHiBit 1.0/65535.0 8 | #define root_twelve 3.464101615137755 9 | 10 | uint64_t sconst[] = { 11 | 0xcaf32e182df87139, 12 | 0x2f768dac7bd5142f, 13 | 0xf5cb7923ed83419b, 14 | 0xbd8a2796d321864b, 15 | 0xe8cfb5a916bc4a93, 16 | 0xe4f5acd7c748df31, 17 | 0xe1fa45cbd78e9ba5, 18 | 0xbfa95c43b8642c7d, 19 | 0x371b825a76b93e5d, 20 | 0xd81ea45f719b48c3, 21 | 0x4f1e86c36123b57d, 22 | 0x9b876df18d45c6ef, 23 | 0x178fa56d4bca6217, 24 | 0xc3718fd4873a64b5, 25 | 0x1af8d6e51ad649b7, 26 | 0x28b71edacfd5a671, 27 | 0xfae7cd4154c689d1, 28 | 0xbdf6248a6bc872a5, 29 | 0xa137f8d63457e921, 30 | 0x125e7f3a69ecb5a3, 31 | 0xb12e3857687cd5a9, 32 | 0xb53427cd4295ebd7, 33 | 0xf765bead7241aecb, 34 | 0x819a34fc27e4c153, 35 | 0xca652d1f4f65b183, 36 | 0xca6d73b9c6b15e29, 37 | 0xfa29b7134fbd8713, 38 | 0xf5ba18e9f8712dc5, 39 | 0x4921df75f2e4ba3d, 40 | 0x2c5f4e8b274ed1a9 41 | }; 42 | 43 | 44 | inline static uint32_t mswsi(uint64_t xi, uint64_t wi, uint64_t si) { 45 | 46 | xi *= xi; xi += (wi += si); 47 | return xi = (xi>>32) | (xi<<32); 48 | 49 | } 50 | 51 | inline static uint64_t init_rand_digits(uint64_t n) { 52 | 53 | uint64_t c, i, j, k, m, r, t, u, v, xi, wi, si; 54 | 55 | /* initialize state for local msws rng */ 56 | 57 | r = n / 100000000; 58 | t = n % 100000000; 59 | si = sconst[r%30]; 60 | r /= 30; 61 | xi = wi = t*si + r*si*100000000; 62 | 63 | /* get odd random number for low order digit */ 64 | 65 | u = (mswsi(xi, wi, si) % 8) * 2 + 1; v = (1<0;) { 70 | j = mswsi(xi, wi, si); /* get 8 digit 32-bit random word */ 71 | for (i=0;i<32;i+=4) { 72 | k = (j>>i) & 0xf; /* get a digit */ 73 | if (k!=0 && (c & (1<> 32) | (x1 << 32); 90 | x2 *= x2; x2 += (w2 += s2); x2 = (x2 >> 32) | (x2 << 32); 91 | return (xx ^ x2)>>11; 92 | } 93 | 94 | //Source: Middle Square Weyl Sequence RNG - Bernard Widynski1 95 | 96 | inline double grey_dither(double colour, double rand,double sdv, int sxf){ 97 | 98 | double sAB=sdv*root_twelve*0.5; 99 | double randm=sAB*(2*rand-1)*-1; 100 | double out=(sdv!=0)?colour+(randm*( (sxf==1)?rcptHiBit:rcptwoFiveFive) ):colour; 101 | 102 | return out; 103 | 104 | } 105 | 106 | double logisticMap(double rand){ 107 | double rMap =3.98; 108 | double randOld=rand; 109 | 110 | randOld=rMap*randOld*(1-randOld); 111 | randOld=rMap*randOld*(1-randOld); 112 | randOld=rMap*randOld*(1-randOld); 113 | randOld=12050*randOld+0.597*randOld; 114 | 115 | return randOld - floor(randOld); 116 | } 117 | -------------------------------------------------------------------------------- /C_RGB_Dither_x64/rgb_dither.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "..\avisynth_c.h" 5 | #include "functions_c.h" 6 | 7 | typedef struct RGB_Dither { 8 | double sdv; 9 | double dark; 10 | int sixtyFour; 11 | } RGB_Dither; 12 | 13 | AVS_VideoFrame * AVSC_CC RGB_Dither_get_frame (AVS_FilterInfo * p, int n) 14 | { 15 | AVS_VideoFrame * src; 16 | RGB_Dither* params = (RGB_Dither*) p->user_data; 17 | 18 | src = avs_get_frame(p->child, n); 19 | 20 | int row_size, height, src_pitch,x, y,sxf; 21 | BYTE* srcp; 22 | 23 | double sddev=params->sdv; 24 | double drk=params->dark; 25 | sxf=params->sixtyFour; 26 | 27 | avs_make_writable(p->env, &src); 28 | 29 | srcp = avs_get_write_ptr(src); 30 | src_pitch = avs_get_pitch(src); 31 | row_size = avs_get_row_size(src); 32 | height = avs_get_height(src); 33 | 34 | ///////////////ACTUALLY DRAW PIXELS/////////////////////////////////////// 35 | for (y=0; yvi.num_frames+1)*(y+1)*(row_size+1))*(mn+1); 60 | 61 | uint64_t r1=msws53(x1, w1, s1, x2, w2, s2); 62 | 63 | uint64_t f_nm=p->vi.fps_numerator; 64 | f_nm=(f_nm>1)?f_nm:1; 65 | 66 | uint64_t f_dnm=p->vi.fps_denominator; 67 | f_dnm=(f_dnm>1)?f_dnm:1; 68 | 69 | s1 =((f_nm)*(x+1)*(row_size+1))*(rgb_prod+1)*(n+1); 70 | s2=((f_dnm)*(y+1)*(height+1))*(rgb_sum+1)*(n+1); 71 | 72 | uint64_t r2=msws53(x1, w1, s1, x2, w2, s2); 73 | 74 | int xp; 75 | double r12 =(double)( (frexp (r1*r2 , &xp)-0.5)*2); 76 | 77 | r12=logisticMap(r12); 78 | 79 | double dth=grey_dither(mx_d,r12,sddev,sxf); 80 | 81 | R=(mx_d==0)?dth:dth*(R/mx_d); 82 | G=(mx_d==0)?dth:dth*(G/mx_d); 83 | B=(mx_d==0)?dth:dth*(B/mx_d); 84 | 85 | R=lerp(R,lerp(R,rOG,mx_d),drk); 86 | G=lerp(G,lerp(G,gOG,mx_d),drk); 87 | B=lerp(B,lerp(B,bOG,mx_d),drk); 88 | 89 | int wp_b=MAX(MIN(round(B*255),255),0); 90 | int wp_g=MAX(MIN(round(G*255),255),0); 91 | int wp_r=MAX(MIN(round(R*255),255),0); 92 | 93 | srcp[x] =wp_b; //blue : blue 94 | srcp[x+1] =(sxf==1)?wp_b:wp_g; // blue : green 95 | srcp[x+2] =(sxf==1)? wp_g:wp_r; // green: red 96 | srcp[x+3] =(sxf==1)? wp_g:srcp[x+3]; //green : self 97 | srcp[x+4] =(sxf==1)? wp_r:srcp[x+4]; //red : self 98 | srcp[x+5] =(sxf==1)? wp_r:srcp[x+5]; //red : self 99 | 100 | x=(sxf==1)?x+7:x+3; 101 | 102 | } 103 | srcp += src_pitch; 104 | } 105 | 106 | return src; 107 | } 108 | 109 | void AVSC_CC free_RGB_Dither(AVS_FilterInfo* fi) 110 | { 111 | RGB_Dither* params = (RGB_Dither*) fi->user_data; 112 | free(params); 113 | } 114 | 115 | AVS_Value AVSC_CC create_RGB_Dither (AVS_ScriptEnvironment * env,AVS_Value args, void * dg) 116 | { 117 | AVS_Value v; 118 | AVS_FilterInfo * fi; 119 | AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); 120 | RGB_Dither *params = (RGB_Dither*)malloc(sizeof(RGB_Dither)); 121 | 122 | if (!params) 123 | return avs_void; 124 | 125 | params->sdv= avs_defined(avs_array_elt(args, 1))?avs_as_float(avs_array_elt(args, 1)):1.8; 126 | params->dark= avs_defined(avs_array_elt(args, 2))?avs_as_float(avs_array_elt(args, 2)):0.5; 127 | 128 | if (!((avs_is_rgb32(&fi->vi))||(avs_is_rgb64(&fi->vi)))) { 129 | return avs_new_value_error ("Input video must be in RGB32 OR RGB64 format!"); 130 | } else if(params->sdv<0){ 131 | return avs_new_value_error ("sdv must be >0!"); 132 | } else if(params->dark<0 || params->dark>1){ 133 | return avs_new_value_error ("dark must be between 0 and 1!"); 134 | }else { 135 | 136 | if(avs_defined(avs_array_elt(args, 3))){ 137 | params->sixtyFour =avs_as_bool(avs_array_elt(args, 3)); 138 | }else{ 139 | params->sixtyFour = (avs_is_rgb64(&fi->vi))?true:false; 140 | } 141 | fi->user_data = (void*) params; 142 | fi->get_frame = RGB_Dither_get_frame; 143 | v = avs_new_value_clip(new_clip); 144 | fi->free_filter = free_RGB_Dither; 145 | } 146 | avs_release_clip(new_clip); 147 | return v; 148 | } 149 | 150 | const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env) 151 | { 152 | avs_add_function(env, "RGB_Dither", "c[sdv]f[dark]f[sixtyFour]b", create_RGB_Dither, 0); 153 | return "RGB_Dither C plugin"; 154 | } 155 | -------------------------------------------------------------------------------- /C_Saturation_percentiles_x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/C_Saturation_percentiles_x64.dll -------------------------------------------------------------------------------- /C_Saturation_percentiles_x64/Function definition.txt: -------------------------------------------------------------------------------- 1 | ( 2 | clip clip, 3 | float "perc"=1.000 (0 to 1), 4 | int "out"= 0 (0 to 2), 5 | int "col"= 0 (0 to 2), 6 | bool "below"=true, 7 | bool "sixtyFour"=false 8 | ) 9 | -------------------------------------------------------------------------------- /C_Saturation_percentiles_x64/functions_c.h: -------------------------------------------------------------------------------- 1 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 2 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 3 | #define lerp(a,b,t) ((1 - (t)) * (a) + (t) * (b) ) 4 | #define rcptwoFiveFive 1.0/255.0 5 | #define rcptHiBit 1.0/65535.0 6 | 7 | int compare (const void * a, const void * b) 8 | { 9 | return (*(double*)a > *(double*)b) ? 1 : (*(double*)a < *(double*)b) ? -1:0; 10 | } 11 | -------------------------------------------------------------------------------- /C_Saturation_percentiles_x64/saturation_percentiles.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "..\avisynth_c.h" 5 | #include "functions_c.h" 6 | 7 | typedef struct Saturation_Percentiles { 8 | int below; 9 | int out; 10 | int sixtyFour; 11 | int pxels; 12 | double *sats; 13 | double *satsOG; 14 | int refEl_lo; 15 | int refEl_hi; 16 | double refEl_lerp; 17 | int refEl; 18 | int gOut; 19 | } Saturation_Percentiles; 20 | 21 | AVS_VideoFrame * AVSC_CC Saturation_Percentiles_get_frame (AVS_FilterInfo * p, int n) 22 | { 23 | AVS_VideoFrame * src; 24 | Saturation_Percentiles* params = (Saturation_Percentiles*) p->user_data; 25 | 26 | src = avs_get_frame(p->child, n); 27 | 28 | int row_size, height, src_pitch,x, y,sxf,blw,gOt; 29 | long pxls; 30 | const BYTE* rrcp; 31 | BYTE* srcp; 32 | double bOG,gOG,rOG,ot; 33 | 34 | sxf=params->sixtyFour; 35 | blw=params->below; 36 | ot=params->out; 37 | gOt=params->gOut; 38 | 39 | 40 | avs_make_writable(p->env, &src); 41 | 42 | srcp = avs_get_write_ptr(src); 43 | rrcp = avs_get_read_ptr(src); 44 | src_pitch = avs_get_pitch(src); 45 | row_size = avs_get_row_size(src); 46 | height = avs_get_height(src); 47 | 48 | long k=0; 49 | pxls=params->pxels; 50 | double* sats=params->sats; 51 | double* satsOG=params->satsOG; 52 | for (y=0; ysat, 1->chr, 2->mcs 72 | 73 | if(ot!=1){ // sat || mcs 74 | sat=(mx==0)?0:(chr)/mx; 75 | 76 | if(ot==2){ //mcs 77 | mtr=MIN(sat,chr); 78 | }else{ //sat 79 | mtr=sat; 80 | } 81 | 82 | } 83 | 84 | 85 | sats[k]=mtr; 86 | satsOG[k]=mtr; 87 | 88 | k++; 89 | x=(sxf==1)?x+7:x+3; 90 | } 91 | rrcp += src_pitch; 92 | } 93 | 94 | qsort(sats, pxls, sizeof(double), compare); 95 | double refSat=(params->refEl!=-1)?sats[params->refEl]:lerp(sats[params->refEl_lo],sats[params->refEl_hi],params->refEl_lerp); 96 | 97 | k=0; 98 | 99 | ///////////////ACTUALLY DRAW PIXELS/////////////////////////////////////// 100 | for (y=0; yrefSat){ 105 | srcp[x] =gOt; //blue : blue 106 | srcp[x+1] =(sxf==1)?gOt:gOt; // blue : green 107 | srcp[x+2] =(sxf==1)? gOt:gOt; // green: red 108 | srcp[x+3] =(sxf==1)? gOt:srcp[x+3]; //green : self 109 | srcp[x+4] =(sxf==1)? gOt:srcp[x+4]; //red : self 110 | srcp[x+5] =(sxf==1)? gOt:srcp[x+5]; //red : self 111 | } 112 | }else{ 113 | if(satsOG[k]user_data; 138 | free(params); 139 | } 140 | 141 | AVS_Value AVSC_CC create_Saturation_Percentiles (AVS_ScriptEnvironment * env,AVS_Value args, void * dg) 142 | { 143 | AVS_Value v; 144 | AVS_FilterInfo * fi; 145 | AVS_Clip * new_clip = avs_new_c_filter(env, &fi, avs_array_elt(args, 0), 1); 146 | Saturation_Percentiles *params = (Saturation_Percentiles*)malloc(sizeof(Saturation_Percentiles)); 147 | 148 | if (!params) 149 | return avs_void; 150 | 151 | double perc= avs_defined(avs_array_elt(args, 1))?avs_as_float(avs_array_elt(args, 1)):1; 152 | params->below= avs_defined(avs_array_elt(args, 2))?avs_as_bool(avs_array_elt(args, 2)):true; 153 | params->out= avs_defined(avs_array_elt(args, 3))?avs_as_int(avs_array_elt(args, 3)):0; 154 | int col= avs_defined(avs_array_elt(args, 4))?avs_as_int(avs_array_elt(args, 4)):0; 155 | 156 | double gOtD; 157 | 158 | switch(col){ 159 | case 1: 160 | gOtD=0.5; 161 | break; 162 | 163 | case 2: 164 | gOtD=1; 165 | break; 166 | 167 | default: 168 | gOtD=0; 169 | break; 170 | } 171 | 172 | if (!((avs_is_rgb32(&fi->vi))||(avs_is_rgb64(&fi->vi)))) { 173 | return avs_new_value_error ("Input video must be in RGB32 OR RGB64 format!"); 174 | }else if (params->out<0 || params->out>2) { 175 | return avs_new_value_error ("\"out\" must be between 0 and 2!"); 176 | }else if (col<0 || col>2) { 177 | return avs_new_value_error ("\"col\" must be between 0 and 2!"); 178 | } else { 179 | 180 | if(avs_defined(avs_array_elt(args, 5))){ 181 | params->sixtyFour =avs_as_bool(avs_array_elt(args, 5)); 182 | }else{ 183 | params->sixtyFour = (avs_is_rgb64(&fi->vi))?true:false; 184 | } 185 | params->gOut=round(gOtD*255); 186 | params->pxels=fi->vi.height*fi->vi.width; 187 | double d_pxels=(double)params->pxels; 188 | if(params->pxels==1){ 189 | params->refEl=1; 190 | }else{ 191 | double refEl_d=((d_pxels+1)*perc)-1; 192 | params->refEl_lo=floor(refEl_d); 193 | params->refEl_hi=ceil(refEl_d); 194 | params->refEl_lerp=refEl_d-floor(refEl_d); 195 | params->refEl=(params->refEl_lo==params->refEl_hi)?params->refEl_lo:-1; 196 | } 197 | 198 | params->sats = (double*)malloc( params->pxels* sizeof(double)); 199 | params->satsOG = (double*)malloc( params->pxels* sizeof(double)); 200 | 201 | fi->user_data = (void*) params; 202 | fi->get_frame = Saturation_Percentiles_get_frame; 203 | v = avs_new_value_clip(new_clip); 204 | fi->free_filter = free_Saturation_Percentiles; 205 | } 206 | avs_release_clip(new_clip); 207 | return v; 208 | } 209 | 210 | const char * AVSC_CC avisynth_c_plugin_init(AVS_ScriptEnvironment * env) 211 | { 212 | avs_add_function(env, "Saturation_Percentiles", "c[perc]f[below]b[out]i[col]i[sixtyFour]b", create_Saturation_Percentiles, 0); 213 | return "Saturation_Percentiles C plugin"; 214 | } 215 | -------------------------------------------------------------------------------- /Colour space XYZ.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crabshank/Avisynth-filters/95767900e78110ccc9e16ca4174fbebe193e1224/Colour space XYZ.xlsx -------------------------------------------------------------------------------- /Helper files/Iframe list gen.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 |
20 | 21 |
22 |
23 | 24 | 25 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Helper files/WP brace change generator.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 18 |

WP brace change generator

19 | 20 |

24 | Paste brace changes here: 25 |

26 | Paste braces here: 27 |
28 |

29 |
30 | 243 | 244 | -------------------------------------------------------------------------------- /Helper files/WP frames list gen.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 |

WP brace start frames list generator

13 | Enter WP braces here: 14 | 15 |
16 |
17 |
18 | 19 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Helper files/WP_brace_RGB_gamma_conv.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 |

WP brace RGB gamma converter

12 | 13 | 14 |     Max RGB value: 15 |
16 | 17 | 198 | 199 | -------------------------------------------------------------------------------- /Helper files/WP_edits fix.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 |

WP edits fixer

12 | 14 | 62 | 63 | -------------------------------------------------------------------------------- /Helper files/backup_style.dat: -------------------------------------------------------------------------------- 1 | (dp1 2 | S'textstyles' 3 | p2 4 | (dp3 5 | S'comment' 6 | p4 7 | Vface:Gentium Book Basic,size:24,fore:#586e75,back:#002b36,bold 8 | p5 9 | sS'sliderwindowtextctrl' 10 | p6 11 | S'fore:#EBEBEB,back:#353535' 12 | p7 13 | sS'badbrace' 14 | p8 15 | Vface:Verdana,size:10,fore:#dc322f,back:#002b36,bold 16 | p9 17 | sS'highlightline' 18 | p10 19 | S'back:#280132' 20 | p11 21 | sS'calltiphighlight' 22 | p12 23 | S'fore:#c1c5bb' 24 | p13 25 | sS'scrapwindow' 26 | p14 27 | Vface:Courier New,size:10,fore:#93a1a1,back:#073642 28 | p15 29 | sS'number' 30 | p16 31 | Vface:Microsoft JhengHei,size:16,fore:#2aa198,back:#002b36,bold,italic 32 | p17 33 | sS'endcomment' 34 | p18 35 | Vface:Verdana,size:10,fore:#586e75,back:#002b36 36 | p19 37 | sS'stringtriple' 38 | p20 39 | Vface:Verdana,size:16,fore:#2aa198,back:#002b36 40 | p21 41 | sS'operator' 42 | p22 43 | Vface:Verdana,size:10,fore:#987c9c,back:#002b36,bold 44 | p23 45 | sS'sliderwindowdefvalue' 46 | p24 47 | S'fore:#FFFD37,bold' 48 | p25 49 | sS'badnumber' 50 | p26 51 | Vface:Courier New,size:10,fore:#dc322f,back:#002b36 52 | p27 53 | sS'stringeol' 54 | p28 55 | Vface:Microsoft JhengHei,size:10,fore:#2aa198,back:#073642 56 | p29 57 | sS'blockcomment' 58 | p30 59 | Vface:Georgia,size:14,fore:#586e75,back:#002b36 60 | p31 61 | sS'userdefined' 62 | p32 63 | Vface:Verdana,size:10,fore:#b58900,back:#002b36,bold 64 | p33 65 | sS'clipproperty' 66 | p34 67 | Vface:Verdana,size:10,fore:#268bd2,back:#002b36,bold 68 | p35 69 | sS'sliderwindowbackslider' 70 | p36 71 | S'back:#2b2b2b' 72 | p37 73 | sS'parameter' 74 | p38 75 | Vface:Verdana,size:18,fore:#586e75,back:#002b36 76 | p39 77 | sS'string' 78 | p40 79 | Vface:Microsoft Sans Serif,size:16,fore:#ec3f0d,back:#002b36,bold 80 | p41 81 | sS'internalfunction' 82 | p42 83 | Vface:Verdana,size:10,fore:#268bd2,back:#002b36,bold 84 | p43 85 | sS'assignment' 86 | p44 87 | Vface:MS Reference Sans Serif,size:18,fore:#2a97a2,back:#002b36,bold 88 | p45 89 | sS'bracelight' 90 | p46 91 | Vface:Verdana,size:10,fore:#859900,back:#002b36,bold 92 | p47 93 | sS'sliderwindow' 94 | p48 95 | S'fore:#E4DEDA,back:#2B2B2B' 96 | p49 97 | sS'unknownfunction' 98 | p50 99 | Vface:Verdana,size:10,fore:#dc322f,back:#002b36,bold 100 | p51 101 | sS'userslider' 102 | p52 103 | Vface:Verdana,size:10,fore:#859900,back:#002b36 104 | p53 105 | sS'sliderwindowextrabtn1' 106 | p54 107 | S'fore:#ADB7A4' 108 | p55 109 | sS'miscword' 110 | p56 111 | Vface:Verdana,size:10,fore:#859900,back:#002b36,bold 112 | p57 113 | sS'externalfilter' 114 | p58 115 | Vface:Verdana,size:10,fore:#d33682,back:#002b36,bold 116 | p59 117 | sS'keyword' 118 | p60 119 | Vface:Verdana,size:14,fore:#859900,back:#002b36,bold 120 | p61 121 | sS'default' 122 | p62 123 | Vface:Microsoft PhagsPa,size:14,fore:#839496,back:#002b36 124 | p63 125 | sS'foldmargin' 126 | p64 127 | S'fore:#586e75,back:#073642' 128 | p65 129 | sS'monospaced' 130 | p66 131 | Vface:Microsoft JhengHei,size:14,bold 132 | p67 133 | sS'comment2' 134 | p68 135 | S'face:Verdana,size:8,fore:#000000,back:#FFFFFF' 136 | p69 137 | sS'cursor' 138 | p70 139 | S'fore:#c1c5bb' 140 | p71 141 | sS'datatype' 142 | p72 143 | Vface:Verdana,size:14,fore:#859900,back:#002b36 144 | p73 145 | sS'linenumber' 146 | p74 147 | Vface:Segoe UI,size:12,fore:#586e75,back:#073642,bold 148 | p75 149 | sS'calltip' 150 | p76 151 | S'fore:#839496,back:#073642' 152 | p77 153 | sS'highlight' 154 | p78 155 | S'fore:#c1c5bb,back:#2f525b' 156 | p79 157 | sS'internalfilter' 158 | p80 159 | Vface:Microsoft JhengHei,size:10,fore:#6c71c4,back:#002b36,bold 160 | p81 161 | ssS'version' 162 | p82 163 | S'2.6.9.6' 164 | p83 165 | sS'colourdata' 166 | p84 167 | V1,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000,#000000 168 | p85 169 | s. -------------------------------------------------------------------------------- /Manual WP/Function definition.txt: -------------------------------------------------------------------------------- 1 | ( 2 | clip clip, 3 | float "x"=0.312727 (0 to 1 by 0.0001), 4 | float "y"=0.329023 (0 to 1 by 0.0001), 5 | int "R"=-1, 6 | int "G"=-1, 7 | int "B"=-1, 8 | int "mode"=0 (0 to 12 by 1), 9 | int "debug"=0 (0 to 9 by 1), 10 | float "debug_val"=1 (0 to 1 by 0.001), 11 | float "debug_val2"=1 (0 to 1 by 0.001), 12 | bool "sixtyFour" = false, 13 | float "dst_x"=0.312727 (0 to 1 by 0.0001), 14 | float "dst_y"=0.329023 (0 to 1 by 0.0001), 15 | bool "auto_WP" = false, 16 | string "file"="", 17 | string "log_id"="", 18 | bool "overwrite" = false, 19 | bool "linear" = false, 20 | string "edits"="", 21 | int "ed_off"=0, 22 | int "ed_base"=-1, 23 | bool "approxPow" = true, 24 | string "bb"="", 25 | string "bb2"="", 26 | int "bb_off"=0, 27 | int "bb_base"=-1 28 | ) 29 | -------------------------------------------------------------------------------- /Manual WP/functions_c.h: -------------------------------------------------------------------------------- 1 | #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 2 | #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 3 | #define lerp(a,b,t) ((1 - (t)) * (a) + (t) * (b) ) 4 | 5 | void RGB_prp(double rgb[3], double rgb_prp[3]) 6 | { 7 | double rgbSum=rgb[0]+rgb[1]+rgb[2]; 8 | 9 | rgb_prp[0]=(rgbSum==0)?third:rgb[0]/rgbSum; 10 | rgb_prp[1]=(rgbSum==0)?third:rgb[1]/rgbSum; 11 | rgb_prp[2]=(rgbSum==0)?third:rgb[2]/rgbSum; 12 | } 13 | 14 | double rgb2hue_360(double rgb[3]) 15 | { 16 | double r=rgb[0]; 17 | double g=rgb[1]; 18 | double b=rgb[2]; 19 | 20 | double mn=MIN(r,MIN(g,b)); 21 | double mx=MAX(r,MAX(g,b)); 22 | double chr=mx-mn; 23 | double hue_d=0; 24 | 25 | if (chr!=0){ 26 | if ((r>=g)&&(r>=b)){ 27 | hue_d =(g - b) / chr; 28 | }else if ((g>=r)&&(g>=b)){ 29 | hue_d = 2.0 + (b - r) / chr; 30 | }else{ 31 | hue_d = 4.0 + (r - g) / chr; 32 | } 33 | hue_d=(hue_d==6)?0:hue_d; 34 | hue_d*=60; 35 | hue_d =(hue_d < 0)?hue_d + 360:hue_d; 36 | } 37 | return hue_d; 38 | 39 | } 40 | 41 | void rgb2hsvc_360 (double rgb[3],double hsvc[4]) 42 | { 43 | double r=rgb[0]; 44 | double g=rgb[1]; 45 | double b=rgb[2]; 46 | 47 | double mn=MIN(r,MIN(g,b)); 48 | double mx=MAX(r,MAX(g,b)); 49 | double chr=mx-mn; 50 | double sat=(mx==0)?0:chr/mx; 51 | double hue_d=0; 52 | 53 | if (chr!=0){ 54 | if ((r>=g)&&(r>=b)){ 55 | hue_d =(g - b) / chr; 56 | }else if ((g>=r)&&(g>=b)){ 57 | hue_d = 2.0 + (b - r) / chr; 58 | }else{ 59 | hue_d = 4.0 + (r - g) / chr; 60 | } 61 | hue_d=(hue_d==6)?0:hue_d; 62 | hue_d*=60; 63 | hue_d =(hue_d < 0)?hue_d + 360:hue_d; 64 | } 65 | 66 | hsvc[0]=hue_d; 67 | hsvc[1]=sat; 68 | hsvc[2]=mx; 69 | hsvc[3]=chr; 70 | } 71 | 72 | void hsv2rgb_360(double hsv[3], double rgb[3]) 73 | { 74 | double h=hsv[0]/360.0; 75 | double s=hsv[1]; 76 | double v=hsv[2]; 77 | 78 | int i = floor(h * 6); 79 | double f = h * 6 - i; 80 | double p = v * (1 - s); 81 | double q = v * (1 - f * s); 82 | double t = v * (1 - (1 - f) * s); 83 | switch (i % 6) { 84 | case 0: rgb[0] = v, rgb[1] = t, rgb[2] = p; break; 85 | case 1: rgb[0] = q, rgb[1] = v, rgb[2] = p; break; 86 | case 2: rgb[0] = p, rgb[1] = v, rgb[2] = t; break; 87 | case 3: rgb[0] = p, rgb[1] = q, rgb[2] = v; break; 88 | case 4: rgb[0] = t, rgb[1] = p, rgb[2] = v; break; 89 | case 5: rgb[0] = v, rgb[1] = p, rgb[2] = q; break; 90 | } 91 | } 92 | 93 | void hsvc2rgb_360(double hsvc[4], double rgb[3]) 94 | { 95 | double hsv[3]={hsvc[0], hsvc[1], hsvc[2]}; 96 | hsv2rgb_360(hsv, rgb); 97 | } 98 | 99 | void debug_1(double rgb[3], double rgb_out[3], double amp,int aprxPw) 100 | { 101 | double mx=MAX(rgb[0],MAX(rgb[1],rgb[2])); 102 | double sat=(mx==0)?0:(mx-MIN(rgb[0],MIN(rgb[1],rgb[2])))/mx; 103 | 104 | double dbg_out; 105 | if(aprxPw==1){ 106 | dbg_out=(amp==1)?sat:fastPrecisePow(sat,amp); 107 | }else{ 108 | dbg_out=(amp==1)?sat:pow(sat,amp); 109 | } 110 | 111 | rgb_out[0]=dbg_out; 112 | rgb_out[1]=dbg_out; 113 | rgb_out[2]=dbg_out; 114 | } 115 | 116 | void debug_2_8(double rgb[3], double rgb_out[3], double amp, int dbg) 117 | { 118 | double mx=MAX(rgb[0],MAX(rgb[1],rgb[2])); 119 | double sat=(mx==0)?0:(mx-MIN(rgb[0],MIN(rgb[1],rgb[2])))/mx; 120 | 121 | rgb_out[0]=(sat>=amp)?rgb[0]:((dbg==8)?0.5:0); 122 | rgb_out[1]=(sat>=amp)?rgb[1]:((dbg==8)?0.5:0); 123 | rgb_out[2]=(sat>=amp)?rgb[2]:((dbg==8)?0.5:0); 124 | } 125 | 126 | void debug_2(double rgb[3], double rgb_out[3], double amp) 127 | { 128 | debug_2_8(rgb, rgb_out, amp, 2); 129 | } 130 | 131 | void debug_8(double rgb[3], double rgb_out[3], double amp) 132 | { 133 | debug_2_8(rgb, rgb_out, amp, 8); 134 | } 135 | 136 | void debug_3(double rgb[3], double rgb_out[3], double amp, double rOG, double gOG, double bOG) 137 | { 138 | double mx=MAX(rgb[0],MAX(rgb[1],rgb[2])); 139 | double sat=(mx==0)?0:(mx-MIN(rgb[0],MIN(rgb[1],rgb[2])))/mx; 140 | 141 | double mxOG=MAX(rOG,MAX(gOG,bOG)); 142 | double satOG=(mxOG==0)?0:(mxOG-MIN(rOG,MIN(gOG,bOG)))/mxOG; 143 | satOG=(amp>=0)?satOG*(1-amp):satOG; 144 | rgb_out[0]=(sat>=satOG)?rgb[0]:0; 145 | rgb_out[1]=(sat>=satOG)?rgb[1]:0; 146 | rgb_out[2]=(sat>=satOG)?rgb[2]:0; 147 | } 148 | 149 | void debug_4(double rgb[3], double rOG, double gOG, double bOG, double rgb_out[3], double amp) 150 | { 151 | double mx=MAX(rgb[0],MAX(rgb[1],rgb[2])); 152 | double sat=(mx==0)?0:(mx-MIN(rgb[0],MIN(rgb[1],rgb[2])))/mx; 153 | 154 | double mxOG=MAX(rOG,MAX(gOG,bOG)); 155 | double satOG=(mxOG==0)?0:(mxOG-MIN(rOG,MIN(gOG,bOG)))/mxOG; 156 | 157 | double hue_dbg=120; 158 | 159 | double abs_satDiff=(satOG==0)?fabs(satOG-sat):fabs(satOG-sat)/satOG; 160 | double satDiff1=(satOG==0)?satOG-sat:fabs(satOG-sat)/satOG; 161 | satDiff1=satDiff1*satDiff1; 162 | double satDiff2=(satOG==1)?sat-satOG:(sat-satOG)/(1-satOG); 163 | satDiff2=satDiff2*satDiff2; 164 | 165 | hue_dbg=(satsatOG)?lerp(307.5,367.5,satDiff2):hue_dbg; //Sat increased, Magenta to Orange 167 | hue_dbg=(hue_dbg==360)?0:hue_dbg; 168 | hue_dbg=(hue_dbg>360)?hue_dbg-360:hue_dbg; 169 | double hsv_dbg[3]={hue_dbg,1,lerp(0.3*(1-amp),1-amp,abs_satDiff)}; 170 | hsv2rgb_360(hsv_dbg,rgb_out); 171 | } 172 | 173 | void debug_5(double rgb_out[3],int x, int row_size, double rOG, double gOG, double bOG, int fv_swt) 174 | { 175 | double x_shift=(double)(x)/(double)(row_size); 176 | 177 | if(fv_swt==1){ 178 | rgb_out[0]=(x_shift<0.5)?rOG:bOG; 179 | rgb_out[1]=(x_shift<0.5)?rOG:bOG; 180 | rgb_out[2]=(x_shift<0.5)?rOG:bOG; 181 | }else if(fv_swt==2){ 182 | rgb_out[0]=rOG; 183 | rgb_out[1]=gOG; 184 | rgb_out[2]=bOG; 185 | 186 | } 187 | } 188 | 189 | void debug_6(double rgb[3], double rgb_out[3], double rgbs_dbg_six[4], double amp, double rOG, double gOG, double bOG) 190 | { 191 | double mx=MAX(rgb[0],MAX(rgb[1],rgb[2])); 192 | double sat=(mx==0)?0:(mx-MIN(rgb[0],MIN(rgb[1],rgb[2])))/mx; 193 | double OGmx=MAX(rOG,MAX(gOG,bOG)); 194 | double OGsat=(mx==0)?0:(OGmx-MIN(rOG,MIN(gOG,bOG)))/OGmx; 195 | double redu=OGsat-sat; 196 | if((redu>rgbs_dbg_six[3])&&(sat<=amp)){ 197 | rgbs_dbg_six[0]=rOG; 198 | rgbs_dbg_six[1]=gOG; 199 | rgbs_dbg_six[2]=bOG; 200 | rgbs_dbg_six[3]=redu; 201 | } 202 | rgb_out[0]=(sat<=amp)?rOG:0; 203 | rgb_out[1]=(sat<=amp)?gOG:0; 204 | rgb_out[2]=(sat<=amp)?bOG:0; 205 | } 206 | 207 | void debug_7(double rgb[3], double rgb_out[3], double amp) 208 | { 209 | 210 | int grey=((rgb[0]==rgb[1])&&(rgb[1]==rgb[2]))?1:0; 211 | 212 | if (grey==0){ 213 | 214 | double dbgHSV[3]; 215 | dbgHSV[1]=1.0; 216 | dbgHSV[2]=1-amp; 217 | 218 | double dbgRGB[3]; 219 | 220 | double hue_d=rgb2hue_360(rgb); 221 | int hue=floor(hue_d*10); 222 | 223 | if((hue>=3525)||(((hue>=0) && (hue<75)))){ 224 | dbgHSV[0]=0.0; 225 | }else if((hue>=75) && (hue<375)){ 226 | dbgHSV[0]=30.0; 227 | }else if((hue>=375) && (hue<675)){ 228 | dbgHSV[0]=60.0; 229 | }else if((hue>=675) && (hue<975)){ 230 | dbgHSV[0]=90.0; 231 | }else if((hue>=975) && (hue<1275)){ 232 | dbgHSV[0]=120.0; 233 | }else if((hue>=1275) && (hue<1575)){ 234 | dbgHSV[0]=150.0; 235 | }else if((hue>=1575) && (hue<1875)){ 236 | dbgHSV[0]=180.0; 237 | }else if((hue>=1875) && (hue<2175)){ 238 | dbgHSV[0]=210.0; 239 | }else if((hue>=2175) && (hue<2475)){ 240 | dbgHSV[0]=240.0; 241 | }else if((hue>=2475) && (hue<3075)){ 242 | dbgHSV[0]=270.0; 243 | }else if((hue>=3075) && (hue<3375)){ 244 | dbgHSV[0]=330.0; 245 | dbgHSV[1]=0.8; 246 | }else if((hue>=3375) && (hue<3525)){ 247 | dbgHSV[0]=345.0; 248 | dbgHSV[1]=0.95; 249 | } 250 | 251 | hsv2rgb_360(dbgHSV, dbgRGB); 252 | rgb_out[0]=dbgRGB[0]; 253 | rgb_out[1]=dbgRGB[1]; 254 | rgb_out[2]=dbgRGB[2]; 255 | 256 | }else{ 257 | rgb_out[0]=1.0; 258 | rgb_out[1]=1.0; 259 | rgb_out[2]=1.0; 260 | } 261 | 262 | } 263 | 264 | void debug_9(double rgb[3], double rgb_out[3], double amp, double amp2) 265 | { 266 | double mx=MAX(rgb[0],MAX(rgb[1],rgb[2])); 267 | double sat=(mx==0)?0:(mx-MIN(rgb[0],MIN(rgb[1],rgb[2])))/mx; 268 | 269 | rgb_out[0]=(sat>=amp2)?rgb[0]:((sat=amp2)?rgb[1]:((sat=amp2)?rgb[2]:((sat>= 1; 55 | } 56 | 57 | double res= r * u.d; 58 | 59 | if(neg_b==0){ 60 | return res; 61 | }else{ 62 | return 1.0/res; 63 | } 64 | 65 | } 66 | //Source: https://martin.ankerl.com/2012/01/25/optimized-approximative-fastPrecisePow-in-c-and-cpp/ 67 | 68 | // A is m x p and B is p x n, so C is m x n 69 | void mul( int rows_a, int cols_a, int cols_b,void* ma, void* mb, void* mres) 70 | { 71 | 72 | int i,j,k; 73 | 74 | double (*a)[cols_a] = (double (*)[cols_a]) ma; 75 | double (*b)[cols_b] = (double (*)[cols_b]) mb; 76 | double (*res)[cols_b] = (double (*)[cols_b]) mres; 77 | 78 | double *pta = &a[0][0]; 79 | double *ptb = &b[0][0]; 80 | double *ptr = &res[0][0]; 81 | // double*ptr, *ptr1, *ptr2; 82 | 83 | 84 | 85 | // Multiplying matrix firstMatrix and secondMatrix and storing in array mult. 86 | for(i = 0; i < rows_a; i++) 87 | { 88 | for(j = 0; j < cols_b; j++) 89 | { 90 | *(ptr+(i*cols_b+j))=0; 91 | for(k=0; k 0.0404482362771082 )?fastPrecisePow(fabs((rgbGam[0]+0.055)*rcpOFiveFive),2.4):rgbGam[0]*rcpTwelveNineTwo; 107 | rgbLin[1]=(rgbGam[1] > 0.0404482362771082 )?fastPrecisePow(fabs((rgbGam[1]+0.055)*rcpOFiveFive),2.4):rgbGam[1]*rcpTwelveNineTwo; 108 | rgbLin[2]=(rgbGam[2] > 0.0404482362771082 )?fastPrecisePow(fabs((rgbGam[2]+0.055)*rcpOFiveFive),2.4):rgbGam[2]*rcpTwelveNineTwo; 109 | }else if ((mode==5)||(mode==10)){ //DCI-P3 110 | rgbLin[0]=fastPrecisePow(rgbGam[0],2.6); 111 | rgbLin[1]=fastPrecisePow(rgbGam[1],2.6); 112 | rgbLin[2]=fastPrecisePow(rgbGam[2],2.6); 113 | }else if (mode==7 || mode==12){ //Original NTSC - Source: 47 CFR, Section 73.682 - TV transmission standards 114 | rgbLin[0]=fastPrecisePow(rgbGam[0],2.2); 115 | rgbLin[1]=fastPrecisePow(rgbGam[1],2.2); 116 | rgbLin[2]=fastPrecisePow(rgbGam[2],2.2); 117 | }else if(mode==11){ //Rec. 2100 HLG 118 | rgbLin[0]=(rgbLin[0]>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(rgbLin[0]-HLG_c)*rcp_HLG_a)+HLG_b):rgbLin[0]*rgbLin[0]*third; 119 | rgbLin[1]=(rgbLin[1]>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(rgbLin[1]-HLG_c)*rcp_HLG_a)+HLG_b):rgbLin[1]*rgbLin[1]*third; 120 | rgbLin[2]=(rgbLin[2]>0.5)?rcpTwelve*(fastPrecisePow(euler_e,(rgbLin[2]-HLG_c)*rcp_HLG_a)+HLG_b):rgbLin[2]*rgbLin[2]*third; 121 | }else{ //Rec transfer 122 | rgbLin[0]=(rgbGam[0] < recBetaLin )?rcpFourFive*rgbGam[0]:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-rgbGam[0])),rcpTxFourFive); 123 | rgbLin[1]=(rgbGam[1] < recBetaLin )?rcpFourFive*rgbGam[1]:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-rgbGam[1])),rcpTxFourFive); 124 | rgbLin[2]=(rgbGam[1] < recBetaLin )?rcpFourFive*rgbGam[2]:fastPrecisePow(-1*(rcpRecAlpha*(1-recAlpha-rgbGam[2])),rcpTxFourFive); 125 | } 126 | }else{ 127 | if ((mode==0)||(mode==6)){ //sRGB transfer 128 | rgbLin[0]=(rgbGam[0] > 0.0404482362771082 )?pow(fabs((rgbGam[0]+0.055)*rcpOFiveFive),2.4):rgbGam[0]*rcpTwelveNineTwo; 129 | rgbLin[1]=(rgbGam[1] > 0.0404482362771082 )?pow(fabs((rgbGam[1]+0.055)*rcpOFiveFive),2.4):rgbGam[1]*rcpTwelveNineTwo; 130 | rgbLin[2]=(rgbGam[2] > 0.0404482362771082 )?pow(fabs((rgbGam[2]+0.055)*rcpOFiveFive),2.4):rgbGam[2]*rcpTwelveNineTwo; 131 | }else if ((mode==5)||(mode==10)){ //DCI-P3 132 | rgbLin[0]=pow(rgbGam[0],2.6); 133 | rgbLin[1]=pow(rgbGam[1],2.6); 134 | rgbLin[2]=pow(rgbGam[2],2.6); 135 | }else if (mode==7 || mode==12){ //Original NTSC - Source: 47 CFR, Section 73.682 - TV transmission standards 136 | rgbLin[0]=pow(rgbGam[0],2.2); 137 | rgbLin[1]=pow(rgbGam[1],2.2); 138 | rgbLin[2]=pow(rgbGam[2],2.2); 139 | }else if(mode==11){ //Rec. 2100 HLG 140 | rgbLin[0]=(rgbLin[0]>0.5)?rcpTwelve*(pow(euler_e,(rgbLin[0]-HLG_c)*rcp_HLG_a)+HLG_b):rgbLin[0]*rgbLin[0]*third; 141 | rgbLin[1]=(rgbLin[1]>0.5)?rcpTwelve*(pow(euler_e,(rgbLin[1]-HLG_c)*rcp_HLG_a)+HLG_b):rgbLin[1]*rgbLin[1]*third; 142 | rgbLin[2]=(rgbLin[2]>0.5)?rcpTwelve*(pow(euler_e,(rgbLin[2]-HLG_c)*rcp_HLG_a)+HLG_b):rgbLin[2]*rgbLin[2]*third; 143 | }else{ //Rec transfer 144 | rgbLin[0]=(rgbGam[0] < recBetaLin )?rcpFourFive*rgbGam[0]:pow(-1*(rcpRecAlpha*(1-recAlpha-rgbGam[0])),rcpTxFourFive); 145 | rgbLin[1]=(rgbGam[1] < recBetaLin )?rcpFourFive*rgbGam[1]:pow(-1*(rcpRecAlpha*(1-recAlpha-rgbGam[1])),rcpTxFourFive); 146 | rgbLin[2]=(rgbGam[1] < recBetaLin )?rcpFourFive*rgbGam[2]:pow(-1*(rcpRecAlpha*(1-recAlpha-rgbGam[2])),rcpTxFourFive); 147 | } 148 | } 149 | } 150 | 151 | void Apply_gamma(double rgbLin[3], double rgbGam[3], int mode, int aprxPw){ 152 | 153 | double r=rgbLin[0]; 154 | double g=rgbLin[1]; 155 | double b=rgbLin[2]; 156 | if(aprxPw==1){ 157 | if ((mode==0)||(mode==6)){ //sRGB transfer 158 | rgbGam[0]=(r> 0.00313066844250063)?1.055 * fastPrecisePow(r,rcpTwoFour) - 0.055:12.92 *r; 159 | rgbGam[1]=(g> 0.00313066844250063)?1.055 * fastPrecisePow(g,rcpTwoFour) - 0.055:12.92 *g; 160 | rgbGam[2]=(b> 0.00313066844250063)?1.055 * fastPrecisePow(b,rcpTwoFour) - 0.055:12.92 *b; 161 | }else if ((mode==5)||(mode==10)){ //DCI-P3 162 | rgbGam[0]=fastPrecisePow(r,invTwoSix); 163 | rgbGam[1]=fastPrecisePow(g,invTwoSix); 164 | rgbGam[2]=fastPrecisePow(b,invTwoSix); 165 | }else if (mode==7 || mode==12){ //Original NTSC 166 | rgbGam[0]=fastPrecisePow(r,invTwoTwo); 167 | rgbGam[1]=fastPrecisePow(g,invTwoTwo); 168 | rgbGam[2]=fastPrecisePow(b,invTwoTwo); 169 | }else if (mode==11){ //Rec. 2100 HLG 170 | rgbGam[0]=(rgbGam[0] > rcpTwelve)?HLG_a*log(12.0*rgbGam[0]-HLG_b)+HLG_c:root_three*fastPrecisePow(rgbGam[0],0.5); 171 | rgbGam[1]=(rgbGam[1] > rcpTwelve)?HLG_a*log(12.0*rgbGam[1]-HLG_b)+HLG_c:root_three*fastPrecisePow(rgbGam[1],0.5); 172 | rgbGam[2]=(rgbGam[2] > rcpTwelve)?HLG_a*log(12.0*rgbGam[2]-HLG_b)+HLG_c:root_three*fastPrecisePow(rgbGam[2],0.5); 173 | }else{ //Rec transfer 174 | rgbGam[0]=(r< recBeta)?4.5*r:recAlpha*fastPrecisePow(r,0.45)-(recAlpha-1); 175 | rgbGam[1]=(g< recBeta)?4.5*g:recAlpha*fastPrecisePow(g,0.45)-(recAlpha-1); 176 | rgbGam[2]=(b< recBeta)?4.5*b:recAlpha*fastPrecisePow(b,0.45)-(recAlpha-1); 177 | } 178 | }else{ 179 | if ((mode==0)||(mode==6)){ //sRGB transfer 180 | rgbGam[0]=(r> 0.00313066844250063)?1.055 * pow(r,rcpTwoFour) - 0.055:12.92 *r; 181 | rgbGam[1]=(g> 0.00313066844250063)?1.055 * pow(g,rcpTwoFour) - 0.055:12.92 *g; 182 | rgbGam[2]=(b> 0.00313066844250063)?1.055 * pow(b,rcpTwoFour) - 0.055:12.92 *b; 183 | }else if ((mode==5)||(mode==10)){ //DCI-P3 184 | rgbGam[0]=pow(r,invTwoSix); 185 | rgbGam[1]=pow(g,invTwoSix); 186 | rgbGam[2]=pow(b,invTwoSix); 187 | }else if (mode==7 || mode==12){ //Original NTSC 188 | rgbGam[0]=pow(r,invTwoTwo); 189 | rgbGam[1]=pow(g,invTwoTwo); 190 | rgbGam[2]=pow(b,invTwoTwo); 191 | }else if (mode==11){ //Rec. 2100 HLG 192 | rgbGam[0]=(rgbGam[0] > rcpTwelve)?HLG_a*log(12.0*rgbGam[0]-HLG_b)+HLG_c:root_three*pow(rgbGam[0],0.5); 193 | rgbGam[1]=(rgbGam[1] > rcpTwelve)?HLG_a*log(12.0*rgbGam[1]-HLG_b)+HLG_c:root_three*pow(rgbGam[1],0.5); 194 | rgbGam[2]=(rgbGam[2] > rcpTwelve)?HLG_a*log(12.0*rgbGam[2]-HLG_b)+HLG_c:root_three*pow(rgbGam[2],0.5); 195 | }else{ //Rec transfer 196 | rgbGam[0]=(r< recBeta)?4.5*r:recAlpha*pow(r,0.45)-(recAlpha-1); 197 | rgbGam[1]=(g< recBeta)?4.5*g:recAlpha*pow(g,0.45)-(recAlpha-1); 198 | rgbGam[2]=(b< recBeta)?4.5*b:recAlpha*pow(b,0.45)-(recAlpha-1); 199 | } 200 | } 201 | } 202 | 203 | void WPconv_func(double XYZ[3],double from[3], double to[3],double outp[3]) 204 | { 205 | 206 | double Bradford[3][3]={ 207 | {0.8951,0.2664,-0.1614}, 208 | {-0.7502,1.7135,0.0367}, 209 | {0.0389,-0.0685,1.0296}}; 210 | 211 | double BradfordInv[3][3]={ 212 | {0.9869929,-0.1470543,0.1599627}, 213 | {0.4323053,0.5183603,0.0492912}, 214 | {-0.0085287,0.0400428,0.9684867}}; 215 | 216 | 217 | double BradFrom[3]; 218 | 219 | mul(3,3,1,Bradford,from,BradFrom); 220 | 221 | double BradTo[3]; 222 | 223 | mul(3,3,1,Bradford,to,BradTo); 224 | 225 | 226 | double CR[3][3]={{0,0,0},{0,0,0},{0,0,0}}; 227 | 228 | CR[0][0]=BradTo[0]/BradFrom[0]; 229 | CR[1][1]=BradTo[1]/BradFrom[1]; 230 | CR[2][2]=BradTo[2]/BradFrom[2]; 231 | 232 | double convBrad2[3][3]={{0,0,0},{0,0,0},{0,0,0}}; 233 | double convBrad[3][3]={{0,0,0},{0,0,0},{0,0,0}}; 234 | 235 | mul(3,3,3,BradfordInv,CR,convBrad2); 236 | mul(3,3,3,convBrad2,Bradford,convBrad); 237 | 238 | 239 | mul(3,3,1,convBrad,XYZ,outp); 240 | 241 | //mul(1,3,3,XYZ,Bradford,outp); //WORKS (double3 X 3x3 )!!!! 242 | 243 | //mul(3,3,1,Bradford,XYZ,outp); //WORKS (3x3 X double3)!!! 244 | 245 | } 246 | 247 | void WPconv(double XYZ[3],double from[3], double to[3],double outp[3]) 248 | { 249 | WPconv_func(XYZ, from, to, outp); 250 | } 251 | 252 | void WPconv2Grey(double from[3], double to[3],double outp[3]) 253 | { 254 | WPconv_func(D65XYZ, from, to, outp); //D65 255 | } 256 | 257 | void LinRGB2XYZ(double rgbLin[3], double XYZ_out[3], int mode) 258 | { 259 | double v1[3]; 260 | double v2[3]; 261 | double v3[3]; 262 | 263 | if (mode==1){ //Rec 601 NTSC 264 | v1[0]=0.3935891; 265 | v1[1]=0.3652497; 266 | v1[2]=0.1916313; 267 | v2[0]=0.2124132; 268 | v2[1]=0.7010437; 269 | v2[2]=0.0865432; 270 | v3[0]=0.0187423; 271 | v3[1]=0.1119313; 272 | v3[2]=0.9581563; 273 | }else if (mode==2){ //Rec 601 PAL 274 | v1[0]=0.430619; 275 | v1[1]=0.3415419; 276 | v1[2]=0.1783091; 277 | v2[0]=0.2220379; 278 | v2[1]=0.7066384; 279 | v2[2]=0.0713236; 280 | v3[0]=0.0201853; 281 | v3[1]=0.1295504; 282 | v3[2]=0.9390944; 283 | }else if(mode==5){ //DCI-P3 284 | v1[0]=0.445169815564552; 285 | v1[1]=0.277134409206778; 286 | v1[2]=0.172282669815565; 287 | v2[0]=0.209491677912731; 288 | v2[1]=0.721595254161044; 289 | v2[2]=0.068913067926226; 290 | v3[0]=0; 291 | v3[1]=0.047060560053981; 292 | v3[2]=0.907355394361973; 293 | }else if(mode==6){ 294 | v1[0]=0.48663265; 295 | v1[1]=0.2656631625; 296 | v1[2]=0.1981741875; 297 | v2[0]=0.2290036; 298 | v2[1]=0.691726725; 299 | v2[2]=0.079269675; 300 | v3[0]=0; 301 | v3[1]=0.0451126125; 302 | v3[2]=1.0437173875; 303 | }else if ((mode==4)||(mode==11)){ //Rec 2020/2100 304 | v1[0]=0.637010191411101; 305 | v1[1]=0.144615027396969; 306 | v1[2]=0.16884478119193; 307 | v2[0]=0.26272171736164; 308 | v2[1]=0.677989275502262; 309 | v2[2]=0.059289007136098; 310 | v3[0]=0; 311 | v3[1]=0.028072328847647; 312 | v3[2]=1.06075767115235; 313 | }else if (mode==7){ //Original NTSC 314 | v1[0]=0.6069928; 315 | v1[1]=0.1734485; 316 | v1[2]=0.2005713; 317 | v2[0]=0.2989666; 318 | v2[1]=0.5864212; 319 | v2[2]=0.1146122; 320 | v3[0]=0; 321 | v3[1]=0.0660756; 322 | v3[2]=1.1174687; 323 | }else if (mode==8){ //Rec 601 D93 324 | v1[0]=0.3275085; 325 | v1[1]=0.3684739; 326 | v1[2]=0.2568954; 327 | v2[0]=0.1767506; 328 | v2[1]=0.7072321; 329 | v2[2]=0.1160173; 330 | v3[0]=0.0155956; 331 | v3[1]=0.1129194; 332 | v3[2]=1.2844772; 333 | }else if (mode==9){ //Rec 709 D93 334 | v1[0]=0.3490195; 335 | v1[1]=0.3615584; 336 | v1[2]=0.2422998; 337 | v2[0]=0.1799632; 338 | v2[1]=0.7231169; 339 | v2[2]=0.0969199; 340 | v3[0]=0.0163603; 341 | v3[1]=0.1205195; 342 | v3[2]=1.2761125; 343 | }else if (mode==10){ //DCI-P3 D60/ACES 344 | v1[0]=0.504949534191744; 345 | v1[1]=0.264681488895262; 346 | v1[2]=0.18301505148284; 347 | v2[0]=0.23762331020788; 348 | v2[1]=0.689170669198985; 349 | v2[2]=0.073206020593136; 350 | v3[0]=0; 351 | v3[1]=0.04494591320863; 352 | v3[2]=0.963879271142956; 353 | }else if(mode==12){ //Original NTSC D65 354 | v1[0]=0.5881556; 355 | v1[1]=0.1791317; 356 | v1[2]=0.1831827; 357 | v2[0]=0.2896886; 358 | v2[1]=0.6056356; 359 | v2[2]=0.1046758; 360 | v3[0]=0; 361 | v3[1]=0.0682406; 362 | v3[2]=1.0205895; 363 | }else{ //sRGB - Rec 709 364 | v1[0]=0.4124564; 365 | v1[1]=0.3575761; 366 | v1[2]=0.1804375; 367 | v2[0]=0.2126729; 368 | v2[1]=0.7151522; 369 | v2[2]=0.072175; 370 | v3[0]=0.0193339; 371 | v3[1]=0.119192; 372 | v3[2]=0.9503041; 373 | } 374 | 375 | XYZ_out[0]=v1[0]*rgbLin[0]+v1[1]*rgbLin[1]+v1[2]*rgbLin[2]; 376 | XYZ_out[1]=v2[0]*rgbLin[0]+v2[1]*rgbLin[1]+v2[2]*rgbLin[2]; 377 | XYZ_out[2]=v3[0]*rgbLin[0]+v3[1]*rgbLin[1]+v3[2]*rgbLin[2]; 378 | 379 | } 380 | 381 | inline double LinRGB2Y(double rgbLin[3], int mode) 382 | { 383 | double v2[3]; 384 | 385 | if (mode==1){ //Rec 601 NTSC 386 | v2[0]=0.2124132; 387 | v2[1]=0.7010437; 388 | v2[2]=0.0865432; 389 | }else if (mode==2){ //Rec 601 PAL 390 | v2[0]=0.2220379; 391 | v2[1]=0.7066384; 392 | v2[2]=0.0713236; 393 | }else if(mode==5){ //DCI-P3 394 | v2[0]=0.209491677912731; 395 | v2[1]=0.721595254161044; 396 | v2[2]=0.068913067926226; 397 | }else if(mode==6){ 398 | v2[0]=0.2290036; 399 | v2[1]=0.691726725; 400 | v2[2]=0.079269675; 401 | }else if ((mode==4)||(mode==11)){ //Rec 2020/2100 402 | v2[0]=0.26272171736164; 403 | v2[1]=0.677989275502262; 404 | v2[2]=0.059289007136098; 405 | }else if (mode==7){ //Original NTSC 406 | v2[0]=0.2989666; 407 | v2[1]=0.5864212; 408 | v2[2]=0.1146122; 409 | }else if (mode==8){ //Rec 601 D93 410 | v2[0]=0.1767506; 411 | v2[1]=0.7072321; 412 | v2[2]=0.1160173; 413 | }else if (mode==9){ //Rec 709 D93; 414 | v2[0]=0.1799632; 415 | v2[1]=0.7231169; 416 | v2[2]=0.0969199; 417 | }else if (mode==10){ //DCI-P3 D60/ACES 418 | v2[0]=0.23762331020788; 419 | v2[1]=0.689170669198985; 420 | v2[2]=0.073206020593136; 421 | }else if(mode==12){ //Original NTSC D65 422 | v2[0]=0.2896886; 423 | v2[1]=0.6056356; 424 | v2[2]=0.1046758; 425 | }else{ //sRGB - Rec 709 426 | v2[0]=0.2126729; 427 | v2[1]=0.7151522; 428 | v2[2]=0.072175; 429 | } 430 | 431 | return v2[0]*rgbLin[0]+v2[1]*rgbLin[1]+v2[2]*rgbLin[2]; 432 | 433 | } 434 | 435 | void XYZ2LinRGB(double XYZ[3],double rgb_out[3], int mode) 436 | { 437 | double v1[3]; 438 | double v2[3]; 439 | double v3[3]; 440 | 441 | if (mode==1){ //Rec 601 NTSC 442 | v1[0]=3.505396; 443 | v1[1]=-1.7394894; 444 | v1[2]=-0.543964; 445 | v2[0]=-1.0690722; 446 | v2[1]=1.9778245; 447 | v2[2]=0.0351722; 448 | v3[0]=0.05632; 449 | v3[1]=-0.1970226; 450 | v3[2]=1.0502026; 451 | }else if (mode==2){ //Rec 601 PAL 452 | v1[0]=3.0628971; 453 | v1[1]=-1.3931791; 454 | v1[2]=-0.4757517; 455 | v2[0]=-0.969266; 456 | v2[1]=1.8760108; 457 | v2[2]=0.041556; 458 | v3[0]=0.0678775; 459 | v3[1]=-0.2288548; 460 | v3[2]=1.069349; 461 | }else if(mode==5){ //DCI-P3 462 | v1[0]=2.72539403049173; 463 | v1[1]=-1.01800300622718; 464 | v1[2]=-0.440163195190036; 465 | v2[0]=-0.795168025808764; 466 | v2[1]=1.68973205484362; 467 | v2[2]=0.022647190608478; 468 | v3[0]=0.0412418913957; 469 | v3[1]=-0.087639019215862; 470 | v3[2]=1.10092937864632; 471 | }else if(mode==6){ 472 | v1[0]=2.49318075532897; 473 | v1[1]=-0.93126552549714; 474 | v1[2]=-0.402659723758882; 475 | v2[0]=-0.829503115821079; 476 | v2[1]=1.76269412111979; 477 | v2[2]=0.02362508874174; 478 | v3[0]=0.035853625780072; 479 | v3[1]=-0.076188954782652; 480 | v3[2]=0.957092621518022; 481 | }else if ((mode==4)||(mode==11)){ //Rec 2020/2100 482 | v1[0]=1.71651066976197; 483 | v1[1]=-0.355641669986716; 484 | v1[2]=-0.253345541821907; 485 | v2[0]=-0.666693001182624; 486 | v2[1]=1.61650220834691; 487 | v2[2]=0.015768750389995; 488 | v3[0]=0.017643638767459; 489 | v3[1]=-0.042779781669045; 490 | v3[2]=0.942305072720018; 491 | }else if (mode==7){ //Original NTSC 492 | v1[0]=1.9096754; 493 | v1[1]=-0.5323648; 494 | v1[2]=-0.2881607; 495 | v2[0]=-0.9849649; 496 | v2[1]=1.9997772; 497 | v2[2]=-0.0283168; 498 | v3[0]=0.0582407; 499 | v3[1]=-0.1182463; 500 | v3[2]=0.896554; 501 | }else if (mode==8){ //Rec 601 D93 502 | v1[0]=4.2126707; 503 | v1[1]=-2.0904617; 504 | v1[2]=-0.6537183; 505 | v2[0]=-1.0597177; 506 | v2[1]=1.9605182; 507 | v2[2]=0.0348645; 508 | v3[0]=0.0420119; 509 | v3[1]=-0.1469691; 510 | v3[2]=0.7833991; 511 | }else if (mode==9){ //Rec 709 D93 512 | v1[0]=3.8294307; 513 | v1[1]=-1.8165248; 514 | v1[2]=-0.5891432; 515 | v2[0]=-0.9585901; 516 | v2[1]=1.8553477; 517 | v2[2]=0.0410983; 518 | v3[0]=0.0414369; 519 | v3[1]=-0.1519354; 520 | v3[2]=0.7873016; 521 | }else if (mode==10){ //DCI-P3 D60/ACES 522 | v1[0]=2.40274141422225; 523 | v1[1]=-0.897484163940685; 524 | v1[2]=-0.388053369996071; 525 | v2[0]=-0.832579648740884; 526 | v2[1]=1.76923175357438; 527 | v2[2]=0.023712711514772; 528 | v3[0]=0.038823381466857; 529 | v3[1]=-0.082499685617071; 530 | v3[2]=1.03636859971248; 531 | }else if(mode==12){ //Original NTSC D65 532 | v1[0]=1.9708379; 533 | v1[1]=-0.5494152; 534 | v1[2]=-0.2973899; 535 | v2[0]=-0.9537159; 536 | v2[1]=1.9363323; 537 | v2[2]=-0.0274184; 538 | v3[0]=0.0637692; 539 | v3[1]=-0.1294708; 540 | v3[2]=0.9816592; 541 | }else{ //sRGB - Rec 709 542 | v1[0]=3.2404542; 543 | v1[1]=-1.5371385; 544 | v1[2]=-0.4985314; 545 | v2[0]=-0.969266; 546 | v2[1]=1.8760108; 547 | v2[2]=0.041556; 548 | v3[0]=0.0556434; 549 | v3[1]=-0.2040259; 550 | v3[2]=1.0572252; 551 | } 552 | 553 | rgb_out[0]=v1[0]*XYZ[0]+v1[1]*XYZ[1]+v1[2]*XYZ[2]; 554 | rgb_out[1]=v2[0]*XYZ[0]+v2[1]*XYZ[1]+v2[2]*XYZ[2]; 555 | rgb_out[2]=v3[0]*XYZ[0]+v3[1]*XYZ[1]+v3[2]*XYZ[2]; 556 | 557 | } 558 | 559 | void LinRGB2XYZ_grey(double lin_rgb[3], double XYZ_out[3],int mode) 560 | { 561 | double avg=(lin_rgb[0]+lin_rgb[1]+lin_rgb[2])/3.0; 562 | double rgb_avg[3]={avg,avg,avg}; 563 | LinRGB2XYZ(rgb_avg, XYZ_out, mode); 564 | } 565 | 566 | void XYZ2xyY(double XYZ[3], double xyY_out[3]) 567 | { 568 | double tot=XYZ[0]+XYZ[1]+XYZ[2]; 569 | //Avoid putting double3(0,0,0) as XYZ! 570 | 571 | xyY_out[0]=XYZ[0]/tot; 572 | xyY_out[1]=XYZ[1]/tot; 573 | xyY_out[2]=XYZ[1]; 574 | } 575 | 576 | void xyY2XYZ(double xyY[3], double XYZ_out[3]) 577 | { 578 | XYZ_out[0]=(1.0/xyY[1])*xyY[0]*xyY[2]; 579 | XYZ_out[1]=xyY[2]; 580 | XYZ_out[2]=(1.0/xyY[1])*(1-xyY[0]-xyY[1])*(xyY[2]); 581 | } 582 | 583 | void LinRGB2xyY(double rgb_lin[3], double xyY_out[3],int mode) 584 | { 585 | double rgb_lin_adj[3]={rgb_lin[0],rgb_lin[1],rgb_lin[2]}; 586 | 587 | int rgb_is_blk=(rgb_lin[0]==0 && rgb_lin[1]==0 && rgb_lin[2]==0)?1:0; 588 | 589 | if(rgb_is_blk==1){ 590 | rgb_lin_adj[0]=1; 591 | rgb_lin_adj[1]=1; 592 | rgb_lin_adj[2]=1; 593 | } 594 | double XYZ[3]; 595 | LinRGB2XYZ(rgb_lin_adj, XYZ, mode); 596 | XYZ2xyY(XYZ, xyY_out); 597 | xyY_out[2]=(rgb_is_blk==1)?0:xyY_out[2]; 598 | } 599 | 600 | void rgb2XYZ(double rgb[3], double XYZ_out[3], int mode, int aprxPw) 601 | { 602 | double rgbLin[3]; 603 | Linearise(rgb, rgbLin, mode, aprxPw); 604 | LinRGB2XYZ(rgbLin, XYZ_out, mode); 605 | } 606 | 607 | void rgb2xyY(double rgb[3], double xyY_out[3], int mode, int aprxPw) 608 | { 609 | double rgb_lin[3]; 610 | Linearise(rgb, rgb_lin, mode, aprxPw); 611 | LinRGB2xyY(rgb_lin, xyY_out, mode); 612 | } 613 | 614 | void xyY2LinRGB(double xyY[3], double lin_rgb_out[3], int mode) 615 | { 616 | double XYZ[3]; 617 | xyY2XYZ(xyY, XYZ); 618 | XYZ2LinRGB(XYZ, lin_rgb_out,mode); 619 | } 620 | 621 | void xyY2rgb(double xyY[3], double rgb_out[3], int mode, int aprxPw) 622 | { 623 | double lin_rgb[3]; 624 | xyY2LinRGB(xyY, lin_rgb, mode); 625 | Apply_gamma(lin_rgb, rgb_out, mode, aprxPw); 626 | } 627 | 628 | void XYZ2rgb(double XYZ[3], double rgb_out[3], int mode, int aprxPw) 629 | { 630 | double rgb_lin[3]; 631 | XYZ2LinRGB(XYZ, rgb_lin, mode); 632 | Apply_gamma(rgb_lin, rgb_out, mode, aprxPw); 633 | } 634 | 635 | void rgb2XYZ_grey(double rgb[3], double XYZ_out[3], int mode, int aprxPw) 636 | { 637 | double lin_rgb[3]; 638 | Linearise(rgb, lin_rgb, mode, aprxPw); 639 | LinRGB2XYZ_grey(lin_rgb, XYZ_out, mode); 640 | } 641 | 642 | inline double rgb2Y(double rgb[3], int mode, int aprxPw) 643 | { 644 | double lin_rgb[3]; 645 | Linearise(rgb, lin_rgb, mode, aprxPw); 646 | return LinRGB2Y(lin_rgb, mode); 647 | } 648 | 649 | void xy2XYZ(double xyCoord[2], double XYZ_out[3]) 650 | { 651 | XYZ_out[0]=(1/xyCoord[1])*xyCoord[0]; 652 | XYZ_out[1]=1; 653 | XYZ_out[2]=(1/xyCoord[1])*(1-xyCoord[0]-xyCoord[1]); 654 | } 655 | 656 | void get_xy(double rgb[3],double xy_out[2], int mode, int linr, int aprxPw) 657 | { 658 | double XYZ1[3]; 659 | double XYZ2[3]; 660 | 661 | if(linr==0){ 662 | rgb2XYZ(rgb,XYZ1,mode,aprxPw); 663 | rgb2XYZ_grey(rgb,XYZ2,mode,aprxPw); 664 | }else{ 665 | LinRGB2XYZ(rgb,XYZ1,mode); 666 | LinRGB2XYZ_grey(rgb,XYZ2,mode); 667 | } 668 | 669 | double XYZ3[3]; 670 | WPconv2Grey(XYZ1,XYZ2,XYZ3); 671 | 672 | double xyY[3]; 673 | XYZ2xyY(XYZ3,xyY); 674 | 675 | xy_out[0]=xyY[0]; 676 | xy_out[1]=xyY[1]; 677 | } 678 | 679 | //Source: https://stackoverflow.com/a/45263428; http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.htm; https://en.wikipedia.org/wiki/Rec._2020#Transfer_characteristics 680 | -------------------------------------------------------------------------------- /Uniform dither.hlsl: -------------------------------------------------------------------------------- 1 | sampler s0 : register(s0); 2 | float4 p0 : register(c0); 3 | float4 p1 : register(c1); 4 | 5 | #define width (p0[0]) 6 | #define height (p0[1]) 7 | #define counter (p0[2]) 8 | #define clock (p0[3]) 9 | #define one_over_width (p1[0]) 10 | #define one_over_height (p1[1]) 11 | 12 | static float d_x_b[2]={0,1};static float d_y_b[2]={0,1}; 13 | 14 | #define dither_points 7 15 | 16 | static float2 d[dither_points] = { 17 | 0,0, 18 | 1,0, 19 | 64.90915,63.75, 20 | 131.4898,127.5, 21 | 194.1036,191.25, 22 | 254,255, 23 | 255,255 24 | }; 25 | 26 | float dither_map(float dither){int i=0;int exact=0;[unroll(dither_points)]for(i=0;i=d_x_b[0]){d_x_b[0]=d[i][0]/255;d_y_b[0]=d[i][1]/255;} if(d[i][0]/255<=d_x_b[1]&&dither0)?lerp(c1.rgb,c0,1-pow(c1Max,drk)):c1.rgb; 99 | 100 | return c1; 101 | 102 | } --------------------------------------------------------------------------------