📄 mapmergemodulater.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
MapMergeModulater.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 "MapMergeModulater.h"
#include <iostream>
#include <fstream>
#include <vector>
#include "OgreImageCodec.h"
#include "OgreILCodecs.h"
#include "fileutils.h"
namespace Ogre
{
//-----------------------------------------------------------------------
MapMergeModulater::MapMergeModulater()
{
}
//-----------------------------------------------------------------------
MapMergeModulater::~MapMergeModulater()
{
}
//-----------------------------------------------------------------------
void MapMergeModulater::ModulateGrayAndRgbInRgb(Image *GrayImage, Image *RgbImage,
uint factor)
{
uchar *DataRGB = RgbImage->getData();
uchar *DataGray = GrayImage->getData();
uint image_width = RgbImage->getWidth ();
uint image_height = RgbImage->getHeight ();
if (GrayImage->getNumElemBytes (GrayImage->getFormat ()) != 1 ||
RgbImage->getNumElemBytes (RgbImage->getFormat ()) != 3 ||
image_width != GrayImage->getWidth () ||
image_height != GrayImage->getHeight ())
{
String err = "Error: Invalid parameters, No way to modulate";
Except( Exception::ERR_INVALIDPARAMS, err, "MapMergeModulater::ModulateGrayAndRgbInRgb" );
}
uint row_count_rgb = 0;
uint row_count_gray = 0;
uint image_width_rgb_size = image_width * 3;
Real modulate = (Real) factor / 255.0f;
for (uint j = 0; j < image_height; j++)
{
uint col_count_rgb = row_count_rgb;
for (uint i = 0; i < image_width; i++)
{
Real Gray = DataGray[row_count_gray + i] * modulate;
Real Color = DataRGB[ col_count_rgb] * Gray;
if (Color > 255.0f)
Color = 255.0f;
DataRGB[col_count_rgb] = uchar(Color);
Color = DataRGB[ col_count_rgb + 1] * Gray;
if (Color > 255.0f)
Color = 255.0f;
DataRGB[col_count_rgb + 1] = uchar(Color);
Color = DataRGB[ col_count_rgb + 2] * Gray;
if (Color > 255.0f)
Color = 255.0f;
DataRGB[col_count_rgb + 2] = uchar(Color);
col_count_rgb += 3;
}
row_count_gray += image_width;
row_count_rgb += image_width_rgb_size;
}
}
//-----------------------------------------------------------------------
void MapMergeModulater::ModulateGrayAndRgbaInRgba (Image *GrayImage, Image *RgbaImage,
uint factor)
{
uchar *DataRGBA = RgbaImage->getData();
uchar *DataGray = GrayImage->getData();
uint image_width = RgbaImage->getWidth ();
uint image_height = RgbaImage->getHeight ();
if (GrayImage->getNumElemBytes (GrayImage->getFormat ()) != 1 ||
RgbaImage->getNumElemBytes (RgbaImage->getFormat ()) != 4 ||
image_width != GrayImage->getWidth () ||
image_height != GrayImage->getHeight ())
{
String err = "Error: Invalid parameters, No way to modulate";
Except( Exception::ERR_INVALIDPARAMS, err, "MapMergeModulater::ModulateGrayAndRgbInRgb" );
}
uint row_count_rgba = 0;
uint row_count_gray = 0;
uint image_width_rgba_size = image_width * 4;
Real modulate = (Real) factor / 255.0f;
for (uint j = 0; j < image_height; j++)
{
uint col_count_rgba = row_count_rgba;
for (uint i = 0; i < image_width; i++)
{
Real Gray = DataGray[row_count_gray + i] * modulate;
Real Color = DataRGBA[ col_count_rgba] * Gray;
if (Color > 255.0f)
Color = 255.0f;
DataRGBA[col_count_rgba] = uchar(Color);
Color = DataRGBA[ col_count_rgba + 1] * Gray;
if (Color > 255.0f)
Color = 255.0f;
DataRGBA[col_count_rgba + 1] = uchar(Color);
Color = DataRGBA[ col_count_rgba + 2] * Gray;
if (Color > 255.0f)
Color = 255.0f;
DataRGBA[col_count_rgba + 2] = uchar(Color);
col_count_rgba += 4;
}
row_count_gray += image_width;
row_count_rgba += image_width_rgba_size;
}
}
//-----------------------------------------------------------------------
void MapMergeModulater::MergeGrayAndRgbaInRgba (Image *GrayImage, Image *RgbaImage)
{
uchar *DataRGBA = RgbaImage->getData();
uchar *DataGray = GrayImage->getData();
uint image_width = RgbaImage->getWidth ();
uint image_height = RgbaImage->getHeight ();
if (GrayImage->getNumElemBytes (GrayImage->getFormat ()) != 1 ||
RgbaImage->getNumElemBytes (RgbaImage->getFormat ()) != 4 ||
image_width != GrayImage->getWidth () ||
image_height != GrayImage->getHeight ())
{
String err = "Error: Invalid parameters, No way to Merge";
Except( Exception::ERR_INVALIDPARAMS, err, "MapMergeModulater::MergeGrayAndRgbaInRgba" );
}
uint row_count_rgba = 0;
uint row_count_gray = 0;
uint image_width_rgba_size = image_width * 4;
for (uint j = 0; j < image_height; j++)
{
uint col_count_rgba = row_count_rgba;
for (uint i = 0; i < image_width; i++)
{
DataRGBA[col_count_rgba] = DataGray[row_count_gray + i];
DataRGBA[col_count_rgba + 1] = DataGray[row_count_gray + i];
DataRGBA[col_count_rgba + 2] = DataGray[row_count_gray + i];
col_count_rgba += 4;
}
row_count_rgba += image_width_rgba_size;
row_count_gray += image_width;
}
}
//-----------------------------------------------------------------------
Image *MapMergeModulater::MergeGrayAndRgbInRgba(Image *GrayImage, Image *RgbImage)
{
uchar *DataRGB = RgbImage->getData();
uchar *DataGray = GrayImage->getData();
uint image_width = RgbImage->getWidth ();
uint image_height = RgbImage->getHeight ();
if (GrayImage->getNumElemBytes (GrayImage->getFormat ()) != 1 ||
RgbImage->getNumElemBytes (RgbImage->getFormat ()) != 3 ||
image_width != GrayImage->getWidth () ||
image_height != GrayImage->getHeight ())
{
String err = "Error: Invalid parameters, No way to merge";
Except( Exception::ERR_INVALIDPARAMS, err, "MapMergeModulater::MergeGrayAndRgbInRgba" );
}
DataChunk dc;
dc.allocate(image_width*image_height*4);
uchar *DataRGBA = dc.getPtr ();
uint row_count_rgb = 0;
uint row_count_rgba = 0;
uint row_count_gray = 0;
uint image_width_rgb_size = image_width * 3;
uint image_width_rgba_size = image_width * 4;
for (uint j = 0; j < image_height; j++)
{
uint col_count_rgb = row_count_rgb;
uint col_count_rgba = row_count_rgba;
for (uint i = 0; i < image_width; i++)
{
DataRGBA[col_count_rgba] = DataRGB[col_count_rgb];
DataRGBA[col_count_rgba + 1] = DataRGB[col_count_rgb + 1];
DataRGBA[col_count_rgba + 2] = DataRGB[col_count_rgb + 2];
DataRGBA[col_count_rgba + 3] = DataGray[row_count_gray + i];
col_count_rgb += 3;
col_count_rgba += 4;
}
row_count_gray += image_width;
row_count_rgb += image_width_rgb_size;
row_count_rgba += image_width_rgba_size;
}
Image *RgbaImage = new Image();
RgbaImage->loadRawData (dc, image_width, image_height, PF_A8R8G8B8);
dc.clear();
return RgbaImage;
}
//-----------------------------------------------------------------------
Image *MapMergeModulater::MergeAlphaAndRgbInRgba(Image *AlphaImage, Image *RgbImage)
{
uchar *DataRGB = RgbImage->getData();
uchar *DataAlpha = AlphaImage->getData();
uint image_width = RgbImage->getWidth ();
uint image_height = RgbImage->getHeight ();
if (AlphaImage->getNumElemBytes (AlphaImage->getFormat ()) != 1 ||
RgbImage->getNumElemBytes (RgbImage->getFormat ()) != 3 ||
image_width != AlphaImage->getWidth () ||
image_height != AlphaImage->getHeight ())
{
String err = "Error: Invalid parameters, No way to merge";
Except( Exception::ERR_INVALIDPARAMS, err, "MapMergeModulater::MergeAlphaAndRgbInRgba" );
}
DataChunk dc;
dc.allocate(image_width*image_height*4);
uchar *DataRGBA = dc.getPtr ();
uint row_count_rgb = 0;
uint row_count_rgba = 0;
uint row_count_Alpha = 0;
uint image_width_rgb_size = image_width * 3;
uint image_width_rgba_size = image_width * 4;
for (uint j = 0; j < image_height; j++)
{
uint col_count_rgb = row_count_rgb;
uint col_count_rgba = row_count_rgba;
for (uint i = 0; i < image_width; i++)
{
DataRGBA[col_count_rgba] = DataRGB[col_count_rgb];
DataRGBA[col_count_rgba + 1] = DataRGB[col_count_rgb + 1];
DataRGBA[col_count_rgba + 2] = DataRGB[col_count_rgb + 2];
DataRGBA[col_count_rgba + 3] = DataAlpha[row_count_Alpha + i];
col_count_rgb += 3;
col_count_rgba += 4;
}
row_count_Alpha += image_width;
row_count_rgb += image_width_rgb_size;
row_count_rgba += image_width_rgba_size;
}
Image *RgbaImage = new Image();
RgbaImage->loadRawData (dc, image_width, image_height, PF_A8R8G8B8);
dc.clear();
return RgbaImage;
}
}//namespace Ogre
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -