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.
struct pixel_bufferalloc_pixbuf (unsigned int width, unsigned int height)
 Allocate pixel buffer.

Detailed Description

Pixel buffer.

Definition in file pixbuf.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __attribute__ ( (always_inline)  ) [inline, static]

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.

References ref_get.

                                           {
        ref_get ( &pixbuf->refcnt );
        return pixbuf;
}
struct pixel_buffer* alloc_pixbuf ( unsigned int  width,
unsigned int  height 
) [read]

Allocate pixel buffer.

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

Definition at line 58 of file pixbuf.c.

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

                                                                               {
        struct pixel_buffer *pixbuf;

        /* Allocate and initialise structure */
        pixbuf = zalloc ( sizeof ( *pixbuf ) );
        if ( ! pixbuf )
                goto err_alloc_pixbuf;
        ref_init ( &pixbuf->refcnt, free_pixbuf );
        pixbuf->width = width;
        pixbuf->height = height;
        pixbuf->len = ( width * height * sizeof ( uint32_t ) );

        /* Check for multiplication overflow */
        if ( ( width != 0 ) &&
             ( ( pixbuf->len / sizeof ( uint32_t ) ) / width ) != height ) {
                goto err_overflow;
        }

        /* Allocate pixel data buffer */
        pixbuf->data = umalloc ( pixbuf->len );
        if ( ! pixbuf->data )
                goto err_alloc_data;

        return pixbuf;

 err_alloc_data:
 err_overflow:
        pixbuf_put ( pixbuf );
 err_alloc_pixbuf:
        return NULL;
}