当前位置: 首页>>代码示例>>C++>>正文


C++ PNG类代码示例

本文整理汇总了C++中PNG的典型用法代码示例。如果您正苦于以下问题:C++ PNG类的具体用法?C++ PNG怎么用?C++ PNG使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PNG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testCollage

/**
 * Tests the collage code with the appropriate algorithm.
 */
void testCollage(DrawAlgorithm algorithm)
{
    cout << "Testing collage:" << endl;
    vector<PNG> layers = setupImages();
    vector<Point> coords = setupPoints();
    Collage collage(layers, coords);

    double startTime = omp_get_wtime();
    PNG* result = collage.draw(algorithm, true);
    double endTime = omp_get_wtime();
    double parallelTime = endTime - startTime;

    cout << "  - saving image" << endl;
    result->writeToFile("collage.png");    
    cout << "Elapsed collage time: " << parallelTime << endl;

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

    startTime = omp_get_wtime();
    result = collage.draw(algorithm, false);
    endTime = omp_get_wtime();
    cout << "Speedup: " << (endTime - startTime) / parallelTime << endl;
    delete result;
}
开发者ID:chrislee0793,项目名称:CS225,代码行数:30,代码来源:main.cpp

示例2: testWaterfall

void testWaterfall()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("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");
	
	List<int> list3;

	for (int i = 1; i <= 8; i++)
	list3.insertBack(i);
	list3.waterfall();
	//cout << "[waterfall custom]: " << list3 << endl;
}
开发者ID:guptadipanshu,项目名称:Data_structure,代码行数:28,代码来源:main.cpp

示例3: rx_save_png

bool rx_save_png(Image& img, std::string filename, bool datapath) {
  
  PNG png;

  png_uint_32 type;

  if(img.getPixelFormat() == RX_FMT_GRAY8) {
    type = PNG_COLOR_TYPE_GRAY;
  }
  else if(img.getPixelFormat() == RX_FMT_RGB24) {
    type = PNG_COLOR_TYPE_RGB;
  }
  else if(img.getPixelFormat() == RX_FMT_RGBA32) {
    type = PNG_COLOR_TYPE_RGB_ALPHA;
  }
  else {
    RX_ERROR(ERR_IMG_UNSUPPORTED_FORMAT);
    return false;
  }

  png.setPixels(img.getPixels(), img.getWidth(), img.getHeight(), type);
  png.save(filename, datapath);

  return true;
}
开发者ID:basseyndon,项目名称:roxlu_experimental,代码行数:25,代码来源:Image.cpp

示例4: testFlip

/**
 * 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;
}
开发者ID:chrislee0793,项目名称:CS225,代码行数:28,代码来源:main.cpp

示例5: main

int main()
{ 
   SquareMaze m;
   m.makeMaze(TEST,TEST);
   std::cout << "MakeMaze complete" << std::endl;

    /*
    for ( int i = 0; i < TEST; i++)
    {
        for ( int j = 0; j < TEST ; j++)
        {
            cout <<"RIGHT: "<< m.canTravel(i,j,RIGHT)<< " x: "<<i<<" y: "<<j<<endl;
            cout <<"BOTTOM: "<< m.canTravel(i,j,BOTTOM)<< " x: "<<i<<" y: "<<j<<endl;
        }
    }
    */

   PNG* unsolved = m.drawMaze();
   unsolved->writeToFile("unsolved.png");
   delete unsolved;
   std::cout << "drawMaze complete" << std::endl;
   
   vector<int> sol = m.solveMaze();
   std::cout << "solveMaze complete" << std::endl;
   
   PNG* solved = m.drawMazeWithSolution();
   solved->writeToFile("solved.png");
   delete solved;
   std::cout << "drawMazeWithSolution complete" << std::endl;

   return 0;
}
开发者ID:AdonisSaveYourLife,项目名称:cs225,代码行数:32,代码来源:testsquaremaze.cpp

示例6: testShift

/**
 * 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;
}
开发者ID:chrislee0793,项目名称:CS225,代码行数:36,代码来源:main.cpp

示例7: loadHeightMap

void Terrain::loadHeightMap(string filename, int res_x, int res_y)
{
	PNG inputFile;
	inputFile.load(filename);
	dim_x = inputFile.width;
	dim_y = inputFile.height;
	unsigned char * data = inputFile.getData();

	int size = dim_x*dim_y;
	float * originalHeightMap = new float[size];
	int i,x,y;

	for (i=0; i<size; i++){
		originalHeightMap[i] = 256*data[2*i]+data[2*i + 1];
	}
	// recalculate to the given resolution (use linear interpolation...)
	size = res_x*res_y;
	heightMap = new float[size];
	float step_x = float(dim_x)/float(res_x);
	float step_y = float(dim_y)/float(res_y);
	
	for(x=0; x<res_x; x++)
	{
		for(y=0; y<res_y; y++)
		{
			heightMap[x*res_y + y] = getHeightAt(originalHeightMap, dim_x, dim_y, float(x*step_x), float(y*step_y));
		}
	}
	SAFE_DELETE_ARRAY_PTR(originalHeightMap);

}
开发者ID:kidd32pg,项目名称:natureal,代码行数:31,代码来源:Terrain.cpp

示例8: testReverseNth

void testReverseNth()
{
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("in_03.png");
	
    /*
    List<int> test;

    for (int i = 1; i <= 11; i++)
    {
        test.insertBack(i);
    }

    cout<<test<<endl;
    test.reverseNth(3);
    cout<<test<<endl;
    */
	List<RGBAPixel> list = imageToList(in);
	list.reverseNth(in.height() * 20);

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

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

	in.readFromFile("in_04.png");
	list = imageToList(in);
	list.reverseNth(in.height() * 61);
	out = listToImage(list, in.width(), in.height());
	out.writeToFile("reverseNth_02.png");

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

}
开发者ID:AdonisSaveYourLife,项目名称:cs225,代码行数:34,代码来源:main.cpp

示例9: testWaterfall

void testWaterfall()
{
	List<double> li;
	cout<<li<<endl;
	li.waterfall();
	cout<<li<<endl;
	cout << "[main]: " << __func__ << "()" << endl;
	PNG in("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");
}
开发者ID:Albertmt,项目名称:Data-Structures,代码行数:25,代码来源:main.cpp

示例10: main

int main(int argc, char* argv[])
{
	const int canvas_width = 128;
	const int canvas_height = 128;

	PNG canvas;
	canvas.resize(canvas_width, canvas_height);


	const RGBAPixel triangle_color = color::ORANGE;
	Shape* triangle = new Triangle(triangle_color,
			Vector2(32, 32),
			Vector2(64, 64),
			Vector2(32, 64));

	triangle->draw(&canvas);

	canvas.writeToFile("test_destructor.png");

	/* TODO: Why is this leaking memory?  Triangle does have a valid destructor!?
	 * Can you stop it from leaking WITHOUT changing triangle's type from a
	 * Shape pointer to a Triangle pointer type? */
	delete triangle;
	triangle = NULL;

	return 0;
}
开发者ID:irtefa,项目名称:dumbshit,代码行数:27,代码来源:test_destructor.cpp

示例11: brighten

/**
 * This function brightens a rectangle of a PNG, increasing the components
 * (red, green, blue) of each pixel by the given amount. You must account
 * for potential overflow issues (color components can only store numbers
 * between 0 and 255). If you attempt to store a value greater than 255
 * into a color component, the result will wrap around (and you won't be
 * able to check if it was greater than 255).
 *
 * @param original A PNG object which holds the image data to be modified.
 * @param amount The integer amount by which to increase each pixel's
 * components.
 *
 * @return The brightened image.
 */
PNG brighten(PNG original, int amount)
{
    /// You can assume amount is positive.
    for (size_t yi = 0; yi < original.height(); yi++)
    {
        for (size_t xi = 0; xi < original.width(); xi++)
        {
            /// Your code here!
		int blue = original(xi, yi)->blue;
		int green = original(xi, yi)->green;
		int red = original(xi, yi)->red;
		if(red+amount<255)
		original(xi,yi)->red= red+amount;
		else
		original(xi,yi)->red= 255;		
        
		if(blue+amount<255)
		original(xi,yi)->blue= blue+amount;
		else
		original(xi,yi)->blue= 255;

		if(green+amount<255)
		original(xi,yi)->green= green+amount;
		else
		original(xi,yi)->green= 255;
	}
    }
    return original;
}
开发者ID:guptadipanshu,项目名称:Data_structure,代码行数:43,代码来源:main.cpp

示例12: output

/**
 * Removes an RGB color component from the PNG.
 * THIS FUNCTION IS GRADED.
 * @todo - parallelize removeColor()
 * @param source - the original PNG
 * @param color - the color to remove
 * @return - a PNG object with an RGB component taken out
 *  of each pixel (if color parameter is valid)
 */
PNG ImageTools::removeColor(const PNG & source, const Color & color)
{
    int width = source.width();
    int height = source.height();
    PNG output(width, height);
	#pragma omp parallel for
    for(int i = 0; i < width; ++i)
    {	
	
        for(int j = 0; j < height; ++j)
        {
            *output(i, j) = *source(i, j);
            switch(color)
            {
                case RED:
                    output(i,j)->red=0;
                    break;
                case GREEN:
                    output(i,j)->green=0;
                    	break;
                case BLUE:
                    output(i,j)->blue=0;
                    	break;
            }
        }
    }

    return output;
}
开发者ID:cwang100,项目名称:class-projects,代码行数:38,代码来源:image_tools.cpp

示例13: shiftParallel

/**
 * Makes an animation of an image shifting to the left
 * @param toShift - the image to be shifted
 * @return - an animation of the image being shifted
 */
animation Shifter::shiftParallel(const PNG & toShift)
{
    
 PNG image = toShift;
    animation anim;
    int width = image.width();
    int height = image.height();
    int shiftAmount = 32;

	  // shift image to the left by 32 pixels each iteration
  
	
  for(int destCol = 0; destCol < width; destCol += 32)
    {
        for(int x = 0; x < width - 32; ++x)
        {
	#pragma omp parallel for 
            for(int y = 0; y < height; ++y)
            {
                *image(x, y) = *image(x + 32, y);
            }
        }
        if(destCol % shiftAmount == 0)
        {
            anim.addFrame(image);
        }
    }
    

    return anim;
}
开发者ID:karanghai,项目名称:cs225Labs,代码行数:36,代码来源:shifter.cpp

示例14: makePhotoMosaic

void makePhotoMosaic(const string & inFile, const string & tileDir, int numTiles, int pixelsPerTile, const string & outFile)
{
	PNG inImage(inFile);
	SourceImage source(inImage, numTiles);
	vector<TileImage> tiles = getTiles(tileDir);

	if (tiles.empty())
	{
		cerr << "ERROR: No tile images found in " << tileDir << endl;
		exit(2);
	}

	MosaicCanvas::enableOutput = true;
	MosaicCanvas * mosaic = mapTiles(source, tiles);
	cerr << endl;

	if (mosaic == NULL)
	{
		cerr << "ERROR: Mosaic generation failed" << endl;
		exit(3);
	}

	PNG result = mosaic->drawMosaic(pixelsPerTile);
	cerr << "Saving Output Image... ";
	result.writeToFile(outFile);
	cerr << "Done" << endl;
	delete mosaic;
}
开发者ID:irtefa,项目名称:dumbshit,代码行数:28,代码来源:photomosaic.cpp

示例15: brighten

/**
 * This function brightens a rectangle of a PNG, increasing the components
 * (red, green, blue) of each pixel by the given amount. You must account
 * for potential overflow issues (color components can only store numbers
 * between 0 and 255). If you attempt to store a value greater than 255
 * into a color component, the result will wrap around (and you won't be
 * able to check if it was greater than 255).
 *
 * @param original A PNG object which holds the image data to be modified.
 * @param amount The integer amount by which to increase each pixel's
 * components.
 *
 * @return The brightened image.
 */
PNG brighten(PNG original, int amount)
{
    /// You can assume amount is positive.
    for (size_t yi = 0; yi < original.height(); yi++)
    {
        for (size_t xi = 0; xi < original.width(); xi++)
        {
		size_t r = original(xi, yi) -> red;
		size_t g = original(xi, yi) -> green;
		size_t b = original(xi, yi) -> blue;		
		r = r + amount;
		g = g + amount;
		b = b + amount;
		if(r > 255){
			r = 255;
		}
		

		if(g > 255){
			g = 255;
		}
	
		if(b > 255){
			b = 255;
		}           

		original(xi, yi) ->red = r;
		original(xi, yi) ->green = g;
		original(xi, yi) ->blue = b;

		/// Your code here!
        }
    }
    return original;
}
开发者ID:Yankkk,项目名称:C-,代码行数:49,代码来源:main.cpp


注:本文中的PNG类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。