View Issue Details

IDProjectCategoryView StatusLast Update
0015485ScribusScripterpublic2019-06-04 20:56
Reporterdockattt Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version1.5.4.svn 
Target VersionFixed in Version1.5.5.svn 
Summary0015485: add getImageColorSpace python function
Descriptioncolorspace information can be useful to double check what types of images are in Scribus. I've had requirements that an image be off one type of colorspace. Adding the function in the patch called "getImageColorSpace" will allow a script to walk through every page of a document and look at the image's colorspace. Then it can report that the color spaces are right. The function is using what colorspace is in the ImageInfoRecord struct.
Steps To Reproduceadd an Image Frame and add images of different colorspaces to it. Try it without an image and it will return -1. Without an image is defined as an ScImage with 0 width and 0 height. Doesn't seem like there is an image in that object.
TagsNo tags attached.
PatchYes

Activities

dockattt

2018-11-14 18:22

reporter  

getImageColorSpace.patch (3,449 bytes)
Index: Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(revision 22756)
+++ Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(working copy)
@@ -393,7 +393,43 @@
 	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 *i = GetUniqueItem(QString::fromUtf8(Name));
+	if(i == nullptr)
+		return nullptr;
+	if(i->itemType() != PageItem::ImageFrame){
+		PyErr_SetString(PyExc_RuntimeError,
+			QObject::tr("Page item must be an ImageFrame", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
 
+	ScImage* pixm = &i->pixm;
+	if(pixm != nullptr){
+		if(pixm->width() != 0 && pixm->height() != 0){
+			ImageInfoRecord* iir = &pixm->imgInfo;
+			if(iir != nullptr){
+				int cspace = iir->colorspace;
+				/*
+				RGB  = 0,
+				CMYK = 1,
+				Gray = 2,
+				Duotone = 3,
+				Monochrome = 4
+				*/
+				return PyInt_FromLong(static_cast<long>(cspace));
+			}
+		}
+	}
+	return PyInt_FromLong(static_cast<long>(-1));
+}
+
+
 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
 with header files structure untouched (docstrings are kept near declarations)
 PV */
@@ -411,5 +447,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__;
 }
Index: Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(revision 22756)
+++ Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(working copy)
@@ -238,5 +238,15 @@
 "));
 PyObject *scribus_getobjectattributes(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getimagecolorspace__doc__,
+QT_TR_NOOP("getImageColorSpace([\"name\"]) -> integer\n\
+Returns the color space for an image in an Image Frame of \"name\".\n\
+0 RGB, 1 CMYK, 2 Gray, 3 Duotone, 4 Monochrome.\n\
+Returns the above numbers or -1 if there isn't an image\n\
+in the Image Frame.\n\
+"));
+PyObject *scribus_getimagecolorspace(PyObject * /*self*/, PyObject* args);
+
 #endif
 
Index: Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 22756)
+++ Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(working copy)
@@ -595,6 +595,7 @@
 	{const_cast<char*>("setTextAnnotation"), scribus_settextannotation, METH_VARARGS,tr(scribus_settextannotation__doc__)},
 	{const_cast<char*>("createPdfAnnotation"), scribus_createpdfannotation, METH_VARARGS,tr(scribus_createpdfannotation__doc__)},
 	{const_cast<char*>("isAnnotated"),(PyCFunction)scribus_isannotated, METH_VARARGS|METH_KEYWORDS,tr(scribus_isannotated__doc__)},
+        {const_cast<char*>("getImageColorSpace"), scribus_getimagecolorspace, METH_VARARGS, tr(scribus_getimagecolorspace__doc__)},
 	{nullptr, (PyCFunction)(nullptr), 0, nullptr} /* sentinel */
 };
 
getImageColorSpace.patch (3,449 bytes)

jghali

2018-11-23 00:24

administrator   ~0045654

Committed. I added CSPACE_RGB, CSPACE_CMYK, etc..., constants and modified doc accordingly so as to encourage users to use those constants in their scripts instead of integers directly.

Issue History

Date Modified Username Field Change
2018-11-14 18:22 dockattt New Issue
2018-11-14 18:22 dockattt File Added: getImageColorSpace.patch
2018-11-23 00:24 jghali Assigned To => jghali
2018-11-23 00:24 jghali Status new => resolved
2018-11-23 00:24 jghali Resolution open => fixed
2018-11-23 00:24 jghali Fixed in Version => 1.5.5.svn
2018-11-23 00:24 jghali Note Added: 0045654
2019-06-04 20:56 cbradney Status resolved => closed