int main(int argc, char* argv[]) { if (error(argc, argv)) return 1; char* index = argv[2]; int oneSide = atoi(argv[4]); // this finds the length the binary number should be (number of pixels) int squareSize = pow(oneSide, 2); //==other calc log(size)/log(2) + 1; double size = pow(2, oneSide*oneSide) -1; // 511 is the max combinations for a 3x3 square of pixels // if (argv[1]==std::string("-percentage")) { // index = size*(index/100.0); // std::cout << index << std::endl; // } Image image; image.Allocate(oneSide); vector<vector<int> > coordinates(getCoordinates(squareSize)); //only needed for all images solution // string binString[size]; // for (int i = 0; i<size; i++) { // binString[i] = convertBin(squareSize, i); // } //cant use with large values (bigger than 10) // std::string aBin = convertBin(squareSize, index); // right now this only does one of the combinations for a size drawImage(image, coordinates, index); std::vector<unsigned char> png = image.getOutput(); saveImage(index, png, oneSide); std::cout << "finished." << std::endl; return 0; }
bool Renderer::TakeScreenshot(const char* directory_name) { // Fill our path string char filename[50]; time_t now = time(nullptr); strftime(filename, _countof(filename), "SS.%Y.%m.%d.%H.%M.%S.jpg", localtime(&now)); char delimeter[2] = { system::GetPathDelimeter(), '\0' }; size_t size = strlen(directory_name) + strlen(filename) + 2; // 1 is for delimeter, another 1 is for \0 char *full_filename = new char[size]; strcpy(full_filename, directory_name); strcat(full_filename, delimeter); strcat(full_filename, filename); system::CreateDirectory(directory_name); // create directory if it doesn't exist Image image; // allocate memory and read pixels u8 *data = image.Allocate(width_, height_, Image::Format::kRGB8); ReadPixels(width_, height_, data); if (!image.Save(full_filename)) { delete[] full_filename; return false; } delete[] full_filename; return true; }
int main(int argc, char* argv[]) { if (argc != 5) { std::cerr << "Usage: " << argv[0] << " input.ppm output.ppm distance_field_method visualization_style" << std::endl; exit(1); } // open the input image Image<Color> input; if (!input.Load(argv[1])) { std::cerr << "ERROR: Cannot open input file: " << argv[1] << std::endl; exit(1); } // a place to write the distance values Image<DistancePixel> distance_image; distance_image.Allocate(input.Width(),input.Height()); // calculate the distance field (each function returns the maximum distance value) double max_distance = 0; if (std::string(argv[3]) == std::string("naive_method")) { max_distance = NaiveDistanceFieldMethod(input,distance_image); } else if (std::string(argv[3]) == std::string("improved_method")) { max_distance = ImprovedDistanceFieldMethod(input,distance_image); } else if (std::string(argv[3]) == std::string("pq_with_map")) { max_distance = FastMarchingMethod(input,distance_image); } else if (std::string(argv[3]) == std::string("pq_with_hash_table")) { // EXTRA CREDIT: implement FastMarchingMethod with a hash table } else { std::cerr << "ERROR: Unknown distance field method: " << argv[3] << std::endl; exit(1); } // convert distance values to a visualization Image<Color> output; output.Allocate(input.Width(),input.Height()); for (int i = 0; i < input.Width(); i++) { for (int j = 0; j < input.Height(); j++) { double v = distance_image.GetPixel(i,j).getValue(); if (std::string(argv[4]) == std::string("greyscale")) { output.SetPixel(i,j,GreyBands(v,max_distance*1.01,1)); } else if (std::string(argv[4]) == std::string("grey_bands")) { output.SetPixel(i,j,GreyBands(v,max_distance,4)); } else if (std::string(argv[4]) == std::string("rainbow")) { output.SetPixel(i,j,Rainbow(v,max_distance)); } else { // EXTRA CREDIT: create other visualizations std::cerr << "ERROR: Unknown visualization style" << std::endl; exit(0); } } } // save output if (!output.Save(argv[2])) { std::cerr << "ERROR: Cannot save to output file: " << argv[2] << std::endl; exit(1); } return 0; }