Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with correct colours in python script
#1
I have created a small script which fills a transparent layer with a colour. If I carry out the procedure manually I get the correct colour, but when I do it in Python the colour is incorrect. The example detailed below the colour is D37518 Hex - 211, 117, 24 Decimal.


The relevant piece of the code is:

   Tone = pdb.gimp_layer_new(image, width, height, type, "Tone", opacity, mode)            #new empty layer
    image.add_layer(Tone, 0)
    
    if colour == 0:
    
        sepia = gimpcolor.RGB(211,66,20)
        pdb.gimp_context_set_foreground(sepia)

    pdb.gimp_drawable_edit_fill(Tone, FILL_FOREGROUND)

If I run the code then check the inserted colour with the eyedropper I get the result in the screenshot.

No doubt something silly I am doing!


Attached Files Image(s)
   
Reply
#2
(12-06-2021, 04:16 PM)david Wrote: I have created a small script which fills a transparent layer with a colour. If I carry out the procedure manually I get the correct colour, but when I do it in Python the colour is incorrect. The example detailed below the colour is D37518 Hex - 211, 117, 24 Decimal.


The relevant piece of the code is:

   Tone = pdb.gimp_layer_new(image, width, height, type, "Tone", opacity, mode)            #new empty layer
    image.add_layer(Tone, 0)
    
    if colour == 0:
    
        sepia = gimpcolor.RGB(211,66,20)
        pdb.gimp_context_set_foreground(sepia)

    pdb.gimp_drawable_edit_fill(Tone, FILL_FOREGROUND)

If I run the code then check the inserted colour with the eyedropper I get the result in the screenshot.

No doubt something silly I am doing!

So what sets the foreground colour if colour != 0 ?
Reply
#3
I forgot to add to my original post: GIMP 2.10.28 running under ubuntu 20.04.

In case it is relevant I have attached the complete code. i just gave the one example, but the other four options with different colours are also incorrect.


Attached Files
.zip   colour_tone.zip (Size: 1.48 KB / Downloads: 139)
Reply
#4
(12-06-2021, 07:32 PM)david Wrote: I forgot to add to my original post: GIMP 2.10.28 running under ubuntu 20.04.

In case it is relevant I have attached the complete code. i just gave the one example, but the other four options with different colours are also incorrect.

I'm puzzled. I downloaded your script and to start with I was getting different values with the colour picker to those that were being set. I tried changing a few things and then could only get the correct values. I even deleted the version I had been playing with and re-downloaded the script - it still worked.

I am starting GIMP 2.10.28, creating a new RGB 8-bit image filled with the background colour of white. Image mode = RGB, precision = 8-bit with perceptual gamma (sRGB), colour management enabled. Then I run your script but have to make the lower two layer invisible before the picker gives the (expected) results.
Reply
#5
Works for me.

Is your image color indexed? Your code only considers Grayscale or else.

Your long if/else screams for an array/list or better: https://www.gimp-forum.net/Thread-Python...es-by-name

Your registration method is deprecated.
Reply
#6
Just tired on another system and it works for me all the time - not sure what I was seeing last night - probably just too tired :-)
Reply
#7
Many thanks for the replies.

I have carried out more tests this morning. The results are absolutely consistent. I used RGB and Grey images (which are converted to RGB), 8 bit precision, but have tried up to 32 bit floating point with the same results. I measured the result after converting the layer mode from soft-light to normal.

With colour selected as white: FFFFFF     255,255,255
the measured result is:           C5C5C5    197,197,197

With colour selected as red:   FF0000     255,0,0
the measured result is:          C50000    197,0,0

Similarly for green and blue.

With colour selected as grey: 7F7F7F     127,127,127
the measured result is:         616161     97,97,97

The result is consistently 0.77 (decimal) of the correct value.

Any suggestions for tests to resolve this problem are most welcome.
Reply
#8
(12-07-2021, 11:40 AM)david Wrote: Many thanks for the replies.

I have carried out more tests this morning. The results are absolutely consistent. I used RGB and Grey images (which are converted to RGB), 8 bit precision, but have tried up to 32 bit floating point with the same results. I measured the result after converting the layer mode from soft-light to normal.

With colour selected as white: FFFFFF     255,255,255
the measured result is:           C5C5C5    197,197,197

With colour selected as red:   FF0000     255,0,0
the measured result is:          C50000    197,0,0

Similarly for green and blue.

With colour selected as grey: 7F7F7F     127,127,127
the measured result is:         616161     97,97,97

The result is consistently 0.77 (decimal) of the correct value.

Any suggestions for tests to resolve this problem are most welcome.
Could you post the image that you are starting with - or if you are creating a new image the exact steps that you are using (including the settings under Advanced Options of the Create a New Image dialog?

Not doubting what you see, we just need to work out the difference between what you are doing and what Ofnuts and I are doing.

What settings do you have in Preferences/Colour Management?
Reply
#9
programmer_ceds,

Thanks for the reply.
I am getting the same consistent results with all the photographs I have tried - jpg and tif format - recent and going back as far as 2009.

I have attached a typical picture. However, I had to scale it to get within the size limits set by the site, but I have confirmed that it gives the same result.


Attached Files Thumbnail(s)
   
Image(s)
   
Reply
#10
I still don't see a problem when I load your image (even with the colour management settings the same). Just to be clear, in order to get the colour-picker readings I am making the lower two layers invisible - just leaving the Tone layer.
Reply


Forum Jump: