char* windowSnapshot(GLWindow* glw)
{
    // This is where we'll snap a picture of our OpenGL context
    // and return a pointer to the raw byte data
    char   			*dataBuffer = NULL;
    GLRect 			glRegion;
    long 			imgSize;
    QDErr			error;
    GLenum glerr;

    RectToGLRect(&glRegion, &glw->winRect);
    // Alloc enough memory for this data
    imgSize = glRegion.width * glRegion.height * 4;
    dataBuffer = MemAlloc(imgSize);
    // Read the back buffer (glReadBuffer() is set to GL_BACK by default in a double buffered context
    glReadBuffer(GL_BACK);
    glReadPixels(0,0,640,480, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV , dataBuffer);
    glerr = glGetError();
    if(glerr != 0)
	printf("Error: glReadPixels() failed : %li\n", glerr);

    InvertGLImage(dataBuffer, imgSize, 640 * 4);

    // Allocate memory for the buffer if its null
    if(gwBuffer == NULL)
	gwBuffer = malloc(sizeof(GWorldPtr));
	
    // Add this new image to our GWorld
    error = NewGWorldFromPtr(&gwBuffer[imageCount], k32ARGBPixelFormat, &glw->winRect, 0, 0, 0, dataBuffer, 640*4);

    // Increment the image count;
    imageCount++;
    
    // Check to see if we're in a sequence or a movie
    if(snapshotTimer || snapshotTimerUPP)
    {
	// Just return nothing
	return NULL;
    }
    else
    {
	void *noData = NULL;
	// only 1 image, so process it
	//ProcessImageArray(imageCount, gwBuffer);
	MPProcessImageAsync(noData);
	// Return the data buffer
	return dataBuffer;
    }
}
Пример #2
0
void pxBuffer::blit(pxSurfaceNative s, int dstLeft, int dstTop, int dstWidth, int dstHeight, 
    int srcLeft, int srcTop)
{
		Rect pr;
		MacSetRect(&pr, 0, 0, width(), height());	
		
		GWorldPtr gworld;
		NewGWorldFromPtr (&gworld, 32, &pr, NULL, NULL, 0, (char*)base(), 4*width());

		Rect dr, sr;
		MacSetRect(&dr, dstLeft, dstTop, dstLeft + dstWidth, dstTop + dstHeight);
		MacSetRect(&sr, srcLeft, srcTop, srcLeft + dstWidth, srcTop + dstHeight);
		CopyBits((BitMapPtr)*GetGWorldPixMap(gworld),(BitMapPtr)*GetGWorldPixMap(s),&sr,&dr,srcCopy,NULL);
	
		DisposeGWorld(gworld);
}
Пример #3
0
static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, int recty, ReportList *reports)
{
	SCTemporalSettings gTemporalSettings;
	OSErr err = noErr;

	qtexport->ibuf = IMB_allocImBuf (rectx, recty, 32, IB_rect);
	qtexport->ibuf2 = IMB_allocImBuf (rectx, recty, 32, IB_rect);

	err = NewGWorldFromPtr( &qtexport->theGWorld,
							k32ARGBPixelFormat,
							trackFrame,
							NULL, NULL, 0,
							(Ptr)qtexport->ibuf->rect,
							rectx * 4 );
	CheckError (err, "NewGWorldFromPtr error", reports);

	qtexport->thePixMap = GetGWorldPixMap(qtexport->theGWorld);
	LockPixels(qtexport->thePixMap);

	SCDefaultPixMapSettings (qtdata->theComponent, qtexport->thePixMap, true);

	// workaround for crash with H.264, which requires an upgrade to
	// the new callback based api for proper encoding, but that's not
	// really compatible with rendering out frames sequentially
	gTemporalSettings = qtdata->gTemporalSettings;
	if(qtdata->gSpatialSettings.codecType == kH264CodecType) {
		if(gTemporalSettings.temporalQuality != codecMinQuality) {
			BKE_reportf(reports, RPT_WARNING, "Only minimum quality compression supported for QuickTime H.264.\n");
			gTemporalSettings.temporalQuality = codecMinQuality;
		}
	}

	SCSetInfo(qtdata->theComponent, scTemporalSettingsType,	&gTemporalSettings);
	SCSetInfo(qtdata->theComponent, scSpatialSettingsType,	&qtdata->gSpatialSettings);
	SCSetInfo(qtdata->theComponent, scDataRateSettingsType,	&qtdata->aDataRateSetting);

	err = SCCompressSequenceBegin(qtdata->theComponent, qtexport->thePixMap, NULL, &qtexport->anImageDescription); 
	CheckError (err, "SCCompressSequenceBegin error", reports );
}
Пример #4
0
bool MCImageBitmapToPICT(MCImageBitmap *p_bitmap, MCMacSysPictHandle &r_pict)
{
#ifdef LIBGRAPHICS_BROKEN
	bool t_success = true;
	
	Pixmap drawdata = nil, drawmask = nil;
	MCBitmap *maskimagealpha = nil;
	
	t_success = MCImageSplitPixmaps(p_bitmap, drawdata, drawmask, maskimagealpha);
	
	if (!t_success)
		return false;

	Rect t_rect;
	SetRect(&t_rect, 0, 0, p_bitmap->width, p_bitmap->height);
	
	GWorldPtr t_old_gworld;
	GDHandle t_old_gdevice;
	GetGWorld(&t_old_gworld, &t_old_gdevice);

	PixMapHandle t_draw_pixmap;
	t_draw_pixmap = GetGWorldPixMap((CGrafPtr)drawdata -> handle . pixmap);
	
	GWorldPtr t_img_gworld;
	t_img_gworld = NULL;
	if (t_success)
	{
		QDErr t_err;
		t_err = NewGWorld(&t_img_gworld, 32, &t_rect, NULL, NULL, 0);
		if (t_err != noErr)
			t_success = false;
	}
	
	if (t_success)
	{
		SetGWorld(t_img_gworld, GetGDevice());
		
		PenMode(srcCopy);
		ForeColor(blackColor);
		BackColor(whiteColor);
		
		if (maskimagealpha != NULL)
		{
			GWorldPtr t_alpha_gworld;
			if (NewGWorldFromPtr(&t_alpha_gworld, 8, &t_rect, GetCTable(40), NULL, 0, maskimagealpha -> data, maskimagealpha -> bytes_per_line) == noErr)
			{
				const BitMap *t_dst_bits;
				t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld);
				
				const BitMap *t_src_bits;
				t_src_bits = GetPortBitMapForCopyBits((CGrafPtr)drawdata -> handle . pixmap);
				
				const BitMap *t_mask_bits;
				t_mask_bits = GetPortBitMapForCopyBits(t_alpha_gworld);
				
				EraseRect(&t_rect);
				
				CopyDeepMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect, srcCopy, NULL);
			}
		}
		else if (drawmask != NULL)
		{
			PixMapHandle t_mask_pixmap;
			t_mask_pixmap = GetGWorldPixMap((CGrafPtr)drawmask -> handle . pixmap);
			
			EraseRect(&t_rect);
			
			const BitMap *t_dst_bits;
			t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld);
			
			const BitMap *t_src_bits;
			LockPixels(t_draw_pixmap);
			t_src_bits = (BitMap *)*t_draw_pixmap;
			
			const BitMap *t_mask_bits;
			LockPixels(t_mask_pixmap);
			t_mask_bits = (BitMap *)*t_mask_pixmap;
			
			CopyMask(t_src_bits, t_mask_bits, t_dst_bits, &t_rect, &t_rect, &t_rect);
			
			UnlockPixels(t_mask_pixmap);
			
			UnlockPixels(t_draw_pixmap);
		}
		else
		{
			const BitMap *t_dst_bits;
			t_dst_bits = GetPortBitMapForCopyBits(t_img_gworld);
			
			const BitMap *t_src_bits;
			LockPixels(t_draw_pixmap);
			t_src_bits = (BitMap *)*t_draw_pixmap;
			CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL);
			UnlockPixels(t_draw_pixmap);
		}
	}
	
	PicHandle t_handle;
	t_handle = NULL;
	if (t_success)
	{
		OpenCPicParams t_params;
		t_params . srcRect = t_rect;
		t_params . hRes = 72 << 16;
		t_params . vRes = 72 << 16;
		t_params . version = -2;
		t_params . reserved1 = 0;
		t_params . reserved2 = 0;
		t_handle = OpenCPicture(&t_params);
		if (t_handle == NULL)
			t_success = false;
	}

	if (t_success)
	{
		GWorldPtr t_pict_gworld;
		GDHandle t_pict_gdevice;
		GetGWorld(&t_pict_gworld, &t_pict_gdevice);
		
		PenMode(srcCopy);
		ForeColor(blackColor);
		BackColor(whiteColor);
		
		const BitMap *t_dst_bits;
		t_dst_bits = GetPortBitMapForCopyBits(t_pict_gworld);

		const BitMap *t_src_bits;
		t_src_bits = GetPortBitMapForCopyBits(t_img_gworld);
		CopyBits(t_src_bits, t_dst_bits, &t_rect, &t_rect, srcCopy, NULL);
		
		ClosePicture();
	}
	
	if (t_img_gworld != NULL)
		DisposeGWorld(t_img_gworld);
	
	SetGWorld(t_old_gworld, t_old_gdevice);

	MCscreen->freepixmap(drawdata);
	MCscreen->freepixmap(drawmask);
	if (maskimagealpha != nil)
		MCscreen->destroyimage(maskimagealpha);
	
	if (t_success)
		r_pict = (MCMacSysPictHandle)t_handle;
	
	return t_success;
#else
	return false;
#endif
}
Пример #5
0
OSStatus MovieMaker::setupMovie()
{
	OSStatus	error = noErr;
	FSRef		fileRef;
	FSSpec		fileSpec;
	
	rowBytes = width * 4;
	bufferSize = height * rowBytes;
	buffer = (char*)malloc(bufferSize);
	invertedBuffer = (char*)malloc(bufferSize);

	rect.left = 0;
	rect.top = 0;
	rect.right = width;
	rect.bottom = height;
	
	error = NewGWorldFromPtr(&gworld, k32ARGBPixelFormat, &rect, 0, 0, 0, buffer, rowBytes);

	if (error == noErr)
	{
		LockPixels(GetGWorldPixMap(gworld));
	}

// MBW -- I think this needs to happen after all the dialogs, etc.	
//	if (error == noErr)
//	{
//		Microseconds(&lastFrameTime);
//		error = grabFrame();
//	}

	if (error == noErr)
	{
		error = EnterMovies();
	}
	
	if (error == noErr)
	{
		ci = OpenDefaultComponent(StandardCompressionType,StandardCompressionSubType);
		if(ci == NULL)
			error = paramErr;
	}
		
	if (error == noErr)
	{
		long flags;
		
		SCGetInfo(ci,scPreferenceFlagsType,&flags);
		flags &= ~scShowBestDepth;
		flags |= scAllowZeroFrameRate;
		SCSetInfo(ci,scPreferenceFlagsType,&flags);
	}

	if (error == noErr)
	{
		send_agent_pause();
		gViewerWindow->mWindow->beforeDialog();

		error = SCRequestSequenceSettings(ci);

		gViewerWindow->mWindow->afterDialog();
		send_agent_resume();

		if (error == scUserCancelled) 
		{
			// deal with user cancelling.
			EndCapture();
		}
	}
	
	if (error == noErr)
	{
		// This is stoopid. I have to take the passed full path, create the file so I can get an FSRef, and Get Info to get the FSSpec for QuickTime. Could Apple make this any more difficult...
		FILE* file = LLFile::fopen(fname, "w");		/* Flawfinder: ignore */
		if (file)
		{
			fclose(file);
			
			error = FSPathMakeRef((UInt8*)fname, &fileRef, NULL);
			if (error == noErr)
				error = FSGetCatalogInfo(&fileRef, 0, NULL, NULL, &fileSpec, NULL);
		}
		else
		{
			error = paramErr;
		}
	}
	
	if (error == noErr)
	{
		error = CreateMovieFile(&fileSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, &movieResRef, &movie);
	}
	
	if (error == noErr)
	{
		track = NewMovieTrack(movie, FixRatio(width, 1), FixRatio(height, 1), kNoVolume);
		error = GetMoviesError();
	}
	
	if (error == noErr)
	{
		media = NewTrackMedia(track, VideoMediaType, 600, NULL, 0);
		error = GetMoviesError();
	}
	
	if (error == noErr)
	{
		Microseconds(&lastFrameTime);
		error = grabFrame();
	}

	if (error == noErr)
	{
		error = SCCompressSequenceBegin(ci,GetPortPixMap(gworld),nil,&idh);
	}

	if (error == noErr)
	{
		error = BeginMediaEdits(media);
	}
	
	if (error != noErr)
	{
		media = NULL;
	}
	
	return error;
}
Пример #6
0
// -----------------------------------------------------------------------------
//	CreateCGImageWithQTFromFile
// -----------------------------------------------------------------------------
//
OSStatus
CreateCGImageWithQTFromFile(
	FSRef*						inFSRef,
	CGImageRef*					outImage )
{
	OSStatus					err;
	GraphicsImportComponent		importer;
	FSSpec						fileSpec;
	GWorldPtr					gWorld = NULL;
	Rect						bounds;
	CGDataProviderRef			provider;
	CGColorSpaceRef				colorspace;
	long						width;
	long						height;
	long						rowbytes;
	Ptr							dataPtr;

	// Make an FSRef into an FSSpec
	err = FSGetCatalogInfo( inFSRef, kFSCatInfoNone, NULL, NULL, &fileSpec, NULL );
	require_noerr( err, CantMakeFSSpec );

	err = GetGraphicsImporterForFile( &fileSpec, &importer );
	require_noerr( err, CantGetImporter );
	
	err = GraphicsImportGetNaturalBounds( importer, &bounds );
	require_noerr( err, CantGetBounds );

	// Allocate the buffer
	width = RECT_WIDTH( bounds );
	height = RECT_HEIGHT( bounds );
	rowbytes = width * 4;
	dataPtr = NewPtr( height * rowbytes );
	require_action( dataPtr != NULL, CantAllocBuffer, err = memFullErr );
	
	err = NewGWorldFromPtr( &gWorld, 32, &bounds, NULL, NULL, NULL, dataPtr, rowbytes );
	require_noerr( err, CantCreateGWorld );

	err = GraphicsImportSetGWorld( importer, gWorld, GetGWorldDevice( gWorld) );
	require_noerr( err, CantSetGWorld );

	err = GraphicsImportDraw( importer );
	require_noerr( err, CantDraw );
	
	provider = CGDataProviderCreateWithData( NULL, dataPtr, height * rowbytes,
			GWorldImageBufferRelease );
	require_action( provider != NULL, CantCreateProvider, err = memFullErr );

	colorspace = CGColorSpaceCreateDeviceRGB();
	require_action( colorspace != NULL, CantCreateColorSpace, err = memFullErr );
	
	*outImage = CGImageCreate( width, height, 8, 32, rowbytes, colorspace,
			kCGImageAlphaPremultipliedFirst, provider, NULL, false, kCGRenderingIntentDefault );
	require_action( *outImage != NULL, CantCreateImage, err = memFullErr );
	
CantCreateImage:
	CGColorSpaceRelease( colorspace );

CantCreateColorSpace:
	CGDataProviderRelease( provider );

CantCreateProvider:
CantDraw:
CantSetGWorld:
	if ( gWorld != NULL )
		DisposeGWorld( gWorld );

CantCreateGWorld:
CantAllocBuffer:
CantGetBounds:
CantGetImporter:
CantMakeFSSpec:
	return err;
}