9front - general discussion about 9front
 help / color / mirror / Atom feed
* crop(1) -c negative coordinates
@ 2015-10-26 22:51 istvan bak
  0 siblings, 0 replies; only message in thread
From: istvan bak @ 2015-10-26 22:51 UTC (permalink / raw)
  To: 9front

The -c flag in crop(1) works incorrectly for images that have a
nonzero upper left corner X coordinate. It crops the left and right
side of the image relative to [0, width[, instead of [r.min.x,
r.max.x[ . So, images with r.min.x < 0 have their left side eaten away
and their right side kept with the unwanted border. One can make such
images with paint(1). Rectangle coords of images can be viewed with
tweak(1). I presume such rectangles are normal and that images don't
usually need to be normalized (please confirm?).

A way to trigger the bug:
Add wide enough pink border (this works as expected):
crop -i -100 -b 255 150 150 image | page
Remove maximum amount of pink border:
crop -i -100 -b 255 150 150 image | crop -c 255 150 150 | page
Lament the fact that pink border remains on at least one side.

Fix below; apologies if gmail hard wraps long lines.

/sys/src/cmd/crop.c:34,40 - crop.c:34,40
  crop(Memimage *m, ulong c)
  {
        Memimage *n;
-       int x, y, bpl, wpl;
+       int i, x, y, bpl, wpl;
        int left, right, top, bottom;
        ulong *buf;

/sys/src/cmd/crop.c:61,68 - crop.c:61,69
                x = unloadmemimage(m, Rect(m->r.min.x, y, m->r.max.x,
y+1), (uchar*)buf, bpl);
                if(x != bpl)
                        sysfatal("unloadmemimage");
-               for(x=0; x<wpl; x++)
-                       if(buf[x] != c){
+               for(i=0; i<wpl; i++)
+                       if(buf[i] != c){
+                               x = m->r.min.x + i;
                                if(x < left)
                                        left = x;
                                if(x > right)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-10-26 22:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-26 22:51 crop(1) -c negative coordinates istvan bak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).