sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "GDIPANIC.h" sl@0: sl@0: // sl@0: // CPalette sl@0: // sl@0: sl@0: _LIT(KGdiCPalettePanicCategory,"CPalette"); sl@0: sl@0: EXPORT_C CPalette::CPalette(): sl@0: CBase(), sl@0: iArray(NULL), sl@0: iNumEntries(0) sl@0: {} sl@0: sl@0: sl@0: EXPORT_C CPalette::~CPalette() sl@0: /** Destructor. */ sl@0: { sl@0: delete [] iArray; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CPalette::Clear() sl@0: /** Clears all the entries in the palette to TRgb(0). */ sl@0: { sl@0: TRgb blank(0); sl@0: for(TInt count=0;countConstructL(aNumberOfEntries); sl@0: CleanupStack::Pop(); sl@0: return(thisptr); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CPalette* CPalette::NewDefaultL(TDisplayMode aDispMode) sl@0: /** Creates a new default palette for the specified display mode. The default palette sl@0: for a particular display mode has one entry for each possible colour in that sl@0: display mode (2 entries for EGray2, 16 entries for EColor16 etc.); the colour sl@0: of each index p in the default palette is set to its default value according sl@0: to its display mode (e.g. if the mode is EColor16 then palette[p]==TRgb::Color16(p); sl@0: if the mode is EGray4 then palette[p]==TRgb::_Gray4(p)). sl@0: sl@0: @param aDispMode The display mode for which the palette is to be created. sl@0: @return The newly created palette */ sl@0: { sl@0: TInt numentries=0; sl@0: switch(aDispMode) sl@0: { sl@0: case EGray2: sl@0: numentries=2; sl@0: break; sl@0: case EGray4: sl@0: numentries=4; sl@0: break; sl@0: case EGray16: sl@0: case EColor16: sl@0: numentries=16; sl@0: break; sl@0: case EGray256: sl@0: case EColor256: sl@0: numentries=256; sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: }; sl@0: CPalette* thisptr=new(ELeave) CPalette; sl@0: CleanupStack::PushL(thisptr); sl@0: thisptr->ConstructL(numentries); sl@0: TInt count=0; sl@0: switch(aDispMode) sl@0: { sl@0: case EGray2: sl@0: thisptr->iArray[0]=TRgb::_Gray2(0); sl@0: thisptr->iArray[1]=TRgb::_Gray2(1); sl@0: break; sl@0: case EGray4: sl@0: for(;countiArray[count]=TRgb::_Gray4(count); sl@0: break; sl@0: case EGray16: sl@0: for(;countiArray[count]=TRgb::_Gray16(count); sl@0: break; sl@0: case EColor16: sl@0: for(;countiArray[count]=TRgb::Color16(count); sl@0: break; sl@0: case EGray256: sl@0: for(;countiArray[count]=TRgb::_Gray256(count); sl@0: break; sl@0: case EColor256: sl@0: for(;countiArray[count]=TRgb::Color256(count); sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: CleanupStack::Pop(); sl@0: return(thisptr); sl@0: } sl@0: sl@0: void CPalette::ConstructL(TInt aNumberOfEntries) sl@0: { sl@0: if(aNumberOfEntries<=0) User::Leave(KErrArgument); sl@0: iArray=new(ELeave) TRgb[aNumberOfEntries]; sl@0: iNumEntries=aNumberOfEntries; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TRgb CPalette::GetEntry(TInt aIndex) const sl@0: /** Gets the RGB value of the palette entry at aPaletteIndex. sl@0: sl@0: @param aPaletteIndex The index of the palette entry to get. sl@0: @return The RGB value of the palette entry */ sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(aIndexInternal(); sl@0: sl@0: TInt difference = Abs((TInt)(aColor.Internal()&0xFF)-(TInt)(value&0xFF))+ sl@0: (Abs((TInt)(aColor.Internal()&0xFF00)-(TInt)(value&0xFF00))>>8)+ sl@0: (Abs((TInt)(aColor.Internal()&0xFF0000)-(TInt)(value&0xFF0000))>>16); sl@0: sl@0: if(difference