Store and Restore

I’ve worked a bit this week end and today, to improve the new commands store and restore.
Here is the current help they display:

  • Command store:

    store (+):
        variable_name1,_variable_name2,...

      Store selected images into one or several named variables.
      Selected images are transferred to the variables, and are so removed from the image list.
      (except if the prepended variant of the command '+store[selection]' is used).
      If a single variable name is specified, all images of the selection are assigned
      to the named variable. Otherwise, there must be as many variable names as images
      in the selection, and each selected image is assigned to each specified named variable.
      Use command 'restore' to get the stored images back in the list.
      
      Example: [#1]  sample eagle,earth store img1,img2 \
                 restore img2,img1
  • Command restore:

    restore (+):
        variable_name1,_variable_name2,...

      Restore images previously stored in the specified named variables, and insert them at the end
      of the image list. Note that restoring image data does not remove the data from
      the corresponding named variable (use 'variable_name=' to explicitely delete a variable content).
  • I’ve made some work to optimize the assignment of image-encoded variables, so the speed is quite acceptable right now.
  • Also, the copy operator is now functional, so you can assign an image-based variable to another variable if necessary.

In a few minutes, the pre-release version 2.7.2 will be updated with new binary packages on the G’MIC website. Let me know if you have the occasion to test this new feature!

2 Likes

Just a thought: wondering if it would be good to use store and restore. Although in English it means “to bring back” or “recover”, it could be confusing for nonnative speakers for store to be in both command names. Could be taken as “re-store”, as in “store again”. Since I used the word recover, maybe that could the name… or maybe retrieve. Thoughts?

I like the idea of having similar names for both commands, as both commands clearly work together. As a non-english speaker, I think it really helps remembering their names.

As a native spanish speaker, I have to say that I prefer reserve - recover.

Reserva = Reserve
Recuperar = Recover

But, store and restore is easier to remember as all you need to remember is store, and only add re to do something else.

Well, what I see from the Merriam-Webster dictionnary is :

  • Store : to place or leave in a location (such as a warehouse, library, or computer memory) for preservation or later use or disposal

  • Restore: to bring back to or put back into a former or original state

My understanding of that is we cannot be more close to what these commands does in G’MIC :slight_smile:
store has indeed the meaning of moving something in another place (so here, an image, from the image list to a variable), and restore brings the image back.

1 Like

No problem. Just adding to the discussion. :slight_smile:

Just for info : Today, I’ve implemented the store and restore commands, as custom commands in the stdlib.
As a result, scripts using these commands (introduced natively in 2.7.2) should work also with previous versions 2.7.0 and 2.7.1 of G’MIC (they will just be a little slower though).

So, do not hesitate to use store and restore commands in your scripts already !

  • Commands img2var and var2img have been moved to my personal update file david_tschumperle.gmic, to ensure the recent scripts from @Reptorian continue to work (but if you can replace their use with store and restore, it would be better). Not sure how long they will stay there.

  • There are anyway small differences between the native and custom versions of store and restore. I don’t think that’s going to be a problem, though.

1 Like

Have I hit a limit? This works

gmic sp tiger +store input fftpolar +.. 1 log.. store mag,phase restore input,mag,phase

but when I input a larger image such as heal_mushrooms.jpg, I hit a wall

[gmic] *** Error in ./store/*if/*substitute/uchar2base64/ *** Command 'eval': gmic<float>: Function 'copy()': Out-of-bounds image pointer (length: 2, increment: 1, offset start: 92434578, offset end: 92434579, offset max: 92434575).

Yes, that’s one difference with the ‘native’ versions of the commands.
Your example works with 2.7.2_pre currently.

You mean the native versions can handle this? I am confused which ones are native and which ones aren’t…

@David_Tschumperle I figured it out, and changes work on my tiled form filter. If you’d like, you can remove the arg2var and var2img.

Yes, that’s it.
Native versions of store and restore are basically there is you are using G’MIC 2.7.2.
Before that version, the limited custom versions of these commands applies.

Oh, I think I know what you are saying: native overrides stdlib. Since I haven’t updated core yet, I am using stdlib's.

You could check https://gmic.eu/files/prerelease/, where a Windows build of G’MIC 2.7.2 is available for testing.

After thinking about it, it would be interesting to use store and restore command to replicate this -

Is it feasible? Right now, all I can think of is a gui filter that uses text input. Rather tiring to do it manually.


@David_Tschumperle

I just have one issue with store and restore. I really don’t want to see this in preview when using code[local]. The command is basically for reverse engineering gradient map.

Same thing with apply_tiles.

image

Oh no. I do think this has to do with store.

All I did was apply rep_form_pixel to 4096 (Squared) Nebulous Image.

Worked a second time, I don’t know what happened.

Looks like he has found the same limitation as you did with the custom versions of store and restore.
@Reptorian, are you running latest version 2.7.2 of the plug-in ?

2.7.2_pre#190912 via Krita 4.3 pre-alpha

So that’s probably one pre-release that didn’t contain the native versions of the store and restore commands. Try updating to latest stable version instead, it should work better.

I tested it, I get the variable store/restore not assigned. By Layer option for GUI Tiled Form worked before. Now it doesn’t.

gmic sp lena sp tiger rep_form_pixel -1,5,5,100
[gmic]-0./ Start G'MIC interpreter.
[gmic]-1./ Input sample image 'lena' (1 image 512x512x1x3).
[gmic]-1./ Input sample image 'tiger' (1 image 750x500x1x3).
[gmic]-2./rep_form_pixel/ Set local variable 'sid=-1'.
[gmic]-2./rep_form_pixel/ Set local variable 'isnum_sid=1'.
[gmic]-2./rep_form_pixel/ Set local variable 'isint_sid=1'.
[gmic]-2./rep_form_pixel/ Set local variable 'isnis=1'.
[gmic]-2./rep_form_pixel/ Set local variable 'isnum_sid=1'.
[gmic]-2./rep_form_pixel/ Set local variable 'isint_sid=1'.
[gmic]-2./rep_form_pixel/ Set local variable 'isnis=1'.
[gmic]-2./rep_form_pixel/ Store image [0] as variable 'shape_reference'
[gmic]-2./rep_form_pixel/*if/ Resize image [0] to 750x500x100%x100% , with no interpolation, dirichlet boundary conditions and alignment (0.5,0.5,0,0).
[gmic]-2./rep_form_pixel/*if/ Resize image [1] to 750x500x100%x100% , with no interpolation, neumann boundary conditions and alignment (0.5,0.5,0,0).
[gmic]-1./rep_form_pixel/*if/*if/ Apply command 'restore shape_reference rv _rep_form_pixel -1,5,5,100' on all image [1] in parallel, using 12 threads.
[gmic] *** Error in ./rep_form_pixel/*if/*if/apply_parallel/_apply_parallel/*if/ *** *** Error in ./rep_form_pixel/*if/*if/(...)/*thread0/_ap/*repeat/*local/ *** Command 'restore': Variable 'shape_reference' has not been assigned.