From 49346811b7583648c18a8ae3af4734faf20d5abd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 5 Dec 2013 18:52:41 +0530 Subject: [PATCH] Workaround MagickConstituteImage not working on OS X --- src/calibre/gui2/tweak_book/editor/canvas.py | 10 +++++++++- src/calibre/test_build.py | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/editor/canvas.py b/src/calibre/gui2/tweak_book/editor/canvas.py index 694dd06194..df29bcbcc4 100644 --- a/src/calibre/gui2/tweak_book/editor/canvas.py +++ b/src/calibre/gui2/tweak_book/editor/canvas.py @@ -14,6 +14,7 @@ from PyQt4.Qt import ( QPointF, QPen, pyqtSignal, QUndoCommand, QUndoStack, QIcon, QImage, QByteArray) from calibre import fit_image +from calibre.constants import isosx from calibre.gui2 import error_dialog, pixmap_to_data from calibre.utils.config_base import tweaks from calibre.utils.magick import Image @@ -93,6 +94,14 @@ def get_pixel_map(): return _qimage_pixel_map def qimage_to_magick(img): + ans = Image() + if isosx: + # For some reson, on OSX MagickConstituteImage fails, and I can't be + # bothered figuring out why. Dumping to uncompressed PNG is reasonably + # fast. + raw = pixmap_to_data(img, 'PNG', quality=100) + ans.load(raw) + return ans fmt = get_pixel_map() if not img.hasAlphaChannel(): if img.format() != img.Format_RGB32: @@ -104,7 +113,6 @@ def qimage_to_magick(img): img = QImage(img) img.setFormat(img.Format_ARGB32) raw = img.constBits().ascapsule() - ans = Image() ans.constitute(img.width(), img.height(), fmt, raw) return ans diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index e06eb5f75e..7acc36f8a0 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -127,6 +127,14 @@ def test_woff(): test() print ('WOFF ok!') +def test_magick(): + from calibre.utils.magick import create_canvas + i = create_canvas(100, 100) + from calibre.gui2.tweak_book.editor.canvas import qimage_to_magick, magick_to_qimage + img = magick_to_qimage(i) + i = qimage_to_magick(img) + print ('magick OK!') + def test(): test_plugins() test_lxml() @@ -138,6 +146,7 @@ def test(): test_qt() test_html5lib() test_regex() + test_magick() if iswindows: test_winutil() test_wpd()