Changeset 30885b9 in mainline for kernel/genarch/src/fb/fb.c


Ignore:
Timestamp:
2009-07-31T19:11:54Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a405563
Parents:
646b996
Message:

RGB conversion functions should work with a well-defined pixel format.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/fb/fb.c

    r646b996 r30885b9  
    5151#include <ddi/ddi.h>
    5252#include <arch/types.h>
     53#include <byteorder.h>
    5354
    5455SPINLOCK_INITIALIZE(fb_lock);
     
    8182#define INV_COLOR    0xaaaaaa
    8283
    83 #define RED(x, bits)         ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
    84 #define GREEN(x, bits)       ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
    85 #define BLUE(x, bits)        ((x >> (8 - bits)) & ((1 << bits) - 1))
     84#define RED(x, bits)         (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1))
     85#define GREEN(x, bits)       (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1))
     86#define BLUE(x, bits)        (((x) >> (8 - (bits))) & ((1 << (bits)) - 1))
    8687
    8788#define COL2X(col)           ((col) * FONT_WIDTH)
     
    9899static void (*rgb_conv)(void *, uint32_t);
    99100
    100 
    101 /** ARGB 8:8:8:8 conversion
    102  *
    103  */
     101/*
     102 * RGB conversion functions.
     103 *
     104 * These functions write an RGB value to some memory in some predefined format.
     105 * The naming convention corresponds to the format created by these functions.
     106 * The functions use the so called network order (i.e. big endian) with respect
     107 * to their names.
     108 */
     109
    104110static void rgb_0888(void *dst, uint32_t rgb)
    105111{
    106         *((uint32_t *) dst) = rgb & 0xffffff;
    107 }
    108 
    109 
    110 /** ABGR 8:8:8:8 conversion
    111  *
    112  */
     112        *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
     113            (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8)));
     114}
     115
    113116static void bgr_0888(void *dst, uint32_t rgb)
    114117{
    115         *((uint32_t *) dst)
    116             = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
     118        *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
     119            (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8)));
    117120}
    118121
    119122static void rgb_8880(void *dst, uint32_t rgb)
    120123{
    121         *((uint32_t *) dst)
    122            = (RED(rgb, 8) << 24) | (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8);
    123 
    124 }
    125 
    126 
    127 /** RGB 8:8:8 conversion
    128  *
    129  */
     124        *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
     125            (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
     126}
     127
     128static void bgr_8880(void *dst, uint32_t rgb)
     129{
     130        *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) |
     131            (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0);
     132}
     133
    130134static void rgb_888(void *dst, uint32_t rgb)
     135{
     136        ((uint8_t *) dst)[0] = RED(rgb, 8);
     137        ((uint8_t *) dst)[1] = GREEN(rgb, 8);
     138        ((uint8_t *) dst)[2] = BLUE(rgb, 8);
     139}
     140
     141static void bgr_888(void *dst, uint32_t rgb)
    131142{
    132143        ((uint8_t *) dst)[0] = BLUE(rgb, 8);
     
    135146}
    136147
    137 
    138 /** BGR 8:8:8 conversion
    139  *
    140  */
    141 static void bgr_888(void *dst, uint32_t rgb)
    142 {
    143         ((uint8_t *) dst)[0] = RED(rgb, 8);
    144         ((uint8_t *) dst)[1] = GREEN(rgb, 8);
    145         ((uint8_t *) dst)[2] = BLUE(rgb, 8);
    146 }
    147 
    148 
    149 /** RGB 5:5:5 conversion
    150  *
    151  */
    152 static void rgb_555(void *dst, uint32_t rgb)
    153 {
    154         *((uint16_t *) dst)
    155             = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
    156 }
    157 
    158 
    159 /** RGB 5:6:5 conversion
    160  *
    161  */
    162 static void rgb_565(void *dst, uint32_t rgb)
    163 {
    164         *((uint16_t *) dst)
    165             = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
    166 }
    167 
    168 
    169 /** RGB 3:2:3
     148static void bgr_555(void *dst, uint32_t rgb)
     149{
     150        uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff;
     151        uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2);
     152        *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
     153}
     154
     155static void bgr_565(void *dst, uint32_t rgb)
     156{
     157        uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff;
     158        uint8_t lo = (GREEN(rgb, 6) >> 3) | (RED(rgb, 5) << 3);
     159        *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
     160}
     161
     162
     163/** BGR 3:2:3
    170164 *
    171165 * Even though we try 3:2:3 color scheme here, an 8-bit framebuffer
     
    184178 *
    185179 */
    186 static void rgb_323(void *dst, uint32_t rgb)
     180static void bgr_323(void *dst, uint32_t rgb)
    187181{
    188182        *((uint8_t *) dst)
     
    458452        switch (props->visual) {
    459453        case VISUAL_INDIRECT_8:
    460                 rgb_conv = rgb_323;
     454                rgb_conv = bgr_323;
    461455                pixelbytes = 1;
    462456                break;
    463         case VISUAL_RGB_5_5_5:
    464                 rgb_conv = rgb_555;
     457        case VISUAL_BGR_5_5_5:
     458                rgb_conv = bgr_555;
    465459                pixelbytes = 2;
    466460                break;
    467         case VISUAL_RGB_5_6_5:
    468                 rgb_conv = rgb_565;
     461        case VISUAL_BGR_5_6_5:
     462                rgb_conv = bgr_565;
    469463                pixelbytes = 2;
    470464                break;
     
    487481        case VISUAL_BGR_0_8_8_8:
    488482                rgb_conv = bgr_0888;
     483                pixelbytes = 4;
     484                break;
     485        case VISUAL_BGR_8_8_8_0:
     486                rgb_conv = bgr_8880;
    489487                pixelbytes = 4;
    490488                break;
Note: See TracChangeset for help on using the changeset viewer.