📄 mapblender.cpp
字号:
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
/**
@file
MapBlender.cpp
@brief
Utility that split big map in tiles, pre-calculate splatting by
pre-calculating coverage map and pre-calculate normals.
*/
#include "MapUtil.h"
#include "MapBlender.h"
namespace Ogre
{
//-----------------------------------------------------------------------
MapBlender::MapBlender()
{
}
//-----------------------------------------------------------------------
MapBlender::~MapBlender()
{
}
//-----------------------------------------------------------------------
void MapBlender::blendColor (uchar *DataDest, uchar *DataA, Real FactorA,
uchar *DataB, Real FactorB)
{
for (uint curr_bpp = 0; curr_bpp < mBpp; curr_bpp++)
{
DataDest[curr_bpp] = uchar (((uint) DataA[curr_bpp]) * FactorA +
((uint) DataB[curr_bpp]) * FactorB);
}
}
//-----------------------------------------------------------------------
Image *MapBlender::blend (Image *AImage, Image *BImage)
{
uchar *DataA = AImage->getData();
uchar *DataB = BImage->getData();
mwidth = AImage->getWidth ();
mheight = AImage->getHeight ();
mBpp = AImage->getNumElemBytes (AImage->getFormat ());
if ((BImage->getNumElemBytes (BImage->getFormat ()) !=
AImage->getNumElemBytes (AImage->getFormat ())) ||
mwidth != BImage->getWidth () ||
mheight != BImage->getHeight ())
{
String err = "Error: Invalid parameters, No way to Blend";
Except( Exception::ERR_INVALIDPARAMS, err, "MapBlender::blend" );
}
DataChunk dc;
dc.allocate (mwidth * mheight * mBpp);
uchar *FinalData = dc.getPtr ();
uint row_count = 0;
uint image_width_size = mwidth * mBpp;
for (uint y = 0; y < mheight; y++)
{
uint col_count = row_count;
for (uint x = 0; x < mwidth; x++)
{
blendColor (&FinalData[col_count],
&DataA[col_count], 0.5f,
&DataB[col_count], 0.5f);
col_count += mBpp;
}
row_count += image_width_size;
}
Image *FinalImage = new Image();
PixelFormat pxlfmt;
switch (mBpp)
{
case 1:
pxlfmt = PF_A8;
break;
case 3:
pxlfmt = PF_A8R8G8B8;
break;
case 4:
pxlfmt = PF_A8R8G8B8;
break;
}
FinalImage->loadRawData (dc, mwidth, mheight, pxlfmt);
dc.clear();
return FinalImage;
}
}//namespace Ogre
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -