Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Andy Huynh
- * @date 10/20/18
- * @file h12.cpp
- */
- #include <string>
- #include <iostream>
- using namespace std;
- string STUDENT = "ahuynh86"; // Add your Canvas/occ-email ID
- #include "h12.h"
- // Add your code here
- void negative(unsigned char * const img, int width, int height)
- {
- unsigned char * p = img;
- unsigned char * end = img + width * height * 4;
- while(p!=end)
- {
- *p = 255 - *p;
- p++;
- *p = 255 - *p;
- p++;
- *p = 255 - *p;
- p+=2;
- }
- }
- void greenScreen(unsigned char * const img, int width, int height)
- {
- unsigned char * p = img;
- const auto * end = img + width * height * 4;
- while(p!=end)
- {
- if(*(p+1) >= 2*(*p) && *(p+1) >= 2 * (*(p+2)))
- {
- *p = 0;
- p++;
- *p = 0;
- p++;
- *p = 0;
- p++;
- *p = 0;
- p++;
- }
- else
- p+=4;
- }
- }
- void composite(unsigned char * const bg, unsigned char * const fg, int width, int height)
- {
- greenScreen(fg, width, height);
- unsigned char *dest = fg;
- unsigned char *src = bg;
- unsigned char * end = fg + width * height * 4;
- while(dest!=end)
- {
- if((*(dest+3))==0)
- {
- *(dest)=*(src);
- *(dest+1)=*(src+1);
- *(dest+2)=*(src+2);
- *(dest+3)=*(src+3);
- }
- src += 4;
- dest += 4;
- }
- }
- /////////////// STUDENT TESTING ////////////////////
- int run()
- {
- // Just some samples for class
- cout << "Load images/paris.jpg" << endl;
- // 1. Load a jpg file using 4 bytes per pixel (bpp RGBA)
- int width, height, bpp, channels = 4;
- unsigned char * paris =
- stbi_load("images/paris.jpg", // input file
- &width, &height, &bpp, // pointers (out)
- channels); // channels (in)
- // Now write it out in current folder as a 4-bytes-per-pixel PNG
- if (stbi_write_png("paris.png", width, height, channels, paris,
- width * channels))
- cout << "Find paris.png in current folder." << endl;
- else
- cout << "Couldn't write paris.png" << endl;
- // IMPORTANT - free the memory
- stbi_image_free(paris);
- // 2. Load a png file using 1 byte per pixel (Gray scale)
- cout << "Loading images/stegosuarus.png as gray scale." << endl;
- channels = 1;
- unsigned char * stego = stbi_load("images/stegosaurus.png",
- &width, &height, &bpp, channels);
- cout << "Writing as stego-bw.bmp in current folder: ";
- if (stbi_write_bmp("stego-bw.bmp", width, height, channels, stego))
- cout << "Success!" << endl;
- else cout << "Failed!" << endl;
- stbi_image_free(stego);
- // 3. Load a png file using 3 bytes (RGB only)
- cout << "Load images/Vermeer-Milkmaid.png, 3 bpp." << endl;
- channels = 3;
- int quality = 50; // medium quality jpg
- auto vermeer = stbi_load("images/Vermeer-Milkmaid.png", &width, &height, &bpp, channels);
- stbi_write_jpg("vermeer.jpg", width, height, channels, stego, quality);
- stbi_image_free(vermeer);
- cout << "Saved as vermeer.jpg in current folder." << endl;
- return 0;
- }
- //https://drive.google.com/file/d/1JWb1gESD5WubuJh8ytpg1A7LxNSovL-X/view
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement