To show the density, we need a two-dimensional array to keep track the shape of the spectrum for each scan.
/* save data in vv[][] */ for(int ix=0;ix<spectrum_x;ix++) { int iy = (1.0-val)*density_y*0.9 + density_y*0.1; vv[iy][ix]++; if(vv[iy][ix] > vvmax) vvmax = vv[iy][ix]; } /* density draw */ p2 = m_image2->get_pixels(); for (int j = 0; j < density_y; j++) { for (int i = 0; i < density_x; i++) { double vvv = double (vv[j][i]) / double (vvmax); *p2++ = colormap_r( vvv ); *p2++ = colormap_g( vvv ); *p2++ = colormap_b( vvv ); } }