Skip to content

Commit

Permalink
Update the video preview when changing a 'YUV -> RGB' option without …
Browse files Browse the repository at this point in the history
…re-evaluating the script
  • Loading branch information
vdcrim committed Aug 3, 2013
1 parent d50bcfe commit a950485
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 58 deletions.
45 changes: 34 additions & 11 deletions avsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7616,6 +7616,7 @@ def createScriptWindow(self):
scriptWindow.workdir = ""
scriptWindow.encoding = 'latin1'
scriptWindow.AVI = None
scriptWindow.display_clip_refresh_needed = False
scriptWindow.previewtxt = []
scriptWindow.sliderTexts = []
scriptWindow.sliderProperties = []
Expand Down Expand Up @@ -9032,6 +9033,7 @@ def OnMenuVideoYUV2RGB(self, event):
else:
menuItem.Check(not self.swapuv)
value = self.yuv2rgbDict[menuItem.GetLabel()]
refresh = False
AVI = self.currentScript.AVI
if value == 'swapuv':
self.swapuv = not self.swapuv
Expand All @@ -9048,8 +9050,12 @@ def OnMenuVideoYUV2RGB(self, event):
self.matrix[0] = value
if AVI:
refresh = AVI.IsYUV
if self.previewWindowVisible and refresh:
self.OnMenuVideoRefresh(event)
if refresh:
for index in xrange(self.scriptNotebook.GetPageCount()):
script = self.scriptNotebook.GetPage(index)
script.display_clip_refresh_needed = True
if self.previewWindowVisible:
self.ShowVideoFrame(forceRefresh=False, focus=self.options['focusonrefresh'])

def OnMenuVideoReuseEnvironment(self, event):
self.reuse_environment = not self.reuse_environment
Expand Down Expand Up @@ -13816,6 +13822,7 @@ def ShowVideoFrame(self, framenum=None, forceRefresh=False, wrap=True, script=No
script = self.currentScript
if script.AVI is None:
forceRefresh = True
display_clip_refresh_needed = script.display_clip_refresh_needed
if self.UpdateScriptAVI(script, forceRefresh, keep_env=keep_env) is None:
#~ wx.MessageBox(_('Error loading the script'), _('Error'), style=wx.OK|wx.ICON_ERROR)
return False
Expand Down Expand Up @@ -13929,7 +13936,8 @@ def ShowVideoFrame(self, framenum=None, forceRefresh=False, wrap=True, script=No
resize = False
else:
resize = True
self.LayoutVideoWindows(w, h, resize, forceRefresh=forceRefresh)
self.LayoutVideoWindows(w, h, resize, forceRefresh=forceRefresh or
display_clip_refresh_needed)

self.toggleButton.SetBitmapLabel(self.bmpVidDown)
self.toggleButton.Refresh()
Expand Down Expand Up @@ -14290,6 +14298,7 @@ def UpdateScriptAVI(self, script=None, forceRefresh=False, keep_env=None, prompt
if self.playing_video:
self.PlayPauseVideo()
self.playing_video = ''
script.display_clip_refresh_needed = False
scripttxt = script.GetText()
# Replace any user-inserted sliders (defined with self.regexp)
#~ script.SetFocus()
Expand Down Expand Up @@ -14345,21 +14354,35 @@ def UpdateScriptAVI(self, script=None, forceRefresh=False, keep_env=None, prompt
wx.MessageBox('%s\n\n%s' % (s1, s2), _('Error'), style=wx.OK|wx.ICON_ERROR)
script.AVI = None
return None
if not self.zoomwindow and boolOldAVI and \
(oldWidth, oldHeight) != (script.AVI.Width, script.AVI.Height):
script.lastSplitVideoPos = None
# Update the script tag properties
self.UpdateScriptTagProperties(script, scripttxt)
self.GetAutoSliderInfo(script, scripttxt)
script.previewtxt = self.ScriptChanged(script, return_styledtext=True)[1]
script.autocrop_values = None
if self.cropDialog.IsShown():
self.PaintCropWarnings()
boolNewAVI = True
if self.playing_video == '':
self.PlayPauseVideo()
if script == self.currentScript:
self.refreshAVI = False
if script.display_clip_refresh_needed and not boolNewAVI:
script.display_clip_refresh_needed = False
oldWidth, oldHeight = script.AVI.Width, script.AVI.Height
boolOldAVI = True
wx.BeginBusyCursor()
ok = script.AVI.CreateDisplayClip(matrix=self.matrix,
interlaced=self.interlaced, swapuv=self.swapuv)
wx.EndBusyCursor()
if ok:
boolNewAVI = True
else:
return None
if boolNewAVI:
if not self.zoomwindow and boolOldAVI and \
(oldWidth, oldHeight) != (script.AVI.Width, script.AVI.Height):
script.lastSplitVideoPos = None
script.autocrop_values = None
if self.cropDialog.IsShown():
self.PaintCropWarnings()
if self.playing_video == '':
self.PlayPauseVideo()

return boolNewAVI

def ScriptChanged(self, script=None, return_styledtext=False):
Expand Down
87 changes: 40 additions & 47 deletions pyavs.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,24 @@ def __init__(self, script, filename='', workdir='', env=None, fitHeight=None,
self.GetParity = avisynth.avs_get_parity(self.clip,0)#self.vi.image_type
self.HasAudio = self.vi.HasAudio()

# Initialize display-related variables
self.interlaced = interlaced
if display_clip and not self.CreateDisplayClip(matrix, interlaced, swapuv):
return
if self.IsRGB and reorder_rgb:
self.clip = self.BGR2RGB(self.clip)
self.initialized = True
if __debug__:
print "AviSynth clip created successfully: '{0}'".format(self.name)

def __del__(self):
if self.initialized:
self.clip = None
self.display_clip = None
if __debug__:
print "Deleting allocated video memory for '{0}'".format(self.name)

def CreateDisplayClip(self, matrix=['auto', 'tv'], interlaced=None, swapuv=False):
self.current_frame = -1
if isinstance(matrix, basestring):
self.matrix = matrix
else:
Expand All @@ -230,30 +247,21 @@ def __init__(self, script, filename='', workdir='', env=None, fitHeight=None,
matrix[0] = '601'
matrix[1] = 'Rec' if matrix[1] == 'tv' else 'PC.'
self.matrix = matrix[1] + matrix[0]
self.interlaced = interlaced if self.IsYV12 else False
if display_clip:
self.display_clip = self.clip
if swapuv and self.IsYUV and not self.IsY8:
try:
arg = avisynth.AVS_Value(self.display_clip)
avsfile = self.env.Invoke("swapuv", arg, 0)
arg.Release()
self.display_clip = avsfile.AsClip(self.env)
except avisynth.AvisynthError, err:
return
if not self._ConvertToRGB():
if interlaced is not None:
self.interlaced = interlaced
self.display_clip = self.clip
if swapuv and self.IsYUV and not self.IsY8:
try:
arg = avisynth.AVS_Value(self.display_clip)
avsfile = self.env.Invoke("swapuv", arg, 0)
arg.Release()
self.display_clip = avsfile.AsClip(self.env)
except avisynth.AvisynthError, err:
return
elif self.IsRGB and reorder_rgb:
self.clip = self.BGR2RGB(self.clip)
if not self._ConvertToRGB():
return
return True

def __del__(self):
if self.initialized:
self.clip = None
self.display_clip = None
if __debug__:
print "Deleting allocated video memory for '{0}'".format(self.name)

def _ConvertToRGB(self):
'''Convert to RGB for display. Return True if successful'''
pass
Expand Down Expand Up @@ -679,22 +687,16 @@ def ExitRoutines():

class AvsClip(AvsClipBase):

def __init__(self, *args, **kwargs):

if not AvsClipBase.__init__(self, *args, **kwargs):
def CreateDisplayClip(self, *args, **kwargs):
if not AvsClipBase.CreateDisplayClip(self, *args, **kwargs):
return

if self.display_clip:
# Prepare info header for displaying
self.bmih = BITMAPINFOHEADER()
avisynth.CreateBitmapInfoHeader(self.display_clip, self.bmih)
self.pInfo = ctypes.pointer(self.bmih)
#~ self.BUF=ctypes.c_ubyte*self.bmih.biSizeImage
#~ self.pBits=self.BUF()

self.initialized = True
if __debug__:
print "AviSynth clip created successfully: '{0}'".format(self.name)
# Prepare info header for displaying
self.bmih = BITMAPINFOHEADER()
avisynth.CreateBitmapInfoHeader(self.display_clip, self.bmih)
self.pInfo = ctypes.pointer(self.bmih)
#~ self.BUF=ctypes.c_ubyte*self.bmih.biSizeImage
#~ self.pBits=self.BUF()
return True

def _ConvertToRGB(self):
if not self.IsRGB:
Expand Down Expand Up @@ -748,16 +750,7 @@ def ExitRoutines():


class AvsClip(AvsClipBase):

def __init__(self, *args, **kwargs):

if not AvsClipBase.__init__(self, *args, **kwargs):
return

self.initialized = True
if __debug__:
print "AviSynth clip created successfully: '{0}'".format(self.name)


def _ConvertToRGB(self):
# There's issues with RGB32, we convert to RGB24
# AviSynth uses BGR ordering but we need RGB
Expand Down

0 comments on commit a950485

Please sign in to comment.