Skip to content

Commit

Permalink
Support LiquidRescaleImage
Browse files Browse the repository at this point in the history
  • Loading branch information
rmagick committed Jan 28, 2008
1 parent 832978f commit a348148
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions ext/RMagick/extconf.rb
Expand Up @@ -162,6 +162,7 @@ def exit_failure(msg)
"GetNextImageProperty", # 6.3.1
"IsHistogramImage", # 6.3.5
"LinearStretchImage", # 6.3.1
"LiquidRescaleImage", # 6.3.8-2
"MagickCoreGenesis", # 6.3.4
"OpaquePaintImageChannel", # 6.3.7-10
"PolaroidImage", # 6.3.1-6
Expand Down
3 changes: 2 additions & 1 deletion ext/RMagick/rmagick.h
@@ -1,4 +1,4 @@
/* $Id: rmagick.h,v 1.222 2008/01/20 21:02:22 rmagick Exp $ */
/* $Id: rmagick.h,v 1.223 2008/01/28 22:31:50 rmagick Exp $ */
/*=============================================================================
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmagick.h
Expand Down Expand Up @@ -860,6 +860,7 @@ extern VALUE Image_inspect(VALUE);
extern VALUE Image_level2(int, VALUE *, VALUE);
extern VALUE Image_level_channel(int, VALUE *, VALUE);
extern VALUE Image_linear_stretch(int, VALUE *, VALUE);
extern VALUE Image_liquid_rescale(int, VALUE *, VALUE);
extern VALUE Image__load(VALUE, VALUE);
extern VALUE Image_magnify(VALUE);
extern VALUE Image_magnify_bang(VALUE);
Expand Down
50 changes: 49 additions & 1 deletion ext/RMagick/rmimage.c
@@ -1,4 +1,4 @@
/* $Id: rmimage.c,v 1.278 2008/01/17 23:48:19 rmagick Exp $ */
/* $Id: rmimage.c,v 1.279 2008/01/28 22:31:50 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmimage.c
Expand Down Expand Up @@ -5455,6 +5455,54 @@ Image_linear_stretch(int argc, VALUE *argv, VALUE self)
#endif
}


/*
Method: Image#liquid_rescale(columns, rows, delta_x=0.0, rigidity=0.0)
Purpose: Call the LiquidRescaleImage API
*/
VALUE
Image_liquid_rescale(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_LIQUIDRESCALEIMAGE)
Image *image, *new_image;
unsigned long cols, rows;
double delta_x = 0.0;
double rigidity = 0.0;
ExceptionInfo exception;

image = rm_check_destroyed(self);

switch (argc)
{
case 4:
rigidity = NUM2DBL(argv[3]);
case 3:
delta_x = NUM2DBL(argv[2]);
case 2:
rows = NUM2ULONG(argv[1]);
cols = NUM2ULONG(argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 4)", argc);
break;
}

GetExceptionInfo(&exception);
new_image = LiquidRescaleImage(image, cols, rows, delta_x, rigidity, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
DestroyExceptionInfo(&exception);
rm_ensure_result(new_image);

return rm_image_new(new_image);
#else
argc = argc; // defeat "unused parameter" messages
argv = argv;
self = self;
rm_not_implemented();
return(VALUE)0;
#endif
}

/*
Method: Image._load
Purpose: implement marshalling
Expand Down
5 changes: 3 additions & 2 deletions ext/RMagick/rmmain.c
@@ -1,4 +1,4 @@
/* $Id: rmmain.c,v 1.235 2008/01/19 16:22:25 rmagick Exp $ */
/* $Id: rmmain.c,v 1.236 2008/01/28 22:31:50 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmmain.c
Expand Down Expand Up @@ -565,6 +565,7 @@ Init_RMagick2(void)
rb_define_method(Class_Image, "level2", Image_level2, -1);
rb_define_method(Class_Image, "level_channel", Image_level_channel, -1);
rb_define_method(Class_Image, "linear_stretch", Image_linear_stretch, -1);
rb_define_method(Class_Image, "liquid_rescale", Image_liquid_rescale, -1);
rb_define_method(Class_Image, "magnify", Image_magnify, 0);
rb_define_method(Class_Image, "magnify!", Image_magnify_bang, 0);
rb_define_method(Class_Image, "map", Image_map, -1);
Expand Down Expand Up @@ -1686,7 +1687,7 @@ static void version_constants(void)
rb_define_const(Module_Magick, "Version", str);

sprintf(long_version,
"This is %s ($Date: 2008/01/19 16:22:25 $) Copyright (C) 2008 by Timothy P. Hunter\n"
"This is %s ($Date: 2008/01/28 22:31:50 $) Copyright (C) 2008 by Timothy P. Hunter\n"
"Built with %s\n"
"Built for %s\n"
"Web page: http://rmagick.rubyforge.org\n"
Expand Down

0 comments on commit a348148

Please sign in to comment.