On Sun, Jul 31, 2011 at 01:38, Anton Khirnov <[email protected]> wrote:
>
> On Sun, 31 Jul 2011 00:27:46 +0800, Yu-Jie Lin <[email protected]> wrote:
>> +#define REGION_WIN_BORDER 3
>> +/**
>> + * Draw grabbing region window
>> + *
>> + * @param s x11_grab context
>> + */
>> +static void
>> +x11grab_draw_region_win(struct x11_grab *s)
>> +{
>> +    Display *dpy = s->dpy;
>> +    int screen;
>> +    Window win = s->region_win;
>> +    GC gc;
>> +
>> +    screen = DefaultScreen(dpy);
>> +    gc = XCreateGC(dpy, win, 0, 0);
>> +    XSetForeground(dpy, gc, WhitePixel(dpy, screen));
>> +    XSetBackground(dpy, gc, BlackPixel(dpy, screen));
>> +    XSetLineAttributes(dpy, gc, 3, LineDoubleDash, 0, 0);
>                                   ^
> Shouldn't this be REGION_WIN_BORDER?

It is.

>> +    XDrawRectangle(dpy, win, gc,
>> +                   1, 1,
>> +                   s->width + REGION_WIN_BORDER * 2 - 1 * 2 - 1,
>                                                   ^^^^^^^^^^^^^^^
> It's not very clear to me what are those for. Can you explain?

I should put a pair of parentheses:

XDrawRectangle(dpy, win, gc,
               1, 1,
               (s->width + REGION_WIN_BORDER * 2) - 1 * 2 - 1,

region_win's geometry's top-left and bottom-right points are

    (0, 0), (width - 1, height -1),

where width and height are its window size, and

    width = s->width + REGION_WIN_BORDER * 2

The rectangle should be drawn at (with line_width (i.e. REGION_WIN_BORDER) = 3)

   (1, 1), ((width - 1) - 1, (height - 1) - 1),

The width of rectangle is

   rect_width = width - 1 * 2

1 is the leftmost point, the other 1 is rightmost point.

The XDrawRectangle(..., x, y, w, h) draw a rectangle from top-left
point (x, y) to bottom-right point (x + w, y + h). So for the top line
of the rectangle, it is actually drawn with (x + w) - x + 1 = w + 1
pixels.

If we wants WIDTH pixels to be drawn, one pixel must be subtracted
from the desired amount of pixels, hence

   rect_width_for_XDrawRectangle = width - 1 * 2 - 1

and it

   = (s->width + REGION_WIN_BORDER * 2) - 1 * 2 - 1

Hope this clarifies.

>>  /**
>>   * Initialize the x11 grab device demuxer (public device demuxer API).
>>   *
>> @@ -109,6 +175,7 @@ x11grab_read_header(AVFormatContext *s1, 
>> AVFormatParameters *ap)
>>          x11grab->draw_mouse = !strstr(offset, "nomouse");
>>          *offset= 0;
>>      }
>> +    x11grab->region_win = 0;
>
> No need for this, private contexts are initialised to 0.

Thanks for the tip.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to