Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.33 KB | None | 0 0
  1. /**
  2.  *  @author Andy Huynh
  3.  *  @date 10/20/18
  4.  *  @file h12.cpp
  5.  */
  6. #include <string>
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. string STUDENT = "ahuynh86"; // Add your Canvas/occ-email ID
  11. #include "h12.h"
  12.  
  13. // Add your code here
  14. void negative(unsigned char * const img, int width, int height)
  15. {
  16.     unsigned char * p = img;
  17.     unsigned char * end = img + width * height * 4;
  18.     while(p!=end)
  19.     {
  20.         *p = 255 - *p;
  21.         p++;
  22.         *p = 255 - *p;
  23.         p++;
  24.         *p = 255 - *p;
  25.         p+=2;
  26.  
  27.     }
  28. }
  29.  
  30. void greenScreen(unsigned char * const img, int width, int height)
  31. {
  32.     unsigned char * p = img;
  33.     const auto * end = img + width * height * 4;
  34.     while(p!=end)
  35.     {
  36.         if(*(p+1) >= 2*(*p) && *(p+1) >= 2 * (*(p+2)))
  37.         {
  38.             *p = 0;
  39.             p++;
  40.             *p = 0;
  41.             p++;
  42.             *p = 0;
  43.             p++;
  44.             *p = 0;
  45.             p++;
  46.         }
  47.         else
  48.             p+=4;
  49.     }
  50. }
  51.  
  52. void composite(unsigned char * const bg, unsigned char * const fg, int width, int height)
  53. {
  54.     greenScreen(fg, width, height);
  55.     unsigned char *dest = fg;
  56.     unsigned char *src = bg;
  57.     unsigned char * end = fg + width * height * 4;
  58.     while(dest!=end)
  59.     {
  60.         if((*(dest+3))==0)
  61.         {
  62.             *(dest)=*(src);
  63.             *(dest+1)=*(src+1);
  64.             *(dest+2)=*(src+2);
  65.             *(dest+3)=*(src+3);
  66.         }
  67.         src += 4;
  68.         dest += 4;
  69.     }
  70. }
  71. /////////////// STUDENT TESTING ////////////////////
  72. int run()
  73. {
  74.     // Just some samples for class
  75.     cout << "Load images/paris.jpg" << endl;
  76.     // 1. Load a jpg file using 4 bytes per pixel (bpp RGBA)
  77.     int width, height, bpp, channels = 4;
  78.     unsigned char * paris =
  79.         stbi_load("images/paris.jpg",       // input file
  80.                     &width, &height, &bpp,  // pointers (out)
  81.                     channels);              // channels (in)
  82.  
  83.     // Now write it out in current folder as a 4-bytes-per-pixel PNG
  84.     if (stbi_write_png("paris.png", width, height, channels, paris,
  85.                     width * channels))
  86.         cout << "Find paris.png in current folder." << endl;
  87.     else
  88.         cout << "Couldn't write paris.png" << endl;
  89.  
  90.     // IMPORTANT - free the memory
  91.     stbi_image_free(paris);
  92.  
  93.     // 2. Load a png file using 1 byte per pixel (Gray scale)
  94.     cout << "Loading images/stegosuarus.png as gray scale." << endl;
  95.     channels = 1;
  96.     unsigned char * stego = stbi_load("images/stegosaurus.png",
  97.                                 &width, &height, &bpp, channels);
  98.     cout << "Writing as stego-bw.bmp in current folder: ";
  99.     if (stbi_write_bmp("stego-bw.bmp", width, height, channels, stego))
  100.         cout << "Success!" << endl;
  101.     else cout << "Failed!" << endl;
  102.  
  103.     stbi_image_free(stego);
  104.  
  105.     // 3. Load a png file using 3 bytes (RGB only)
  106.     cout << "Load images/Vermeer-Milkmaid.png, 3 bpp." << endl;
  107.     channels = 3;
  108.     int quality = 50; // medium quality jpg
  109.     auto vermeer = stbi_load("images/Vermeer-Milkmaid.png", &width, &height, &bpp, channels);
  110.     stbi_write_jpg("vermeer.jpg", width, height, channels, stego, quality);
  111.     stbi_image_free(vermeer);
  112.     cout << "Saved as vermeer.jpg in current folder." << endl;
  113.  
  114.     return 0;
  115. }
  116.  
  117. //https://drive.google.com/file/d/1JWb1gESD5WubuJh8ytpg1A7LxNSovL-X/view
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement