iPXE
Data Structures | Functions | Variables
pixbuf.h File Reference

Pixel buffer. More...

#include <stddef.h>
#include <ipxe/refcnt.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...
 

Variables

static unsigned int x
 
static unsigned int unsigned int y
 
 index = ( ( y * pixbuf->width ) + x )
 
return &pixbuf data [index]
 

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.

Get pixel.

Drop reference to pixel buffer.

Parameters
pixbufPixel buffer
Return values
pixbufPixel buffer
Parameters
pixbufPixel buffer
pixbufPixel buffer
xX position
yY position
Return values
pixelPixel

Definition at line 37 of file pixbuf.h.

38  {
39  ref_get ( &pixbuf->refcnt );
40  return pixbuf;
41 }
#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 59 of file pixbuf.c.

59  {
60  struct pixel_buffer *pixbuf;
61 
62  /* Allocate and initialise structure */
63  pixbuf = zalloc ( sizeof ( *pixbuf ) );
64  if ( ! pixbuf )
65  goto err_alloc_pixbuf;
66  ref_init ( &pixbuf->refcnt, free_pixbuf );
67  pixbuf->width = width;
68  pixbuf->height = height;
69  pixbuf->pixels = ( width * height );
70  pixbuf->len = ( pixbuf->pixels * sizeof ( uint32_t ) );
71 
72  /* Check for multiplication overflow */
73  if ( ( width != 0 ) &&
74  ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height ) {
75  goto err_overflow;
76  }
77 
78  /* Allocate pixel data buffer */
79  pixbuf->data = umalloc ( pixbuf->len );
80  if ( ! pixbuf->data )
81  goto err_alloc_data;
82 
83  return pixbuf;
84 
85  err_alloc_data:
86  err_overflow:
87  pixbuf_put ( pixbuf );
88  err_alloc_pixbuf:
89  return NULL;
90 }
static void free_pixbuf(struct refcnt *refcnt)
Free pixel buffer.
Definition: pixbuf.c:44
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
unsigned int height
Height.
Definition: pixbuf.h:22
unsigned int pixels
Total number of pixels.
Definition: pixbuf.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
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
A pixel buffer.
Definition: pixbuf.h:16
struct refcnt refcnt
Reference count.
Definition: pixbuf.h:18
unsigned int uint32_t
Definition: stdint.h:12
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition: umalloc.h:56
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
unsigned int width
Width.
Definition: pixbuf.h:20

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

Referenced by png_image_header(), and pnm_pixbuf().

Variable Documentation

◆ x

unsigned int x

◆ y

unsigned int unsigned int y

◆ index

index = ( ( y * pixbuf->width ) + x )

Definition at line 65 of file pixbuf.h.

◆ data

return& pixbuf data[index]

Definition at line 66 of file pixbuf.h.