ext/RMagick/rminfo.c in rmagick-2.7.1 vs ext/RMagick/rminfo.c in rmagick-2.7.2

- old
+ new

@@ -1,6 +1,6 @@ -/* $Id: rminfo.c,v 1.72 2008/08/26 22:36:15 rmagick Exp $ */ +/* $Id: rminfo.c,v 1.73 2008/11/13 00:06:57 rmagick Exp $ */ /*============================================================================\ | Copyright (C) 2008 by Timothy P. Hunter | Name: rminfo.c | Author: Tim Hunter | Purpose: Info class method definitions for RMagick. @@ -160,10 +160,25 @@ return self; } +/* + Static: pixel_packet_to_hexname(pp, name) + Purpose: convert a PixelPacket to a hex-format color name +*/ +static char *pixel_packet_to_hexname(PixelPacket *pp, char *name) +{ + MagickPixelPacket mpp; + + GetMagickPixelPacket(NULL, &mpp); + rm_set_magick_pixel_packet(pp, NULL, &mpp); + (void) GetColorTuple(&mpp, MagickTrue, name); + return name; +} + + DEF_ATTR_ACCESSOR(Info, antialias, bool) /* Method: value = Info[format, key] value = Info[key] @@ -366,22 +381,25 @@ Data_Get_Struct(self, Info, info); return PixelPacket_to_Color_Name_Info(info, &info->background_color); } + /* Method: Info#background_color=<aString> Purpose: set the background color Raises: ArgumentError */ VALUE Info_background_color_eq(VALUE self, VALUE bc_arg) { Info *info; + char colorname[MaxTextExtent]; Data_Get_Struct(self, Info, info); Color_to_PixelPacket(&info->background_color, bc_arg); + SetImageOption(info, "background", pixel_packet_to_hexname(&info->background_color, colorname)); return self; } /* Method: Info#border_color @@ -404,13 +422,15 @@ */ VALUE Info_border_color_eq(VALUE self, VALUE bc_arg) { Info *info; + char colorname[MaxTextExtent]; Data_Get_Struct(self, Info, info); Color_to_PixelPacket(&info->border_color, bc_arg); + SetImageOption(info, "bordercolor", pixel_packet_to_hexname(&info->border_color, colorname)); return self; } @@ -734,10 +754,29 @@ { "2", "BackgroundDispose", BackgroundDispose}, { "3", "PreviousDispose", PreviousDispose}, }; #define N_DISPOSE_OPTIONS (int)(sizeof(Dispose_Option)/sizeof(Dispose_Option[0])) + +DisposeType rm_dispose_to_enum(const char *name) +{ + DisposeType dispose = UndefinedDispose; + int x; + + for (x = 0; x < N_DISPOSE_OPTIONS; x++) + { + if (strcmp(Dispose_Option[x].string, name) == 0) + { + dispose = Dispose_Option[x].enumerator; + break; + } + } + + return dispose; +} + + VALUE Info_dispose(VALUE self) { Info *info; int x; @@ -1025,10 +1064,29 @@ { "West", "WestGravity", WestGravity}, { "Static", "StaticGravity", StaticGravity} }; #define N_GRAVITY_OPTIONS (int)(sizeof(Gravity_Option)/sizeof(Gravity_Option[0])) + +GravityType rm_gravity_to_enum(const char *name) +{ + GravityType gravity = UndefinedGravity; + int x; + + for (x = 0; x < N_GRAVITY_OPTIONS; x++) + { + if (strcmp(name, Gravity_Option[x].string) == 0) + { + gravity = Gravity_Option[x].enumerator; + break; + } + } + + return gravity; +} + + VALUE Info_gravity(VALUE self) { Info *info; const char *gravity; int x; @@ -1176,12 +1234,14 @@ */ VALUE Info_matte_color_eq(VALUE self, VALUE matte_arg) { Info *info; + char colorname[MaxTextExtent]; Data_Get_Struct(self, Info, info); Color_to_PixelPacket(&info->matte_color, matte_arg); + SetImageOption(info, "mattecolor", pixel_packet_to_hexname(&info->matte_color, colorname)); return self; } /* Method: Info#monitor=