GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
cairodriver/write_bmp.c
Go to the documentation of this file.
1/*!
2 \file lib/cairodriver/write_bmp.c
3
4 \brief GRASS cairo display driver - write bitmap (lower level functions)
5
6 SPDX-FileCopyrightText: 2007-2008 Lars Ahlzen
7 SPDX-FileCopyrightText: GRASS Development Team
8 SPDX-License-Identifier: GPL-2.0-or-later
9
10 \author Lars Ahlzen <lars ahlzen.com> (original contributor)
11 \author Glynn Clements
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17
18#include <grass/gis.h>
19#include <grass/glocale.h>
20#include "cairodriver.h"
21
22static unsigned char *put_2(unsigned char *p, unsigned int n)
23{
24 *p++ = n & 0xFF;
25 n >>= 8;
26 *p++ = n & 0xFF;
27 return p;
28}
29
30static unsigned char *put_4(unsigned char *p, unsigned int n)
31{
32 *p++ = n & 0xFF;
33 n >>= 8;
34 *p++ = n & 0xFF;
35 n >>= 8;
36 *p++ = n & 0xFF;
37 n >>= 8;
38 *p++ = n & 0xFF;
39 return p;
40}
41
42static void make_bmp_header(unsigned char *p)
43{
44 *p++ = 'B';
45 *p++ = 'M';
46
47 p = put_4(p, HEADER_SIZE + ca.width * ca.height * 4);
48 p = put_4(p, 0);
49 p = put_4(p, HEADER_SIZE);
50
51 p = put_4(p, 40);
52 p = put_4(p, ca.width);
53 p = put_4(p, -ca.height);
54 p = put_2(p, 1);
55 p = put_2(p, 32);
56 p = put_4(p, 0);
57 p = put_4(p, ca.width * ca.height * 4);
58 p = put_4(p, 0);
59 p = put_4(p, 0);
60 p = put_4(p, 0);
61 p = put_4(p, 0);
62}
63
65{
66 unsigned char header[HEADER_SIZE];
67 FILE *output;
68
69 output = fopen(ca.file_name, "wb");
70 if (!output)
71 G_fatal_error(_("Cairo: unable to open output file <%s>"),
72 ca.file_name);
73
74 memset(header, 0, sizeof(header));
75 make_bmp_header(header);
76 fwrite(header, sizeof(header), 1, output);
77
78 fwrite(ca.grid, ca.stride, ca.height, output);
79
81}
void cairo_write_bmp(void)
GRASS cairo display driver - header file.
#define HEADER_SIZE
Definition cairodriver.h:45
struct cairo_state ca
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
#define _(str)
Definition glocale.h:10
void output(const char *fmt,...)