iPXE
Functions
pixbuf.c File Reference

Pixel buffer. More...

#include <stdlib.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.
struct pixel_bufferalloc_pixbuf (unsigned int width, unsigned int height)
 Allocate pixel buffer.
int image_pixbuf (struct image *image, struct pixel_buffer **pixbuf)
 Create pixel buffer from image.
 REQUIRING_SYMBOL (image_pixbuf)
 REQUIRE_OBJECT (config_pixbuf)

Detailed Description

Pixel buffer.

Definition in file pixbuf.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void free_pixbuf ( struct refcnt refcnt) [static]

Free pixel buffer.

Parameters:
refcntReference count

Definition at line 43 of file pixbuf.c.

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

Referenced by alloc_pixbuf().

                                                  {
        struct pixel_buffer *pixbuf =
                container_of ( refcnt, struct pixel_buffer, refcnt );

        ufree ( pixbuf->data );
        free ( 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;
}
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 97 of file pixbuf.c.

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

Referenced by console_exec(), and pixbuf_okx().

                                                                       {
        int rc;

        /* Check that this image can be used to create a pixel buffer */
        if ( ! ( image->type && image->type->pixbuf ) )
                return -ENOTSUP;

        /* Try creating pixel buffer */
        if ( ( rc = image->type->pixbuf ( image, pixbuf ) ) != 0 ) {
                DBGC ( image, "IMAGE %s could not create pixel buffer: %s\n",
                       image->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}
REQUIRE_OBJECT ( config_pixbuf  )