- lastrow = ny * nycell - 1;
- for (irow = 0; irow < ny; irow++)
- {
- int icol, ir;
- int rpos = irow * nycell;
- for (ir = rpos; ir < rpos + nycell; ir++)
- {
- for (icol = 0; icol < nx; icol++)
- {
- double dens;
- int ic;
- int cpos = icol * nxcell;
- dens = (v[icol][irow] - densmin) / (densmax - densmin);
- if (dens < 0)
- dens = 0;
- else if (dens > 1)
- dens = 1;
- for (ic = cpos; ic < cpos + nxcell; ic++)
- {
- rowp[ic] = (unsigned int) (dens * (double) (N_GRAYSCALE - 1));
- gdImageSetPixel(gif, ic, lastrow - ir, gs_indices[rowp[ic]]);
- }
- }
+ int lastrow = ny * nycell - 1;
+ for (int irow = 0; irow < ny; irow++) {
+ int rpos = irow * nycell;
+ for (int ir = rpos; ir < rpos + nycell; ir++) {
+ for (int icol = 0; icol < nx; icol++) {
+ int cpos = icol * nxcell;
+ double dens = (v[icol][irow] - densmin) / (densmax - densmin);
+ dens = clamp(dens, 0., 1.);
+ for (int ic = cpos; ic < cpos + nxcell; ic++) {
+ rowp[ic] = (unsigned int) (dens * (double) (N_GRAYSCALE - 1));
+ gdImageSetPixel(gif, ic, lastrow - ir, gs_indices[rowp[ic]]);