Changeset c2803e5


Ignore:
Timestamp:
12/24/08 19:54:06 (5 years ago)
Author:
olivier <>
Branches:
master, crem, crem2, dev, dev2, diadems, feature/breadcrumbs, feature/ts-0.5, feature/ts-0.5.4, feature/writecache, forma, generic, instru_search, lam, lam2, mapsv3, merge, nlivemulti, production, release/1.4.4, sabiod, security, server, social, storage, telecaster, test, video
Children:
583df3f
Parents:
40f3d09
git-author:
olivier <> (12/24/08 19:54:06)
git-committer:
olivier <> (12/24/08 19:54:06)
Message:

allow visualization colors customization

Location:
telemeta/visualization
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • telemeta/visualization/api.py

    r6699ec9 rc2803e5  
    2121        """ 
    2222 
     23    def set_colors(self, background=None, scheme=None): 
     24        """Set the colors used for image generation. background is a RGB tuple,  
     25        and scheme a a predefined color theme name""" 
     26        pass 
     27 
    2328    def render(media_item, width=None, height=None, options=None): 
    2429        """Generator that streams the visualization output as a PNG image""" 
  • telemeta/visualization/spectrogram.py

    re84ac08 rc2803e5  
    2626        return "Spectrogram 1" 
    2727     
     28    def set_colors(self, background=None, scheme=None): 
     29        pass 
     30 
    2831    def render(self, media_item, options=None): 
    2932        """Generator that streams the spectral view as a PNG image""" 
  • telemeta/visualization/spectrogram2.py

    r9f20f85 rc2803e5  
    2626    def get_name(self): 
    2727        return "Spectrogram (octave)" 
     28 
     29    def set_colors(self, background=None, scheme=None): 
     30        pass 
    2831     
    29     def render(self, media_item, options=None): 
     32    def render(self, media_item, width=None, height=None, options=None): 
    3033        """Generator that streams the spectral view as a PNG image""" 
    3134 
  • telemeta/visualization/spectrogram3.py

    r1f728bb rc2803e5  
    1919    implements(IMediaItemVisualizer) 
    2020 
     21    bg_color = None 
     22    color_scheme = None 
     23 
    2124    def get_id(self): 
    2225        return "spectrogram3" 
     
    2528        return "Spectrogram (audiolab)" 
    2629     
     30    def set_colors(self, background=None, scheme=None): 
     31        self.bg_color = background 
     32        self.color_scheme = scheme 
     33 
    2734    def render(self, media_item, width=None, height=None, options=None): 
    2835        """Generator that streams the spectrogram as a PNG image with a python method""" 
     
    4148             
    4249        fft_size = 2048 
    43         args = (wav_file, pngFile.name, image_width, image_height, fft_size) 
     50        args = (wav_file, pngFile.name, image_width, image_height, fft_size,  
     51                self.bg_color, self.color_scheme) 
    4452        create_spectrogram_png(*args) 
    4553 
  • telemeta/visualization/spectrogram4.py

    r1f728bb rc2803e5  
    1919    implements(IMediaItemVisualizer) 
    2020 
     21    bg_color = None 
     22    color_scheme = None 
     23 
    2124    def get_id(self): 
    2225        return "spectrogram4" 
     
    2528        return "Spectrogram (audiolab large)" 
    2629     
     30    def set_colors(self, background=None, scheme=None): 
     31        self.bg_color = background 
     32        self.color_scheme = scheme 
     33 
    2734    def render(self, media_item, width=None, height=None, options=None): 
    2835        """Generator that streams the spectrogram as a PNG image with a python method""" 
     
    4148             
    4249        fft_size = 2048 
    43         args = (wav_file, pngFile.name, image_width, image_height, fft_size) 
     50        args = (wav_file, pngFile.name, image_width, image_height, fft_size,  
     51                self.bg_color, self.color_scheme) 
    4452        create_spectrogram_png(*args) 
    4553 
  • telemeta/visualization/wav2png.py

    r1f728bb rc2803e5  
    2929import scikits.audiolab as audiolab 
    3030 
     31color_schemes = { 
     32    'default': { 
     33        'waveform': [(50,0,200), (0,220,80), (255,224,0), (255,0,0)], 
     34        'spectrogram': [(0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100), 
     35                      (224,224,44), (255,60,30), (255,255,255)] 
     36    }, 
     37    'purple': { 
     38        'waveform': [(173,173,173), (147,149,196), (77,80,138), (108,66,0)], 
     39        'spectrogram': [(0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100), 
     40                      (224,224,44), (255,60,30), (255,255,255)] 
     41    } 
     42} 
     43 
    3144class TestAudioFile(object): 
    3245    """A class that mimics audiolab.sndfile but generates noise instead of reading 
     
    245258 
    246259class WaveformImage(object): 
    247     def __init__(self, image_width, image_height): 
    248         self.image = Image.new("RGB", (image_width, image_height)) 
     260    def __init__(self, image_width, image_height, bg_color = None, color_scheme = None): 
     261        if not bg_color: 
     262            bg_color = (0,0,0) 
     263        if not color_scheme:  
     264            color_scheme = 'default' 
     265 
     266        self.image = Image.new("RGB", (image_width, image_height), bg_color) 
    249267         
    250268        self.image_width = image_width 
     
    254272        self.previous_x, self.previous_y = None, None 
    255273         
    256         colors = [ 
    257                     (50,0,200), 
    258                     (0,220,80), 
    259                     (255,224,0), 
    260                     (255,0,0), 
    261                  ] 
     274        colors = color_schemes[color_scheme]['waveform'] 
    262275         
    263276        # this line gets the old "screaming" colors back... 
     
    328341         
    329342class SpectrogramImage(object): 
    330     def __init__(self, image_width, image_height, fft_size): 
     343    def __init__(self, image_width, image_height, fft_size, bg_color = None, color_scheme = None): 
     344 
     345        #FIXME: bg_color is ignored 
     346 
     347        if not color_scheme:  
     348            color_scheme = 'default' 
     349 
    331350        self.image = Image.new("P", (image_height, image_width)) 
    332351         
     
    335354        self.fft_size = fft_size 
    336355         
    337         colors = [ 
    338                     (0, 0, 0), 
    339                     (58/4,68/4,65/4), 
    340                     (80/2,100/2,153/2), 
    341                     (90,180,100), 
    342                     (224,224,44), 
    343                     (255,60,30), 
    344                     (255,255,255) 
    345                  ] 
     356        colors = color_schemes[color_scheme]['spectrogram'] 
    346357         
    347358        self.image.putpalette(interpolate_colors(colors, True)) 
     
    379390 
    380391 
    381 def create_wavform_png(input_filename, output_filename_w, image_width, image_height, fft_size): 
     392def create_wavform_png(input_filename, output_filename_w, image_width, image_height, fft_size, 
     393                       bg_color = None, color_scheme = None): 
    382394    audio_file = audiolab.sndfile(input_filename, 'read') 
    383395 
     
    385397    processor = AudioProcessor(audio_file, fft_size, numpy.hanning) 
    386398     
    387     waveform = WaveformImage(image_width, image_height) 
     399    waveform = WaveformImage(image_width, image_height, bg_color, color_scheme) 
    388400     
    389401    for x in range(image_width): 
     
    405417    print " done" 
    406418 
    407 def create_spectrogram_png(input_filename, output_filename_s, image_width, image_height, fft_size): 
     419def create_spectrogram_png(input_filename, output_filename_s, image_width, image_height, fft_size, 
     420                           bg_color = None, color_scheme = None): 
    408421    audio_file = audiolab.sndfile(input_filename, 'read') 
    409422 
     
    411424    processor = AudioProcessor(audio_file, fft_size, numpy.hanning) 
    412425     
    413     spectrogram = SpectrogramImage(image_width, image_height, fft_size) 
     426    spectrogram = SpectrogramImage(image_width, image_height, fft_size, bg_color, color_scheme) 
    414427     
    415428    for x in range(image_width): 
  • telemeta/visualization/waveform.py

    r59ecfdd rc2803e5  
    2929        return "Waveform" 
    3030     
     31    def set_colors(self, background=None, scheme=None): 
     32        pass 
     33 
    3134    def render(self, media_item, options=None): 
    3235        """Generator that streams the waveform as a PNG image""" 
  • telemeta/visualization/waveform2.py

    r9f20f85 rc2803e5  
    2929        return "Waveform (octave)" 
    3030     
     31    def set_colors(self, background=None, scheme=None): 
     32        pass 
     33 
    3134    def render(self, media_item, options=None): 
    3235        """Generator that streams the temporal view as a PNG image""" 
  • telemeta/visualization/waveform3.py

    r1f728bb rc2803e5  
    1919    implements(IMediaItemVisualizer) 
    2020 
     21    bg_color = None 
     22    color_scheme = None 
     23 
    2124    def get_id(self): 
    2225        return "waveform3" 
     
    2427    def get_name(self): 
    2528        return "Waveform (audiolab)" 
     29 
     30    def set_colors(self, background=None, scheme=None): 
     31        self.bg_color = background 
     32        self.color_scheme = scheme 
    2633 
    2734    def render(self, media_item, width=None, height=None, options=None): 
     
    4148 
    4249        fft_size = 2048 
    43         args = (wav_file, pngFile.name, image_width, image_height, fft_size) 
     50        args = (wav_file, pngFile.name, image_width, image_height, fft_size,  
     51                self.bg_color, self.color_scheme) 
    4452        create_wavform_png(*args) 
    4553 
  • telemeta/visualization/waveform4.py

    r1f728bb rc2803e5  
    1919    implements(IMediaItemVisualizer) 
    2020 
     21    bg_color = None 
     22    color_scheme = None 
     23 
    2124    def get_id(self): 
    2225        return "waveform4" 
     
    2528        return "Waveform (audiolab large)" 
    2629 
    27     def render(self, media_item,  width=None, height=None, options=None): 
     30    def set_colors(self, background=None, scheme=None): 
     31        self.bg_color = background 
     32        self.color_scheme = scheme 
     33 
     34    def render(self, media_item, width=None, height=None, options=None): 
    2835        """Generator that streams the waveform as a PNG image with a python method""" 
    2936 
     
    4148 
    4249        fft_size = 2048 
    43         args = (wav_file, pngFile.name, image_width, image_height, fft_size) 
     50        args = (wav_file, pngFile.name, image_width, image_height, fft_size, self.bg_color, self.color_scheme) 
    4451        create_wavform_png(*args) 
    4552 
Note: See TracChangeset for help on using the changeset viewer.