iPXE
Data Structures | Functions
pixbuf.h File Reference

Pixel buffer. More...

#include <stddef.h>
#include <ipxe/refcnt.h>
#include <ipxe/uaccess.h>

Go to the source code of this file.

Data Structures

struct  pixel_buffer
 A pixel buffer. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __attribute__ ((always_inline)) struct pixel_buffer *pixbuf_get(struct pixel_buffer *pixbuf)
 Get reference to pixel buffer. More...
 
struct pixel_bufferalloc_pixbuf (unsigned int width, unsigned int height)
 Allocate pixel buffer. More...
 

Detailed Description

Pixel buffer.

Definition in file pixbuf.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Get reference to pixel buffer.

Drop reference to pixel buffer.

Parameters
pixbufPixel buffer
Return values
pixbufPixel buffer
Parameters
pixbufPixel buffer

Definition at line 36 of file pixbuf.h.

37  {
38  ref_get ( &pixbuf->refcnt );
39  return pixbuf;
40 }
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and pixel_buffer::refcnt.

◆ alloc_pixbuf()

struct pixel_buffer* alloc_pixbuf ( unsigned int  width,
unsigned int  height 
)

Allocate pixel buffer.

Parameters
widthWidth @h height Height
Return values
pixbufPixel buffer, or NULL on failure

Definition at line 58 of file pixbuf.c.

58  {
59  struct pixel_buffer *pixbuf;
60 
61  /* Allocate and initialise structure */
62  pixbuf = zalloc ( sizeof ( *pixbuf ) );
63  if ( ! pixbuf )
64  goto err_alloc_pixbuf;
65  ref_init ( &pixbuf->refcnt, free_pixbuf );
66  pixbuf->width = width;
67  pixbuf->height = height;
68  pixbuf->len = ( width * height * sizeof ( uint32_t ) );
69 
70  /* Check for multiplication overflow */
71  if ( ( width != 0 ) &&
72  ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height ) {
73  goto err_overflow;
74  }
75 
76  /* Allocate pixel data buffer */
77  pixbuf->data = umalloc ( pixbuf->len );
78  if ( ! pixbuf->data )
79  goto err_alloc_data;
80 
81  return pixbuf;
82 
83  err_alloc_data:
84  err_overflow:
85  pixbuf_put ( pixbuf );
86  err_alloc_pixbuf:
87  return NULL;
88 }
static void free_pixbuf(struct refcnt *refcnt)
Free pixel buffer.
Definition: pixbuf.c:43
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
unsigned int height
Height.
Definition: pixbuf.h:23
size_t len
Total length.
Definition: pixbuf.h:27
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
A pixel buffer.
Definition: pixbuf.h:17
struct refcnt refcnt
Reference count.
Definition: pixbuf.h:19
unsigned int uint32_t
Definition: stdint.h:12
static __always_inline userptr_t umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:54
userptr_t data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
Definition: pixbuf.h:25
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
unsigned int width
Width.
Definition: pixbuf.h:21

References pixel_buffer::data, free_pixbuf(), pixel_buffer::height, pixel_buffer::len, NULL, ref_init, pixel_buffer::refcnt, umalloc(), pixel_buffer::width, and zalloc().

Referenced by png_image_header(), and pnm_pixbuf().