Example #1
0
def convertfileavitobmp(avi_file_name, frame_num=0):
    bmp2avi=shortfilename(gethelperbinary('bmp2avi'))
    with common.usetempfile('bmp') as _bmp:
        bmp_file_name=shortfilename(_bmp)
        run(bmp2avi, '-t', `frame_num`, '-i', shortfilename(avi_file_name),
            '-o', bmp_file_name)
        return wx.Image(bmp_file_name)
Example #2
0
def convertfileavitobmp(avi_file_name, frame_num=0):
    bmp2avi = shortfilename(gethelperbinary('bmp2avi'))
    with common.usetempfile('bmp') as _bmp:
        bmp_file_name = shortfilename(_bmp)
        run(bmp2avi, '-t', ` frame_num `, '-i', shortfilename(avi_file_name),
            '-o', bmp_file_name)
        return wx.Image(bmp_file_name)
Example #3
0
def BPFSImageFile(fshandler, location, name=None, img=None, width=-1, height=-1, valign="center", bgcolor=None):
    """Handles image files

    If we have to do any conversion on the file then we return PNG
    data.  This used to be a class derived from wx.FSFile, but due to
    various wxPython bugs it instead returns the parameters to make a
    wx.FSFile since a new one has to be made every time.
    """
    # if this is a bad or non-existing image file, use the dummy one!
    if name is None and img is None:
        name=guihelper.getresourcefile('wallpaper.png')
    # special fast path if we aren't resizing or converting image
    if img is None and width<0 and height<0:
        mime=guihelper.getwxmimetype(name)
        # wxPython 2.5.3 has a new bug and fails to read bmp files returned as a stream
        if mime not in (None, "image/x-bmp"):
            return (open(name, "rb"), location, mime, "", wx.DateTime_Now())

    if img is None:
        img=wx.Image(name)

    if width>0 and height>0:
        b=ScaleImageIntoBitmap(img, width, height, bgcolor, valign)
    else:
        b=img.ConvertToBitmap()

    with common.usetempfile('png') as f:
        if not b.SaveFile(f, wx.BITMAP_TYPE_PNG):
            raise Exception, "Saving to png failed"
        data=open(f, "rb").read()
        return (cStringIO.StringIO(data), location, "image/png", "", wx.DateTime_Now())
Example #4
0
 def saveimage_PNG(self, img, imgparams):
     # ::TODO:: this is where the file size constraints should be examined
     # and obeyed
     with common.usetempfile('png') as f:
         if img.SaveFile(f, wx.BITMAP_TYPE_PNG):
             return file(f, 'rb').read()
         return False
Example #5
0
 def saveimage_PNG(self, img, imgparams):
     # ::TODO:: this is where the file size constraints should be examined
     # and obeyed
     with common.usetempfile('png') as f:
         if img.SaveFile(f, wx.BITMAP_TYPE_PNG):
             return file(f, 'rb').read()
         return False
Example #6
0
 def saveimage_BMP(self, img, imgparams):
     if img.ComputeHistogram(wx.ImageHistogram())<=236: # quantize only does 236 or less
         img.SetOptionInt(wx.IMAGE_OPTION_BMP_FORMAT, wx.BMP_8BPP)
     with common.usetempfile('bmp') as f:
         if img.SaveFile(f, wx.BITMAP_TYPE_BMP):
             return file(f, 'rb').read()
         return False
Example #7
0
def convertjpgtoavi(jpg_data, avi_file_name, fps=4, new_file=False):
    bmp2avi=shortfilename(gethelperbinary('bmp2avi'))
    if new_file:
        # delete any existing file and start fresh
        try:
            os.remove(avi_file_name)
        except:
            pass
    # convert the jpg data to bmp data
    with contextlib.nested(common.usetempfile('jpg'),
                           common.usetempfile('bmp')) as (_jpg, _bmp):
        jpg_name=shortfilename(_jpg)
        bmp_name=shortfilename(_bmp)
        file(jpg_name, "wb").write(jpg_data)
        wx.Image(jpg_name).SaveFile(bmp_name, wx.BITMAP_TYPE_BMP)
        # add the bmp frame to the avi file
        run(bmp2avi, '-f', `fps`, '-i', bmp_name, '-o', avi_file_name)
Example #8
0
def convertjpgtoavi(jpg_data, avi_file_name, fps=4, new_file=False):
    bmp2avi = shortfilename(gethelperbinary('bmp2avi'))
    if new_file:
        # delete any existing file and start fresh
        try:
            os.remove(avi_file_name)
        except:
            pass
    # convert the jpg data to bmp data
    with contextlib.nested(common.usetempfile('jpg'),
                           common.usetempfile('bmp')) as (_jpg, _bmp):
        jpg_name = shortfilename(_jpg)
        bmp_name = shortfilename(_bmp)
        file(jpg_name, "wb").write(jpg_data)
        wx.Image(jpg_name).SaveFile(bmp_name, wx.BITMAP_TYPE_BMP)
        # add the bmp frame to the avi file
        run(bmp2avi, '-f', ` fps `, '-i', bmp_name, '-o', avi_file_name)
Example #9
0
 def getringtones(self, result):
     result=com_lgvx4400.Phone.getringtones(self, result)
     if not conversions.helperavailable('pvconv'):
         return result
     media=result['ringtone']
     # get& convert the voice memo files
     with contextlib.nested(common.usetempfile('qcp'),
                            common.usetempfile('wav')) as (_qcp_file, _wav_file):
         try:
             vmemo_files=self.listfiles(self.VoiceMemoDir)
             keys=vmemo_files.keys()
             for k in keys:
                 if k.endswith('.qcp'):
                     key_name='VoiceMemo'+k[-8:-4]
                     file(_qcp_file, 'wb').write(self.getfilecontents(k, True))
                     conversions.convertqcptowav(_qcp_file, _wav_file)
                     media[key_name]=file(_wav_file, 'rb').read()
         except:
             if __debug__:
                 raise
     result['ringtone']=media
     return result
Example #10
0
def converttomp3(inputfilename, bitrate, samplerate, channels):
    """Reads inputfilename and returns data for an mp3 conversion

    @param bitrate: bitrate to use in khz (ie 16 is 16000 bits per second)
    @param samplerate: audio sampling rate in Hertz
    @param channels: 1 is mono, 2 is stereo
    """
    ffmpeg=gethelperbinary("ffmpeg")
    with common.usetempfile('mp3') as mp3file:
        try:
            run(ffmpeg, "-i", shortfilename(inputfilename), "-hq", "-ab", `bitrate`, "-ar", `samplerate`, "-ac", `channels`, shortfilename(mp3file))
        except common.CommandExecutionFailed, e:
            # we get this exception on bad parameters, or any other
            # issue so we assume bad parameters for the moment.
            raise ConversionFailed, ' '.join(e.args)+'\n'+e.logstr
        return file(mp3file, "rb").read()
Example #11
0
def converttomp3(inputfilename, bitrate, samplerate, channels):
    """Reads inputfilename and returns data for an mp3 conversion

    @param bitrate: bitrate to use in khz (ie 16 is 16000 bits per second)
    @param samplerate: audio sampling rate in Hertz
    @param channels: 1 is mono, 2 is stereo
    """
    ffmpeg = gethelperbinary("ffmpeg")
    with common.usetempfile('mp3') as mp3file:
        try:
            run(ffmpeg, "-i", shortfilename(inputfilename), "-hq", "-ab",
                ` bitrate `, "-ar", ` samplerate `, "-ac", ` channels `,
                shortfilename(mp3file))
        except common.CommandExecutionFailed, e:
            # we get this exception on bad parameters, or any other
            # issue so we assume bad parameters for the moment.
            raise ConversionFailed, ' '.join(e.args) + '\n' + e.logstr
        return file(mp3file, "rb").read()
Example #12
0
def convertfilelgbittobmp(bit_file_name):
    "File-based wrapper for convertlgbittobmp."
    with common.usetempfile('png') as bmp:
        bmpdata = convertlgbittobmp(file(bit_file_name, "rb").read())
        file(bmp, "wb").write(bmpdata)
        return wx.Image(bmp)
Example #13
0
def convertavitobmp(avi_data, frame_num=0):
    with common.usetempfile('avi') as _avi:
        avi_file = shortfilename(_avi)
        file(avi_file, 'wb').write(avi_data)
        return convertfileavitobmp(avi_file, frame_num)
Example #14
0
def convertfilelgbittobmp(bit_file_name):
    "File-based wrapper for convertlgbittobmp."
    with common.usetempfile('png') as bmp:
        bmpdata=convertlgbittobmp(file(bit_file_name,"rb").read())
        file(bmp, "wb").write(bmpdata)
        return wx.Image(bmp)
Example #15
0
 def saveimage_JPEG(self, img, imgparams):
     img.SetOptionInt("quality", 100)
     with common.usetempfile('jpg') as f:
         if img.SaveFile(f, wx.BITMAP_TYPE_JPEG):
             return file(f, 'rb').read()
         return False
Example #16
0
def convertavitobmp(avi_data, frame_num=0):
    with common.usetempfile('avi') as _avi:
        avi_file=shortfilename(_avi)
        file(avi_file, 'wb').write(avi_data)
        return convertfileavitobmp(avi_file, frame_num)
Example #17
0
 def saveimage_JPEG(self, img, imgparams):
     img.SetOptionInt("quality", 100)        
     with common.usetempfile('jpg') as f:
         if img.SaveFile(f, wx.BITMAP_TYPE_JPEG):
             return file(f, 'rb').read()
         return False