1 #ifndef __NR_PIXBLOCK_H__
2 #define __NR_PIXBLOCK_H__
4 /** \file
5 * \brief Pixel block structure. Used for low-level rendering.
6 *
7 * Authors:
8 * (C) 1999-2002 Lauris Kaplinski <lauris@kaplinski.com>
9 * (C) 2005 Ralf Stephan <ralf@ark.in-berlin.de> (some cleanup)
10 *
11 * This code is in the Public Domain.
12 */
14 #include <libnr/nr-rect-l.h>
15 #include <libnr/nr-forward.h>
17 /// Size indicator. Hardcoded to max. 3 bits.
18 typedef enum {
19 NR_PIXBLOCK_SIZE_TINY, ///< Fits in (unsigned char *)
20 NR_PIXBLOCK_SIZE_4K, ///< Pixelstore
21 NR_PIXBLOCK_SIZE_16K, ///< Pixelstore
22 NR_PIXBLOCK_SIZE_64K, ///< Pixelstore
23 NR_PIXBLOCK_SIZE_256K, ///< Pixelstore
24 NR_PIXBLOCK_SIZE_1M, ///< Pixelstore
25 NR_PIXBLOCK_SIZE_BIG, ///< Normally allocated
26 NR_PIXBLOCK_SIZE_STATIC ///< Externally managed
27 } NR_PIXBLOCK_SIZE;
29 /// Mode indicator. Hardcoded to max. 2 bits.
30 typedef enum {
31 NR_PIXBLOCK_MODE_A8, ///< Grayscale
32 NR_PIXBLOCK_MODE_R8G8B8, ///< 8 bit RGB
33 NR_PIXBLOCK_MODE_R8G8B8A8N, ///< Normal 8 bit RGBA
34 NR_PIXBLOCK_MODE_R8G8B8A8P ///< Premultiplied 8 bit RGBA
35 } NR_PIXBLOCK_MODE;
37 /// The pixel block struct.
38 struct NRPixBlock {
39 NR_PIXBLOCK_SIZE size : 3; ///< Size indicator
40 NR_PIXBLOCK_MODE mode : 2; ///< Mode indicator
41 bool empty : 1; ///< Empty flag
42 unsigned int rs; ///< Size of line in bytes
43 NRRectL area;
44 NRRectL visible_area;
45 union {
46 unsigned char *px; ///< Pointer to buffer
47 unsigned char p[sizeof (unsigned char *)]; ///< Tiny buffer
48 } data;
49 };
51 /// Returns number of bytes per pixel (1, 3, or 4).
52 inline int
53 NR_PIXBLOCK_BPP (NRPixBlock *pb)
54 {
55 return ((pb->mode == NR_PIXBLOCK_MODE_A8) ? 1 :
56 (pb->mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4);
57 }
59 /// Returns pointer to pixel data.
60 inline unsigned char*
61 NR_PIXBLOCK_PX (NRPixBlock *pb)
62 {
63 return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ?
64 pb->data.p : pb->data.px);
65 }
67 void nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
68 void nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
69 void nr_pixblock_setup_extern (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, unsigned char *px, int rs, bool empty, bool clear);
70 void nr_pixblock_release (NRPixBlock *pb);
72 NRPixBlock *nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
73 NRPixBlock *nr_pixblock_free (NRPixBlock *pb);
75 unsigned char *nr_pixelstore_4K_new (bool clear, unsigned char val);
76 void nr_pixelstore_4K_free (unsigned char *px);
77 unsigned char *nr_pixelstore_16K_new (bool clear, unsigned char val);
78 void nr_pixelstore_16K_free (unsigned char *px);
79 unsigned char *nr_pixelstore_64K_new (bool clear, unsigned char val);
80 void nr_pixelstore_64K_free (unsigned char *px);
81 unsigned char *nr_pixelstore_256K_new (bool clear, unsigned char val);
82 void nr_pixelstore_256K_free (unsigned char *px);
83 unsigned char *nr_pixelstore_1M_new (bool clear, unsigned char val);
84 void nr_pixelstore_1M_free (unsigned char *px);
86 #endif
87 /*
88 Local Variables:
89 mode:c++
90 c-file-style:"stroustrup"
91 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
92 indent-tabs-mode:nil
93 fill-column:99
94 End:
95 */
96 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :