It is currently Tue Jul 02, 2024 3:19 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 12:27 am  (#21) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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")

Attachment:
GimpCurvesConfig.7z [238.53 KiB]
Downloaded 14 times

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 12:50 am  (#22) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
@tin
tried to put the explicit indication of where the file is in my samj's version, id est:

    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

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 1:14 am  (#23) 
Offline
GimpChat Member
User avatar

Joined: Dec 09, 2018
Posts: 656
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")

Attachment:
GimpCurvesConfig.7z

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

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

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


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 2:55 am  (#24) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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.

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 3:12 am  (#25) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
update:
added stmts for green and blue to my version: EUREKA, curves applied.

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 5:22 am  (#26) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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
Attachment:
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).

_________________
Image


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 5:31 am  (#27) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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
Attachment:
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).

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 5:57 am  (#28) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4001
Location: Canada
dinasset,
here's how I could do it.
    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)

_________________
TinT


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 6:08 am  (#29) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Tin, this is the current status of the filter I have tested.

Attachment:
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.

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 10:12 am  (#30) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
@tin
created a second process inserting what you suggested;
inserted traces;
it seems that the load loads only 6 presets, then stops
Attachment:
CatturaTraces.PNG
CatturaTraces.PNG [ 12.32 KiB | Viewed 566 times ]

any idea?

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 10:29 am  (#31) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
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?

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 1:18 pm  (#32) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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?

_________________
Image


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 1:58 pm  (#33) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Yes, of course.

Attachment:
python_cc_test2.7z [2.36 KiB]
Downloaded 13 times

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 2:50 pm  (#34) 
Offline
GimpChat Member
User avatar

Joined: Dec 09, 2018
Posts: 656
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:
      samplesString=extract(r'\(samples \d+ ([0-9. ]+)\)',samplesLine) # skip count value
to this
      samplesString=extract(r'\(samples \d+ ([-0-9.eE ]+)\)',samplesLine) # skip count value


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sat Jan 27, 2024 11:11 pm  (#35) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Thanks teapot.
Changed as indicated and now all presets are browsed.
Only left error at end, I will try to understand.

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sun Jan 28, 2024 12:34 am  (#36) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Update:
- completed the application of all 5 curves (value, red, green, bue, alpha)
here the new zipped program
Attachment:
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...

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sun Jan 28, 2024 2:14 am  (#37) 
Offline
GimpChat Member
User avatar

Joined: Dec 09, 2018
Posts: 656
dinasset wrote:
Update:
- completed the application of all 5 curves (value, red, green, bue, alpha)
here the new zipped program
Attachment:
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).


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sun Jan 28, 2024 2:52 am  (#38) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Thanks teapot.
I'll try to do my best in doing that, later on today.

_________________
"Where am I ?"


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sun Jan 28, 2024 3:48 am  (#39) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4752
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:

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)

_________________
Image


Top
 Post subject: Re: use of a color curves preset in a python filter
PostPosted: Sun Jan 28, 2024 6:27 am  (#40) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
@ofnuts
Wow!
Fantastic simplicity.
Updated the filter, done just the default test: OKAY.
Thanks a lot!
I will continue tests with all interesting presets.

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) How to call a python filter to run interactively

10

No new posts Attachment(s) Python calling G'MIC filter? (Solved)

4

No new posts New GEGL filter that inverts transparency and allows a color fill

2

No new posts Attachment(s) New G'MIC filter "Color Wheel"

12

No new posts Attachment(s) Like GIMP's new 3D transform preset.

5



* Login  



Powered by phpBB3 © phpBB Group