コード例 #1
0
ファイル: movie_shooter.cpp プロジェクト: CCChaos/RyzomCore
// ***************************************************************************
void				CMovieShooter::getFrameData(CFrameHeader *frame, NLMISC::CBitmap &bmp)
{
	uint	w= frame->Width;
	uint	h= frame->Height;
	// resize
	if(bmp.getWidth()!=w || bmp.getHeight()!=h)
		bmp.resize(w, h);
	// unpack.
	uint16	*src= (uint16*)frame->Data;
	CRGBA	*dst= (CRGBA*)&bmp.getPixels()[0];
	for(uint npix= w*h; npix>0; npix--, src++, dst++)
	{
		dst->set565(*src);
	}
}
コード例 #2
0
ファイル: Browse.cpp プロジェクト: mixxit/solinia
void Browse::OnExportBorder() 
{
	// Select a file
	CFileDialog sFile (false, NULL, NULL, OFN_ENABLESIZING,
		"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
	if (sFile.DoModal()==IDOK)
	{
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array;

		// 256 or 128 ?
		int width, height;
		tileBank2.getTileSet (land)->getBorder128 (m_ctrl.Texture==1?CTile::diffuse:CTile::additive)->get (width, height, array);

		// Make a bitmap
		if (width&&height)
		{
			NLMISC::CBitmap bitmap;
			bitmap.resize (width, height, NLMISC::CBitmap::RGBA);

			// Get pixel
			CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

			// Make a copy
			for (int i=0; i<width*height; i++)
			{
				// Copy the pixel
				pPixel->R=array[i].R;
				pPixel->G=array[i].G;
				pPixel->B=array[i].B;
				pPixel->A=array[i].A;
				pPixel++;
			}

			// Write the bitmap
			bool error=false;
			CString pathName=sFile.GetPathName();
			try
			{
				COFile file;
				if (file.open ((const char*)pathName))
				{
					// Export
					bitmap.writeTGA (file, 32);
				}
				else
					error=true;
			}
			catch (Exception& e)
			{
				const char *toto=e.what ();
				error=true;
			}

			// Error during export ?
			if (error)
			{
				// Error message
				char tmp[512];
				sprintf (tmp, "Can't write bitmap %s", (const char*)pathName);
				MessageBox (tmp, "Export border", MB_OK|MB_ICONEXCLAMATION);
			}
		}
	}
}
コード例 #3
0
ファイル: builder_zone.cpp プロジェクト: mixxit/solinia
// ---------------------------------------------------------------------------
void CBuilderZone::snapshotCustom (const char *fileName, uint width, uint height, bool keepRatio, uint sizeSource, bool grayscale)
{
	if (_ZoneRegions.size() == 0)
		return;

	// Some bitmaps
	NLMISC::CBitmap bitmapTmp;
	NLMISC::CBitmap bitmapDest;

	const CZoneRegion *pBZR = &(getDocument ()->getZoneRegion (_ZoneRegionSelected));
	sint32 nMinX = pBZR->getMinX();
	sint32 nMaxX = pBZR->getMaxX();
	sint32 nMinY = pBZR->getMinY();
	sint32 nMaxY = pBZR->getMaxY();

	uint nSizeX = (nMaxX - nMinX + 1)*sizeSource;
	uint nSizeY = (nMaxY - nMinY + 1)*sizeSource;
	sint x, y, j;

	// Keep ratio ?
	if (keepRatio)
		height = (width * nSizeY) / nSizeX;

	// Resize the bitmaps
	bitmapDest.resize (nSizeX, nSizeY, NLMISC::CBitmap::RGBA);

	// white all
	NLMISC::CObjectVector<uint8> &rPixels = bitmapDest.getPixels();
	memset (&rPixels[0], 0xff, rPixels.size ());
	
	// Copy ZoneBitmaps in the bitmap
	CUV uvMin, uvMax;
	ITexture *pTexture;
	CZoneBankElement *pZBE;
	uint8 nRot, nFlip;

	// For each tiles
	for (y = nMinY; y <= nMaxY; ++y)
	for (x = nMinX; x <= nMaxX; ++x)
	{
		const string &rsZoneName = pBZR->getName (x, y);
		if ((rsZoneName == STRING_OUT_OF_BOUND) && (rsZoneName == STRING_UNUSED))
			continue;

		pZBE = _ZoneBank.getElementByZoneName (rsZoneName);
		if (pZBE == NULL)
			continue;

		// Get the texture
		pTexture = _DataBase.getTexture (rsZoneName, pBZR->getPosX(x, y), 
										pBZR->getPosY(x, y), uvMin, uvMax);

		// Generate it
		pTexture->generate ();

		// Be sure it is tga
		pTexture->convertToType (NLMISC::CBitmap::RGBA);

		// Get rot
		nRot = pBZR->getRot(x, y);

		// Get flip
		nFlip = pBZR->getFlip(x, y);

		// Copy the texture

		// Dest bitmap size
		uint destWidth = 1+(uint)((float)pTexture->getWidth() * (uvMax.U - uvMin.U));
		uint destHeight = 1+(uint)((float)pTexture->getHeight() * (uvMax.V - uvMin.V));
		bitmapTmp.resize (destWidth, destHeight, NLMISC::CBitmap::RGBA);

		// Source bitmap size and position
		uint u = (uint)((float)pTexture->getWidth() * uvMin.U);
		uint v = (uint)((float)pTexture->getHeight() * uvMin.V);
		uint sourceWidth = pTexture->getWidth();
		uint sourceHeight = pTexture->getHeight();

		// Source pointer
		uint8 *srcPixels = &(pTexture->getPixels ()[0]);

		// Destination pointer
		uint8 *destPixels = &(bitmapTmp.getPixels ()[0]);

		// Copy the temp bitmap
		for (j = 0; j < (sint)destHeight; ++j)
			// Copy the line
			memcpy (destPixels+(4*j*destWidth), srcPixels + 4 * ( (v + j) * sourceWidth + u), destWidth*4);

		// Flip ?
		if (nFlip)
			bitmapTmp.flipH();

		// Rot ?
		while (nRot)
		{
			bitmapTmp.rot90CW ();
			nRot--;
		}

		// Resize the bitmap to normal size
		if ( (bitmapTmp.getWidth () != sizeSource) || (bitmapTmp.getHeight () != sizeSource) )
			bitmapTmp.resample (sizeSource, sizeSource);

		// Copy it in the map
		bitmapDest.blit (&bitmapTmp, (x-nMinX)*sizeSource, (y-nMinY)*sizeSource);

		pTexture->release ();
	}

	// Resample the final bitmap
	bitmapDest.resample (width, height);
	bitmapDest.flipV ();

	COFile f(fileName, false, false, true);

	if (grayscale)
	{
		bitmapDest.convertToType (NLMISC::CBitmap::Luminance);
		if (bitmapDest.writeTGA (f, 8))
			f.close();
	}
	else
	{
		if (bitmapDest.writeTGA (f, 32))
			f.close();
	}
}
//TODO titegus: replace that by 4 buttons Export128Diffuse, Export128Additive, Export256Diffuse, Export256Diffuse ?
void CTile_browser_dlg::on_exportBorderPushButton_clicked()
{
	// Select a file
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getSaveFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		fileName = QDir::toNativeSeparators(fileName);
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array;

		// 256 or 128 ?
		int width, height;
		//TODO titegus: And So what if Alpha ??? and what about border256 ???
		tileBankBrowser.getTileSet (tileSetIndex)->getBorder128 ((CTile::TBitmap)tileTextureButtonGroup->checkedId())->get (width, height, array);

		// Make a bitmap
		if (width&&height)
		{
			NLMISC::CBitmap bitmap;
			bitmap.resize (width, height, NLMISC::CBitmap::RGBA);

			// Get pixel
			CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

			// Make a copy
			for (int i=0; i<width*height; i++)
			{
				// Copy the pixel
				pPixel->R=array[i].R;
				pPixel->G=array[i].G;
				pPixel->B=array[i].B;
				pPixel->A=array[i].A;
				pPixel++;
			}

			// Write the bitmap
			bool error=false;
			try
			{
				COFile file;
				if (file.open (fileName.toStdString().c_str()))
				{
					// Export
					bitmap.writeTGA (file, 32);
				}
				else
					error=true;
			}
			catch (Exception& e)
			{
				const char *toto=e.what ();
				error=true;
			}

			// Error during export ?
			if (error)
			{
				// Error message
				QString s = tr("Can't write bitmap %1").arg(fileName);
				QMessageBox::information (this, tr("Export border"), s);
			}
		}
	}

}