PassRefPtr<ImageData> ImageBufferData::getImageData(const IntRect& rect, const IntSize& size, VGImageFormat format) const { ASSERT(m_surface); PassRefPtr<ImageData> result = ImageData::create(rect.width(), rect.height()); unsigned char* data = result->data()->data()->data(); // If this copy operation won't fill all of the pixels in the target image, // paint it black in order to avoid random uninitialized pixel garbage. if (rect.x() < 0 || rect.y() < 0 || (rect.right()) > size.width() || (rect.bottom()) > size.height()) memset(data, 0, result->data()->length()); if (!m_tiledImage) m_surface->makeCurrent(); // OpenVG ignores pixels that are out of bounds, so we can just // call vgReadPixels() without any further safety assurances. if (m_surface->isCurrent()) { vgReadPixels(data, rect.width() * 4, format, rect.x(), rect.y(), rect.width(), rect.height()); } else { vgGetImageSubData(m_tiledImage->tile(0, 0), data, rect.width() * 4, format, rect.x(), rect.y(), rect.width(), rect.height()); } ASSERT_VG_NO_ERROR(); return result; }
void ImageBufferData::transformColorSpace(const Vector<int>& lookUpTable) { ASSERT(m_surface); VGint width = m_surface->width(); VGint height = m_surface->height(); VGubyte* data = new VGubyte[width * height * 4]; VGubyte* currentPixel = data; m_surface->makeCurrent(); vgReadPixels(data, width * 4, IMAGEBUFFER_VG_EXCHANGE_FORMAT, 0, 0, width, height); ASSERT_VG_NO_ERROR(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; currentPixel += 4, x++) { currentPixel[IMAGEBUFFER_A] = lookUpTable[currentPixel[IMAGEBUFFER_A]]; currentPixel[IMAGEBUFFER_R] = lookUpTable[currentPixel[IMAGEBUFFER_R]]; currentPixel[IMAGEBUFFER_G] = lookUpTable[currentPixel[IMAGEBUFFER_G]]; currentPixel[IMAGEBUFFER_B] = lookUpTable[currentPixel[IMAGEBUFFER_B]]; } } vgWritePixels(data, width * 4, IMAGEBUFFER_VG_EXCHANGE_FORMAT, 0, 0, width, height); ASSERT_VG_NO_ERROR(); delete[] data; }
void CTReadWriteChild::ReadFuncL() { vgDrawImage(iImage); vgReadPixels(iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight); VgLeaveIfErrorL(); //Small delay to aid pixel access sharing between processes User::After(TTimeIntervalMicroSeconds32(1000)); }
static void draw(void) { static const VGint red_pixel = 255 << 24 | 255 << 16 | 0 << 8 | 0; static const VGint blue_pixel = 255 << 24 | 0 << 16 | 0 << 8 | 255; VGint i; vgSetfv(VG_CLEAR_COLOR, 4, red_color); vgClear(0, 0, window_width(), window_height()); vgFlush(); memset(data, 0, window_width() * window_height() * sizeof(VGint)); vgReadPixels(data, window_width() * sizeof(VGint), VG_lARGB_8888, 0, 0, window_width(), window_height()); fprintf(stderr, "Red 0 = 0x%x and at 600 = 0x%x\n", data[0], data[600]); for (i = 0; i < window_width() * window_height(); ++i) { assert(data[i] == red_pixel); } vgSetfv(VG_CLEAR_COLOR, 4, blue_color); vgClear(50, 50, 50, 50); vgFlush(); memset(data, 0, window_width() * window_height() * sizeof(VGint)); vgReadPixels(data, 50 * sizeof(VGint), VG_lARGB_8888, 50, 50, 50, 50); fprintf(stderr, "Blue 0 = 0x%x and at 100 = 0x%x\n", data[0], data[100]); for (i = 0; i < 50 * 50; ++i) { assert(data[i] == blue_pixel); } }
void takeScreenshot(int frame, int line) { if (!windowWidth || !windowHeight) { return; } #if defined(TAKE_SCREENSHOTS) && defined(USE_VG) char* image = (char*)malloc(windowWidth * windowHeight * 4); char fn[512]; FILE* f; assert(image); sprintf(fn, "trace_%dx%d_%04d_%d.raw", windowWidth, windowHeight, frame, line); f = fopen(fn, "wb"); assert(f); vgReadPixels(image + windowWidth * (windowHeight - 1) * 4, -windowWidth * 4, VG_sABGR_8888, 0, 0, windowWidth, windowHeight); fwrite(image, 1, windowWidth * windowHeight * 4, f); fclose(f); free(image); #elif defined(TAKE_SCREENSHOTS) && (defined(USE_GLES2) || defined(USE_GLES)) char* image = (char*)malloc(windowWidth * windowHeight * 4); char fn[512]; FILE* f; assert(image); sprintf(fn, "trace_%dx%d_%04d_%d.raw", windowWidth, windowHeight, frame, line); f = fopen(fn, "wb"); assert(f); glReadPixels(0, 0, windowWidth, windowHeight, GL_RGBA, GL_UNSIGNED_BYTE, image); fwrite(image, 1, windowWidth * windowHeight * 4, f); fclose(f); free(image); #endif }
// dumpscreen writes the raster void dumpscreen(int w, int h, FILE * fp) { void *ScreenBuffer = malloc(w * h * 4); vgReadPixels(ScreenBuffer, (w * 4), VG_sABGR_8888, 0, 0, w, h); fwrite(ScreenBuffer, 1, w * h * 4, fp); free(ScreenBuffer); }
/*!*********************************************************************** @Function ApiScreenCaptureBuffer @Input Width Width of the region to capture @Input Height Height of the region to capture @Input pBuf A buffer to put the screen capture into @description API-specific function to store the current content of the FrameBuffer into the memory allocated by the user. *************************************************************************/ bool PVRShellInit::ApiScreenCaptureBuffer(int Width,int Height,unsigned char *pBuf) { unsigned char *pLines2; int i, j; bool bRet = true; #ifdef BUILD_OVG if(eglQueryAPI() != EGL_OPENVG_API) { m_pShell->PVRShellOutputDebug("PVRShell: Screen capture failed. OpenVG is not the current API"); return false; } #endif /* Allocate memory for line */ pLines2 = (unsigned char *)calloc(4 * Width * Height, sizeof(unsigned char)); if (!pLines2) return false; #ifdef BUILD_OVG while (vgGetError()); vgReadPixels(pLines2, Width * 4, VG_sRGBA_8888, 0, 0, Width, Height); if(vgGetError()) { bRet = false; } else { /* Convert RGB to BGR in line */ for (j = 0, i = 0; j < 4 * Width * Height; j += 4, i += 3) { pBuf[i] = pLines2[j+1]; pBuf[i+1] = pLines2[j+2]; pBuf[i+2] = pLines2[j+3]; } } #else while (glGetError()); /* Read line from frame buffer */ glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pLines2); if(glGetError()) { bRet = false; } else { /* Convert RGB to BGR in line */ for (j = 0, i = 0; j < 4 * Width * Height; j += 4, i += 3) { pBuf[i] = pLines2[j+2]; pBuf[i+1] = pLines2[j+1]; pBuf[i+2] = pLines2[j]; } } #endif free(pLines2); return bRet; }
void BackingStoreScrollbar::repaint(const WebCore::IntRect& hotRect, bool vertical) { SurfaceOpenVG* surface = SurfacePool::globalSurfacePool()->tileRenderingSurface(); const IntSize surfaceSize(surface->width(), surface->height()); PainterOpenVG painter(surface); // If the rendering surface is smaller than the scrollbar // (e.g. when the screen is rotated), paint it multiple times. int lastXTile = (m_size.width() - 1) / surfaceSize.width(); int lastYTile = (m_size.height() - 1) / surfaceSize.height(); FloatRect innerRect = hotRect; innerRect.move(0.5, 0.5); // draw it pixel-perfect with a 1.0 wide stroke int radius = vertical ? hotRect.width() / 2 : hotRect.height() / 2; if (vertical) innerRect.inflateY(-radius); else innerRect.inflateX(-radius); Path path; if (vertical) { path.moveTo(FloatPoint(innerRect.x(), innerRect.y())); path.addArc(FloatPoint(innerRect.x() + radius, innerRect.y()), radius, piFloat, 0, false); path.addLineTo(FloatPoint(innerRect.right(), innerRect.bottom())); path.addArc(FloatPoint(innerRect.x() + radius, innerRect.bottom()), radius, 0, piFloat, false); path.closeSubpath(); } else { path.moveTo(FloatPoint(innerRect.right(), innerRect.y())); path.addArc(FloatPoint(innerRect.right(), innerRect.y() + radius), radius, piFloat + piFloat / 2, piFloat / 2, false); path.addLineTo(FloatPoint(innerRect.x(), innerRect.bottom())); path.addArc(FloatPoint(innerRect.x(), innerRect.y() + radius), radius, piFloat / 2, piFloat + piFloat / 2, false); path.closeSubpath(); } for (int i = 0; i <= lastXTile; ++i) { for (int j = 0; j <= lastYTile; ++j) { const int dstX = i * surfaceSize.width(); const int dstY = j * surfaceSize.height(); const int dstRight = (i == lastXTile) ? m_size.width() : (i + 1) * surfaceSize.width(); const int dstBottom = (j == lastYTile) ? m_size.height() : (j + 1) * surfaceSize.height(); painter.translate(rect().x(), rect().y()); if (dstX || dstY) painter.translate(-dstX, -dstY); // Paint the actual scrollbar. painter.setFillColor(Color(255, 255, 255)); painter.drawRect(IntRect(IntPoint(0, 0), rect().size()), VG_FILL_PATH); painter.setFillColor(Color(173, 176, 178)); painter.drawPath(path, VG_FILL_PATH, WebCore::RULE_NONZERO); surface->makeCurrent(); unsigned char* dstBufferStart = m_image + (dstY * imageStride()) + (dstX * imageBytesPerPixel()); vgReadPixels(dstBufferStart, imageStride(), VG_sRGB_565, 0, 0, dstRight - dstX, dstBottom - dstY); ASSERT_VG_NO_ERROR(); // Paint the alpha channel for the actual scrollbar. painter.setCompositeOperation(CompositeClear); painter.setFillColor(Color(0, 0, 0)); painter.drawRect(IntRect(IntPoint(0, 0), rect().size()), VG_FILL_PATH); painter.setCompositeOperation(CompositeSourceOver); painter.setFillColor(Color(255, 255, 255)); painter.drawPath(path, VG_FILL_PATH, WebCore::RULE_NONZERO); surface->makeCurrent(); // FIXME: We need VG_A_4 until proper alpha blending is available. // When we get 8-bit formats, make sure to adapt both the format // and remove the division by two when determining the dstAlphaBufferStart. unsigned char* dstAlphaBufferStart = m_alphaImage + (dstY * alphaImageStride()) + dstX / 2; vgReadPixels(dstAlphaBufferStart, alphaImageStride(), VG_A_4, 0, 0, dstRight - dstX, dstBottom - dstY); ASSERT_VG_NO_ERROR(); if (dstX || dstY) painter.translate(dstX, dstY); } } }
void platformBlitToWindow(EGLSurfaceImpl* surface) { WindowContext* context = static_cast<WindowContext*>(surface->windowContext()); if (!context || !surface) return; int width = surface->width(); int height = surface->height(); if (!context->m_buffer || !context->m_bitmap || context->m_width != width || context->m_height != height) { if (context->m_bitmap) { ::DeleteObject(context->m_bitmap); context->m_bitmap = 0; } context->m_buffer = 0; context->m_width = width; context->m_height = height; struct { BITMAPINFOHEADER header; DWORD rMask; DWORD gMask; DWORD bMask; } bmi; memset(&bmi, 0, sizeof(bmi)); bmi.header.biSize = sizeof(BITMAPINFOHEADER); bmi.header.biWidth = width; bmi.header.biHeight = height; bmi.header.biPlanes = 1; bmi.header.biBitCount = static_cast<WORD>(32); bmi.header.biCompression = BI_BITFIELDS; bmi.rMask = 0x000000ff; bmi.gMask = 0x0000ff00; bmi.bMask = 0x00ff0000; context->m_bitmap = ::CreateDIBSection( context->m_bitmapDC, reinterpret_cast<BITMAPINFO*>(&bmi), DIB_RGB_COLORS, reinterpret_cast<void**>(&context->m_buffer), NULL, 0); if (!context->m_bitmap) { context->m_buffer = 0; return; } } if (context->m_buffer) { ::GdiFlush(); VGImageFormat format = VG_sXBGR_8888; // Little endian. vgReadPixels(context->m_buffer, width * sizeof(unsigned int), format, 0, 0, width, height); ::SelectObject(context->m_bitmapDC, context->m_bitmap); HDC winDC = ::GetDC(context->m_window); ::BitBlt(winDC, 0, 0, width, height, context->m_bitmapDC, 0, 0, SRCCOPY); ::ReleaseDC(context->m_window, winDC); ::SelectObject(context->m_bitmapDC, NULL); } }