Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttzpimagefx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    Global  functions
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void parseIndexes(string indexes, vector<string> &items)</string>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#ifndef MACOSX
Toshihiro Shimizu 890ddd
	char seps[] = " ,;";
Toshihiro Shimizu 890ddd
	char *token;
Toshihiro Shimizu 890ddd
	if (indexes == "all" || indexes == "All" || indexes == "ALL")
Toshihiro Shimizu 890ddd
		indexes = "0-4095";
Toshihiro Shimizu 890ddd
	char *context = 0;
Toshihiro Shimizu 890ddd
	token = strtok_s((char *)(indexes.c_str()), seps, &context);
Toshihiro Shimizu 890ddd
	while (token != NULL) {
Toshihiro Shimizu 890ddd
		items.push_back(token);
Toshihiro Shimizu 890ddd
		token = strtok_s(NULL, seps, &context);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	char seps[] = " ,;";
Toshihiro Shimizu 890ddd
	char *token;
Toshihiro Shimizu 890ddd
	if (indexes == "all" || indexes == "All" || indexes == "ALL")
Toshihiro Shimizu 890ddd
		indexes = "0-4095";
Toshihiro Shimizu 890ddd
	token = strtok((char *)(indexes.c_str()), seps);
Toshihiro Shimizu 890ddd
	while (token != NULL) {
Toshihiro Shimizu 890ddd
		items.push_back(token);
Toshihiro Shimizu 890ddd
		token = strtok(NULL, seps);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void insertIndexes(vector<string> items, PaletteFilterFxRenderData *t)</string>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#ifndef MACOSX
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)items.size(); i++) {
Toshihiro Shimizu 890ddd
		char *starttoken, *endtoken;
Toshihiro Shimizu 890ddd
		char subseps[] = "-";
Toshihiro Shimizu 890ddd
		string tmp = items[i];
Toshihiro Shimizu 890ddd
		char *context = 0;
Toshihiro Shimizu 890ddd
		starttoken = strtok_s((char *)tmp.c_str(), subseps, &context);
Toshihiro Shimizu 890ddd
		endtoken = strtok_s(NULL, subseps, &context);
Toshihiro Shimizu 890ddd
		if (!endtoken && isInt(starttoken)) {
Toshihiro Shimizu 890ddd
			int index;
Toshihiro Shimizu 890ddd
			index = toInt(starttoken);
Toshihiro Shimizu 890ddd
			t->m_colors.insert(index);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			if (isInt(starttoken) && isInt(endtoken)) {
Toshihiro Shimizu 890ddd
				int start, end;
Toshihiro Shimizu 890ddd
				start = toInt(starttoken);
Toshihiro Shimizu 890ddd
				end = toInt(endtoken);
Toshihiro Shimizu 890ddd
				for (int i = start; i <= end; i++)
Toshihiro Shimizu 890ddd
					t->m_colors.insert(i);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	for (int i = 0; i < (int)items.size(); i++) {
Toshihiro Shimizu 890ddd
		char *starttoken, *endtoken;
Toshihiro Shimizu 890ddd
		char subseps[] = "-";
Toshihiro Shimizu 890ddd
		string tmp = items[i];
Toshihiro Shimizu 890ddd
		starttoken = strtok((char *)tmp.c_str(), subseps);
Toshihiro Shimizu 890ddd
		endtoken = strtok(NULL, subseps);
Toshihiro Shimizu 890ddd
		if (!endtoken && isInt(starttoken)) {
Toshihiro Shimizu 890ddd
			int index;
Toshihiro Shimizu 890ddd
			index = toInt(starttoken);
Toshihiro Shimizu 890ddd
			t->m_colors.insert(index);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			if (isInt(starttoken) && isInt(endtoken)) {
Toshihiro Shimizu 890ddd
				int start, end;
Toshihiro Shimizu 890ddd
				start = toInt(starttoken);
Toshihiro Shimizu 890ddd
				end = toInt(endtoken);
Toshihiro Shimizu 890ddd
				for (int i = start; i <= end; i++)
Toshihiro Shimizu 890ddd
					t->m_colors.insert(i);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    ExternalPaletteFxRenderData  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ExternalPaletteFxRenderData::ExternalPaletteFxRenderData(TPaletteP palette, const string &name)
Toshihiro Shimizu 890ddd
	: m_palette(palette), m_name(name)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool ExternalPaletteFxRenderData::operator==(const TRasterFxRenderData &data) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return false; // non sono capace. non ho i pezzi per browsare nell'albero da qui.
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
string ExternalPaletteFxRenderData::toString() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_name;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    PaletteFilterFxRenderData  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PaletteFilterFxRenderData::PaletteFilterFxRenderData()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_keep = false;
Toshihiro Shimizu 890ddd
	m_type = eApplyToInksAndPaints;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool PaletteFilterFxRenderData::operator==(const TRasterFxRenderData &data) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const PaletteFilterFxRenderData *theData = dynamic_cast<const *="" palettefilterfxrenderdata="">(&data);</const>
Toshihiro Shimizu 890ddd
	if (!theData)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return (theData->m_colors == m_colors && theData->m_type == m_type && theData->m_keep == m_keep);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
string PaletteFilterFxRenderData::toString() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	string alias;
Toshihiro Shimizu 890ddd
	std::set<int>::const_iterator it = m_colors.begin();</int>
Toshihiro Shimizu 890ddd
	for (; it != m_colors.end(); ++it)
Toshihiro Shimizu 890ddd
		alias += ::toString(*it);
Toshihiro Shimizu 890ddd
	alias += "keep=" + ::toString((int)m_keep);
Toshihiro Shimizu 890ddd
	alias += "type=" + ::toString(m_type);
Toshihiro Shimizu 890ddd
	return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    SandorFxRenderData  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
SandorFxRenderData::SandorFxRenderData(Type type, int argc, const char *argv[], int border, int shrink,
Toshihiro Shimizu 890ddd
									   const TRectD &controllerBBox, const TRasterP &controller)
Toshihiro Shimizu 890ddd
	: m_type(type), m_border(border), m_shrink(shrink), m_blendParams(), m_callParams(), m_contourParams(), m_argc(argc), m_controllerBBox(controllerBBox), m_controller(controller), m_controllerAlias()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < argc; i++)
Toshihiro Shimizu 890ddd
		m_argv[i] = argv[i];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool SandorFxRenderData::operator==(const TRasterFxRenderData &data) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const SandorFxRenderData *theData = dynamic_cast<const *="" sandorfxrenderdata="">(&data);</const>
Toshihiro Shimizu 890ddd
	if (!theData)
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_type == BlendTz)
Toshihiro Shimizu 890ddd
		return (theData->m_blendParams.m_colorIndex == m_blendParams.m_colorIndex &&
Toshihiro Shimizu 890ddd
				theData->m_blendParams.m_noBlending == m_blendParams.m_noBlending &&
Toshihiro Shimizu 890ddd
				theData->m_blendParams.m_amount == m_blendParams.m_amount &&
Toshihiro Shimizu 890ddd
				theData->m_blendParams.m_smoothness == m_blendParams.m_smoothness);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_type == Calligraphic || m_type == OutBorder)
Toshihiro Shimizu 890ddd
		return (theData->m_callParams.m_colorIndex == m_callParams.m_colorIndex &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_thickness == m_callParams.m_thickness &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_doWDiagonal == m_callParams.m_doWDiagonal &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_noise == m_callParams.m_noise &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_horizontal == m_callParams.m_horizontal &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_vertical == m_callParams.m_vertical &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_accuracy == m_callParams.m_accuracy &&
Toshihiro Shimizu 890ddd
				theData->m_callParams.m_upWDiagonal == m_callParams.m_upWDiagonal);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_type == ArtAtContour)
Toshihiro Shimizu 890ddd
		return (theData->m_contourParams.m_density == m_contourParams.m_density &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_colorIndex == m_contourParams.m_colorIndex &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_keepLine == m_contourParams.m_keepLine &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_maxOrientation == m_contourParams.m_maxOrientation &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_maxDistance == m_contourParams.m_maxDistance &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_maxSize == m_contourParams.m_maxSize &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_minOrientation == m_contourParams.m_minOrientation &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_minDistance == m_contourParams.m_minDistance &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_minSize == m_contourParams.m_minSize &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_randomness == m_contourParams.m_randomness &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_keepColor == m_contourParams.m_keepColor &&
Toshihiro Shimizu 890ddd
				theData->m_contourParams.m_includeAlpha == m_contourParams.m_includeAlpha &&
Toshihiro Shimizu 890ddd
				theData->m_controllerAlias == m_controllerAlias);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
string SandorFxRenderData::toString() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	string alias;
Toshihiro Shimizu 890ddd
	if (m_type == BlendTz) {
Toshihiro Shimizu 890ddd
		alias += ::toString(m_blendParams.m_colorIndex) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_blendParams.m_smoothness) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_blendParams.m_amount) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_blendParams.m_noBlending);
Toshihiro Shimizu 890ddd
		return alias;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_type == Calligraphic || m_type == OutBorder) {
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_colorIndex) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_noise) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_accuracy) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_upWDiagonal) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_vertical) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_upWDiagonal) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_horizontal) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_callParams.m_thickness);
Toshihiro Shimizu 890ddd
		return alias;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_type == ArtAtContour) {
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_maxSize) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_minSize) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_maxOrientation) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_minOrientation) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_randomness) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_maxDistance) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_minDistance) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_density) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_keepLine) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_keepColor) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_includeAlpha) + " ";
Toshihiro Shimizu 890ddd
		alias += ::toString(m_contourParams.m_colorIndex) + " ";
Toshihiro Shimizu 890ddd
		alias += m_controllerAlias;
Toshihiro Shimizu 890ddd
		return alias;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TRectD SandorFxRenderData::getBBoxEnlargement(const TRectD &bbox)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	switch (m_type) {
Toshihiro Shimizu 890ddd
	case BlendTz: {
Toshihiro Shimizu 890ddd
		//Nothing happen, unless we have color 0 among the blended ones. In such case,
Toshihiro Shimizu 890ddd
		//we have to enlarge the bbox proportionally to the amount param.
Toshihiro Shimizu 890ddd
		vector<string> items;</string>
Toshihiro Shimizu 890ddd
		string indexes = std::string(m_argv[0]);
Toshihiro Shimizu 890ddd
		parseIndexes(indexes, items);
Toshihiro Shimizu 890ddd
		PaletteFilterFxRenderData paletteFilterData;
Toshihiro Shimizu 890ddd
		insertIndexes(items, &paletteFilterData);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (paletteFilterData.m_colors.size() > 0 && *paletteFilterData.m_colors.begin() == 0)
Toshihiro Shimizu 890ddd
			return bbox.enlarge(m_blendParams.m_amount);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return bbox;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		CASE Calligraphic : __OR OutBorder:
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			return bbox.enlarge(m_callParams.m_thickness);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		CASE ArtAtContour:
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			return bbox.enlarge(
Toshihiro Shimizu 890ddd
				tmax(tceil(m_controllerBBox.getLx()), tceil(m_controllerBBox.getLy())) * m_contourParams.m_maxSize);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DEFAULT : {
Toshihiro Shimizu 890ddd
		assert(false);
Toshihiro Shimizu 890ddd
		return bbox;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}