Commits

Roberto Gea  committed e3a5ad6

...

  • Participants
  • Parent commits 620f6a5

Comments (0)

Files changed (5)

File eyecandy/__init__.py

 from .effector import ASSGenerator as load
 
 from .core import (
-    ASSTime as asstime, progressbar, namedenc, namedalign,
-    percentzoom, ENCODINGS, ALIGNS, F24P, F30P, timeit)
+    ASSTime as asstime, progressbar, timeit, namedenc, namedalign,
+    percentzoom, ENCODINGS, ALIGNS, FPS_NTSC_FILM, FPS_NTSC,
+    FPS_NTSC_DOUBLE, FPS_NTSC_QUAD, FPS_FILM, FPS_PAL, FPS_PAL_DOUBLE,
+    FPS_PAL_QUAD)
 
 #TODO: use python-progressbar

File eyecandy/asstags.py

 #-*- coding:utf-8 -*-
 from __future__ import absolute_import
 
-import random
-import string
 import math
-
+import between as interpolate
 try:
     from . import core
     from .core import round_format_str
     @dx, @dy: distancia en x, y
     """
     be = '\\be' + round_format_str(strength, 2)
-    if dx is None and dx is None:
-        return xybord(dx, dy) + be
+    if dx is None and dy is None:
+        return be
     else:
-        return be
+        return bord(dx, dy) + be
 
 
 def fscx(scale=100):
                 x1, y1, x2, y2, ti, tf)
 
 
-def imove(x1, x2, ix, iy, t1=None, t2=None):
+def imove(x1, y1, ix, iy, t1=None, t2=None):
     """
     Movimiento del texto, usando un sistema incremental.
 
     @d: distancia en x
     @tipo[blur/be]: tipo de difuminado, por defecto se utiliza blur
     """
-    tipos_blr = {'be': asstags.be(blr), 'blur': asstags.blur(blr)}
-    return xybord(d, 0) + tipos_blr.get(tipo.lower(), asstags.blur(blr))
+    tipos_blr = {'be': be(blr), 'blur': blur(blr)}
+    return bord(d, 0) + tipos_blr.get(tipo.lower(), blur(blr))
 
 
 def yblur(blr, d, tipo='blur'):
     @d: distancia en y
     @tipo[blur/be]: tipo de difuminado, por defecto se utiliza blur
     """
-    tipos_blr = {'be': asstags.be(int(blr)), 'blur': asstags.blur(blr)}
-    return xybord(0, d) + tipos_blr.get(tipo.lower(), asstags.blur(blr))
+    tipos_blr = {'be': be(int(blr)), 'blur': blur(blr)}
+    return bord(0, d) + tipos_blr.get(tipo.lower(), blur(blr))
 
 
 def blur(strength=1, dx=None, dy=None):
     cx, cy = polar2rec(radius, angle)
     return centerx + cx, centery + cy
 
-def pcircle_range(n, x, y, r):
-    """
+
+def pcircle_range(n, x, y, r, func=None):
+    """)
     Genera una lista con las posiciones para generar un circulo,
     especificando el numero de partículas.
 
     @x, @y: centro del circulo.
     @r: radio del circulo.
     """
-    add = 360 / n
-    angle = 0
-    circle = []
-    for i in xrange(1, n + 1):
-        circle = pcircle(x, y, r, angle)
-        angle += add
-        yield circle
+    if func:
+        crange = list(interpolate.inerpolate_circle_range(n + 1, func))[:-1]
+    else:
+        crange = list(interpolate.inerpolate_circle_range(n + 1))[:-1]
+    for deg in crange:
+        yield pcircle(x, y, r, deg)
 
 
 def cycletags(inicio, duracion, intervalo, *tags):
         ttags += t(start_time, duracion, tags[i % n])
     return ttags
 
-
-#class DrawAss(object):
-    #def Draw(self, tipo, x, y):
-        #return '%s %d %d ' % (tipo, x, y)
-
-    #def DrawBezier(self, x1, y1, x2, y2, x3, y3):
-        #return 'b %d %d %d %d %d %d ' % (x1, y1, x2, y2, x3, y3)
-
-    #def DrawSpline(self, *posiciones):
-        #bspline = 's '
-        #for pos in posiciones:
-            #bspline += '%d ' % pos
-        #return bspline + ' c'
-
-
-#def DrawContorno(x, y, width, height):
-    #"""
-    #Retorna un contorno alrededor de la silaba
-    #"""
-    #Dibu = DrawAss()
-    #pt1 = Dibu.Draw('m', x, 0)
-    #pt2 = Dibu.Draw('l', x + width, 0)
-    #pt3 = Dibu.Draw('l', x + width, height)
-    #pt4 = Dibu.Draw('l', x, height)
-    #return pt1 + pt2 + pt3 + pt4
-
-
-#def DrawCircle(radio=10):
-    ##Pseudo circle (intento de circulo)
-    #Dibu = DrawAss()
-    #m1 = Dibu.Draw('m', radio, 0)
-    #x1, y1 = radio, radio + radio / 2 - 1
-    #x2, y2 = -radio, radio + radio / 2 - 1
-    #x3, y3 = -radio, 0
-    #b1 = Dibu.DrawBezier(x1, y1, x2, y2, x3, y3)
-
-    #m2 = Dibu.Draw('m', x3, y3)
-    #x1, y1 = -radio, -radio - radio / 2 + 1
-    #x2, y2 = radio, -radio - radio / 2 + 1
-    #x3, y3 = radio, 0
-    #b2 = Dibu.DrawBezier(x1, y1, x2, y2, x3, y3)
-    #return m1 + b1 + m2 + b2
-
-
-#def DrawRectangle(w, h):
-    #return ('m 0 0 l %(w)s 0 %(w)s %(h)s 0 %(h)s'
-            #% {'w': w, 'h': h})
-
 #TODO: SVG path to Qt path to ASS shape or SVG to ASS

File eyecandy/core.py

 
 from collections import namedtuple
 import decimal
-import functools
 import math
 import os
 import re
 
 # constants
 PYTHON_MAIN_VER = int(sys.version[:1])
-F24P = 24 / 1.001
-F30P = 30 / 1.001
-
+FPS_NTSC_FILM = 24000 / 1001
+FPS_NTSC = 30000 / 1001
+FPS_NTSC_DOUBLE = 60000 / 1001
+FPS_NTSC_QUAD = 120000 / 1001
+FPS_FILM = 24
+FPS_PAL = 25
+FPS_PAL_DOUBLE= 50
+FPS_PAL_QUAD = 100
 #TODO:
 # ENC_ANSI = 0
 # ...
                  scale=(100, 100), ssampling=8):
         self.scale = (scale[0] / 100, scale[1] / 100)
         self.ssampling = ssampling
-        #print(self.ssampling)
         self.bord = bord
         self.font = set_font(
             family, pixelsize, spacing, bold, italic, self.ssampling)
         seg, ms = divmod(time_diff, 1000)
         m, s = divmod(seg, 60)
         h, m = divmod(m, 60)
-        cs = int(round(ms / 10, 0))
+
+        hstr = ''
+        mstr = ''
+        sstr = ''
 
         if h:
-            h = '{:d} hours '.format(h)
-        else:
-            h = ''
+            hstr = ' {:d} hours '.format(h)
         if m:
-            m = '{:d} minutes '.format(m)
-        else:
-            m = ''
+            mstr = ' {:d} minutes '.format(m)
         if s:
-            s = '{:d} seconds '.format(s)
-        else:
-            s = ''
+            sstr = ' {:d} seconds '.format(s)
 
-        time_message = ('{:s} took {:s}{:s}{:s}'
-                        '{:d}.{:02d} miliseconds.'.format(
-                method.__name__, h, m, s, ms, cs))
+        time_message = ('{:s} took{:s}{:s}{:s}'
+                        '{:3d} miliseconds.'.format(
+                method.__name__, hstr, mstr, sstr, ms))
 
         sys.stdout.write(time_message)
         sys.stdout.write('\n')
         return "<class '{:s}'>".format(self._typename)
 
 
+#def ms_to_structime(timems):
+    #pass
+
+
 def ms_to_strtime(timems):
     """Convert Milliseconds to ASS string time"""
     s, ms = divmod(timems, 1000)
     m, s = divmod(s, 60)
     h, m = divmod(m, 60)
     cs = int(round(ms_to_cs(ms), 0))
-
-    if cs >= 100:
-        s = int(cs / 100)
-        cs -= s * 100
-
     return '{:01d}:{:02d}:{:02d}.{:02d}'.format(h, m, s, cs)
 
 
     return ms / 1000
 
 
-def ms_to_frames(ms, framerate=F24P):
+def ms_to_frames(ms, framerate=FPS_NTSC_FILM):
     """Convert Frames to Milliseconds"""
     return int(math.floor(framerate * ms_to_s(ms)))
 
     return ms_to_strtime(cs_to_ms(cs))
 
 
-def cs_to_frames(cs, framerate=F24P):
+def cs_to_frames(cs, framerate=FPS_NTSC_FILM):
     """Convert Centiseconds to Frames"""
     return ms_to_frames(cs_to_ms(cs), framerate)
 
     return ms_to_strtime(s_to_ms(s))
 
 
-def s_to_frames(s, framerate=F24P):
+def s_to_frames(s, framerate=FPS_NTSC_FILM):
     """Convert Seconds to Frames"""
     return ms_to_frames(s_to_ms(s), framerate)
 
 
-def frames_to_s(frames, framerate=F24P):
+def frames_to_s(frames, framerate=FPS_NTSC_FILM):
     """Convert Frames to Seconds"""
     return frames / framerate
 
 
 def strtime_to_ms(time):
     """Convert ASS string time to Milliseconds"""
+
     h, m, s = time.split(':')
     s, cs = s.split('.')
     error = ('Check if the time format is correct H:MM:SS.CC '
     def s(self):
         return ms_to_s(self.ms)
 
-    def frames(self, framerate=F24P):
+    def frames(self, framerate=FPS_NTSC_FILM):
         return ms_to_frames(self.ms, framerate)
 
     @property

File eyecandy/effector.py

 
 
                 chard = [self.layer, core.ASSTime(start).strtime,
-                         core.ASSTime(end).strtime, self.style.name, self.actor,
-                         self.effect, char.strip(), self.comment, s.inline,
+                         core.ASSTime(end).strtime, self.style.name,
+                         self.actor, self.effect, char.strip(),
+                         self.comment, s.inline,
                          cleft, s.end, s.start]
                 chars.append(ASSChar(chard, self._style, self._resolution, i))
 
     """ASS Generator"""
 
     def __init__(self, script_input, script_output=None,
-                 original=True, framerate=core.F24P, adjustment=0):
+                 original=True, framerate=core.FPS_NTSC_FILM):
         self._script_input = script_input
         self._script_output = script_output
         self._original = original
         self._framerate = framerate
-        self._adjustment = adjustment
         self._writer = writer.ASSWriter(script_output)
         self._reader = reader.ASSReader(script_input).read()
         self._add_default()    # Use values from the loaded subtitle
         """Overwrite the original script video path (Aegisub)"""
         self._reader['video'] = self._writer.video(path, zoom)
 
-    def setdummyvideo(self, framerate=core.F24P, frames=3000,
+    def setdummyvideo(self, framerate=core.FPS_NTSC_FILM, frames=3000,
                       color=crayon.Color(), checkboard=False, zoom=8):
         """Overwrite the original script video for a dummyvideo (Aegisub)"""
         color = '&H00' + color.bgrhex
         try:
             num, den = ar.split(':')
             ar = 'c%s' %(core.round_format_str(num / den, 6))
-            self._reader['video_aspect_ratio'] = self._writer.videoaspectratio(ar)
+            ar = self._writer.videoaspectratio(ar)
+            self._reader['video_aspect_ratio'] = ar
         except AttributeError:
-            ar = 'c%s' %(core.round_format_str(ar, 6))
-            self._reader['video_aspect_ratio'] = self._writer.videoaspectratio(ar)
-
+            ar = '%s' %(core.round_format_str(ar, 6))
+            ar = self._writer.videoaspectratio(ar)
+            self._reader['video_aspect_ratio'] = ar
     def _add_default_ar(self):
         """Add default video aspect ratio"""
         ar = float(self.getvideoar().replace('c', ''))
         i = 0
         for dlg in self._reader['dialog']:
             if dlg[6] and not dlg[-1]:
-                #yield dtext(dlg, self._getdstyles(), self.getresolution(), i)
                 dialog.append(
                     dtext(dlg, self._getdstyles(), self.getresolution(), i))
                 i += 1

File eyecandy/writer.py

                     **kwargs)
         return self._resolution
 
-    def dummyvideo(self, framerate=core.F24P, frames=3000, color='&H00000000',
+    def dummyvideo(self, framerate=core.FPS_NTSC_FILM, frames=3000, color='&H00000000',
                    checkboard=False, zoom=8):
         """Set dummyvideo