// create image and load external data imgSrc = vgCreateImage(VG_lRGBA_8888, imgGirlAlphaWidth, imgGirlAlphaHeight, VG_IMAGE_QUALITY_NONANTIALIASED); vgImageSubData(imgSrc, (const void *)imgGirlAlphaData, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); imgDst = vgCreateImage(VG_lRGBA_8888, imgGirlAlphaWidth, imgGirlAlphaHeight, VG_IMAGE_QUALITY_NONANTIALIASED); // create a 5x5 kernel matrix kernel[0] = -5; kernel[5] = -3; kernel[10] = -2; kernel[15] = 0; kernel[20] = 0; kernel[1] = -3; kernel[6] = -2; kernel[11] = -1; kernel[16] = 0; kernel[21] = 0; kernel[2] = -2; kernel[7] = -1; kernel[12] = 1; kernel[17] = 1; kernel[22] = 2; kernel[3] = 0; kernel[8] = 0; kernel[13] = 1; kernel[18] = 2; kernel[23] = 3; kernel[4] = 0; kernel[9] = 0; kernel[14] = 2; kernel[19] = 3; kernel[24] = 5; // set channel masks and a border color vgSeti(VG_FILTER_CHANNEL_MASK, VG_RED | VG_GREEN | VG_BLUE | VG_ALPHA); col[0] = 0.12f; col[1] = 0.35f; col[2] = 0.75f; col[3] = 1.0f; vgSetfv(VG_TILE_FILL_COLOR, 4, col); vgSeti(VG_FILTER_FORMAT_LINEAR, VG_TRUE); vgSeti(VG_FILTER_FORMAT_PREMULTIPLIED, VG_FALSE); // basic centered convolve filter vgConvolve(imgDst, imgSrc, 5, 5, 2, 2, kernel, 1.0f / 1.0f, 0.0f, VG_TILE_FILL); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_convolve.png"); saveImage32(f, imgFileName, "Basic centered convolve filter.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // decentered convolve filter, with tile fill vgConvolve(imgDst, imgSrc, 5, 5, 128, -128, kernel, 1.0f / 1.0f, 0.0f, VG_TILE_FILL); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_convolve_fill.png"); saveImage32(f, imgFileName, "Decentered convolve filter, with tile fill.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // decentered convolve filter, with tile pad vgConvolve(imgDst, imgSrc, 5, 5, 128, -128, kernel, 1.0f / 1.0f, 0.0f, VG_TILE_PAD); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_convolve_pad.png"); saveImage32(f, imgFileName, "Decentered convolve filter, with tile pad.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // decentered convolve filter, with tile repeat vgConvolve(imgDst, imgSrc, 5, 5, 128, -128, kernel, 1.0f / 1.0f, 0.0f, VG_TILE_REPEAT); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_convolve_repeat.png"); saveImage32(f, imgFileName, "Decentered convolve filter, with tile repeat.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // decentered convolve filter, with tile reflect vgConvolve(imgDst, imgSrc, 5, 5, 128, -128, kernel, 1.0f / 1.0f, 0.0f, VG_TILE_REFLECT); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_convolve_reflect.png"); saveImage32(f, imgFileName, "Decentered convolve filter, with tile reflect.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); vgDestroyImage(imgSrc); vgDestroyImage(imgDst);