|
@ -22,12 +22,12 @@ PNG::PNG(unsigned int width, unsigned int height, unsigned int num_colors): |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void PNG::clear() { |
|
|
void PNG::clear() { |
|
|
for ( unsigned int i = 0; i < width*height*num_colors; i++ ) { |
|
|
for(unsigned int i = 0; i < width*height*num_colors; i++) { |
|
|
int_array[i] = 0; |
|
|
int_array[i] = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void PNG::plot(double * position) { |
|
|
void PNG::plot(double* position) { |
|
|
const double& x = position[0]; |
|
|
const double& x = position[0]; |
|
|
const double& y = position[1]; |
|
|
const double& y = position[1]; |
|
|
|
|
|
|
|
@ -44,61 +44,61 @@ void PNG::plot(double * position) { |
|
|
I/O functions |
|
|
I/O functions |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
void PNG::output_file(const char * filename){ |
|
|
void PNG::output_file(const char* filename) { |
|
|
unsigned int * max_int = new unsigned int[num_colors]; |
|
|
unsigned int* max_int = new unsigned int[num_colors]; |
|
|
double * power = new double[num_colors]; |
|
|
double* power = new double[num_colors]; |
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < num_colors; i++ ) { |
|
|
for(unsigned int i = 0; i < num_colors; i++) { |
|
|
max_int[i] = 0; |
|
|
max_int[i] = 0; |
|
|
double cumulative = 0; |
|
|
double cumulative = 0; |
|
|
unsigned int n = 0; |
|
|
unsigned int n = 0; |
|
|
|
|
|
|
|
|
for ( unsigned int j = 0; j < width*height; j++) { |
|
|
for(unsigned int j = 0; j < width*height; j++) { |
|
|
if ( max_int[i] < int_array[j+i*width*height] ) { |
|
|
if(max_int[i] < int_array[j+i*width*height]) { |
|
|
max_int[i] = int_array[j+i*width*height]; |
|
|
max_int[i] = int_array[j+i*width*height]; |
|
|
} |
|
|
} |
|
|
if ( int_array[j+i*width*height] ) { |
|
|
if(int_array[j+i*width*height]) { |
|
|
cumulative += int_array[j+i*width*height]; |
|
|
cumulative += int_array[j+i*width*height]; |
|
|
n++; |
|
|
n++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( n > 100 ) { |
|
|
if(n > 100) { |
|
|
const double average = cumulative / (double)n; |
|
|
const double average = cumulative / (double)n; |
|
|
power[i] = -2.5/log(average/(double)max_int[i]); |
|
|
power[i] = -2.5/log(average/(double)max_int[i]); |
|
|
if ( power[i] < 0 ) |
|
|
if(power[i] < 0) |
|
|
power[i] = 1; |
|
|
power[i] = 1; |
|
|
} else { |
|
|
} else { |
|
|
power[i] = 1; |
|
|
power[i] = 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( n <= 10 ) { |
|
|
if(n <= 10) { |
|
|
LogInfo("not enough data\n"); |
|
|
LogInfo("not enough data\n"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const double vibrancy = 2.0; |
|
|
const double vibrancy = 2.0; |
|
|
double averagePower = 0; |
|
|
double averagePower = 0; |
|
|
for ( unsigned int i = 0; i < num_colors; i++ ) { |
|
|
for(unsigned int i = 0; i < num_colors; i++) { |
|
|
averagePower += power[i]; |
|
|
averagePower += power[i]; |
|
|
} |
|
|
} |
|
|
averagePower /= (double)num_colors; |
|
|
averagePower /= (double)num_colors; |
|
|
for ( unsigned int i = 0; i < num_colors; i++ ) { |
|
|
for(unsigned int i = 0; i < num_colors; i++) { |
|
|
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower; |
|
|
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pngwriter * pngFile = new pngwriter(width, height, 0.0, filename); |
|
|
pngwriter* pngFile = new pngwriter(width, height, 0.0, filename); |
|
|
pngFile->setcompressionlevel(9); |
|
|
pngFile->setcompressionlevel(9); |
|
|
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor"); |
|
|
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor"); |
|
|
|
|
|
|
|
|
for ( unsigned int x = 0; x < width; x++ ) { |
|
|
for(unsigned int x = 0; x < width; x++) { |
|
|
for ( unsigned int y = 0; y < height; y++ ) { |
|
|
for(unsigned int y = 0; y < height; y++) { |
|
|
double r = 0.0; |
|
|
double r = 0.0; |
|
|
double g = 0.0; |
|
|
double g = 0.0; |
|
|
double b = 0.0; |
|
|
double b = 0.0; |
|
|
for ( unsigned int c = 0; c < num_colors; c++ ) { |
|
|
for(unsigned int c = 0; c < num_colors; c++) { |
|
|
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c]; |
|
|
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c]; |
|
|
switch(c){ |
|
|
switch(c) { |
|
|
case 0: { |
|
|
case 0: { |
|
|
r = (pow(norm_value, power[c]))*3.5; |
|
|
r = (pow(norm_value, power[c]))*3.5; |
|
|
break; |
|
|
break; |
|
@ -127,7 +127,7 @@ void PNG::output_file(const char * filename){ |
|
|
LogInfo("Writing %s\n", filename); |
|
|
LogInfo("Writing %s\n", filename); |
|
|
|
|
|
|
|
|
std::ofstream file(filename); |
|
|
std::ofstream file(filename); |
|
|
if ( !file ) { |
|
|
if(!file) { |
|
|
LogError("Couldn't write to file"); |
|
|
LogError("Couldn't write to file"); |
|
|
} |
|
|
} |
|
|
pngFile->close(); |
|
|
pngFile->close(); |
|
|