OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008-2010, 2015 Travis Geiselbrecht | 2 * Copyright (c) 2008-2010, 2015 Travis Geiselbrecht |
3 * | 3 * |
4 * Permission is hereby granted, free of charge, to any person obtaining | 4 * Permission is hereby granted, free of charge, to any person obtaining |
5 * a copy of this software and associated documentation files | 5 * a copy of this software and associated documentation files |
6 * (the "Software"), to deal in the Software without restriction, | 6 * (the "Software"), to deal in the Software without restriction, |
7 * including without limitation the rights to use, copy, modify, merge, | 7 * including without limitation the rights to use, copy, modify, merge, |
8 * publish, distribute, sublicense, and/or sell copies of the Software, | 8 * publish, distribute, sublicense, and/or sell copies of the Software, |
9 * and to permit persons to whom the Software is furnished to do so, | 9 * and to permit persons to whom the Software is furnished to do so, |
10 * subject to the following conditions: | 10 * subject to the following conditions: |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include <string.h> | 37 #include <string.h> |
38 #include <stdlib.h> | 38 #include <stdlib.h> |
39 #include <assert.h> | 39 #include <assert.h> |
40 #include <arch/ops.h> | 40 #include <arch/ops.h> |
41 #include <sys/types.h> | 41 #include <sys/types.h> |
42 #include <lib/gfx.h> | 42 #include <lib/gfx.h> |
43 #include <dev/display.h> | 43 #include <dev/display.h> |
44 | 44 |
45 #define LOCAL_TRACE 0 | 45 #define LOCAL_TRACE 0 |
46 | 46 |
47 | |
48 // Convert a 32bit ARGB image to its respective gamma corrected grayscale value. | 47 // Convert a 32bit ARGB image to its respective gamma corrected grayscale value. |
49 static uint32_t ARGB8888_to_Luma(uint32_t in) | 48 static uint32_t ARGB8888_to_Luma(uint32_t in) |
50 { | 49 { |
51 uint8_t out; | 50 uint8_t out; |
52 | 51 |
53 uint32_t blue = (in & 0xFF) * 74; | 52 uint32_t blue = (in & 0xFF) * 74; |
54 uint32_t green = ((in >> 8) & 0xFF) * 732; | 53 uint32_t green = ((in >> 8) & 0xFF) * 732; |
55 uint32_t red = ((in >> 16) & 0xFF) * 218; | 54 uint32_t red = ((in >> 16) & 0xFF) * 218; |
56 | 55 |
57 uint32_t intensity = red + blue + green; | 56 uint32_t intensity = red + blue + green; |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 | 653 |
655 return surface; | 654 return surface; |
656 } | 655 } |
657 | 656 |
658 /** | 657 /** |
659 * @brief Create a new graphics surface object from a display | 658 * @brief Create a new graphics surface object from a display |
660 */ | 659 */ |
661 gfx_surface *gfx_create_surface_from_display(struct display_info *info) | 660 gfx_surface *gfx_create_surface_from_display(struct display_info *info) |
662 { | 661 { |
663 gfx_surface *surface; | 662 gfx_surface *surface; |
664 surface = gfx_create_surface(info->framebuffer, info->width, info->height, i
nfo->stride, info->format); | 663 gfx_format format; |
| 664 switch (info->format) { |
| 665 case DISPLAY_FORMAT_RGB_565: |
| 666 format = GFX_FORMAT_RGB_565; |
| 667 break; |
| 668 case DISPLAY_FORMAT_RGB_332: |
| 669 format = GFX_FORMAT_RGB_332; |
| 670 break; |
| 671 case DISPLAY_FORMAT_RGB_2220: |
| 672 format = GFX_FORMAT_RGB_2220; |
| 673 break; |
| 674 case DISPLAY_FORMAT_ARGB_8888: |
| 675 format = GFX_FORMAT_ARGB_8888; |
| 676 break; |
| 677 case DISPLAY_FORMAT_RGB_x888: |
| 678 format = GFX_FORMAT_RGB_x888; |
| 679 break; |
| 680 case DISPLAY_FORMAT_MONO_8: |
| 681 format = GFX_FORMAT_MONO; |
| 682 break; |
| 683 default: |
| 684 dprintf(INFO, "invalid graphics format)"); |
| 685 DEBUG_ASSERT(0); |
| 686 return NULL; |
| 687 } |
| 688 |
| 689 surface = gfx_create_surface(info->framebuffer, info->width, info->height, i
nfo->stride, format); |
665 | 690 |
666 surface->flush = info->flush; | 691 surface->flush = info->flush; |
667 | 692 |
668 return surface; | 693 return surface; |
669 } | 694 } |
670 | 695 |
671 /** | 696 /** |
672 * @brief Destroy a graphics surface and free all resources allocated to it. | 697 * @brief Destroy a graphics surface and free all resources allocated to it. |
673 * | 698 * |
674 * @param surface Surface to destroy. This pointer is no longer valid after | 699 * @param surface Surface to destroy. This pointer is no longer valid after |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 | 839 |
815 gfx_flush(surface); | 840 gfx_flush(surface); |
816 | 841 |
817 gfx_surface_destroy(surface); | 842 gfx_surface_destroy(surface); |
818 | 843 |
819 return 0; | 844 return 0; |
820 } | 845 } |
821 | 846 |
822 #endif | 847 #endif |
823 #endif | 848 #endif |
OLD | NEW |