Upload
jonah-ashley
View
65
Download
6
Embed Size (px)
DESCRIPTION
How to program OpenVG. Hwanyong Lee HUONE Inc. Contents. About HUONE Development Environments EGL Basic Concepts Path Image Paint. HUONE Inc. is developing solutions for handheld devices since 2001. Developing Mobile Solution File systems for mobile phone - PowerPoint PPT Presentation
Citation preview
© Copyright Khronos Group, 2006 - Page 1
How to How to program OpenVGprogram OpenVG
Hwanyong LeeHUONE Inc.
© Copyright Khronos Group, 2006 - Page 2
ContentsContents
About HUONE
Development Environments
EGL
Basic Concepts
Path
Image
Paint
© Copyright Khronos Group, 2006 - Page 3
HUONE INC.HUONE INC.• HUONE Inc. is developing solutions for handheld devices since 2001.
- Developing Mobile Solution- File systems for mobile phone- Multi-media Solution for mobile phone- Mobile Phone UI / Mobile Phone SI
- Solutions based on Khronos Standard- AlexVG™ engine : Vector Graphics Solution for Handheld device based on OpenVG 1.0- AlexVG™ t-Player : SVG Tiny 1.1 Player running on OpenVG 1.0
• HUONE is collaborating with Khronos Group to set up OpenVG standard. - In Nov. 2005, HUONE and Khronos Group agreed to develop "conformance test suite for
OpenVG 1.0” and the development is on going.
© Copyright Khronos Group, 2006 - Page 4
Platform & EGLPlatform & EGL
© Copyright Khronos Group, 2006 - Page 5
Development EnvironmentsDevelopment Environments• EGL– portable layer for graphics resource management
- Graphics context management- Surface/buffer binding- Rendering synchronization- supports OpenVG after EGL 1.2
• EGL API and OpenVG API
OpenVGEngine
FrameBuffer
GraphicDevices eglSwapBuffers()
User Application
OpenVG APIEGL API
Windows SDKor Others
OpenVG ImplementationPlatform
EGLEGL
SurfaceSurfaceContextContext
© Copyright Khronos Group, 2006 - Page 6
Windows SystemWindows System• Use Platform Dependent SDK
- Examples)- Win32 SDK : HUONE AlexVG engine for windows- Glut : Hybrid RI- MFC, Xlib
• Create Windows- Example)
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow )
- RegisterClass( &WndClass );- CreateWindow( lpszClass, lpszClass, dwStyle,
CW_USEDEFAULT, CW_USEDEFAULT, width,height, NULL, (HMENU)NULL, hInstance, NULL );
• Make Event Handler- Examples)
- LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )- WM_CREATE, WM_DESTROY- WM_PAINT- WM_KEYPRESS, WM_TIMER …….
© Copyright Khronos Group, 2006 - Page 7
EGL (1/3)EGL (1/3)• Initialization EGLint config_list[ ] = { EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_NONE};EGLConfig config;EGLint num_config;
EGLDisplay display; display = eglGetDisplay( hdc );
if (display == EGL_NO_DISPLAY) return 0;
if (eglInitialize(display, NULL, NULL) == EGL_FALSE || eglGetError() != EGL_SUCCESS) return 0;
eglBindAPI(EGL_OPENVG_API);
eglChooseConfig(display, config_list, &config, 1, &num_config);
© Copyright Khronos Group, 2006 - Page 8
EGL (2/3)EGL (2/3)• EGL Surface
EGLint attrib_list[ ] = { EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_NONPRE, EGL_COLORSPACE, EGL_COLORSPACE_sRGB, EGL_NONE };
EGLSurface surface;
surface = eglCreateWindowSurface( display, config, hWnd, attrib_list );
if ( surface == EGL_NO_SURFACE || eglGetError() != EGL_SUCCESS ) return 0;
• EGL Context EGLContext context;
context = eglCreateContext( display, 0, NULL, NULL ); if ( context == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS ) return 0;
if ( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE || eglGetError() != EGL_SUCCESS ) return 0;
© Copyright Khronos Group, 2006 - Page 9
EGL (3/3)EGL (3/3)• EGL Release
eglMakeCurrent( display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
eglDestroyContext( display, context ); context = NULL;
eglDestroySurface( display, surface );surface = NULL;
eglTerminate( display );display = NULL;
• Display
if ( vgGetError() == VG_NO_ERROR ) eglSwapBuffers( display, surface );
© Copyright Khronos Group, 2006 - Page 10
Basic OpenVG ProgrammingBasic OpenVG Programming
© Copyright Khronos Group, 2006 - Page 11
What’s programmed?What’s programmed?• Object Definition
- Path- Path Segments
- Image- RGBA streaming data
• Paint Definition- Stroke Paint- Fill Paint
• Transformation- User to Surface Transform- Paint to User Transform
• Parameter Definition- Stroke Parameter- Fill Parameter- Other Setting Parameter
• Refer to OpenVG Specification
??? ?
??
?
© Copyright Khronos Group, 2006 - Page 12
Context ParameterContext Parameter• Transform Parameter
- VG_MATRIX_MODE VG_MATRIX_PATH_USER_TO_SURFACE
• Fill Parameter- VG_FILL_RULE VG_EVEN_ODD
• Stroke Parameter - VG_STROKE_LINE_WIDTH 1.0f- VG_STROKE_CAP_STYLE VG_CAP_BUTT- VG_STROKE_JOIN_STYLE VG_JOIN_MITER- VG_STROKE_MITER_LIMIT 4.0f- VG_STROKE_DASH_PATTERN { } (array of length 0) (disabled)- VG_STROKE_DASH_PHASE 0.0f
• Other Parameter- VG_IMAGE_QUALITY VG_IMAGE_QUALITY_FASTER- VG_RENDERING_QUALITY VG_RENDERING_QUALITY_FASTER- VG_BLEND_MODE VG_BLEND_SRC_OVER- VG_IMAGE_MODE VG_DRAW_IMAGE_NORMAL- VG_SCISSORING VG_FALSE (disabled)- VG_SCISSOR_RECTS { } (array of length 0)- VG_TILE_FILL_COLOR { 0.0f, 0.0f, 0.0f, 0.0f }- VG_CLEAR_COLOR { 0.0f, 0.0f, 0.0f, 0.0f }- VG_MASKING VG_FALSE (disabled)- VG_PIXEL_LAYOUT VG_PIXEL_LAYOUT_UNKNOWN- VG_FILTER_FORMAT_LINEAR VG_FALSE (disabled)- VG_FILTER_FORMAT_PREMULTIPLIED VG_FALSE (disabled)- VG_FILTER_CHANNEL_MASK (VG_RED | VG_GREEN |VG_BLUE | VG_ALPHA)
• Read-only Parameter- VG_MAX_SCISSOR_RECTS, VG_MAX_DASH_COUNT, VG_MAX_KERNEL_SIZE,
G_MAX_SEPARABLE_KERNEL_SIZE,- VG_MAX_COLOR_RAMP_STOPS, VG_MAX_IMAGE_WIDTH, VG_MAX_IMAGE_HEIGHT, VG_MAX_IMAGE_PIXELS,
VG_MAX_IMAGE_BYTES, VG_MAX_FLOAT
© Copyright Khronos Group, 2006 - Page 13
Data TypesData Types• Primitive Data Types
- VGbyte- VGubyte- VGshort- VGint- VGuint- VGbitfield- VGboolean
- VG_TRUE- VG_FALSE
- VGfloat
• Handle Type- VGPath- VGImage- VGPaint
• Enum Data Types- Refer to openvg.h
© Copyright Khronos Group, 2006 - Page 14
Example. Context Parameter SettingExample. Context Parameter Setting• Screen Clear
• Scissoring
VGfloat clear[4] = { 1.0f, 1.0f, 1.0f, 0.5f };
vgSetfv( VG_CLEAR_COLOR, 4, clear );
vgClear( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
VGfloat color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
VGint rects[8] = { 0, 0, 100, 100, 100, 100, 200, 200 };
vgSeti( VG_SCISSORING, VG_TRUE );
vgSetiv( VG_SCISSOR_RECTS, 8, rects );
vgGetfv( VG_CLEAR_COLOR, 4, color );
color[3] = 1.0f;
vgSetfv( VG_CLEAR_COLOR, 4, color );
vgClear( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
© Copyright Khronos Group, 2006 - Page 15
Path DrawingPath Drawing
© Copyright Khronos Group, 2006 - Page 16
Path DefinitionPath Definition• Path Segments
- Basic Path Segments- MOVE_TO- LINE_TO- QUAD_TO- CUBIC_TO- CLOSE_PATH
- Smooth Curves Segments- SQUAD_TO, SCUBIC_TO
- Elliptical Arcs Segments- SCCWARC_TO, SCWARC_TO, LCCWARC_TO, LCWARC_TO
• For easy definition- Use VGU Functions
- vguLine- vguPolygon- vguRect- vguRoundRect- vguEllipse- vguArc
• Absolute / Relative Coordinates
© Copyright Khronos Group, 2006 - Page 17
Path APIsPath APIs• Path Handle
- Handle Creation- VGPath vgCreatePath( VGint pathFormat, VGPathDatatype datatype, VGfloat scale, VGfloat bias,
VGint segmentCapacityHint, VGint coordCapacityHint, VGbitfield capabilities );- Handle Destroy
- void vgDestroyPath( VGPath path );- Path Drawing
- void vgDrawPath( VGPath path, VGbitfield paintModes );- VG_STROKE_PATH- VG_FILL_PATH
• Path Segments Definition- Segments Definition
- List of Path Segments- VGubyte pathSegments[numSegments] = { Segment1, Segment2, Segment3, …….. };
- Coords Definition- List of Coord for each Segments- VGbyte / VGshort / VGint / VGVGfloat pathData[?] = { Segment1_Coord1, Segment1_Coord2,
Segment2_Coord1, Segment2_Coord2, Segment2_Coord3, … };- Append Segments to Path Handle
- void vgAppendPathData( VGPath dstPath, VGint numSegments, const VGubyte * pathSegments, const void * pathData );
© Copyright Khronos Group, 2006 - Page 18
Example. Shape DrawingExample. Shape Drawing
• TriangleVGPath path;
VGubyte segments[] = { VG_MOVE_TO_ABS, VG_LINE_TO_REL, VG_LINE_TO_REL, VG_CLOSE_PATH };
VGfloat coords[] = { 0.0f, 0.0f, // VG_MOVE_TO_ABS
50.0f, 0.0f, // VG_LINE_TO_REL
-25.0f, 25.0f // VG_LINE_TO_REL
};
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
vgAppendPathData( path, 4, segments, coords );
vgDrawPath( path, VG_STROKE_PATH );
vgDestroyPath( path );
© Copyright Khronos Group, 2006 - Page 19
Transform DefinitionTransform Definition• Coordinate Systems of OpenVG
- Orthogonal Coordinate System- pixel (0, 0) is located at the lower-left corner
• Type of coordinate system- User Coordinate
- For Path- For Image
- Surface Coordinate- Paint Coordinate
- For Stroke Paint- For Fill Paint
• Transform Matrix- Matrix Mode
- VG_MATRIX_PATH_USER_TO_SURFACE- VG_MATRIX_IMAGE_USER_TO_SURFACE- VG_MATRIX_FILL_PAINT_TO_USER- VG_MATRIX_STROKE_PAINT_TO_USER
User coordinate Surface coordinate
User coordinate Surface coordinatePaint coordinate
© Copyright Khronos Group, 2006 - Page 20
Transformation MatrixTransformation Matrix• Path Transform
- use 2x3 affine transformations
• Image Transform- Images use 3x3 perspective transformations
© Copyright Khronos Group, 2006 - Page 21
Transform APIsTransform APIs• Transformation functions are similar to OpenGL:
- void vgLoadIdentity( void );- void vgLoadMatrix( const VGfloat * m );- void vgGetMatrix( VGfloat * m );- void vgMultMatrix( const VGfloat * m );- void vgTranslate( VGfloat tx, VGfloat ty );- void vgScale( VGfloat sx, VGfloat sy );- void vgShear( VGfloat shx, VGfloat shy );- void vgRotate( VGfloat angle );
• VGU Image Warping APIs- vguComputeWarpQuadToSquare( VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix );- vguComputeWarpSquareToQuad( VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat * matrix );- vguComputeWarpQuadToQuad( VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix );
right-multiplies the current matrix M
© Copyright Khronos Group, 2006 - Page 22
Example. Path TransformExample. Path Transform• Round Rectangle
• Transform
vgTranslate( 10.0f, 10.0f );
vgTranslate( 10.0f, 10.0f );
vgScale( 5.0f, 5.0f );
vgScale( 5.0f, 5.0f );
vgTranslate( 10.0f, 10.0f );
VGPath path;
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
vguRoundRect( path, 0.0f, 0.0f, 20.0f, 20.0f, 5.0f, 5.0f );
vgDrawPath( path, VG_STROKE_PATH );
vgDestroyPath( path );
vgScale( 5.0f, 5.0f );
vgTranslate( 10.0f, 10.0f );
vgRotate( 30.0f );
© Copyright Khronos Group, 2006 - Page 23
Example. Stroke Parameter (1/3)Example. Stroke Parameter (1/3)• Draw two Lines
• Set Line Width
VGPath path;
VGubyte segments[] = { VG_MOVE_TO_ABS, VG_HLINE_TO_REL, VG_LINE_TO_REL };
VGfloat coords[] = { 50.0f, 50.0f, 200.0f, -200.0f, 150.0f };
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
vgAppendPathData( path, 3, segments, coords );
// to do – Set Stroke Parameter
vgDrawPath( path, VG_STROKE_PATH);
vgDestroyPath( path );
vgSeti( VG_STROKE_LINE_WIDTH, 20 );
* Yellow line is virtual line for description
© Copyright Khronos Group, 2006 - Page 24
Example. Stroke Example. Stroke ParameterParameter (2/3) (2/3)• Set Join-Style
- BEVEL
- MITER
- ROUND
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSeti( VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL );
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSeti( VG_STROKE_JOIN_STYLE, VG_JOIN_MITER );
vgSetf( VG_STROKE_MITER_LIMIT, 3.0f );+
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSeti( VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND );
MiterLimit
© Copyright Khronos Group, 2006 - Page 25
Example. Stroke Parameter (3/3)Example. Stroke Parameter (3/3)• Set End-Cap Style
- BUTT
- SQUARE
- ROUND
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_BUTT );
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_SQUARE );
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_ROUND );
© Copyright Khronos Group, 2006 - Page 26
Example. Dash PatternExample. Dash Pattern• Dash Pattern
VGint pattern[4] = { 50, 30, 20, 10 };
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSetiv( VG_STROKE_DASH_PATTERN, 4, pattern );
VGint pattern[4] = { 50, 30, 20, 10 };
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSetiv( VG_STROKE_DASH_PATTERN, 4, pattern );
vgSeti( VG_STROKE_CAP_STYLE, VG_CAP_ROUND );
VGint pattern[4] = { 50, 30, 20, 10 };
vgSetf( VG_STROKE_LINE_WIDTH, 20.0f );
vgSetiv( VG_STROKE_DASH_PATTERN, 4, pattern );
vgSeti( VG_STROKE_DASH_PHASE, 40 );
© Copyright Khronos Group, 2006 - Page 27
Example. Fill ParameterExample. Fill Parameter
• Draw DonutsVGPath path;
VGubyte segments[] = { VG_MOVE_TO_ABS, VG_LCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH,
VG_MOVE_TO_ABS, VG_LCCWARC_TO_REL, VG_SCCWARC_TO_REL, VG_CLOSE_PATH };
VGfloat coords[] = { 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 20.0f, 0.0f, 10.0f, 10.0f, 0.0f, -20.0f, 0.0f,
5.0f, 0.0f, 5.0f, 5.0f, 0.0f, 10.0f, 0.0f, 5.0f, 5.0f, 0.0f, -10.0f, 0.0f };
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
vgAppendPathData( path, 8, segments, coords );
vgScale( 5.0f, 5.0f );
vgTranslate( 10.0f, 20.0f );
vgSeti( VG_FILL_RULE, VG_EVEN_ODD );
vgDrawPath( path, VG_FILL_PATH );
vgTranslate( 25.0f, 0.0f );
vgSeti( VG_FILL_RULE, VG_NON_ZERO );
vgDrawPath( path, VG_FILL_PATH );
0 1 2 1 00 1 2 1 0
© Copyright Khronos Group, 2006 - Page 28
more Path APIsmore Path APIs• Path Capability
• void vgRemovePathCapabilities (VGPath path, VGbitfield capabilities);• VGbitfield vgGetPathCapabilities(VGPath path);
• Path Clear• void vgClearPath (VGPath path, VGbitfield capabilities);
• Path Coord Modify• void vgModifyPathCoords (VGPath dstPath, VGint startIndex, VGint numSegments, const void * pathData);
• Path Merge and Transform• void vgAppendPath (VGPath dstPath, VGPath srcPath);• void vgTransformPath (VGPath dstPath, VGPath srcPath);• VGboolean vgInterpolatePath (VGPath dstPath, VGPath startPath, VGPath endPath, VGfloat amount);
• Query Path Length and Tangent• VGfloat vgPathLength (VGPath path, VGint startSegment, VGint numSegments);• void vgPointAlongPath (VGPath path, VGint startSegment, VGint numSegments, VGfloat distance,
VGfloat * x, VGfloat * y, VGfloat * tangentX, VGfloat * tangentY);
• Path Bound• void vgPathBounds (VGPath path, VGfloat * minX, VGfloat * minY, VGfloat * width, VGfloat * height);• void vgPathTransformedBounds (VGPath path, VGfloat * minX, VGfloat * minY, VGfloat * width, VGfloat * height);
© Copyright Khronos Group, 2006 - Page 29
Image DrawingImage Drawing
© Copyright Khronos Group, 2006 - Page 30
Image FormatsImage Formats• Color Space
- sRGB, lRGB- Premultiplied, Non-Premultiplied Alpha - Color Depth
• Image Formatstypedef enum {
VG_IMAGE_FORMAT_INVALID = -1,VG_sRGBX_8888 = 0,VG_sRGBA_8888 = 1,VG_sRGBA_8888_PRE = 2,VG_sRGB_565 = 3,VG_sRGBA_5551 = 4,VG_sRGBA_4444 = 5,VG_sL_8 = 6,VG_lRGBX_8888 = 7,VG_lRGBA_8888 = 8,VG_lRGBA_8888_PRE = 9,VG_lL_8 = 10,VG_A_8 = 11,VG_BW_1 = 12
} VGImageFormat;
© Copyright Khronos Group, 2006 - Page 31
Image APIsImage APIs
• Image Handle- Handle Creation
- VGImage vgCreateImage( VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality);- Handle Destroy
- void vgDestroyImage( VGImage image );- Image Drawing
- void vgDrawImage( VGImage image );- vgSeti( VG_IMAGE_MODE, VGImageMode mode );- VG_DRAW_IMAGE_NORMAL- VG_DRAW_IMAGE_MULTIPLY- VG_DRAW_IMAGE_STENCIL
- Clear Image- void vgClearImage(VGImage image, VGint x, VGint y, VGint width, VGint height);
• Define Image Data- Append Image Data to Image Handle
- void vgImageSubData( VGImage image, const void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height);
© Copyright Khronos Group, 2006 - Page 32
Example. Draw ImageExample. Draw Image
• Draw ImageVGImage image;
extern unsigned long cimg[];
image = vgCreateImage( VG_sRGBA_8888, SCREEN_WIDTH, SCREEN_HEIGHT, VG_IMAGE_QUALITY_BETTER );
vgImageSubData( image, cimg, SCREEN_WIDTH*4, VG_sRGBA_8888, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
vgDrawImage( image );
vgDestroyImage( image );
const unsigned long cimg[] = {
0x467C55FF, 0x4B7E58FF, 0x4B805DFF, 0x4D8260FF, 0x508462FF,
……
};
© Copyright Khronos Group, 2006 - Page 33
more Image APIsmore Image APIs• Image Data Query from Image Handle
• void vgGetImageSubData (VGImage image, void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height);
• Parent & Child Image• VGImage vgChildImage (VGImage parent, VGint x, VGint y, VGint width, VGint height);• VGImage vgGetParent (VGImage image);
• Copy Image• void vgCopyImage (VGImage dst, VGint dx, VGint dy,
VGImage src, VGint sx, VGint sy, VGint width, VGint height, VGboolean dither);
• Surface vs Image• void vgSetPixels (VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height);• void vgWritePixels (const void * data, VGint dataStride, VGImageFormat dataFormat, VGint dx, VGint dy,
VGint width, VGint height);• void vgGetPixels (VGImage dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height);• void vgReadPixels (void * data, VGint dataStride, VGImageFormat dataFormat, VGint sx, VGint sy,
VGint width, VGint height);• void vgCopyPixels (VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height);
© Copyright Khronos Group, 2006 - Page 34
Stroke & Fill PaintStroke & Fill Paint
© Copyright Khronos Group, 2006 - Page 35
Paint APIsPaint APIs• Paint Handle
- Handle Creation- VGPaint vgCreatePaint( void );
- Handle Destroy- void vgDestroyPaint( VGPaint paint );
- Set Paint- Current Context- void vgSetPaint( VGPaint paint, VGbitfield paintModes );- VG_STROKE_PATH- VG_FILL_PATH
- Query Paint- VGPaint vgGetPaint( VGPaintMode paintMode );
• Paint Parameter Set/Query- void vgSetParameter{i,f, iv, fv} ( VGPaint paint, VGint paramType, ……… );- void vgGetParameter{i, f, iv, fv}( VGPaint paint, VGint paramType, ……… );
- void vgSetColor( VGPaint paint, VGuint rgba );- VGuint vgGetColor( VGPaint paint );
© Copyright Khronos Group, 2006 - Page 36
Example. Paint DefinitionExample. Paint Definition
• Paint DefinitionVGPath path;
VGPaint stroke, fill;
// To do : Path Definition
// To do : Transform Definition
vgScale( 5.0f, 5.0f );
vgSeti ( VG_FILL_RULE, VG_NON_ZERO );
stroke = vgCreatePaint();
vgSetPaint( stroke, VG_STROKE_PATH );
// To do : Stroke Paint Setting
fill = vgCreatePaint();
vgSetPaint( fill, VG_FILL_PATH );
// To do : Stroke Paint Setting
vgDrawPath( path, VG_STROKE_PATH | VG_FILL_PATH );
vgDestroyPath( path );
vgDestroyPaint( stroke );
vgDestroyPaint( fill );
© Copyright Khronos Group, 2006 - Page 37
Example. Simple Color PaintExample. Simple Color Paint
• Stroke Paint
• Fill Paint
VGfloat black[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
stroke = vgCreatePaint();
vgSetPaint( stroke, VG_STROKE_PATH );
vgSetParameteri( stroke, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR );
vgSetParameterfv( stroke, VG_PAINT_COLOR, 4, black );
fill = vgCreatePaint();
vgSetPaint( fill, VG_FILL_PATH );
vgSetParameteri( fill, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR );
vgSetColor( fill, 0xFF0000FF );
© Copyright Khronos Group, 2006 - Page 38
Example. Linear Gradient PaintExample. Linear Gradient Paint• Color Ramp Stops
• Linear Gradient Paint
VGfloat rampStops[15] = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.5f, 0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 0.0f, 1.0f };
vgSetParameterfv( fill, VG_PAINT_COLOR_RAMP_STOPS, 15, rampStops );
vgSetParameteri( fill, VG_PAINT_COLOR_RAMP_SPREAD_MODE,
VG_COLOR_RAMP_SPREAD_PAD );
VG_COLOR_RAMP_SPREAD_REPEAT
VG_COLOR_RAMP_SPREAD_REFLECT
VGfloat linearGradient[4] = { 0.0f, 0.0f, 10.0f, 10.0f };
vgSetParameterfv( fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient );
vgSetParameteri( fill, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT );
© Copyright Khronos Group, 2006 - Page 39
Example. Radial Gradient PaintExample. Radial Gradient Paint• Radial Gradient Paint
VGfloat radialGradient[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 20.0f };
vgSetParameteri( fill, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT );
vgSetParameterfv( fill, VG_PAINT_RADIAL_GRADIENT, 5, radialGradient );
vgSetParameterfv( fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient );
VGfloat radialGradient[5] = { 0.0f, 0.0f, 5.0f, 5.0f, 20.0f };
vgSetParameteri( fill, VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT );
vgSetParameterfv( fill, VG_PAINT_RADIAL_GRADIENT, 5, radialGradient );
vgSetParameterfv( fill, VG_PAINT_LINEAR_GRADIENT, 4, linearGradient );
© Copyright Khronos Group, 2006 - Page 40
Example. Pattern Image PaintExample. Pattern Image Paint• Pattern Image
- Pattern Definition
- Paint Matrix Definition
- Apply Pattern Image
VGImage image;
extern unsigned long cimg[];
image = vgCreateImage( VG_sRGBA_8888, SCREEN_WIDTH, SCREEN_HEIGHT, VG_IMAGE_QUALITY_BETTER );
vgImageSubData( image, cimg, SCREEN_WIDTH*4, VG_sRGBA_8888, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
vgSeti( VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER );
vgLoadIdentity();
vgTranslate( 0.0f, -10.0f );
vgScale( 0.1f, 0.1f );
vgSetParameteri( fill, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN );
vgSetParameteri( fill, VG_PAINT_PATTERN_TILING_MODE, VG_TILE_FILL );
VG_TILE_PAD
VG_TILE_REPEAT
VG_TILE_REFLECT
vgPaintPattern( fill, image );
© Copyright Khronos Group, 2006 - Page 41
Image FilterImage Filter
© Copyright Khronos Group, 2006 - Page 42
Image Filters APIs (1/2)Image Filters APIs (1/2)• OpenVG APIs
- Color Matrix : RGB Swap, Gray Scale, ……- void vgColorMatrix (VGImage dst, VGImage src, const VGfloat * matrix);
- Lookup Table : Invert, Darken, Lighten, Depth, ……- void vgLookup( VGImage dst, VGImage src, const VGubyte * redLUT, const VGubyte * greenLUT,
const VGubyte * blueLUT, const VGubyte * alphaLUT, VGboolean outputLinear, VGboolean outputPremultiplied);
- void vgLookupSingle( VGImage dst, VGImage src, const VGuint * lookupTable, VGImageChannel sourceChannel, VGboolean outputLinear, VGboolean outputPremultiplied);
© Copyright Khronos Group, 2006 - Page 43
Image Filters APIs (2/2)Image Filters APIs (2/2)• Using Kernel
- Convolve - void vgConvolve (VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight,
VGint shiftX, VGint shiftY, const VGshort * kernel, VGfloat scale, VGfloat bias, VGTilingMode tilingMode);
- void vgSeparableConvolve (VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernelX, const VGshort * kernelY, VGfloat scale, VGfloat bias, VGTilingMode tilingMode);
- Gaussian Blur- void vgGaussianBlur (VGImage dst, VGImage src,
VGfloat stdDeviationX, VGfloat stdDeviationY, VGTilingMode tilingMode);
© Copyright Khronos Group, 2006 - Page 44
ContactContact
Hwanyong LEEChief of Research Institutes | General Manager of Solution Division
Tel +82-53-325-4956 | Fax +82-53-325-4951
E-mail: [email protected]
HUONE INC.4F. Doge Bldg. 969-9, Dongcheon
Buk-gu, Daegu, Korea (702-250)
Tel +82-53-325-4956 | Fax +82-53-325-4951
E-mail: [email protected]
Homepage: www.hu1.com
© Copyright Khronos Group, 2006 - Page 45
Thank you!!Thank you!!
www.khronos.org/openvg
www.alexvg.com
www.khronos.org
www.hu1.com