Available filters in qmic CLI

$${<some custom command>} is an interface to extract entries from the custom command hash table that -command builds. -command doesn’t care about readability; its game is to reduce the right hand side of : to the minimum length string that is still a legal gmic script. So, out goes comments and white space. The left hand side of : fits a regular expression somewhat like ^_*[a-zA-Z0-9_]+ *: (The emacs regular expression I use to find the beginning of command definitions in .gmic files). If I also didn’t care about comments and white space, then what $${} does is ideal. I don’t have to worry about what .gmic file defines a command or how to get it; if the command has been hashed, then I get a minimum string representation of the pipeline implementing it.

But if readability matters, you almost want a “-command_lite” version that doesn’t reduce the right hand side of a command definition, preserving white space and comments. You’d like to rewrite -command so that it doesn’t reduce pipeline definitions to the minimum length.

Unfortunately, G’MIC’s -command is a built-in, implemented in C++; you can’t directly adapt it. Nor does the G’MIC command line interpreter have a regular expression parser to find the beginning of command definitions inside of text text files, so a G’MIC script version of a -command_lite could be some work. I think if I wanted to write a “-command_lite” partial parser, I’d turn to Python and import regex and use it to block text files into command definitions, then not minimize the blocks. Of course, once I start in Python, I generally finish in Python. Good luck!

1 Like

There is actually a command parse_cli that is used to parse the different commands and the associated documentation.
It is used for instance to generate the reference pages in the G’MIC website, as well as to print the help for a particular command, when typing gmic -h command.

It could be possible to add your own ‘output mode’ that fits your needs. Not easy, but doable.

Thanks, @KaRo. zart is “c-koi/zart” I would assume. Need to fix the following:

Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv4' found
Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv4' found
Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv4' found
Package opencv4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv4' found
In file included from gmic.cpp:1809:
In file included from ./gmic.h:261:
./CImg.h:452:10: fatal error: 'opencv2/opencv.hpp' file not found

Thanks for the good starting point, well appreciated.

Nachtrag: Fixed by adding /opt/homebrew/lib/pkgconfig to PKG_CONFIG_PATH

Ahh, ok, have forgotten zart clone line, thanks!

Dangerous to mix MacPorts and Homebrew IMHO. Yes, there was a problem with pkgconfig of opencv4. Possibly I have copied it from anywhere:

opencv4.pc :
# Package Information for pkg-config

prefix=/opt/local/libexec/opencv4
exec_prefix=${prefix}
libdir=/opt/local/lib/opencv4
includedir=/opt/local/include/opencv4

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.6.0
Libs: -L/opt/local/lib/opencv4 -lopencv_gapi.4.6.0 -lopencv_highgui.4.6.0 -lopencv_ml.4.6.0 -lopencv_objdetect.4.6.0 -lopencv_photo.4.6.0 -lopencv_stitching.4.6.0 -lopencv_video.4.6.0 -lopencv_calib3d.4.6.0 -lopencv_features2d.4.6.0 -lopencv_flann.4.6.0 -lopencv_videoio.4.6.0 -lopencv_imgcodecs.4.6.0 -lopencv_imgproc.4.6.0 -lopencv_core.4.6.0
Libs.private: 
Cflags: -I${includedir}
~

Thanks a lot. I also guess that OpenMP is not used. Could that explain why gmic is rather slow.

Re “Dangerous to mix MacPorts and Homebrew IMHO.”. Yes, it sees to have become messy on my Mac and I will remove all packages from both, HB and MP, and will start over again.

Tried all with brew. gmic compiles nicely, however, gmic-qt only delivers an error

cd ../gmic-qt && qmake CONFIG+=release GMIC_PATH=/Users/kaufmann/Programming/gmic-from-sources/gmic/src PRERELEASE=23082715 GMIC_DYNAMIC_LINKING=off HOST=none gmic_qt.pro && /Applications/Xcode.app/Contents/Developer/usr/bin/make
Project MESSAGE: GMIC_PATH is set (/Users/kaufmann/Programming/gmic-from-sources/gmic/src)
Project MESSAGE: G'MIC repository was found (/Users/kaufmann/Programming/gmic-from-sources/gmic/src)
Project MESSAGE: G'MIC version is ................. 330
Project MESSAGE: CImg version is .................. 330
Project MESSAGE: gmic_stdlib_community.h version is 330
Project MESSAGE: Prerelease date is 23082715
Project MESSAGE: Building standalone version
Project MESSAGE: Release build
Project WARNING: Qt has only been tested with version 10.15 of the platform SDK, you're using 13.3.
Project WARNING: This is an unsupported configuration. You may experience build issues, and by using
Project WARNING: the 13.3 SDK you are opting in to new features that Qt has not been prepared for.
Project WARNING: Please downgrade the SDK you use to build your app to version 10.15, or configure
Project WARNING: with CONFIG+=sdk_no_version_check when running qmake to silence this warning.
Project WARNING: Cross compiling without sysroot. Disabling pkg-config.
Project WARNING: Cross compiling without sysroot. Disabling pkg-config.
sh: --exists: command not found
Project ERROR: fftw3 development package not found
make: *** [gmic_qt] Error 3
+ exit

I am using bash as the shell. Even the latest one on the Mac, but to no avail.

No idea, not tried with homebrew.
At least fftw3 is also in gmic used afaik. I don’t know anymore where I stuck with homebrew. It looked much simpler compared to macports, still…
I am using zsh since it has become the default shell.

Tried zsh as well. So, did you use MacPort then? I seem to be stuck with both. Never mind, I will look at it again and report back

Yes, MacPorts with bash too in my script, there should be no difference in sh and zsh for that. I’ll look into my building messages, perhaps I get a hint…

First, let see what the pure “make” is doing with “make -n”.
Do instead “make clean gimp gmic_qt zart”
AND most important do that all in ~/sw/gmic/src !!

I think Qt5 is not installed properly, qmake possibly missing

Here is the beginning of my build:

cd ../gmic-qt && qmake CONFIG+=release GMIC_PATH=/Volumes/mbkaroSD2/Users/karo/sw/gmic/src PRERELEASE=23082722 GMIC_DYNAMIC_LINKING=off HOST=gimp gmic_qt.pro && make
Project MESSAGE: GMIC_PATH is set (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC repository was found (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC version is ................. 330
Project MESSAGE: CImg version is .................. 330
Project MESSAGE: gmic_stdlib_community.h version is 330
Project MESSAGE: Prerelease date is 23082722
Project MESSAGE: Target host software is GIMP
Project MESSAGE: Release build
make[1]: Entering directory '/Volumes/mbkaroSD2/Users/karo/sw/gmic-qt'
Project MESSAGE: GMIC_PATH is set (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC repository was found (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC version is ................. 330
Project MESSAGE: CImg version is .................. 330
Project MESSAGE: gmic_stdlib_community.h version is 330
Project MESSAGE: Prerelease date is 23082722
Project MESSAGE: Target host software is GIMP
Project MESSAGE: Release build
make[2]: *** No rule to make target 'gmic_gimp_qt'.  Stop.
/opt/local/bin/qmake -o Makefile gmic_qt.pro CONFIG+=release GMIC_PATH=/Volumes/mbkaroSD2/Users/karo/sw/gmic/src PRERELEASE=23082722 GMIC_DYNAMIC_LINKING=off HOST=gimp
Project MESSAGE: GMIC_PATH is set (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC repository was found (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC version is ................. 330
Project MESSAGE: CImg version is .................. 330
Project MESSAGE: gmic_stdlib_community.h version is 330
Project MESSAGE: Prerelease date is 23082722
Project MESSAGE: Target host software is GIMP
Project MESSAGE: Release build
Project MESSAGE: GMIC_PATH is set (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC repository was found (/Volumes/mbkaroSD2/Users/karo/sw/gmic/src)
Project MESSAGE: G'MIC version is ................. 330
Project MESSAGE: CImg version is .................. 330
Project MESSAGE: gmic_stdlib_community.h version is 330
Project MESSAGE: Prerelease date is 23082722
Project MESSAGE: Target host software is GIMP
Project MESSAGE: Release build
make[2]: *** No rule to make target 'gmic_gimp_qt'.  Stop.
/Volumes/mbkaroSD2/opt/local/libexec/qt5/bin/uic ui/inoutpanel.ui -o .ui/ui_inoutpanel.h
/Volumes/mbkaroSD2/opt/local/libexec/qt5/bin/uic ui/sourceswidget.ui -o .ui/ui_sourceswidget.h
/Volumes/mbkaroSD2/opt/local/libexec/qt5/bin/uic ui/multilinetextparameterwidget.ui -o .ui/ui_multilinetextparameterwidget.h

Ok, that is from gimp plugin, still no severe difference.

What does this mean, you are not on your M1 ?

I am … This is what I am getting when I did a fresh start, removing the gmic-qt directory and cloning it from the repo.

Nachtrag: It seems that this error might be due to the cone environment installed. I have removed that one and at least I get some compilations now till it is stopped through

In file included from src/MainWindow.cpp:65:
In file included from .ui/ui_mainwindow.h:30:
src/Widgets/PreviewWidget.h:99:29: error: non-virtual member function marked 'override' hides virtual member function
  void enterEvent(QEvent *) override;
                            ^
/opt/homebrew/include/QtWidgets/qwidget.h:672:18: note: hidden overloaded virtual function 'QWidget::enterEvent' declared here: type mismatch at 1st parameter ('QEnterEvent *' vs 'QEvent *')
    virtual void enterEvent(QEnterEvent *event);
                 ^
1 error generated.

Getting there. Slowly.

If I correct the error above, I get one more with head inconsistencies. Adding the /opt/homebrew/include and /opt/homebrew/lib to the Makefile options then finally allows to compile without errors and the gmic-qt is finally executing.

I could send you privately my crowded sh file with lots of trials. There is also one with clang++-mp-11!
Maybe you can improve something… e-mail please!

That would be great. I have managed in the meantime to get gmic running with OpenMP. gmic-qt not yet. I will PM you my email.

Not that I find the PM function here … if there is one.

Please use remedy-rafts0x@icloud.com

On my M1, gmic … samj_Barbouillage_Paint_Daub 2,2,100,0.2,1,4,1,0,8 … on a 24MP image takes about 15 minutes without OpenMP. With OpenMP and 8 threads, it takes about 3 minutes. The former is way too long and the latter still feels slow but is not compared to the former.

Some filters can take a while, others can be fast. Try blur 200. Also, 24MP is 24000000 pixel, so that’s a lot of loops.

Thanks, all. To end the discussion for the time being regarding M1 support for gmic, here is the script that compiles gmic for M1 processors (and I would assume M2).

#/bin/bash

# Install libraries and compilers
brew install --quiet opencv libheif fftw llvm libomp

# Set environment variables
# Note that LLVM-capable C and C++ compilers are needed, hence the settings for CC and CXX
export CC=/opt/homebrew/opt/llvm/bin/clang
export CXX=/opt/homebrew/opt/llvm/bin/clang++
export C_INCLUDE_PATH=/opt/homebrew/include:/opt/homebrew/opt/libomp/include
export CPLUS_INCLUDE_PATH=/opt/homebrew/include:/opt/homebrew/opt/libomp/include
export LD_LIBRARY_PATH=/opt/homebrew/lib:/opt/homebrew/opt/libomp/lib
export PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig
export CONFIG+=openmp

# Get or update required repositories
git clone https://github.com/GreycLab/gmic 2> /dev/null || git -C gmic pull 

# 
# Build gmic
# 

# First, determine current gmic version
cd gmic/src
RELEASE0=`grep "#define gmic_version" gmic.h | tail -c 5`
RELEASE1=`echo $RELEASE0 | head -c 1`
RELEASE2=`echo $RELEASE0 | head -c 2 | tail -c 1`
RELEASE3=`echo $RELEASE0 | head -c 3 | tail -c 1`

# Second, set and display version identifier
VERSION=$RELEASE1.$RELEASE2.$RELEASE3
DATE=$(date "+%Y-%m-%d-%H:%M:%S")
echo "Building version ${VERSION} as of ${DATE}"

# Third, build gmic
make clean 
make -B OPENCV_CFLAGS="\$(shell pkg-config opencv4 --cflags)" OPENCV_LIBS="\$(shell pkg-config opencv4 --libs)" EXTRA_CFLAGS="-fopenmp -I/opt/homebrew/include -I/opt/homebrew/include/opencv4 -I/opt/local/include -march=native -flto -Wno-unused-parameter -Wno-c11-extensions -Wno-deprecated-declarations -Wno-c++17-extensions -Wno-variadic-macros -Dcimg_use_opencv \$(OPENCV_CFLAGS) -Dcimg_use_heif" EXTRA_LIBS="\$(OPENCV_LIBS) -L/opt/homebrew/lib -lheif" cli
cd ../..

# Copy executables
sudo cp gmic/src/gmic /usr/local/bin/
echo "Build complete and copied to /usr/local/bin - Enjoy!"

I am aware that the script is not optimised but it serves the purpose and on my 8 core system, it get a performance boost of about 5 to 6 as opposed to not using OpenMP.

I have tried quite a lot of things to get gmic-qt to use OpenMP but did not manage. So I will end the search for the time being.

Thanks everybody for providing input.

2 Likes