diff -r 000000000000 -r 5d03bc08d59c graphicsdeviceinterface/gdi/sgdi/PALETTE.CPP --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graphicsdeviceinterface/gdi/sgdi/PALETTE.CPP Tue Feb 02 01:47:50 2010 +0200 @@ -0,0 +1,218 @@ +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "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: +// +// Description: +// + +#include +#include "GDIPANIC.h" + +// +// CPalette +// + +_LIT(KGdiCPalettePanicCategory,"CPalette"); + +EXPORT_C CPalette::CPalette(): + CBase(), + iArray(NULL), + iNumEntries(0) + {} + + +EXPORT_C CPalette::~CPalette() +/** Destructor. */ + { + delete [] iArray; + } + + +EXPORT_C void CPalette::Clear() +/** Clears all the entries in the palette to TRgb(0). */ + { + TRgb blank(0); + for(TInt count=0;countConstructL(aNumberOfEntries); + CleanupStack::Pop(); + return(thisptr); + } + + +EXPORT_C CPalette* CPalette::NewDefaultL(TDisplayMode aDispMode) +/** Creates a new default palette for the specified display mode. The default palette +for a particular display mode has one entry for each possible colour in that +display mode (2 entries for EGray2, 16 entries for EColor16 etc.); the colour +of each index p in the default palette is set to its default value according +to its display mode (e.g. if the mode is EColor16 then palette[p]==TRgb::Color16(p); +if the mode is EGray4 then palette[p]==TRgb::_Gray4(p)). + +@param aDispMode The display mode for which the palette is to be created. +@return The newly created palette */ + { + TInt numentries=0; + switch(aDispMode) + { + case EGray2: + numentries=2; + break; + case EGray4: + numentries=4; + break; + case EGray16: + case EColor16: + numentries=16; + break; + case EGray256: + case EColor256: + numentries=256; + break; + default: + User::Leave(KErrNotSupported); + }; + CPalette* thisptr=new(ELeave) CPalette; + CleanupStack::PushL(thisptr); + thisptr->ConstructL(numentries); + TInt count=0; + switch(aDispMode) + { + case EGray2: + thisptr->iArray[0]=TRgb::_Gray2(0); + thisptr->iArray[1]=TRgb::_Gray2(1); + break; + case EGray4: + for(;countiArray[count]=TRgb::_Gray4(count); + break; + case EGray16: + for(;countiArray[count]=TRgb::_Gray16(count); + break; + case EColor16: + for(;countiArray[count]=TRgb::Color16(count); + break; + case EGray256: + for(;countiArray[count]=TRgb::_Gray256(count); + break; + case EColor256: + for(;countiArray[count]=TRgb::Color256(count); + break; + default: + User::Leave(KErrNotSupported); + } + CleanupStack::Pop(); + return(thisptr); + } + +void CPalette::ConstructL(TInt aNumberOfEntries) + { + if(aNumberOfEntries<=0) User::Leave(KErrArgument); + iArray=new(ELeave) TRgb[aNumberOfEntries]; + iNumEntries=aNumberOfEntries; + } + + +EXPORT_C TRgb CPalette::GetEntry(TInt aIndex) const +/** Gets the RGB value of the palette entry at aPaletteIndex. + +@param aPaletteIndex The index of the palette entry to get. +@return The RGB value of the palette entry */ + { + GDI_ASSERT_ALWAYS_GENERAL(aIndexInternal(); + + TInt difference = Abs((TInt)(aColor.Internal()&0xFF)-(TInt)(value&0xFF))+ + (Abs((TInt)(aColor.Internal()&0xFF00)-(TInt)(value&0xFF00))>>8)+ + (Abs((TInt)(aColor.Internal()&0xFF0000)-(TInt)(value&0xFF0000))>>16); + + if(difference