Code

moving trunk for module inkscape
[inkscape.git] / src / libnr / nr-pixblock.h
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         union {
45                 unsigned char *px; ///< Pointer to buffer
46                 unsigned char p[sizeof (unsigned char *)]; ///< Tiny buffer
47         } data;
48 };
50 /// Returns number of bytes per pixel (1, 3, or 4).
51 inline int 
52 NR_PIXBLOCK_BPP (NRPixBlock *pb)
53
54     return ((pb->mode == NR_PIXBLOCK_MODE_A8) ? 1 : 
55             (pb->mode == NR_PIXBLOCK_MODE_R8G8B8) ? 3 : 4); 
56 }
57     
58 /// Returns pointer to pixel data.
59 inline unsigned char*
60 NR_PIXBLOCK_PX (NRPixBlock *pb) 
61
62     return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ? 
63             pb->data.p : pb->data.px);
64 }
66 void nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
67 void nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
68 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);
69 void nr_pixblock_release (NRPixBlock *pb);
71 NRPixBlock *nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
72 NRPixBlock *nr_pixblock_free (NRPixBlock *pb);
74 unsigned char *nr_pixelstore_4K_new (bool clear, unsigned char val);
75 void nr_pixelstore_4K_free (unsigned char *px);
76 unsigned char *nr_pixelstore_16K_new (bool clear, unsigned char val);
77 void nr_pixelstore_16K_free (unsigned char *px);
78 unsigned char *nr_pixelstore_64K_new (bool clear, unsigned char val);
79 void nr_pixelstore_64K_free (unsigned char *px);
80 unsigned char *nr_pixelstore_256K_new (bool clear, unsigned char val);
81 void nr_pixelstore_256K_free (unsigned char *px);
82 unsigned char *nr_pixelstore_1M_new (bool clear, unsigned char val);
83 void nr_pixelstore_1M_free (unsigned char *px);
85 #endif
86 /*
87   Local Variables:
88   mode:c++
89   c-file-style:"stroustrup"
90   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91   indent-tabs-mode:nil
92   fill-column:99
93   End:
94 */
95 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :