Add implmentation of chromakey for surface
authorNobuhiko Tanibata <ntanibata@jp.adit-jv.com>
Thu, 26 Jul 2012 05:55:40 +0000 (14:55 +0900)
committerMichael Schuldt <michael.schuldt@bmw.de>
Wed, 12 Sep 2012 09:34:00 +0000 (11:34 +0200)
LayerManagerClient:
-Add members into structure of ilmSurfaceProperties to get status of chromakey by ilm_getPropertiesOfSurface
-ilm_surfaceSetChromaKey and Modification of ilm_getPropertiesOfSurface to get properties of chromakey

GenericCommunicator:
-Add SetSurfaceChromaKey and GetPropertiesOfSurface

LayerManagerService
-Add colorkey's methods and valiables to GraphicalObject

LayerManagerPlugins
-Add SurfaceSetChromakeyCommand

LayerManagerClient/ilmClient/include/ilm_client.h
LayerManagerClient/ilmClient/include/ilm_types.h
LayerManagerClient/ilmClient/src/generic_ilm_client.c
LayerManagerCommands/include/SurfaceSetChromaKeyCommand.h [new file with mode: 0644]
LayerManagerCommands/src/SurfaceSetChromaKeyCommand.cpp [new file with mode: 0644]
LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h
LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp
LayerManagerService/include/GraphicalObject.h

index 5deeb94..a9549a5 100644 (file)
@@ -684,7 +684,6 @@ ilmErrorTypes ilm_surfaceGetPixelformat(t_ilm_layer surfaceId, ilmPixelFormat *p
  * \ingroup ilmClient
  * \param[in] surfaceId Id of the surface to set the chromakey of.
  * \param[in] pColor array of the color value which is defined in red, green, blue
- * \todo This method is currently not implemented.
  * \return ILM_SUCCESS if the method call was successful
  * \return ILM_FAILED if the client can not call the method on the service.
  */
index 7194b17..1eda3ec 100644 (file)
@@ -1,6 +1,7 @@
 /***************************************************************************
 *
 * Copyright 2010,2011 BMW Car IT GmbH
+* Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -187,6 +188,10 @@ struct ilmSurfaceProperties
     t_ilm_uint pixelformat;                 /*!< pixel format of surface */
     t_ilm_uint nativeSurface;               /*!< native surface handle of surface */
     ilmInputDevice inputDevicesAcceptance;  /*!< bitmask of ilmInputDevice from which the surface can accept input events */
+    t_ilm_bool chromaKeyEnabled;            /*!< chromakey validness of the surface */
+    t_ilm_uint chromaKeyRed;                /*!< chromakey's red value of the surface */
+    t_ilm_uint chromaKeyGreen;              /*!< chromakey's green value of the surface */
+    t_ilm_uint chromaKeyBlue;               /*!< chromakey's blue value of the surface */
 };
 
 /**
index ba52fa4..af3d641 100644 (file)
@@ -1,7 +1,7 @@
 /**************************************************************************
  *
  * Copyright 2012 BMW Car IT GmbH
- *
+ * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
  *
  * Licensed under the Apache License, Version 2.0 (the "License\0");
  * you may not use this file except in compliance with the License.
@@ -117,7 +117,11 @@ ilmErrorTypes ilm_getPropertiesOfSurface(t_ilm_uint surfaceID, struct ilmSurface
         && gIpcModule.getUint(&pSurfaceProperties->updateCounter)
         && gIpcModule.getUint(&pSurfaceProperties->pixelformat)
         && gIpcModule.getUint(&pSurfaceProperties->nativeSurface)
-        && gIpcModule.getUint(&pSurfaceProperties->inputDevicesAcceptance))
+        && gIpcModule.getUint(&pSurfaceProperties->inputDevicesAcceptance)
+        && gIpcModule.getBool(&pSurfaceProperties->chromaKeyEnabled)
+        && gIpcModule.getUint(&pSurfaceProperties->chromaKeyRed)
+        && gIpcModule.getUint(&pSurfaceProperties->chromaKeyGreen)
+        && gIpcModule.getUint(&pSurfaceProperties->chromaKeyBlue))
     {
         returnValue = ILM_SUCCESS;
     }
@@ -1249,11 +1253,36 @@ ilmErrorTypes ilm_surfaceGetPixelformat(t_ilm_layer surfaceId, ilmPixelFormat *p
 ilmErrorTypes ilm_surfaceSetChromaKey(t_ilm_surface surfaceId, t_ilm_int* pColor)
 {
     LOG_ENTER_FUNCTION;
-    ilmErrorTypes error = ILM_FAILED;
+    ilmErrorTypes returnValue = ILM_FAILED;
+    do
+    {
+        if (!gIpcModule.createMessage("SetSurfaceChromaKey\0")
+            || !gIpcModule.appendUint(surfaceId))
+        {
+            break;
+        }
 
-    // TODO: Implement this on both server and client
+        if (NULL != pColor)
+        {
+            const t_ilm_uint number = 3;
+            if (!gIpcModule.appendUintArray(pColor, number))
+            {
+                break;
+            }
+        }
 
-    return error;
+        if (!gIpcModule.sendMessage()
+        || !gIpcModule.receiveMessage(gReceiveTimeout)
+        || gIpcModule.isErrorMessage())
+        {
+            break;
+        }
+
+        returnValue = ILM_SUCCESS;
+
+    } while(0);
+
+    return returnValue;
 }
 
 ilmErrorTypes ilm_surfaceInvalidateRectangle(t_ilm_surface surfaceId)
diff --git a/LayerManagerCommands/include/SurfaceSetChromaKeyCommand.h b/LayerManagerCommands/include/SurfaceSetChromaKeyCommand.h
new file mode 100644 (file)
index 0000000..65e564b
--- /dev/null
@@ -0,0 +1,67 @@
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+* Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*        http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+
+#ifndef _SURFACESETCHROMAKEYCOMMAND_H_
+#define _SURFACESETCHROMAKEYCOMMAND_H_
+
+#include "BaseCommandAsynchronous.h"
+
+class SurfaceSetChromaKeyCommand : public BaseCommandAsynchronous
+{
+public:
+    /*!
+     * \action    This command sets the chroma key of a surface within the GENIVI LayerManagement
+     * \frequency Called in order to rearrange graphical output.
+     * \param[in] surfaceId Id of the surface to set the chromakey of.
+     * \param[in] array array of color value which is defined in red, green, blue
+     * \param[in] length length of array provided as argument array
+     * \ingroup Commands
+     */
+    SurfaceSetChromaKeyCommand(unsigned int surfaceid, unsigned int* array, unsigned  int length);
+
+    /**
+     * \brief default destructor
+     */
+    virtual ~SurfaceSetChromaKeyCommand() {}
+
+    /**
+     * \brief Execute this command.
+     * \param[in] executor Pointer to instance executing the LayerManagement Commands
+     * \return ExecutionSuccess: execution successful
+     * \return ExecutionSuccessRedraw: execution successful and screen needs to be redrawn
+     * \return ExecutionFailed: execution failed
+     * \return ExecutionFailedRedraw: execution unsuccessful and screen needs to be redrawn
+     */
+    virtual ExecutionResult execute(ICommandExecutor* executor);
+
+    /**
+     * \brief Get description string for this command.
+     * \return String object with description of this command object
+     */
+    virtual const std::string getString();
+
+private:
+    const unsigned int m_surfaceid;
+    unsigned int* m_array;
+    unsigned int m_length;
+};
+
+
+#endif /* _SURFACESETCHROMAKEYCOMMAND_H_ */
diff --git a/LayerManagerCommands/src/SurfaceSetChromaKeyCommand.cpp b/LayerManagerCommands/src/SurfaceSetChromaKeyCommand.cpp
new file mode 100644 (file)
index 0000000..1f35960
--- /dev/null
@@ -0,0 +1,84 @@
+/***************************************************************************
+*
+* Copyright 2010,2011 BMW Car IT GmbH
+* Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*        http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+****************************************************************************/
+#include "SurfaceSetChromaKeyCommand.h"
+#include "ICommandExecutor.h"
+#include "Scene.h"
+#include "Log.h"
+
+SurfaceSetChromaKeyCommand::SurfaceSetChromaKeyCommand(unsigned int surfaceid,unsigned int* array,unsigned  int length)
+: m_surfaceid(surfaceid)
+, m_array(array)
+, m_length(length)
+{
+}
+
+ExecutionResult SurfaceSetChromaKeyCommand::execute(ICommandExecutor* executor)
+{
+    Scene& scene = *(executor->getScene());
+
+    ExecutionResult result = ExecutionFailed;
+
+    Surface* surface = scene.getSurface(m_surfaceid);
+
+    if (NULL == m_array)
+    {
+        if (surface)
+        {
+            LOG_DEBUG("SurfaceSetChromaKeyCommand","new chromakey disable for id: " << m_surfaceid);
+            result = surface->setChromaKeyEnabled(false) ? ExecutionSuccessRedraw : ExecutionSuccess;
+        }
+    }
+    else
+    {
+        if (surface)
+        {
+            LOG_DEBUG("SurfaceSetChromaKeyCommand","new chromakey (" << m_array[0] << ", " << m_array[1] << ", " << m_array[2] << ") for id: " << m_surfaceid);
+            bool ansSetEnabled = surface->setChromaKeyEnabled(true);
+            bool ansSetValues = surface->setChromaKey((unsigned char)m_array[0], (unsigned char)m_array[1], (unsigned char)m_array[2]);
+            if ((true == ansSetEnabled) | (true == ansSetValues))
+            {
+                result = ExecutionSuccessRedraw;
+            }
+            else
+            {
+                result = ExecutionSuccess;
+            }
+        }
+        delete[] m_array;
+    }
+
+    return result;
+}
+
+const std::string SurfaceSetChromaKeyCommand::getString()
+{
+    std::stringstream description;
+    description << "SurfaceSetChromaKeyCommand("
+                << "surfaceid=" << m_surfaceid
+                << ", m_array=[";
+
+    for (unsigned int i = 0; i < m_length; ++i)
+    {
+        description << m_array[i] << ",";
+    }
+    description << "], m_length=" << m_length
+                << ")";
+    return description.str();
+}
index c7743e4..038e6e1 100644 (file)
@@ -1,6 +1,7 @@
 /***************************************************************************
  *
  * Copyright 2012 BMW Car IT GmbH
+ * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -153,6 +154,7 @@ private:
     void SetKeyboardFocusOn();
     void GetKeyboardFocusSurfaceId();
     void UpdateInputEventAcceptanceOn();
+    void SetSurfaceChromaKey();
 
 private:
     void RemoveApplicationReference(char* owner);
index 9fdbd36..7af104d 100644 (file)
@@ -1,5 +1,6 @@
 /***************************************************************************
  * Copyright 2012 BMW Car IT GmbH
+ * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,6 +82,7 @@
 #include "SurfaceSetKeyboardFocusCommand.h"
 #include "SurfaceGetKeyboardFocusCommand.h"
 #include "SurfaceUpdateInputEventAcceptance.h"
+#include "SurfaceSetChromaKeyCommand.h"
 
 #include <stdbool.h>
 #include <unistd.h>
@@ -188,7 +190,8 @@ GenericCommunicator::GenericCommunicator(ICommandExecutor* executor)
         { "SetUniforms",                      &GenericCommunicator::SetUniforms },
         { "SetKeyboardFocusOn",               &GenericCommunicator::SetKeyboardFocusOn },
         { "GetKeyboardFocusSurfaceId",        &GenericCommunicator::GetKeyboardFocusSurfaceId },
-        { "UpdateInputEventAcceptanceOn",     &GenericCommunicator::UpdateInputEventAcceptanceOn }
+        { "UpdateInputEventAcceptanceOn",     &GenericCommunicator::UpdateInputEventAcceptanceOn },
+        { "SetSurfaceChromaKey",              &GenericCommunicator::SetSurfaceChromaKey },
     };
 
     int entryCount = sizeof(manager_methods) / sizeof(MethodTable);
@@ -603,6 +606,10 @@ void GenericCommunicator::GetPropertiesOfSurface()
         Rectangle dest = surface->getDestinationRegion();
         Rectangle src = surface->getSourceRegion();
         OrientationType orientation = surface->getOrientation();
+        unsigned char chromaKeyRed = 0;
+        unsigned char chromaKeyGreen = 0;
+        unsigned char chromaKeyBlue = 0;
+        surface->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
 
         m_ipcModule.createMessage((char*)__FUNCTION__);
         m_ipcModule.appendDouble(surface->getOpacity());
@@ -624,6 +631,10 @@ void GenericCommunicator::GetPropertiesOfSurface()
         m_ipcModule.appendUint(surface->getPixelFormat());
         m_ipcModule.appendUint(surface->getNativeContent());
         m_ipcModule.appendUint(surface->getInputEventAcceptanceOnDevices());
+        m_ipcModule.appendBool(surface->getChromaKeyEnabled());
+        m_ipcModule.appendUint(chromaKeyRed);
+        m_ipcModule.appendUint(chromaKeyGreen);
+        m_ipcModule.appendUint(chromaKeyBlue);
         m_ipcModule.sendMessage();
     }
     else
@@ -2015,6 +2026,27 @@ void GenericCommunicator::UpdateInputEventAcceptanceOn()
     }
 }
 
+void GenericCommunicator::SetSurfaceChromaKey()
+{
+    uint* array = NULL;
+    int length = 0;
+    uint surfaceid = 0;
+
+    m_ipcModule.getUint(&surfaceid);
+    m_ipcModule.getUintArray(&array, &length);
+
+    t_ilm_bool status = m_executor->execute(new SurfaceSetChromaKeyCommand(surfaceid, array, length));
+    if (status)
+    {
+        m_ipcModule.createMessage((char*)__FUNCTION__);
+        m_ipcModule.sendMessage();
+    }
+    else
+    {
+        m_ipcModule.sendError(RESSOURCE_NOT_FOUND);
+    }
+}
+
 extern "C" ICommunicator* createGenericCommunicator(ICommandExecutor* executor)
 {
     return new GenericCommunicator(executor);
index a830696..2c05d66 100644 (file)
@@ -1,6 +1,7 @@
 /***************************************************************************
  *
  * Copyright 2010,2011 BMW Car IT GmbH
+ * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
  *
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,6 +53,38 @@ public:
     double getOpacity() const;
 
     /**
+     * @brief Set chroma key enabled value
+     * @param[in] newEnabled The new ChromaKey enable (true) or disable (false)
+     * @return TRUE if the new ChromaKey Enabled Value are not equal to the current Value
+     *         FALSE if they are equal
+     */
+    virtual bool setChromaKeyEnabled(bool newEnabled);
+
+    /**
+     * @brief Get chroma key enabled value
+     * @return The current chromakey enable (true) or disable (false)
+     */
+    bool getChromaKeyEnabled() const;
+
+    /**
+     * @brief Set chroma key
+     * @param[in] newRed The new Red Value between 0 and 255
+     * @param[in] newGreen The new Green Value between 0 and 255
+     * @param[in] newBlue The new Blue Value between 0 and 255
+     * @return TRUE if the new ChromaKey Values are not equal to the current ChromaKey Values
+     *         FALSE if they are equal
+     */
+    virtual bool setChromaKey(unsigned char newRed, unsigned char newGreen, unsigned char newBlue);
+
+    /**
+     * @brief Get chroma key values
+     * @param[out] The current Red Value between 0 and 255
+     * @param[out] The current Green Value between 0 and 255
+     * @param[out] The current Blue Value between 0 and 255
+     */
+    void getChromaKey(unsigned char& red, unsigned char& green, unsigned char& blue) const;
+
+    /**
      * Set the visibility
      * @param[in] newVisibility set this object visible (true) or invisible (false)
      * @return TRUE if the new visiblity value is not equal to the current visibility value
@@ -92,6 +125,10 @@ public:
     Shader* shader;
     double opacity;
     bool visibility;
+    bool chromaKeyEnabled;
+    unsigned char chromaKeyRed;
+    unsigned char chromaKeyGreen;
+    unsigned char chromaKeyBlue;
 
 protected:
     unsigned int graphicInternalId;
@@ -108,6 +145,10 @@ inline GraphicalObject::GraphicalObject(ObjectType type, double opacity, bool vi
 , shader(0)
 , opacity(opacity)
 , visibility(visibility)
+, chromaKeyEnabled(false)
+, chromaKeyRed(0)
+, chromaKeyGreen(0)
+, chromaKeyBlue(0)
 , graphicInternalId(nextGraphicId[type]++)
 {
     graphicExternalId = graphicInternalId;
@@ -120,6 +161,10 @@ inline GraphicalObject::GraphicalObject(int externalId, ObjectType type, double
 , shader(0)
 , opacity(opacity)
 , visibility(visibility)
+, chromaKeyEnabled(false)
+, chromaKeyRed(0)
+, chromaKeyGreen(0)
+, chromaKeyBlue(0)
 , graphicInternalId(nextGraphicId[type]++)
 , graphicExternalId(externalId)
 {
@@ -157,6 +202,42 @@ inline bool GraphicalObject::getVisibility() const
     return visibility;
 }
 
+inline bool GraphicalObject::setChromaKeyEnabled(bool newEnabled)
+{
+    if (chromaKeyEnabled != newEnabled)
+    {
+        chromaKeyEnabled = newEnabled;
+        renderPropertyChanged = true;
+        return true;
+    }
+    return false;
+}
+
+inline bool GraphicalObject::getChromaKeyEnabled() const
+{
+    return chromaKeyEnabled;
+}
+
+inline bool GraphicalObject::setChromaKey(unsigned char newRed, unsigned char newGreen, unsigned char newBlue)
+{
+    if ((chromaKeyRed != newRed) || (chromaKeyGreen != newGreen) || (chromaKeyBlue != newBlue))
+    {
+        chromaKeyRed = newRed;
+        chromaKeyGreen = newGreen;
+        chromaKeyBlue = newBlue;
+        renderPropertyChanged = true;
+        return true;
+    }
+    return false;
+}
+
+inline void GraphicalObject::getChromaKey(unsigned char& red, unsigned char& green, unsigned char& blue) const
+{
+    red = chromaKeyRed;
+    green = chromaKeyGreen;
+    blue = chromaKeyBlue;
+}
+
 inline unsigned int GraphicalObject::getID()
 {
     return graphicExternalId;