Advertisement
Guest User

debug

a guest
Jan 30th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <cstdlib>
  2. #include "png.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. //
  7. // sets up the output image
  8. PNG * setupOutput(int w, int h)
  9. {
  10.     PNG * image = new PNG(w, h);
  11.     return image;
  12. }
  13.  
  14.  
  15. // Returns my favorite color
  16. RGBAPixel * myFavoriteColor(int intensity)
  17. {
  18.     RGBAPixel * color = new RGBAPixel;
  19.     color->red   = 0;
  20.     color->green = intensity/2;
  21.     color->blue  = intensity;
  22.     return color;
  23. }
  24.  
  25.  
  26. void sketchify()
  27. {
  28.     // Load in.png
  29.     PNG * original = new PNG;
  30.     original->readFromFile("in.png");
  31.     int width  = original->width();
  32.     int height = original->height();
  33.     // Create out.png
  34.     PNG * output=new PNG;
  35.     output=setupOutput(width, height); 
  36.  
  37.     // Load our favorite color to color the outline
  38.     RGBAPixel * myPixel = myFavoriteColor(192);
  39.  
  40.     // Go over the whole image, and if a pixel differs from that to its upper
  41.     // left, color it my favorite color in the output
  42.    
  43.     for (int y = 1; y < height; y++)
  44.     {
  45.         for (int x = 1;  x < width; x++)
  46.         {
  47.             // Calculate the pixel difference
  48.             RGBAPixel * prev = (*original)(x-1, y-1);
  49.             RGBAPixel * curr = (*original)(x  , y  );
  50.             int diff = abs(curr->red   - prev->red  ) +
  51.                        abs(curr->green - prev->green) +
  52.                        abs(curr->blue  - prev->blue );
  53.            
  54.             // If the pixel is an edge pixel,
  55.             // color the output pixel with my favorite color
  56.             RGBAPixel * currOutPixel = (*output)(x,y);  
  57.            
  58.            
  59.             if (diff > 100)
  60.                 * currOutPixel = * myPixel;
  61.  
  62.         }
  63.     }
  64.    
  65.     // Save the output file
  66.     output->writeToFile("out.png");
  67.    
  68.  
  69.     // Clean up memory
  70.     delete myPixel;
  71.     delete output;
  72.     delete original;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement