⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filter_utils.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 3 页
字号:
	if( !trParam )
		return false;
	
	nType = trParam.Type.nVal;
	if( FILTER_TYPE_ASCII == trFilter.Type.nVal )
	{
		if( !trParam.Line || !trParam.Pos || !trParam.End )
			return false;
		n1 = trParam.Line.nVal;
		n2 = trParam.Pos.nVal;
		n3 = trParam.End.nVal;
	}
	else // FILTER_TYPE_BINARY
	{
		if( !trParam.Offset || !trParam.Size )
			return false;
		n1 = trParam.Offset.nVal;
		n2 = trParam.Size.nVal;
		// n3 is not used
	}
	
	return true;
}

bool fuGetASCHeaderParam(TreeNode &trFilter, LPCSTR lpcszName, int &nType, int &nLine, int &nPos, int &nEnd)
{
	return fuGetHeaderParam(trFilter, lpcszName, nType, nLine, nPos, nEnd);
}

bool fuGetBinHeaderParam(TreeNode &trFilter, LPCSTR lpcszName, int &nType, int &nOffset, int &nSize)
{
	int n; // temp var for last arg
	return fuGetHeaderParam(trFilter, lpcszName, nType, nOffset, nSize, n);
}

bool fuGetHdrVarScan(TreeNode &trFilter, int &iFirstLine, int &iLastLine, int &iSeparator)
{
	TreeNode trParams = fuGetHeaderParams(trFilter);
	if( !trParams )
		return false;
	if( !trParams.FirstLine || !trParams.LastLine || !trParams.Separator )
		return false;
	iFirstLine = trParams.FirstLine.nVal;
	iLastLine = trParams.LastLine.nVal;
	iSeparator = trParams.Separator.nVal;
	return true;
}

bool fuSetHdrVarScan(TreeNode &trFilter, int iFirstLine, int iLastLine, int iSeparator)
{
	TreeNode trParams = fuGetHeaderParams(trFilter);
	if( !trParams )
		return false;
	trParams.FirstLine.nVal = iFirstLine;
	trParams.LastLine.nVal = iLastLine;
	trParams.Separator.nVal = iSeparator;
	return true;
}

bool fuGetHdrSave(TreeNode &trFilter, int &iFirstLine, int &iNumLines)
{
	if( !trFilter.Common.HdrSaveFirstLine || !trFilter.Common.HdrSaveNumLines )
		return false;
	iFirstLine = trFilter.Common.HdrSaveFirstLine.nVal;
	iNumLines = trFilter.Common.HdrSaveNumLines.nVal;
	return true;
}

bool fuSetHdrSave(TreeNode &trFilter, int iFirstLine, int iNumLines)
{
	trFilter.Common.HdrSaveFirstLine.nVal = iFirstLine;
	trFilter.Common.HdrSaveNumLines.nVal = iNumLines;
	return true;
}

//--------------------------------------------------------------------------
bool fuGetFileSpec(TreeNode &trFilter, string &strFileSpec)
{
	if( trFilter.Common.FileSpec )
		strFileSpec = trFilter.Common.FileSpec.strVal;
	else
		strFileSpec.Empty();
	return true;
}

bool fuSetFileSpec(TreeNode &trFilter, LPCSTR lpcstrFileSpec)
{
	trFilter.Common.FileSpec.strVal = lpcstrFileSpec;
	return true;
}

bool fuGetFilesOfTypeGroupName(TreeNode &trFilter, string &strName)
{
	if( trFilter.Common.GroupName )
		strName = trFilter.Common.GroupName.strVal;
	else
		strName.Empty();
	return true;
}

bool fuSetFilesOfTypeGroupName(TreeNode &trFilter, LPCSTR lpcstrName)
{
	trFilter.Common.GroupName.strVal = lpcstrName;
	return true;
}

bool fuGetFilesOfType(TreeNode &trFilter, StringArray &saFileSpecNames)
{
	if( trFilter &&	trFilter.Common && trFilter.Common.FilesOfType && trFilter.Common.FilesOfType.Names )
	{
		TreeNode trName = trFilter.Common.FilesOfType.Names.FirstNode;
		while( trName )
		{
			saFileSpecNames.Add(trName.strVal);
			trName = trName.NextNode;
		}
		return true;
	}
	return false;
}

bool fuSetFilesOfType(TreeNode &trFilter, StringArray &saFileSpecNames)
{
	trFilter.Common.FilesOfType.RemoveChild("Names");
	TreeNode trNames = trFilter.Common.FilesOfType.AddNode("Names");
	if( trNames )
	{
		string str;
		for( int i = 0; i < saFileSpecNames.GetSize(); i++ )
		{
			str.Format("Type%d", i);
			trNames.AddTextNode(saFileSpecNames[i], str);
		}
		return true;
	}
	return false;
}

//--------------------------------------------------------------------------
BOOL fuIsFileNameToWksLabel(TreeNode &trFilter)
{
	if( trFilter.Common.FileNameToWksLabel )
		return trFilter.Common.FileNameToWksLabel.nVal;
	return TRUE; // on by default 
}

void fuSetFileNameToWksLabel(TreeNode &trFilter, BOOL bSet)
{
	trFilter.Common.FileNameToWksLabel.nVal = bSet;
}

//--------------------------------------------------------------------------
/// EJP 07-07-2003 v7.0619 QA70-4783 POST_IMPORT_EXECUTE
bool fuGetPostImportScript(TreeNode &trFilter, string &strScript)
{
	if( !trFilter.Common.PostImportScript )
		return false;
	strScript = trFilter.Common.PostImportScript.strVal;
	
	// The string went into the filter with CR-LF combo, but the tree or XML
	// code strips the CR char.  Here I will replace all LF chars with CR-LF combo.
	// First check if combo is there in case tree or XML behavior changes.
	if( -1 == strScript.Find("\r\n") ) // If CR-LF combo is not found
		strScript.Replace("\n", "\r\n"); // Replace LF with CR-LF
	
	return true;
}

void fuSetPostImportScript(TreeNode &trFilter, LPCSTR lpcszScript)
{
	trFilter.Common.PostImportScript.strVal = lpcszScript;
}
/// end POST_IMPORT_EXECUTE

//--------------------------------------------------------------------------
/// EJP 07-17-2003 v7.0627 QA70-4818 SAVE_FILTER_IN_WKS
bool fuGetPageFilterName(string &strName, int iType)
{
	switch( iType )
	{
	case FILTER_TYPE_ASCII:
		strName += "ImportFilter_ASCII";
		break;
	case FILTER_TYPE_BINARY:
		strName += "ImportFilter_Binary";
		break;
	case FILTER_TYPE_USERDEFINED:
		strName += "ImportFilter_UserDefined";
		break;
	default:
		return false;
	}
	return true;
}

bool fuIsOneFilterInPage(Page &pgTarget, LPCSTR lpcszDataFile, int &iFilterType)
{
	int iType;
	int iCount = 0;
	
	if( fuIsFilterInPage(pgTarget, FILTER_TYPE_ASCII, lpcszDataFile) )
	{
		iType = FILTER_TYPE_ASCII;
		iCount++;
	}
	if( fuIsFilterInPage(pgTarget, FILTER_TYPE_BINARY, lpcszDataFile) )
	{
		iType = FILTER_TYPE_BINARY;
		iCount++;
	}
	if( fuIsFilterInPage(pgTarget, FILTER_TYPE_USERDEFINED, lpcszDataFile) )
	{
		iType = FILTER_TYPE_USERDEFINED;
		iCount++;
	}

	if( 1 == iCount )
	{
		iFilterType = iType;
		return true;
	}
	return false;
}

bool fuIsFilterInPage(Page &pgTarget, int iType, LPCSTR lpcszDataFile)
{
	/*
	string strName;
	if( fuGetPageFilterName(strName, iType) )
	{
		vector<byte> vb;
		if( pgTarget.GetMemory(strName, vb) )
		{
			if( !lpcszDataFile )
				return true;
			
			Tree trFilter(lpcszFilterFile);
	if( trFilter )
			return fuIsApplicable(trFilter, lpcszDataFile, iType);
		}
	}
	*/	
	if( IS_FILTER_TYPE(iType) )
	{
		Tree trFilter;
		if( fuLoadFilterFromPage(trFilter, pgTarget, iType) )
			return fuIsApplicable(trFilter, lpcszDataFile, iType);
	}
	else
	{
		if( fuIsFilterInPage(pgTarget, FILTER_TYPE_ASCII, lpcszDataFile) )
			return true;
		if( fuIsFilterInPage(pgTarget, FILTER_TYPE_BINARY, lpcszDataFile) )
			return true;
		if( fuIsFilterInPage(pgTarget, FILTER_TYPE_USERDEFINED, lpcszDataFile) )
			return true;
	}
	return false;
}

bool fuSaveFilterToPage(TreeNode &trFilter, Page &pgTarget)
{
	string strFilter = trFilter.XML;
	vector<byte> vb;
	if( strFilter.GetBytes(vb) )
	{
		string strName;
		if( fuGetPageFilterName(strName, trFilter.Type.nVal) )
		{
			if( pgTarget.SetMemory(strName, vb) )
				return true;
		}
	}
	return false;
}

bool fuLoadFilterFromPage(TreeNode &trFilter, Page &pgTarget, int iType)
{
	string strName;
	if( fuGetPageFilterName(strName, iType) )
	{
		vector<byte> vb;
		if( pgTarget.GetMemory(strName, vb) )
		{
			string strFilter;
			if( strFilter.SetBytes(vb) )
			{
				trFilter.XML = strFilter;
				return true;
			}
		}
	}
	return false;
}
/// end SAVE_FILTER_IN_WKS

bool fuGetUserDefinedFunction(TreeNode &trFilter, string &strOCFile, string &strOCFunction)
{
	if( trFilter.Common.OCFile && trFilter.Common.OCFunction )
	{
		strOCFile = trFilter.Common.OCFile.strVal;
		strOCFunction = trFilter.Common.OCFunction.strVal;
		return true;
	}
	return false;
}

bool fuSetUserDefinedFunction(TreeNode &trFilter, LPCSTR lpcszOCFile, LPCSTR lpcszOCFunction)
{
	trFilter.Common.OCFile.strVal = lpcszOCFile;
	trFilter.Common.OCFunction.strVal = lpcszOCFunction;
	return true;
}

/// EJP 09-09-2003 v7.5689 QA70-4818 UPDATE_ASCIMP_FROM_FILTER_SAVED_TO_WKS
bool fuUpdatePageASCIMP(Page &pg, bool bUpdateInternal)
{
	Tree trFilter;
	if( !fuLoadFilterFromPage(trFilter, pg, FILTER_TYPE_ASCII) )
		return false; // page does not have an ASCII filter

	Worksheet wks(pg.GetName());
	if( !wks )
		return false; // failed to get reference to wks

	ASCIMP ascimp;
	if( bUpdateInternal ) // update internal settings from filter
	{
		if( !fuGetASCIMP(trFilter, ascimp) )
			return false; // failed to get ASCIMP from filter
		wks.SetASCIMP(ascimp);
	}
	else // update filter from internal settings
	{
		wks.GetASCIMP(ascimp);
		fuSetASCIMP(trFilter, ascimp);
		fuSaveFilterToPage(trFilter, pg);
	}
	return true; // ascimp updated
}
/// end UPDATE_ASCIMP_FROM_FILTER_SAVED_TO_WKS

bool fuSave(TreeNode &trFilter, LPCSTR lpcszFile)
{
	if( !lpcszFile )
		return false;

	double d;
	LT_get_var("@V", &d);
	trFilter.OriginVersion.dVal = d;

	Tree tr;
	tr = trFilter;
	
	return tr.Save(lpcszFile);
}

bool fuLoad(TreeNode &trFilter, LPCSTR lpcszFile)
{
	if( !lpcszFile )
		return false;

	Tree tr;
	tr = trFilter;

	return tr.Load(lpcszFile);
}

/// EJP 09-24-2003 v7.5706 QA70-4073.55 ADD_FILTER_DESCRIPTION
bool fuGetDescription(TreeNode &trFilter, string &strDescrip)
{
	TreeNode trn;
	trn = trFilter.Common.Description;
	if( trn )
	{
		strDescrip = trFilter.Common.Description.strVal;
		return true;
	}
	return false;
}

bool fuSetDescription(TreeNode &trFilter, LPCSTR lpcszDescrip)
{
	if( trFilter && lpcszDescrip )
	{
		trFilter.Common.Description.strVal = lpcszDescrip;
		return true;
	}
	return false;
}
/// end ADD_FILTER_DESCRIPTION

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -