view dstep/appkit/NSBitmapImageRep.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents
children b9de51448c6b
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Sep 24, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.appkit.NSBitmapImageRep;

import dstep.appkit.NSColor;
import dstep.appkit.NSImageRep;
import dstep.applicationservices.coregraphics.CGImage;
import dstep.applicationservices.coregraphics.CGBase;
import dstep.foundation.NSArray;
import dstep.foundation.NSData;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSGeometry;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSString;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;
import dstep.quartzcore.CIImage;

import bindings = dstep.appkit.NSBitmapImageRep_bindings;

alias NSUInteger NSTIFFCompression;
alias NSUInteger NSBitmapImageFileType;
alias NSInteger NSImageRepLoadStatus;
alias NSUInteger NSBitmapFormat;

private
{
	NSString NSImageCompressionMethod_;
	NSString NSImageCompressionFactor_;
	NSString NSImageDitherTransparency_;
	NSString NSImageRGBColorTable_;
	NSString NSImageInterlaced_;
	NSString NSImageColorSyncProfileData_;
	NSString NSImageFrameCount_;
	NSString NSImageCurrentFrame_;
	NSString NSImageCurrentFrameDuration_;
	NSString NSImageLoopCount_;
	NSString NSImageGamma_;
	NSString NSImageProgressive_;
	NSString NSImageEXIFData_;
	NSString NSImageFallbackBackgroundColor_;
}

NSString NSImageCompressionMethod ()
{
	if (NSImageCompressionMethod_)
		return NSImageCompressionMethod_;

	return NSImageCompressionMethod_ = new NSString(bindings.NSImageCompressionMethod);
}

NSString NSImageCompressionFactor ()
{
	if (NSImageCompressionFactor_)
		return NSImageCompressionFactor_;

	return NSImageCompressionFactor_ = new NSString(bindings.NSImageCompressionFactor);
}

NSString NSImageDitherTransparency ()
{
	if (NSImageDitherTransparency_)
		return NSImageDitherTransparency_;

	return NSImageDitherTransparency_ = new NSString(bindings.NSImageDitherTransparency);
}

NSString NSImageRGBColorTable ()
{
	if (NSImageRGBColorTable_)
		return NSImageRGBColorTable_;

	return NSImageRGBColorTable_ = new NSString(bindings.NSImageRGBColorTable);
}

NSString NSImageInterlaced ()
{
	if (NSImageInterlaced_)
		return NSImageInterlaced_;

	return NSImageInterlaced_ = new NSString(bindings.NSImageInterlaced);
}

NSString NSImageColorSyncProfileData ()
{
	if (NSImageColorSyncProfileData_)
		return NSImageColorSyncProfileData_;

	return NSImageColorSyncProfileData_ = new NSString(bindings.NSImageColorSyncProfileData);
}

NSString NSImageFrameCount ()
{
	if (NSImageFrameCount_)
		return NSImageFrameCount_;

	return NSImageFrameCount_ = new NSString(bindings.NSImageFrameCount);
}

NSString NSImageCurrentFrame ()
{
	if (NSImageCurrentFrame_)
		return NSImageCurrentFrame_;

	return NSImageCurrentFrame_ = new NSString(bindings.NSImageCurrentFrame);
}

NSString NSImageCurrentFrameDuration ()
{
	if (NSImageCurrentFrameDuration_)
		return NSImageCurrentFrameDuration_;

	return NSImageCurrentFrameDuration_ = new NSString(bindings.NSImageCurrentFrameDuration);
}

NSString NSImageLoopCount ()
{
	if (NSImageLoopCount_)
		return NSImageLoopCount_;

	return NSImageLoopCount_ = new NSString(bindings.NSImageLoopCount);
}

NSString NSImageGamma ()
{
	if (NSImageGamma_)
		return NSImageGamma_;

	return NSImageGamma_ = new NSString(bindings.NSImageGamma);
}

NSString NSImageProgressive ()
{
	if (NSImageProgressive_)
		return NSImageProgressive_;

	return NSImageProgressive_ = new NSString(bindings.NSImageProgressive);
}

NSString NSImageEXIFData ()
{
	if (NSImageEXIFData_)
		return NSImageEXIFData_;

	return NSImageEXIFData_ = new NSString(bindings.NSImageEXIFData);
}

NSString NSImageFallbackBackgroundColor ()
{
	if (NSImageFallbackBackgroundColor_)
		return NSImageFallbackBackgroundColor_;

	return NSImageFallbackBackgroundColor_ = new NSString(bindings.NSImageFallbackBackgroundColor);
}

enum
{
	NSTIFFCompressionNone = 1,
	NSTIFFCompressionCCITTFAX3 = 3,
	NSTIFFCompressionCCITTFAX4 = 4,
	NSTIFFCompressionLZW = 5,
	NSTIFFCompressionJPEG = 6,
	NSTIFFCompressionNEXT = 32766,
	NSTIFFCompressionPackBits = 32773,
	NSTIFFCompressionOldJPEG = 32865
}

enum
{
	NSTIFFFileType,
	NSBMPFileType,
	NSGIFFileType,
	NSJPEGFileType,
	NSPNGFileType,
	NSJPEG2000FileType
}

enum
{
	NSImageRepLoadStatusUnknownType = -1,
	NSImageRepLoadStatusReadingHeader = -2,
	NSImageRepLoadStatusWillNeedAllData = -3,
	NSImageRepLoadStatusInvalidData = -4,
	NSImageRepLoadStatusUnexpectedEOF = -5,
	NSImageRepLoadStatusCompleted = -6
}

enum
{
	NSAlphaFirstBitmapFormat = 1 << 0,
	NSAlphaNonpremultipliedBitmapFormat = 1 << 1,
	NSFloatingPointSamplesBitmapFormat = 1 << 2
}

const TNSBitmapImageFileTypeExtensions = `

	static NSData representationOfImageRepsInArray (NSArray imageReps, uint storageType, NSDictionary properties)
	{
		return invokeObjcSelfClass!(NSData, "representationOfImageRepsInArray:usingType:properties:", NSArray, uint, NSDictionary)(imageReps, storageType, properties);
	}

	NSData representationUsingType (uint storageType, NSDictionary properties)
	{
		return invokeObjcSelf!(NSData, "representationUsingType:properties:", uint, NSDictionary)(storageType, properties);
	}

	void setProperty (NSString property, Object value)
	{
		return invokeObjcSelf!(void, "setProperty:withValue:", NSString, Object)(property, value);
	}

	Object valueForProperty (NSString property)
	{
		return invokeObjcSelf!(Object, "valueForProperty:", NSString)(property);
	}

	//mixin ObjcBindClassMethod!(representationOfImageRepsInArray, "representationOfImageRepsInArray:usingType:properties:");
	//mixin ObjcBindMethod!(representationUsingType, "representationUsingType:properties:");
	//mixin ObjcBindMethod!(setProperty, "setProperty:withValue:");
	//mixin ObjcBindMethod!(valueForProperty, "valueForProperty:");

`;

class NSBitmapImageRep : NSImageRep
{
	mixin (ObjcWrap);

	NSBitmapImageRep initWithFocusedViewRect (NSRect rect)
	{
		id result = invokeObjcSelf!(id, "initWithFocusedViewRect:", NSRect)(rect);
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this (NSRect rect)
	{
		super(NSBitmapImageRep.alloc.initWithFocusedViewRect(rect).objcObject);
	}

	NSBitmapImageRep initWithBitmapDataPlanes (ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, NSInteger rBytes, NSInteger pBits)
	{
		id result = invokeObjcSelf!(id, "initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:", ubyte**, NSInteger, NSInteger, NSInteger, NSInteger, bool, bool, NSString, NSInteger, NSInteger)(planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName, rBytes, pBits);
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this (ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, NSInteger rBytes, NSInteger pBits)
	{
		super(NSBitmapImageRep.alloc.initWithBitmapDataPlanes(planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName, rBytes, pBits).objcObject);
	}

	NSBitmapImageRep initWithBitmapDataPlanes (ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, uint bitmapFormat, NSInteger rBytes, NSInteger pBits)
	{
		id result = invokeObjcSelf!(id, "initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:", ubyte**, NSInteger, NSInteger, NSInteger, NSInteger, bool, bool, NSString, uint, NSInteger, NSInteger)(planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName, bitmapFormat, rBytes, pBits);
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this (ubyte** planes, NSInteger width, NSInteger height, NSInteger bps, NSInteger spp, bool alpha, bool isPlanar, NSString colorSpaceName, uint bitmapFormat, NSInteger rBytes, NSInteger pBits)
	{
		super(NSBitmapImageRep.alloc.initWithBitmapDataPlanes(planes, width, height, bps, spp, alpha, isPlanar, colorSpaceName, bitmapFormat, rBytes, pBits).objcObject);
	}

	NSBitmapImageRep initWithCGImage (CGImageRef cgImage)
	{
		id result = invokeObjcSelf!(id, "initWithCGImage:", CGImageRef)(cgImage);
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this (CGImageRef cgImage)
	{
		super(NSBitmapImageRep.alloc.initWithCGImage(cgImage).objcObject);
	}

	NSBitmapImageRep initWithCIImage (CIImage ciImage)
	{
		id result = invokeObjcSelf!(id, "initWithCIImage:", CIImage)(ciImage);
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this (CIImage ciImage)
	{
		super(NSBitmapImageRep.alloc.initWithCIImage(ciImage).objcObject);
	}

	static NSArray imageRepsWithData (NSData data)
	{
		return invokeObjcSelfClass!(NSArray, "imageRepsWithData:", NSData)(data);
	}

	static Object imageRepWithData (NSData data)
	{
		return invokeObjcSelfClass!(Object, "imageRepWithData:", NSData)(data);
	}

	NSBitmapImageRep initWithData (NSData data)
	{
		id result = invokeObjcSelf!(id, "initWithData:", NSData)(data);
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this (NSData data)
	{
		super(NSBitmapImageRep.alloc.initWithData(data).objcObject);
	}

	char* bitmapData ()
	{
		return invokeObjcSelf!(char*, "bitmapData");
	}

	void getBitmapDataPlanes (ubyte** data)
	{
		return invokeObjcSelf!(void, "getBitmapDataPlanes:", ubyte**)(data);
	}

	bool isPlanar ()
	{
		return invokeObjcSelf!(bool, "isPlanar");
	}

	NSInteger samplesPerPixel ()
	{
		return invokeObjcSelf!(NSInteger, "samplesPerPixel");
	}

	NSInteger bitsPerPixel ()
	{
		return invokeObjcSelf!(NSInteger, "bitsPerPixel");
	}

	NSInteger bytesPerRow ()
	{
		return invokeObjcSelf!(NSInteger, "bytesPerRow");
	}

	NSInteger bytesPerPlane ()
	{
		return invokeObjcSelf!(NSInteger, "bytesPerPlane");
	}

	NSInteger numberOfPlanes ()
	{
		return invokeObjcSelf!(NSInteger, "numberOfPlanes");
	}

	uint bitmapFormat ()
	{
		return invokeObjcSelf!(uint, "bitmapFormat");
	}

	void getCompression (NSTIFFCompression* compression, float* factor)
	{
		return invokeObjcSelf!(void, "getCompression:factor:", NSTIFFCompression*, float*)(compression, factor);
	}

	void setCompression (uint compression, float factor)
	{
		return invokeObjcSelf!(void, "setCompression:factor:", uint, float)(compression, factor);
	}

	NSData TIFFRepresentation ()
	{
		return invokeObjcSelf!(NSData, "TIFFRepresentation");
	}

	NSData TIFFRepresentationUsingCompression (uint comp, float factor)
	{
		return invokeObjcSelf!(NSData, "TIFFRepresentationUsingCompression:factor:", uint, float)(comp, factor);
	}

	static NSData TIFFRepresentationOfImageRepsInArray (NSArray array)
	{
		return invokeObjcSelfClass!(NSData, "TIFFRepresentationOfImageRepsInArray:", NSArray)(array);
	}

	static NSData TIFFRepresentationOfImageRepsInArray (NSArray array, uint comp, float factor)
	{
		return invokeObjcSelfClass!(NSData, "TIFFRepresentationOfImageRepsInArray:usingCompression:factor:", NSArray, uint, float)(array, comp, factor);
	}

	static void getTIFFCompressionTypes (NSTIFFCompression** list, NSInteger* numTypes)
	{
		return invokeObjcSelfClass!(void, "getTIFFCompressionTypes:count:", NSTIFFCompression**, NSInteger*)(list, numTypes);
	}

	static NSString localizedNameForTIFFCompressionType (uint compression)
	{
		return invokeObjcSelfClass!(NSString, "localizedNameForTIFFCompressionType:", uint)(compression);
	}

	bool canBeCompressedUsing (uint compression)
	{
		return invokeObjcSelf!(bool, "canBeCompressedUsing:", uint)(compression);
	}

	void colorizeByMappingGray (CGFloat midPoint, NSColor midPointColor, NSColor shadowColor, NSColor lightColor)
	{
		return invokeObjcSelf!(void, "colorizeByMappingGray:toColor:blackMapping:whiteMapping:", CGFloat, NSColor, NSColor, NSColor)(midPoint, midPointColor, shadowColor, lightColor);
	}

	NSBitmapImageRep initForIncrementalLoad ()
	{
		id result = invokeObjcSelf!(id, "initForIncrementalLoad");
		return result is this.objcObject ? this : (result !is null ? new NSBitmapImageRep(result) : null);
	}

	this ()
	{
		super(NSBitmapImageRep.alloc.initForIncrementalLoad.objcObject);
	}

	NSInteger incrementalLoadFromData (NSData data, bool complete)
	{
		return invokeObjcSelf!(NSInteger, "incrementalLoadFromData:complete:", NSData, bool)(data, complete);
	}

	void setColor (NSColor color, NSInteger x, NSInteger y)
	{
		return invokeObjcSelf!(void, "setColor:atX:y:", NSColor, NSInteger, NSInteger)(color, x, y);
	}

	NSColor colorAtX (NSInteger x, NSInteger y)
	{
		return invokeObjcSelf!(NSColor, "colorAtX:y:", NSInteger, NSInteger)(x, y);
	}

	void getPixel (NSUInteger* p, NSInteger x, NSInteger y)
	{
		return invokeObjcSelf!(void, "getPixel:atX:y:", NSUInteger*, NSInteger, NSInteger)(p, x, y);
	}

	void setPixel (NSUInteger* p, NSInteger x, NSInteger y)
	{
		return invokeObjcSelf!(void, "setPixel:atX:y:", NSUInteger*, NSInteger, NSInteger)(p, x, y);
	}

	CGImageRef CGImage ()
	{
		return invokeObjcSelf!(CGImageRef, "CGImage");
	}
	
	// NSBitmapImageFileTypeExtensions
	static NSData representationOfImageRepsInArray (NSArray imageReps, uint storageType, NSDictionary properties)
	{
		return invokeObjcSelfClass!(NSData, "representationOfImageRepsInArray:usingType:properties:", NSArray, uint, NSDictionary)(imageReps, storageType, properties);
	}

	NSData representationUsingType (uint storageType, NSDictionary properties)
	{
		return invokeObjcSelf!(NSData, "representationUsingType:properties:", uint, NSDictionary)(storageType, properties);
	}

	void setProperty (NSString property, Object value)
	{
		return invokeObjcSelf!(void, "setProperty:withValue:", NSString, Object)(property, value);
	}

	Object valueForProperty (NSString property)
	{
		return invokeObjcSelf!(Object, "valueForProperty:", NSString)(property);
	}
}