Prechádzať zdrojové kódy

Remove indentation around 'imshow()' functions

The code had 1-2 extra levels of indentation.
Benno Evers 5 rokov pred
rodič
commit
d283d47d08
1 zmenil súbory, kde vykonal 65 pridanie a 63 odobranie
  1. 65 63
      matplotlibcpp.h

+ 65 - 63
matplotlibcpp.h

@@ -589,77 +589,79 @@ bool hist(const std::vector<Numeric>& y, long bins=10,std::string color="b",
 }
 
 #ifndef WITHOUT_NUMPY
-    namespace internal {
-        inline void imshow(void *ptr, const NPY_TYPES type, const int rows, const int columns, const int colors, const std::map<std::string, std::string> &keywords, PyObject** out)
-        {
-            assert(type == NPY_UINT8 || type == NPY_FLOAT);
-            assert(colors == 1 || colors == 3 || colors == 4);
-
-            detail::_interpreter::get();    //interpreter needs to be initialized for the numpy commands to work
-
-            // construct args
-            npy_intp dims[3] = { rows, columns, colors };
-            PyObject *args = PyTuple_New(1);
-            PyTuple_SetItem(args, 0, PyArray_SimpleNewFromData(colors == 1 ? 2 : 3, dims, type, ptr));
-
-            // construct keyword args
-            PyObject* kwargs = PyDict_New();
-            for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
-            {
-                PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
-            }
-
-            PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_imshow, args, kwargs);
-            Py_DECREF(args);
-            Py_DECREF(kwargs);
-            if (!res)
-                throw std::runtime_error("Call to imshow() failed");
-            if (out)
-                *out = res;
-            else
-                Py_DECREF(res);
-        }
-    }
+namespace internal {
 
-    inline void imshow(const unsigned char *ptr, const int rows, const int columns, const int colors, const std::map<std::string, std::string> &keywords = {}, PyObject** out = nullptr)
-    {
-        internal::imshow((void *) ptr, NPY_UINT8, rows, columns, colors, keywords, out);
-    }
+inline void imshow(void *ptr, const NPY_TYPES type, const int rows, const int columns, const int colors, const std::map<std::string, std::string> &keywords, PyObject** out)
+{
+    assert(type == NPY_UINT8 || type == NPY_FLOAT);
+    assert(colors == 1 || colors == 3 || colors == 4);
+
+    detail::_interpreter::get();    //interpreter needs to be initialized for the numpy commands to work
 
-    inline void imshow(const float *ptr, const int rows, const int columns, const int colors, const std::map<std::string, std::string> &keywords = {}, PyObject** out = nullptr)
+    // construct args
+    npy_intp dims[3] = { rows, columns, colors };
+    PyObject *args = PyTuple_New(1);
+    PyTuple_SetItem(args, 0, PyArray_SimpleNewFromData(colors == 1 ? 2 : 3, dims, type, ptr));
+
+    // construct keyword args
+    PyObject* kwargs = PyDict_New();
+    for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
     {
-        internal::imshow((void *) ptr, NPY_FLOAT, rows, columns, colors, keywords, out);
+        PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
     }
 
-#ifdef WITH_OPENCV
-    void imshow(const cv::Mat &image, const std::map<std::string, std::string> &keywords = {})
-    {
-        // Convert underlying type of matrix, if needed
-        cv::Mat image2;
-        NPY_TYPES npy_type = NPY_UINT8;
-        switch (image.type() & CV_MAT_DEPTH_MASK) {
-        case CV_8U:
-            image2 = image;
-            break;
-        case CV_32F:
-            image2 = image;
-            npy_type = NPY_FLOAT;
-            break;
-        default:
-            image.convertTo(image2, CV_MAKETYPE(CV_8U, image.channels()));
-        }
+    PyObject *res = PyObject_Call(detail::_interpreter::get().s_python_function_imshow, args, kwargs);
+    Py_DECREF(args);
+    Py_DECREF(kwargs);
+    if (!res)
+        throw std::runtime_error("Call to imshow() failed");
+    if (out)
+        *out = res;
+    else
+        Py_DECREF(res);
+}
 
-        // If color image, convert from BGR to RGB
-        switch (image2.channels()) {
-        case 3:
-            cv::cvtColor(image2, image2, CV_BGR2RGB);
-            break;
-        case 4:
-            cv::cvtColor(image2, image2, CV_BGRA2RGBA);
-        }
+} // namespace internal
+
+inline void imshow(const unsigned char *ptr, const int rows, const int columns, const int colors, const std::map<std::string, std::string> &keywords = {}, PyObject** out = nullptr)
+{
+    internal::imshow((void *) ptr, NPY_UINT8, rows, columns, colors, keywords, out);
+}
 
-        internal::imshow(image2.data, npy_type, image2.rows, image2.cols, image2.channels(), keywords);
+inline void imshow(const float *ptr, const int rows, const int columns, const int colors, const std::map<std::string, std::string> &keywords = {}, PyObject** out = nullptr)
+{
+    internal::imshow((void *) ptr, NPY_FLOAT, rows, columns, colors, keywords, out);
+}
+
+#ifdef WITH_OPENCV
+void imshow(const cv::Mat &image, const std::map<std::string, std::string> &keywords = {})
+{
+    // Convert underlying type of matrix, if needed
+    cv::Mat image2;
+    NPY_TYPES npy_type = NPY_UINT8;
+    switch (image.type() & CV_MAT_DEPTH_MASK) {
+    case CV_8U:
+        image2 = image;
+        break;
+    case CV_32F:
+        image2 = image;
+        npy_type = NPY_FLOAT;
+        break;
+    default:
+        image.convertTo(image2, CV_MAKETYPE(CV_8U, image.channels()));
     }
+
+    // If color image, convert from BGR to RGB
+    switch (image2.channels()) {
+    case 3:
+        cv::cvtColor(image2, image2, CV_BGR2RGB);
+        break;
+    case 4:
+        cv::cvtColor(image2, image2, CV_BGRA2RGBA);
+    }
+
+    internal::imshow(image2.data, npy_type, image2.rows, image2.cols, image2.channels(), keywords);
+}
 #endif // WITH_OPENCV
 #endif // WITHOUT_NUMPY