92
|
1 |
/*
|
|
2 |
* Copyright (c)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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <exception>
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <badesca.h>
|
|
22 |
|
|
23 |
#include <fbs.h>
|
|
24 |
#include <bitdev.h>
|
|
25 |
#include <QPixmap>
|
|
26 |
#include <HbIcon>
|
|
27 |
#include <QBitmap>
|
|
28 |
#include <QDebug>
|
|
29 |
#include <XQConversions>
|
|
30 |
|
|
31 |
#include "cadef.h"
|
|
32 |
#include "cabitmapadapter.h"
|
|
33 |
|
|
34 |
static QImage::Format TDisplayMode2Format(TDisplayMode mode)
|
|
35 |
{
|
|
36 |
QImage::Format format;
|
|
37 |
switch (mode) {
|
|
38 |
case EGray2:
|
|
39 |
format = QImage::Format_MonoLSB;
|
|
40 |
break;
|
|
41 |
case EColor256:
|
|
42 |
case EGray256:
|
|
43 |
format = QImage::Format_Indexed8;
|
|
44 |
break;
|
|
45 |
case EColor4K:
|
|
46 |
format = QImage::Format_RGB444;
|
|
47 |
break;
|
|
48 |
case EColor64K:
|
|
49 |
format = QImage::Format_RGB16;
|
|
50 |
break;
|
|
51 |
case EColor16M:
|
|
52 |
format = QImage::Format_RGB888;
|
|
53 |
break;
|
|
54 |
case EColor16MU:
|
|
55 |
format = QImage::Format_RGB32;
|
|
56 |
break;
|
|
57 |
case EColor16MA:
|
|
58 |
format = QImage::Format_ARGB32;
|
|
59 |
break;
|
|
60 |
case EColor16MAP:
|
|
61 |
format = QImage::Format_ARGB32_Premultiplied;
|
|
62 |
break;
|
|
63 |
default:
|
|
64 |
format = QImage::Format_Invalid;
|
|
65 |
break;
|
|
66 |
}
|
|
67 |
return format;
|
|
68 |
}
|
|
69 |
|
|
70 |
QPixmap CaBitmapAdapter::fromSymbianCFbsBitmap(CFbsBitmap *aBitmap)
|
|
71 |
{
|
|
72 |
aBitmap->BeginDataAccess();
|
|
73 |
uchar *data = (uchar *)aBitmap->DataAddress();
|
|
74 |
TSize size = aBitmap->SizeInPixels();
|
|
75 |
TDisplayMode displayMode = aBitmap->DisplayMode();
|
|
76 |
|
|
77 |
// QImage format must match to bitmap format
|
|
78 |
QImage image(data, size.iWidth, size.iHeight, TDisplayMode2Format(
|
|
79 |
displayMode));
|
|
80 |
aBitmap->EndDataAccess();
|
|
81 |
|
|
82 |
// No data copying happens because
|
|
83 |
// image format matches native OpenVG format.
|
|
84 |
// So QPixmap actually points to CFbsBitmap data.
|
|
85 |
return QPixmap::fromImage(image);
|
|
86 |
}
|
|
87 |
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
// copying compressed bitmap
|
|
90 |
//----------------------------------------------------------------------------
|
|
91 |
CFbsBitmap *CaBitmapAdapter::copyBitmapLC(CFbsBitmap *input)
|
|
92 |
{
|
|
93 |
CFbsBitmap *bmp = new(ELeave) CFbsBitmap();
|
|
94 |
CleanupStack::PushL(bmp);
|
|
95 |
bmp->Create(input->SizeInPixels(), input->DisplayMode());
|
|
96 |
|
|
97 |
CFbsBitmapDevice *bitmapDevice = CFbsBitmapDevice::NewL(bmp);
|
|
98 |
CleanupStack::PushL(bitmapDevice);
|
|
99 |
CFbsBitGc *bmpGc;
|
|
100 |
bitmapDevice->CreateContext(bmpGc);
|
|
101 |
bmpGc->BitBlt(TPoint(0,0), input);
|
|
102 |
delete bmpGc;
|
|
103 |
CleanupStack::PopAndDestroy(bitmapDevice);
|
|
104 |
return bmp;
|
|
105 |
}
|
|
106 |
|
|
107 |
void CaBitmapAdapter::fromBitmapAndMaskToPixmapL(CFbsBitmap* fbsBitmap,
|
|
108 |
CFbsBitmap* fbsMask, QPixmap& pixmap)
|
|
109 |
{
|
|
110 |
if (fbsBitmap->Header().iCompression == ENoBitmapCompression) {
|
|
111 |
pixmap = CaBitmapAdapter::fromSymbianCFbsBitmap(fbsBitmap);
|
|
112 |
QPixmap mask = CaBitmapAdapter::fromSymbianCFbsBitmap(fbsMask);
|
|
113 |
pixmap.setAlphaChannel(mask);
|
|
114 |
} else { // we need special handling for icons in 9.2 (NGA)
|
|
115 |
// let's hope that in future it will be in QT code
|
|
116 |
CFbsBitmap *temp(NULL);
|
|
117 |
temp = CaBitmapAdapter::copyBitmapLC(fbsBitmap);
|
|
118 |
pixmap = CaBitmapAdapter::fromSymbianCFbsBitmap(temp);
|
|
119 |
CleanupStack::PopAndDestroy();
|
|
120 |
temp = CaBitmapAdapter::copyBitmapLC(fbsMask);
|
|
121 |
QPixmap mask = CaBitmapAdapter::fromSymbianCFbsBitmap(temp);
|
|
122 |
CleanupStack::PopAndDestroy();
|
|
123 |
pixmap.setAlphaChannel(mask);
|
|
124 |
}
|
|
125 |
}
|