Add implementation of chromakey for layer
authorNobuhiko Tanibata <ntanibata@jp.adit-jv.com>
Sat, 4 Aug 2012 13:47:16 +0000 (22:47 +0900)
committerMichael Schuldt <michael.schuldt@bmw.de>
Wed, 12 Sep 2012 09:34:34 +0000 (11:34 +0200)
LayerManagerClient:
-Add members into structure of ilmLayerProperties to get status of chromakey by ilm_getPropertiesOfLayer
-ilm_layerSetChromaKey and modification of ilm_getPropertiesOfLayer to get properties of chromakey

GenericCommunicator:
-Add SetLayerChromaKey and GetPropertiesOfLayer

LayerManagerCommands:
-Add LayerSetChromaKeyCommand

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

index a9549a5..3fccaa9 100644 (file)
@@ -373,7 +373,6 @@ ilmErrorTypes ilm_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrie
  * \ingroup ilmClient
  * \param[in] layerId Id of layer.
  * \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 1eda3ec..ac85619 100644 (file)
@@ -214,6 +214,10 @@ struct ilmLayerProperties
     ilmOrientation orientation;  /*!< orientation value of the layer */
     t_ilm_bool visibility;       /*!< visibility value of the layer */
     t_ilm_uint type;             /*!< type of layer */
+    t_ilm_bool chromaKeyEnabled; /*!< chromakey validness of the layer */
+    t_ilm_uint chromaKeyRed;     /*!< chromakey's red value of the layer */
+    t_ilm_uint chromaKeyGreen;   /*!< chromakey's green value of the layer */
+    t_ilm_uint chromaKeyBlue;    /*!< chromakey's blue value of the layer */
 };
 
 
index af3d641..417dfac 100644 (file)
@@ -153,7 +153,12 @@ ilmErrorTypes ilm_getPropertiesOfLayer(t_ilm_uint layerID, struct ilmLayerProper
         && gIpcModule.getUint(&pLayerProperties->destHeight)
         && gIpcModule.getUint(&pLayerProperties->orientation)
         && gIpcModule.getBool(&pLayerProperties->visibility)
-        && gIpcModule.getUint(&pLayerProperties->type))
+        && gIpcModule.getUint(&pLayerProperties->type)
+        && gIpcModule.getBool(&pLayerProperties->chromaKeyEnabled)
+        && gIpcModule.getUint(&pLayerProperties->chromaKeyRed)
+        && gIpcModule.getUint(&pLayerProperties->chromaKeyGreen)
+        && gIpcModule.getUint(&pLayerProperties->chromaKeyBlue)
+        && gIpcModule.destroyMessage())        
     {
         returnValue = ILM_SUCCESS;
     }
@@ -683,12 +688,40 @@ ilmErrorTypes ilm_layerGetOrientation(t_ilm_layer layerId, ilmOrientation *pOrie
     return returnValue;
 }
 
-ilmErrorTypes ilm_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* color)
+ilmErrorTypes ilm_layerSetChromaKey(t_ilm_layer layerId, t_ilm_int* pColor)
 {
     LOG_ENTER_FUNCTION;
-    ilmErrorTypes error = ILM_FAILED;
-    // TODO: Implement this on both server and client
-    return error;
+    ilmErrorTypes returnValue = ILM_FAILED;
+
+    do
+    {
+        if (!gIpcModule.createMessage("SetLayerChromaKey\0")
+         || !gIpcModule.appendUint(layerId))
+        {
+            break;
+        }
+
+        if (pColor != NULL)
+        {
+            const t_ilm_uint n = 3;
+            if (!gIpcModule.appendUintArray(pColor, n))
+            {
+                break;
+            }
+        }
+
+        if (!gIpcModule.sendMessage()
+         || !gIpcModule.receiveMessage(gReceiveTimeout)
+         ||  gIpcModule.isErrorMessage())
+        {
+            break;
+        }
+
+        returnValue = ILM_SUCCESS;
+
+    } while (0);
+
+    return returnValue;
 }
 
 ilmErrorTypes ilm_layerSetRenderOrder(t_ilm_layer layerId, t_ilm_layer *pSurfaceId, t_ilm_int number)
diff --git a/LayerManagerCommands/include/LayerSetChromaKeyCommand.h b/LayerManagerCommands/include/LayerSetChromaKeyCommand.h
new file mode 100644 (file)
index 0000000..4a48916
--- /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 _LAYERSETCHROMAKEYCOMMAND_H_
+#define _LAYERSETCHROMAKEYCOMMAND_H_
+
+#include "BaseCommandAsynchronous.h"
+
+class LayerSetChromaKeyCommand : public BaseCommandAsynchronous
+{
+public:
+    /*!
+     * \action    This command sets the chroma key of a layer within the GENIVI LayerManagement
+     * \frequency Called in order to rearrange graphical output.
+     * \param[in] layer Id of the layer 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
+     */
+    LayerSetChromaKeyCommand(unsigned int layerid, unsigned int* array, unsigned  int length);
+
+    /**
+     * \brief default destructor
+     */
+    virtual ~LayerSetChromaKeyCommand() {}
+
+    /**
+     * \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_layerid;
+    unsigned int* m_array;
+    unsigned int m_length;
+};
+
+
+#endif /* _LAYERSETCHROMAKEYCOMMAND_H_ */
diff --git a/LayerManagerCommands/src/LayerSetChromaKeyCommand.cpp b/LayerManagerCommands/src/LayerSetChromaKeyCommand.cpp
new file mode 100644 (file)
index 0000000..507f846
--- /dev/null
@@ -0,0 +1,85 @@
+/***************************************************************************
+*
+* 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 "LayerSetChromaKeyCommand.h"
+#include "ICommandExecutor.h"
+#include "Scene.h"
+#include "Log.h"
+
+LayerSetChromaKeyCommand::LayerSetChromaKeyCommand(unsigned int layerid,unsigned int* array,unsigned  int length)
+: m_layerid(layerid)
+, m_array(array)
+, m_length(length)
+{
+}
+
+ExecutionResult LayerSetChromaKeyCommand::execute(ICommandExecutor* executor)
+{
+    Scene& scene = *(executor->getScene());
+
+    ExecutionResult result = ExecutionFailed;
+
+    Layer* layer = scene.getLayer(m_layerid);
+
+    if (NULL == m_array)
+    {
+        if (layer)
+        {
+            LOG_DEBUG("LayerSetChromaKeyCommand","new chromakey disable for id: " << m_layerid);
+            result = layer->setChromaKeyEnabled(false) ? ExecutionSuccessRedraw : ExecutionSuccess;
+        }
+    }
+    else
+    {
+        if (layer)
+        {
+            LOG_DEBUG("LayerSetChromaKeyCommand","new chromakey ("
+                << m_array[0] << ", " << m_array[1] << ", " << m_array[2] << ") for id: " << m_layerid);
+            bool ansSetEnabled = layer->setChromaKeyEnabled(true);
+            bool ansSetValues = layer->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 LayerSetChromaKeyCommand::getString()
+{
+    std::stringstream description;
+    description << "LayerSetChromaKeyCommand("
+                << "layerid=" << m_layerid
+                << ", m_array=[";
+
+    for (unsigned int i = 0; i < m_length; ++i)
+    {
+        description << m_array[i] << ",";
+    }
+    description << "], m_length=" << m_length
+                << ")";
+    return description.str();
+}
index 038e6e1..f64ae52 100644 (file)
@@ -155,6 +155,7 @@ private:
     void GetKeyboardFocusSurfaceId();
     void UpdateInputEventAcceptanceOn();
     void SetSurfaceChromaKey();
+    void SetLayerChromaKey();
 
 private:
     void RemoveApplicationReference(char* owner);
index 7af104d..fddabcc 100644 (file)
@@ -83,6 +83,7 @@
 #include "SurfaceGetKeyboardFocusCommand.h"
 #include "SurfaceUpdateInputEventAcceptance.h"
 #include "SurfaceSetChromaKeyCommand.h"
+#include "LayerSetChromaKeyCommand.h"
 
 #include <stdbool.h>
 #include <unistd.h>
@@ -192,6 +193,7 @@ GenericCommunicator::GenericCommunicator(ICommandExecutor* executor)
         { "GetKeyboardFocusSurfaceId",        &GenericCommunicator::GetKeyboardFocusSurfaceId },
         { "UpdateInputEventAcceptanceOn",     &GenericCommunicator::UpdateInputEventAcceptanceOn },
         { "SetSurfaceChromaKey",              &GenericCommunicator::SetSurfaceChromaKey },
+        { "SetLayerChromaKey",                &GenericCommunicator::SetLayerChromaKey },
     };
 
     int entryCount = sizeof(manager_methods) / sizeof(MethodTable);
@@ -654,6 +656,10 @@ void GenericCommunicator::GetPropertiesOfLayer()
         Rectangle dest = layer->getDestinationRegion();
         Rectangle src = layer->getSourceRegion();
         OrientationType orientation = layer->getOrientation();
+        unsigned char chromaKeyRed = 0;
+        unsigned char chromaKeyGreen = 0;
+        unsigned char chromaKeyBlue = 0;
+        layer->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
 
         m_ipcModule.createMessage((char*)__FUNCTION__);
         m_ipcModule.appendDouble(layer->getOpacity());
@@ -670,6 +676,10 @@ void GenericCommunicator::GetPropertiesOfLayer()
         m_ipcModule.appendUint(orientation);
         m_ipcModule.appendBool(layer->getVisibility());
         m_ipcModule.appendUint(layer->getLayerType());
+        m_ipcModule.appendBool(layer->getChromaKeyEnabled());
+        m_ipcModule.appendUint(chromaKeyRed);
+        m_ipcModule.appendUint(chromaKeyGreen);
+        m_ipcModule.appendUint(chromaKeyBlue);
         m_ipcModule.sendMessage();
     }
     else
@@ -2047,6 +2057,27 @@ void GenericCommunicator::SetSurfaceChromaKey()
     }
 }
 
+void GenericCommunicator::SetLayerChromaKey()
+{
+    uint* array = NULL;
+    int length = 0;
+    uint layerid = 0;
+
+    m_ipcModule.getUint(&layerid);
+    m_ipcModule.getUintArray(&array, &length);
+
+    t_ilm_bool status = m_executor->execute(new LayerSetChromaKeyCommand(layerid, 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);