videoeditorengine/vedengine/GenManip/src/DCDithering.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 7 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description:  
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 //----IMAAMI----
       
    21 //*************************************************************************
       
    22 //DCDithering.cpp
       
    23 //
       
    24 //Version 1.00
       
    25 //
       
    26 //Contains:
       
    27 //	CDCDithering 
       
    28 //			
       
    29 //History:
       
    30 //	19.08.2003 version 1.00 created using existing IMAAMI algorithms	
       
    31 //*************************************************************************
       
    32 
       
    33 //  Include Files  
       
    34 #include <e32std.h>   // The basic definitions
       
    35 #include <fbs.h>      // For FBS bitmap
       
    36 #include "DCDithering.h"     // The DCDithering class
       
    37 
       
    38 
       
    39 
       
    40 //  MEMBER FUNCTIONS
       
    41 //=============================================================================
       
    42 
       
    43 
       
    44 
       
    45 /*
       
    46 -----------------------------------------------------------------------------
       
    47 
       
    48     CDCDithering
       
    49 
       
    50     Constructor
       
    51 
       
    52     Default constructor
       
    53 
       
    54     Return Values:  none
       
    55 
       
    56 -----------------------------------------------------------------------------
       
    57 */
       
    58 CDCDithering::CDCDithering()
       
    59 {
       
    60 	// This function is intentionally left blank.
       
    61 }
       
    62 
       
    63 
       
    64 
       
    65 
       
    66 /*
       
    67 -----------------------------------------------------------------------------
       
    68 
       
    69     CDCDithering
       
    70 
       
    71     NewLC
       
    72 
       
    73     Factory function to instantiate the class.
       
    74     This function leaves the class pointer to the cleanup stack
       
    75     May leave with KErrNoMemory if no memory available
       
    76 
       
    77     Return Values:  CDCDithering* self:  pointer to the class instance
       
    78 
       
    79 -----------------------------------------------------------------------------
       
    80 */
       
    81 CDCDithering* CDCDithering::NewLC()
       
    82 {
       
    83     CDCDithering* self = new (ELeave) CDCDithering();
       
    84     CleanupStack::PushL(self);
       
    85     self->ConstructL();
       
    86     return self;
       
    87 }
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 /*
       
    93 -----------------------------------------------------------------------------
       
    94 
       
    95     CDCDithering
       
    96 
       
    97     NewL
       
    98 
       
    99     Factory function to instantiate the class.
       
   100     May leave with KErrNoMemory if no memory available
       
   101 
       
   102     Return Values:  CDCDithering* self:  pointer to the class instance
       
   103 
       
   104 -----------------------------------------------------------------------------
       
   105 */
       
   106 CDCDithering* CDCDithering::NewL()
       
   107 {
       
   108     CDCDithering* self = CDCDithering::NewLC();
       
   109     CleanupStack::Pop();
       
   110     return self;
       
   111 }
       
   112 
       
   113 
       
   114 
       
   115 /*
       
   116 -----------------------------------------------------------------------------
       
   117 
       
   118     CDCDithering
       
   119 
       
   120     ConstructL
       
   121 
       
   122     Second phase constructor. Does nothing at the moment
       
   123 
       
   124     Return Values:  none
       
   125 
       
   126 -----------------------------------------------------------------------------
       
   127 */
       
   128 void CDCDithering::ConstructL()
       
   129 {
       
   130     // This function is intentionally left blank.
       
   131 }
       
   132 
       
   133 
       
   134 
       
   135 
       
   136 /*
       
   137 -----------------------------------------------------------------------------
       
   138 
       
   139     CDCDithering
       
   140 
       
   141     Destructor
       
   142 
       
   143     Return Values:  none
       
   144 
       
   145 -----------------------------------------------------------------------------
       
   146 */
       
   147 CDCDithering::~CDCDithering()
       
   148 {
       
   149 	// This function is intentionally left blank.
       
   150 }
       
   151 
       
   152 
       
   153 
       
   154 /*
       
   155 -----------------------------------------------------------------------------
       
   156 
       
   157   ProcessL
       
   158 	
       
   159   Process image referenced by aImage (modify aImage).
       
   160   May leave with KErrNoMemory if no memory available
       
   161 	  
       
   162   Return Values:  none
       
   163 		
       
   164 -----------------------------------------------------------------------------
       
   165 */
       
   166 void CDCDithering::ProcessL(CFbsBitmap& aImage)
       
   167 {
       
   168 	TUint	r, g, b;	// Color components
       
   169 	TUint8*	dataPtr;	// Pointer to data
       
   170 
       
   171 	//Dithering variables, init to 0
       
   172 	TInt	count=0;	
       
   173 	TInt16	dither=0;
       
   174 	
       
   175 	//EColor16M image is needed
       
   176 	if (aImage.DisplayMode() != EColor16M || aImage.DisplayMode() != EColor16M)
       
   177 		return;
       
   178 	
       
   179 	// Line Buffer and pointer to the data
       
   180 	TUint imageWidth = aImage.SizeInPixels().iWidth;
       
   181 	TUint scanLineLengthInBytes = aImage.ScanLineLength(imageWidth, aImage.DisplayMode());
       
   182 	
       
   183 	//Allocate buffer for scanline
       
   184 	iScanLineBuffer = HBufC8::NewMaxL(scanLineLengthInBytes);
       
   185 	//Pointer to scanline
       
   186 	TPtr8 linePtr = iScanLineBuffer->Des();
       
   187 	
       
   188 	//Step through image lines
       
   189 	for (TInt lineNo=0; lineNo<aImage.SizeInPixels().iHeight; ++lineNo)
       
   190 	{
       
   191 		//Get line
       
   192 		aImage.GetScanLine(linePtr, TPoint(0, lineNo), imageWidth, aImage.DisplayMode());
       
   193 		//CHECK! CONST_CAST not used in every algorithm which way is better?
       
   194 		dataPtr = CONST_CAST(TUint8*, linePtr.Ptr());
       
   195 
       
   196 		//Step through image pixels
       
   197 		for (TUint x=0; x < imageWidth; ++x)
       
   198 		{
       
   199 			// Get original values
       
   200 			b = *dataPtr++;
       
   201 			g = *dataPtr++;
       
   202 			r = *dataPtr++;
       
   203 			
       
   204 			//Compute DCDithering factor from base count
       
   205 			switch (count&1)
       
   206 			{
       
   207 			case 0:
       
   208 				dither = (TInt16)(dither*0x7ffd);
       
   209 				break;
       
   210 			case 1:
       
   211 				dither = (TInt16)(dither+0x7f21);
       
   212 				break;
       
   213 			}
       
   214 			
       
   215 			//Add DCDithering factor, adjust gain according to quantization factors.
       
   216 			r = Limit255((TInt)r + (dither>>13));
       
   217 			g = Limit255((TInt)g - (dither>>14));
       
   218 			b = Limit255((TInt)b + (dither>>13));
       
   219 			
       
   220 			//Move to the previous pixel
       
   221 			dataPtr -= 3;
       
   222 			
       
   223 			/* Set the result */
       
   224 			*dataPtr++ = (TUint8)b;
       
   225 			*dataPtr++ = (TUint8)g;
       
   226 			*dataPtr++ = (TUint8)r;
       
   227 		
       
   228 			//Increase bae count
       
   229 			count++;
       
   230 		}
       
   231 		
       
   232 		//Set scan line
       
   233 		aImage.SetScanLine(linePtr, lineNo);
       
   234 	}
       
   235 
       
   236 	//Free allocated memory
       
   237 	delete(iScanLineBuffer);
       
   238 	iScanLineBuffer = 0;
       
   239 }
       
   240 //  End of File  
       
   241 //----IMAAMI----