File: Draw_bitmap.c

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (57 lines) | stat: -rw-r--r-- 1,531 bytes parent folder | download
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
/*!
  \file cairodriver/Draw_bitmap.c

  \brief GRASS cairo display driver - draw bitmap

  (C) 2007-2010 by Lars Ahlzen and the GRASS Development Team
  
  This program is free software under the GNU General Public License
  (>=v2). Read the file COPYING that comes with GRASS for details.
  
  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
  \author Glynn Clements  
*/

#include <grass/glocale.h>

#include "cairodriver.h"

/*!
  \brief Draw bitmap

  \param ncols,nrows number of columns and rows
  \param threshold threshold value
  \param buf data buffer
*/
void Cairo_draw_bitmap(int ncols, int nrows, int threshold,
		       const unsigned char *buf)
{
    cairo_surface_t *surf;
    int stride;
    unsigned char *data;
    int i;

    G_debug(1, "Cairo_draw_bitmap: %d %d %d", ncols, nrows, threshold);

#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,8)
    stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
#else
#define MULTIPLE 4
    stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE;
#endif
    data = malloc(stride * nrows);
    surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_A8, ncols,
					       nrows, stride);

    if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
	G_fatal_error(_("Cairo_draw_bitmap: Failed to create source"));

    for (i = 0; i < nrows; i++)
	memcpy(&data[i * stride], &buf[i * ncols], ncols);

    cairo_surface_mark_dirty(surf);
    cairo_mask_surface(cairo, surf, cur_x, cur_y);

    cairo_surface_destroy(surf);
    modified = 1;
}