Fix macOS crash when drawing image with draw_image() in some scenarios (#1372)
This commit is contained in:
parent
ea27dafe1e
commit
d9a3fb32da
@ -50,28 +50,27 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
|
|||||||
{
|
{
|
||||||
if (!linedelta) linedelta = W*abs(delta);
|
if (!linedelta) linedelta = W*abs(delta);
|
||||||
|
|
||||||
uchar *tmpBuf = 0;
|
|
||||||
if (!cb) {
|
if (!cb) {
|
||||||
if (delta < 0) buf -= (W-1)*(-delta);
|
if (delta < 0) buf -= (W-1)*(-delta);
|
||||||
if (linedelta < 0) buf -= (H-1)*abs(linedelta);
|
if (linedelta < 0) buf -= (H-1)*abs(linedelta);
|
||||||
}
|
}
|
||||||
const void *array = buf;
|
const void *array = buf;
|
||||||
if (cb || driver->has_feature(Fl_Quartz_Graphics_Driver::PRINTER)) {
|
// Always duplicate the image data because Quartz delays using that data which may have
|
||||||
tmpBuf = new uchar[ H*W*abs(delta) ];
|
// been released when used (see #1372).
|
||||||
if (cb) {
|
uchar *tmpBuf = new uchar[ H*W*abs(delta) ];
|
||||||
for (int i=0; i<H; i++) {
|
if (cb) {
|
||||||
cb(userdata, 0, i, W, tmpBuf+i*W*abs(delta));
|
for (int i=0; i<H; i++) {
|
||||||
}
|
cb(userdata, 0, i, W, tmpBuf+i*W*abs(delta));
|
||||||
} else {
|
}
|
||||||
uchar *p = tmpBuf;
|
} else {
|
||||||
for (int i=0; i<H; i++) {
|
uchar *p = tmpBuf;
|
||||||
memcpy(p, buf+i*abs(linedelta), W*abs(delta));
|
for (int i=0; i<H; i++) {
|
||||||
p += W*abs(delta);
|
memcpy(p, buf+i*abs(linedelta), W*abs(delta));
|
||||||
}
|
p += W*abs(delta);
|
||||||
}
|
}
|
||||||
array = (void*)tmpBuf;
|
|
||||||
linedelta = W*abs(delta);
|
|
||||||
}
|
}
|
||||||
|
array = (void*)tmpBuf;
|
||||||
|
linedelta = W*abs(delta);
|
||||||
// create an image context
|
// create an image context
|
||||||
CGColorSpaceRef lut = 0;
|
CGColorSpaceRef lut = 0;
|
||||||
if (abs(delta)<=2)
|
if (abs(delta)<=2)
|
||||||
@ -81,8 +80,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
|
|||||||
// a release callback is necessary when the gc is a print context because the image data
|
// a release callback is necessary when the gc is a print context because the image data
|
||||||
// must be kept until the page is closed. Thus tmpBuf can't be deleted here. It's too early.
|
// must be kept until the page is closed. Thus tmpBuf can't be deleted here. It's too early.
|
||||||
CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, abs(linedelta)*H,
|
CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, abs(linedelta)*H,
|
||||||
tmpBuf ? dataReleaseCB : NULL
|
dataReleaseCB);
|
||||||
);
|
|
||||||
CGImageRef img = CGImageCreate( W, H, 8, 8*abs(delta), abs(linedelta),
|
CGImageRef img = CGImageCreate( W, H, 8, 8*abs(delta), abs(linedelta),
|
||||||
lut, abs(delta)&1?kCGImageAlphaNone:kCGImageAlphaLast,
|
lut, abs(delta)&1?kCGImageAlphaNone:kCGImageAlphaLast,
|
||||||
src, 0L, false, kCGRenderingIntentDefault);
|
src, 0L, false, kCGRenderingIntentDefault);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user