Exemple #1
0
static void
draw(void)
{
    VGint WINDSIZEX = window_width();
    VGint WINDSIZEY = window_height();

    VGPaint fill;
    VGPath box;
    VGfloat color[4]		= {1.f, 0.f, 0.f, 1.f};
    VGfloat bgCol[4]		= {0.7f, 0.7f, 0.7f, 1.0f};
    VGfloat transCol[4]         = {0.f, 0.f, 0.f, 0.f};
    VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height,
                                  VG_IMAGE_QUALITY_NONANTIALIASED);

    /* Background clear */
    fill = vgCreatePaint();
    vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
    vgSetPaint(fill, VG_FILL_PATH);

    box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
                       1, 0, 0, 0, VG_PATH_CAPABILITY_ALL);
    /* Rectangle to cover completely 16x16 pixel area. */
    RectToPath(box, 0, 0, 64, 64);

    vgSetfv(VG_CLEAR_COLOR, 4, transCol);
    vgClearImage(image, 0, 0, img_width, img_height);
    vgSetfv(VG_CLEAR_COLOR, 4, color);
    vgClearImage(image, 10, 10, 12, 12);
    //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride,
    //               VG_sRGBA_8888, 0, 0, 32, 32);
    vgSeti(VG_MASKING, VG_TRUE);
    vgLoadIdentity();

    vgSetfv(VG_CLEAR_COLOR, 4, bgCol);
    vgClear(0, 0, WINDSIZEX, WINDSIZEY);


    vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height());
    vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100);

    vgDrawPath(box, VG_FILL_PATH);

    //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
    //vgTranslate(-10, -10);
    //vgDrawImage(image);


    vgDestroyPaint(fill);
    vgDestroyPath(box);
}
Exemple #2
0
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);
}
TBool CHuiFxVg10BlurFilter::Draw(CHuiFxEngine& aEngine, CHuiGc& /* aGc */, CHuiFxRenderbuffer& aTarget,
                                 CHuiFxRenderbuffer& aSource, const TRect& aTargetRect, const TRect& aSourceRect, TBool aHasSurface)
    {
    aTarget.BindAsTexture(ERenderbufferUsageWriteOnly);
    aSource.BindAsTexture(ERenderbufferUsageReadOnly);
    VGImage srcImage  = (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aSource))->AcquireSubImage(aSourceRect);
    VGImage destImage = (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aTarget))->AcquireSubImage(aTargetRect);
    
    // take opacity into account
    const VGfloat opacity = clamp(iOpacity, 0.0f, 1.0f);

    if(opacity > EPSILON)
        {
        DrawEffect(aEngine, destImage, srcImage, aSourceRect.Width(), aSourceRect.Height(), aHasSurface);
        }
    else
        {
//        VGint width = vgGetParameteri(srcImage, VG_IMAGE_WIDTH);
//        VGint height = vgGetParameteri(srcImage, VG_IMAGE_HEIGHT);
        VGint width = aSourceRect.Width();
        VGint height = aSourceRect.Height();
        vgClearImage(destImage, 0, 0, width, height);
        }

    HUIFX_VG_INVARIANT();    
    (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aSource))->ReleaseSubImage(srcImage);
    (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(&aTarget))->ReleaseSubImage(destImage);
    aTarget.UnbindAsTexture();
    aSource.UnbindAsTexture();
    
    return wasEnoughMemory();
    }
void CHuiVg10CanvasGc::DoClearRenderBuffer( CHuiCanvasRenderBuffer& aImage, const TRect & aRect )
    {
    HUIFX_VG_INVARIANT();   
    const CHuiVg10CanvasRenderBuffer* vg10RenderBuffer = (const CHuiVg10CanvasRenderBuffer*) &aImage;    

    const TInt COLOR_COMPONENTS = 4;
    VGfloat savedColor[COLOR_COMPONENTS];
    vgGetfv(VG_CLEAR_COLOR, COLOR_COMPONENTS, savedColor);
    
    VGfloat color[COLOR_COMPONENTS] = 
                {
                 0.0f, 0.0f, 0.0f, 0.0f
                };
    vgSetfv(VG_CLEAR_COLOR, COLOR_COMPONENTS, color);
    vgClearImage(vg10RenderBuffer->Image(), aRect.iTl.iX, aRect.iTl.iY, aRect.Size().iWidth, aRect.Size().iHeight);
    vgSetfv(VG_CLEAR_COLOR, COLOR_COMPONENTS, savedColor);
    HUIFX_VG_INVARIANT();   
    }
Exemple #5
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 CChildImage::InitView()
{
	//Create an image
	m_vgImage = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED);

	/*
	Populate the image 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_vgImage, 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;

	//Create child images

	/*
	The first child is a child of m_vgImage and is made up of the region of m_vgImage from (0,0) to (IMG_SIZE / 2, IMG_SIZE / 2).
	Note: The area specified must be in the bounds of the parent.
	*/
	m_avgChildImages[0] = vgChildImage(m_vgImage,  0, 0, (VGint) (IMG_SIZE * 0.5), (VGint) (IMG_SIZE * 0.5));

	//The second child is a clone of the first child.

	//Get the dimensions of the first child..
	int i32ChildWidth = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_WIDTH);
	int i32ChildHeight= vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT);

	//..and use them to define the region for creating the second child.
	m_avgChildImages[1] = vgChildImage(m_avgChildImages[0],  0, 0, i32ChildWidth,  i32ChildHeight);

	/*
	Clear a small portion of the bottom left-hand corner of m_avgChildImages[0] to red.
	This change will be seen in all relatives of m_avgChildImages[0], reason being they
	all share the same physical memory.

	Note:

	When clearing you specify the coordinate you want to start from and then how many pixels
	across and up you want to clear.
	*/
	VGfloat afClearColour[] = {1.0f, 0.0f, 0.0f, 1.0f};
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);
	vgClearImage(m_avgChildImages[0], 0, 0, 10, 10);

	//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;
}
Exemple #6
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;
}