cl_3a_image_processor: connect 3a component into pipeline

 * make cl_image_processor clean and as base cl processor
 * integrate 3a components into CL3AImageProcessor
      blacklevel->hdr->demosaic->csc(nv12)
diff --git a/xcore/Makefile.am b/xcore/Makefile.am
index 8aa06f3..068f457 100644
--- a/xcore/Makefile.am
+++ b/xcore/Makefile.am
@@ -99,8 +99,9 @@
 	cl_memory.cpp            \
 	cl_image_handler.cpp     \
 	cl_image_processor.cpp   \
+	cl_3a_image_processor.cpp    \
 	cl_demo_handler.cpp      \
-        cl_blc_handler.cpp       \
+	cl_blc_handler.cpp       \
 	drm_bo_buffer.cpp        \
 	cl_hdr_handler.cpp       \
 	cl_demosaic_handler.cpp  \
diff --git a/xcore/cl_3a_image_processor.cpp b/xcore/cl_3a_image_processor.cpp
new file mode 100644
index 0000000..f44df20
--- /dev/null
+++ b/xcore/cl_3a_image_processor.cpp
@@ -0,0 +1,132 @@
+/*
+ * cl_3a_image_processor.cpp - CL 3A image processor
+ *
+ *  Copyright (c) 2015 Intel Corporation
+ *
+ * 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.
+ *
+ * Author: Wind Yuan <feng.yuan@intel.com>
+ */
+#include "cl_3a_image_processor.h"
+#include "cl_context.h"
+#include "cl_blc_handler.h"
+#include "cl_demosaic_handler.h"
+#include "cl_csc_handler.h"
+#include "cl_hdr_handler.h"
+
+namespace XCam {
+
+CL3aImageProcessor::CL3aImageProcessor ()
+    : CLImageProcessor ("CL3aImageProcessor")
+    , _output_fourcc (V4L2_PIX_FMT_NV12)
+    , _enable_hdr (false)
+{
+    XCAM_LOG_DEBUG ("CL3aImageProcessor constructed");
+}
+
+CL3aImageProcessor::~CL3aImageProcessor ()
+{
+    XCAM_LOG_DEBUG ("CL3aImageProcessor destructed");
+}
+
+bool
+CL3aImageProcessor::set_output_format (uint32_t fourcc)
+{
+    XCAM_FAIL_RETURN (
+        WARNING,
+        fourcc == V4L2_PIX_FMT_NV12 || fourcc == V4L2_PIX_FMT_RGB32,
+        false,
+        "CL3aImageProcessor doesn't support format(%s) output",
+        xcam_fourcc_to_string (fourcc));
+
+    _output_fourcc = fourcc;
+    return true;
+}
+
+bool
+CL3aImageProcessor::can_process_result (SmartPtr<X3aResult> &result)
+{
+    XCAM_UNUSED (result);
+    return false;
+}
+
+XCamReturn
+CL3aImageProcessor::apply_3a_results (X3aResultList &results)
+{
+    XCAM_UNUSED (results);
+    return XCAM_RETURN_NO_ERROR;
+}
+
+XCamReturn
+CL3aImageProcessor::apply_3a_result (SmartPtr<X3aResult> &result)
+{
+    XCAM_UNUSED (result);
+    return XCAM_RETURN_NO_ERROR;
+}
+
+XCamReturn
+CL3aImageProcessor::create_handlers ()
+{
+    SmartPtr<CLImageHandler> image_handler;
+    SmartPtr<CLContext> context = get_cl_context ();
+
+    XCAM_ASSERT (context.ptr ());
+
+    /* black leve as first */
+    image_handler = create_cl_blc_image_handler (context);
+    _black_level = image_handler;
+    XCAM_FAIL_RETURN (
+        WARNING,
+        image_handler.ptr (),
+        XCAM_RETURN_ERROR_CL,
+        "CL3aImageProcessor create blc handler failed");
+    add_handler (image_handler);
+
+    /* demosaic */
+    image_handler = create_cl_demosaic_image_handler (context);
+    _demosaic = image_handler.dynamic_cast_ptr<CLBayer2RGBImageHandler> ();
+    XCAM_FAIL_RETURN (
+        WARNING,
+        _demosaic.ptr (),
+        XCAM_RETURN_ERROR_CL,
+        "CL3aImageProcessor create demosaic handler failed");
+    add_handler (image_handler);
+
+    /* hdr */
+    if (_enable_hdr) {
+        image_handler = create_cl_hdr_image_handler (context);
+        _hdr = image_handler;
+        XCAM_FAIL_RETURN (
+            WARNING,
+            _hdr.ptr (),
+            XCAM_RETURN_ERROR_CL,
+            "CL3aImageProcessor create hdr handler failed");
+        add_handler (image_handler);
+    }
+
+    /* color space conversion */
+    if (_output_fourcc == V4L2_PIX_FMT_NV12) {
+        image_handler = create_cl_csc_image_handler (context);
+        _csc = image_handler.dynamic_cast_ptr<CLRgba2Nv12ImageHandler> ();
+        XCAM_FAIL_RETURN (
+            WARNING,
+            _csc .ptr (),
+            XCAM_RETURN_ERROR_CL,
+            "CL3aImageProcessor create csc handler failed");
+        add_handler (image_handler);
+    }
+
+    return XCAM_RETURN_NO_ERROR;
+}
+
+};
diff --git a/xcore/cl_3a_image_processor.h b/xcore/cl_3a_image_processor.h
new file mode 100644
index 0000000..8264619
--- /dev/null
+++ b/xcore/cl_3a_image_processor.h
@@ -0,0 +1,66 @@
+/*
+ * cl_3a_image_processor.h - CL 3A image processor
+ *
+ *  Copyright (c) 2015 Intel Corporation
+ *
+ * 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.
+ *
+ * Author: Wind Yuan <feng.yuan@intel.com>
+ */
+
+#ifndef XCAM_CL_3A_IMAGE_PROCESSOR_H
+#define XCAM_CL_3A_IMAGE_PROCESSOR_H
+
+#include "xcam_utils.h"
+#include "cl_image_processor.h"
+
+namespace XCam {
+
+class CLBayer2RGBImageHandler;
+class CLRgba2Nv12ImageHandler;
+
+class CL3aImageProcessor
+    : public CLImageProcessor
+{
+public:
+    explicit CL3aImageProcessor ();
+    virtual ~CL3aImageProcessor ();
+
+    bool set_output_format (uint32_t fourcc);
+    void set_hdr (bool enable) {
+        _enable_hdr = enable;
+    }
+
+protected:
+
+    //derive from ImageProcessor
+    virtual bool can_process_result (SmartPtr<X3aResult> &result);
+    virtual XCamReturn apply_3a_results (X3aResultList &results);
+    virtual XCamReturn apply_3a_result (SmartPtr<X3aResult> &result);
+
+private:
+    virtual XCamReturn create_handlers ();
+    XCAM_DEAD_COPY (CL3aImageProcessor);
+
+private:
+    uint32_t                           _output_fourcc;
+    bool                               _enable_hdr;
+
+    SmartPtr<CLImageHandler>           _black_level;
+    SmartPtr<CLBayer2RGBImageHandler>  _demosaic;
+    SmartPtr<CLImageHandler>           _hdr;
+    SmartPtr<CLRgba2Nv12ImageHandler>  _csc;
+};
+
+};
+#endif //XCAM_CL_3A_IMAGE_PROCESSOR_H
\ No newline at end of file
diff --git a/xcore/cl_image_processor.cpp b/xcore/cl_image_processor.cpp
index eac91f8..8cf30c8 100644
--- a/xcore/cl_image_processor.cpp
+++ b/xcore/cl_image_processor.cpp
@@ -28,8 +28,8 @@
 
 namespace XCam {
 
-CLImageProcessor::CLImageProcessor ()
-    : ImageProcessor ("CLImageProcessor")
+CLImageProcessor::CLImageProcessor (const char* name)
+    : ImageProcessor (name ? name : "CLImageProcessor")
 {
     _context = CLDevice::instance ()->get_context ();
     XCAM_ASSERT (_context.ptr());
@@ -49,6 +49,11 @@
     return true;
 }
 
+SmartPtr<CLContext>
+CLImageProcessor::get_cl_context ()
+{
+    return _context;
+}
 
 bool
 CLImageProcessor::can_process_result (SmartPtr<X3aResult> &result)
@@ -117,15 +122,6 @@
         "CLImageProcessor create demo handler failed");
     add_handler (demo_handler);
 
-    SmartPtr<CLImageHandler> blc_handler;
-    blc_handler = create_cl_blc_image_handler (_context);
-    XCAM_FAIL_RETURN (
-        WARNING,
-        blc_handler.ptr (),
-        XCAM_RETURN_ERROR_CL,
-        "CLImageProcessor create blc handler failed");
-    add_handler (blc_handler);
-
     return XCAM_RETURN_NO_ERROR;
 }
 
diff --git a/xcore/cl_image_processor.h b/xcore/cl_image_processor.h
index 53e478e..75b1f85 100644
--- a/xcore/cl_image_processor.h
+++ b/xcore/cl_image_processor.h
@@ -35,18 +35,21 @@
 {
     typedef std::list<SmartPtr<CLImageHandler>>  ImageHandlerList;
 public:
-    explicit CLImageProcessor ();
+    explicit CLImageProcessor (const char* name = NULL);
     virtual ~CLImageProcessor ();
 
-protected:
     bool add_handler (SmartPtr<CLImageHandler> &handler);
 
+protected:
+
     //derive from ImageProcessor
     virtual bool can_process_result (SmartPtr<X3aResult> &result);
     virtual XCamReturn apply_3a_results (X3aResultList &results);
     virtual XCamReturn apply_3a_result (SmartPtr<X3aResult> &result);
     virtual XCamReturn process_buffer (SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output);
 
+    SmartPtr<CLContext> get_cl_context ();
+
 private:
     virtual XCamReturn create_handlers ();
     XCAM_DEAD_COPY (CLImageProcessor);