示例#1
0
static void QTFrame_CalcWindowMinMaxInfo (HWND theWnd, LPMINMAXINFO lpMinMax)
{
	WindowObject				myWindowObject = NULL;
	Movie						myMovie = NULL;
	MovieController				myMC = NULL;
	GraphicsImportComponent		myImporter = NULL;
	Rect						myRect;
	ComponentResult				myErr = noErr;
	
	myWindowObject = QTFrame_GetWindowObjectFromWindow(theWnd);
	if (myWindowObject != NULL) {
		myMC = (**myWindowObject).fController;
		myMovie = (**myWindowObject).fMovie;
		myImporter = (**myWindowObject).fGraphicsImporter;
	}
	
	// we're expecting a window with either an image or a movie
	if ((myImporter == NULL) && (myMovie == NULL))
		return;

	if (myImporter != NULL) {
		myErr = GraphicsImportGetBoundsRect(myImporter, &myRect);
		if (myErr != noErr)
			return;
	}
	
	if (myMovie != NULL) {
		GetMovieBox(myMovie, &myRect);
		if (myMC != NULL)
			if (MCGetVisible(myMC))
				MCGetControllerBoundsRect(myMC, &myRect);
	}
	
	// we currently don't allow images or movies to be resized, so we return both 
	// min and max rectangles set to the current image or movie size, plus the 
	// appropriate window frame and caption sizes
	lpMinMax->ptMinTrackSize.x = myRect.right + (2 * GetSystemMetrics(SM_CXFRAME));
	lpMinMax->ptMinTrackSize.y = myRect.bottom + (2 * GetSystemMetrics(SM_CXFRAME)) + GetSystemMetrics(SM_CYCAPTION);

	lpMinMax->ptMaxTrackSize.x = lpMinMax->ptMinTrackSize.x;
	lpMinMax->ptMaxTrackSize.y = lpMinMax->ptMinTrackSize.y;
	
	lpMinMax->ptMaxSize.x = lpMinMax->ptMinTrackSize.x;
	lpMinMax->ptMaxSize.y = lpMinMax->ptMinTrackSize.y;
}
void DisplayJPEGAndDisposeHandle( Handle imageData )
{
	OSErr err;
	Rect naturalBounds;
	MatrixRecord matrix;
	SInt32 gapH, gapV;
	Fixed scaleH, scaleV;
	Rect boundsRect;
	GraphicsImportComponent grip;
	Rect windowPortRect;
	static char gifSentinel[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
	static char jpegSentinel[] = {0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9};
	Ptr sentinel;
	Size sentinelSize;
	
	if( !imageData )
	{
		ofLogNotice() << "NO IMAGE DATA" << endl;
	}	else {
		
		ofImage image;
		//ofPixels pixels();
		//pixels = imageData;
		//image.setFromPixels((const unsigned char *)imageData);
		//string image
		//image.saveImage(ofToDataPath(ofGetTimestampString()+".jpg", OF_IMAGE_QUALITY_BEST));
		
		ofLogError() << "WE HAVE DATA!" << endl;
	}

	return;
	
again:
	
	ofLogError() << "Again called";
	if( 'G' == **imageData ) {
		grip = gripG;
		// for GIF:
		// FF FF FF FF will ensure that the bit parser aborts, since you can't
		// have two consecutive all-ones symbols in the LZW codestream --
		// you can sometimes have one (say, a 9-bit code), but after consuming
		// it the code width increases (so we're now using 10-bit codes) 
		// and the all-ones code won't be valid for a while yet.
		sentinel = gifSentinel;
		sentinelSize = sizeof(gifSentinel);
	}
	else {
		grip = gripJ;
		// for JPEG:
		// FF D9 FF D9 will ensure (a) that the bit-parser aborts, since FF D9
		// is an "unstuffed" FF and hence illegal in the entropy-coded datastream,
		// and (b) be long enough to stop overreads.
		sentinel = jpegSentinel;
		sentinelSize = sizeof(jpegSentinel);
	}
	
	//•• add sentinel pattern to the end of the handle.
	err = PtrAndHand( sentinel, imageData, sentinelSize );
	
	err = GraphicsImportSetDataHandle( grip, imageData );
	if( err )
	{
		
		ofLogNotice() << "GraphicsImportSetDataHandle Error" << endl;
		goto bail;
	}
	err = GraphicsImportGetNaturalBounds( grip, &naturalBounds );
	if( err )
	{
		
		ofLogNotice() << "GraphicsImportGetNaturalBounds Error" << endl;
		goto bail;
	}
	
	//GetPortBounds( GetWindowPort( window ), &windowPortRect );
	gapH = windowPortRect.right - naturalBounds.right;
	gapV = windowPortRect.bottom - naturalBounds.bottom;
	
	if( gapH >= 0 ) {
		gapH = ((UInt16)Random()) % gapH;
		scaleH = fixed1;
	}
	else {
		gapH = 0;
		scaleH = FixDiv( windowPortRect.right, naturalBounds.right );
	}
	
	if( gapV >= 0 ) {
		gapV = ((UInt16)Random()) % gapV;
		scaleV = fixed1;
	}
	else {
		gapV = 0;
		scaleV = FixDiv( windowPortRect.bottom, naturalBounds.bottom );
	}
	
	// need to use smaller scale of the two, and then recalc the other gap.
	if( scaleH > scaleV ) {
		scaleH = scaleV;
		gapH = windowPortRect.right - FixMul(scaleH, naturalBounds.right);
		gapH = ((UInt16)Random()) % gapH;
	} else if( scaleH < scaleV ) {
		scaleV = scaleH;
		gapV = windowPortRect.bottom - FixMul(scaleV, naturalBounds.bottom);
		gapV = ((UInt16)Random()) % gapV;
	}
	
	SetIdentityMatrix( &matrix );
	ScaleMatrix( &matrix, scaleH, scaleV, 0, 0 );
	TranslateMatrix( &matrix, gapH<<16, gapV<<16 );
	
	err = GraphicsImportSetMatrix( grip, &matrix );
	if( err ) goto bail;
	
	err = GraphicsImportDraw( grip );
	if( err ) goto bail;
	
	err = GraphicsImportGetBoundsRect( grip, &boundsRect );
	if( err ) goto bail;
	InsetRect( &boundsRect, -1, -1 );
	//SetPortWindowPort( window );
	FrameRect( &boundsRect );
	
	if( scanForAnotherImageMarker(imageData))
	{
		 ofLogError() << "again: scanForAnotherImageMarker" << endl;
		goto again;
	}
	
bail:
	DisposeHandle( imageData );

	//gDrewJPEG = true;
}
示例#3
0
文件: QutTexture.c 项目: refnum/quesa
//=============================================================================
//		QutTexture_CreateGWorldFromFile : Create a GWorld from a file.
//-----------------------------------------------------------------------------
GWorldPtr
QutTexture_CreateGWorldFromFile(const FSSpec *theFSSpec, TQ3PixelType pixelType)
{	CTabHandle					colourTableHnd;
	ImageDescriptionHandle		imageDescHnd;
	ComponentInstance			theImporter;
	GWorldPtr					theGWorld;
	TQ3Uns32					theDepth;
	Rect						theRect;
	OSErr						theErr;



	// Initialise ourselves
	theImporter    = NULL;
	theGWorld      = NULL;
	imageDescHnd   = NULL;
	colourTableHnd = NULL;
	theDepth       = (pixelType == kQ3PixelTypeARGB16 || pixelType == kQ3PixelTypeRGB16) ? 16 : 32;



	// Create the importer
	theErr = GetGraphicsImporterForFile(theFSSpec, &theImporter);



	// Query the importer for the information we need
	if (theErr == noErr)
		{
		GraphicsImportGetBoundsRect(theImporter, &theRect);
	
		theErr = GraphicsImportGetImageDescription(theImporter, &imageDescHnd);
		if (theErr == noErr)
			theErr = GetImageDescriptionCTable(imageDescHnd, &colourTableHnd);
		}



	// Create the GWorld
	if (theErr == noErr)
		theErr = NewGWorld(&theGWorld, theDepth, &theRect, colourTableHnd, NULL,
			useTempMem | kQ3NativeEndianPixMap );



	// Draw the image into the GWorld
	if (theErr == noErr)
		{
		GraphicsImportSetGWorld(theImporter, theGWorld, NULL);
		GraphicsImportDraw(theImporter);
		}



	// Clean up
	if (theImporter != NULL)
		CloseComponent(theImporter);
		
	if (imageDescHnd != NULL)
		DisposeHandle((Handle) imageDescHnd);
		
	if (colourTableHnd != NULL)
		DisposeCTable(colourTableHnd);

	return(theGWorld);
}