예제 #1
0
/* Create a CGImageSourceRef from raw data */
CGImageRef CreateCGImageFromDataStream(std::istream& fin)
{
    CGImageRef image_ref = NULL;
    CGImageSourceRef source_ref;
    /* The easy way would be to use CGImageSourceCreateWithData,
     * but this presumes you have a known fixed-length buffer of data.
     * The istream makes this harder to know, so we use the ProviderCallbacks APIs
    CFDataRef the_cf_data = CFDataCreateWithBytesNoCopy(
        kCFAllocatorDefault,
        (const UInt8*)the_data,
        CFIndex length,
        kCFAllocatorNull // do not free data buffer, must do it yourself
    );
    source_ref = CGImageSourceCreateWithData(the_cf_data, NULL);
*/

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
    CGDataProviderSequentialCallbacks provider_callbacks =
    {
        0,
        MyProviderGetBytesCallback,
        MyProviderSkipForwardBytesCallback,
        MyProviderRewindCallback,
        MyProviderReleaseInfoCallback
    };

    CGDataProviderRef data_provider = CGDataProviderCreateSequential(&fin, &provider_callbacks);


#else // CGDataProviderCreate was deprecated in 10.5

    CGDataProviderCallbacks provider_callbacks =
    {
        MyProviderGetBytesCallback,
        MyProviderSkipBytesCallback,
        MyProviderRewindCallback,
        MyProviderReleaseInfoCallback
    };

    CGDataProviderRef data_provider = CGDataProviderCreate(&fin, &provider_callbacks);
#endif
    // If we had a way of hinting at what the data type is, we could
    // pass this hint in the second parameter.
    source_ref = CGImageSourceCreateWithDataProvider(data_provider, NULL);

    CGDataProviderRelease(data_provider);


    if(!source_ref)
    {
        return NULL;
    }

    image_ref = CGImageSourceCreateImageAtIndex(source_ref, 0, NULL);

    /* Don't need the SourceRef any more (error or not) */
    CFRelease(source_ref);

    return image_ref;
}
예제 #2
0
static CGImageSourceRef data_to_CGImageSrc(SkData* data) {
    CGDataProviderRef cgData = CGDataProviderCreateWithData(data, data->data(), data->size(),
            nullptr);
    if (!cgData) {
        return nullptr;
    }
    CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(cgData, 0);
    CGDataProviderRelease(cgData);
    return imageSrc;
}
예제 #3
0
void MacCGDecoder::attachStream(Stream& stream)
{
  Base::attachStream(stream);

  CGDataProviderRef cgDataProvider = CGDataProviderCreateSequential(this, &_providerCallbacks);
  if (cgDataProvider != NULL)
  {
    _cgImageSource = CGImageSourceCreateWithDataProvider(cgDataProvider, NULL);
    CFRelease(cgDataProvider);
  }
}
예제 #4
0
// This creates a CGImageSourceRef which is a handle to an image that can be used to examine information
// about the image or load the actual image data.
static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options)
{
	CGImageSourceRef source_ref;

	// Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams.
	
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated
	CGDataProviderSequentialCallbacks provider_callbacks =
	{
        0,
		MyProviderGetBytesCallback,
		MyProviderSkipForwardBytesCallback,
		MyProviderRewindCallback,
		MyProviderReleaseInfoCallback
	};
	
	CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks);
	
	
#else // CGDataProviderCreate was deprecated in 10.5
	
	CGDataProviderCallbacks provider_callbacks =
	{
		MyProviderGetBytesCallback,
		MyProviderSkipBytesCallback,
		MyProviderRewindCallback,
		MyProviderReleaseInfoCallback
	};
	
	CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks);
#endif
	// Get the CGImageSourceRef.
	// The dictionary can be NULL or contain hints to help ImageIO figure out the image type.
	source_ref = CGImageSourceCreateWithDataProvider(data_provider, hints_and_options);
	return source_ref;
}
예제 #5
0
static CGImageRef quartz_loadimage(GVJ_t * job, usershape_t *us)
{
    assert(job);
    assert(us);
    assert(us->name);

    if (us->data && us->datafree != quartz_freeimage) {
	     us->datafree(us);        /* free incompatible cache data */
	     us->data = NULL;
	     us->datafree = NULL;
	}
    
    if (!us->data) { /* read file into cache */
		if (!gvusershape_file_access(us))
			return NULL;
			
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000
		CGDataProviderRef data_provider = CGDataProviderCreateSequential(us->f, &file_data_provider_callbacks);
#else
		CGDataProviderRef data_provider = CGDataProviderCreate(us->f, &file_data_provider_callbacks);	
#endif
		
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1040
		/* match usershape format to a UTI for type hinting, if possible */
		format_type hint_format_type;
		switch (us->type) {
		case FT_BMP:
			hint_format_type = FORMAT_BMP;
			break;
		case FT_GIF:
			hint_format_type = FORMAT_GIF;
			break;
		case FT_PNG:
			hint_format_type = FORMAT_PNG;
			break;
		case FT_JPEG:
			hint_format_type = FORMAT_JPEG;
			break;
		case FT_PDF:
			hint_format_type = FORMAT_PDF;
			break;
		default:
			hint_format_type = FORMAT_NONE;
			break;
		}
		CFDictionaryRef options = hint_format_type == FORMAT_NONE ? NULL : CFDictionaryCreate(
			kCFAllocatorDefault,
			(const void **)&kCGImageSourceTypeIdentifierHint,
			(const void **)(format_uti + hint_format_type),
			1,
			&kCFTypeDictionaryKeyCallBacks,
			&kCFTypeDictionaryValueCallBacks);

		/* get first image from usershape file */
		CGImageSourceRef image_source = CGImageSourceCreateWithDataProvider(data_provider, options);
		us->data = CGImageSourceCreateImageAtIndex(image_source, 0, NULL);
		if (image_source)
			CFRelease(image_source);
		if (options)
			CFRelease(options);
#else
		switch (us->type) {
			case FT_PNG:		
				us->data = CGImageCreateWithPNGDataProvider(data_provider, NULL, false, kCGRenderingIntentDefault);
				break;	
			case FT_JPEG:		
				us->data = CGImageCreateWithJPEGDataProvider(data_provider, NULL, false, kCGRenderingIntentDefault);
				break;
			default:
				us->data = NULL;
				break;
		}
		
#endif
		/* clean up */
		if (us->data)
			us->datafree = quartz_freeimage;
		CGDataProviderRelease(data_provider);
			
		gvusershape_file_release(us);
    }
    return (CGImageRef)(us->data);
}
예제 #6
0
static CGImageSourceRef SkStreamToCGImageSource(SkStream* stream) {
    CGDataProviderRef data = SkStreamToDataProvider(stream);
    CGImageSourceRef imageSrc = CGImageSourceCreateWithDataProvider(data, 0);
    CGDataProviderRelease(data);
    return imageSrc;
}
예제 #7
0
int get_exif_rot (CGDataProviderRef image_source) {

	int val;
	
	// Create a source to read the exif from
	CGImageSourceRef image_exif_source = CGImageSourceCreateWithDataProvider (image_source, NULL);
	
	// Check for a NULL value in the CGImageSourceRef
	if (NULL == image_exif_source) {
		
		// Could not create the CGImageSoureRef
		printf ("Could not create CGImageSourceRef for image.\n");
	}

	// NSDictionary to hold the exif from the file.
	CFDictionaryRef exif;
	
	// create an NSDictionary and populate it with the EXIF
	exif = (CFDictionaryRef) CGImageSourceCopyPropertiesAtIndex (image_exif_source, 0, NULL);
	
	// Check for a NULL value for the exif CFDict
	if (NULL == exif) {
		
		// there was no EXIF
		printf ("This file has no EXIF.\n"); 

		// Release the exif source provider
		CFRelease (image_exif_source);
		image_exif_source = NULL;

		// Release the CFDictionary
		CFRelease (exif);
		exif = NULL;

		// set the orientation to Normal.
		return 1;

	} else {

		val = CFNumberToCInt (CFDictionaryGetValue (exif, kCGImagePropertyOrientation));

		// Release the exif source provider
		CFRelease (image_exif_source);
		image_exif_source = NULL;

		// Release the CFDictionary
		CFRelease (exif);
		exif = NULL;

		// get the value at the "Orientation" tag
		return val;
	}

	// Release the exif source provider
	CFRelease (image_exif_source);
	image_exif_source = NULL;

	// Release the CFDictionary
	CFRelease (exif);
	exif = NULL;

	return 1;
	
} // get_exif ()