コード例 #1
0
//=============================================
//		CNSmlDSCrypt::EncryptedL()
//		Destructor.
//=============================================
EXPORT_C TDesC& CNSmlDSCrypt::EncryptedL( const TDesC& aInput )
	{
	delete iOutput;
	iOutput = 0;

	iOutput = aInput.AllocL();

	TPtr ptrOutput( iOutput->Des() );
	
	// Keys to be used in encryption / decryption.
	TUint16 key1 = 0xa576;
	TUint16 key2 = 0x02f9;

	for (TInt i = 0; i < iOutput->Length(); i++ )
		{
		key1 %= key2;
		key1 <<= 7;
		key1 ^= key2;
		key2 %= key1;
		key2 <<= 3;
		key2 ^= key1;
		ptrOutput[i] ^= key1;
		}

	return *iOutput;
	}
コード例 #2
0
ファイル: ImageProcessor.cpp プロジェクト: krinnewitz/ccv
void ImageProcessor::reduceColors(cv::Mat input, cv::Mat &output, int numColors)
{
	//allocate output
	output = cv::Mat(input.size(), CV_8U);
	//3 channel pointer to input image
	cv::Mat_<cv::Vec3b>& ptrInput = (cv::Mat_<cv::Vec3b>&)input; 
	//1 channel pointer to output image
	cv::Mat_<uchar>& ptrOutput = (cv::Mat_<uchar>&)output;

	for (int y = 0; y < input.size().height; y++)
	{
		for(int x = 0; x < input.size().width; x++)
		{
			unsigned long int currCol = 0;
			currCol |= (ptrInput(y, x)[0]) << 16;
			currCol |= (ptrInput(y, x)[1]) <<  8;
			currCol |= (ptrInput(y, x)[2]) <<  0;
			ptrOutput(y,x) = currCol / (pow(2, 24) / numColors);
		}
	}
}
コード例 #3
0
ファイル: ImageProcessor.cpp プロジェクト: krinnewitz/ccv
void ImageProcessor::connectedCompLabeling(cv::Mat input, cv::Mat &output)
{
	//Allocate output and set it to zero
	output = cv::Mat(input.size(), CV_16U);
	output.setTo(cv::Scalar(0));
	
	//1 channel pointer to input image
	cv::Mat_<uchar>& ptrInput = (cv::Mat_<uchar>&)input;
	//1 channel pointer to output image
	cv::Mat_<ushort>& ptrOutput = (cv::Mat_<ushort>&)output; 

	//disjoint set data structure to manage the labels 
	unsigned long int* parent = new unsigned long int[output.size().height * output.size().width];
	for(unsigned long int i = 0; i < output.size().height * output.size().width; i++) parent[i] = i;

	std::vector<int>  rank (output.size().height * output.size().width);
//	std::vector<int>  parent (output.size().height * output.size().width);
//	boost::disjoint_sets<int*,int*> ds(&rank[0], &parent[0]);
//	for(unsigned long int i = 0; i < output.size().height * output.size().width; i++) {ds.make_set(i);}

	//first pass: Initial labeling
	unsigned short int currentLabel = 0;
	for (int y = 0; y < input.size().height; y++)
	{
		for(int x = 0; x < input.size().width; x++)
		{
			if (y == 0)
			{
				if(x == 0)
				{
					//First pixel. Create first label.
					ptrOutput(y,x) = ++currentLabel;
				}
				else
				{
					//First row. Only check left pixel	
					if (ptrInput(y,x) == ptrInput(y, x - 1))
					{
						//same region as left pixel -> assign same label
						ptrOutput(y,x) = ptrOutput(y, x - 1);
					}
					else
					{
						//different region -> create new label
						ptrOutput(y,x) = ++currentLabel;
					}
				}
			}
			else
			{
				if(x == 0)
				{
					//First column. Only check top pixel	
					if (ptrInput(y,x) == ptrInput(y - 1, x))
					{
						//same region as top pixel -> assign same label
						ptrOutput(y,x) = ptrOutput(y - 1, x);
					}
					else
					{
						//different region -> create new label
						ptrOutput(y,x) = ++currentLabel;
					}
				}
				else
				{
					//Regular column. Check top and left pixel
					if (ptrInput(y,x) == ptrInput(y, x - 1) && ptrInput(y,x) == ptrInput(y - 1, x))
					{
						//same region as left and top pixel -> assign minimum label of both
						ptrOutput(y,x) = std::min(ptrOutput(y, x - 1), ptrOutput(y - 1, x));
						if (ptrOutput(y, x - 1) != ptrOutput(y - 1, x))
						{
							//mark labels as equivalent
							//we are using the union/find algorithm for disjoint sets
							ImageProcessor::unite(ImageProcessor::find(ptrOutput(y, x - 1), parent),
									      ImageProcessor::find(ptrOutput(y - 1, x), parent), parent);
//							ds.union_set(ptrOutput(y, x - 1), ptrOutput(y - 1, x));
						}
					}
					else
					if (ptrInput(y,x) == ptrInput(y, x - 1))
					{
						//same region as left pixel -> assign same label
						ptrOutput(y,x) = ptrOutput(y, x - 1);
					}
					else
					if (ptrInput(y,x) == ptrInput(y - 1, x))
					{
						//same region as top pixel -> assign same label
						ptrOutput(y,x) = ptrOutput(y - 1, x);
					}
					else
					{
						//different region -> create new label
						ptrOutput(y,x) = ++currentLabel;
					}
				}
			}
		}
	}

	//second pass: Merge equivalent labels
	for (int y = 0; y < output.size().height; y++)
	{
		for(int x = 0; x < output.size().width; x++)
		{
			//we are using the union/find algorithm for disjoint sets
			ptrOutput(y,x) = (unsigned short int) ImageProcessor::find(ptrOutput(y, x), parent);
//			ptrOutput(y,x) = ds.find_set(ptrOutput(y, x));
		}
	}

	delete[] parent;
}