9front - general discussion about 9front
 help / color / mirror / Atom feed
From: istvan bak <bdhpfl@gmail.com>
To: 9front@9front.org
Subject: crop(1) -c negative coordinates
Date: Mon, 26 Oct 2015 22:51:46 +0000	[thread overview]
Message-ID: <CAO+DOcpCwsUMqdRCzBeUVfRi_=9t2fTP7xHSCY1usrnuxYuzog@mail.gmail.com> (raw)

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)


                 reply	other threads:[~2015-10-26 22:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO+DOcpCwsUMqdRCzBeUVfRi_=9t2fTP7xHSCY1usrnuxYuzog@mail.gmail.com' \
    --to=bdhpfl@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).