Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pixbuf.c 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * Pixel buffer
  23. *
  24. */
  25. #include <stdlib.h>
  26. #include <ipxe/umalloc.h>
  27. #include <ipxe/pixbuf.h>
  28. /**
  29. * Free pixel buffer
  30. *
  31. * @v refcnt Reference count
  32. */
  33. static void free_pixbuf ( struct refcnt *refcnt ) {
  34. struct pixel_buffer *pixbuf =
  35. container_of ( refcnt, struct pixel_buffer, refcnt );
  36. ufree ( pixbuf->data );
  37. free ( pixbuf );
  38. }
  39. /**
  40. * Allocate pixel buffer
  41. *
  42. * @v width Width
  43. * @h height Height
  44. * @ret pixbuf Pixel buffer, or NULL on failure
  45. */
  46. struct pixel_buffer * alloc_pixbuf ( unsigned int width, unsigned int height ) {
  47. struct pixel_buffer *pixbuf;
  48. /* Allocate and initialise structure */
  49. pixbuf = zalloc ( sizeof ( *pixbuf ) );
  50. if ( ! pixbuf )
  51. goto err_alloc_pixbuf;
  52. ref_init ( &pixbuf->refcnt, free_pixbuf );
  53. pixbuf->width = width;
  54. pixbuf->height = height;
  55. pixbuf->len = ( width * height * sizeof ( uint32_t ) );
  56. /* Allocate pixel data buffer */
  57. pixbuf->data = umalloc ( pixbuf->len );
  58. if ( ! pixbuf->data )
  59. goto err_alloc_data;
  60. return pixbuf;
  61. err_alloc_data:
  62. pixbuf_put ( pixbuf );
  63. err_alloc_pixbuf:
  64. return NULL;
  65. }