It is currently Thu Apr 25, 2024 7:58 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: help invert color
PostPosted: Sun May 29, 2016 4:50 am  (#1) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
How to write invert Colos in the SCM code, but instead of calling the plugin in the Invert.

I tried to use (gimp-drawable-get-pixel drawable x-Coord y-Coord) for each pixel value, again with 255 minus the per-pixel values, and then use the (gimp-drawable-set-pixel drawable x-Coord y-Coord) to redraw, but in execution (GIMP-drawable-get-pixel drawable X-Coord y-Coord) when an error do not know how to extract the RGB value, please advise. Or a complete SCM code available for reference.
Attachment:
snip_20160529172759.png
snip_20160529172759.png [ 31.31 KiB | Viewed 3034 times ]


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 8:47 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
just a piece of the script you want, only to show how to access independently R,G,B values

(define (script-fu-test-color-by-pixel
         image
         drawable
       )
  (let*
   (
     (RGBvalues '(0 0 0))
     (REDvalue 0)
     (GREENvalue 0)
     (BLUEvalue 0)
   )
  (set! RGBvalues (cadr (gimp-drawable-get-pixel drawable 100 100)))
  (set! REDvalue  (aref RGBvalues 0))
  (set! GREENvalue  (aref RGBvalues 1))
  (set! BLUEvalue  (aref RGBvalues 2))
  (gimp-message (string-append "RED = " (number->string REDvalue)))
 
  ;;; and so on ....
 
  ) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
            _"<Image>/Script-Fu/Test/test-color-by-pixel"
            "test getting RGB from a pixel"
            "D.N"
            "2016"
            "2016"
            "RGB*"
            SF-IMAGE        "Image"     0
            SF-DRAWABLE     "Drawable"  0
)
 

_________________
"Where am I ?"


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 10:37 am  (#3) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
dinasset wrote:
just a piece of the script you want, only to show how to access independently R,G,B values

(define (script-fu-test-color-by-pixel
         image
         drawable
       )
  (let*
   (
     (RGBvalues '(0 0 0))
     (REDvalue 0)
     (GREENvalue 0)
     (BLUEvalue 0)
   )
  (set! RGBvalues (cadr (gimp-drawable-get-pixel drawable 100 100)))
  (set! REDvalue  (aref RGBvalues 0))
  (set! GREENvalue  (aref RGBvalues 1))
  (set! BLUEvalue  (aref RGBvalues 2))
  (gimp-message (string-append "RED = " (number->string REDvalue)))
 
  ;;; and so on ....
 
  ) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
            _"<Image>/Script-Fu/Test/test-color-by-pixel"
            "test getting RGB from a pixel"
            "D.N"
            "2016"
            "2016"
            "RGB*"
            SF-IMAGE        "Image"     0
            SF-DRAWABLE     "Drawable"  0
)
 

Thank dinasset.


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 11:56 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Take it as an exercise, because there is no reason to manage pixel by pixel an image using scheme, it will require a huge amount of time.
I recommend you to use python instead with the use of tiles, extremely faster.
You may take as a base my filter remove-overpainted-colours.py here
You will need to change only a few statements to "invert the colours".
I can't follow you during the next days, because I'm going out for week or so.
But you may try and -if necessary- we will be again in touch when I'll be back.

_________________
"Where am I ?"


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:13 pm  (#5) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
dinasset wrote:
Take it as an exercise, because there is no reason to manage pixel by pixel an image using scheme, it will require a huge amount of time.
I recommend you to use python instead with the use of tiles, extremely faster.
You may take as a base my filter remove-overpainted-colours.py here
You will need to change only a few statements to "invert the colours".
I can't follow you during the next days, because I'm going out for week or so.
But you may try and -if necessary- we will be again in touch when I'll be back.


Thank dinasset, but I can not open this page.


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:17 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
click on Latest GIMP Scripts & Plug-ins (top area of this panel)
search on the left the most recent addition
you should find the link

_________________
"Where am I ?"


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:21 pm  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
BTW, on my previous message, did you click on the word "here"?

_________________
"Where am I ?"


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:26 pm  (#8) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
dinasset wrote:
BTW, on my previous message, did you click on the word "here"?

I see it, but I based on network constraints, can not open website you said.


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:34 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
which kind of network constraint?

_________________
"Where am I ?"


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:45 pm  (#10) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
dinasset wrote:
which kind of network constraint?

Network provider, firewall policy reasons, cannot open certain Web sites


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 12:47 pm  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
this info should be addressed to the Moderators, hope they can solve that problem.
Create a new thread (Help/ Site Support) to address this issue directly to the site moderators

_________________
"Where am I ?"


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 2:36 pm  (#12) 
Offline
Administrator
User avatar

Joined: Aug 10, 2012
Posts: 13016
Location: Native to NYC living in Arizona, Gimp 2.8 & 2.10, Win 11 PC.
gimptest wrote:
dinasset wrote:
which kind of network constraint?

Network provider, firewall policy reasons, cannot open certain Web sites



dinasset wrote:
this info should be addressed to the Moderators, hope they can solve that problem.
Create a new thread (Help/ Site Support) to address this issue directly to the site moderators


It seems as though this is a "Network Provider Firewall Policy".
As was stated by gimptest.
If gimptest's Network Provider doesn't allow some traffic in particular to it's own Firewall Policies.
This has nothing to do with Gimp Chat or the Gimp Scripts website.
Gimp Chat nor the Gimp Scripts website;
can not possibly accommodate every "Network Provider's Fire Wall Policies".
This would be something which gimptest would need to circumvent on his own,
or with the help of his Network Provider.

_________________
Image
"A wise man learns more from a foolish question than a fool can learn from a wise answer"
Image


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 7:36 pm  (#13) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
dinasset wrote:
this info should be addressed to the Moderators, hope they can solve that problem.
Create a new thread (Help/ Site Support) to address this issue directly to the site moderators

Only network providers set limits


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 7:37 pm  (#14) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
Wallace wrote:
gimptest wrote:
dinasset wrote:
which kind of network constraint?

Network provider, firewall policy reasons, cannot open certain Web sites



dinasset wrote:
this info should be addressed to the Moderators, hope they can solve that problem.
Create a new thread (Help/ Site Support) to address this issue directly to the site moderators


It seems as though this is a "Network Provider Firewall Policy".
As was stated by gimptest.
If gimptest's Network Provider doesn't allow some traffic in particular to it's own Firewall Policies.
This has nothing to do with Gimp Chat or the Gimp Scripts website.
Gimp Chat nor the Gimp Scripts website;
can not possibly accommodate every "Network Provider's Fire Wall Policies".
This would be something which gimptest would need to circumvent on his own,
or with the help of his Network Provider.


Yes, access to certain websites had to use a VPN, but use the VPN is also sometimes can and sometimes cannot be


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 8:07 pm  (#15) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
dinasset wrote:
just a piece of the script you want, only to show how to access independently R,G,B values

(define (script-fu-test-color-by-pixel
         image
         drawable
       )
  (let*
   (
     (RGBvalues '(0 0 0))
     (REDvalue 0)
     (GREENvalue 0)
     (BLUEvalue 0)
   )
  (set! RGBvalues (cadr (gimp-drawable-get-pixel drawable 100 100)))
  (set! REDvalue  (aref RGBvalues 0))
  (set! GREENvalue  (aref RGBvalues 1))
  (set! BLUEvalue  (aref RGBvalues 2))
  (gimp-message (string-append "RED = " (number->string REDvalue)))
 
  ;;; and so on ....
 
  ) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
            _"<Image>/Script-Fu/Test/test-color-by-pixel"
            "test getting RGB from a pixel"
            "D.N"
            "2016"
            "2016"
            "RGB*"
            SF-IMAGE        "Image"     0
            SF-DRAWABLE     "Drawable"  0
)
 


I'm using (gimp-drawable-set-pixel drawable x-Coord y-Coord NUM-channels pixel), parameter error, don't know how this argument is correct

Attachment:
snip_20160530085704.png
snip_20160530085704.png [ 32.51 KiB | Viewed 1181 times ]

 (define (script-fu-test-color-by-pixel
image
drawable
)
(let*
(
(RGBvalues '(0 0 0))
(REDvalue 0)
(GREENvalue 0)
(BLUEvalue 0)
(numch 0)
)
(set! RGBvalues (cadr (gimp-drawable-get-pixel drawable 100 100)))
(set! numch (car (gimp-drawable-get-pixel drawable 100 100)))
(set! REDvalue (aref RGBvalues 0))
(set! GREENvalue (aref RGBvalues 1))
(set! BLUEvalue (aref RGBvalues 2))
(gimp-message (string-append "RED = " (number->string REDvalue)))
(set! RGBvalues '((- 255 REDvalue) (- 255 GREENvalue) (- 255 BLUEvalue)))
(gimp-drawable-set-pixel drawable 100 numch RGBvalues)
(gimp-displays-flush)

;;; and so on ....

) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
_"<Image>/Script-Fu/Test/test-color-by-pixel"
"test getting RGB from a pixel"
"D.N"
"2016"
"2016"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)
 


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 8:37 pm  (#16) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
(gimp-drawable-set-pixel drawable 100 numch RGBvalues)
seems to be missing an x-coord or y-coord

_________________
TinT


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 8:47 pm  (#17) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
trandoductin wrote:
(gimp-drawable-set-pixel drawable 100 numch RGBvalues)
seems to be missing an x-coord or y-coord


Thank trandoductin
It still doesn't work. (gimp-drawable-set-pixel drawable x-Coord y-Coord NUM-channels pixel) pixel parameters do not know how to write

Attachment:
snip_20160530094605.png
snip_20160530094605.png [ 31.24 KiB | Viewed 1177 times ]


 (define (script-fu-test-color-by-pixel
image
drawable
)
(let*
(
(RGBvalues '(0 0 0))
(REDvalue 0)
(GREENvalue 0)
(BLUEvalue 0)
(numch 0)
(x-coord 100)
(y-coord 100)
)
(set! RGBvalues (cadr (gimp-drawable-get-pixel drawable x-coord y-coord)))
(set! numch (car (gimp-drawable-get-pixel drawable x-coord y-coord)))
(set! REDvalue (aref RGBvalues 0))
(set! GREENvalue (aref RGBvalues 1))
(set! BLUEvalue (aref RGBvalues 2))
(gimp-message (string-append "RED = " (number->string REDvalue)))
(set! RGBvalues '((- 255 REDvalue) (- 255 GREENvalue) (- 255 BLUEvalue)))
(gimp-drawable-set-pixel drawable x-coord y-coord numch RGBvalues)
(gimp-displays-flush)

;;; and so on ....

) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
_"<Image>/Script-Fu/Test/test-color-by-pixel"
"test getting RGB from a pixel"
"D.N"
"2016"
"2016"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)
 


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 10:04 pm  (#18) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
you can't do math in a static list, you'll have to use (list) function to construct a list.
gimp-drawable-set-pixel accepts an array/vector instead of list so you'll have to use (list->vector) function
and also it doesn't update the front end for you to see the change until you call (gimp-drawable-update) or manually hide the layer and show it again.
try sample code below

(set! RGBvalues (list (- 255 REDvalue) (- 255 GREENvalue) (- 255 BLUEvalue)))
(gimp-drawable-set-pixel drawable x-coord y-coord numch (list->vector RGBvalues))
(gimp-drawable-update drawable 0 0 (car (gimp-drawable-width drawable)) (car (gimp-drawable-height drawable)))


Note: the numch can be a 4 if there's an alpha channel in your layer/drawable, you might want to copy the 4th value over if drawable/layer has alpha.

_________________
TinT


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 10:50 pm  (#19) 
Offline
GimpChat Member

Joined: Feb 21, 2016
Posts: 34
trandoductin wrote:
you can't do math in a static list, you'll have to use (list) function to construct a list.
gimp-drawable-set-pixel accepts an array/vector instead of list so you'll have to use (list->vector) function
and also it doesn't update the front end for you to see the change until you call (gimp-drawable-update) or manually hide the layer and show it again.
try sample code below

(set! RGBvalues (list (- 255 REDvalue) (- 255 GREENvalue) (- 255 BLUEvalue)))
(gimp-drawable-set-pixel drawable x-coord y-coord numch (list->vector RGBvalues))
(gimp-drawable-update drawable 0 0 (car (gimp-drawable-width drawable)) (car (gimp-drawable-height drawable)))


Note: the numch can be a 4 if there's an alpha channel in your layer/drawable, you might want to copy the 4th value over if drawable/layer has alpha.


Thank trandoductin
I've added alpha, but didn't know it was still wrong
You can paste the complete code let me reference?

Attachment:
snip_20160530113918.png
snip_20160530113918.png [ 30 KiB | Viewed 1163 times ]


(define (script-fu-test-color-by-pixel
         image
         drawable
       )
  (let*
   (
     (RGBvalues '(0 0 0))
     (REDvalue 0)
     (GREENvalue 0)
     (BLUEvalue 0)
    (numch 0)
    (x-coord 100)
     (y-coord 100)
    (alpha (car (gimp-drawable-has-alpha drawable)))
   )
   
  (if (= alpha FALSE) (gimp-layer-add-alpha drawable))
  (set! RGBvalues (cadr (gimp-drawable-get-pixel drawable 100 100)))
  (set! numch (car (gimp-drawable-get-pixel drawable 100 100)))
  (set! REDvalue  (aref RGBvalues 0))
  (set! GREENvalue  (aref RGBvalues 1))
  (set! BLUEvalue  (aref RGBvalues 2))
  (gimp-message (string-append "RED = " (number->string REDvalue)))
  (set! RGBvalues (list (- 255 REDvalue) (- 255 GREENvalue) (- 255 BLUEvalue)))
  (gimp-drawable-set-pixel drawable x-coord y-coord numch (list->vector RGBvalues))
  (gimp-drawable-update drawable 0 0 (car (gimp-drawable-width drawable)) (car (gimp-drawable-height drawable)))

  (gimp-displays-flush)
 
  ;;; and so on ....
 
  ) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
            _"<Image>/Script-Fu/Test/test-color-by-pixel"
            "test getting RGB from a pixel"
            "D.N"
            "2016"
            "2016"
            "RGB*"
            SF-IMAGE        "Image"     0
            SF-DRAWABLE     "Drawable"  0
)
 


Top
 Post subject: Re: help invert color
PostPosted: Sun May 29, 2016 11:30 pm  (#20) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
try this, it'll check to see if numch is 4 means there's alpha and will also work if there's no alpha channel.
(define (script-fu-test-color-by-pixel
image
drawable
)
(let*
(
(RGBvalues 0)
(REDvalue 0)
(GREENvalue 0)
(BLUEvalue 0)
(numch 0)
(x-coord 100)
(y-coord 100)
)
(set! RGBvalues (cadr (gimp-drawable-get-pixel drawable x-coord y-coord)))
(set! numch (car (gimp-drawable-get-pixel drawable x-coord y-coord)))
(set! REDvalue (aref RGBvalues 0))
(set! GREENvalue (aref RGBvalues 1))
(set! BLUEvalue (aref RGBvalues 2))
(define my_pixel (list (- 255 REDvalue) (- 255 GREENvalue) (- 255 BLUEvalue) 255))
(if (= numch 4)
   (begin   ;if numch = 4 means drawable has an alpha channel we just add whatever that is to our pixel
      (set! my_pixel (append my_pixel (list (aref RGBvalues 3))))
   )
   (begin   ;else do nothing
   )
)
;(gimp-message (string-append "RED = " (number->string REDvalue)))
(gimp-drawable-set-pixel drawable x-coord y-coord numch (list->vector my_pixel))
(gimp-drawable-update drawable 0 0 (car (gimp-drawable-width drawable)) (car (gimp-drawable-height drawable)))
(gimp-displays-flush)

;;; and so on ....

) ; end let
) ; end define

(script-fu-register "script-fu-test-color-by-pixel"
_"<Image>/Script-Fu/Test/test-color-by-pixel"
"test getting RGB from a pixel"
"D.N"
"2016"
"2016"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
)

_________________
TinT


Top
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) GEGL Color Light Fusion (12 blend modes for color overlay)

9

No new posts Attachment(s) Background color chanage and typed text color change

8

No new posts Attachment(s) Color does not exactly match color in GIMP 2.10 (SOLVED)

9

No new posts Color changes to last color when I touch tablet pen to tablet. HELP

2

No new posts Color Adjusting Help

1



* Login  



Powered by phpBB3 © phpBB Group