Skip to content

Commit

Permalink
Merge pull request #553 from mbeacom/autofix/wrapped2_to3_fix-0
Browse files Browse the repository at this point in the history
Avoid mutable default arguments
  • Loading branch information
Mark Beacom committed Apr 25, 2017
2 parents 03fdc2c + 34db3d3 commit 7bd0678
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
8 changes: 6 additions & 2 deletions moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_frame(self, t):
else:
return self.make_frame(t)

def fl(self, fun, apply_to=[], keep_duration=True):
def fl(self, fun, apply_to=None, keep_duration=True):
""" General processing of a clip.
Returns a new Clip whose frames are a transformation
Expand Down Expand Up @@ -131,6 +131,8 @@ def fl(self, fun, apply_to=[], keep_duration=True):
>>> newclip = clip.fl(fl, apply_to='mask')
"""
if apply_to is None:
apply_to = []

#mf = copy(self.make_frame)
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
Expand All @@ -153,7 +155,7 @@ def fl(self, fun, apply_to=[], keep_duration=True):



def fl_time(self, t_func, apply_to=[], keep_duration=False):
def fl_time(self, t_func, apply_to=None, keep_duration=False):
"""
Returns a Clip instance playing the content of the current clip
but with a modified timeline, time ``t`` being replaced by another
Expand Down Expand Up @@ -184,6 +186,8 @@ def fl_time(self, t_func, apply_to=[], keep_duration=False):
>>> newclip = clip.fl_time(lambda: 3-t)
"""
if apply_to is None:
apply_to = []

return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
keep_duration=keep_duration)
Expand Down
4 changes: 3 additions & 1 deletion moviepy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def get_setting(varname):
return gl[varname]


def change_settings(new_settings={}, file=None):
def change_settings(new_settings=None, file=None):
""" Changes the value of configuration variables."""
if new_settings is None:
new_settings = {}
gl = globals()
if file is not None:
execfile(file)
Expand Down
16 changes: 12 additions & 4 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,13 @@ def subfx(self, fx, ta=0, tb=None, **kwargs):

# IMAGE FILTERS

def fl_image(self, image_func, apply_to=[]):
def fl_image(self, image_func, apply_to=None):
"""
Modifies the images of a clip by replacing the frame
`get_frame(t)` by another frame, `image_func(get_frame(t))`
"""
if apply_to is None:
apply_to = []
return self.fl(lambda gf, t: image_func(gf(t)), apply_to)

# --------------------------------------------------------------
Expand Down Expand Up @@ -918,12 +920,14 @@ def __init__(self, img, ismask=False, transparent=True,
self.size = img.shape[:2][::-1]
self.img = img

def fl(self, fl, apply_to=[], keep_duration=True):
def fl(self, fl, apply_to=None, keep_duration=True):
"""General transformation filter.
Equivalent to VideoClip.fl . The result is no more an
ImageClip, it has the class VideoClip (since it may be animated)
"""
if apply_to is None:
apply_to = []
# When we use fl on an image clip it may become animated.
# Therefore the result is not an ImageClip, just a VideoClip.
newclip = VideoClip.fl(self, fl, apply_to=apply_to,
Expand All @@ -932,13 +936,15 @@ def fl(self, fl, apply_to=[], keep_duration=True):
return newclip

@outplace
def fl_image(self, image_func, apply_to=[]):
def fl_image(self, image_func, apply_to=None):
"""Image-transformation filter.
Does the same as VideoClip.fl_image, but for ImageClip the
tranformed clip is computed once and for all at the beginning,
and not for each 'frame'.
"""
if apply_to is None:
apply_to = []
arr = image_func(self.get_frame(0))
self.size = arr.shape[:2][::-1]
self.make_frame = lambda t: arr
Expand All @@ -952,7 +958,7 @@ def fl_image(self, image_func, apply_to=[]):
setattr(self, attr, new_a)

@outplace
def fl_time(self, time_func, apply_to=['mask', 'audio'],
def fl_time(self, time_func, apply_to=None,
keep_duration=False):
"""Time-transformation filter.
Expand All @@ -962,6 +968,8 @@ def fl_time(self, time_func, apply_to=['mask', 'audio'],
This method does nothing for ImageClips (but it may affect their
masks or their audios). The result is still an ImageClip.
"""
if apply_to is None:
apply_to = ['mask', 'audio']
for attr in apply_to:
if hasattr(self, attr):
a = getattr(self, attr)
Expand Down
4 changes: 3 additions & 1 deletion moviepy/video/fx/blackwhite.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import numpy as np

def blackwhite(clip, RGB = [1,1,1], preserve_luminosity=True):
def blackwhite(clip, RGB = None, preserve_luminosity=True):
""" Desaturates the picture, makes it black and white.
Parameter RGB allows to set weights for the different color
channels.
If RBG is 'CRT_phosphor' a special set of values is used.
preserve_luminosity maintains the sum of RGB to 1."""
if RGB is None:
RGB = [1,1,1]

if RGB == 'CRT_phosphor':
RGB = [0.2125, 0.7154, 0.0721]
Expand Down
4 changes: 3 additions & 1 deletion moviepy/video/fx/mask_color.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

def mask_color(clip, color=[0,0,0], thr=0, s=1):
def mask_color(clip, color=None, thr=0, s=1):
""" Returns a new clip with a mask for transparency where the original
clip is of the given color.
Expand All @@ -12,6 +12,8 @@ def mask_color(clip, color=[0,0,0], thr=0, s=1):
which is 1 when d>>thr and 0 for d<<thr, the stiffness of the effect being
parametrized by s
"""
if color is None:
color = [0,0,0]

# code a little sloppy, it just works.
hill = lambda x: (1.0*(x!=0) if (thr==0) else (x**s/ (thr**s+x**s)))
Expand Down
4 changes: 3 additions & 1 deletion moviepy/video/tools/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

import numpy as np

def blit(im1, im2, pos=[0, 0], mask=None, ismask=False):
def blit(im1, im2, pos=None, mask=None, ismask=False):
""" Blit an image over another.
Blits ``im1`` on ``im2`` as position ``pos=(x,y)``, using the
``mask`` if provided. If ``im1`` and ``im2`` are mask pictures
(2D float arrays) then ``ismask`` must be ``True``.
"""
if pos is None:
pos = [0, 0]

# xp1,yp1,xp2,yp2 = blit area on im2
# x1,y1,x2,y2 = area of im1 to blit on im2
Expand Down

0 comments on commit 7bd0678

Please sign in to comment.