Ejemplo n.º 1
0
	ISurface* DFBImageProvider::prepare(bool isGif) {
		ISurface* renderedSurface = NULL;

		IDirectFBImageProvider* ip;
		ip = (IDirectFBImageProvider*)decoder;

		DFBImageDescription imgDsc;
		IDirectFBSurface* destination = NULL;
		DFBSurfaceDescription surDsc;
		IColor* chromaKey = NULL;

		//IDirectFBSurface* source;
		if ((ip->GetImageDescription(ip, &imgDsc) == DFB_OK) &&
			 (ip->GetSurfaceDescription(ip, &surDsc) == DFB_OK)) {

			destination = (IDirectFBSurface*)(
					LocalDeviceManager::getInstance()->createSurface(&surDsc));

			renderedSurface = new DFBSurface(destination);

			if (imgDsc.caps & DICAPS_ALPHACHANNEL) {
				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " setted alphachannel: ";*/

				//alpha channel of gif does not exists anymore, it turn into
				//black src color key (marcio 20/04/2007)
				if (isGif) {
					chromaKey = new Color(0, 0, 0);
					renderedSurface->setChromaColor(chromaKey);
					//outputDisplay->setColorKey(0, 0, 0);
					//cout << "black color cause it is a gif image" << endl;

				} else {
					renderedSurface->setCaps(DWCAPS_ALPHACHANNEL);
				}

				//cout << " trying to blit image alpha channel" << endl;

				DFBCHECK(destination->SetBlittingFlags(destination,
					 (DFBSurfaceBlittingFlags)(DSBLIT_BLEND_ALPHACHANNEL)));

				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " setted alpha: '";
				cout << (((int)(imgDsc.colorkey_r & 0xFF)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_g)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_b)) & 0xFF);
				cout << "'" << endl;*/
			}

			if (imgDsc.caps & DICAPS_COLORKEY) {
				chromaKey = new Color(
					    imgDsc.colorkey_r,
					    imgDsc.colorkey_g,
					    imgDsc.colorkey_b);

				DFBCHECK(destination->SetBlittingFlags(destination,
					    (DFBSurfaceBlittingFlags)(
					    DSBLIT_BLEND_ALPHACHANNEL |
					    DSBLIT_SRC_COLORKEY)));

				renderedSurface->setChromaColor(chromaKey);
				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " setted colorkey: '";
				cout << (((int)(imgDsc.colorkey_r & 0xFF)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_g)) & 0xFF);
				cout << ", " << (((int)(imgDsc.colorkey_b)) & 0xFF);
				cout << "'" << endl;*/
			}

			if (imgDsc.caps & DICAPS_NONE) {
				DFBCHECK(destination->SetBlittingFlags(destination,
					    (DFBSurfaceBlittingFlags)DSBLIT_NOFX));

				renderedSurface->setCaps(DWCAPS_NONE);
				/*cout << "ImagePlayer::ImagePlayer(" << mrl << ")";
				cout << " NOFX" << endl;*/
			}
		}

		if (destination != NULL && renderedSurface != NULL) {
			DFBCHECK(ip->RenderTo(
					ip,
					(IDirectFBSurface*)(renderedSurface->getContent()), NULL));
		}
		return renderedSurface;
	}