~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/oeb/transforms/rescale.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
 
3
from __future__ import with_statement
 
4
 
 
5
__license__   = 'GPL v3'
 
6
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
 
7
__docformat__ = 'restructuredtext en'
 
8
 
 
9
from calibre import fit_image
 
10
 
 
11
class RescaleImages(object):
 
12
    'Rescale all images to fit inside given screen size'
 
13
 
 
14
    def __call__(self, oeb, opts):
 
15
        from PyQt4.Qt import QApplication, QImage, Qt
 
16
        from calibre.gui2 import pixmap_to_data
 
17
        self.oeb, self.opts, self.log = oeb, opts, oeb.log
 
18
        page_width, page_height = opts.dest.width, opts.dest.height
 
19
        for item in oeb.manifest:
 
20
            if item.media_type.startswith('image'):
 
21
                raw = item.data
 
22
                if not raw: continue
 
23
                if QApplication.instance() is None:
 
24
                    QApplication([])
 
25
 
 
26
                img = QImage(10, 10, QImage.Format_ARGB32_Premultiplied)
 
27
                if not img.loadFromData(raw): continue
 
28
                width, height = img.width(), img.height()
 
29
                scaled, new_width, new_height = fit_image(width, height,
 
30
                        page_width, page_height)
 
31
                if scaled:
 
32
                    self.log('Rescaling image', item.href)
 
33
                    img = img.scaled(new_width, new_height,
 
34
                            Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
 
35
                    item.data = pixmap_to_data(img)
 
36
 
 
37