#define SWAP_IMAGES(idx0, idx1) \ vgCopyImage(tmpImage, 0, 0, imgChildren[idx0], 0, 0, 64, 64, VG_FALSE); \ vgCopyImage(imgChildren[idx0], 0, 0, imgChildren[idx1], 0, 0, 64, 64, VG_FALSE); \ vgCopyImage(imgChildren[idx1], 0, 0, tmpImage, 0, 0, 64, 64, VG_FALSE); // 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); // create a temporary image, used for swap tmpImage = vgCreateImage(VG_lRGBA_8888, 64, 64, VG_IMAGE_QUALITY_NONANTIALIASED); k = 0; for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) imgChildren[k++] = vgChildImage(imgSrc, j * 64, i * 64, 64, 64); SWAP_IMAGES(0, 13) SWAP_IMAGES(7, 8) SWAP_IMAGES(5, 15) SWAP_IMAGES(10, 3) SWAP_IMAGES(2, 14) SWAP_IMAGES(1, 4) SWAP_IMAGES(6, 12) SWAP_IMAGES(9, 11) imgParent = vgGetParent(imgChildren[8]); vgGetImageSubData(imgParent, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "image_children_swap.png"); saveImage32(f, imgFileName, "Create and swap 16 child images.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // clear a new child image imgChildren[16] = vgChildImage(imgSrc, 64, 64, 128, 128); col[0] = 0.1f; col[1] = 0.3f; col[2] = 0.7f; col[3] = 1.0f; vgSetfv(VG_CLEAR_COLOR, 4, col); vgClearImage(imgChildren[16], -32, -32, 192, 192); imgParent = vgGetParent(imgChildren[16]); vgGetImageSubData(imgParent, imgOutputDataRGBA, imgGirlAlphaDataStride, imgGirlAlphaFormat, 0, 0, imgGirlAlphaWidth, imgGirlAlphaHeight); strcpy(imgFileName, "image_children_clear.png"); saveImage32(f, imgFileName, "Clear a child image.", imgGirlAlphaWidth, imgGirlAlphaHeight, imgOutputDataRGBA, 0); // destroy images for (k = 0; k < 17; ++k) vgDestroyImage(imgChildren[k]); vgDestroyImage(imgSrc); vgDestroyImage(tmpImage); #undef SWAP_IMAGES