mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Workaround MagickConstituteImage not working on OS X
This commit is contained in:
parent
a7b7577fd1
commit
49346811b7
@ -14,6 +14,7 @@ from PyQt4.Qt import (
|
|||||||
QPointF, QPen, pyqtSignal, QUndoCommand, QUndoStack, QIcon, QImage, QByteArray)
|
QPointF, QPen, pyqtSignal, QUndoCommand, QUndoStack, QIcon, QImage, QByteArray)
|
||||||
|
|
||||||
from calibre import fit_image
|
from calibre import fit_image
|
||||||
|
from calibre.constants import isosx
|
||||||
from calibre.gui2 import error_dialog, pixmap_to_data
|
from calibre.gui2 import error_dialog, pixmap_to_data
|
||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
from calibre.utils.magick import Image
|
from calibre.utils.magick import Image
|
||||||
@ -93,6 +94,14 @@ def get_pixel_map():
|
|||||||
return _qimage_pixel_map
|
return _qimage_pixel_map
|
||||||
|
|
||||||
def qimage_to_magick(img):
|
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()
|
fmt = get_pixel_map()
|
||||||
if not img.hasAlphaChannel():
|
if not img.hasAlphaChannel():
|
||||||
if img.format() != img.Format_RGB32:
|
if img.format() != img.Format_RGB32:
|
||||||
@ -104,7 +113,6 @@ def qimage_to_magick(img):
|
|||||||
img = QImage(img)
|
img = QImage(img)
|
||||||
img.setFormat(img.Format_ARGB32)
|
img.setFormat(img.Format_ARGB32)
|
||||||
raw = img.constBits().ascapsule()
|
raw = img.constBits().ascapsule()
|
||||||
ans = Image()
|
|
||||||
ans.constitute(img.width(), img.height(), fmt, raw)
|
ans.constitute(img.width(), img.height(), fmt, raw)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
@ -127,6 +127,14 @@ def test_woff():
|
|||||||
test()
|
test()
|
||||||
print ('WOFF ok!')
|
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():
|
def test():
|
||||||
test_plugins()
|
test_plugins()
|
||||||
test_lxml()
|
test_lxml()
|
||||||
@ -138,6 +146,7 @@ def test():
|
|||||||
test_qt()
|
test_qt()
|
||||||
test_html5lib()
|
test_html5lib()
|
||||||
test_regex()
|
test_regex()
|
||||||
|
test_magick()
|
||||||
if iswindows:
|
if iswindows:
|
||||||
test_winutil()
|
test_winutil()
|
||||||
test_wpd()
|
test_wpd()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user