~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/libnr/nr-pixblock.h

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef __NR_PIXBLOCK_H__
2
 
#define __NR_PIXBLOCK_H__
3
 
 
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
 
 */
13
 
 
14
 
#include <libnr/nr-rect-l.h>
15
 
#include <libnr/nr-forward.h>
16
 
 
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;
28
 
 
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;
36
 
 
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
 
};
50
 
 
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
 
}
58
 
    
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
 
}
66
 
inline unsigned char const*
67
 
NR_PIXBLOCK_PX (NRPixBlock const *pb) 
68
 
69
 
    return ((pb->size == NR_PIXBLOCK_SIZE_TINY) ? 
70
 
            pb->data.p : pb->data.px);
71
 
}
72
 
 
73
 
void nr_pixblock_setup (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
74
 
void nr_pixblock_setup_fast (NRPixBlock *pb, NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
75
 
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);
76
 
void nr_pixblock_release (NRPixBlock *pb);
77
 
 
78
 
NRPixBlock *nr_pixblock_new (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
79
 
NRPixBlock *nr_pixblock_new_fast (NR_PIXBLOCK_MODE mode, int x0, int y0, int x1, int y1, bool clear);
80
 
NRPixBlock *nr_pixblock_free (NRPixBlock *pb);
81
 
 
82
 
unsigned char *nr_pixelstore_4K_new (bool clear, unsigned char val);
83
 
void nr_pixelstore_4K_free (unsigned char *px);
84
 
unsigned char *nr_pixelstore_16K_new (bool clear, unsigned char val);
85
 
void nr_pixelstore_16K_free (unsigned char *px);
86
 
unsigned char *nr_pixelstore_64K_new (bool clear, unsigned char val);
87
 
void nr_pixelstore_64K_free (unsigned char *px);
88
 
unsigned char *nr_pixelstore_256K_new (bool clear, unsigned char val);
89
 
void nr_pixelstore_256K_free (unsigned char *px);
90
 
unsigned char *nr_pixelstore_1M_new (bool clear, unsigned char val);
91
 
void nr_pixelstore_1M_free (unsigned char *px);
92
 
 
93
 
#endif
94
 
/*
95
 
  Local Variables:
96
 
  mode:c++
97
 
  c-file-style:"stroustrup"
98
 
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
99
 
  indent-tabs-mode:nil
100
 
  fill-column:99
101
 
  End:
102
 
*/
103
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :