Changeset 30885b9 in mainline for uspace/srv/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
  • 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.