Page 1 of 1

PythonMagick::ColorspaceType

Posted: 2014-03-17T06:30:40-07:00
by isedev
The MagickCore::ColorspaceType enum is not implemented in PythonMagick 0.9.9.

A quick search on the web shows that this has been an issue for some people, including myself, who wanted to perform colour quantisation using PythonMagick. I could not find any information online explaining why the enumeration was not provided as part of the interface.

In the hope it was just an omission and that I haven't missed some deeper meaning, here's a patch which exposes that enum in PythonMagick. I have perform limited testing of the functionality in Python and all seems well.

Example usage:

Code: Select all

import PythonMagick as pm
img = pm.Image()
img.read('/tmp/test.png')
img.quantizeColorSpace(pm.ColorspaceType.YUVColorspace)
img.quantizeColors(64)
img.quantize()
Patch:

Code: Select all

--- /dev/null
+++ b/pyste_src/ColorspaceType.pyste
@@ -0,0 +1 @@
+Enum("MagickCore::ColorspaceType", "Magick++/Include.h")

--- /dev/null
+++ b/pythonmagick_src/_ColorspaceType.cpp
@@ -0,0 +1,43 @@
+
+// Boost Includes =============================================================
+#include <boost/python.hpp>
+#include <boost/cstdint.hpp>
+
+// Includes ===================================================================
+#include <Magick++/Include.h>
+
+// Using ======================================================================
+using namespace boost::python;
+
+// Module =====================================================================
+void Export_pyste_src_ColorspaceType()
+{
+    enum_< MagickCore::ColorspaceType >("ColorspaceType")
+        .value("UndefinedColorspace", MagickCore::UndefinedColorspace)
+        .value("RGBColorspace", MagickCore::RGBColorspace)
+        .value("GRAYColorspace", MagickCore::GRAYColorspace)
+        .value("TransparentColorspace", MagickCore::TransparentColorspace)
+        .value("OHTAColorspace", MagickCore::OHTAColorspace)
+        .value("LabColorspace", MagickCore::LabColorspace)
+        .value("XYZColorspace", MagickCore::XYZColorspace)
+        .value("YCbCrColorspace", MagickCore::YCbCrColorspace)
+        .value("YCCColorspace", MagickCore::YCCColorspace)
+        .value("YIQColorspace", MagickCore::YIQColorspace)
+        .value("YPbPrColorspace", MagickCore::YPbPrColorspace)
+        .value("YUVColorspace", MagickCore::YUVColorspace)
+        .value("CMYKColorspace", MagickCore::CMYKColorspace)
+        .value("sRGBColorspace", MagickCore::sRGBColorspace)
+        .value("HSBColorspace", MagickCore::HSBColorspace)
+        .value("HSLColorspace", MagickCore::HSLColorspace)
+        .value("HWBColorspace", MagickCore::HWBColorspace)
+        .value("Rec601LumaColorspace", MagickCore::Rec601LumaColorspace)
+        .value("Rec601YCbCrColorspace", MagickCore::Rec601YCbCrColorspace)
+        .value("Rec709LumaColorspace", MagickCore::Rec709LumaColorspace)
+        .value("Rec709YCbCrColorspace", MagickCore::Rec709YCbCrColorspace)
+        .value("LogColorspace", MagickCore::LogColorspace)
+        .value("CMYColorspace", MagickCore::CMYColorspace)
+        .value("LuvColorspace", MagickCore::LuvColorspace)
+        .value("HCLColorspace", MagickCore::HCLColorspace)
+    ;
+}
+

--- a/pythonmagick_src/_main.cpp
+++ b/pythonmagick_src/_main.cpp
@@ -86,6 +86,7 @@ void Export_pyste_src_CompressionType();
 void Export_pyste_src_CompositeOperator();
 void Export_pyste_src_Color();
 void Export_pyste_src_Blob();
+void Export_pyste_src_ColorspaceType();

 // Module =====================================================================
 BOOST_PYTHON_MODULE(_PythonMagick)
@@ -174,4 +175,5 @@ BOOST_PYTHON_MODULE(_PythonMagick)
     Export_pyste_src_CompositeOperator();
     Export_pyste_src_Color();
     Export_pyste_src_Blob();
+    Export_pyste_src_ColorspaceType();
 }

--- a/PythonMagick/__init__.py
+++ b/PythonMagick/__init__.py
@@ -15,6 +15,9 @@ class Blob(_PythonMagick.Blob):
 class Color(_PythonMagick.Color):
    pass
 
+class ColorspaceType(_PythonMagick.ColorspaceType):
+    pass
+
 class CompositeOperator(_PythonMagick.CompositeOperator):
    pass

--- a/pythonmagick_src/Makefile.am
+++ b/pythonmagick_src/Makefile.am
@@ -84,6 +84,7 @@ libpymagick_la_SOURCES = _DrawableFillRule.cpp \
                                                 _DrawableMiterLimit.cpp \
                                                 _PathClosePath.cpp \
                                                 _PathSmoothCurvetoRel.cpp \
-                                                _PathLinetoHorizontalRel.cpp
+                                                _PathLinetoHorizontalRel.cpp \
+                                                _ColorspaceType.cpp

 libpymagick_la_CXXFLAGS = -I$(PYTHON_INCLUDE_DIR) $(BOOST_CPPFLAGS) $(MAGICKPP_CFLAGS)

Re: PythonMagick::ColorspaceType

Posted: 2014-03-17T09:54:07-07:00
by magick
We'll get your patch into PythonMagick 0.9.10 by sometime tomorrow. Thanks.