vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER); vgSeti(VG_SCISSORING, VG_FALSE); vgSeti(VG_MASKING, VG_TRUE); // create a path path0 = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); vguRect(path0, 10.0f, 10.0f, 236.0f, 236.0f); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); // create and set a paint for fill fillPaint = vgCreatePaint(); vgSetParameteri(fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); col[0] = 0.5f; col[1] = 0.5f; col[2] = 1.0f; col[3] = 1.0f; vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, col); vgSetPaint(fillPaint, VG_FILL_PATH); // set clear color col[0] = 1.0f; col[1] = 1.0f; col[2] = 1.0f; col[3] = 1.0f; vgSetfv(VG_CLEAR_COLOR, 4, col); #if defined(OPENVG_VERSION_1_1) for (j = VG_sRGBX_8888; j <= VG_A_4; ++j) { #else for (j = VG_sRGBX_8888; j <= VG_BW_1; ++j) { #endif char filePrefix[128]; char descPostfix[128]; // create image and load external data imgSrc = vgCreateImage((VGImageFormat)j, imgBarbaraAlphaWidth, imgBarbaraAlphaHeight, VG_IMAGE_QUALITY_NONANTIALIASED); vgImageSubData(imgSrc, (const void *)&imgBarbaraAlphaData[imgBarbaraAlphaWidth * (imgBarbaraAlphaHeight - 1)], -imgBarbaraAlphaDataStride, imgBarbaraAlphaFormat, 0, 0, imgBarbaraAlphaWidth, imgBarbaraAlphaHeight); imgTmp = vgCreateImage((VGImageFormat)j, imgBarbaraAlphaWidth, imgBarbaraAlphaHeight, VG_IMAGE_QUALITY_NONANTIALIASED); vgImageSubData(imgTmp, (const void *)imgBarbaraAlphaData, imgBarbaraAlphaDataStride, imgBarbaraAlphaFormat, 0, 0, imgBarbaraAlphaWidth, imgBarbaraAlphaHeight); strcpy(filePrefix, "vgmasking_"); strcat(filePrefix, imageFormatToString((VGImageFormat)j)); strcpy(descPostfix, " using a "); strcat(descPostfix, imageFormatToString((VGImageFormat)j)); strcat(descPostfix, " image."); // test CLEAR operation vgClear(0, 0, 256, 256); vgMask(imgSrc, VG_SET_MASK, 0, 0, 256, 256); vgMask(VG_INVALID_HANDLE, VG_CLEAR_MASK, -128, -128, 256, 256); vgDrawPath(path0, VG_FILL_PATH); strcpy(imgFileName, filePrefix); strcat(imgFileName, "_clear.png"); strcpy(testDesc, "vgMask CLEAR operation"); strcat(testDesc, descPostfix); saveDrawingSurface(f, imgFileName, testDesc, 0, 0, 256, 256); eglSwapBuffers(display, surface); // test FILL operation vgClear(0, 0, 256, 256); vgMask(imgSrc, VG_SET_MASK, 0, 0, 256, 256); vgMask(VG_INVALID_HANDLE, VG_FILL_MASK, 128, 128, 256, 256); vgDrawPath(path0, VG_FILL_PATH); strcpy(imgFileName, filePrefix); strcat(imgFileName, "_fill.png"); strcpy(testDesc, "vgMask FILL operation"); strcat(testDesc, descPostfix); saveDrawingSurface(f, imgFileName, testDesc, 0, 0, 256, 256); eglSwapBuffers(display, surface); // test SET operation vgClear(0, 0, 256, 256); vgMask(imgSrc, VG_SET_MASK, 0, 0, 256, 256); vgMask(imgTmp, VG_SET_MASK, -128, 0, 256, 256); vgDrawPath(path0, VG_FILL_PATH); strcpy(imgFileName, filePrefix); strcat(imgFileName, "_set.png"); strcpy(testDesc, "vgMask SET operation"); strcat(testDesc, descPostfix); saveDrawingSurface(f, imgFileName, testDesc, 0, 0, 256, 256); eglSwapBuffers(display, surface); // test UNION operation vgClear(0, 0, 256, 256); vgMask(imgSrc, VG_SET_MASK, 0, 0, 256, 256); vgMask(imgTmp, VG_UNION_MASK, 0, 0, 256, 256); vgDrawPath(path0, VG_FILL_PATH); strcpy(imgFileName, filePrefix); strcat(imgFileName, "_union.png"); strcpy(testDesc, "vgMask UNION operation"); strcat(testDesc, descPostfix); saveDrawingSurface(f, imgFileName, testDesc, 0, 0, 256, 256); eglSwapBuffers(display, surface); // test INTERSECT operation vgClear(0, 0, 256, 256); vgMask(imgSrc, VG_SET_MASK, 0, 0, 256, 256); vgMask(imgTmp, VG_INTERSECT_MASK, 0, 0, 256, 256); vgDrawPath(path0, VG_FILL_PATH); strcpy(imgFileName, filePrefix); strcat(imgFileName, "_intersect.png"); strcpy(testDesc, "vgMask INTERSECT operation"); strcat(testDesc, descPostfix); saveDrawingSurface(f, imgFileName, testDesc, 0, 0, 256, 256); eglSwapBuffers(display, surface); // test SUBTRACT operation vgClear(0, 0, 256, 256); vgMask(imgSrc, VG_SET_MASK, 0, 0, 256, 256); vgMask(imgTmp, VG_SUBTRACT_MASK, 0, 0, 256, 256); vgDrawPath(path0, VG_FILL_PATH); strcpy(imgFileName, filePrefix); strcat(imgFileName, "_subtract.png"); strcpy(testDesc, "vgMask SUBTRACT operation"); strcat(testDesc, descPostfix); saveDrawingSurface(f, imgFileName, testDesc, 0, 0, 256, 256); eglSwapBuffers(display, surface); vgDestroyImage(imgSrc); vgDestroyImage(imgTmp); } vgDestroyPath(path0); vgDestroyPaint(fillPaint);