--- ../ORG/lib/pspaint.c	2017-12-23 18:00:00.000000000 +0900
+++ ./pspaint.c	2023-06-19 18:00:00.000000000 +0900
@@ -340,15 +340,15 @@
 
 int paintm(float *v, float vlo, float vhi, float vnvd)
 {   double wt, xb, yb, x, y;
-    double hstp, vmed, va, vb, vc;
+    double vstp, vmin, va, vb, vc;
     float *pv1, *pv2, *pv3, *pv4;
     int pen, col, typ;
     int n, r, g, b, ix, iy, l, ls, ct;
     if (kdir == 0)
         { fprintf(stderr, "paintm: frame undefined\n"); return(-1); }
-    if (vhi == vlo)
+    if (vhi <= vlo)
         { fprintf(stderr, "paintm: invalid parameter\n"); return(-1); }
-    hstp = (vhi-vlo)/(nlvl+nlvl); vmed = (vlo+vhi)/2.;
+    vstp = (vhi-vlo)/nlvl; vmin = vlo-vstp;
     if ((pen=qpatr(0,&col,&typ,&wt)) < 0)
         { fprintf(stderr, "paintm: error at calling qpatr\n"); return(-1); }
     qpsfp(&fp);
@@ -370,20 +370,20 @@
     for (y=dy/2,iy=0; iy<ny; iy++,y+=dy) {
         while (y > yb) { pv1 = pv2; pv2+=(imx+1); yb+=1.; }
         if ((*pv1==vnvd) || (*pv2==vnvd)) vb = vnvd;
-        else vb = *pv1*(yb-y) + *pv2*(y+1.-yb);
+        else vb = (*pv2) + (*pv1 - *pv2)*(yb-y);
         pv3 = pv1; pv4 = pv2; xb = 0.;
         for (x=dx/2,ix=0; ix<nx; ix++,x+=dx) {
             while (x > xb) {
                 pv3++; pv4++; xb+=1.; va = vb;
                 if ((*pv3==vnvd) || (*pv4==vnvd)) vb = vnvd;
-                else vb = *pv3*(yb-y) + *pv4*(y+1.-yb);
+                else vb = (*pv4) + (*pv3 - *pv4)*(yb-y);
             }
             if ((va==vnvd) || (vb==vnvd)) l = nlvl+2;
             else {
-                vc = va*(xb-x) + vb*(x+1.-xb);
-                l = (int)((vc-vmed)/hstp) + (nlvl+1);
-                l = ((vc>=vmed)? (l+1)/2: l/2);
-                if (l < 0) l = 0; else if (l > (nlvl+1)) l = nlvl+1;
+                vc = vb + (va - vb)*(xb-x);
+                l = (int)((vc-vmin)/vstp);
+                if (l < 0) l = 0;
+                else if (l > nlvl) l = nlvl+1;
             }
             if (ls == -1) { ls = l; ct = 0; }
             else if ((ls==l) && (ct<255)) ct++;
@@ -417,16 +417,16 @@
 
 int paintw(float *v, float vlo, float vhi, float vnvd, float *u)
 {   double wt, xb, yb, x, y;
-    double hstp, vmed, va, vb, vc, ua, ub, uc;
+    double vstp, vmin, va, vb, vc, ua, ub, uc;
     float *pv1, *pv2, *pv3, *pv4;
     float *pu1, *pu2, *pu3, *pu4;
     int pen, col, typ, wcol;
     int n, ix, iy, l, ls, m, ms, ct;
     if (kdir == 0)
         { fprintf(stderr, "paintw: frame undefined\n"); return(-1); }
-    if (vhi == vlo)
+    if (vhi <= vlo)
         { fprintf(stderr, "paintw: invalid parameter\n"); return(-1); }
-    hstp = (vhi-vlo)/(nlvl+nlvl); vmed = (vlo+vhi)/2.;
+    vstp = (vhi-vlo)/nlvl; vmin = vlo-vstp;
     if ((pen=qpatr(0,&col,&typ,&wt)) < 0)
         { fprintf(stderr, "paintw: error at calling qpatr\n"); return(-1); }
     qpsfp(&fp);
@@ -438,24 +438,22 @@
         while (y > yb)
             { pv1 = pv2; pv2+=(imx+1); pu1 = pu2; pu2+=(imx+1); yb+=1.; }
         if ((*pv1==vnvd) || (*pv2==vnvd)) vb = vnvd;
-        else { vb = *pv1*(yb-y) + *pv2*(y+1.-yb);
-               ub = *pu1*(yb-y) + *pu2*(y+1.-yb); }
+        else { vb = (*pv2) + (*pv1 - *pv2)*(yb-y);
+               ub = (*pu2) + (*pu1 - *pu2)*(yb-y); }
         pv3 = pv1; pv4 = pv2; pu3 = pu1; pu4 = pu2; xb = 0.;
         for (x=dx/2,ix=0; ix<nx; ix++,x+=dx) {
             while (x > xb) {
                 pv3++; pv4++; pu3++; pu4++; xb+=1.; va = vb; ua = ub;
                 if ((*pv3==vnvd) || (*pv4==vnvd)) vb = vnvd;
-                else { vb = *pv3*(yb-y) + *pv4*(y+1.-yb);
-                       ub = *pu3*(yb-y) + *pu4*(y+1.-yb); }
+                else { vb = (*pv4) + (*pv3 - *pv4)*(yb-y);
+                       ub = (*pu4) + (*pu3 - *pu4)*(yb-y); }
             }
             if ((va==vnvd) || (vb==vnvd)) l = nlvl+2;
             else {
-                vc = va*(xb-x) + vb*(x+1.-xb);
-                uc = ua*(xb-x) + ub*(x+1.-xb);
-                l = (int)((vc-vmed)/hstp) + (nlvl+1);
-                l = ((vc>=vmed)? (l+1)/2: l/2);
-                if (l < 0) l = 0; else if (l > (nlvl+1)) l = nlvl+1;
-                m = (int)(uc*20.);
+                vc = vb + (va - vb)*(xb-x);
+                uc = ub + (ua - ub)*(xb-x);
+                l = (int)((vc-vmin)/vstp); m = (int)(uc*20.);
+                if (l < 0) l = 0; else if (l > nlvl) l = nlvl+1;
                 if (m < 0) m = 0; else if (m > 19) m = 19;
             }
             if (ls == -1) { ls = l; ms = m; ct = 0; }
