home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1375 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.8 KB  |  79 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. import ctypes
  7. import os
  8. import sys
  9. from calibre import iswindows, isosx
  10.  
  11. class WandException(Exception):
  12.     pass
  13.  
  14. if iswindows:
  15.     pass
  16. elif isosx:
  17.     pass
  18.  
  19. _lib_name = 'libWand.so'
  20. if iswindows and hasattr(sys, 'frozen'):
  21.     im_dir = os.path.join(os.path.dirname(sys.executable), 'ImageMagick')
  22.     os.putenv('PATH', im_dir + ';' + os.environ['PATH'])
  23.  
  24. _libwand = None
  25.  
  26. try:
  27.     _libwand = ctypes.cdll.LoadLibrary(_lib_name)
  28. except:
  29.     pass
  30.  
  31.  
  32. class Severity(ctypes.c_long):
  33.     pass
  34.  
  35.  
  36. class String(ctypes.c_char_p):
  37.     
  38.     def __del__(self):
  39.         _libwand.MagickRelinquishMemory(self)
  40.  
  41.     
  42.     def __str__(self):
  43.         return self.value
  44.  
  45.  
  46. if _libwand is not None:
  47.     _libwand.MagickGetException.argtypes = [
  48.         ctypes.c_void_p,
  49.         ctypes.POINTER(Severity)]
  50.     _libwand.MagickGetException.restype = String
  51.  
  52.  
  53. def get_exception(wand):
  54.     severity = Severity()
  55.     desc = _libwand.MagickGetException(wand, ctypes.byref(severity))
  56.     return str(desc)
  57.  
  58.  
  59. def convert(source, dest):
  60.     if _libwand is None:
  61.         raise WandException('Could not find ImageMagick library')
  62.     _libwand is None
  63.     if not _libwand.MagickWandGenesis():
  64.         raise WandException('Unable to initialize Image Magick')
  65.     _libwand.MagickWandGenesis()
  66.     wand = _libwand.NewMagickWand()
  67.     if wand <= 0:
  68.         raise WandException('Unable to initialize Image Magick. Cannot create wand.')
  69.     wand <= 0
  70.     if not _libwand.MagickReadImage(wand, source):
  71.         raise WandException('Cannot read image %s: %s' % (source, get_exception(wand)))
  72.     _libwand.MagickReadImage(wand, source)
  73.     if not _libwand.MagickWriteImage(wand, dest):
  74.         raise WandException('Cannot write image to file %s: %s' % (source, get_exception(wand)))
  75.     _libwand.MagickWriteImage(wand, dest)
  76.     _libwand.DestroyMagickWand(wand)
  77.     _libwand.MagickWandTerminus()
  78.  
  79.