The Big Bad G'MIC Thread of Silly Questions

Duplicate:input does not delete, drain or otherwise change storage variables. Storage variables may be used to restore their related images any number of times.

How do you delete stored images when you don’t need them anymore? Reassign the var to an empty string? What is the proper way to remove them?

Yes x10.

You’re using store?

Will probably do, yes. Why?

Just verifying. Syntax looks like this.

To store images and remove them from the list of images

store[$img_indexes] images

You can also use multiple variables too.

sample cat,dog
store[-2,-1] animal_1,animal_2
$animal_1

To keep the images, you can use +store instead.

And you can get rid of the stored image in variable by doing var=

Yes, i know.
you can also use compression :
+store[$img_indexes] 1,images

the +store is what i’m interested in, to keep some generated trees and ruse them later. Could save some loops since generating all this takes time.
Haven’t really thought about any other way yet. I think i made one mistake when pasting the trees directly on the background. I should probably just alpha blend them in batch, and store that batch, and call it later. The problem is i can’t have them all in the same image since i have to blend the atmosphere at some intervals, creating some fake depth. So, small batches. Let’s hope that"ll speed things up a bit.

Still have to do the ground, too.

The store tutorial glides over this bit, to wit: image storage variables have the same visibility as any other command line variable. This can lead to retrieval —um— ‘surprises’ when storing images in different scopes (need to mention this in Tutorial Land. Noting it here for now). This cautionary primarily concerns -store; +store duplicates images before storage.

If they are to be manipulated cooperatively by some number of custom commands, then it is probably safest to store images using globally visible variables (those prepended with _).

Locally defined storage variable gotcha: Images, selected by some custom command and stored by such commands through locally defined variables — ones that are visible in just those custom commands — cannot be subsequently retrieved in the parent context. That is because locally defined variables of custom commands are deleted upon scope return, leaving no keys behind in the parent context to retrieve the images.

Such images, selected by custom commands and stored through them, are effectively deleted by the custom command, insofar as the parent context is concerned.

TL;DR:
Test (1–9) results - see ‘Gory Details’ for gory details. Summaries here:

  1. Can create an image, name it ‘CarmenSanDiego’ and confirm that it is on the image list.
  2. Can store ‘CarmenSanDiego’ (using - prefix) harnessing a local variable, sandiego.
    2a. The image ‘CarmenSanDiego’ disappears from the image list, as expected.
    2b. The image data for ‘CarmenSanDiego’ is available in the math environment via get(), using the key sandiego.
  3. Cannot retrieve the image ‘CarmenSanDiego’ through a custom command (which operates in a child scope), using the key sandiego defined in the parent scope. The custom command just creates a different variable in its child scope. That different variable bears no relationship to any similarly named local variable in the parent scope.
  4. So long as there is no scope change, the local variable sandiego can be used to restore image ‘CarmenSanDiego’ by way of the -input command, (as advertised).
    4a. The retrieval also restores the image’s collection membership, if any.
  5. Deleting (re-referencing) the key sandiego throws away the reference to the stored image — effectively deleting it, as @Reptorian observed — even in math environments. Already retrieved images, now safe on the image list, are unaffected.
  6. Custom commands may store their selected images using local storage variables, then retrieve and otherwise manipulate them in the child context, but:
    6a. The parent scope can’t retrieve images that (1) have been cited in custom command selections, and (2) stored in local storage variables: the local storage variables go out of scope on the custom command’s exit; they cannot then be used as retrieval keys in the parent context.
    6b. Such custom commands, effectively, delete their selections.
    6c. Such deleted images are also not available in the math environment.
  7. Can store CarmenSanDiego (using - prefix) harnessing a global variable, _sandiego.
    7a. The image ‘CarmenSanDiego’ disappears from the image list, as expected.
  8. A custom command (creating a child context) can restore the image ‘CarmenSanDiego’ harnessing the global variable _sandiego.
Gory Details

witwicsd.gmic:

whereintheworldiscarmensandiego :
   # Carmen San Diego:
   -input 1
   -name. CarmenSanDiego
   carmensz:=whds
   -named "CarmenSanDiego"
   -echo "\nCarmenSanDiego has one pixel…"
   -echo "$0: (1.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (1.) Image list length, pre-CarmenSanDiego storage: "$!"."

   -echo "\nStoring CarmenSanDiego in a local storage variable named 'sandiego'."
   -store[CarmenSanDiego] sandiego
   -named "CarmenSanDiego"
   -echo "$0: (2.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (2.) Image list length following-CarmenSanDiego storage: "$!"."

   # Something like CarmenSanDiego in a mathematical expression environment?
   -echo "\n(2 Looking in math.) Something like CarmenSanDiego in a mathematical expression environment?"
   -eval ">
            V=get('sandiego',"$carmensz");
            print(V)
         "

   # Go to another scope (custom command 'showcarmen'). That scope tries to get CarmenSanDiego via $sandiego.
   -echo "\nCustom command 'showcarmen' attempts to fetch CarmenSanDiego via 'sandiego' (It should throw an exception)."
   -showcarmen
   -named "CarmenSanDiego"
   -echo "$0: (3.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (3.) Image list length, following showcarmen fetch: "$!"."

   # Try to retrieve CarmenSanDiego in the current scope.
   -echo "\nRetrieving CarmenSanDiego from the local storage variable named 'sandiego'\nExpect collection affiliations to be restored as well."
   -input $sandiego
   -named "CarmenSanDiego"
   -echo "$0: (4.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (4.) Image list length, following sandiego fetch in same scope: "$!"."
   -echo "$0: (4.) The command interpreter local variable key 'sandiego' references: "$sandiego"."

   # Delete key. referenced value gone?
   -echo "\nDelete key sandiego. Referenced value now gone? Collection 'CarmenSanDiego' gone too?"
   -echo "$0: (5.) Dereferencing key 'sandiego'."
   sandiego=
   -echo "$0: After dereferencing 'sandiego', can a mathematical expression environment still fetch 'sandiego' as a vector?"
   -eval ">
            V=get('sandiego',"$carmensz");
            print(V)
         "
   -echo "$0: (5.) After dereferencing, the command interpreter local variable key 'sandiego' references: "$sandiego"."
   -named "CarmenSanDiego"
   -echo "$0: (5.) After dereferencing, the image list still has an image named 'CarmenSanDiego' at index (not count!): "${}"."

   # Can a child scope store CarmenSanDiego on our behalf?
   -echo "\nCustom command 'hideme' stores CarmenSanDiego on our behalf in its own local storage variable named 'carmen'."
   -hideme[CarmenSanDiego]
   -named "CarmenSanDiego"
   -echo "$0: (6.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (6.) Image list length, following CarmenSanDiego stored in a child custom command (hideme): "$!"."

   # Try to restore CarmenSanDiego from child-declared storage location 'carmen'…
   -echo "\nTrying to restore CarmenSanDiego from the child-declared storage location 'carmen'…\nExpect an exception to be thrown."
   -local
       -input $carmen
   -onfail
       -echo "$0: (6 local.) Cannot re-input that which was stored in a child scope."
   -done
   -if !$!
      -echo "$0: (6 Empty Image List.) The CarmenSanDiego image seems to have escaped!\nMight anything be found in a mathematical expression environment?"
      -eval ">
               V=get('carmen',"$carmensz");
	       print(V)
            "
      -echo "$0: Making a new one…"
      -input 1
      -name. CarmenSanDiego
   -fi

   # Where is Carmen SanDiego now?
   -echo "\nPossibly through restoration or other means, maybe CarmenSanDiego is on the image list."
   -named "CarmenSanDiego"
   -echo "$0: Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: Image list length: "$!"."

   # Use global store
   -echo "\nPutting CarmenSanDiego in global storage '_sandiego'."
   -store[CarmenSanDiego] _sandiego
   -named "CarmenSanDiego"
   -echo "$0: (7.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (7.) Image list length, following attempting to store CarmenSanDiego in global storage: "$!"."

   # Can a custom command restore CarmenSanDiego to the parent context from global storage? (Expect it to succeed).
   -echo "\nCan the custom command, 'showglobalcarmen', restore CarmenSanDiego using global storage '_sandiego' (Expect it to succeed)?"
   -showglobalcarmen
   -named "CarmenSanDiego"
   -echo "$0: (8.) Indices (not counts!) of images in CarmenSanDiego collection: "${}
   -echo "$0: (8.) Image list length, following showglobalcarmen fetch from global storage '_sandiego': "$!".\n"

# -----------------------------------------------------------------------------------------
hideme:
   nm={n}
   -echo "$0: Storing some selected image named: "$nm" in a local storage variable named 'carmen'" 
   -store. carmen
   -echo "$0: Image "$nm" is gone. Image list length in "$0": "$!"."
   -echo "Restoring "$nm":"
   -input $carmen
   -echo "$0: (6.) Indices (not counts!) of images in CarmenSanDiego collection: "${}"."
   -echo "$0: (6.) Image list length, following attempt to restore "$nm" from local storage 'carmen': "$!"."
   -echo "$0: (6.) Storing "$nm" again to 'carmen', removing it from image list."
   -store. carmen

# -----------------------------------------------------------------------------------------
showcarmen:
   -local
      -echo "$0: Attempting to fetch an image from a local storage variable named sandiego\n(as it was declared in the parent scope)."
      -input $sandiego
   -onfail
      echo "$0: Cannot retrieve that which was stored in a parent scope."
   -done

# -----------------------------------------------------------------------------------------
showglobalcarmen:
   -local
      -echo "$0: Attempting to fetch an image from global storage named _sandiego\n(as it was declared in the parent scope)."
      -input $_sandiego
      -echo "$0: Global variable key '_sandiego' references: "$_sandiego
   -onfail
      echo "$0: Cannot retrieve that what was stored globally in a parent scope."
   -done

Shell log:

gosgood@bertha ~/gmicscripts $ gmic -m witwicsd.gmic v 3 whereintheworldiscarmensandiego v -3
[gmic]./ Start G'MIC interpreter (v.3.3.6).
[gmic]./ Import commands from file 'witwicsd.gmic', with debug info (4 new, total: 4789).
[gmic]./ Set verbosity level to 3.
[gmic]./whereintheworldiscarmensandiego/ Input black image at position 0 (1 image 1x1x1x1).
[gmic]./whereintheworldiscarmensandiego/ Set name of image [0] to 'CarmenSanDiego'.
[gmic]./whereintheworldiscarmensandiego/ Set local variable 'carmensz:=whds'->'1'.
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [0] (case-sensitive).

CarmenSanDiego has one pixel…
whereintheworldiscarmensandiego: (1.) Indices (not counts!) of images in CarmenSanDiego collection: 0.
whereintheworldiscarmensandiego: (1.) Image list length, pre-CarmenSanDiego storage: 1.

Storing CarmenSanDiego in a local storage variable named 'sandiego'.
[gmic]./whereintheworldiscarmensandiego/ Store image [0] as variable 'sandiego'
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [] (case-sensitive).
whereintheworldiscarmensandiego: (2.) Indices (not counts!) of images in CarmenSanDiego collection: .
whereintheworldiscarmensandiego: (2.) Image list length following-CarmenSanDiego storage: 0.

(2 Looking in math.) Something like CarmenSanDiego in a mathematical expression environment?
[gmic]./whereintheworldiscarmensandiego/ Evaluate expression '> V=get('sandiego',1); print(V) ' and assign it to status.
[gmic_math_parser] V = (uninitialized) (mem[44]: vector1)
[gmic_math_parser] V = [ 0 ] (size: 1)

Custom command 'showcarmen' attempts to fetch CarmenSanDiego via 'sandiego' (It should throw an exception).
showcarmen: Attempting to fetch an image from a local storage variable named sandiego
(as it was declared in the parent scope).
[gmic]./whereintheworldiscarmensandiego/showcarmen/ local#112/ Input file '' at position 0 
[gmic]./whereintheworldiscarmensandiego/showcarmen/ local#112/ *** Error (file 'witwicsd.gmic', line #114) *** Command 'input': Unknown filename ''.
showcarmen: Cannot retrieve that which was stored in a parent scope.
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [] (case-sensitive).
whereintheworldiscarmensandiego: (3.) Indices (not counts!) of images in CarmenSanDiego collection: .
whereintheworldiscarmensandiego: (3.) Image list length, following showcarmen fetch: 0.

Retrieving CarmenSanDiego from the local storage variable named 'sandiego'
Expect collection affiliations to be restored as well.
[gmic]./whereintheworldiscarmensandiego/ Input image from variable 'sandiego', at position 0 (1 image 1x1x1x1).
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [0] (case-sensitive).
whereintheworldiscarmensandiego: (4.) Indices (not counts!) of images in CarmenSanDiego collection: 0.
whereintheworldiscarmensandiego: (4.) Image list length, following sandiego fetch in same scope: 1.
whereintheworldiscarmensandiego: (4.) The command interpreter local variable key 'sandiego' references: *store/sandiego.

Delete key sandiego. Referenced value now gone? Collection 'CarmenSanDiego' gone too?
whereintheworldiscarmensandiego: (5.) Dereferencing key 'sandiego'.
[gmic]./whereintheworldiscarmensandiego/ Set local variable 'sandiego='.
whereintheworldiscarmensandiego: After dereferencing 'sandiego', can a mathematical expression environment still fetch 'sandiego' as a vector?
[gmic]./whereintheworldiscarmensandiego/ Evaluate expression '> V=get('sandiego',1); print(V) ' and assign it to status.
[gmic_math_parser] V = (uninitialized) (mem[44]: vector1)
[gmic_math_parser] V = [ 0 ] (size: 1)
whereintheworldiscarmensandiego: (5.) After dereferencing, the command interpreter local variable key 'sandiego' references: .
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [0] (case-sensitive).
whereintheworldiscarmensandiego: (5.) After dereferencing, the image list still has an image named 'CarmenSanDiego' at index (not count!): 0.

Custom command 'hideme' stores CarmenSanDiego on our behalf in its own local storage variable named 'carmen'.
[gmic]./whereintheworldiscarmensandiego/hideme/ Set local variable 'nm=CarmenSanDiego'.
hideme: Storing some selected image named: CarmenSanDiego in a local storage variable named 'carmen'
[gmic]./whereintheworldiscarmensandiego/hideme/ Store image [0] as variable 'carmen'
hideme: Image CarmenSanDiego is gone. Image list length in hideme: 0.
Restoring CarmenSanDiego:
[gmic]./whereintheworldiscarmensandiego/hideme/ Input image from variable 'carmen', at position 0 (1 image 1x1x1x1).
hideme: (6.) Indices (not counts!) of images in CarmenSanDiego collection: 0.
hideme: (6.) Image list length, following attempt to restore CarmenSanDiego from local storage 'carmen': 1.
hideme: (6.) Storing CarmenSanDiego again to 'carmen', removing it from image list.
[gmic]./whereintheworldiscarmensandiego/hideme/ Store image [0] as variable 'carmen'
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [] (case-sensitive).
whereintheworldiscarmensandiego: (6.) Indices (not counts!) of images in CarmenSanDiego collection: .
whereintheworldiscarmensandiego: (6.) Image list length, following CarmenSanDiego stored in a child custom command (hideme): 0.

Trying to restore CarmenSanDiego from the child-declared storage location 'carmen'…
Expect an exception to be thrown.
[gmic]./whereintheworldiscarmensandiego/ local#61/ Start 'local...done' block, with image [].
[gmic]./whereintheworldiscarmensandiego/ local#61/ Input file '' at position 0
[gmic]./whereintheworldiscarmensandiego/ local#61/ *** Error (file 'witwicsd.gmic', line #62) *** Command 'input': Unknown filename ''.
[gmic]./whereintheworldiscarmensandiego/ local#61/ Reach 'onfail' block.
whereintheworldiscarmensandiego: (6 local.) Cannot re-input that which was stored in a child scope.
[gmic]./whereintheworldiscarmensandiego/ local#61/ End 'local...done' block.
[gmic]./whereintheworldiscarmensandiego/ if#63/ Start 'if...endif' block -> condition '!0' holds.
whereintheworldiscarmensandiego: (6 Empty Image List.) The CarmenSanDiego image seems to have escaped!
Might anything be found in a mathematical expression environment?
[gmic]./whereintheworldiscarmensandiego/ if#63/ Evaluate expression '> V=get('carmen',1); print(V) ' and assign it to status.
[gmic_math_parser] V = (uninitialized) (mem[42]: vector1)
[gmic_math_parser] V = [ nan ] (size: 1)
whereintheworldiscarmensandiego: Making a new one…
[gmic]./whereintheworldiscarmensandiego/ if#63/ Input black image at position 0 (1 image 1x1x1x1).
[gmic]./whereintheworldiscarmensandiego/ if#63/ Set name of image [0] to 'CarmenSanDiego'.
[gmic]./whereintheworldiscarmensandiego/ if#63/ End 'if...endif' block.

Possibly through restoration or other means, maybe CarmenSanDiego is on the image list.
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [0] (case-sensitive).
whereintheworldiscarmensandiego: Indices (not counts!) of images in CarmenSanDiego collection: 0.
whereintheworldiscarmensandiego: Image list length: 1.

Putting CarmenSanDiego in global storage '_sandiego'.
[gmic]./whereintheworldiscarmensandiego/ Store image [0] as variable '_sandiego'
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [] (case-sensitive).
whereintheworldiscarmensandiego: (7.) Indices (not counts!) of images in CarmenSanDiego collection: .
whereintheworldiscarmensandiego: (7.) Image list length, following attempting to store CarmenSanDiego in global storage: 0.

Can the custom command, 'showglobalcarmen', restore CarmenSanDiego using global storage '_sandiego' (Expect it to succeed)?
showglobalcarmen: Attempting to fetch an image from global storage named _sandiego
(as it was declared in the parent scope).
[gmic]./whereintheworldiscarmensandiego/showglobalcarmen/ local#121/ Input image from variable '_sandiego', at position 0 (1 image 1x1x1x1).
showglobalcarmen: Global variable key '_sandiego' references: *store/_sandiego
[gmic]./whereintheworldiscarmensandiego/ Get all image indices with name 'CarmenSanDiego' for image [0] (case-sensitive).
whereintheworldiscarmensandiego: (8.) Indices (not counts!) of images in CarmenSanDiego collection: 0
whereintheworldiscarmensandiego: (8.) Image list length, following showglobalcarmen fetch from global storage '_sandiego': 1.
2 Likes

@grosgood Thanks for all the details! I’ll dive into the gore later, it’s a bit late for that now.
Somehow I feel like all the tutorial pages will end up in this thread :wink:

On another subject, for Underwoods, as I wanted to paste all the trees ( with alpha chan) on an empty 4 chans ( zeroed) image with ja, I’m running again into a sad case of … nothing happening. Tree is pasted, but empty remains empty, so there’s nothing to see with d0. Looks like the same case as the gingko/ circles stuff from before but with different commands.
Tried to replicate in the shell ( with a saved png) but… It worked there. Alpha chan is really tricky.
It works fine when I paste on a 3 chans image though, as seen in previous posts.

Blending layers ( alpha mode) works fine but not ideal since they don’t have the same dimensions ( the casted shadows are going out of the main image. They are not cropped so I can resize them later for shorter shadows, without clipping), and I cannot set their position like with ja. I’ll try to see if I can crop the trees layer before blending but that may also be tricky. Don’t know yet.

Missed all of the Sturm und Drang that Underwoods has undergone since Fun with prawnsushi: Post #11, 29-March, and only pulled gmic-community this AM (noonish, CET). Take a closer look n the morning regardiing the persistence of emptiness…

Here’s what it’s like now ( but this is an indexed image ):

I think you can pretty much guess how it’s made just by looking at it

3 Likes

I’ve got a silly question…because I’m not sure of the boundaries here (and I only have a jpeg XD…), but would anyone like to see a nail sticking out of my hand? Nailed myself at work today…

Uh no. This is about G’MIC scripting.

Oh geez, it is too… Sorry, I didn’t notice the forum listed.
I mistakenly thought it was just a general discussion thread.

2 Likes

Renamed the thread to avoid random encounters :slight_smile:

1 Like

Speaking of which, I am still waiting for random encounters to be implemented. :joy_cat:

@afre Someone should start writing a generator for G’mic for all things that exist :slight_smile:

But for now i have a bug to fix that i have absolutely no clue how to fix :sweat_smile:

Is there a var that is passed when someone selects “new image, new layer” in Gmic_qt?
I’m in a place with very slow 4g connection so it’s a bit difficult to check online.

Be careful with layer organization and manipulation because each host app can treat them differently (e.g., GIMP vs Krita). :imp:

To state the obvious, your filter is at the stage where organization is key to optimization, solving bugs and refining the user experience.

First, I would check the loops: i.e., are there places where you can avoid loops or bring things out of them? E.g., some generation can be pre-determined.

Second, organize code into sub-commands or macros.

Edit: I recall someone reminding you to step through the code using tools such as print and echo. You can actually do that when testing your code in the GUI, not just in CLI, i.e., the G’MIC engine is still running in the background.

The problem only occurs when someone selects “new image, new layer” in Gmic_qt (which i obviously never do).
Somehow it messes up the script. Probably the list, there’s an image missing, probably wrongly renamed because the order becomes different.

You can still find out where it went wrong by outputting all the variables, images and stored arrays step by step for examination. I forget how G’MIC behaves when you are trying to access an image by name that does not exist. Probably an error. I suppose you can error-proof your image retrieval by using an if-error-do-this logic for now, or temporarily put a notice in the filter GUI text.

Yes i know, i’m using d0 around the bug right now.
It looks like fx_tree is eating an image [BG]?

Here’s what i see :

When using “in place” :

  • create an image named BG
  • repeat 2 times fx_tree : outputs tree to image 0 each time (why? no idea but i got used to it, that’s how fx_tree works)
    At this point BG still exists
  • name image 0 tree1
  • name image 1 tree2

When using “new layer, etc”

  • create an image named BG
  • repeat 2 times fx_tree : outputs to image 0 but BG disappears the first time, then tree2 replaces tree 1
  • name image 0 tree1
  • name image 1 tree2 <= fails because there is only image 0 and outputs error

This is knida tricky since i fear fixing behaviour 2 will make bahviour 1 bug instead.

Mods i’ve made show the trees are created in a different position instead of 0,1.
Gotta find the way to create them surely at the same position each time.
Will eventually get it one day :stuck_out_tongue:

Just check the code for fx_tree :

fx_tree :
  _fx_tree. $* mv. 0 <= moves to 0 heh
  if 0$_output_mode k[0] fi  <= no idea what this is

Now i know why it is moved to postition 0.

I’ll modify my code to use _fx_tree directly instead and see what happens. Probably more bugs :slight_smile: