You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Apply color map to test image. See http://peterkovesi.com/projects/colourmaps/colourmaptestimage.html */
std::string ToPPM_Test(int n, const unsigned char* srgb_colormap)
{
static const float twopi = 2.0 * M_PI;
int jMax = 128; // height
int iMax = 512; // width
int colormap_size = jMax * iMax;
std::string s = "P3\n"; // magic number for plain (ASCII txt) PPM
s += std::to_string(n) + " " + std::to_string(jMax) + "\n"; // save n=width and jMax=height to s string
s += "255\n"; // max val
for (int j = 0; j < jMax; j++){ // y , jMax = height
float v = 1.0f - (j / (jMax - 1.0f));
for (int i = 0; i < iMax; i++) // x , so here n = width. outside n = number of colors in the map
{
float u = i / (iMax - 1.0f);
// Test image formula
float ramp = u;
float modulation = 0.05f * std::sin(iMax / 8 * twopi * u);
float value = ramp + v * v * modulation;
// Applying colormap
int k = std::round(value * (colormap_size / 3 - 1));
if (k < 0)
{k = 0;}
else if (k >= colormap_size / 3) k = colormap_size / 3 - 1;
// add RGB string to s string
s += std::to_string(srgb_colormap[3 * k + 0]) + ' '
+ std::to_string(srgb_colormap[3 * k + 1]) + ' '
+ std::to_string(srgb_colormap[3 * k + 2]) + '\n';
}}
return s;
}
It gives Segmentation fault
What should I change ?
The text was updated successfully, but these errors were encountered:
Hi
I try to add test image by Peter Kovesi
It gives Segmentation fault
What should I change ?
The text was updated successfully, but these errors were encountered: