Esempio n. 1
0
static struct collection_definition *_get_collection_definition(
	short collection_index)
{
	struct collection_definition **collection= get_collection_header(collection_index)->collection;

	return collection ? (struct collection_definition *) StripAddress(*collection) : (struct collection_definition *) NULL;
}
Esempio n. 2
0
Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory)
{
	static Boolean firstTime = true;
	OSErr result;
	TemporaryMemoryHandle tempMemBlock;
	Ptr tempPtr = nil;

	tempMemBlock = (TemporaryMemoryHandle)TempNewHandle(size + sizeof(TemporaryMemoryBlock), &result);
	if (tempMemBlock && result == noErr) {
		HLockHi((Handle)tempMemBlock);
		tempPtr = (**tempMemBlock).data;
		if (clearMemory) memset(tempPtr, 0, size);
		tempPtr = StripAddress(tempPtr);

		// keep track of the allocated blocks.
		(**tempMemBlock).nextBlock = theTemporaryMemory;
		theTemporaryMemory = tempMemBlock;
	}

#     if !defined(SHARED_LIBRARY_BUILD)
	// install an exit routine to clean up the memory used at the end.
	if (firstTime) {
		atexit(&GC_MacFreeTemporaryMemory);
		firstTime = false;
	}
#     endif

	return tempPtr;
}
Esempio n. 3
0
static struct collection_definition *get_collection_definition(
	short collection_index)
{
	struct collection_definition **collection= get_collection_header(collection_index)->collection;

	vassert(collection, csprintf(temporary, "collection #%d isnÕt loaded", collection_index));

	return (struct collection_definition *) StripAddress(*collection);
}
Esempio n. 4
0
static void *get_collection_shading_tables(
	short collection_index,
	short clut_index)
{
	void *shading_tables= *get_collection_header(collection_index)->shading_tables;

	(byte *)shading_tables+= clut_index*get_shading_table_size(collection_index);
	shading_tables= StripAddress(shading_tables);
	
	return shading_tables;
}
Esempio n. 5
0
static void *get_collection_tint_tables(
	short collection_index,
	short tint_index)
{
	struct collection_definition *definition= get_collection_definition(collection_index);
	void *tint_table= *get_collection_header(collection_index)->shading_tables;

	(byte *)tint_table+= get_shading_table_size(collection_index)*definition->clut_count + shading_table_size*tint_index;
	tint_table= StripAddress(tint_table);
	
	return tint_table;
}
Esempio n. 6
0
static void QTVideo_AddVideoSamplesToMedia (Media theMedia, const Rect *trackFrame)
{
	long maxCompressedSize;
	GWorldPtr theGWorld = nil;
	long curSample;
	Handle compressedData = nil;
	Ptr compressedDataPtr;
	ImageDescriptionHandle imageDesc = nil;
	CGrafPtr oldPort;
	GDHandle oldGDeviceH;
	OSErr err = noErr;



		err = NewGWorld (&theGWorld, 
						kPixelDepth,	/* pixel depth */
						trackFrame, 
						nil, 
						nil, 
						(GWorldFlags) 0 );
		CheckError (err, "NewGWorld error");

		LockPixels (theGWorld->portPixMap);
		err = GetMaxCompressionSize(theGWorld->portPixMap,
									trackFrame, 
									kMgrChoose, /* let ICM choose depth */
									codecNormalQuality, 
									kAnimationCodecType, 
									(CompressorComponent) anyCodec,
									&maxCompressedSize);
		CheckError (err, "GetMaxCompressionSize error" );

		compressedData = NewHandle(maxCompressedSize);
		CheckError( MemError(), "NewHandle error" );

		MoveHHi( compressedData );
		HLock( compressedData );
		compressedDataPtr = StripAddress( *compressedData );

		imageDesc = (ImageDescriptionHandle)NewHandle(4);
		CheckError( MemError(), "NewHandle error" );

		GetGWorld (&oldPort, &oldGDeviceH);
		SetGWorld (theGWorld, nil);

		for (curSample = 1; curSample <= kNumVideoFrames; curSample++) 
		{
			EraseRect (trackFrame);

			QTVideo_DrawFrame(trackFrame, curSample);

			err = CompressImage (theGWorld->portPixMap, 
								trackFrame, 
								codecNormalQuality,
								kAnimationCodecType,
								imageDesc, 
								compressedDataPtr );
			CheckError( err, "CompressImage error" );

			err = AddMediaSample(theMedia, 
								compressedData,
								kNoOffset,	/* no offset in data */
								(**imageDesc).dataSize, 
								kSampleDuration,	/* frame duration = 1/10 sec */
								(SampleDescriptionHandle)imageDesc, 
								kAddOneVideoSample,	/* one sample */
								kSyncSample,	/* self-contained samples */
								nil);
			CheckError( err, "AddMediaSample error" );
		}
		SetGWorld (oldPort, oldGDeviceH);

		if (imageDesc)
		{
			DisposeHandle ((Handle)imageDesc);
		}
		if (compressedData)
		{
			DisposeHandle (compressedData);
		}
		if (theGWorld)
		{
			DisposeGWorld (theGWorld);
		}
} 
Esempio n. 7
0
void TLevelWriter3gp::save(const TImageP &img, int frameIndex)
{
	if (m_cancelled)
		return;

	TRasterImageP image(img);
	int lx = image->getRaster()->getLx();
	int ly = image->getRaster()->getLy();
	//void *buffer = image->getRaster()->getRawData();
	int pixSize = image->getRaster()->getPixelSize();
	if (pixSize != 4)
		throw TImageException(getFilePath(), "Unsupported pixel type");

	QMutexLocker sl(&m_mutex);

	if (!m_properties)
		m_properties = new Tiio::MovWriterProperties();

	Tiio::MovWriterProperties *prop = (Tiio::MovWriterProperties *)(m_properties);

	//CodecType compression = StandardCompressionType;  prop->getCurrentCodec();
	//CodecQ quality = StandardQualityType;  prop->getCurrentQuality();

	if (!m_initDone) {
		//FSSpec fspec;
		Rect frame;
		long max_compressed_size;
		QDErr err;

		m_videoTrack = NewMovieTrack(m_movie, FixRatio((short)lx, 1), FixRatio((short)ly, 1), kNoVolume);

		if ((err = GetMoviesError() != noErr))
			throw TImageException(getFilePath(), "can't create video track");

		m_dataRef = nil;
		m_hMovieData = NewHandle(0);

		// Construct the Handle data reference
		err = PtrToHand(&m_hMovieData, &m_dataRef, sizeof(Handle));

		if ((err = GetMoviesError() != noErr))
			throw TImageException(getFilePath(), "can't create Data Ref");

		m_videoMedia = NewTrackMedia(m_videoTrack, VideoMediaType, (TINT32)m_frameRate, m_dataRef, HandleDataHandlerSubType);

		OpenADefaultComponent(MovieExportType, '3gpp', &m_myExporter);

		//  err = (short)MovieExportDoUserDialog(m_myExporter, m_movie, 0, 0, 0, &m_cancelled);

		//  if (m_cancelled)
		//	  throw TImageException(getFilePath(), "User abort of 3GP render");
		if ((err = GetMoviesError() != noErr))
			throw TImageException(getFilePath(), "can't create video media");
		if ((err = BeginMediaEdits(m_videoMedia)) != noErr)
			throw TImageException(getFilePath(), "can't begin edit video media");
		frame.left = 0;
		frame.top = 0;
		frame.right = lx;
		frame.bottom = ly;

#if 0
  if ((err = NewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0))!=noErr)
#else /* Mac OSX 10.7 later */
		if ((err = QTNewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0)) != noErr)
#endif
		throw TImageException(getFilePath(), "can't create movie buffer");
#ifdef WIN32
		LockPixels(m_gworld->portPixMap);
		if ((err = GetMaxCompressionSize(m_gworld->portPixMap, &frame, 0,
										 quality, compression, anyCodec,
										 &max_compressed_size)) != noErr)
			throw TImageException(getFilePath(), "can't get max compression size");

#else

#if 0
  PixMapHandle pixmapH = GetPortPixMap (m_gworld);
  LockPixels(pixmapH);
#else
		PixMapHandle pixmapH = NULL;
#endif
		max_compressed_size = lx * ly * 4 * 20;

/*if ((err = GetMaxCompressionSize(pixmapH, &frame, 0, 
                                quality,  compression,anyCodec, 
				 &max_compressed_size))!=noErr)
    throw TImageException(getFilePath(), "can't get max compression size");*/
#endif

		m_compressedData = NewHandle(max_compressed_size);

		if ((err = MemError()) != noErr)
			throw TImageException(getFilePath(), "can't allocate compressed data for movie");

		MoveHHi(m_compressedData);
		HLock(m_compressedData);
		if ((err = MemError()) != noErr)
			throw TImageException(getFilePath(), "can't allocate img handle");

#if 0
  m_pixmap = GetGWorldPixMap(m_gworld);
  
  
  if (!LockPixels(m_pixmap))
    throw TImageException(getFilePath(), "can't lock pixels");

  buf    = (PixelXRGB*) GetPixBaseAddr(m_pixmap);
#else
		m_pixmap = NULL;
		buf = NULL;
#endif
		buf_lx = lx;
		buf_ly = ly;

		m_initDone = true;
	}

	unsigned short rowBytes = (unsigned short)(((short)(*(m_pixmap))->rowBytes & ~(3 << 14)));

	Rect frame;
	ImageDescriptionHandle img_descr;
	Ptr compressed_data_ptr;
	QDErr err;

	frame.left = 0;
	frame.top = 0;
	frame.right = lx;
	frame.bottom = ly;

	TRasterP ras = image->getRaster();
#ifdef WIN32
	compressed_data_ptr = StripAddress(*(m_compressedData));
	copy(ras, buf, buf_lx, buf_ly);
#else
	compressed_data_ptr = *m_compressedData;
	copy(ras, buf, buf_lx, buf_ly, rowBytes);
#endif
	img_descr = (ImageDescriptionHandle)NewHandle(4);

#ifdef WIN32
	if ((err = CompressImage(m_gworld->portPixMap,
							 &frame,
							 quality, compression,
							 img_descr, compressed_data_ptr)) != noErr)
		throw TImageException(getFilePath(), "can't compress image");
#else

#if 0
 PixMapHandle pixmapH = GetPortPixMap (m_gworld);
 if ((err = CompressImage(pixmapH, 
	                 &frame, 
  			 codecNormalQuality, kJPEGCodecType,
			 img_descr, compressed_data_ptr))!=noErr)
	{
  throw TImageException(getFilePath(), "can't compress image");
}
#endif
#endif

	if ((err = AddMediaSample(m_videoMedia, m_compressedData, 0,
							  (*img_descr)->dataSize, 1,
							  (SampleDescriptionHandle)img_descr,
							  1, 0, 0)) != noErr)
		throw TImageException(getFilePath(), "can't add image to movie media");

	DisposeHandle((Handle)img_descr);
}
Esempio n. 8
0
static OSErr QTDR_AddVideoSamplesToMedia (Media theMedia, short theTrackWidth, short theTrackHeight)
{
	GWorldPtr					myGWorld = NULL;
	PixMapHandle				myPixMap = NULL;
	CodecType					myCodecType = kJPEGCodecType;
	long						myNumSample;
	long						myMaxComprSize = 0L;
	Handle						myComprDataHdl = NULL;
	Ptr							myComprDataPtr = NULL;
	ImageDescriptionHandle		myImageDesc = NULL;
	CGrafPtr 					mySavedPort = NULL;
	GDHandle					mySavedDevice = NULL;
	Rect						myRect;
	OSErr						myErr = noErr;

	MacSetRect(&myRect, 0, 0, theTrackWidth, theTrackHeight);

	myErr = NewGWorld(&myGWorld, kPixelDepth, &myRect, NULL, NULL, (GWorldFlags)0);
	if (myErr != noErr)
		goto bail;

	myPixMap = GetGWorldPixMap(myGWorld);
	if (myPixMap == NULL)
		goto bail;

	LockPixels(myPixMap);
	myErr = GetMaxCompressionSize(	myPixMap,
									&myRect, 
									0,							// let ICM choose depth
									codecNormalQuality, 
									myCodecType, 
									(CompressorComponent)anyCodec,
									&myMaxComprSize);
	if (myErr != noErr)
		goto bail;

	myComprDataHdl = NewHandle(myMaxComprSize);
	if (myComprDataHdl == NULL)
		goto bail;

	HLockHi(myComprDataHdl);
#if TARGET_CPU_68K
	myComprDataPtr = StripAddress(*myComprDataHdl);
#else
	myComprDataPtr = *myComprDataHdl;
#endif

	myImageDesc = (ImageDescriptionHandle)NewHandle(4);
	if (myImageDesc == NULL)
		goto bail;

	GetGWorld(&mySavedPort, &mySavedDevice);
	SetGWorld(myGWorld, NULL);

	for (myNumSample = 1; myNumSample <= kNumVideoFrames; myNumSample++) {
		EraseRect(&myRect);
		
		QTDR_DrawFrame(theTrackWidth, theTrackHeight, myNumSample, myGWorld);

		myErr = CompressImage(	myPixMap, 
								&myRect, 
								codecNormalQuality,
								myCodecType,
								myImageDesc, 
								myComprDataPtr);
		if (myErr != noErr)
			goto bail;

		myErr = AddMediaSample(	theMedia, 
								myComprDataHdl,
								0,								// no offset in data
								(**myImageDesc).dataSize, 
								kVideoFrameDuration,			// frame duration
								(SampleDescriptionHandle)myImageDesc, 
								1,								// one sample
								0,								// self-contained samples
								NULL);
		if (myErr != noErr)
			goto bail;
	}

bail:
	SetGWorld(mySavedPort, mySavedDevice);

	if (myImageDesc != NULL)
		DisposeHandle((Handle)myImageDesc);

	if (myComprDataHdl != NULL)
		DisposeHandle(myComprDataHdl);

	if (myGWorld != NULL)
		DisposeGWorld(myGWorld);
		
	return(myErr);
}
Esempio n. 9
0
OSErr NetDDPOpenSocket(
    short *socketNumber,
    packetHandlerProcPtr packetHandler)
{
    OSErr     error;
    Handle    socket_listener_resource;
    ProcPtr   initialize_socket_listener, socket_listener;
    MPPPBPtr  myMPPPBPtr= (MPPPBPtr) NewPtrClear(sizeof(MPPParamBlock));

    static ProcPtr           initialize_upp = NULL;
    static UniversalProcPtr  packet_handler_upp = NULL;

    assert(packetHandler); /* canÕt have NULL packet handlers */
    assert(!ddpPacketBuffer); /* canÕt have more than one socket listener installed */

    socket_listener_resource = GetResource(SOCKET_LISTENER_RESOURCE_TYPE, SOCKET_LISTENER_ID);
    assert(socket_listener_resource);
    HLock(socket_listener_resource);
    HNoPurge(socket_listener_resource);

    initialize_socket_listener = (ProcPtr) StripAddress(*socket_listener_resource);

    ddpPacketBuffer= (DDPPacketBufferPtr) NewPtrClear(sizeof(DDPPacketBuffer));

    error= MemError();
    if (error==noErr)
    {
        if (packet_handler_upp == NULL)
        {
            packet_handler_upp = (UniversalProcPtr) NewRoutineDescriptor((ProcPtr) packetHandler,
                                 uppPacketHandlerProcInfo, GetCurrentISA());
        }
        assert(packet_handler_upp);

        if (initialize_upp == NULL)
        {
            initialize_upp = (ProcPtr) NewRoutineDescriptor((ProcPtr) initialize_socket_listener,
                             uppInitializeListenerProcInfo, kM68kISA); // it's in a 68k code resource
        }
        assert(initialize_upp);

#ifdef env68k  // it seems that we don't have CallUniversalProc() in the library. strange...
#ifndef VULCAN

        socket_listener = (ProcPtr) initialize_socket_listener(packet_handler_upp,
                          ddpPacketBuffer, 1);
#else
        debugstr("Hey, socket listener was never initialized");
#endif
#else
        socket_listener = (ProcPtr) CallUniversalProc((UniversalProcPtr) initialize_upp, uppInitializeListenerProcInfo,
                          packet_handler_upp, ddpPacketBuffer, 1);
#endif

        listenerUPP = (DDPSocketListenerUPP) NewRoutineDescriptor((ProcPtr) socket_listener, uppDDPSocketListenerProcInfo,
                      kM68kISA); // have to force it to realize that it's a 68K resource
        assert(listenerUPP);

        myMPPPBPtr->DDP.socket= 0;
        myMPPPBPtr->DDP.u.listener= listenerUPP;

        error= POpenSkt(myMPPPBPtr, FALSE);
        if (error==noErr)
        {
            *socketNumber= myMPPPBPtr->DDP.socket;
        }

        DisposePtr((Ptr)myMPPPBPtr);
    }

    return error;
}