shared (eq. to
sh) is one of the dangerous command of G’MIC Basically, you can make the G’MIC interpreter segfault if you use it the wrong way.
That being said, it is also a very useful command !
sh[img] ind0,ind1 will insert a new image at the end of the list, that has the particularity to share its data buffer with image
img, more precisely only for the channels from
(there are also ways to get other kind of shared portions of an image than channels, but I won’t detail it here).
So, if you have a RGB or RGBA image
img (image with 3 or 4 channels), invoking
sh[img] 0,2 will insert a new RGB-only shared image. Now if you process this new image, you’ll also modify the original image
img (that is what a shared image is defined for!).
If I go back to my example, this means that :
sh. 0,2 # Get only the RGB-portion of the latest RGB or RGBA image.
mirror. c # Apply mirroring along the c-channel, so RGB becomes BGR.
rm. # Remove the shared image, we don't need it anymore.
This is faster because no buffer copies are involved during the process. A shared image by definition does not copy the original data, and the mirror command just acts in-place.