Giter Club home page Giter Club logo

libovg's Introduction

LibOVG

LibOVG is a thin drawing library on top of OpenVG. It is designed to allow unified drawing commands between platforms (Raspberry Pi, BeagleBone, pcDuino, ...) and allowing for development on a desktop or laptop of choice. It can be run on these embedded devices without an X11 environment, greatly improving speed of your application. On your development machine, you can debug and preview your graphics with X running!

Requirements

OpenVG

On embedded devices like the Raspberry Pi, this should come pre-installed. For development environments (e.g. your laptop), support is provided through the ShivaVG project, which implements OpenVG API on top of OpenGL.

Installation

make
sudo make install

Usage

Simple example usage is provided below. You can compile with gcc -o ovg_demo temp.c -l ovg and run with ./ovg_demo. You should get a yellowish rectangle at the bottom of the screen that appears.

#include <stdio.h>
#include <ovg.h>

int main(int argc, char **argv) {
    Path rect;

    ovg_init(); //initialize OpenGL contexts, etc

    ovg_open(0,0,400,400); //open a 400x400 window at 0,0 on your monitor

    ovg_fill(255,200,128,255);     //R,G,B,A
    rect = ovg_rect(76,50,200,90); //X,Y,W,H

    //perform the drawing commands
    ovg_draw_path(rect, FILL_PATH);
    ovg_draw();


    getchar(); //quick way to pause and wait for user input. press enter to close

    ovg_cleanup(); //properly destroy windows and release memory

    return 0;
}

Filename Conventions

any filename ending in _pi.c or _x11.c will only get compiled on their target platforms. all other filenames get compiled for all targets.

libovg's People

Contributors

pzl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

happy-ferret

libovg's Issues

add intermediate alpha values to masking

using vgRenderToMask ignores any transparency information in the path's paint. The path used is assumed to be filled to 1.0 all throughout. Should add support for mask values like 0.3, 0.5, etc.

OpenVG 1.0.1 path-based masking

OpenVG 1.1 added vgRenderToMask to allow paths to be a masking object. versions below that only have the image-based vgMask. Need to update ovg_mask to use vgMask for older versions

Image warping

matrix operations might already work when images come around, but not convenient warping operations (vguWarpQuadToQuad..)

Disable complex modes at init-time

Disable scissoring, masking, etc at program start to save resources.

Consider these things disabled by default, but enabled once a scissor or mask call happens

Remove hard-coded window size

Currently hardcoded to be 1366x768 to match my pi's monitor. Need to remove this. Probably a settable attribute before (and after?) initialization. Unspecified might lead to full monitor size.

Probably should also add queryable monitor dimensions.

Drawing Frequency

Currently redrawing on-demand -- when a module has new things to be drawn, it happens as soon as it's received. This is great for very infrequent updates, there is no need to keep redrawing the screen when nothing changes. But this is not-so-great for quickly updating things.

Should there be a draw loop? Should any module updates be queued for the next draw loop to sweep through?

ShivaVG masking

using ShivaVG as compatability layer for desktop systems, vgMask is not supported.

Allow multiple windows

Getting an error on the pi when trying to open more than one window, in certain scenarios (more than 1 win per thread/process or multiple instantiations of shared lib).

Error is tv service-client failed to connect to tv service

solution according to this thread is to make sure bcm_host_init is only called once

Enable Scissoring?

I'm not sure what the use of scissoring would be that couldn't be accomplished through a black clear color and clearing. Or using masking/clipping.

Note that ShivaVG only supports a single scissor rect, and as of now, the Pi supports 0x1160 or 4,448

Some sort of privacy window or custom window shape, I guess. But still, could be obtained through clip/masks.

Warnings when compiling on Pi

GCC info

gcc --version
gcc (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Output

make
gcc -Wall -Wextra -Wfloat-equal -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -ftrapv -fPIC -DPI -Os -std=gnu99 -pedantic -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -c -o build/windowing_pi.o src/windowing_pi.c -shared -Wl,-soname,libovg.so.0 -L/opt/vc/lib -s -lbcm_host -lEGL -lGLESv2
In file included from /opt/vc/include/interface/vcos/vcos.h:139:0,
                 from /opt/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
                 from /opt/vc/include/EGL/eglplatform.h:110,
                 from /opt/vc/include/EGL/egl.h:36,
                 from src/windowing_pi.c:4:
/opt/vc/include/interface/vcos/vcos_logging.h:225:39: warning: ISO C does not permit named variadic macros [-Wvariadic-macros]
 #  define _VCOS_LOG_X(cat, _level, fmt...)   do { if (vcos_is_log_enabled(cat,_level)) vcos_log_impl(cat,_level,fmt); } while (0)
                                       ^
In file included from /opt/vc/include/interface/vmcs_host/vc_tvservice_defs.h:37:0,
                 from /opt/vc/include/interface/vmcs_host/vc_tvservice.h:40,
                 from /opt/vc/include/bcm_host.h:47,
                 from src/windowing_pi.c:6:
/opt/vc/include/interface/vmcs_host/vc_sdtv.h:42:33: warning: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
    SDTV_COLOUR_FORCE_32BIT    = 0x80000000
                                 ^
/opt/vc/include/interface/vmcs_host/vc_sdtv.h:61:28: warning: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
    SDTV_MODE_FORCE_32BIT = 0x80000000
                            ^
/opt/vc/include/interface/vmcs_host/vc_sdtv.h:72:29: warning: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
    SDTV_ASPECTFORCE_32BIT = 0x80000000
                             ^
/opt/vc/include/interface/vmcs_host/vc_sdtv.h:101:26: warning: ISO C restricts enumerator values to range of 'int' [-Wpedantic]
    SDTV_CP_FORCE_32BIT = 0x80000000
                          ^
In file included from /opt/vc/include/interface/vcos/vcos.h:185:0,
                 from /opt/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
                 from /opt/vc/include/EGL/eglplatform.h:110,
                 from /opt/vc/include/EGL/egl.h:36,
                 from src/windowing_pi.c:4:
/opt/vc/include/interface/vcos/vcos_timer.h:112:6: warning: inline function 'vcos_timer_delete' declared but never defined
 void vcos_timer_delete(VCOS_TIMER_T *timer);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:109:6: warning: inline function 'vcos_timer_reset' declared but never defined
 void vcos_timer_reset(VCOS_TIMER_T *timer, VCOS_UNSIGNED delay);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:102:6: warning: inline function 'vcos_timer_cancel' declared but never defined
 void vcos_timer_cancel(VCOS_TIMER_T *timer);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:95:6: warning: inline function 'vcos_timer_set' declared but never defined
 void vcos_timer_set(VCOS_TIMER_T *timer, VCOS_UNSIGNED delay);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:80:15: warning: inline function 'vcos_timer_create' declared but never defined
 VCOS_STATUS_T vcos_timer_create(VCOS_TIMER_T *timer,
               ^
In file included from /opt/vc/include/interface/vcos/vcos.h:127:0,
                 from /opt/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
                 from /opt/vc/include/EGL/eglplatform.h:110,
                 from /opt/vc/include/EGL/egl.h:36,
                 from src/windowing_pi.c:4:
/opt/vc/include/interface/vcos/vcos_thread.h:269:6: warning: inline function 'vcos_thread_resume' declared but never defined
 void vcos_thread_resume(VCOS_THREAD_T *thread);
      ^
/opt/vc/include/interface/vcos/vcos_thread.h:262:5: warning: inline function 'vcos_thread_running' declared but never defined
 int vcos_thread_running(VCOS_THREAD_T *thread);
     ^
/opt/vc/include/interface/vcos/vcos_thread.h:251:15: warning: inline function 'vcos_change_preemption' declared but never defined
 VCOS_UNSIGNED vcos_change_preemption(VCOS_UNSIGNED pe);
               ^
/opt/vc/include/interface/vcos/vcos_thread.h:234:6: warning: inline function 'vcos_thread_relinquish' declared but never defined
 void vcos_thread_relinquish(void);
      ^
/opt/vc/include/interface/vcos/vcos_thread.h:186:15: warning: inline function 'vcos_thread_get_affinity' declared but never defined
 VCOS_UNSIGNED vcos_thread_get_affinity(VCOS_THREAD_T *thread);
               ^
In file included from /opt/vc/include/interface/vcos/vcos.h:185:0,
                 from /opt/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
                 from /opt/vc/include/EGL/eglplatform.h:110,
                 from /opt/vc/include/EGL/egl.h:36,
                 from src/windowing_pi.c:4:
/opt/vc/include/interface/vcos/vcos_timer.h:112:6: warning: inline function 'vcos_timer_delete' declared but never defined
 void vcos_timer_delete(VCOS_TIMER_T *timer);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:109:6: warning: inline function 'vcos_timer_reset' declared but never defined
 void vcos_timer_reset(VCOS_TIMER_T *timer, VCOS_UNSIGNED delay);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:102:6: warning: inline function 'vcos_timer_cancel' declared but never defined
 void vcos_timer_cancel(VCOS_TIMER_T *timer);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:95:6: warning: inline function 'vcos_timer_set' declared but never defined
 void vcos_timer_set(VCOS_TIMER_T *timer, VCOS_UNSIGNED delay);
      ^
/opt/vc/include/interface/vcos/vcos_timer.h:80:15: warning: inline function 'vcos_timer_create' declared but never defined
 VCOS_STATUS_T vcos_timer_create(VCOS_TIMER_T *timer,
               ^
In file included from /opt/vc/include/interface/vcos/vcos.h:127:0,
                 from /opt/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
                 from /opt/vc/include/EGL/eglplatform.h:110,
                 from /opt/vc/include/EGL/egl.h:36,
                 from src/windowing_pi.c:4:
/opt/vc/include/interface/vcos/vcos_thread.h:269:6: warning: inline function 'vcos_thread_resume' declared but never defined
 void vcos_thread_resume(VCOS_THREAD_T *thread);
      ^
/opt/vc/include/interface/vcos/vcos_thread.h:262:5: warning: inline function 'vcos_thread_running' declared but never defined
 int vcos_thread_running(VCOS_THREAD_T *thread);
     ^
/opt/vc/include/interface/vcos/vcos_thread.h:251:15: warning: inline function 'vcos_change_preemption' declared but never defined
 VCOS_UNSIGNED vcos_change_preemption(VCOS_UNSIGNED pe);
               ^
/opt/vc/include/interface/vcos/vcos_thread.h:234:6: warning: inline function 'vcos_thread_relinquish' declared but never defined
 void vcos_thread_relinquish(void);
      ^
/opt/vc/include/interface/vcos/vcos_thread.h:186:15: warning: inline function 'vcos_thread_get_affinity' declared but never defined
 VCOS_UNSIGNED vcos_thread_get_affinity(VCOS_THREAD_T *thread);
               ^
ar rcs libovg.a build/transform.o build/utility.o build/basic_shapes.o build/font.o build/paint.o build/windowing_pi.o
gcc -Wall -Wextra -Wfloat-equal -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -ftrapv -fPIC -DPI -Os -std=gnu99 -pedantic -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -shared -Wl,-soname,libovg.so.0 -L/opt/vc/lib -s -o libovg.so.0.0.1 build/transform.o build/utility.o build/basic_shapes.o build/font.o build/paint.o build/windowing_pi.o -lbcm_host -lEGL -lGLESv2

Expand platform Support

BeagleBone: OpenVG 1.0
BeagleBoneBlack: OpenVG 1.0(?)
i.MX357: OpenVG 1.1
i.MX503: OpenVG 1.1
i.MX6: OpenVG 1.1
Ti OMAP 2/3: OpenVG ?.?
Anything containing a Mali GPU: OpenVG 1.1 (Mali-55 uses 1.0, but is uncommon)

Image filters

invert, darken, lighten, posterize, gaussian blur, emboss, edges (convolve), colormatrix operations

Need better exit calls

Needs some way to close a window. This might happen already in cleanup() on the Pi, but this is a noop on X11. So if it does close everything on Pi, needs to close window on X11 and maybe change the name to close(). If it doesn't do this on the Pi, we need a close() method in general.

Get point and Tangent from Path

Supported in OpenVG:

void vgPointAlongPath(VGPath p, VGint startsegment, VGint nsegments, VGfloat distance, VGfloat *x, VGfloat *y, VGfloat *tanx, VGfloat *tany)

but not implemented in ShivaVG.

Need to wrap the function in libovg, and either patch shiva or add our own compat function to fill in

Should text rendering use VGFont?

Currently using raw paths and glyphs.

VGFont seems to only be an OpenVG1.1 feature -- not supported by ShivaVG. Could fall back to current method on unsupported platforms?

change line syntax

line([x0,x1],[y0,y1])? what was I thinking?

Change it to something sensible line (x0,y0,x1,y1) or ([x0,y0],[x1,y1]) or create a Point class or something.

More efficient Path capabilities

Currently creating all paths will all capabilities. This may use more resources than necessary1 when used on simple paths. Instead, maybe take a minimum-and-build-up approach where a path is created with bare minimum capabilities, and as each function is requested (a transform, an interpolation) the capability is dynamically added before the operation.

1: ARM Mali GPU doc:

3.2.6. Set correct path capabilities

Specify what your paths are going to be used for. If VG_PATH_CAPABILITY_*_FROM or VG_PATH_CAPABILITY_MODIFY are not required, the driver can conserve memory as it can throw away the original input data.

Add image support

JPEG, PNG at least. non-animated GIF maybe. Who knows about others.

ovg_clear_rect coords are absolute

ovg_clear_rect should probably respect transforms. Currently uses absolute window coordinates disregarding the current matrix

Test Case to Reproduce

#include <stdio.h>
#include <ovg.h>

int main(int argc, char **argv){
    ovg_init();
    ovg_fill(255,0,0,255);


    ovg_translate(200,200);
    ovg_rect(0,0,100,100);
    ovg_clear_rect(0,0,50,50);

    ovg_draw();

    getchar();
    ovg_cleanup();
    return 0;
}

bottom left corner of the red square should be missing/cleared. Instead, clear's (0,0) coordinates mean bottom left of the window, so the red square is untouched.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.