// 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); // set channel masks vgSeti(VG_FILTER_CHANNEL_MASK, VG_RED | VG_GREEN | VG_BLUE | VG_ALPHA); vgSeti(VG_FILTER_FORMAT_LINEAR, VG_TRUE); vgSeti(VG_FILTER_FORMAT_PREMULTIPLIED, VG_FALSE); // generate a non-premultiplied palatte for (i = 0; i < 256; ++i) { redLUT[i] = (VGubyte)(127.0f * cos(2 * (i * 6.2831f / 256.0f)) + 127.5f); greenLUT[i] = (VGubyte)(127.0f * cos(1 * (i * 6.2831f / 256.0f)) + 127.5f); blueLUT[i] = (VGubyte)(127.0f * sin(3 * (i * 6.2831f / 256.0f)) + 127.5f); alphaLUT[i] = i; } // lookup filter, in linear non-premultiplied color space vgLookup(imgDst, imgSrc, redLUT, greenLUT, blueLUT, alphaLUT, VG_TRUE, VG_FALSE); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_lookup_l.png"); saveImage32(f, imgFileName, "Lookup filter, in linear non-premultiplied color space.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // lookup filter, in non-linear non-premultiplied color space vgLookup(imgDst, imgSrc, redLUT, greenLUT, blueLUT, alphaLUT, VG_FALSE, VG_FALSE); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_lookup_s.png"); saveImage32(f, imgFileName, "Lookup filter, in non-linear non-premultiplied color space.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // generate a premultiplied palatte for (i = 0; i < 256; ++i) { alphaLUT[i] = i; redLUT[i] = (VGubyte)(alphaLUT[i] * (127.0f * cos(2 * (i * 6.2831f / 256.0f)) + 127.5f) / 255.0f); greenLUT[i] = (VGubyte)(alphaLUT[i] * (127.0f * cos(1 * (i * 6.2831f / 256.0f)) + 127.5f) / 255.0f); blueLUT[i] = (VGubyte)(alphaLUT[i] * (127.0f * sin(3 * (i * 6.2831f / 256.0f)) + 127.5f) / 255.0f); } // lookup filter, in linear premultiplied color space vgLookup(imgDst, imgSrc, redLUT, greenLUT, blueLUT, alphaLUT, VG_TRUE, VG_TRUE); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_lookup_lpre.png"); saveImage32(f, imgFileName, "Lookup filter, in linear non-premultiplied color space.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // lookup filter, in non-linear premultiplied color space vgLookup(imgDst, imgSrc, redLUT, greenLUT, blueLUT, alphaLUT, VG_FALSE, VG_TRUE); vgGetImageSubData(imgDst, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "filter_lookup_spre.png"); saveImage32(f, imgFileName, "Lookup filter, in non-linear non-premultiplied color space.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); vgDestroyImage(imgSrc); vgDestroyImage(imgDst);