Exemplo n.º 1
0
int main()
{
	PNG oldImage;
	oldImage.readFromFile("in.png");	
	size_t vertical = oldImage.height();
	size_t horizontal = oldImage.width();
/*
* have initialized newImage just so that the pixels are accessable 
*/
	PNG newImage;
	newImage.readFromFile("in.png");
/*
 * we will flip the image horizontally and vertically to rotate it by 180 degrees
*/
	for (size_t x = 0; x < oldImage.width(); x++)
	{	
		for (size_t y = 0; y < oldImage.height(); y++)
		{
			newImage(horizontal-x-1, vertical-y-1)->red = oldImage(x,y)->red;
			newImage(horizontal-x-1, vertical-y-1)->green = oldImage(x,y)->green;
			newImage(horizontal-x-1, vertical-y-1)->blue = oldImage(x,y)->blue;
		}
	}
	newImage.writeToFile("out.png");
}	
Exemplo n.º 2
0
void pacmanTests() {
	cout << "Testing PacMan" << endl;

	// PAC MAN BFS
	PNG img;
	img.readFromFile("originals/pacMan.png");
	rainbowColorPicker BFSfiller(1.0/1000.0);
	animation pacManBFS = filler::bfs::fill(img, img.width()/2, img.height()/2,
	                               BFSfiller, 8000, INT_MAX);
	img.writeToFile("images/pacManBFS.png");
	cout << "\tWrote images/pacManBFS.png" << endl;
	//blueManBFS.write("pacManBFS.gif");

	// PAC MAN DFS
	img.readFromFile("originals/pacMan.png");
	rainbowColorPicker DFSfiller(1.0/1000.0);
	animation pacManDFS = filler::dfs::fill(img, img.width()/2, img.height()/2,
	                               DFSfiller, 8000, INT_MAX);
	img.writeToFile("images/pacManDFS.png");
	cout << "\tWrote images/pacManDFS.png" << endl;


	// Make ANTI image
	PNG antiImg;
	antiImg.readFromFile("originals/pacMan.png");
	RGBAPixel black;
	black.red = black.green = black.blue = 0;
	RGBAPixel grey;
	grey.red = grey.green = grey.blue = 1;
    filler::bfs::fillSolid(antiImg, 10, 10, grey, 8000, INT_MAX);
    filler::bfs::fillSolid(antiImg, antiImg.width()/2, antiImg.height()/2, black, 8000, INT_MAX);

	// ANTI PAC MAN BFS
	img = antiImg;
	rainbowColorPicker aBFSfiller(1.0/1000.0);
	animation aManBFS = filler::bfs::fill(img, 20, 20, aBFSfiller, 0, 2000);
	//img.writeToFile("antiPacManBFS.png");
	aManBFS.write("images/antiPacManBFS.gif");
	cout << "\tWrote images/antiPacManBFS.gif" << endl;

	// ANTI PAC MAN DFS
	img = antiImg;
	rainbowColorPicker aDFSfiller(1.0/1000.0);
	animation aManDFS = filler::dfs::fill(img, 20, 20, aDFSfiller, 0, 2000);
	//img.writeToFile("antiPacManDFS.png");
	aManDFS.write("images/antiPacManDFS.gif");
	cout << "\tWrote images/antiPacManDFS.gif" << endl;
}
Exemplo n.º 3
0
/**
 * Tests the image shifting code
 */
void testShift()
{
    // remove old frames
    system("rm -rf frames 2> /dev/null");

    PNG image;
    cout << "Testing image shifter:" << endl;
    image.readFromFile("images/08_1024x768.png");

    cout << "  - shifting image" << endl;
    double startTime = omp_get_wtime();
    animation anim = Shifter::shiftParallel(image);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    anim.write("shifted.gif");
    cout << "Elapsed shifting time: " << parallelTime << endl;

    cout << "Checking correctness: ";
    bool correct = Shifter::checkCorrectness();
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;

    // remove old frames
    system("rm -rf frames 2> /dev/null");

    // calculate speedup
    startTime = omp_get_wtime();
    anim = Shifter::shiftSerial(image);
    endTime = omp_get_wtime();

    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
}
Exemplo n.º 4
0
/**
 * Tests the image flipping code.
 */
void testFlip()
{
    PNG image;
    cout << "Testing in-place image flipper:" << endl;
    image.readFromFile("images/03_2560x1680.png");

    cout << "  - flipping image" << endl;
    double startTime = omp_get_wtime();
    Flipper::flipParallel(image);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    image.writeToFile("flipped.png");
    cout << "Elapsed flip time: " << parallelTime << endl;

    cout << "Checking correctness: ";
    bool correct = Flipper::checkCorrectness(image);
    cout << (correct ? makeGreen("PASS") : makeRed("FAIL") + " (the images are different)") << endl;

    startTime = omp_get_wtime();
    Flipper::flipSerial(image);
    endTime = omp_get_wtime();
    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
}
Exemplo n.º 5
0
int main()
{

	// Load in.png
	PNG * original;

	original=new PNG;
	original->readFromFile("in.png");
	int width  = original->width();
	int height = original->height();
	// Create out.png
	PNG * output;
	output = new PNG;
	output = setupOutput(width, height);	
	// Loud our favorite color to color the outline
	RGBAPixel * myPixel;
	myPixel=new RGBAPixel;
	myPixel= myFavoriteColor(192);

	

	// Go over the whole image, and if a pixel differs from that to its upper
	// left, color it my favorite color in the output
	for (int y = 1; y < height; y++)
	{
		for (int x = 1; x < width; x++)
		{
			// Calculate the pixel difference
			RGBAPixel * prev = (*original)(x-1, y-1);
			RGBAPixel * curr = (*original)(x  , y  );
			int diff = abs(curr->red   - prev->red  ) +
					   abs(curr->green - prev->green) +
					   abs(curr->blue  - prev->blue );

			// If the pixel is an edge pixel,
			// color the output pixel with my favorite color
			RGBAPixel * currOutPixel = (*output)(x,y);
			if (diff > 100)
				{currOutPixel->red=myPixel->red;
currOutPixel->green=myPixel->green;
currOutPixel->blue=myPixel->blue;}

		
	}
}

	// Save the output file
	output->writeToFile("out.png");


	// Clean up memory
	myPixel=NULL;
	delete myPixel;
	delete output;
	output=NULL;
	delete original;
	original=NULL;
	return 0;
}
Exemplo n.º 6
0
void checkSoln(string test, PNG out, string soln_file)
{
	PNG soln;
	soln.readFromFile(soln_file.c_str());

	if (!(soln == out))
		cerr << "[" << test << "]: Image does not match " << soln_file << endl;
}
Exemplo n.º 7
0
void sketchify()
{
	// Load in.png
	PNG * original;

	//std::cout << "Reached line 28" << endl;	
	original = new PNG();
	original->readFromFile("in.png");
	int width  = original->width();
	int height = original->height();
	//std::cout << "Reached line 32" << endl;

	// Create out.png
	PNG * output = setupOutput(width, height);	

	// Loud our favorite color to color the outline
	RGBAPixel * myPixel = myFavoriteColor(192);

	// Go over the whole image, and if a pixel differs from that to its upper
	// left, color it my favorite color in the output
	for (int y = 1; y < height; y++)
	{
		//std::cout << "begin" << endl;
		for (int x = 1; x < width; x++)
		{
			// Calculate the pixel difference
			RGBAPixel * prev = (*original)(x-1, y-1);
			RGBAPixel * curr = (*original)(x  , y  );
			int diff = abs(curr->red   - prev->red  ) +
					   abs(curr->green - prev->green) +
					   abs(curr->blue  - prev->blue );

			// If the pixel is an edge pixel,
			// color the output pixel with my favorite color
			RGBAPixel * currOutPixel =(*output)(x,y);

			if (diff > 100)
				*currOutPixel = *myPixel;
				//*(*output)(x,y) = *myPixel;
			
		}
		//std::cout << "end" << endl;
	}
	
	// Save the output file
	//std::cout << "begin" << endl;
	output->writeToFile("out.png");
	//std::cout << "end" << endl;

	// Clean up memory
	delete myPixel;
	//std::cout << "check1" << endl;
	delete output;
	delete original;
	//std::cout << "check2" << endl;
}
Exemplo n.º 8
0
void testWaterfall()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in;
	in.readFromFile("in_05.png");

	List<RGBAPixel> list = imageToList(in);
	list.waterfall();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_01.png");

	checkSoln(__func__, out, "soln_waterfall_01.png");

	in.readFromFile("in_06.png");
	list = imageToList(in);
	list.waterfall();
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("waterfall_02.png");

	checkSoln(__func__, out, "soln_waterfall_02.png");
}
Exemplo n.º 9
0
void testGridFill( const Filler & filler, const string & outputFile ) {
	PNG img;
	img.readFromFile( GRIDTESTIMAGE );
	RGBAPixel px( 70, 25, 70 );

    animation anim;
    if( filler == DFS )
        anim = filler::dfs::fillGrid( img, GRIDX, GRIDY, px, GRIDGRIDSPACING, GRIDTOLERANCE, GRIDFRAMEFREQ );
    else
        anim = filler::bfs::fillGrid( img, GRIDX, GRIDY, px, GRIDGRIDSPACING, GRIDTOLERANCE, GRIDFRAMEFREQ );
	anim.write( outputFile );
	cout << "\tWrote " << outputFile << endl;
}
Exemplo n.º 10
0
void testSolidFill( const Filler & filler, const string & outputFile ) {
	PNG img;
	img.readFromFile( SOLIDTESTIMAGE );
	RGBAPixel px( 70, 50, 13 );

    animation anim;
    if( filler == DFS )
        anim = filler::dfs::fillSolid( img, SOLIDX, SOLIDY, px, SOLIDTOLERANCE, SOLIDFRAMEFREQ );
    else
        anim = filler::bfs::fillSolid( img, SOLIDX, SOLIDY, px, SOLIDTOLERANCE, SOLIDFRAMEFREQ );
	anim.write( outputFile );
	cout << "\tWrote " << outputFile << endl;
}
Exemplo n.º 11
0
void testReverse()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in;
	in.readFromFile("in_02.png");

	List<RGBAPixel> list = imageToList(in);
	list.reverse();

	PNG out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverse.png");

	checkSoln(__func__, out, "soln_reverse.png");
}
Exemplo n.º 12
0
/**
 * Initializes the vector of PNGs for the collage constructor.
 * @return - a vector of PNGs representing layers in the collage
 */
vector<PNG> setupImages()
{
    vector<PNG> layers;
    string filenames[NUM_COLLAGE_FILES] = { "01_8182x4096.png", "02_5000x3750.png",
        "03_2560x1680.png", "04_1920x1200.png", "05_1680x1050.png",
        "06_1440x900.png", "07_1280x1024.png", "08_1024x768.png",
        "09_600x400.png", "10_300x200.png", "11_150x100.png", "12_50x50.png" };
    for(int i = 0; i < NUM_COLLAGE_FILES; ++i)
    {
        cout << "  - loading image " << i << endl;
        PNG png;
        png.readFromFile("images/" + filenames[i]);
        layers.push_back(png);
    }
    return layers;
}
Exemplo n.º 13
0
void testGradientFill( const Filler & filler, const string & outputFile ) {
	PNG img;
	img.readFromFile( GRADIENTTESTIMAGE );
	RGBAPixel px;
	px.red = px.blue = 0;
	px.green = 25;
	RGBAPixel px2;
	px2.red = px2.blue = 200;
	px2.green = 25;

    animation anim;
    if( filler == DFS )
        anim = filler::dfs::fillGradient( img, GRADIENTX, GRADIENTY, px, px2, GRADIENTRADIUS, GRADIENTTOLERANCE, GRADIENTFRAMEFREQ );
    else
        anim = filler::bfs::fillGradient( img, GRADIENTX, GRADIENTY, px, px2, GRADIENTRADIUS, GRADIENTTOLERANCE, GRADIENTFRAMEFREQ );
	anim.write( outputFile );
	cout << "\tWrote " << outputFile << endl;
}
Exemplo n.º 14
0
/**
 * Makes sure that the collage.png matches soln_collage.png
 * @param image - the image to test
 * @return - whether it matches soln_collage.png
 */
bool Collage::checkCorrectness(const PNG & image)
{
    PNG solution;
    solution.readFromFile("soln_collage.png");
    return solution == image;
}
Exemplo n.º 15
0
/**
 * Makes sure that the flipped.png matches soln_flipped.png
 * @param image - the image to test
 * @return - whether it matches soln_flipped.png
 */
bool Flipper::checkCorrectness(const PNG & image)
{
    PNG solution;
    solution.readFromFile("soln_flipped.png");
    return solution == image;
}