mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Fix a crash when performing some image editing operations on 64 bit calibre builds
This commit is contained in:
parent
bd460282a5
commit
856db1901b
@ -14,7 +14,6 @@ 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.gui2.dnd import (
|
from calibre.gui2.dnd import (
|
||||||
IMAGE_EXTENSIONS, dnd_has_extension, dnd_has_image, dnd_get_image, DownloadDialog)
|
IMAGE_EXTENSIONS, dnd_has_extension, dnd_has_image, dnd_get_image, DownloadDialog)
|
||||||
@ -94,13 +93,6 @@ def get_pixel_map():
|
|||||||
|
|
||||||
def qimage_to_magick(img):
|
def qimage_to_magick(img):
|
||||||
ans = Image()
|
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:
|
||||||
@ -117,7 +109,7 @@ def qimage_to_magick(img):
|
|||||||
|
|
||||||
def magick_to_qimage(img):
|
def magick_to_qimage(img):
|
||||||
fmt = get_pixel_map()
|
fmt = get_pixel_map()
|
||||||
# ImageMagick can output only output raw data in some formats that can be
|
# ImageMagick can only output raw data in some formats that can be
|
||||||
# read into QImage directly, if the QImage format is not one of those, use
|
# read into QImage directly, if the QImage format is not one of those, use
|
||||||
# PNG
|
# PNG
|
||||||
if fmt in {'RGBA', 'BGRA'}:
|
if fmt in {'RGBA', 'BGRA'}:
|
||||||
|
@ -540,14 +540,14 @@ magick_Image_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
// Image.constitute {{{
|
// Image.constitute {{{
|
||||||
static PyObject *
|
static PyObject *
|
||||||
magick_Image_constitute(magick_Image *self, PyObject *args) {
|
magick_Image_constitute(magick_Image *self, PyObject *args) {
|
||||||
const char *map;
|
const char *map = NULL;
|
||||||
Py_ssize_t width, height;
|
unsigned int width = 0, height = 0;
|
||||||
PyObject *capsule;
|
PyObject *capsule = NULL;
|
||||||
MagickBooleanType res;
|
MagickBooleanType res = MagickFalse;
|
||||||
void *data;
|
void *data = NULL;
|
||||||
|
|
||||||
NULL_CHECK(NULL)
|
NULL_CHECK(NULL)
|
||||||
if (!PyArg_ParseTuple(args, "iisO", &width, &height, &map, &capsule)) return NULL;
|
if (!PyArg_ParseTuple(args, "IIsO", &width, &height, &map, &capsule)) return NULL;
|
||||||
|
|
||||||
if (!PyCapsule_CheckExact(capsule)) {
|
if (!PyCapsule_CheckExact(capsule)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "data is not a capsule object");
|
PyErr_SetString(PyExc_TypeError, "data is not a capsule object");
|
||||||
@ -557,7 +557,7 @@ magick_Image_constitute(magick_Image *self, PyObject *args) {
|
|||||||
data = PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule));
|
data = PyCapsule_GetPointer(capsule, PyCapsule_GetName(capsule));
|
||||||
if (data == NULL) return NULL;
|
if (data == NULL) return NULL;
|
||||||
|
|
||||||
res = MagickConstituteImage(self->wand, width, height, map, CharPixel, data);
|
res = MagickConstituteImage(self->wand, (size_t)width, (size_t)height, map, CharPixel, data);
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
return magick_set_exception(self->wand);
|
return magick_set_exception(self->wand);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user