void TiledImageOpenVG::detachTiles() { makeSharedContextCurrent(); // because we create new images int numTiles = m_tiles.size(); VGImage newTile, originalTile; for (int i = 0; i < numTiles; ++i) { originalTile = m_tiles.at(i); if (originalTile == VG_INVALID_HANDLE) continue; VGImageFormat format = (VGImageFormat) vgGetParameteri(originalTile, VG_IMAGE_FORMAT); VGint width = vgGetParameteri(originalTile, VG_IMAGE_WIDTH); VGint height = vgGetParameteri(originalTile, VG_IMAGE_HEIGHT); ASSERT_VG_NO_ERROR(); newTile = vgCreateImage(format, width, height, VG_IMAGE_QUALITY_FASTER); ASSERT_VG_NO_ERROR(); vgCopyImage(newTile, 0, 0, originalTile, 0, 0, width, height, VG_FALSE /* dither */); ASSERT_VG_NO_ERROR(); m_tiles.at(i) = newTile; } }
VGImage ResizeImage(VGImage src, int width, int height) { int orig_width = vgGetParameteri(src, VG_IMAGE_WIDTH); int orig_height = vgGetParameteri(src, VG_IMAGE_HEIGHT); printf("(%d, %d)\n", orig_width, orig_height); VGImage dst = vgCreateImage(VG_sABGR_8888, width, height, VG_IMAGE_QUALITY_BETTER); vgCopyImage(dst, 0, 0,src,0,0,width, height,0); return dst; }
static void draw(void) { const VGint w = 48; VGImage img1, img2; VGint x, y; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, window_width(), window_height()); img1 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); img2 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); x = 5; y = (window_height() - w) / 2; /* test vgSetPixels */ vgSetfv(VG_CLEAR_COLOR, 4, red); vgClearImage(img1, 0, 0, w, w / 2); vgSetfv(VG_CLEAR_COLOR, 4, black); vgClearImage(img1, 0, w / 2, w, w / 2); vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgDrawImage */ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(x, y); vgDrawImage(img1); /* test vgGetPixels */ vgGetPixels(img1, 0, 0, x, y, w, w); x += w + 5; vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgCopyImage */ vgCopyImage(img2, 0, 0, img1, 0, 0, w, w, VG_FALSE); vgSetPixels(x, y, img2, 0, 0, w, w); /* vgCopyPixels */ vgCopyPixels(x + w + 5, y, x, y, w, w); vgDestroyImage(img1); vgDestroyImage(img2); }
void* QVGPixmapData::toNativeType(NativeType type) { if (type == QPixmapData::SgImage) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) toVGImage(); if (!isValid() || vgImage == VG_INVALID_HANDLE) return 0; TInt err = 0; RSgDriver driver; err = driver.Open(); if (err != KErrNone) return 0; TSgImageInfo sgInfo; sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; sgInfo.iSizeInPixels.SetSize(w, h); sgInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface; QScopedPointer<RSgImage> sgImage(new RSgImage()); err = sgImage->Create(sgInfo, NULL, NULL); if (err != KErrNone) { driver.Close(); return 0; } const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(), EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)sgImage.data(), (EGLint*)KEglImageAttribs); if (!eglImage || eglGetError() != EGL_SUCCESS) { sgImage->Close(); driver.Close(); return 0; } VGImage dstVgImage = QVG::vgCreateEGLImageTargetKHR(eglImage); if (!dstVgImage || vgGetError() != VG_NO_ERROR) { QEgl::eglDestroyImageKHR(QEgl::display(), eglImage); sgImage->Close(); driver.Close(); return 0; } vgCopyImage(dstVgImage, 0, 0, vgImage, 0, 0, w, h, VG_FALSE); if (vgGetError() != VG_NO_ERROR) { sgImage->Close(); sgImage.reset(); } // release stuff vgDestroyImage(dstVgImage); QEgl::eglDestroyImageKHR(QEgl::display(), eglImage); driver.Close(); return reinterpret_cast<void*>(sgImage.take()); #endif } else if (type == QPixmapData::FbsBitmap && isValid()) { ensureReadback(true); if (source.isNull()) { source = QVolatileImage(w, h, sourceFormat()); } // Just duplicate the bitmap handle, no data copying happens. return source.duplicateNativeImage(); } return 0; }
void* QVGPixmapData::toNativeType(NativeType type) { if (type == QPixmapData::SgImage) { #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL) toVGImage(); if (!isValid() || vgImage == VG_INVALID_HANDLE) return 0; TInt err = 0; RSgDriver driver; err = driver.Open(); if (err != KErrNone) return 0; TSgImageInfo sgInfo; sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE; sgInfo.iSizeInPixels.SetSize(w, h); sgInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface; RSgImage *sgImage = q_check_ptr(new RSgImage()); err = sgImage->Create(sgInfo, NULL, NULL); if (err != KErrNone) { driver.Close(); return 0; } pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR"); if (eglGetError() != EGL_SUCCESS || !(QEgl::hasExtension("EGL_KHR_image") || QEgl::hasExtension("EGL_KHR_image_pixmap")) || !vgCreateEGLImageTargetKHR) { driver.Close(); return 0; } const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE}; EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(), EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)sgImage, (EGLint*)KEglImageAttribs); if (eglGetError() != EGL_SUCCESS) { sgImage->Close(); driver.Close(); return 0; } VGImage dstVgImage = vgCreateEGLImageTargetKHR(eglImage); if (vgGetError() != VG_NO_ERROR) { QEgl::eglDestroyImageKHR(QEgl::display(), eglImage); sgImage->Close(); driver.Close(); return 0; } vgCopyImage(dstVgImage, 0, 0, vgImage, 0, 0, w, h, VG_FALSE); if (vgGetError() != VG_NO_ERROR) { sgImage->Close(); sgImage = 0; } // release stuff vgDestroyImage(dstVgImage); QEgl::eglDestroyImageKHR(QEgl::display(), eglImage); driver.Close(); return reinterpret_cast<void*>(sgImage); #endif } else if (type == QPixmapData::FbsBitmap) { CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap); if (bitmap) { if (bitmap->Create(TSize(source.width(), source.height()), EColor16MAP) == KErrNone) { const uchar *sptr = source.constBits(); bitmap->BeginDataAccess(); uchar *dptr = (uchar*)bitmap->DataAddress(); Mem::Copy(dptr, sptr, source.byteCount()); bitmap->EndDataAccess(); } else { delete bitmap; bitmap = 0; } } return reinterpret_cast<void*>(bitmap); } return 0; }
/******************************************************************************* * Function Name : InitView * Returns : true if no error occured * Description : Code in InitView() will be called by the Shell upon a change * in the rendering context. * Used to initialise variables that are dependent on the rendering * context (e.g. textures, vertex buffers, etc.) *******************************************************************************/ bool CImage::InitView() { //Create a pair of images m_avgImage[0] = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED); m_avgImage[1] = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED); /* The first image will be populated from memory. A 32bit integer array (8bits per component) is created and populated. */ VGuint* pui32ImgData = new VGuint[IMG_SIZE * IMG_SIZE]; for (int i = 0; i < IMG_SIZE; ++i) { for (int j = 0; j < IMG_SIZE; ++j) { // Fills the data with a fancy pattern if ( ((i*j)/8) % 2 ) pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255,255,0,255); else pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255, 255 - (j * 2), 255 - i, 255 - (i * 2)); } } /* The data in the array is then copied to the portion of the image starting at (0,0) through to (IMG_SIZE, IMG_SIZE), in this case that is the whole image. The coordinate system of the image places (0,0) at the bottom left-hand corner and (IMG_SIZE, IMG_SIZE) at the top right-hand corner. */ vgImageSubData(m_avgImage[0],pui32ImgData, sizeof(VGuint) * IMG_SIZE,VG_sRGBA_8888, 0, 0, IMG_SIZE, IMG_SIZE); // Delete the image data as it is now in OpenVG memory delete[] pui32ImgData; pui32ImgData = 0; /* The second image will initially be cleared to a single colour and then a part of the first image will be copied to it. */ //The colour to clear the image to is taken from the currently set VG_CLEAR_COLOR. VGfloat afClearColour[] = { 1.0f, 0.8f, 0.6f, 1.0f }; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); //Clear the part of the image in the range (0,0) to (IMG_SIZE, IMG_SIZE), in this case that is the whole image. vgClearImage(m_avgImage[1], 0, 0, IMG_SIZE, IMG_SIZE); /* Copy the bottom left-hand corner ((0,0) to (IMG_SIZE / 2, IMG_SIZE / 2)) of the first image into the the second image starting at (IMG_SIZE / 4, IMG_SIZE / 4). */ int i32ImgSizeQuarter = (int) (IMG_SIZE * 0.25); vgCopyImage(m_avgImage[1], i32ImgSizeQuarter, i32ImgSizeQuarter, m_avgImage[0], 0,0, (VGint) (IMG_SIZE * 0.5), (VGint) (IMG_SIZE * 0.5), (VGboolean) false); //Set the clear colour for clearing the sceen afClearColour[0] = 0.6f; afClearColour[1] = 0.8f; afClearColour[2] = 1.0f; afClearColour[3] = 1.0f; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight)); return true; }