Changeset 0d62c10 in mainline for uspace/lib


Ignore:
Timestamp:
2020-10-09T20:27:24Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f80690a
Parents:
8bf9058
Message:

Rendering text in different colors via colorization

Location:
uspace/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/congfx/src/console.c

    r8bf9058 r0d62c10  
    207207
    208208        /* Check that we support all requested flags */
    209         if ((params->flags & ~bmpf_color_key) != 0)
     209        if ((params->flags & ~(bmpf_color_key | bmpf_colorize)) != 0)
    210210                return ENOTSUP;
    211211
     
    296296
    297297        if ((cbm->flags & bmpf_color_key) == 0) {
     298                /* Simple copy */
    298299                for (y = crect.p0.y; y < crect.p1.y; y++) {
    299300                        console_set_pos(cbm->cgc->con, crect.p0.x, y);
     
    312313                        }
    313314                }
    314         } else {
     315        } else if ((cbm->flags & bmpf_colorize) == 0) {
     316                /* Color key */
    315317                for (y = crect.p0.y; y < crect.p1.y; y++) {
    316318                        for (x = crect.p0.x; x < crect.p1.x; x++) {
     
    332334                        }
    333335                }
     336        } else {
     337                /* Color key & colorize */
     338                console_set_rgb_color(cbm->cgc->con, cbm->cgc->clr,
     339                    cbm->cgc->clr);
     340
     341                for (y = crect.p0.y; y < crect.p1.y; y++) {
     342                        for (x = crect.p0.x; x < crect.p1.x; x++) {
     343
     344                                clr = pixelmap_get_pixel(&pixelmap,
     345                                    x - offs.x - cbm->rect.p0.x,
     346                                    y - offs.y - cbm->rect.p0.y);
     347
     348                                if (clr != cbm->key_color) {
     349                                        console_set_pos(cbm->cgc->con, x, y);
     350                                        rv = fputc('X', cbm->cgc->fout);
     351                                        if (rv < 0)
     352                                                return EIO;
     353
     354                                        console_flush(cbm->cgc->con);
     355                                }
     356
     357                        }
     358                }
    334359        }
    335360
  • uspace/lib/gfx/include/types/gfx/bitmap.h

    r8bf9058 r0d62c10  
    4747/** Bitmap flags */
    4848typedef enum {
     49        /** Directly map GC output into this bitmap */
     50        bmpf_direct_output = 0x1,
    4951        /** Enable color key */
    50         bmpf_color_key = 0x1,
    51         /** Directly map GC output into this bitmap */
    52         bmpf_direct_output = 0x2
     52        bmpf_color_key = 0x2,
     53        /** Paint non-background pixels with current drawing color */
     54        bmpf_colorize = 0x4
    5355} gfx_bitmap_flags_t;
    5456
  • uspace/lib/gfxfont/src/font.c

    r8bf9058 r0d62c10  
    122122        gfx_bitmap_params_init(&params);
    123123        params.rect = font->rect;
    124         params.flags = bmpf_color_key;
     124        params.flags = bmpf_color_key | bmpf_colorize;
    125125        params.key_color = PIXEL(0, 0, 0, 0);
    126126
     
    366366        if (nrect->p1.y - nrect->p0.y > params.rect.p1.y)
    367367                params.rect.p1.y = nrect->p1.y - nrect->p0.y;
    368         params.flags = bmpf_color_key;
     368        params.flags = bmpf_color_key | bmpf_colorize;
    369369        params.key_color = PIXEL(0, 0, 0, 0);
    370370
     
    705705        params.rect.p1.x = width;
    706706        params.rect.p1.y = height;
    707         params.flags = bmpf_color_key;
     707        params.flags = bmpf_color_key | bmpf_colorize;
    708708        params.key_color = PIXEL(0, 0, 0, 0);
    709709
  • uspace/lib/gfxfont/src/text.c

    r8bf9058 r0d62c10  
    135135                case gfx_valign_bottom:
    136136                        cpos.y -= fmetrics.descent;
    137                         break;
     137                        break;
    138138                default:
    139139                        break;
  • uspace/lib/memgfx/src/memgc.c

    r8bf9058 r0d62c10  
    225225
    226226        /* Check that we support all requested flags */
    227         if ((params->flags & ~(bmpf_color_key | bmpf_direct_output)) != 0)
     227        if ((params->flags & ~(bmpf_color_key | bmpf_colorize |
     228            bmpf_direct_output)) != 0)
    228229                return ENOTSUP;
    229230
     
    367368                /* Nothing to do */
    368369        } else if ((mbm->flags & bmpf_color_key) == 0) {
     370                /* Simple copy */
    369371                for (y = drect.p0.y; y < drect.p1.y; y++) {
    370372                        for (x = drect.p0.x; x < drect.p1.x; x++) {
     
    375377                        }
    376378                }
    377         } else {
     379        } else if ((mbm->flags & bmpf_colorize) == 0) {
     380                /* Color key */
    378381                for (y = drect.p0.y; y < drect.p1.y; y++) {
    379382                        for (x = drect.p0.x; x < drect.p1.x; x++) {
     
    385388                        }
    386389                }
     390        } else {
     391                /* Color key & colorization */
     392                for (y = drect.p0.y; y < drect.p1.y; y++) {
     393                        for (x = drect.p0.x; x < drect.p1.x; x++) {
     394                                pixel = pixelmap_get_pixel(&smap,
     395                                    x - mbm->rect.p0.x - offs.x,
     396                                    y - mbm->rect.p0.y - offs.y);
     397                                if (pixel != mbm->key_color)
     398                                        pixelmap_put_pixel(&dmap, x, y,
     399                                            mbm->mgc->color);
     400                        }
     401                }
    387402        }
    388403
Note: See TracChangeset for help on using the changeset viewer.