Example #1
0
NSize NRectangle::GetSize()
{
	return NSize(width, height);
}
Example #2
0
static const NString kKeyPoint										= "Test Point";
static const NString kKeySize										= "Test Size";
static const NString kKeyRectangle									= "Test Rectangle";


// Values
static const bool       kValueBoolean1								= true;
static const bool       kValueBoolean2								= false;
static const NNumber    kValueNumber1								=  1234LL;
static const NNumber    kValueNumber2								= -5678LL;
static const NNumber    kValueNumber3								=  1234.12f;
static const NNumber    kValueNumber4								= -5678.5678765000102;
static const NString    kValueString								= "This \" is & a ' test < text > string";
static const UInt8      kValueData[]								= { 0xAA, 0xBB, 0xCC, 0xDD };
static const NPoint		kValuePoint									= NPoint(10, 20);
static const NSize		kValueSize									= NSize(30, 40);
static const NRectangle kValueRectangle								= NRectangle(10, 20, 30, 40);


// Results
static const UInt32  kResultBinary									= 0x0F48C7C8;
static const NString kResultXML										=	"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
																		"<encoder version=\"1.0\">\n"
																		"	<object class=\"TEncodable\" key=\"root\">\n"
																		"		<bool key=\"Test Boolean 1\">true</bool>\n"
																		"		<bool key=\"Test Boolean 2\">false</bool>\n"
																		"		<number key=\"Test Number 1\">1234</number>\n"
																		"		<number key=\"Test Number 2\">-5678</number>\n"
																		"		<number key=\"Test Number 3\">1234.12</number>\n"
																		"		<number key=\"Test Number 4\">-5678.5678765000102</number>\n"
																		"		<string key=\"Test String\">This &quot; is &amp; a &apos; test &lt; text &gt; string</string>\n"
Example #3
0
//============================================================================
//		NCGImage::SetObject : Set the object.
//----------------------------------------------------------------------------
bool NCGImage::SetObject(CGImageRef cfObject, bool takeOwnership)
{	size_t				theWidth, theHeight, bitsPerPixel, bitsPerComponent;
	NCFObject			theObject(cfObject, takeOwnership);
	NCFObject			cgColorSpace, cgContext;
	CGBitmapInfo		bitmapInfo;
	NImageFormat		theFormat;
	NImage				theImage;
	bool				isValid;



	// Get the state we need
	theWidth         = CGImageGetWidth(           cfObject);
	theHeight        = CGImageGetHeight(          cfObject);
	bitsPerPixel     = CGImageGetBitsPerPixel(    cfObject);
	bitsPerComponent = CGImageGetBitsPerComponent(cfObject);



	// Select the image format
	if (bitsPerPixel == 8 && bitsPerComponent == 8)
		{
		// Convert indexed images to 32bpp without alpha
		theFormat    = kNImageFormat_RGBX_8888;
		bitmapInfo   = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast;
		cgColorSpace = NCGColor::GetDeviceRGB();
		}

	else if (bitsPerPixel == 24 && bitsPerComponent == 8)
		{
		// Convert 24bpp images to 32bpp without alpha
		theFormat    = kNImageFormat_RGBX_8888;
		bitmapInfo   = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast;
		cgColorSpace = NCGColor::GetDeviceRGB();
		}

	else if (bitsPerPixel == 32 && bitsPerComponent == 8)
		{
		// Convert 32bpp images to 32bpp with alpha
		theFormat    = kNImageFormat_RGBA_8888;
		bitmapInfo   = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
		cgColorSpace = NCGColor::GetDeviceRGB();
		}

	else
		{
		NN_LOG("Unknown image format: %d/%d", bitsPerPixel, bitsPerComponent);
		theFormat  = kNImageFormatNone;
		bitmapInfo = kCGImageAlphaNone;
		}

	if (!cgColorSpace.IsValid())
		return(false);



	// Set the object
	theImage = NImage(NSize(theWidth, theHeight), theFormat);
	isValid  = cgContext.SetObject(CGBitmapContextCreate(	theImage.GetPixels(),
															theWidth,
															theHeight,
															bitsPerComponent,
															theImage.GetBytesPerRow(),
															cgColorSpace,
															bitmapInfo));

	if (isValid)
		{
		CGContextDrawImage(cgContext, ToCG(theImage.GetBounds()), cfObject);
		*this = theImage;
		}

	return(isValid);
}