ext/RMagick/rminfo.c in rmagick-1.13.0 vs ext/RMagick/rminfo.c in rmagick-1.14.0

- old
+ new

@@ -1,6 +1,6 @@ -/* $Id: rminfo.c,v 1.38 2006/05/27 21:05:59 rmagick Exp $ */ +/* $Id: rminfo.c,v 1.42 2006/09/16 19:15:03 rmagick Exp $ */ /*============================================================================\ | Copyright (C) 2006 by Timothy P. Hunter | Name: rminfo.c | Author: Tim Hunter | Purpose: Info class method definitions for RMagick. @@ -259,11 +259,44 @@ Data_Get_Struct(self, Info, info); Color_to_PixelPacket(&info->border_color, bc_arg); return self; } + + /* + Method: Info#channel(channel [, channel...]) + Purpose: Set the channels + Thanks: Douglas Sellers +*/ +VALUE +Info_channel(int argc, VALUE *argv, VALUE self) +{ +#if defined(HAVE_IMAGEINFO_CHANNEL) + Info *info; + ChannelType channels; + + channels = extract_channels(&argc, argv); + + // Ensure all arguments consumed. + if (argc > 0) + { + raise_ChannelType_error(argv[argc-1]); + } + + Data_Get_Struct(self, Info, info); + + info->channel = channels; + return self; +#else + rm_not_implemented(); + return (VALUE)0; +#endif +} + + +/* Method: Info#colorspace Purpose: Get the colorspace type */ VALUE Info_colorspace(VALUE self) @@ -1511,10 +1544,47 @@ return self; } /* + Method: Image::Info#texture=texture_image + Purpose: Set name of texture to tile onto the image background +*/ +VALUE +Info_texture_eq(VALUE self, VALUE texture) +{ + Info *info; + Image *image; + char name[MaxTextExtent]; + + Data_Get_Struct(self, Info, info); + + // Delete any existing texture file + if (info->texture) + { + rm_delete_temp_image(info->texture); + magick_free(info->texture); + info->texture = NULL; + } + + // If argument is nil we're done + if (texture == Qnil) + { + return self; + } + + // Create a temp copy of the texture and store its name in the texture field + Data_Get_Struct(texture, Image, image); + rm_write_temp_image(image, name); + + magick_clone_string(&info->texture, name); + + return self; +} + + +/* Method: Info#undefine Purpose: Undefine image option */ VALUE @@ -1626,11 +1696,32 @@ magick_clone_string(&info->view, view); } return self; } + /* + Static: destroy_Info + Purpose: if there is a texture image, delete it before destroying + the ImageInfo structure +*/ +static void +destroy_Info(void *infoptr) +{ + Info *info = (Info *)infoptr; + + if (info->texture) + { + rm_delete_temp_image(info->texture); + magick_free(info->texture); + info->texture = NULL; + } + + DestroyImageInfo(info); +} + +/* Method: Info.new Purpose: Create an Info object by calling CloneInfo */ #if !defined(HAVE_RB_DEFINE_ALLOC_FUNC) VALUE @@ -1642,11 +1733,11 @@ info = CloneImageInfo(NULL); if (!info) { rb_raise(rb_eNoMemError, "not enough memory to initialize Info object"); } - new_obj = Data_Wrap_Struct(class, NULL, DestroyImageInfo, info); + new_obj = Data_Wrap_Struct(class, NULL, destroy_Info, info); rb_obj_call_init(new_obj, 0, NULL); return new_obj; } /* @@ -1674,10 +1765,10 @@ info = CloneImageInfo(NULL); if (!info) { rb_raise(rb_eNoMemError, "not enough memory to initialize Info object"); } - info_obj = Data_Wrap_Struct(class, NULL, DestroyImageInfo, info); + info_obj = Data_Wrap_Struct(class, NULL, destroy_Info, info); return info_obj; } /* Extern: rm_info_new Purpose: provide a Info.new method for internal use