Skip to content

Commit

Permalink
Replace CGDataProviderCreateDirect with ...CreateWithData
Browse files Browse the repository at this point in the history
Since it even more ... 'direct' and does not need weird callbacks
to copy data (not sure why I was using 'CreateDirect' in the first
place).
  • Loading branch information
TimurP committed Nov 4, 2016
1 parent 7607695 commit 30eebd8
Showing 1 changed file with 17 additions and 65 deletions.
82 changes: 17 additions & 65 deletions graf2d/cocoa/src/QuartzPixmap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,6 @@
#include "CocoaUtils.h"
#include "X11Colors.h"

//Call backs for data provider.
extern "C" {

//______________________________________________________________________________
const void* ROOT_QuartzImage_GetBytePointer(void *info)
{
assert(info != 0 && "ROOT_QuartzImage_GetBytePointer, info parameter is null");
return info;
}

//______________________________________________________________________________
void ROOT_QuartzImage_ReleaseBytePointer(void *, const void *)
{
//Do nothing.
}

//______________________________________________________________________________
std::size_t ROOT_QuartzImage_GetBytesAtPosition(void *info, void *buffer, off_t position,
std::size_t count)
{
std::copy((char *)info + position, (char *)info + position + count, (char*)buffer);
return count;
}

}

namespace X11 = ROOT::MacOSX::X11;
namespace Util = ROOT::MacOSX::Util;
namespace Quartz = ROOT::Quartz;
Expand Down Expand Up @@ -144,19 +118,14 @@ - (CGImageRef) createImageFromPixmap : (X11::Rectangle) cropArea
assert(cropArea.fWidth <= fWidth && "createImageFromPixmap:, bad cropArea.fWidth");
assert(cropArea.fHeight <= fHeight && "createImageFromPixmap:, bad cropArea.fHeight");

//
const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer,
ROOT_QuartzImage_ReleaseBytePointer,
ROOT_QuartzImage_GetBytesAtPosition, 0};

const unsigned scaledW = fWidth * fScaleFactor;
const unsigned scaledH = fHeight * fScaleFactor;


const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateDirect(&fData[0],
scaledW * scaledH * 4, &providerCallbacks));
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateWithData(nullptr, &fData[0],
scaledW * scaledH * 4, nullptr));
if (!provider.Get()) {
NSLog(@"QuartzPixmap: -pixmapToImage, CGDataProviderCreateDirect failed");
NSLog(@"QuartzPixmap: -pixmapToImage, CGDataProviderCreateWithData failed");
return 0;
}

Expand Down Expand Up @@ -463,14 +432,10 @@ - (id) initWithW : (unsigned) width H : (unsigned) height data : (unsigned char
std::copy(data, data + width * height * 4, &fImageData[0]);

fIsStippleMask = NO;
const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer,
ROOT_QuartzImage_ReleaseBytePointer,
ROOT_QuartzImage_GetBytesAtPosition, 0};

const Util::CFScopeGuard<CGDataProviderRef>
provider(CGDataProviderCreateDirect(&fImageData[0], width * height * 4, &providerCallbacks));
provider(CGDataProviderCreateWithData(nullptr, &fImageData[0], width * height * 4, nullptr));
if (!provider.Get()) {
NSLog(@"QuartzImage: -initWithW:H:data: CGDataProviderCreateDirect failed");
NSLog(@"QuartzImage: -initWithW:H:data: CGDataProviderCreateWithData failed");
return nil;
}

Expand Down Expand Up @@ -521,15 +486,10 @@ - (id) initMaskWithW : (unsigned) width H : (unsigned) height bitmapMask : (unsi
std::copy(mask, mask + width * height, &fImageData[0]);

fIsStippleMask = YES;
const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer,
ROOT_QuartzImage_ReleaseBytePointer,
ROOT_QuartzImage_GetBytesAtPosition, 0};


const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateDirect(&fImageData[0],
width * height, &providerCallbacks));
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateWithData(nullptr, &fImageData[0],
width * height, nullptr));
if (!provider.Get()) {
NSLog(@"QuartzImage: -initMaskWithW:H:bitmapMask: CGDataProviderCreateDirect failed");
NSLog(@"QuartzImage: -initMaskWithW:H:bitmapMask: CGDataProviderCreateWithData failed");
return nil;
}

Expand Down Expand Up @@ -568,14 +528,10 @@ - (id) initMaskWithW : (unsigned) width H : (unsigned) height
}

fIsStippleMask = YES;
const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer,
ROOT_QuartzImage_ReleaseBytePointer,
ROOT_QuartzImage_GetBytesAtPosition, 0};

const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateDirect(&fImageData[0],
width * height, &providerCallbacks));
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateWithData(nullptr, &fImageData[0],
width * height, nullptr));
if (!provider.Get()) {
NSLog(@"QuartzImage: -initMaskWithW:H: CGDataProviderCreateDirect failed");
NSLog(@"QuartzImage: -initMaskWithW:H: CGDataProviderCreateWithData failed");
return nil;
}

Expand Down Expand Up @@ -648,16 +604,12 @@ - (id) initFromImageFlipped : (QuartzImage *) image
std::copy(sourceLine, sourceLine + lineSize, dstLine);
}

const CGDataProviderDirectCallbacks providerCallbacks = {0, ROOT_QuartzImage_GetBytePointer,
ROOT_QuartzImage_ReleaseBytePointer,
ROOT_QuartzImage_GetBytesAtPosition, 0};

if (bpp == 1) {
fIsStippleMask = YES;
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateDirect(&fImageData[0],
width * height, &providerCallbacks));
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateWithData(nullptr, &fImageData[0],
width * height, nullptr));
if (!provider.Get()) {
NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateDirect failed");
NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateWithData failed");
return nil;
}

Expand All @@ -669,10 +621,10 @@ - (id) initFromImageFlipped : (QuartzImage *) image
}
} else {
fIsStippleMask = NO;
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateDirect(&fImageData[0],
width * height * 4, &providerCallbacks));
const Util::CFScopeGuard<CGDataProviderRef> provider(CGDataProviderCreateWithData(nullptr, &fImageData[0],
width * height * 4, nullptr));
if (!provider.Get()) {
NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateDirect failed");
NSLog(@"QuartzImage: -initFromImageFlipped:, CGDataProviderCreateWithData failed");
return nil;
}

Expand Down

0 comments on commit 30eebd8

Please sign in to comment.