aboutsummaryrefslogtreecommitdiff
path: root/lib/mcsfile/mcsfile.h
blob: 38122560c51a8f1c354886986e8a337bdd3a8855 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ****************************************************************************
 * mcsfile/mcsfile.h -- MCS file internals.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of libcasio.
 * libcasio is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3.0 of the License,
 * or (at your option) any later version.
 *
 * libcasio 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libcasio; if not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#ifndef  LOCAL_MCSFILE_H
# define LOCAL_MCSFILE_H 1
# include "../internals.h"

/* ---
 * Macros for interacting with the buffer.
 * --- */

/* Read from a stream. */

# define  READ(CASIO__TO, CASIO__SZ) /* normal read */ { \
	int READ_err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)); \
	if (READ_err) return (READ_err); }
# define FREAD(CASIO__TO, CASIO__SZ) /* fail-less read */ \
	err = tio_read(buffer, (CASIO__TO), (CASIO__SZ));
# define GREAD(CASIO__TO, CASIO__SZ) /* read with goto fail */ \
	if ((err = tio_read(buffer, (CASIO__TO), (CASIO__SZ)))) \
		goto fail;

/* Read using size of the object. */

# define  DREAD(CASIO__TO) \
	READ(&CASIO__TO, sizeof(CASIO__TO))
# define GDREAD(CASIO__TO) \
	GREAD(&CASIO__TO, sizeof(CASIO__TO))

/* Skip. */

# define  SKIP(CASIO__SZ) { \
	int SKIP_err = tio_skip(buffer, (CASIO__SZ)); \
	if (SKIP_err) \
		return (SKIP_err); }
# define GSKIP(CASIO__SZ) { \
	err = tio_skip(buffer, (CASIO__SZ)); \
	if (err) \
		goto fail; }

/* Write. */

# define  WRITE(CASIO__BUF, CASIO__SZ) { \
	int WRITE_err = tio_write(buffer, (CASIO__BUF), (CASIO__SZ), 0); \
	if (WRITE_err) \
		return (WRITE_err); }
# define DWRITE(CASIO__OBJECT) \
	WRITE(&(CASIO__OBJECT), sizeof(CASIO__OBJECT))

/* ---
 * Picture utilities.
 * --- */

# define alloc_pixels(W, H) \
	casio_alloc(sizeof(casio_pixel_t*) \
		* (H) + sizeof(casio_pixel_t) * (W) * (H), 1)
# define prepare_pixels(I, W, H) { \
	unsigned int PIXPREP_y; \
	casio_pixel_t *PIXPREP_line = (casio_pixel_t*)&(I)[(H)]; \
	for (PIXPREP_y = 0; PIXPREP_y < (H); PIXPREP_y++) { \
		(I)[PIXPREP_y] = PIXPREP_line; \
		PIXPREP_line += (W); \
	}}

#endif