javauis/lcdui_akn/javalcdui/src.nokialcdui/TMID8888Format.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:   8 bits for alpha, red, green and blue component in a pixel.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "TMID8888Format.h"
       
    21 
       
    22 // CONSTANTS
       
    23 const TInt KMIDAlphaShift = 24;
       
    24 const TInt KMIDRedShift   = 16;
       
    25 const TInt KMIDGreenShift =  8;
       
    26 
       
    27 inline TUint32 ConvertInternalInline8888(const TMIDInternalARGB& aInternal)
       
    28 {
       
    29     return ((aInternal.iA << KMIDAlphaShift) & K8888AMax) |
       
    30            ((aInternal.iR << KMIDRedShift) & K8888RMax) |
       
    31            ((aInternal.iG << KMIDGreenShift) & K8888GMax) |
       
    32            ((aInternal.iB) & K8888BMax);
       
    33 }
       
    34 
       
    35 inline void ConvertInline8888(TMIDInternalARGB& aResult, TUint32 aColor, TBool aTransparency)
       
    36 {
       
    37     // set alpha only if a bitmap is transparent, otherwise use full opaque
       
    38     aResult.iA = aTransparency
       
    39                  ? (TUint8)((aColor & K8888AMax) >> KMIDAlphaShift)
       
    40                  : KAlphaFullOpaque;
       
    41 
       
    42     aResult.iR = (TUint8)((aColor & K8888RMax) >> KMIDRedShift);
       
    43     aResult.iG = (TUint8)((aColor & K8888GMax) >> KMIDGreenShift);
       
    44     aResult.iB = (TUint8)(aColor & K8888BMax);
       
    45 }
       
    46 
       
    47 void TMID8888Format::InitializeL(const TMIDBitmapParameters& aParameters)
       
    48 {
       
    49     TMIDFormatConverter::InitializeL(aParameters);
       
    50     __ASSERT_DEBUG(!iAlphaBitmap, User::Invariant());
       
    51     iOffset += iTransformer.iPoint.iX + iTransformer.iPoint.iY * iScanlength;
       
    52     iBitmap = aParameters.iPixels;
       
    53 }
       
    54 
       
    55 TUint32 TMID8888Format::ConvertInternal(const TMIDInternalARGB& aInternal)
       
    56 {
       
    57     return ConvertInternalInline8888(aInternal);
       
    58 }
       
    59 
       
    60 void TMID8888Format::Convert(TMIDInternalARGB& aResult, TUint32 aColor) const
       
    61 {
       
    62     ConvertInline8888(aResult, aColor, iTransparency);
       
    63 }
       
    64 
       
    65 void TMID8888Format::GetPixel(TMIDInternalARGB& aResult) const
       
    66 {
       
    67     ConvertInline8888(aResult, iBitmap[ iOffset ], iTransparency);    // CSI: 2 Wrong index means implementation error #
       
    68 }
       
    69 
       
    70 void TMID8888Format::PlotPixel(const TMIDInternalARGB& aInternal)
       
    71 {
       
    72     iBitmap[ iOffset ] = ConvertInternalInline8888(aInternal);    // CSI: 2 Wrong index means implementation error #
       
    73 }
       
    74 
       
    75 TUint8 TMID8888Format::GetAlpha() const
       
    76 {
       
    77     // we need only last 8 bits since it is either white or black
       
    78     __ASSERT_DEBUG(!iAlphaBitmap, User::Invariant());
       
    79     return (TUint8)(iBitmap[ iOffset ] >> KMIDAlphaShift);    // CSI: 2 Wrong index means implementation error #
       
    80 }
       
    81 
       
    82 void TMID8888Format::GetPixelWithAlpha(TMIDInternalARGB& aResult) const
       
    83 {
       
    84     __ASSERT_DEBUG(!iAlphaBitmap, User::Invariant());
       
    85     GetPixel(aResult);
       
    86 }
       
    87 
       
    88 TBool TMID8888Format::CheckSize(TInt aPixelSize, TInt aLastDrawnPixelOffset)
       
    89 {
       
    90     return ((aLastDrawnPixelOffset * KBytesPerPixel8888) <= aPixelSize);
       
    91 }