Workaround MagickConstituteImage not working on OS X

This commit is contained in:
Kovid Goyal 2013-12-05 18:52:41 +05:30
parent a7b7577fd1
commit 49346811b7
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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()