Skip to content
Browse files

Add Image#function_channel

  • Loading branch information...
1 parent 7299cdd commit 06883b2b340454d730e69141936e420a564ac99f rmagick committed Sep 15, 2009
Showing with 96 additions and 4 deletions.
  1. +4 −0 ext/RMagick/extconf.rb
  2. +3 −1 ext/RMagick/rmagick.h
  3. +72 −1 ext/RMagick/rmimage.c
  4. +17 −2 ext/RMagick/rmmain.c
View
4 ext/RMagick/extconf.rb
@@ -201,6 +201,7 @@ def check_multiple_imagemagick_versions()
"EncipherImage", # 6.3.8-6
"EqualizeImageChannel", # 6.3.6-9
"FloodfillPaintImage", # 6.3.7
+ "FunctionImageChannel", # 6.4.8-8
"GetAuthenticIndexQueue", # 6.4.5-6
"GetAuthenticPixels", # 6.4.5-6
"GetImageAlphaChannel", # 6.3.9-2
@@ -257,6 +258,7 @@ def check_multiple_imagemagick_versions()
have_struct_member("DrawInfo", "interline_spacing", headers) # 6.5.5-8
have_struct_member("DrawInfo", "interword_spacing", headers) # 6.4.8-0
have_type("DitherMethod", headers) # 6.4.2
+have_type("MagickFunction", headers) # 6.4.8-8
have_type("ImageLayerMethod", headers) # 6.3.6 replaces MagickLayerMethod
have_type("long double", headers)
#have_type("unsigned long long", headers)
@@ -317,6 +319,8 @@ def check_multiple_imagemagick_versions()
"SineEvaluateOperator", # 6.4.8-5
"AddModulusEvaluateOperator"], # 6.4.8-5
headers)
+have_enum_values("MagickFunction", ["ArcsinFunction", # 6.5.2-8
+ "ArctanFunction"], headers) # 6.5.2-8
have_enum_values("ImageLayerMethod", ["FlattenLayer", # 6.3.6-2
"MergeLayer", # 6.3.6
"MosaicLayer", # 6.3.6-2
View
4 ext/RMagick/rmagick.h
@@ -1,4 +1,4 @@
-/* $Id: rmagick.h,v 1.277 2009/09/11 22:29:30 rmagick Exp $ */
+/* $Id: rmagick.h,v 1.278 2009/09/15 22:09:44 rmagick Exp $ */
/*=============================================================================
| Copyright (C) 2009 by Timothy P. Hunter
| Name: rmagick.h
@@ -363,6 +363,7 @@ EXTERN VALUE Class_ImageType;
EXTERN VALUE Class_InterlaceType;
EXTERN VALUE Class_InterpolatePixelMethod;
EXTERN VALUE CLASS_LAYERMETHODTYPE;
+EXTERN VALUE Class_MagickFunction;
EXTERN VALUE Class_NoiseType;
EXTERN VALUE Class_OrientationType;
EXTERN VALUE Class_PaintMethod;
@@ -954,6 +955,7 @@ extern VALUE Image_flop(VALUE);
extern VALUE Image_flop_bang(VALUE);
extern VALUE Image_frame(int, VALUE *, VALUE);
extern VALUE Image_from_blob(VALUE, VALUE);
+extern VALUE Image_function_channel(int, VALUE *, VALUE);
extern VALUE Image_gamma_channel(int, VALUE *, VALUE);
extern VALUE Image_gamma_correct(int, VALUE *, VALUE);
extern VALUE Image_gaussian_blur(int, VALUE *, VALUE);
View
73 ext/RMagick/rmimage.c
@@ -1,4 +1,4 @@
-/* $Id: rmimage.c,v 1.354 2009/09/10 23:03:33 rmagick Exp $ */
+/* $Id: rmimage.c,v 1.355 2009/09/15 22:09:44 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2009 by Timothy P. Hunter
| Name: rmimage.c
@@ -5126,6 +5126,77 @@ Image_from_blob(VALUE class, VALUE blob_arg)
}
+/*
+ * Method: Image#function_channel(function, args[, channel...])
+ */
+VALUE
+Image_function_channel(int argc, VALUE *argv, VALUE self)
+{
+ Image *image, *new_image;
+ MagickFunction function;
+ unsigned long n, nparms;
+ volatile double *parameters;
+ double *parms;
+ ChannelType channels;
+ ExceptionInfo exception;
+
+ image = rm_check_destroyed(self);
+ channels = extract_channels(&argc, argv);
+
+ // The number of parameters depends on the function.
+ if (argc == 0)
+ {
+ rb_raise(rb_eArgError, "no function specified");
+ }
+
+ VALUE_TO_ENUM(argv[0], function, MagickFunction);
+ argc -= 1;
+ argv += 1;
+
+ switch (function)
+ {
+ case PolynomialFunction:
+ if (argc == 0)
+ {
+ rb_raise(rb_eArgError, "PolynomialFunction requires at least one argument.");
+ }
+ break;
+ case SinusoidFunction:
+#if defined(HAVE_ENUM_ARCSINFUNCTION)
+ case ArcsinFunction:
+#endif
+#if defined(HAVE_ENUM_ARCTANFUNCTION)
+ case ArctanFunction:
+#endif
+ if (argc < 1 || argc > 4)
+ {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc);
+ }
+ break;
+ default:
+ rb_raise(rb_eArgError, "undefined function");
+ break;
+ }
+
+ nparms = argc;
+ parameters = parms = ALLOC_N(double, nparms);
+
+ for (n = 0; n < nparms; n++)
+ {
+ parms[n] = NUM2DBL(argv[n]);
+ }
+
+ GetExceptionInfo(&exception);
+ new_image = rm_clone_image(image);
+ (void) FunctionImageChannel(new_image, channels, function, nparms, parms, &exception);
+ (void) xfree(parms);
+ rm_check_exception(&exception, new_image, DestroyOnError);
+ DestroyExceptionInfo(&exception);
+
+ return rm_image_new(new_image);
+}
+
+
DEF_ATTR_READER(Image, fuzz, dbl)
View
19 ext/RMagick/rmmain.c
@@ -1,4 +1,4 @@
-/* $Id: rmmain.c,v 1.301 2009/09/11 22:29:30 rmagick Exp $ */
+/* $Id: rmmain.c,v 1.302 2009/09/15 22:09:44 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2009 by Timothy P. Hunter
| Name: rmmain.c
@@ -343,6 +343,7 @@ Init_RMagick2(void)
rb_define_method(Class_Image, "flop", Image_flop, 0);
rb_define_method(Class_Image, "flop!", Image_flop_bang, 0);
rb_define_method(Class_Image, "frame", Image_frame, -1);
+ rb_define_method(Class_Image, "function_channel", Image_function_channel, -1);
rb_define_method(Class_Image, "gamma_channel", Image_gamma_channel, -1);
rb_define_method(Class_Image, "gamma_correct", Image_gamma_correct, -1);
rb_define_method(Class_Image, "gaussian_blur", Image_gaussian_blur, -1);
@@ -1224,6 +1225,20 @@ Init_RMagick2(void)
#endif
END_ENUM
+#if defined(HAVE_TYPE_MAGICKFUNCTION)
+ DEF_ENUM(MagickFunction)
+ ENUMERATOR(UndefinedFunction)
+ ENUMERATOR(PolynomialFunction)
+ ENUMERATOR(SinusoidFunction)
+#if defined(HAVE_ENUM_ARCSINFUNCTION)
+ ENUMERATOR(ArcsinFunction)
+#endif
+#if defined(HAVE_ENUM_ARCTANFUNCTION)
+ ENUMERATOR(ArctanFunction)
+#endif
+ END_ENUM
+#endif
+
#if defined(HAVE_TYPE_IMAGELAYERMETHOD)
DEF_ENUM(ImageLayerMethod)
#else
@@ -1641,7 +1656,7 @@ version_constants(void)
rb_define_const(Module_Magick, "Version", str);
sprintf(long_version,
- "This is %s ($Date: 2009/09/11 22:29:30 $) Copyright (C) 2009 by Timothy P. Hunter\n"
+ "This is %s ($Date: 2009/09/15 22:09:44 $) Copyright (C) 2009 by Timothy P. Hunter\n"
"Built with %s\n"
"Built for %s\n"
"Web page: http://rmagick.rubyforge.org\n"

0 comments on commit 06883b2

Please sign in to comment.
Something went wrong with that request. Please try again.