Exemplo n.º 1
0
inline vector<int> buildVector(BlockPNG const & b, int d)
{
	vector<int> v;
	for (int i = 1; i <= (b.width() * b.height()) / (d * d); i++)
		v.push_back(i);

	return v;
}
Exemplo n.º 2
0
void testSort()
{
	cout << "[main]: " << __func__ << "()" << endl;
	
	srand(225);

	// read in image to be shuffled
	BlockPNG b;
	b.readFromFile("in_01.png");

	int d = 60;
	vector<int> v = buildVector(b, d);
	random_shuffle(v.begin(), v.end());

	// generate shuffled image (done for you already)
	
	   PNG b2 = b.genImg(v, d);
	   b2.writeToFile("in_01_shuffled_60_exp.png");
	

	// make list and sort it
	List<int> img_srt(v.begin(), v.end());
	img_srt.sort();

	// vectorize and rebuild image
	vector<int> v2(img_srt.begin(), img_srt.end());

	PNG b3 = b.genImg(v2, d);
	b3.writeToFile("unshuffled_60.png");

	checkSoln("testSort", b3, "in_01.png");

	d = 1;
	v = buildVector(b, d);
	random_shuffle(v.begin(), v.end());

	/*
	   PNG q = b.genImg(v, d);
	   q.writeToFile("in_01_shuffled_1.png");
    */

	List<int> q_srt(v.begin(), v.end());
	q_srt.sort();

	v2 = vector<int>(q_srt.begin(), q_srt.end());

	b3 = b.genImg(v2, d);
	b3.writeToFile("unshuffled_1.png");

	checkSoln("testSort", b3, "in_01.png");

}
Exemplo n.º 3
0
BlockPNG listToImage(List<RGBAPixel> const & list, int width, int height)
{
	BlockPNG ret;
	ret.resize(width, height);
	vector<RGBAPixel> v(list.begin(), list.end());
	int x = 0;
	int y = 0;
	for (unsigned int i = 0; i < v.size(); i++)
	{
		*ret(x,y) = v[i];
		y++;
		if (y == height)
		{
			y = 0;
			x++;
		}
	}
	return ret;
}
Exemplo n.º 4
0
void testSort()
{
	cout << "[main]: " << __func__ << "()" << endl;

	srand(225);

	// read in image to be shuffled
	BlockPNG b;
	b.readFromFile("in_01.png");

	int d = 60;
	vector<int> v = buildVector(b, d);
	random_shuffle(v.begin(), v.end());

	// generate shuffled image (done for you already)
	
	//   PNG b2 = b.genImg(v, d);
	//   b2.writeToFile("in_01_shuffled_60.png");
	

	// make list and sort it
	List<int> img_srt(v.begin(), v.end());
	img_srt.sort();

	// vectorize and rebuild image
	vector<int> v2(img_srt.begin(), img_srt.end());

	PNG b3 = b.genImg(v2, d);
	b3.writeToFile("unshuffled_60.png");

	checkSoln("testSort", b3, "in_01.png");

	d = 1;
	v = buildVector(b, d);
	random_shuffle(v.begin(), v.end());

	
	//   PNG q = b.genImg(v, d);
	//   q.writeToFile("in_01_shuffled_1.png");
    

	List<int> q_srt(v.begin(), v.end());
	q_srt.sort();

	v2 = vector<int>(q_srt.begin(), q_srt.end());

	b3 = b.genImg(v2, d);
	b3.writeToFile("unshuffled_1.png");

	checkSoln("testSort", b3, "in_01.png");
	/*	
	List<int> list3;

	list3.insertBack(6);
	list3.insertBack(1);
	list3.insertBack(5);
	list3.insertBack(8);
	list3.insertBack(4);
	list3.insertBack(3);
	list3.insertBack(7);
	list3.insertBack(2);
	list3.insertBack(9);

	list3.sort();
	cout << "[sort custom]: " << list3 << endl;
	*/
}