Changeset 7b882c1f in mainline


Ignore:
Timestamp:
2019-10-21T18:23:29Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0008c0f
Parents:
1822545
git-author:
Jiri Svoboda <jiri@…> (2019-10-21 00:37:28)
git-committer:
Jiri Svoboda <jiri@…> (2019-10-21 18:23:29)
Message:

Need some vector operations

Location:
uspace/lib
Files:
2 added
6 edited

Legend:

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

    r1822545 r7b882c1f  
    4040#include <congfx/console.h>
    4141#include <gfx/context.h>
     42#include <gfx/coord.h>
    4243#include <gfx/render.h>
    4344#include <io/pixel.h>
     
    191192        console_gc_t *cgc = (console_gc_t *) arg;
    192193        console_gc_bitmap_t *cbm = NULL;
    193         gfx_coord_t w, h;
     194        gfx_coord2_t dim;
    194195        errno_t rc;
    195196
     
    198199                return ENOMEM;
    199200
    200         w = params->rect.p1.x - params->rect.p0.x;
    201         h = params->rect.p1.y - params->rect.p0.y;
     201        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
    202202        cbm->rect = params->rect;
    203203
    204204        if (alloc == NULL) {
    205                 cbm->alloc.pitch = w * sizeof(uint32_t);
     205                cbm->alloc.pitch = dim.x * sizeof(uint32_t);
    206206                cbm->alloc.off0 = 0;
    207                 cbm->alloc.pixels = calloc(w * h, sizeof(uint32_t));
     207                cbm->alloc.pixels = calloc(dim.x * dim.y, sizeof(uint32_t));
    208208                if (cbm->alloc.pixels == NULL) {
    209209                        rc = ENOMEM;
     
    271271
    272272        // XXX Add function to translate rectangle
    273         drect.p0.x = srect.p0.x + offs.x;
    274         drect.p0.y = srect.p0.y + offs.y;
    275         drect.p1.x = srect.p1.x + offs.x;
    276         drect.p1.y = srect.p1.y + offs.y;
     273        gfx_rect_translate(&offs, &srect, &drect);
    277274
    278275        pixelmap.width = cbm->rect.p1.x - cbm->rect.p0.x;
     
    313310}
    314311
    315 
    316312/** @}
    317313 */
  • uspace/lib/gfx/include/gfx/coord.h

    r1822545 r7b882c1f  
    3939#include <types/gfx/coord.h>
    4040
     41extern void gfx_coord2_add(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
     42extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
     43extern void gfx_rect_translate(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *);
     44
    4145#endif
    4246
  • uspace/lib/gfx/include/types/gfx/coord.h

    r1822545 r7b882c1f  
    3434 */
    3535
    36 #ifndef _GFX_COORD_H
    37 #define _GFX_COORD_H
     36#ifndef _GFX_TYPES_COORD_H
     37#define _GFX_TYPES_COORD_H
    3838
    3939#include <errno.h>
  • uspace/lib/gfx/meson.build

    r1822545 r7b882c1f  
    3030        'src/bitmap.c',
    3131        'src/color.c',
     32        'src/coord.c',
    3233        'src/context.c',
    3334        'src/render.c'
     
    3738        'test/bitmap.c',
    3839        'test/color.c',
     40        'test/coord.c',
    3941        'test/main.c',
    4042        'test/render.c',
  • uspace/lib/gfx/test/main.c

    r1822545 r7b882c1f  
    3333PCUT_IMPORT(bitmap);
    3434PCUT_IMPORT(color);
     35PCUT_IMPORT(coord);
    3536PCUT_IMPORT(render);
    3637
  • uspace/lib/guigfx/src/canvas.c

    r1822545 r7b882c1f  
    188188        canvas_gc_t *cgc = (canvas_gc_t *) arg;
    189189        canvas_gc_bitmap_t *cbm = NULL;
    190         gfx_coord_t w, h;
     190        gfx_coord2_t dim;
    191191        errno_t rc;
    192192
     
    195195                return ENOMEM;
    196196
    197         w = params->rect.p1.x - params->rect.p0.x;
    198         h = params->rect.p1.y - params->rect.p0.y;
     197        gfx_coord2_subtract(&params->rect.p1, &params->rect.p0, &dim);
    199198        cbm->rect = params->rect;
    200199
    201200        if (alloc == NULL) {
    202                 cbm->surface = surface_create(w, h, NULL, 0);
     201                cbm->surface = surface_create(dim.x, dim.y, NULL, 0);
    203202                if (cbm->surface == NULL) {
    204203                        rc = ENOMEM;
     
    206205                }
    207206
    208                 cbm->alloc.pitch = w * sizeof(uint32_t);
     207                cbm->alloc.pitch = dim.x * sizeof(uint32_t);
    209208                cbm->alloc.off0 = 0;
    210209                cbm->alloc.pixels = surface_direct_access(cbm->surface);
    211210                cbm->myalloc = true;
    212211        } else {
    213                 cbm->surface = surface_create(w, h, alloc->pixels, 0);
     212                cbm->surface = surface_create(dim.x, dim.y, alloc->pixels, 0);
    214213                if (cbm->surface == NULL) {
    215214                        rc = ENOMEM;
     
    259258        gfx_rect_t drect;
    260259        gfx_coord2_t offs;
     260        gfx_coord2_t dim;
    261261
    262262        if (srect0 != NULL)
     
    272272        }
    273273
    274         // XXX Add function to translate rectangle
    275         drect.p0.x = srect.p0.x + offs.x;
    276         drect.p0.y = srect.p0.y + offs.y;
    277         drect.p1.x = srect.p1.x + offs.x;
    278         drect.p1.y = srect.p1.y + offs.y;
     274        /* Destination rectangle */
     275        gfx_rect_translate(&offs, &srect, &drect);
     276
     277        gfx_coord2_subtract(&drect.p1, &drect.p0, &dim);
    279278
    280279        transform_t transform;
     
    293292
    294293        drawctx_set_source(&drawctx, &source);
    295         drawctx_transfer(&drawctx, drect.p0.x, drect.p0.y,
    296             drect.p1.x - drect.p0.x, drect.p1.y - drect.p0.y);
     294        drawctx_transfer(&drawctx, drect.p0.x, drect.p0.y, dim.x, dim.y);
    297295
    298296        update_canvas(cbm->cgc->canvas, cbm->cgc->surface);
Note: See TracChangeset for help on using the changeset viewer.