ext/RMagick/rmutil.c in rmagick-2.0.0 vs ext/RMagick/rmutil.c in rmagick-2.1.0

- old
+ new

@@ -1,8 +1,8 @@ -/* $Id: rmutil.c,v 1.138 2007/12/26 21:43:52 rmagick Exp $ */ +/* $Id: rmutil.c,v 1.144 2008/01/03 15:32:00 rmagick Exp $ */ /*============================================================================\ -| Copyright (C) 2007 by Timothy P. Hunter +| Copyright (C) 2008 by Timothy P. Hunter | Name: rmutil.c | Author: Tim Hunter | Purpose: Utility functions for RMagick \============================================================================*/ @@ -174,14 +174,14 @@ * Purpose: raise exception if array too short */ void rm_check_ary_len(VALUE ary, long len) { - if (RARRAY(ary)->len < len) + if (RARRAY_LEN(ary) < len) { rb_raise(rb_eIndexError, "not enough elements in array - expecting %ld, got %ld", - len, (long)RARRAY(ary)->len); + len, (long)RARRAY_LEN(ary)); } } /* @@ -202,15 +202,15 @@ return image; } /* - Extern: rm_check_frozen_image + Extern: rm_check_frozen Purpose: raise an error if the image has been destroyed or is frozen */ Image * -rm_check_frozen_image(VALUE obj) +rm_check_frozen(VALUE obj) { Image *image = rm_check_destroyed(obj); rb_check_frozen(obj); return image; } @@ -226,10 +226,26 @@ rb_raise(rb_eTypeError, "can't freeze %s", rb_class2name(CLASS_OF(obj))); } /* + Extern: rm_str2cstr(str, &len); + Purpose: Supply our own version of the "obsolete" rm_str2cstr. +*/ +char * +rm_str2cstr(VALUE str, long *len) +{ + StringValue(str); + if (len) + { + *len = RSTRING_LEN(str); + } + return RSTRING_PTR(str); +} + + +/* * Static: arg_is_number * Purpose: Try to convert the argument to a double, * raise an exception if fail. */ static VALUE @@ -568,11 +584,11 @@ Image *image; Pixel *pixel; char name[MaxTextExtent]; ExceptionInfo exception; ComplianceType compliance = AllCompliance; - unsigned int matte = False; + unsigned int matte = MagickFalse; unsigned int depth = QuantumDepth; switch (argc) { case 3: @@ -658,11 +674,11 @@ class = class; // defeat "never referenced" message from icc memset(&rgb, 0, sizeof(rgb)); hsl = rb_Array(hsl); // Ensure array - if (RARRAY(hsl)->len < 3) + if (RARRAY_LEN(hsl) < 3) { rb_raise(rb_eArgError, "array argument must have at least 3 elements"); } hue = NUM2DBL(rb_ary_entry(hsl, 0)); @@ -2012,11 +2028,35 @@ color = rb_rescue(rb_str_to_str, color, color_arg_rescue, color); Color_Name_to_PixelPacket(pp, color); } } + /* + Extern: Color_to_MagickPixelPacket + Purpose: Convert either a String color name or + a Magick::Pixel to a MagickPixelPacket + Notes: The channel values in a MagickPixelPacket are doubles. +*/ +void +Color_to_MagickPixelPacket(Image *image, MagickPixelPacket *mpp, VALUE color) +{ + PixelPacket pp; + + // image can be NULL + GetMagickPixelPacket(image, mpp); + + memset(&pp, '\0', sizeof(pp)); + Color_to_PixelPacket(&pp, color); + mpp->red = pp.red; + mpp->green = pp.green; + mpp->blue = pp.blue; + mpp->opacity = pp.opacity; +} + + +/* Extern: PrimaryInfo_from_PrimaryInfo(pp) Purpose: Create a Magick::PrimaryInfo object from a PrimaryInfo structure. */ VALUE PrimaryInfo_from_PrimaryInfo(PrimaryInfo *p) @@ -2747,19 +2787,19 @@ enumerators = rb_cvar_get(class, rm_ID_enumerators); if (rb_block_given_p()) { - for (x = 0; x < RARRAY(enumerators)->len; x++) + for (x = 0; x < RARRAY_LEN(enumerators); x++) { (void) rb_yield(rb_ary_entry(enumerators, x)); } rv = class; } else { - copy = rb_ary_new2(RARRAY(enumerators)->len); - for (x = 0; x < RARRAY(enumerators)->len; x++) + copy = rb_ary_new2(RARRAY_LEN(enumerators)); + for (x = 0; x < RARRAY_LEN(enumerators); x++) { (void) rb_ary_push(copy, rb_ary_entry(enumerators, x)); } OBJ_FREEZE(copy); rv = copy;