iPXE
pixbuf.h
Go to the documentation of this file.
1 #ifndef _IPXE_PIXBUF_H
2 #define _IPXE_PIXBUF_H
3 
4 /** @file
5  *
6  * Pixel buffer
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stddef.h>
13 #include <ipxe/refcnt.h>
14 
15 /** A pixel buffer */
16 struct pixel_buffer {
17  /** Reference count */
18  struct refcnt refcnt;
19  /** Width */
20  unsigned int width;
21  /** Height */
22  unsigned int height;
23  /** 32-bit (8:8:8:8) xRGB pixel data, in host-endian order */
25  /** Total number of pixels */
26  unsigned int pixels;
27  /** Total length */
28  size_t len;
29 };
30 
31 /**
32  * Get reference to pixel buffer
33  *
34  * @v pixbuf Pixel buffer
35  * @ret pixbuf Pixel buffer
36  */
37 static inline __attribute__ (( always_inline )) struct pixel_buffer *
38 pixbuf_get ( struct pixel_buffer *pixbuf ) {
39  ref_get ( &pixbuf->refcnt );
40  return pixbuf;
41 }
42 
43 /**
44  * Drop reference to pixel buffer
45  *
46  * @v pixbuf Pixel buffer
47  */
48 static inline __attribute__ (( always_inline )) void
49 pixbuf_put ( struct pixel_buffer *pixbuf ) {
50  ref_put ( &pixbuf->refcnt );
51 }
52 
53 /**
54  * Get pixel
55  *
56  * @v pixbuf Pixel buffer
57  * @v x X position
58  * @v y Y position
59  * @ret pixel Pixel
60  */
61 static inline __attribute__ (( always_inline )) uint32_t *
62 pixbuf_pixel ( struct pixel_buffer *pixbuf, unsigned int x, unsigned int y ) {
63  unsigned int index;
64 
65  index = ( ( y * pixbuf->width ) + x );
66  return &pixbuf->data[index];
67 }
68 
69 extern struct pixel_buffer * alloc_pixbuf ( unsigned int width,
70  unsigned int height );
71 
72 #endif /* _IPXE_PIXBUF_H */
index
Definition: pixbuf.h:65
unsigned int height
Height.
Definition: pixbuf.h:22
static unsigned int x
Definition: pixbuf.h:62
unsigned int pixels
Total number of pixels.
Definition: pixbuf.h:26
struct pixel_buffer * alloc_pixbuf(unsigned int width, unsigned int height)
Allocate pixel buffer.
Definition: pixbuf.c:59
A reference counter.
Definition: refcnt.h:26
size_t len
Total length.
Definition: pixbuf.h:28
uint32_t * data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
Definition: pixbuf.h:24
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
A pixel buffer.
Definition: pixbuf.h:16
static __attribute__((always_inline)) struct pixel_buffer *pixbuf_get(struct pixel_buffer *pixbuf)
Get reference to pixel buffer.
Definition: pixbuf.h:37
struct refcnt refcnt
Reference count.
Definition: pixbuf.h:18
unsigned int uint32_t
Definition: stdint.h:12
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static unsigned int unsigned int y
Definition: pixbuf.h:62
Reference counting.
unsigned int width
Width.
Definition: pixbuf.h:20
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106