Post Reply 

Script-Fu: script does not work properly

May 14, 2011, 21:57
Post: #1
Script-Fu: script does not work properly
Hi gimp-users,
i try to get used to script-fu, but it seems very hard for me.
Now i have written a script and it can be registered in gimp, too, but when i execute it, there seems to be no effect. What should happen, is, that the script should duplicate the current layer. I would appreciate if you can have a look at it and give me some hint.

Thanks.

Script:

(define(script-fu-color-adjustment inImage inLayer)
(gimp-undo-push-group-start inImage)

(let*
(
(cp-layer (car (gimp-layer-copy inLayer 1)))

(gimp-image-add-layer cp-layer -1)
)
)

(gimp-undo-push-group-end inImage)
(gimp-displays-flush)
)

(script-fu-register "script-fu-color-adjustment"
"Color Adjustment"
"this script creates some layers\
to adjust the color settings"
"Tobias Wessels"
"copyright 2011, TW"
"May 14, 2011"
"*"
SF-IMAGE "inImage" 0
SF-DRAWABLE "inLayer" 0
)
(script-fu-menu-register "script-fu-color-adjustment"
"<Image>/Script-Fu/Photo/color-adjustment...")
Find all posts by this user
Quote this message in a reply
May 14, 2011, 22:41
Post: #2
RE: Script-Fu: script does not work properly
This why I write my scripts in Python Smile

Several things to try (or questions I ask here because you didn't says you tried)

1) run the bulk of the code in the script-fu console (Filters/Script-fu/Console) to see if it works as designed
2) see if you get anything in Gimp's error console (Windows/Dockable dialogs/Error console)
3) start Gimp in console mode (gimp-console in windows, or calling gimp from a bash prompt in Linux) and see if you get more info there
4) liberally lade your code with print statements and got to step 3)
5) find a good parentheses balance checker or Scheme editor
6) learn Python Smile

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
May 15, 2011, 13:57
Post: #3
RE: Script-Fu: script does not work properly
Ok, I will have to learn more about the differences of python and scheme and their preferences. But so far i managed to write down the whole script and get it working. Now there is just a little feature left.

In my script i am working with gimp-colorize to colorize my picture. For this procedure i need to get a parameter value (HUE) from the user, which is no problem with SF-VALUE, but i would like to have it like it is in the original menu entry: with a scroll bar and a sample of the color which will be used for colorization. Is it possible to do this with SF-ADJUSTMENT or in any other way?

To ofnuts: Thanks for your previous answer. Actually it did help me a bit. :-)
Find all posts by this user
Quote this message in a reply
May 15, 2011, 16:06
Post: #4
RE: Script-Fu: script does not work properly
Use SF_COLOR and document you only use the Hue.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
May 15, 2011, 21:59
Post: #5
RE: Script-Fu: script does not work properly
(May 15, 2011 16:06)ofnuts Wrote:  Use SF_COLOR and document you only use the Hue.

Ah ok... now i know how the color vector and the hue/saturation/lumination are connected. But is there any easy way to convert the RGB values to HSL values. Perhaps there exists a procedure in gimp or a script on the internet? I really tried to find it out on my own, but i can't find a satisfying answer.

So thank you for your patience, because i know that some questions seem to be stupid, when i look at them now, but i tried my best...
Find all posts by this user
Quote this message in a reply
May 15, 2011, 22:25
Post: #6
RE: Script-Fu: script does not work properly
You'll find the formulas/algorithms there:

http://en.wikipedia.org/wiki/HSL_and_HSV

Otherwise straight from the Gimp source, the C code to convert from one to the other:

Code:
/**
* gimp_rgb_to_hsv:
* @rgb: A color value in the RGB colorspace
* @hsv: The value converted to the HSV colorspace
*
* Does a conversion from RGB to HSV (Hue, Saturation,
* Value) colorspace.
**/
void
gimp_rgb_to_hsv (const GimpRGB *rgb,
                 GimpHSV       *hsv)
{
  gdouble max, min, delta;

  g_return_if_fail (rgb != NULL);
  g_return_if_fail (hsv != NULL);

  max = gimp_rgb_max (rgb);
  min = gimp_rgb_min (rgb);

  hsv->v = max;
  delta = max - min;

  if (delta > 0.0001)
    {
      hsv->s = delta / max;

      if (rgb->r == max)
        {
          hsv->h = (rgb->g - rgb->b) / delta;
          if (hsv->h < 0.0)
            hsv->h += 6.0;
        }
      else if (rgb->g == max)
        {
          hsv->h = 2.0 + (rgb->b - rgb->r) / delta;
        }
      else if (rgb->b == max)
        {
          hsv->h = 4.0 + (rgb->r - rgb->g) / delta;
        }

      hsv->h /= 6.0;
    }
  else
    {
      hsv->s = 0.0;
      hsv->h = 0.0;
    }

  hsv->a = rgb->a;
}

/**
* gimp_hsv_to_rgb:
* @hsv: A color value in the HSV colorspace
* @rgb: The returned RGB value.
*
* Converts a color value from HSV to RGB colorspace
**/
void
gimp_hsv_to_rgb (const GimpHSV *hsv,
                 GimpRGB       *rgb)
{
  gint    i;
  gdouble f, w, q, t;

  gdouble hue;

  g_return_if_fail (rgb != NULL);
  g_return_if_fail (hsv != NULL);

  if (hsv->s == 0.0)
    {
      rgb->r = hsv->v;
      rgb->g = hsv->v;
      rgb->b = hsv->v;
    }
  else
    {
      hue = hsv->h;

      if (hue == 1.0)
        hue = 0.0;

      hue *= 6.0;

      i = (gint) hue;
      f = hue - i;
      w = hsv->v * (1.0 - hsv->s);
      q = hsv->v * (1.0 - (hsv->s * f));
      t = hsv->v * (1.0 - (hsv->s * (1.0 - f)));

      switch (i)
        {
        case 0:
          rgb->r = hsv->v;
          rgb->g = t;
          rgb->b = w;
          break;
        case 1:
          rgb->r = q;
          rgb->g = hsv->v;
          rgb->b = w;
          break;
        case 2:
          rgb->r = w;
          rgb->g = hsv->v;
          rgb->b = t;
          break;
        case 3:
          rgb->r = w;
          rgb->g = q;
          rgb->b = hsv->v;
          break;
        case 4:
          rgb->r = t;
          rgb->g = w;
          rgb->b = hsv->v;
          break;
        case 5:
          rgb->r = hsv->v;
          rgb->g = w;
          rgb->b = q;
          break;
        }
    }

  rgb->a = hsv->a;
}

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Scale Image won’t show inches properly pixelated 5 1,243 Sep 18, 2014 18:47
Last Post: Mark Pigott
  Create new images button & Save as override from Script-fu beniman 12 523 Sep 10, 2014 10:57
Last Post: paynekj
  Can't get copy and paste to work UlyssesBlue 4 442 Sep 8, 2014 09:43
Last Post: UlyssesBlue
  How to work with anti-aliased shapes Sagemode 2 393 Jul 13, 2014 08:23
Last Post: Sagemode
  pattern fill info doesn't work lvquiet 12 662 Jun 5, 2014 06:37
Last Post: lvquiet

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS