summaryrefslogtreecommitdiff
path: root/image.c
blob: 4059d30d43c044a19e41b2b7f7a64b915a7f0fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * image.c
 *
 * Part of gwm, the Gratuitous Window Manager,
 *     by Gary Wong, <gtw@gnu.org>.
 *
 * Copyright (C) 2009  Gary Wong
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of version 3 of the GNU General Public License as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $Id$
 */

#include <config.h>

#include <xcb/xcb.h>

#include "gwm.h"

#include "image.h"

extern xcb_void_cookie_t put_image( xcb_drawable_t drawable, xcb_gcontext_t gc,
				    uint16_t width, uint16_t height, int16_t x,
				    int16_t y, uint8_t left_pad, uint8_t depth,
				    uint32_t len, const uint8_t *data ) {

    static uint16_t max;

    if( !max )
	max = xcb_get_setup( c )->maximum_request_length << 2;

    if( len + sizeof (xcb_put_image_request_t ) < max )
	return xcb_put_image( c, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
			      gc, width, height, x, y, left_pad,
			      depth, len, data );
    else {
	int linesize = len / height;
	int lines = ( max - sizeof (xcb_put_image_request_t) ) / linesize;

	while( height > lines ) {
	    xcb_put_image( c, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
			   gc, width, lines, x, y, left_pad,
			   depth, lines * linesize, data );
	    y += lines;
	    height -= lines;
	    len -= lines * linesize;
	    data += lines * linesize;
	}

	return xcb_put_image( c, XCB_IMAGE_FORMAT_Z_PIXMAP, drawable,
			      gc, width, height, x, y, left_pad,
			      depth, len, data );
    }
}