本文整理汇总了C++中PNG::height方法的典型用法代码示例。如果您正苦于以下问题:C++ PNG::height方法的具体用法?C++ PNG::height怎么用?C++ PNG::height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PNG
的用法示例。
在下文中一共展示了PNG::height方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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");
}
示例2: pacmanTests
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;
}
示例3: 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;
}
示例4: removeColor
/**
* 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: main
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;
}
示例8: sketchify
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;
}
示例9: drawCrosshairs
/**
* This function accepts a PNG object, two integer coordinates and a color, and
* proceeds to draw a horizontal line across the image at the y coordinate and
* a vertical line down the image at the x coordinage using the given color.
* The modified PNG is then returned.
*
* @param original A PNG object which holds the image data to be modified.
* @param centerX The center x coordinate of the crosshair which is to be drawn.
* @param centerY The center y coordinate of the crosshair which is to be drawn.
* @param color The color of the lines to be drawn.
*
* @return The image on which a crosshair has been drawn.
*/
PNG drawCrosshairs(PNG original, int centerX, int centerY, RGBAPixel color)
{
/// This function is already written for you so you can see how to
/// interact with our PNG class.
for (size_t x = 0; x < original.width(); x++)
*original(x, centerY) = color;
for (size_t y = 0; y < original.height(); y++)
*original(centerX, y) = color;
return original;
}
示例10: imageToList
List<RGBAPixel> imageToList(PNG const & img)
{
List<RGBAPixel> list;
for (int i = 0; i < img.width(); i++)
{
for (int j = 0; j < img.height(); j++)
{
list.insertFront(*img(i,j));
}
}
return list;
}
示例11: blendImages
/**
* This function blends, or averages, two PNGs together. That is, each pixel in
* the returned image consists of the averaged components (red, green, blue) of
* the two input images.
*
* @param firstImage The first of the two PNGs to be averaged together.
* @param secondImage The second of the two PNGs to be averaged together.
*
* @return The averaged image.
*/
PNG blendImages(PNG firstImage, PNG secondImage)
{
for (size_t yi = 0; yi < firstImage.height(); yi++)
{
for (size_t xi = 0; xi < firstImage.width(); xi++)
{
firstImage(xi, yi)->green =(firstImage(xi, yi)->green+secondImage(xi, yi)->green)/2;
firstImage(xi, yi)->red =(firstImage(xi, yi)->red+secondImage(xi, yi)->red)/2;
firstImage(xi, yi)->blue =(firstImage(xi, yi)->blue+secondImage(xi, yi)->blue)/2;
}
}
return firstImage;
}
示例12: testWaterfall
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");
}
示例13: 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!
//original(xi,yi)->red = 0;
//original(xi,yi)->blue = 0;
}
}
return original;
}
示例14: testReverse
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");
}
示例15: rotate
PNG rotate(PNG original, PNG result)
{ //this function rotate the original file 180 degree and return the result
size_t height = original.height();
size_t width = original.width();
for (size_t yi = 0; yi < height; yi++)
{
for (size_t xi = 0; xi < width; xi++)
{ result(width-xi-1,height-yi-1)->red = original(xi,yi)->red;
result(width-xi-1,height-yi-1)->green = original(xi,yi)->green;
result(width-xi-1,height-yi-1)->blue = original(xi,yi)->blue;
result(width-xi-1,height-yi-1)->alpha = original(xi,yi)->alpha;
}
}
return result;
}