Store variables should have the option to be used as vector

Hi,

After making my latest filter (which has to come out), I realized that it would be convenient to store images as a set of vector or at least it would make some code easier to write. Something like this.

sp dog,cat,lena store imgs ($imgs)[1]

Desired: cat
Actual: error

In theory, such a syntax would not be a bad idea. In practice, however, it could be. So I’m not sure I want to propose it yet.

My main concern comes from the way the store command is designed to be used. A stored image (or list of images) is saved in memory in a serialized form (which does not compress the image list, but at least re-encode it as a linear buffer of bytes). So “de-serializing” it (with input $imgs) has a quite significant algorithmic cost.

So, allowing a syntax as input $imgs[1] would mean the entire list of images is de-serialized each time, just to return a single image. So in the current settings, this would be always quite slow, and a bad coding practice to allow this.

Two perspectives then:

  1. We don’t allow this, and recommend that if the user wants to access a single image in a stored list, then it’s better to store all images of the list as independent variables, with
sp lena,duck,earth store img0,img1,img2 ... $img1

This is in fact what you can already do with the current version of G’MIC.
If you really want to keep a single variable, then:

sp lena,duck,eart store imgs ... l[] $imgs k[1] endl

will work too.

  1. We allow this in the future, but this means all the store mechanism should be redesigned internally first, to make it more suitable to be used in this context. Not sure it’s worth it, if an alternative solution as above can be always used.

There’s a 3rd solution it appears.

rep_vstore:
name=$1
repeat $!
 tname=_
 tname.=$name
 tname.=$>
 store[0] $tname
 echo $tname
done
sp cat,dog,david rep_vstore img $_img1

Output:dog

However, in conjunction with this

$1=name of image
$2=image_id
rep_vstore_restore:
restore_img=${arg\ 1+0,_$1$2}
$restore_img

It fails to work even it should work in theory.

EDIT: I solved it with this.

rep_vstore_restore:
$_$1$2

------
sp cat,dog,david rep_vstore img rep_vstore_restore img,1
Output : dog