uiacceltk/hitchcock/coretoolkit/rendervg10/src/HuiFxVg10BevelFilter.cpp
changeset 0 15bf7259bb7c
child 29 ac3859d43844
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "HuiFxVg10BevelFilter.h"
       
    21 #include "HuiFxVg10RenderbufferBase.h"
       
    22 #include "HuiFxConstants.h"
       
    23 
       
    24 CHuiFxVg10BevelFilter* CHuiFxVg10BevelFilter::NewL()
       
    25     {
       
    26     CHuiFxVg10BevelFilter* self = new (ELeave) CHuiFxVg10BevelFilter();
       
    27     CleanupStack::PushL( self );
       
    28     self->ConstructL();
       
    29     CleanupStack::Pop( self );
       
    30     return self;
       
    31     }
       
    32 
       
    33 void CHuiFxVg10BevelFilter::ConstructL()
       
    34     {
       
    35     CHuiFxFilter::ConstructL();
       
    36     iOutlineX = 1.0;
       
    37     iOutlineY = 1.0;
       
    38     iSteepness = 20.0;
       
    39 /*    iRed = 0.0f;
       
    40     iGreen = 0.0f;
       
    41     iBlue = 0.0f;*/
       
    42     RegisterParameterL(KLitOutlineX, &iOutlineX);
       
    43     RegisterParameterL(KLitOutlineY, &iOutlineY);
       
    44     RegisterParameterL(KLitSteepness, &iSteepness);
       
    45 /*    RegisterParameterL(KLitRed, &iRed);
       
    46     RegisterParameterL(KLitGreen, &iGreen);
       
    47     RegisterParameterL(KLitBlue, &iBlue);*/
       
    48     }
       
    49 CHuiFxVg10BevelFilter *CHuiFxVg10BevelFilter::CloneL() const
       
    50     {
       
    51     CHuiFxVg10BevelFilter *filter = new(ELeave)CHuiFxVg10BevelFilter;
       
    52     filter->CHuiFxFilter::CopyFromL(this);
       
    53     filter->iOutlineX = iOutlineX;
       
    54     filter->iOutlineY = iOutlineY;
       
    55     filter->iSteepness = iSteepness;
       
    56     filter->CopyParameterL(KLitOutlineX, &filter->iOutlineX, this);
       
    57     filter->CopyParameterL(KLitOutlineY, &filter->iOutlineY, this);
       
    58     filter->CopyParameterL(KLitSteepness, &filter->iSteepness, this);
       
    59     return filter;
       
    60     }
       
    61 
       
    62 void CHuiFxVg10BevelFilter::DrawEffect(CHuiFxEngine& aEngine, VGImage aTargetImage, VGImage aSourceImage, TInt aWidth, TInt aHeight)
       
    63     {
       
    64     VGfloat outline_x = clamp(iOutlineX, EPSILON, 128.0f);
       
    65     VGfloat outline_y = clamp(iOutlineY, EPSILON, 128.0f);
       
    66     VGubyte steepness = (VGubyte)clamp(iSteepness, 0.0f, 255.0f);
       
    67 //    VGint width = vgGetParameteri(aSourceImage, VG_IMAGE_WIDTH);
       
    68 //    VGint height = vgGetParameteri(aSourceImage, VG_IMAGE_HEIGHT);
       
    69     VGint width = aWidth;
       
    70     VGint height = aHeight;
       
    71 
       
    72     if((outline_x > EPSILON && outline_y > EPSILON) || steepness == 0) 
       
    73         {
       
    74         // get an aux buffer
       
    75         CHuiFxRenderbuffer* aux1Buffer = aEngine.AcquireRenderbuffer(TSize(width, height));
       
    76         CHuiFxRenderbuffer* aux2Buffer = aEngine.AcquireRenderbuffer(TSize(width, height));
       
    77         if (!aux1Buffer || !aux2Buffer) // can't render the effect
       
    78             {
       
    79             return;
       
    80             }
       
    81         aux1Buffer->BindAsTexture(ERenderbufferUsageReadWrite);
       
    82         aux2Buffer->BindAsTexture(ERenderbufferUsageReadWrite);
       
    83         
       
    84         VGImage aux1Image = (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(aux1Buffer)->Image());
       
    85         VGImage aux2Image = (reinterpret_cast<CHuiFxVg10RenderbufferBase*>(aux2Buffer)->Image());
       
    86 
       
    87         VGuint lut[256];
       
    88         int threshold = 1;
       
    89         // generate ramp for alpha channel. the bigger the steepness the more solid the outline. 
       
    90         for(int i = 0; i < threshold; i++) 
       
    91             {
       
    92             lut[i] = 0x00000000; // | i;
       
    93             }
       
    94         for(int i = threshold; i < 256; i++)
       
    95             {
       
    96             lut[i] = 0xffffffff; // | i;
       
    97             }
       
    98         vgLookupSingle(aux1Image, aSourceImage, lut, VG_ALPHA, VG_TRUE, VG_FALSE);
       
    99         
       
   100         // TODO: pixel relative parameters
       
   101         // the variables are commented out because they are not used yet
       
   102 /*        
       
   103         VGint shiftX = 0;
       
   104         VGint shiftY = 0;
       
   105 //        VGshort kernel[9] = {0, -1, -2, 1, 0, -1, 2, 1, 0}; 
       
   106         VGshort kernel[9] = {1, 0, -1, 2, 0, -2, 1, 0, -1};
       
   107         VGfloat scale = 0.5f;
       
   108         VGfloat bias = 0.5f;
       
   109 */        
       
   110 
       
   111 //        vgConvolve(aux2Image, aux1Image, 3, 3, shiftX, shiftY, kernel, scale, bias, VG_TILE_PAD);
       
   112 
       
   113 /*        for(int i = 0; i < 126; i++)
       
   114             {
       
   115             lut[i] = 0x000000ff | i << 24 | i << 16 | i << 8 | i;
       
   116             }
       
   117 */        for(int i = 0; i < 10; i++)
       
   118             {
       
   119             lut[i] = 0x00000000  | i << 24 | i << 16 | i << 8 | 255 - i * 3;
       
   120             }
       
   121         for(int i = 20; i < 255; i++)
       
   122             {
       
   123             lut[i] = 0x00000000; // | i << 24 | i << 16 | i << 8 | i;
       
   124             }
       
   125 
       
   126 //        vgLookupSingle(aux1Image, aux2Image, lut, VG_ALPHA, VG_TRUE, VG_FALSE);
       
   127 
       
   128 //        vgGaussianBlur(aTargetImage, aux1Image, outline_x, outline_y, VG_TILE_PAD);        
       
   129         
       
   130         aux1Buffer->UnbindAsTexture();
       
   131         aux2Buffer->UnbindAsTexture();
       
   132         aEngine.ReleaseRenderbuffer(aux1Buffer);
       
   133         aEngine.ReleaseRenderbuffer(aux2Buffer);
       
   134         }
       
   135     else    // fast path --- just copy
       
   136         {
       
   137         vgCopyImage(aTargetImage, 0, 0, aSourceImage, 0, 0, width, height, VG_FALSE);   
       
   138         }
       
   139     }