Changeset 30885b9 in mainline


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.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/src/mach/integratorcp/integratorcp.c

    r646b996 r30885b9  
    137137                .y = 480,
    138138                .scan = 2560,
    139                 .visual = VISUAL_RGB_8_8_8_0,
     139                .visual = VISUAL_BGR_0_8_8_8,
    140140        };
    141141        prop.addr = icp_get_fb_address();
  • kernel/arch/arm32/src/mach/testarm/testarm.c

    r646b996 r30885b9  
    8686                .y = 480,
    8787                .scan = 1920,
    88                 .visual = VISUAL_BGR_8_8_8,
     88                .visual = VISUAL_RGB_8_8_8,
    8989        };
    9090        fb_init(&prop);
  • kernel/arch/ia32/src/drivers/vesa.c

    r646b996 r30885b9  
    8686                    && (vesa_green_mask == 5) && (vesa_green_pos == 5)
    8787                    && (vesa_blue_mask == 5) && (vesa_blue_pos == 0))
    88                         visual = VISUAL_RGB_5_5_5;
     88                        visual = VISUAL_BGR_5_5_5;
    8989                else
    90                         visual = VISUAL_RGB_5_6_5;
     90                        visual = VISUAL_BGR_5_6_5;
    9191                break;
    9292        case 24:
    93                 visual = VISUAL_RGB_8_8_8;
     93                visual = VISUAL_BGR_8_8_8;
    9494                break;
    9595        case 32:
    96                 visual = VISUAL_RGB_0_8_8_8;
     96                visual = VISUAL_BGR_8_8_8_0;
    9797                break;
    9898        default:
  • kernel/arch/mips32/src/mips32.c

    r646b996 r30885b9  
    142142                .y = 480,
    143143                .scan = 1920,
    144                 .visual = VISUAL_BGR_8_8_8,
     144                .visual = VISUAL_RGB_8_8_8,
    145145        };
    146146        fb_init(&gxemul_prop);
  • kernel/arch/ppc32/src/ppc32.c

    r646b996 r30885b9  
    9393                                break;
    9494                        case 16:
    95                                 visual = VISUAL_RGB_5_5_5;
     95                                visual = VISUAL_BGR_5_5_5;
    9696                                break;
    9797                        case 24:
    98                                 visual = VISUAL_RGB_8_8_8;
     98                                visual = VISUAL_BGR_8_8_8;
    9999                                break;
    100100                        case 32:
  • kernel/arch/sparc64/src/drivers/scr.c

    r646b996 r30885b9  
    134134                case 16:
    135135                        fb_scanline = fb_linebytes * (fb_depth >> 3);
    136                         visual = VISUAL_RGB_5_6_5;
     136                        visual = VISUAL_BGR_5_6_5;
    137137                        break;
    138138                case 24:
    139139                        fb_scanline = fb_linebytes * 4;
    140                         visual = VISUAL_RGB_8_8_8_0;
     140                        visual = VISUAL_BGR_8_8_8_0;
    141141                        break;
    142142                case 32:
     
    178178                case 16:
    179179                        fb_scanline = fb_linebytes * (fb_depth >> 3);
    180                         visual = VISUAL_RGB_5_6_5;
     180                        visual = VISUAL_BGR_5_6_5;
    181181                        break;
    182182                case 24:
    183183                        fb_scanline = fb_linebytes * 4;
    184                         visual = VISUAL_RGB_8_8_8_0;
     184                        visual = VISUAL_BGR_8_8_8_0;
    185185                        break;
    186186                case 32:
  • kernel/genarch/include/fb/visuals.h

    r646b996 r30885b9  
    3636#define KERN_VISUALS_H_
    3737
    38 #define VISUAL_INDIRECT_8   0
    39 
    40 #define VISUAL_RGB_5_5_5    1
    41 #define VISUAL_RGB_5_6_5    2
    42 #define VISUAL_RGB_8_8_8    3
    43 #define VISUAL_RGB_8_8_8_0  4
    44 #define VISUAL_RGB_0_8_8_8  5
    45 
    46 #define VISUAL_BGR_0_8_8_8  6
    47 #define VISUAL_BGR_8_8_8    7
     38typedef enum {
     39        VISUAL_INDIRECT_8,
     40        VISUAL_BGR_5_5_5,
     41        VISUAL_BGR_5_6_5,
     42        VISUAL_BGR_8_8_8,
     43        VISUAL_BGR_0_8_8_8,
     44        VISUAL_BGR_8_8_8_0,
     45        VISUAL_RGB_8_8_8,
     46        VISUAL_RGB_0_8_8_8,
     47        VISUAL_RGB_8_8_8_0
     48} visual_t;
    4849
    4950#endif
  • 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;
  • uspace/srv/fb/fb.c

    r646b996 r30885b9  
    5858#include <bool.h>
    5959#include <stdio.h>
     60#include <byteorder.h>
    6061
    6162#include "font-8x16.h"
     
    213214
    214215
    215 #define RED(x, bits)                 ((x >> (8 + 8 + 8 - bits)) & ((1 << bits) - 1))
    216 #define GREEN(x, bits)               ((x >> (8 + 8 - bits)) & ((1 << bits) - 1))
    217 #define BLUE(x, bits)                ((x >> (8 - bits)) & ((1 << bits) - 1))
     216#define RED(x, bits)                 (((x) >> (8 + 8 + 8 - (bits))) & ((1 << (bits)) - 1))
     217#define GREEN(x, bits)               (((x) >> (8 + 8 - (bits))) & ((1 << (bits)) - 1))
     218#define BLUE(x, bits)                (((x) >> (8 - (bits))) & ((1 << (bits)) - 1))
    218219
    219220#define COL2X(col)                   ((col) * FONT_WIDTH)
     
    227228#define GLYPH_POS(glyph, y, cursor)  (((glyph) + (cursor) * FONT_GLYPHS) * screen.glyphbytes + (y) * screen.glyphscanline)
    228229
    229 
    230 /** ARGB 8:8:8:8 conversion
    231  *
    232  */
     230/*
     231 * RGB conversion and mask functions.
     232 *
     233 * These functions write an RGB value to some memory in some predefined format.
     234 * The naming convention corresponds to the format created by these functions.
     235 * The functions use the so called network order (i.e. big endian) with respect
     236 * to their names.
     237 */
     238
    233239static void rgb_0888(void *dst, uint32_t rgb)
    234240{
    235         *((uint32_t *) dst) = rgb & 0x00ffffff;
     241        *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
     242            (RED(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (BLUE(rgb, 8)));
     243}
     244
     245static void bgr_0888(void *dst, uint32_t rgb)
     246{
     247        *((uint32_t *) dst) = host2uint32_t_be((0 << 24) |
     248            (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | (RED(rgb, 8)));
    236249}
    237250
    238251static void mask_0888(void *dst, bool mask)
    239252{
    240         *((uint32_t *) dst) = (mask ? 0x00ffffff : 0);
    241 }
    242 
    243 
    244 /** ABGR 8:8:8:8 conversion
    245  *
    246  */
    247 static void bgr_0888(void *dst, uint32_t rgb)
    248 {
    249         *((uint32_t *) dst)
    250             = (BLUE(rgb, 8) << 16) | (GREEN(rgb, 8) << 8) | RED(rgb, 8);
     253        bgr_0888(dst, mask ? 0xffffff : 0);
    251254}
    252255
    253256static void rgb_8880(void *dst, uint32_t rgb)
    254257{
    255         *((uint32_t *) dst)
    256             = (RED(rgb, 8) << 24) | (GREEN(rgb, 8) << 16) | BLUE(rgb, 8) << 8;
     258        *((uint32_t *) dst) = host2uint32_t_be((RED(rgb, 8) << 24) |
     259            (GREEN(rgb, 8) << 16) | (BLUE(rgb, 8) << 8) | 0);
     260}
     261
     262static void bgr_8880(void *dst, uint32_t rgb)
     263{
     264        *((uint32_t *) dst) = host2uint32_t_be((BLUE(rgb, 8) << 24) |
     265            (GREEN(rgb, 8) << 16) | (RED(rgb, 8) << 8) | 0);
    257266}
    258267
    259268static void mask_8880(void *dst, bool mask)
    260269{
    261         *((uint32_t *) dst) = (mask ? 0xffffff00 : 0);
    262 }
    263 
    264 /** RGB 8:8:8 conversion
    265  *
    266  */
     270        bgr_8880(dst, mask ? 0xffffff : 0);
     271}
     272
    267273static void rgb_888(void *dst, uint32_t rgb)
     274{
     275        ((uint8_t *) dst)[0] = RED(rgb, 8);
     276        ((uint8_t *) dst)[1] = GREEN(rgb, 8);
     277        ((uint8_t *) dst)[2] = BLUE(rgb, 8);
     278}
     279
     280static void bgr_888(void *dst, uint32_t rgb)
    268281{
    269282        ((uint8_t *) dst)[0] = BLUE(rgb, 8);
     
    274287static void mask_888(void *dst, bool mask)
    275288{
    276         if (mask) {
    277                 ((uint8_t *) dst)[0] = 0xff;
    278                 ((uint8_t *) dst)[1] = 0xff;
    279                 ((uint8_t *) dst)[2] = 0xff;
    280         } else {
    281                 ((uint8_t *) dst)[0] = 0;
    282                 ((uint8_t *) dst)[1] = 0;
    283                 ((uint8_t *) dst)[2] = 0;
    284         }
    285 }
    286 
    287 
    288 /** BGR 8:8:8 conversion
    289  *
    290  */
    291 static void bgr_888(void *dst, uint32_t rgb)
    292 {
    293         ((uint8_t *) dst)[0] = RED(rgb, 8);
    294         ((uint8_t *) dst)[1] = GREEN(rgb, 8);
    295         ((uint8_t *) dst)[2] = BLUE(rgb, 8);
    296 }
    297 
    298 
    299 /** RGB 5:5:5 conversion
    300  *
    301  */
    302 static void rgb_555(void *dst, uint32_t rgb)
    303 {
    304         *((uint16_t *) dst)
    305             = (RED(rgb, 5) << 10) | (GREEN(rgb, 5) << 5) | BLUE(rgb, 5);
     289        bgr_888(dst, mask ? 0xffffff : 0);
     290}
     291
     292static void bgr_555(void *dst, uint32_t rgb)
     293{
     294        uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 5) << 5)) & 0xff;
     295        uint8_t lo = (GREEN(rgb, 5) >> 3) | (RED(rgb, 5) << 2);
     296        *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
    306297}
    307298
    308299static void mask_555(void *dst, bool mask)
    309300{
    310         *((uint16_t *) dst) = (mask ? 0x7fff : 0);
    311 }
    312 
    313 
    314 /** RGB 5:6:5 conversion
    315  *
    316  */
    317 static void rgb_565(void *dst, uint32_t rgb)
    318 {
    319         *((uint16_t *) dst)
    320             = (RED(rgb, 5) << 11) | (GREEN(rgb, 6) << 5) | BLUE(rgb, 5);
     301        bgr_555(dst, mask ? 0xffffff : 0);
     302}
     303
     304static void bgr_565(void *dst, uint32_t rgb)
     305{
     306        uint8_t hi = (BLUE(rgb, 5) | (GREEN(rgb, 6) << 5)) & 0xff;
     307        uint8_t lo = (GREEN(rgb, 6) >> 3) | (RED(rgb, 5) << 3);
     308        *((uint16_t *) dst) = host2uint16_t_be((hi << 8) | lo);
    321309}
    322310
    323311static void mask_565(void *dst, bool mask)
    324312{
    325         *((uint16_t *) dst) = (mask ? 0xffff : 0);
    326 }
    327 
    328 
    329 /** RGB 3:2:3
    330  *
    331  */
    332 static void rgb_323(void *dst, uint32_t rgb)
     313        bgr_565(dst, mask ? 0xffffff : 0);
     314}
     315
     316static void bgr_323(void *dst, uint32_t rgb)
    333317{
    334318        *((uint8_t *) dst)
     
    338322static void mask_323(void *dst, bool mask)
    339323{
    340         *((uint8_t *) dst) = (mask ? 0xff : 0);
     324        bgr_323(dst, mask ? 0x0 : ~0x0);
    341325}
    342326
     
    632616    unsigned int scan, unsigned int visual)
    633617{
    634        
    635        
    636618        switch (visual) {
    637619        case VISUAL_INDIRECT_8:
    638                 screen.rgb_conv = rgb_323;
     620                screen.rgb_conv = bgr_323;
    639621                screen.mask_conv = mask_323;
    640622                screen.pixelbytes = 1;
    641623                break;
    642         case VISUAL_RGB_5_5_5:
    643                 screen.rgb_conv = rgb_555;
     624        case VISUAL_BGR_5_5_5:
     625                screen.rgb_conv = bgr_555;
    644626                screen.mask_conv = mask_555;
    645627                screen.pixelbytes = 2;
    646628                break;
    647         case VISUAL_RGB_5_6_5:
    648                 screen.rgb_conv = rgb_565;
     629        case VISUAL_BGR_5_6_5:
     630                screen.rgb_conv = bgr_565;
    649631                screen.mask_conv = mask_565;
    650632                screen.pixelbytes = 2;
     
    673655                screen.rgb_conv = bgr_0888;
    674656                screen.mask_conv = mask_0888;
     657                screen.pixelbytes = 4;
     658                break;
     659        case VISUAL_BGR_8_8_8_0:
     660                screen.rgb_conv = bgr_8880;
     661                screen.mask_conv = mask_8880;
    675662                screen.pixelbytes = 4;
    676663                break;
Note: See TracChangeset for help on using the changeset viewer.