ext/RMagick/rmmain.c in rmagick-2.9.2 vs ext/RMagick/rmmain.c in rmagick-2.10.0

- old
+ new

@@ -1,6 +1,6 @@ -/* $Id: rmmain.c,v 1.288 2009/04/19 17:38:00 rmagick Exp $ */ +/* $Id: rmmain.c,v 1.296 2009/06/19 22:07:05 rmagick Exp $ */ /*============================================================================\ | Copyright (C) 2009 by Timothy P. Hunter | Name: rmmain.c | Author: Tim Hunter | Purpose: Contains all module, class, method declarations. @@ -19,31 +19,102 @@ static void test_Magick_version(void); static void version_constants(void); + + /* + * Handle transferring ImageMagick memory allocations/frees to Ruby. + * These functions have the same signature as the equivalent C functions. + */ +#if defined(HAVE_SETMAGICKMEMORYMETHODS) +static void *rm_malloc(size_t size) +{ + void *p; +// int old_state; + +// old_state = rb_gc_disable(); + p = xmalloc((long)size); +// if (!RTEST(old_state)) +// { +// rb_gc_enable(); +// } + + return p; +} + + + + +static void *rm_realloc(void *ptr, size_t size) +{ + void *p; +// int old_state; + +// old_state = rb_gc_disable(); + p = xrealloc(ptr, (long)size); +// if (!RTEST(old_state)) +// { +// rb_gc_enable(); +// } + + return p; +} + + + + +static void rm_free(void *ptr) +{ + xfree(ptr); +} + + +static void set_managed_memory(void) +{ + ID enable_mm = rb_intern("RMAGICK_ENABLE_MANAGED_MEMORY"); + + if (RTEST(rb_const_defined(rb_cObject, enable_mm)) && RTEST(rb_const_get(rb_cObject, enable_mm))) + { + rb_warning("RMagick: %s", "managed memory enabled. This is an experimental feature."); + SetMagickMemoryMethods(rm_malloc, rm_realloc, rm_free); + rb_define_const(Module_Magick, "MANAGED_MEMORY", Qtrue); + } + else + { + rb_define_const(Module_Magick, "MANAGED_MEMORY", Qfalse); + } +} +#endif + + + + +/* External: Init_RMagick2 Purpose: define the classes and constants Arguments: void Returns: void */ void Init_RMagick2(void) { volatile VALUE observable; -#if defined(HAVE_MAGICKCOREGENESIS) MagickCoreGenesis("RMagick", MagickFalse); -#else - InitializeMagick("RMagick"); -#endif test_Magick_version(); Module_Magick = rb_define_module("Magick"); +#if defined(HAVE_SETMAGICKMEMORYMETHODS) + set_managed_memory(); +#else + rb_define_const(Module_Magick, "MANAGED_MEMORY", Qfalse); +#endif + /*-----------------------------------------------------------------------*/ /* Create IDs for frequently used methods, etc. */ /*-----------------------------------------------------------------------*/ rm_ID_trace_proc = rb_intern("@trace_proc"); @@ -332,10 +403,11 @@ rb_define_method(Class_Image, "sample", Image_sample, -1); rb_define_method(Class_Image, "sample!", Image_sample_bang, -1); rb_define_method(Class_Image, "scale", Image_scale, -1); rb_define_method(Class_Image, "scale!", Image_scale_bang, -1); rb_define_method(Class_Image, "segment", Image_segment, -1); + rb_define_method(Class_Image, "selective_blur_channel", Image_selective_blur_channel, -1); rb_define_method(Class_Image, "separate", Image_separate, -1); rb_define_method(Class_Image, "sepiatone", Image_sepiatone, -1); rb_define_method(Class_Image, "set_channel_depth", Image_set_channel_depth, 2); rb_define_method(Class_Image, "shade", Image_shade, -1); rb_define_method(Class_Image, "shadow", Image_shadow, -1); @@ -740,11 +812,10 @@ ENUMERATOR(CenterAlign) ENUMERATOR(RightAlign) END_ENUM // AlphaChannelType constants -#if defined(HAVE_TYPE_ALPHACHANNELTYPE) DEF_ENUM(AlphaChannelType) ENUMERATOR(UndefinedAlphaChannel) ENUMERATOR(ActivateAlphaChannel) ENUMERATOR(DeactivateAlphaChannel) ENUMERATOR(ResetAlphaChannel) /* deprecated */ @@ -754,12 +825,14 @@ ENUMERATOR(ExtractAlphaChannel) ENUMERATOR(OpaqueAlphaChannel) ENUMERATOR(ShapeAlphaChannel) ENUMERATOR(TransparentAlphaChannel) #endif - END_ENUM +#if defined(HAVE_ENUM_BACKGROUNDALPHACHANNEL) + ENUMERATOR(BackgroundAlphaChannel) #endif + END_ENUM // AnchorType constants (for Draw#text_anchor - these are not defined by ImageMagick) DEF_ENUM(AnchorType) ENUMERATOR(StartAnchor) ENUMERATOR(MiddleAnchor) @@ -840,13 +913,11 @@ ENUMERATOR(Rec601LumaColorspace) ENUMERATOR(Rec601YCbCrColorspace) ENUMERATOR(Rec709LumaColorspace) ENUMERATOR(Rec709YCbCrColorspace) ENUMERATOR(LogColorspace) -#if defined(HAVE_ENUM_CMYCOLORSPACE) ENUMERATOR(CMYColorspace) -#endif END_ENUM // ComplianceType constants are defined as enums but used as bit flags DEF_ENUM(ComplianceType) ENUMERATOR(UndefinedCompliance) @@ -868,14 +939,15 @@ ENUMERATOR(UndefinedCompositeOp) ENUMERATOR(NoCompositeOp) ENUMERATOR(AddCompositeOp) ENUMERATOR(AtopCompositeOp) ENUMERATOR(BlendCompositeOp) +#if defined(HAVE_ENUM_BLURCOMPOSITEOP) + ENUMERATOR(BlurCompositeOp) +#endif ENUMERATOR(BumpmapCompositeOp) -#if defined(HAVE_ENUM_CHANGEMASKCOMPOSITEOP) ENUMERATOR(ChangeMaskCompositeOp) -#endif ENUMERATOR(ClearCompositeOp) ENUMERATOR(ColorBurnCompositeOp) ENUMERATOR(ColorDodgeCompositeOp) ENUMERATOR(ColorizeCompositeOp) ENUMERATOR(CopyBlackCompositeOp) @@ -886,13 +958,14 @@ ENUMERATOR(CopyMagentaCompositeOp) ENUMERATOR(CopyOpacityCompositeOp) ENUMERATOR(CopyRedCompositeOp) ENUMERATOR(CopyYellowCompositeOp) ENUMERATOR(DarkenCompositeOp) -#if defined(HAVE_ENUM_DIVIDECOMPOSITEOP) - ENUMERATOR(DivideCompositeOp) +#if defined(HAVE_ENUM_DISTORTCOMPOSITEOP) + ENUMERATOR(DistortCompositeOp) #endif + ENUMERATOR(DivideCompositeOp) ENUMERATOR(DstAtopCompositeOp) ENUMERATOR(DstCompositeOp) ENUMERATOR(DstInCompositeOp) ENUMERATOR(DstOutCompositeOp) ENUMERATOR(DstOverCompositeOp) @@ -902,13 +975,11 @@ ENUMERATOR(ExclusionCompositeOp) ENUMERATOR(HardLightCompositeOp) ENUMERATOR(HueCompositeOp) ENUMERATOR(InCompositeOp) ENUMERATOR(LightenCompositeOp) -#if defined(HAVE_ENUM_LINEARLIGHTCOMPOSITEOP) ENUMERATOR(LinearLightCompositeOp) -#endif ENUMERATOR(LuminizeCompositeOp) ENUMERATOR(MinusCompositeOp) ENUMERATOR(ModulateCompositeOp) ENUMERATOR(MultiplyCompositeOp) ENUMERATOR(OutCompositeOp) @@ -967,19 +1038,16 @@ ENUMERATOR(BackgroundDispose) ENUMERATOR(NoneDispose) ENUMERATOR(PreviousDispose) END_ENUM -#if defined(HAVE_DISTORTIMAGE) // DistortImage "method" argument values DEF_ENUM(DistortImageMethod) ENUMERATOR(UndefinedDistortion) ENUMERATOR(AffineDistortion) ENUMERATOR(AffineProjectionDistortion) -#if defined(HAVE_ENUM_ARCDISTORTION) ENUMERATOR(ArcDistortion) -#endif #if defined(HAVE_ENUM_POLARDISTORTION) ENUMERATOR(PolarDistortion) #endif #if defined(HAVE_ENUM_DEPOLARDISTORTION) ENUMERATOR(DePolarDistortion) @@ -993,13 +1061,11 @@ #endif #if defined(HAVE_ENUM_BILINEARREVERSEDISTORTION) ENUMERATOR(BilinearReverseDistortion) #endif ENUMERATOR(PerspectiveDistortion) -#if defined(HAVE_ENUM_PERSPECTIVEPROJECTIONDISTORTION) ENUMERATOR(PerspectiveProjectionDistortion) -#endif #if defined(HAVE_ENUM_POLYNOMIALDISTORTION) ENUMERATOR(PolynomialDistortion) #endif ENUMERATOR(ScaleRotateTranslateDistortion) #if defined(HAVE_ENUM_SHEPARDSDISTORTION) @@ -1007,11 +1073,10 @@ #endif #if defined(HAVE_ENUM_BARRELINVERSEDISTORTION) ENUMERATOR(BarrelInverseDistortion) #endif END_ENUM -#endif #if defined(HAVE_TYPE_DITHERMETHOD) DEF_ENUM(DitherMethod) ENUMERATOR(UndefinedDitherMethod) #if defined(HAVE_ENUM_NODITHERMETHOD) @@ -1103,19 +1168,13 @@ ENUMERATOR(UndefinedInterlace) ENUMERATOR(NoInterlace) ENUMERATOR(LineInterlace) ENUMERATOR(PlaneInterlace) ENUMERATOR(PartitionInterlace) -#if defined(HAVE_ENUM_GIFINTERLACE) ENUMERATOR(GIFInterlace) -#endif -#if defined(HAVE_ENUM_JPEGINTERLACE) ENUMERATOR(JPEGInterlace) -#endif -#if defined(HAVE_ENUM_PNGINTERLACE) ENUMERATOR(PNGInterlace) -#endif END_ENUM DEF_ENUM(InterpolatePixelMethod) ENUMERATOR(UndefinedInterpolatePixel) ENUMERATOR(AverageInterpolatePixel) @@ -1141,25 +1200,17 @@ ENUMERATOR(CompareOverlayLayer) ENUMERATOR(OptimizeLayer) ENUMERATOR(OptimizePlusLayer) ENUMERATOR(CoalesceLayer) ENUMERATOR(DisposeLayer) -#if defined(HAVE_ENUM_OPTIMIZETRANSLAYER) ENUMERATOR(OptimizeTransLayer) -#endif #if defined(HAVE_ENUM_OPTIMIZEIMAGELAYER) ENUMERATOR(OptimizeImageLayer) #endif -#if defined(HAVE_ENUM_REMOVEDUPSLAYER) ENUMERATOR(RemoveDupsLayer) -#endif -#if defined(HAVE_ENUM_REMOVEZEROLAYER) ENUMERATOR(RemoveZeroLayer) -#endif -#if defined(HAVE_ENUM_COMPOSITELAYER) ENUMERATOR(CompositeLayer) -#endif #if defined(HAVE_ENUM_MERGELAYER) ENUMERATOR(MergeLayer) #endif #if defined(HAVE_ENUM_MOSAICLAYER) ENUMERATOR(MosaicLayer) @@ -1174,13 +1225,11 @@ DEF_ENUM(MetricType) ENUMERATOR(UndefinedMetric) ENUMERATOR(AbsoluteErrorMetric) ENUMERATOR(MeanAbsoluteErrorMetric) -#if defined(HAVE_ENUM_MEANERRORPERPIXELMETRIC) ENUMERATOR(MeanErrorPerPixelMetric) -#endif ENUMERATOR(MeanSquaredErrorMetric) ENUMERATOR(PeakAbsoluteErrorMetric) ENUMERATOR(PeakSignalToNoiseRatioMetric) ENUMERATOR(RootMeanSquaredErrorMetric) END_ENUM @@ -1191,13 +1240,11 @@ ENUMERATOR(GaussianNoise) ENUMERATOR(MultiplicativeGaussianNoise) ENUMERATOR(ImpulseNoise) ENUMERATOR(LaplacianNoise) ENUMERATOR(PoissonNoise) -#if defined(HAVE_ENUM_RANDOMNOISE) ENUMERATOR(RandomNoise) -#endif END_ENUM // Orientation constants DEF_ENUM(OrientationType) ENUMERATOR(UndefinedOrientation) @@ -1337,22 +1384,16 @@ ENUMERATOR(VoronoiColorInterpolate) END_ENUM #endif // SpreadMethod -#if defined(HAVE_TYPE_SPREADMETHOD) - // In 6.3.0 ReflectSpread is misspelled as ReflectSpead. -#if !defined(HAVE_ENUM_REFLECTSPREAD) -#define ReflectSpread 2 -#endif DEF_ENUM(SpreadMethod) ENUMERATOR(UndefinedSpread) ENUMERATOR(PadSpread) ENUMERATOR(ReflectSpread) ENUMERATOR(RepeatSpread) END_ENUM -#endif // StorageType DEF_ENUM(StorageType) ENUMERATOR(UndefinedPixel) ENUMERATOR(CharPixel) @@ -1395,22 +1436,14 @@ ENUMERATOR(TransparentVirtualPixelMethod) ENUMERATOR(BackgroundVirtualPixelMethod) ENUMERATOR(DitherVirtualPixelMethod) ENUMERATOR(RandomVirtualPixelMethod) ENUMERATOR(ConstantVirtualPixelMethod) -#if defined(HAVE_ENUM_MASKVIRTUALPIXELMETHOD) ENUMERATOR(MaskVirtualPixelMethod) -#endif -#if defined(HAVE_ENUM_BLACKVIRTUALPIXELMETHOD) ENUMERATOR(BlackVirtualPixelMethod) -#endif -#if defined(HAVE_ENUM_GRAYVIRTUALPIXELMETHOD) ENUMERATOR(GrayVirtualPixelMethod) -#endif -#if defined(HAVE_ENUM_WHITEVIRTUALPIXELMETHOD) ENUMERATOR(WhiteVirtualPixelMethod) -#endif #if defined(HAVE_ENUM_HORIZONTALTILEVIRTUALPIXELMETHOD) ENUMERATOR(HorizontalTileVirtualPixelMethod) #endif #if defined(HAVE_ENUM_VERTICALTILEVIRTUALPIXELMETHOD) ENUMERATOR(VerticalTileVirtualPixelMethod) @@ -1571,10 +1604,10 @@ str = rb_str_new2(Q(RMAGICK_VERSION_STRING)); rb_obj_freeze(str); rb_define_const(Module_Magick, "Version", str); sprintf(long_version, - "This is %s ($Date: 2009/04/19 17:38:00 $) Copyright (C) 2009 by Timothy P. Hunter\n" + "This is %s ($Date: 2009/06/19 22:07:05 $) Copyright (C) 2009 by Timothy P. Hunter\n" "Built with %s\n" "Built for %s\n" "Web page: http://rmagick.rubyforge.org\n" "Email: rmagick@rubyforge.org\n", Q(RMAGICK_VERSION_STRING), mgk_version, Q(RUBY_VERSION_STRING));