author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/* This file is part of the KDE project. |
2 |
||
3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
||
5 |
This library is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Lesser General Public License as published by |
|
7 |
the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
||
9 |
This library is distributed in the hope that it will be useful, |
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
GNU Lesser General Public License for more details. |
|
13 |
||
14 |
You should have received a copy of the GNU Lesser General Public License |
|
15 |
along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
||
17 |
*/ |
|
18 |
||
19 |
#include "utils.h" |
|
20 |
#include <e32std.h> |
|
21 |
||
22 |
QT_BEGIN_NAMESPACE |
|
23 |
||
24 |
using namespace Phonon; |
|
25 |
using namespace Phonon::MMF; |
|
26 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
27 |
/*! \namespace Phonon::MMF::Utils |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
28 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
/*! \class Phonon::MMF::TTraceContext |
0 | 32 |
\internal |
33 |
*/ |
|
34 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
35 |
/*! \enum Phonon::MMF::PanicCode |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
\internal |
0 | 37 |
*/ |
38 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
39 |
/*! \enum Phonon::MMF::TTraceCategory |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
\internal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
41 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
42 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
43 |
/*! \enum Phonon::MMF::MediaType |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
44 |
\internal |
0 | 45 |
*/ |
46 |
||
47 |
_LIT(PanicCategory, "Phonon::MMF"); |
|
48 |
||
49 |
void MMF::Utils::panic(PanicCode code) |
|
50 |
{ |
|
51 |
User::Panic(PanicCategory, code); |
|
52 |
} |
|
53 |
||
54 |
||
55 |
static const TInt KMimePrefixLength = 6; // either "audio/" or "video/" |
|
56 |
_LIT(KMimePrefixAudio, "audio/"); |
|
57 |
_LIT(KMimePrefixVideo, "video/"); |
|
58 |
||
59 |
MMF::MediaType MMF::Utils::mimeTypeToMediaType(const TDesC& mimeType) |
|
60 |
{ |
|
61 |
MediaType result = MediaTypeUnknown; |
|
62 |
||
63 |
if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixAudio) == 0) { |
|
64 |
result = MediaTypeAudio; |
|
65 |
} else if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixVideo) == 0) { |
|
66 |
result = MediaTypeVideo; |
|
67 |
} |
|
68 |
||
69 |
return result; |
|
70 |
} |
|
71 |
||
72 |
||
73 |
#ifndef QT_NO_DEBUG |
|
74 |
||
75 |
#include <hal.h> |
|
76 |
#include <hal_data.h> |
|
77 |
#include <gdi.h> |
|
78 |
#include <eikenv.h> |
|
79 |
||
80 |
struct TScreenInfo |
|
81 |
{ |
|
82 |
int width; |
|
83 |
int height; |
|
84 |
int bpp; |
|
85 |
const char* address; |
|
86 |
int initialOffset; |
|
87 |
int lineOffset; |
|
88 |
TDisplayMode displayMode; |
|
89 |
}; |
|
90 |
||
91 |
static void getScreenInfoL(TScreenInfo& info) |
|
92 |
{ |
|
93 |
info.displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode(); |
|
94 |
||
95 |
// Then we must set these as the input parameter |
|
96 |
info.width = info.displayMode; |
|
97 |
info.height = info.displayMode; |
|
98 |
info.initialOffset = info.displayMode; |
|
99 |
info.lineOffset = info.displayMode; |
|
100 |
info.bpp = info.displayMode; |
|
101 |
||
102 |
User::LeaveIfError( HAL::Get(HALData::EDisplayXPixels, info.width) ); |
|
103 |
User::LeaveIfError( HAL::Get(HALData::EDisplayYPixels, info.width) ); |
|
104 |
||
105 |
int address; |
|
106 |
User::LeaveIfError( HAL::Get(HALData::EDisplayMemoryAddress, address) ); |
|
107 |
info.address = reinterpret_cast<const char*>(address); |
|
108 |
||
109 |
User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetToFirstPixel, info.initialOffset) ); |
|
110 |
||
111 |
User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetBetweenLines, info.lineOffset) ); |
|
112 |
||
113 |
User::LeaveIfError( HAL::Get(HALData::EDisplayBitsPerPixel, info.bpp) ); |
|
114 |
} |
|
115 |
||
116 |
||
117 |
QColor MMF::Utils::getScreenPixel(const QPoint& pos) |
|
118 |
{ |
|
119 |
TScreenInfo info; |
|
120 |
TRAPD(err, getScreenInfoL(info)); |
|
121 |
QColor pixel; |
|
122 |
if (err == KErrNone and pos.x() < info.width and pos.y() < info.height) |
|
123 |
{ |
|
124 |
const int bytesPerPixel = info.bpp / 8; |
|
125 |
Q_ASSERT(bytesPerPixel >= 3); |
|
126 |
||
127 |
const int stride = (info.width * bytesPerPixel) + info.lineOffset; |
|
128 |
||
129 |
const char* ptr = |
|
130 |
info.address |
|
131 |
+ info.initialOffset |
|
132 |
+ pos.y() * stride |
|
133 |
+ pos.x() * bytesPerPixel; |
|
134 |
||
135 |
// BGRA |
|
136 |
pixel.setBlue(*ptr++); |
|
137 |
pixel.setGreen(*ptr++); |
|
138 |
pixel.setRed(*ptr++); |
|
139 |
||
140 |
if (bytesPerPixel == 4) |
|
141 |
pixel.setAlpha(*ptr++); |
|
142 |
} |
|
143 |
return pixel; |
|
144 |
} |
|
145 |
||
146 |
// Debugging: for debugging video visibility |
|
147 |
void MMF::Utils::dumpScreenPixelSample() |
|
148 |
{ |
|
149 |
for (int i=0; i<20; ++i) { |
|
150 |
const QPoint pos(i*10, i*10); |
|
151 |
const QColor pixel = Utils::getScreenPixel(pos); |
|
152 |
RDebug::Printf( |
|
153 |
"Phonon::MMF::Utils::dumpScreenPixelSample %d %d = %d %d %d %d", |
|
154 |
pos.x(), pos.y(), pixel.red(), pixel.green(), pixel.blue(), pixel.alpha() |
|
155 |
); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
#endif // _DEBUG |
|
160 |
||
161 |
QT_END_NAMESPACE |
|
162 |