iPXE
Functions
pixbuf.c File Reference

Pixel buffer. More...

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/umalloc.h>
#include <ipxe/image.h>
#include <ipxe/pixbuf.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void free_pixbuf (struct refcnt *refcnt)
 Free pixel buffer. More...
 
struct pixel_bufferalloc_pixbuf (unsigned int width, unsigned int height)
 Allocate pixel buffer. More...
 
int image_pixbuf (struct image *image, struct pixel_buffer **pixbuf)
 Create pixel buffer from image. More...
 
 REQUIRING_SYMBOL (image_pixbuf)
 
 REQUIRE_OBJECT (config_pixbuf)
 

Detailed Description

Pixel buffer.

Definition in file pixbuf.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ free_pixbuf()

static void free_pixbuf ( struct refcnt refcnt)
static

Free pixel buffer.

Parameters
refcntReference count

Definition at line 44 of file pixbuf.c.

44  {
45  struct pixel_buffer *pixbuf =
47 
48  ufree ( pixbuf->data );
49  free ( pixbuf );
50 }
static __always_inline void ufree(void *ptr)
Free external memory.
Definition: umalloc.h:67
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
uint32_t * data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
Definition: pixbuf.h:24
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A pixel buffer.
Definition: pixbuf.h:16

References container_of, pixel_buffer::data, free, and ufree().

Referenced by alloc_pixbuf().

◆ 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().

◆ image_pixbuf()

int image_pixbuf ( struct image image,
struct pixel_buffer **  pixbuf 
)

Create pixel buffer from image.

Parameters
imageImage
pixbufPixel buffer to fill in
Return values
rcReturn status code

Definition at line 99 of file pixbuf.c.

99  {
100  int rc;
101 
102  /* Check that this image can be used to create a pixel buffer */
103  if ( ! ( image->type && image->type->pixbuf ) )
104  return -ENOTSUP;
105 
106  /* Try creating pixel buffer */
107  if ( ( rc = image->type->pixbuf ( image, pixbuf ) ) != 0 ) {
108  DBGC ( image, "IMAGE %s could not create pixel buffer: %s\n",
109  image->name, strerror ( rc ) );
110  return rc;
111  }
112 
113  return 0;
114 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct image_type * type
Image type, if known.
Definition: image.h:58
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int(* pixbuf)(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition: image.h:120
char * name
Name.
Definition: image.h:37

References DBGC, ENOTSUP, image::name, image_type::pixbuf, rc, strerror(), and image::type.

Referenced by console_exec(), and pixbuf_okx().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( image_pixbuf  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_pixbuf  )