in a few places, mug is too cute by half. remember to set gamma for ostate (to prevent √-0.5), and allow for images that are less than 2.0 times 48x48. the first bug can be triggered by starting mug, then B3'ing in the blank space to the right of the images and gamma bar. Reference: /n/atom/patch/applied/mugslug Date: Wed Feb 12 21:09:34 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/mug.c Wed Feb 12 21:07:50 2014 +++ /sys/src/cmd/mug.c Wed Feb 12 21:07:52 2014 @@ -102,6 +102,10 @@ gamma2y(double g) { g -= 0.5; + if(fabs(g) != g){ + fprint(2, "g %g\n", g); + assert(fabs(g) == g); + } return (int)(128.0*sqrt(g)+0.5); } @@ -257,8 +261,8 @@ shrink = dx/48.0; ksize = 1+2*(int)(shrink/2.0); - if(ksize <= 2) - return; + if(ksize < 1) + sysfatal("mug: must start with image larger than 48x48"); k = emalloc(ksize*sizeof(k[0])); @@ -503,8 +507,10 @@ return; } - if(face[slot]==nil) + if(face[slot]==nil){ face[slot] = emalloc(sizeof(*face[slot])); + face[slot]->state.gamma = 1.; + } else{ freeimage(face[slot]->small); face[slot]->small = nil; @@ -999,21 +1005,21 @@ } void -initstate(void) +initstate(State *s) { - state.black = 0.0; - state.white = 1.0; - state.stretch = 1.0; - state.depth = 4; - state.gamma = 1.0; - setgtab(&state); - state.selr = insetrect(orig->r, 5); - sdx = Dx(state.selr); - sdy = Dy(state.selr); + s->black = 0.0; + s->white = 1.0; + s->stretch = 1.0; + s->depth = 4; + s->gamma = 1.0; + setgtab(s); + s->selr = insetrect(orig->r, 5); + sdx = Dx(s->selr); + sdy = Dy(s->selr); if(sdx > sdy) - state.selr.max.x = state.selr.min.x+sdy; + s->selr.max.x = s->selr.min.x+sdy; else - state.selr.max.y = state.selr.min.y+sdx; + s->selr.max.y = s->selr.min.y+sdx; } void @@ -1073,7 +1079,9 @@ for(i=0; ir, state.selr, small); drawscreen(1); flushimage(display, 1); @@ -1094,7 +1102,7 @@ continue; case 0: /* Reset */ mark(); - initstate(); + initstate(&state); small = allocimage(display, Rect(0,0,48,48), CHAN1(CGrey, state.depth), 0, DWhite); if(small == nil) sysfatal("allocimage: %r"); @@ -1124,6 +1132,7 @@ exits(nil); break; } + continue; } if(ptinrect(m.xy, rbig)){ @@ -1232,9 +1241,8 @@ continue; } - do + while(m.buttons==1) m = emouse(); - while(m.buttons==1); } exits(nil); }