1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
#include<iostream>
#include<vector>
#include<random>
#include<chrono>
#include<new>
#include "ppm_file.h"
#include "general_noise.h"
using namespace std;
//ppm_file file;
/*
//seed creation, based on date
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator(seed);*/
/* The random generator seems to works only with double or float
*
* To get unsigned int, we just take the round(abs()) value of this float number
* *
normal_distribution<float> distri(0.0, 0.15);
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @brief ppm_file::ppm_file
* This constructor creates a ppm file with its header and run a body function. This is the default image : 100*100, max value = 255
* Be careful ! If the file already exists, he's deleted.
* @date 04-16-2019
* @author Alexandre Bouton
*/
ppm_file::ppm_file()
{
//Creating the file
this->open("my_ppm_file.ppm", ofstream::trunc);
//Put the default width and height values to 100 pixels
width = height = 100;
max_level = 255;
/**************************
* PPM file structure:
*
* P3 <- for the type of Netpbm format (P1 = PBM, P2 = PGM, P3 = PPM). "P3" means this is a RGB color image in ASCII
* x y <- x is the width and y is the height
* max <- maximum color level
*
* The part under this header is the image
**************************/
*this << "P3\n";
*this << width;
*this << " ";
*this << height;
*this << "\n";
*this << max_level;
*this << "\n";
//Close the file
//ppm_image(name...
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @brief ppm_file::ppm_file
* This constructor creates a ppm file with its header and run a body function
* Be careful ! If the file already exists, he's deleted.
* @param name the name of the file
* @param width
* @param height
* @param max_level the white level
* @author Alexandre Bouton
* @date 04-16-19
*/
ppm_file::ppm_file(const string& name, const unsigned int width, const unsigned int height, const unsigned int max_level)
{
//Creating the file
cout << "Creation du fichier..." << endl;
cout << "Creationde l'en-tete..." << endl;
this->open(name, ofstream::trunc);
/**************************
* PPM file structure:
*
* P3 <- for the type of Netpbm format (P1 = PBM, P2 = PGM, P3 = PPM). "P3" means this is a RGB color image in ASCII
* x y <- x is the width and y is the height
* max <- maximum color level
*
* The part under this header is the image
**************************/
*this << "P3\n";
*this << width;
*this << " ";
*this << height;
*this << "\n";
*this << max_level;
*this << "\n";
cout << "En-tete cree !" << endl;
ppm_image(width, height, max_level);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @brief ppm_file::ppm_image
* This function creates the body of the ppm file
* @author Alexandre Bouton
* @date 04-16-19
*/
void ppm_file::ppm_image(unsigned int width, unsigned int height, unsigned int max_level)
{
//Creating empty arrays
for(unsigned int i=0; i<height; i++)
{
for(unsigned int j=0; j<width; j++)
{
R[i][j] = 0;
G[i][j] = 0;
B[i][j] = 0;
}
}
cout << "Initialisation des valeurs terminee" << endl;
//Creating a general_noise object
general_noise noise;
cout << "Generation terminee !" << endl;
//Writing the file
cout << "Ecriture du fichier en cours ..." << endl;
for(unsigned int i=0; i<height; i++)
{
for(unsigned int j=0; j<width; j++)
{
//R
*this << R[i][j] << endl;
//G
*this << G[i][j] << endl;
//B
*this << B[i][j] << endl;
}
}
close();
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void ppm_file::ppm_close()
{
close();
}
|