Switch to full style
Ask all general Gimp related questions here
Post a reply

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 12:27 am

teapot wrote:I'm on an old version of 2.10 and my GimpCurvesConfig.settings has lines:
(linear no)
which Ofnuts script is also expecting.
However Tim has taken it out as the, presumably later version, file on post #13 doesn't have them.
...

I think that the "linear no" is added after having been used interactively, I see it now in my config file

I attach the zipped file after having used it online (the first now is "the klast used")

GimpCurvesConfig.7z
(238.53 KiB) Downloaded 14 times

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 12:50 am

@tin
tried to put the explicit indication of where the file is in my samj's version, id est:

Code:
    settings=load("C:\\Users\\diego\\Desktop\\Gimp-2.10.36_Portable_32-64bit-Win\\Preferences\\filters\\GimpCurvesConfig.settings")


but I still do get the error

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 1:14 am

dinasset wrote:
teapot wrote:I'm on an old version of 2.10 and my GimpCurvesConfig.settings has lines:
(linear no)
which Ofnuts script is also expecting.
However Tim has taken it out as the, presumably later version, file on post #13 doesn't have them.
...

I think that the "linear no" is added after having been used interactively, I see it now in my config file

I attach the zipped file after having used it online (the first now is "the klast used")

GimpCurvesConfig.7z

I think that means you need to change Tim's:

Code:
# nameLine,timeLine,linearLine=islice(settingsFile,3)
nameLine,timeLine=islice(settingsFile,2)

back to Ofnuts original:
Code:
nameLine,timeLine,linearLine=islice(settingsFile,3)

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 2:55 am

Done as you suggested, teapot.
Now my version displays all the messages sent by the filter, as the original tin's version.
But the layer is not modified, as per tin. at least it seems so.

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 3:12 am

update:
added stmts for green and blue to my version: EUREKA, curves applied.

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 5:22 am

dinasset wrote:Sorry Tin and Ofnuts.
- if I copy what you posted (included ofnuts' suggested change) I get a list of messages, but nothing else
- whatever I add in the code, for instance create a new layer, it is executed but then no more filter messages but an error
error-msg.PNG


As long as my little brain does not see at least one curve applied to an existing image I can't try to use the proposed flow.
You too Tin says: does not work on existing image, which is what I need: apply a curve to the input layer.
Thanks a lot for trying.


"List index out of range" when you are using an index of 0 means that the list is empty. And if you have an empty list it is probably because you have no explicitly named settings (as uploaded my code filters out the auto-saved settings).

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 5:31 am

ofnuts wrote:
dinasset wrote:Sorry Tin and Ofnuts.
- if I copy what you posted (included ofnuts' suggested change) I get a list of messages, but nothing else
- whatever I add in the code, for instance create a new layer, it is executed but then no more filter messages but an error
error-msg.PNG


As long as my little brain does not see at least one curve applied to an existing image I can't try to use the proposed flow.
You too Tin says: does not work on existing image, which is what I need: apply a curve to the input layer.
Thanks a lot for trying.


"List index out of range" when you are using an index of 0 means that the list is empty. And if you have an empty list it is probably because you have no explicitly named settings (as uploaded my code filters out the auto-saved settings).

if you read my last post, solved, and added also the loading of green and blue data (tin did it only for red) and I got the layer updated!
Now I have to find where and how to set the screening of a specific Preset (currently tin+mine load the first one).

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 5:57 am

dinasset,
here's how I could do it.
Code:
    chosen_setting_name = 'Yellowing Dark Corners'
    chosen_setting = None
    for setting in settings:
        if setting.name == chosen_setting_name:
            chosen_setting = setting
    if chosen_setting:           
        pdb.gimp_message(chosen_setting.name)
        pdb.gimp_message(chosen_setting.time)
        pdb.gimp_message(chosen_setting.channels[0].name) #value channel
        pdb.gimp_message(chosen_setting.channels[1].name) #red channel
        pdb.gimp_message(chosen_setting.channels[1].samples) #red channel
        redchannel_samples = chosen_setting.channels[1].samples
        pdb.gimp_drawable_curves_explicit(layer,HISTOGRAM_RED,len(redchannel_samples),redchannel_samples)

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 6:08 am

Tin, this is the current status of the filter I have tested.

python_cc_test.7z
(2.22 KiB) Downloaded 12 times


Apart from the specification of the curves presets source (which for me I had to specify as where I have samj's gimp) you can play with it trying to use the input parameter (already specified) as the preset to load.

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 10:12 am

@tin
created a second process inserting what you suggested;
inserted traces;
it seems that the load loads only 6 presets, then stops
CatturaTraces.PNG
CatturaTraces.PNG (12.32 KiB) Viewed 571 times

any idea?

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 10:29 am

If choose to load "Alien", the preset is applied because it is inside the 6 presets read.

So, the only thing strange is that the process "load" loads only 6 presets.

@ofnuts
any idea?

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 1:18 pm

dinasset wrote:If choose to load "Alien", the preset is applied because it is inside the 6 presets read.

So, the only thing strange is that the process "load" loads only 6 presets.

@ofnuts
any idea?

Can you zip & attach the latest code and settings file?

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 1:58 pm

Yes, of course.

python_cc_test2.7z
(2.36 KiB) Downloaded 13 times

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 2:50 pm

dinasset wrote:If choose to load "Alien", the preset is applied because it is inside the 6 presets read.

So, the only thing strange is that the process "load" loads only 6 presets.

Your seventh preset, "Bright Red" is failing in the green channel as it has numbers of format 9.7999999999999997e-05

The regular expression in funtion readChannel didn't support exponents so try changing this:
Code:
      samplesString=extract(r'\(samples \d+ ([0-9. ]+)\)',samplesLine) # skip count value
to this
Code:
      samplesString=extract(r'\(samples \d+ ([-0-9.eE ]+)\)',samplesLine) # skip count value

Re: use of a color curves preset in a python filter

Sat Jan 27, 2024 11:11 pm

Thanks teapot.
Changed as indicated and now all presets are browsed.
Only left error at end, I will try to understand.

Re: use of a color curves preset in a python filter

Sun Jan 28, 2024 12:34 am

Update:
- completed the application of all 5 curves (value, red, green, bue, alpha)
here the new zipped program
python_cc_test2.7z
(2.44 KiB) Downloaded 12 times


Now, because there are incomplete presets(*), I would like to know which statement insert to skip the types absent ("if ...." do not prepare/run the gimp command curves-explicit).
As I said, I'm ignorant enough not to know it myself.
Thanks for any help.

(*) I get always error messages for one channel, different from preset to preset...

Re: use of a color curves preset in a python filter

Sun Jan 28, 2024 2:14 am

dinasset wrote:Update:
- completed the application of all 5 curves (value, red, green, bue, alpha)
here the new zipped program
python_cc_test2.7z


Now, because there are incomplete presets(*), I would like to know which statement insert to skip the types absent ("if ...." do not prepare/run the gimp command curves-explicit).
As I said, I'm ignorant enough not to know it myself.
Thanks for any help.

(*) I get always error messages for one channel, different from preset to preset...

Some channels won't be present in the settings data as Ofnuts code doesn't add the identity channels (those that don't do anything as their curve is a straight line from bottom left to top right).

Identity channels have this in the GimpCurvesConfig.settings file:
points 4 0 0 1 1
e.g. Your preset "Alien" channel value and channel alpha.
Therefore your preset "Alien" only has red, green and blue channels in the settings data.

So code in your function python_cc_test2 won't work as in hard coding the indices it assumes all channels are present.

I'd suggest you have a for loop that goes through the channels like Ofnuts does at the end of his load-colour-curves-preset.py code:
for c in s.channels:
Or with your variable name
for c in chosen_setting.channels:
Then use c.name to see which one it is e.g. red and c.samples to get the samples.

Unfortunately I'm stuck on an old version of gimp due to hardware issues so can't run your code. (Am hoping for a new computer next month).

Re: use of a color curves preset in a python filter

Sun Jan 28, 2024 2:52 am

Thanks teapot.
I'll try to do my best in doing that, later on today.

Re: use of a color curves preset in a python filter

Sun Jan 28, 2024 3:48 am

teapot wrote:
dinasset wrote:Update:
I'd suggest you have a for loop that goes through the channels like Ofnuts does at the end of his load-colour-curves-preset.py code:
for c in s.channels:
Or with your variable name
for c in chosen_setting.channels:
Then use c.name to see which one it is e.g. red and c.samples to get the samples.

Unfortunately I'm stuck on an old version of gimp due to hardware issues so can't run your code. (Am hoping for a new computer next month).


And to avoid an "if" you just make a dictionary that map the channel name to the channel constant in the call:

Code:
channelConstants={
    "value" : HISTOGRAM_VALUE,
    "red":HISTOGRAM_RED,
    "green":HISTOGRAM_GREEN,
    "blue":HISTOGRAM_BLUE,
    "alpha":HISTOGRAM_ALPHA,
    }
           
for c in setting.channels:
    pdb.gimp_drawable_curves_explicit(drawable, channelConstants[c.name],len(c.samples),c.samples)

Re: use of a color curves preset in a python filter

Sun Jan 28, 2024 6:27 am

@ofnuts
Wow!
Fantastic simplicity.
Updated the filter, done just the default test: OKAY.
Thanks a lot!
I will continue tests with all interesting presets.
Post a reply