diff -r 000000000000 -r 951a5db380a0 videoeditorengine/vedengine/GenManip/src/DCIetd.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/videoeditorengine/vedengine/GenManip/src/DCIetd.cpp Fri Jan 29 14:08:33 2010 +0200 @@ -0,0 +1,519 @@ +/* +* Copyright (c) 2010 Ixonos Plc. +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - Initial contribution +* +* Contributors: +* Ixonos Plc +* +* Description: +* +*/ + + +//----IMAAMI---- +//************************************************************************* +//CDCIETD.cpp +//Version 2.00 +// +//Contains: +// CDCIETD +// Display specific color contrast enhancement, +// Image Enhancement for Transflective Displays version 2, +// IETD 2. +// +//History: +// 23.10.2003 version 2.00 created using existing IMAAMI IETD +//************************************************************************* + +// Include Files +#include // The basic definitions +#include // For FBS bitmap +#include "DCIetd.h" // The DCIetd class + + +// MEMBER FUNCTIONS +//============================================================================= + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + Constructor + + Default constructor, initializes member variables to initial values + + Return Values: none + +----------------------------------------------------------------------------- +*/ +CDCIetd::CDCIetd() +{ + // Set default values for parameters (from init file) + iParameters.aWhitePixels = WhitePixels; + iParameters.aBlackPixels = BlackPixels; + iParameters.aStretchLimit = StretchLimit; + iParameters.aSaturationGain = SaturationGain; + iParameters.aBitLimit = BitLimit; + iParameters.aWBC = WBC; + iParameters.aDBC = DBC; +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + NewLC + + Factory function to instantiate the class. + This function leaves the class pointer to the cleanup stack + May leave with KErrNoMemory if no memory available + + Return Values: CDCIetd* self: pointer to the class instance + +----------------------------------------------------------------------------- +*/ +CDCIetd* CDCIetd::NewLC() +{ + CDCIetd* self = new (ELeave) CDCIetd(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + NewL + + Factory function to instantiate the class. + May leave with KErrNoMemory if no memory available + + Return Values: CDCIetd* self: pointer to the class instance + +----------------------------------------------------------------------------- +*/ +CDCIetd* CDCIetd::NewL() +{ + CDCIetd* self = CDCIetd::NewLC(); + CleanupStack::Pop(); + return self; +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + ConstructL + + Second phase constructor. Does nothing at the moment + + Return Values: none + + ----------------------------------------------------------------------------- +*/ +void CDCIetd::ConstructL() +{ + // This function is intentionally left blank. +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + Destructor + + Return Values: none + +----------------------------------------------------------------------------- +*/ +CDCIetd::~CDCIetd() +{ + // This function is intentionally left blank. +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + Analyze + + Analyze image referenced by aBPtr + + Return Values: none + +----------------------------------------------------------------------------- +*/ +// Analyze image referenced by aBPtr +void CDCIetd::Analyze(CFbsBitmap& aBPtr) +{ + + //EColor16M image is needed + if (aBPtr.DisplayMode() != EColor16M) return; + + //Do analysis + GatherHistograms(aBPtr); + MakeMappings(); +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + ProcessL + + Process image referenced by aImage (modify aImage). + May leave with KErrNoMemory if no memory available + + Return Values: none + +----------------------------------------------------------------------------- +*/ +void CDCIetd::ProcessL (CFbsBitmap& aImage) // image reference +{ + TUint r, g, b; // Color components + TUint lum; // Brightness estimate + TInt dr, dg, db; // Differences to brightness + TUint8* dataPtr; // Pointer to data + + //EColor16M image is needed + if (aImage.DisplayMode() != EColor16M) return; + + //Line Buffer and pointer to the data + TUint imageWidth = aImage.SizeInPixels().iWidth; + TUint scanLineLengthInBytes = aImage.ScanLineLength(imageWidth, aImage.DisplayMode()); + + //Allocate buffer for scanline + iScanLineBuffer = HBufC8::NewMaxL(scanLineLengthInBytes); + //Pointer to scanline + TPtr8 linePtr = iScanLineBuffer->Des(); + + //Step through image pixels and do stretching + //and saturation increase + //--------------------------------------------- + + //Read all lines + for (TInt lineNo=0; lineNo>16; //Y + //lum = (r+g+b)/3; //Simple approximation + lum=(r+(g<<1)+b)>>2; //More effective simple approximation + + //Compute componentwise differences to luminance + dr = r-lum; + dg = g-lum; + db = b-lum; + + //Increase differences => saturation increases. + //Use gain parameter for adjusting the strength of the effect. + b += iParameters.aSaturationGain*db/32; + g += iParameters.aSaturationGain*dg/32; + r += iParameters.aSaturationGain*dr/32; + + //Save data to same image & same pixels + dataPtr -= 3; + + //Limit to available dynamic range [0,255]. + *dataPtr++ = Limit255(b); + *dataPtr++ = Limit255(g); + *dataPtr++ = Limit255(r); + } + + //Save line + aImage.SetScanLine(linePtr, lineNo); + } + + //Free memory + delete(iScanLineBuffer); + iScanLineBuffer = 0; +} + + + + +/* +----------------------------------------------------------------------------- + + CDCIetd + + GatherHistograms + + Gather histograms and make cumulative histogram. + + Return Values: none + +----------------------------------------------------------------------------- +*/ +void CDCIetd::GatherHistograms (const CFbsBitmap& aImage) // Pointer to the image bitmap +{ + const TUint8* dataPtr; //Pointer to data + TInt lineNo; //Line number + TUint x; //Pixel index + TUint color; //Color index + TUint count; // Number of colors in each component + + //Compute image width & allocate scan line memory + TUint imageWidth = aImage.SizeInPixels().iWidth; + TUint histScanLineLengthInBytes = aImage.ScanLineLength(imageWidth, aImage.DisplayMode()); + iScanLineBuffer = HBufC8::NewMaxL(histScanLineLengthInBytes); + + //Pointer to line + TPtr8 linePtr = iScanLineBuffer->Des(); + + //Clear histograms + Mem::FillZ(iHistogram, sizeof(iHistogram)); + + // Read all lines and gather histograms + for (lineNo=0; lineNo0) count++; + } + + // Compute increased stretch limit if a color component has less colors than iBitLimit. + // Otherwise use predetermined stretch limit. + if (count 0 && (TUint)iHistogram[color][x] > MaxBins[color]) + --x; // Find from histogram + + MaxBins[color] = x; // Save bin index = end of stretching part of LUT + } + + //Find minimum of all colors + minBin=255; + for (color=0; color<3; color++) + { + if (minBin>MinBins[color]) minBin=MinBins[color]; + } + + //Find maximum of all colors + maxBin=0; + for (color=0; color<3; color++) + { + if (maxBin no WBC(or DBC). + for (color=0; color<3; color++) + { + if(maxBin-MaxBins[color]>iParameters.aWBC) MaxBins[color]=maxBin-iParameters.aWBC; + if((MinBins[color]-minBin) > iParameters.aDBC) MinBins[color]=minBin+iParameters.aDBC; + } + + //Step through color components + for (color=0; color<3; color++) + { + // If histogram has only one nonzero bin maxBin can be less than minBin. + // In that case change maxBin value to minBin. + if(MaxBins[color]255) + MaxBins[color]=255; + } + + // Set 0 mapping part of the LUT + for (x=0; x<=MinBins[color]; ++x) + iMap[color][x] = 0; + + // Set 255 mapping part of the LUT + for (x=MaxBins[color]; x<=255; ++x) + iMap[color][x] = 255; + + // Compute linear stretching part of the LUT + for (x=MinBins[color]+1; x