fbdev_common.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2011 Stefano Sabatini
  3. * Copyright (c) 2009 Giliard B. de Freitas <giliarde@gmail.com>
  4. * Copyright (C) 2002 Gunnar Monell <gmo@linux.nu>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <stdlib.h>
  23. #include "fbdev_common.h"
  24. #include "libavutil/common.h"
  25. struct rgb_pixfmt_map_entry {
  26. int bits_per_pixel;
  27. int red_offset, green_offset, blue_offset, alpha_offset;
  28. enum AVPixelFormat pixfmt;
  29. };
  30. static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
  31. // bpp, red_offset, green_offset, blue_offset, alpha_offset, pixfmt
  32. { 32, 0, 8, 16, 24, AV_PIX_FMT_RGBA },
  33. { 32, 16, 8, 0, 24, AV_PIX_FMT_BGRA },
  34. { 32, 8, 16, 24, 0, AV_PIX_FMT_ARGB },
  35. { 32, 3, 2, 8, 0, AV_PIX_FMT_ABGR },
  36. { 24, 0, 8, 16, 0, AV_PIX_FMT_RGB24 },
  37. { 24, 16, 8, 0, 0, AV_PIX_FMT_BGR24 },
  38. { 16, 11, 5, 0, 16, AV_PIX_FMT_RGB565 },
  39. };
  40. enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
  41. {
  42. int i;
  43. for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) {
  44. const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i];
  45. if (entry->bits_per_pixel == varinfo->bits_per_pixel &&
  46. entry->red_offset == varinfo->red.offset &&
  47. entry->green_offset == varinfo->green.offset &&
  48. entry->blue_offset == varinfo->blue.offset)
  49. return entry->pixfmt;
  50. }
  51. return AV_PIX_FMT_NONE;
  52. }
  53. const char* ff_fbdev_default_device()
  54. {
  55. const char *dev = getenv("FRAMEBUFFER");
  56. if (!dev)
  57. dev = "/dev/fb0";
  58. return dev;
  59. }