fbdev_common.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "fbdev_common.h"
  23. #include "libavutil/common.h"
  24. struct rgb_pixfmt_map_entry {
  25. int bits_per_pixel;
  26. int red_offset, green_offset, blue_offset, alpha_offset;
  27. enum AVPixelFormat pixfmt;
  28. };
  29. static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
  30. // bpp, red_offset, green_offset, blue_offset, alpha_offset, pixfmt
  31. { 32, 0, 8, 16, 24, AV_PIX_FMT_RGBA },
  32. { 32, 16, 8, 0, 24, AV_PIX_FMT_BGRA },
  33. { 32, 8, 16, 24, 0, AV_PIX_FMT_ARGB },
  34. { 32, 3, 2, 8, 0, AV_PIX_FMT_ABGR },
  35. { 24, 0, 8, 16, 0, AV_PIX_FMT_RGB24 },
  36. { 24, 16, 8, 0, 0, AV_PIX_FMT_BGR24 },
  37. { 16, 11, 5, 0, 16, AV_PIX_FMT_RGB565 },
  38. };
  39. enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
  40. {
  41. int i;
  42. for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) {
  43. const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i];
  44. if (entry->bits_per_pixel == varinfo->bits_per_pixel &&
  45. entry->red_offset == varinfo->red.offset &&
  46. entry->green_offset == varinfo->green.offset &&
  47. entry->blue_offset == varinfo->blue.offset)
  48. return entry->pixfmt;
  49. }
  50. return AV_PIX_FMT_NONE;
  51. }