|
1 /* |
|
2 * Copyright (c) 2007-2008 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: image provider for image file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknsSkinInstance.h> |
|
20 #include <AknsUtils.h> |
|
21 #include "hnconvutils.h" |
|
22 #include "hnglobals.h" |
|
23 #include "hnattrimgprovfileimage.h" |
|
24 #include "imageconversion.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS ============================= |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CHnAttrImgProvFileImage::CHnAttrImgProvFileImage() |
|
34 { |
|
35 } |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 void CHnAttrImgProvFileImage::CorrectBitmapSize( |
|
42 CImageDecoder& aImageDec, TSize& aBitmapSize ) |
|
43 { |
|
44 const TFrameInfo& frameInfo = aImageDec.FrameInfo(); |
|
45 TSize imageSize = frameInfo.iOverallSizeInPixels; |
|
46 if ( imageSize.iWidth && imageSize.iHeight ) |
|
47 { |
|
48 if ( imageSize.iWidth <= aBitmapSize.iWidth |
|
49 && imageSize.iHeight <= aBitmapSize.iHeight) |
|
50 { |
|
51 aBitmapSize = imageSize; |
|
52 } |
|
53 else |
|
54 { |
|
55 TInt reductionFactor = aImageDec.ReductionFactor( |
|
56 imageSize, aBitmapSize ); |
|
57 TInt err = aImageDec.ReducedSize( |
|
58 imageSize, reductionFactor, aBitmapSize ); |
|
59 ASSERT( KErrNone == err ); |
|
60 } |
|
61 } |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 void CHnAttrImgProvFileImage::ConstructL( const TDesC& aFileName ) |
|
69 { |
|
70 TSize bitmapSize( KMaxIconBitmapSize, KMaxIconBitmapSize ); |
|
71 |
|
72 HBufC8* buf = HnConvUtils::StrToStr8LC( aFileName ); |
|
73 iValue.CreateL( aFileName.Length() + 1 ); |
|
74 iValue.Copy( *buf ); |
|
75 CleanupStack::PopAndDestroy( buf ); |
|
76 |
|
77 CImageDecoder* imageDec = CImageDecoder::FileNewL(CEikonEnv::Static()->FsSession(), |
|
78 aFileName, CImageDecoder::EOptionAlwaysThread); |
|
79 CleanupStack::PushL( imageDec ); |
|
80 |
|
81 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap(); |
|
82 TDismissableCleaner bitmapCleaner( bitmap ); |
|
83 CleanupClosePushL( bitmapCleaner ); |
|
84 CFbsBitmap* mask = new (ELeave) CFbsBitmap(); |
|
85 CleanupStack::PushL( mask ); |
|
86 |
|
87 CorrectBitmapSize( *imageDec, bitmapSize ); |
|
88 User::LeaveIfError( bitmap->Create( bitmapSize, EColor64K ) ); |
|
89 User::LeaveIfError( mask->Create( bitmapSize, EGray256 ) ); |
|
90 TRequestStatus status = KRequestPending; |
|
91 imageDec->Convert( &status, *bitmap, *mask ); |
|
92 User::WaitForRequest( status ); |
|
93 |
|
94 CleanupStack::Pop( mask ); |
|
95 CFbsBitmap* avkonishMask = AknIconUtils::CreateIconL( mask ); |
|
96 mask = NULL; |
|
97 CleanupStack::PushL( avkonishMask ); |
|
98 |
|
99 bitmapCleaner.Dismiss(); |
|
100 CFbsBitmap* avkonishBitmap = AknIconUtils::CreateIconL( bitmap ); |
|
101 bitmap = NULL; |
|
102 CleanupStack::PushL( avkonishBitmap ); |
|
103 |
|
104 CreateIconL( avkonishBitmap, avkonishMask ); |
|
105 CleanupStack::Pop( avkonishBitmap ); |
|
106 CleanupStack::Pop( avkonishMask ); |
|
107 |
|
108 CleanupStack::PopAndDestroy( &bitmapCleaner ); |
|
109 CleanupStack::PopAndDestroy( imageDec ); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C CHnAttrImgProvFileImage* CHnAttrImgProvFileImage::NewL( |
|
117 const TDesC& aFileName ) |
|
118 { |
|
119 CHnAttrImgProvFileImage* self = NewLC( aFileName ); |
|
120 CleanupStack::Pop( self ); |
|
121 return self; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C CHnAttrImgProvFileImage* CHnAttrImgProvFileImage::NewLC( |
|
129 const TDesC& aFileName ) |
|
130 { |
|
131 CHnAttrImgProvFileImage* self = new( ELeave ) CHnAttrImgProvFileImage; |
|
132 CleanupStack::PushL( self ); |
|
133 self->ConstructL( aFileName ); |
|
134 return self; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 CHnAttrImgProvFileImage::~CHnAttrImgProvFileImage() |
|
142 { |
|
143 iValue.Close(); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 const TDesC8& CHnAttrImgProvFileImage::Value() |
|
151 { |
|
152 return iValue; |
|
153 } |
|
154 |