From 6700a53676265787ab46106602234448e0174e55 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 16 Sep 2009 18:08:58 +0100 Subject: Added a utility function for reading color of individual pixels from the screen --- src/3rdparty/phonon/mmf/utils.cpp | 75 ++++++++++++++++++++++++++++++++ src/3rdparty/phonon/mmf/utils.h | 9 ++++ src/plugins/phonon/mmf/plugin/plugin.pro | 1 + 3 files changed, 85 insertions(+) diff --git a/src/3rdparty/phonon/mmf/utils.cpp b/src/3rdparty/phonon/mmf/utils.cpp index cebc32e..3d674fd 100644 --- a/src/3rdparty/phonon/mmf/utils.cpp +++ b/src/3rdparty/phonon/mmf/utils.cpp @@ -50,5 +50,80 @@ MMF::MediaType MMF::Utils::mimeTypeToMediaType(const TDesC& mimeType) } +#ifdef _DEBUG + +#include +#include +#include +#include + +struct TScreenInfo +{ + int width; + int height; + int bpp; + const char* address; + int initialOffset; + int lineOffset; + TDisplayMode displayMode; +}; + +void getScreenInfoL(TScreenInfo& info) +{ + info.displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode(); + + // Then we must set these as the input parameter + info.width = info.displayMode; + info.height = info.displayMode; + info.initialOffset = info.displayMode; + info.lineOffset = info.displayMode; + info.bpp = info.displayMode; + + User::LeaveIfError( HAL::Get(HALData::EDisplayXPixels, info.width) ); + User::LeaveIfError( HAL::Get(HALData::EDisplayYPixels, info.width) ); + + int address; + User::LeaveIfError( HAL::Get(HALData::EDisplayMemoryAddress, address) ); + info.address = reinterpret_cast(address); + + User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetToFirstPixel, info.initialOffset) ); + + User::LeaveIfError( HAL::Get(HALData::EDisplayOffsetBetweenLines, info.lineOffset) ); + + User::LeaveIfError( HAL::Get(HALData::EDisplayBitsPerPixel, info.bpp) ); +} + + +QColor MMF::Utils::getScreenPixel(const QPoint& pos) +{ + TScreenInfo info; + TRAPD(err, getScreenInfoL(info)); + QColor pixel; + if(err == KErrNone and pos.x() < info.width and pos.y() < info.height) + { + const int bytesPerPixel = info.bpp / 8; + Q_ASSERT(bytesPerPixel >= 3); + + const int stride = (info.width * bytesPerPixel) + info.lineOffset; + + const char* ptr = + info.address + + info.initialOffset + + pos.y() * stride + + pos.x() * bytesPerPixel; + + // BGRA + pixel.setBlue(*ptr++); + pixel.setGreen(*ptr++); + pixel.setRed(*ptr++); + + if(bytesPerPixel == 4) + pixel.setAlpha(*ptr++); + } + return pixel; +} + +#endif // _DEBUG + QT_END_NAMESPACE diff --git a/src/3rdparty/phonon/mmf/utils.h b/src/3rdparty/phonon/mmf/utils.h index 5a26018..7db7831 100644 --- a/src/3rdparty/phonon/mmf/utils.h +++ b/src/3rdparty/phonon/mmf/utils.h @@ -22,6 +22,8 @@ along with this library. If not, see . #include #include // for RDebug +#include + #include "defs.h" QT_BEGIN_NAMESPACE @@ -51,6 +53,13 @@ void panic(PanicCode code); * type. If it is neither, the function returns MediaTypeUnknown. */ MediaType mimeTypeToMediaType(const TDesC& mimeType); + +#ifdef _DEBUG +/** + * Retrieve color of specified pixel from the screen. + */ +QColor getScreenPixel(const QPoint& pos); +#endif } /** diff --git a/src/plugins/phonon/mmf/plugin/plugin.pro b/src/plugins/phonon/mmf/plugin/plugin.pro index c7bb327d..d620453 100644 --- a/src/plugins/phonon/mmf/plugin/plugin.pro +++ b/src/plugins/phonon/mmf/plugin/plugin.pro @@ -63,6 +63,7 @@ SOURCES += \ debug { INCLUDEPATH += $$PHONON_MMF_DIR/mmfphonondebug LIBS += -lphonon_mmf_debug.lib + LIBS += -lhal } LIBS += -lmediaclientvideo # For CVideoPlayerUtility -- cgit v0.12