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 |
|
|
27 |
/*! \namespace MMF::Utils
|
|
28 |
\internal
|
|
29 |
*/
|
|
30 |
|
|
31 |
/*! \class MMF::TTraceContext
|
|
32 |
\internal
|
|
33 |
*/
|
|
34 |
|
|
35 |
/*! \class MMF::Utils
|
|
36 |
\internal
|
|
37 |
*/
|
|
38 |
|
|
39 |
_LIT(PanicCategory, "Phonon::MMF");
|
|
40 |
|
|
41 |
void MMF::Utils::panic(PanicCode code)
|
|
42 |
{
|
|
43 |
User::Panic(PanicCategory, code);
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
static const TInt KMimePrefixLength = 6; // either "audio/" or "video/"
|
|
48 |
_LIT(KMimePrefixAudio, "audio/");
|
|
49 |
_LIT(KMimePrefixVideo, "video/");
|
|
50 |
|
|
51 |
MMF::MediaType MMF::Utils::mimeTypeToMediaType(const TDesC& mimeType)
|
|
52 |
{
|
|
53 |
MediaType result = MediaTypeUnknown;
|
|
54 |
|
|
55 |
if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixAudio) == 0) {
|
|
56 |
result = MediaTypeAudio;
|
|
57 |
} else if (mimeType.Left(KMimePrefixLength).Compare(KMimePrefixVideo) == 0) {
|
|
58 |
result = MediaTypeVideo;
|
|
59 |
}
|
|
60 |
|
|
61 |
return result;
|
|
62 |
}
|
|
63 |
|
|
64 |
|
|
65 |
#ifndef QT_NO_DEBUG
|
|
66 |
|
|
67 |
#include <hal.h>
|
|
68 |
#include <hal_data.h>
|
|
69 |
#include <gdi.h>
|
|
70 |
#include <eikenv.h>
|
|
71 |
|
|
72 |
struct TScreenInfo
|
|
73 |
{
|
|
74 |
int width;
|
|
75 |
int height;
|
|
76 |
int bpp;
|
|
77 |
const char* address;
|
|
78 |
int initialOffset;
|
|
79 |
int lineOffset;
|
|
80 |
TDisplayMode displayMode;
|
|
81 |
};
|
|
82 |
|
|
83 |
static void getScreenInfoL(TScreenInfo& info)
|
|
84 |
{
|
|
85 |
info.displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode();
|
|
86 |
|
|
87 |
// Then we must set these as the input parameter
|
|
88 |
info.width = info.displayMode;
|
|
89 |
info.height = info.displayMode;
|
|
90 |
info.initialOffset = info.displayMode;
|
|
91 |
info.lineOffset = info.displayMode;
|
|
92 |
info.bpp = info.displayMode;
|
|
93 |
|
|
94 |
User::LeaveIfError( HAL::Get(HALData::EDisplayXPixels, info.width) );
|
|
95 |
User::LeaveIfError( HAL::Get(HALData::EDisplayYPixels, info.width) );
|
|
96 |
|
|
97 |
int address;
|
|
98 |
User::LeaveIfError( HAL::Get(HALData::EDisplayMemoryAddress, address) );
|
|
99 |
info.address = reinterpret_cast<const char*>(address);
|
|
100 |
|
|
101 |
User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetToFirstPixel, info.initialOffset) );
|
|
102 |
|
|
103 |
User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetBetweenLines, info.lineOffset) );
|
|
104 |
|
|
105 |
User::LeaveIfError( HAL::Get(HALData::EDisplayBitsPerPixel, info.bpp) );
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
QColor MMF::Utils::getScreenPixel(const QPoint& pos)
|
|
110 |
{
|
|
111 |
TScreenInfo info;
|
|
112 |
TRAPD(err, getScreenInfoL(info));
|
|
113 |
QColor pixel;
|
|
114 |
if (err == KErrNone and pos.x() < info.width and pos.y() < info.height)
|
|
115 |
{
|
|
116 |
const int bytesPerPixel = info.bpp / 8;
|
|
117 |
Q_ASSERT(bytesPerPixel >= 3);
|
|
118 |
|
|
119 |
const int stride = (info.width * bytesPerPixel) + info.lineOffset;
|
|
120 |
|
|
121 |
const char* ptr =
|
|
122 |
info.address
|
|
123 |
+ info.initialOffset
|
|
124 |
+ pos.y() * stride
|
|
125 |
+ pos.x() * bytesPerPixel;
|
|
126 |
|
|
127 |
// BGRA
|
|
128 |
pixel.setBlue(*ptr++);
|
|
129 |
pixel.setGreen(*ptr++);
|
|
130 |
pixel.setRed(*ptr++);
|
|
131 |
|
|
132 |
if (bytesPerPixel == 4)
|
|
133 |
pixel.setAlpha(*ptr++);
|
|
134 |
}
|
|
135 |
return pixel;
|
|
136 |
}
|
|
137 |
|
|
138 |
// Debugging: for debugging video visibility
|
|
139 |
void MMF::Utils::dumpScreenPixelSample()
|
|
140 |
{
|
|
141 |
for (int i=0; i<20; ++i) {
|
|
142 |
const QPoint pos(i*10, i*10);
|
|
143 |
const QColor pixel = Utils::getScreenPixel(pos);
|
|
144 |
RDebug::Printf(
|
|
145 |
"Phonon::MMF::Utils::dumpScreenPixelSample %d %d = %d %d %d %d",
|
|
146 |
pos.x(), pos.y(), pixel.red(), pixel.green(), pixel.blue(), pixel.alpha()
|
|
147 |
);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
#endif // _DEBUG
|
|
152 |
|
|
153 |
QT_END_NAMESPACE
|
|
154 |
|