r22775 by jghali - #15485: add getImageColorSpace python function <dockattt>

scribus-commit scribus-commit at lists.scribus.net
Fri Nov 23 00:21:59 UTC 2018


Author: jghali
Date: Fri Nov 23 00:21:59 2018
New Revision: 22775

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22775
Log:
#15485: add getImageColorSpace python function <dockattt>

Modified:
    trunk/Scribus/doc/en/scripterapi-constants.html
    trunk/Scribus/doc/en/scripterapi-getobjprop.html
    trunk/Scribus/doc/fr/scripterapi-constants.html
    trunk/Scribus/doc/fr/scripterapi-getobjprop.html
    trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
    trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp

Modified: trunk/Scribus/doc/en/scripterapi-constants.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/doc/en/scripterapi-constants.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-constants.html	(original)
+++ trunk/Scribus/doc/en/scripterapi-constants.html	Fri Nov 23 00:21:59 2018
@@ -254,6 +254,18 @@
 </dl>
 </td></tr></table>
 
+<h4>Colorspace Definitions: </h4>
+<table><tr><td>
+<dl>
+	<dt>CSPACE_UNDEFINED</dt>
+	<dt>CSPACE_RGB</dt>
+	<dt>CSPACE_CMYK</dt>
+	<dt>CSPACE_GRAY</dt>
+	<dt>CSPACE_DUOTONE</dt>
+	<dt>CSPACE_MONOCHROME</dt>
+</dl>
+</td></tr></table>
+
 <h4>Fill related Definitions: </h4>
 <table><tr><td>
 <dl>

Modified: trunk/Scribus/doc/en/scripterapi-getobjprop.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/doc/en/scripterapi-getobjprop.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-getobjprop.html	(original)
+++ trunk/Scribus/doc/en/scripterapi-getobjprop.html	Fri Nov 23 00:21:59 2018
@@ -38,6 +38,20 @@
 <dt><a name="-getFillTransparency"><strong>getFillTransparency</strong>(...)</a></dt>
 <dd><code>getFillTransparency(["name"]) -> float</code>
 <p>Returns the fill transparency of the object "name". If "name" is not given the currently selected Item is used.</p></dd>
+
+<dt><a name="-getImageColorSpace"><strong>getImageColorSpace</strong></a>(...)</dt>
+<dd><code>getImageColorSpace(["name"]) -> integer (see CSPACE_* constants)</code>
+<p>Returns the color space of the image loaded in image frame "name" as one of following integer constants:
+	<ul>
+		<li>CSPACE_RGB</li>
+		<li>CSPACE_CMYK</li>
+		<li>CSPACE_GRAY</li>
+		<li>CSPACE_DUOTONE</li>
+		<li>CSPACE_MONOCHROME.</li>
+	</ul>
+</p>
+<p>Returns CSPACE_UNDEFINED if there is no image loaded in the frame.</p>
+<p>If "name" is not given the currently selected item is used.</p></dd>
 
 <dt><a name="-getImageFile"><strong>getImageFile</strong></a>(...)</dt>
 <dd><code>getImageFile(["name"]) -> string</code>

Modified: trunk/Scribus/doc/fr/scripterapi-constants.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/doc/fr/scripterapi-constants.html
==============================================================================
--- trunk/Scribus/doc/fr/scripterapi-constants.html	(original)
+++ trunk/Scribus/doc/fr/scripterapi-constants.html	Fri Nov 23 00:21:59 2018
@@ -254,6 +254,18 @@
 </dl>
 </td></tr></table>
 
+<h4>Définitions d'espaces de couleur: </h4>
+<table><tr><td>
+<dl>
+	<dt>CSPACE_UNDEFINED</dt>
+	<dt>CSPACE_RGB</dt>
+	<dt>CSPACE_CMYK</dt>
+	<dt>CSPACE_GRAY</dt>
+	<dt>CSPACE_DUOTONE</dt>
+	<dt>CSPACE_MONOCHROME</dt>
+</dl>
+</td></tr></table>
+
 <h4>Réglages relatifs au fond :</h4>
 <table><tr><td>
 <dl>

Modified: trunk/Scribus/doc/fr/scripterapi-getobjprop.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/doc/fr/scripterapi-getobjprop.html
==============================================================================
--- trunk/Scribus/doc/fr/scripterapi-getobjprop.html	(original)
+++ trunk/Scribus/doc/fr/scripterapi-getobjprop.html	Fri Nov 23 00:21:59 2018
@@ -35,6 +35,20 @@
 <dt><a name="-getFillTransparency"><strong>getFillTransparency</strong>(...)</a></dt>
 <dd><code>getFillTransparency(["nom"]) -> nombre réel</code>
 <p>Retourne l'opacité appliquée à la couleur de fond de l'objet "nom". Si "nom" n'est pas fourni, l'élément sélectionné est utilisé.</p></dd>
+
+<dt><a name="-getImageColorSpace"><strong>getImageColorSpace</strong></a>(...)</dt>
+<dd><code>getImageColorSpace(["nom"]) -> entier (voir constantes CSPACE_*)</code>
+<p>Retourne l'espace de couleur de l'image chargée dans le cadre d'image "nom" sous forme d'une constante entière :
+	<ul>
+		<li>CSPACE_RGB</li>
+		<li>CSPACE_CMYK</li>
+		<li>CSPACE_GRAY</li>
+		<li>CSPACE_DUOTONE</li>
+		<li>CSPACE_MONOCHROME.</li>
+	</ul>
+</p>
+<p>Retourne CSPACE_UNDEFINED si aucune image n'est chargée dans le cadre d'image concerné.</p>
+<p>Si "nom" n'est pas fourni, l'élément sélectionné est utilisé.</p></dd>
 
 <dt><a name="-getImageFile"><strong>getImageFile</strong></a>(...)</dt>
 <dd><code>getImageName(["nom"]) -> chaîne</code>

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	Fri Nov 23 00:21:59 2018
@@ -393,6 +393,39 @@
 	return lst;
 }
 
+PyObject *scribus_getimagecolorspace(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return nullptr;
+	if (!checkHaveDocument())
+		return nullptr;
+	PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+	if (item == nullptr)
+		return nullptr;
+	if (item->itemType() != PageItem::ImageFrame)
+	{
+		PyErr_SetString(WrongFrameTypeError,
+			QObject::tr("Page item must be an ImageFrame", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	const ScImage& pixm = item->pixm;
+	if (pixm.width() == 0 || pixm.height() == 0)
+		return PyInt_FromLong(static_cast<long>(-1));
+
+	const ImageInfoRecord& iir = pixm.imgInfo;
+	int cspace = iir.colorspace;
+	/*
+	RGB  = 0,
+	CMYK = 1,
+	Gray = 2,
+	Duotone = 3,
+	Monochrome = 4
+	*/
+	return PyInt_FromLong(static_cast<long>(cspace));
+}
+
 
 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
 with header files structure untouched (docstrings are kept near declarations)
@@ -411,5 +444,5 @@
 	  << scribus_getimgscale__doc__ << scribus_getimagefile__doc__ 
 	  << scribus_getposi__doc__ << scribus_getsize__doc__ 
 	  << scribus_getrotation__doc__ <<  scribus_getallobj__doc__
-	  << scribus_getobjectattributes__doc__;
-}
+	  << scribus_getobjectattributes__doc__ << scribus_getimagecolorspace__doc__;
+}

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	Fri Nov 23 00:21:59 2018
@@ -166,24 +166,35 @@
 PyObject *scribus_getcornerrad(PyObject * /*self*/, PyObject* args);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_getimagecolorspace__doc__,
+QT_TR_NOOP("getImageColorSpace([\"name\"]) -> integer\n\
+Returns the color space for the image loaded in image frame \"name\" as \n\
+one of following integer constants: CSPACE_RGB (0), CSPACE_CMYK (1), \n\
+CSPACE_GRAY (2), CSPACE_DUOTONE (3) or CSPACE_MONOCHROME (4).\n\
+Returns CSPACE_UNDEFINED (-1) if no image is loaded in the frame.\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+PyObject *scribus_getimagecolorspace(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_getimagefile__doc__,
+QT_TR_NOOP("getImageFile([\"name\"]) -> string\n\
+\n\
+Returns the filename for the image in the image frame. If \"name\" is not\n\
+given the currently selected item is used.\n\
+"));
+/*! Returns image name of the object */
+PyObject *scribus_getimagefile(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_getimgscale__doc__,
-QT_TR_NOOP("getImageScale([\"name\"]) -> (x,y)\n\
+	QT_TR_NOOP("getImageScale([\"name\"]) -> (x,y)\n\
 \n\
 Returns a (x, y) tuple containing the scaling values of the image frame\n\
 \"name\".  If \"name\" is not given the currently selected item is used.\n\
 "));
 /*! Returns image scale of the object */
 PyObject *scribus_getimgscale(PyObject * /*self*/, PyObject* args);
-
-/*! docstring */
-PyDoc_STRVAR(scribus_getimagefile__doc__,
-QT_TR_NOOP("getImageFile([\"name\"]) -> string\n\
-\n\
-Returns the filename for the image in the image frame. If \"name\" is not\n\
-given the currently selected item is used.\n\
-"));
-/*! Returns image name of the object */
-PyObject *scribus_getimagefile(PyObject * /*self*/, PyObject* args);
 
 /*! docstring */
 PyDoc_STRVAR(scribus_getposi__doc__,

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22775&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	Fri Nov 23 00:21:59 2018
@@ -374,6 +374,7 @@
 	{const_cast<char*>("getFontSize"), scribus_getfontsize, METH_VARARGS, tr(scribus_getfontsize__doc__)},
 	{const_cast<char*>("getGuiLanguage"), (PyCFunction)scribus_getlanguage, METH_NOARGS, tr(scribus_getlanguage__doc__)},
 	{const_cast<char*>("getHGuides"), (PyCFunction)scribus_getHguides, METH_NOARGS, tr(scribus_getHguides__doc__)},
+	{const_cast<char*>("getImageColorSpace"), scribus_getimagecolorspace, METH_VARARGS, tr(scribus_getimagecolorspace__doc__) },
 	{const_cast<char*>("getImageFile"), scribus_getimagefile, METH_VARARGS, tr(scribus_getimagefile__doc__)},
 	{const_cast<char*>("getImageScale"), scribus_getimgscale, METH_VARARGS, tr(scribus_getimgscale__doc__)},
 	{const_cast<char*>("getLayers"), (PyCFunction)scribus_getlayers, METH_NOARGS, tr(scribus_getlayers__doc__)},
@@ -768,6 +769,12 @@
 	PyDict_SetItemString(d, const_cast<char*>("PAPER_LEGAL"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 1008.0));
 	PyDict_SetItemString(d, const_cast<char*>("PAPER_LETTER"), Py_BuildValue(const_cast<char*>("(ff)"), 612.0, 792.0));
 	PyDict_SetItemString(d, const_cast<char*>("PAPER_TABLOID"), Py_BuildValue(const_cast<char*>("(ff)"), 792.0, 1224.0));
+	PyDict_SetItemString(d, const_cast<char*>("CSPACE_UNDEFINED"), Py_BuildValue(const_cast<char*>("i"), -1));
+	PyDict_SetItemString(d, const_cast<char*>("CSPACE_RGB"), Py_BuildValue(const_cast<char*>("i"), 0));
+	PyDict_SetItemString(d, const_cast<char*>("CSPACE_CMYK"), Py_BuildValue(const_cast<char*>("i"), 1));
+	PyDict_SetItemString(d, const_cast<char*>("CSPACE_GRAY"), Py_BuildValue(const_cast<char*>("i"), 2));
+	PyDict_SetItemString(d, const_cast<char*>("CSPACE_DUOTONE"), Py_BuildValue(const_cast<char*>("i"), 3));
+	PyDict_SetItemString(d, const_cast<char*>("CSPACE_MONOCHROME"), Py_BuildValue(const_cast<char*>("i"), 4));
 	PyDict_SetItemString(d, const_cast<char*>("NORMAL"), Py_BuildValue(const_cast<char*>("i"), 0));
 	PyDict_SetItemString(d, const_cast<char*>("DARKEN"), Py_BuildValue(const_cast<char*>("i"), 1));
 	PyDict_SetItemString(d, const_cast<char*>("LIGHTEN"), Py_BuildValue(const_cast<char*>("i"), 2));




More information about the scribus-commit mailing list