Skip to content

Commit

Permalink
Support Image#pixel_interpolation_method attribute and InterpolatePix…
Browse files Browse the repository at this point in the history
…elMethod enum
  • Loading branch information
rmagick committed Sep 27, 2006
1 parent e0a95d5 commit fffb37d
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 9 deletions.
20 changes: 15 additions & 5 deletions ext/RMagick/rmagick.h
@@ -1,4 +1,4 @@
/* $Id: rmagick.h,v 1.137 2006/09/16 19:15:02 rmagick Exp $ */
/* $Id: rmagick.h,v 1.138 2006/09/27 21:26:35 rmagick Exp $ */
/*=============================================================================
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmagick.h
Expand Down Expand Up @@ -294,6 +294,9 @@ EXTERN VALUE Class_FilterTypes;
EXTERN VALUE Class_GravityType;
EXTERN VALUE Class_ImageType;
EXTERN VALUE Class_InterlaceType;
#if defined(HAVE_INTERPOLATEPIXELCOLOR)
EXTERN VALUE Class_InterpolatePixelMethod;
#endif
#if defined(HAVE_COMPAREIMAGELAYERS)
EXTERN VALUE Class_MagickLayerMethod;
#endif
Expand Down Expand Up @@ -735,6 +738,7 @@ ATTR_ACCESSOR(Image, offset)
ATTR_WRITER(Image, opacity)
ATTR_ACCESSOR(Image, orientation)
ATTR_ACCESSOR(Image, page)
ATTR_ACCESSOR(Image, pixel_interpolation_method)
ATTR_READER(Image, quality)
ATTR_READER(Image, quantum_depth)
ATTR_ACCESSOR(Image, rendering_intent)
Expand Down Expand Up @@ -1017,6 +1021,9 @@ extern VALUE Pixel_to_s(VALUE);
extern VALUE PixelPacket_to_Color_Name(Image *, PixelPacket *);
extern VALUE PixelPacket_to_Color_Name_Info(Info *, PixelPacket *);
extern VALUE Pixel_from_PixelPacket(PixelPacket *);
#if defined(HAVE_MAGICKPIXELPACKET)
extern VALUE Pixel_from_MagickPixelPacket(MagickPixelPacket *);
#endif

extern void Point_to_PointInfo(PointInfo *, VALUE);
extern VALUE PointInfo_to_Point(PointInfo *);
Expand All @@ -1031,6 +1038,12 @@ extern VALUE Segment_from_SegmentInfo(SegmentInfo *);
extern void AffineMatrix_to_AffineMatrix(AffineMatrix *, VALUE);
extern void ChromaticityInfo_to_ChromaticityInfo(ChromaticityInfo *, VALUE);
extern void Color_to_ColorInfo(ColorInfo *, VALUE);
#if defined(HAVE_INTERPOLATEPIXELCOLOR)
extern VALUE InterpolatePixelMethod_new(InterpolatePixelMethod);
#endif
#if defined(HAVE_IMAGE_ORIENTATION)
extern VALUE OrientationType_new(OrientationType);
#endif
extern void PrimaryInfo_to_PrimaryInfo(PrimaryInfo *, VALUE);
extern void Rectangle_to_RectangleInfo(RectangleInfo *, VALUE);
extern void Segment_to_SegmentInfo(SegmentInfo *, VALUE);
Expand All @@ -1042,11 +1055,8 @@ extern VALUE TypeMetric_from_TypeMetric(TypeMetric *);
#if defined(HAVE_GETIMAGESTATISTICS)
extern VALUE Statistics_new(ImageStatistics *);
#endif
#if defined(HAVE_IMAGE_ORIENTATION)
extern VALUE OrientationType_new(OrientationType);
#endif
extern const char *StorageType_name(StorageType);
extern VALUE VirtualPixelMethod_new(VirtualPixelMethod);
extern VALUE VirtualPixelMethod_new(VirtualPixelMethod);

#if defined(HAVE_RB_DEFINE_ALLOC_FUNC)
extern VALUE Enum_alloc(VALUE);
Expand Down
4 changes: 4 additions & 0 deletions ext/RMagick/rmagick_config.h.in
Expand Up @@ -132,6 +132,8 @@
#undef HAVE_IMAGEINFO_CHANNEL
/* Introduced in IM 5.5.7, GM 1.1 */
#undef HAVE_IMPORTIMAGEPIXELS
/* Introduced in IM 6.2.9 */
#undef HAVE_INTERPOLATEPIXELCOLOR
/* Introduced in IM 6.2.6-1 */
#undef HAVE_INTERPRETIMAGEATTRIBUTES
#undef HAVE_INTTYPES_H
Expand All @@ -152,6 +154,8 @@
#undef HAVE_MAGICK_UINT64_T
/* Introduced in IM 6.0.0 */
#undef HAVE_MAGICKOFFSETTYPE
/* Only in ImageMagick */
#undef HAVE_MAGICKPIXELPACKET
/* Introduced in IM 6.0.0, GM 1.1 */
#undef HAVE_MAGICKSIZETYPE
/* Introduced in IM 6.2.0 */
Expand Down
46 changes: 45 additions & 1 deletion ext/RMagick/rmimage.c
@@ -1,4 +1,4 @@
/* $Id: rmimage.c,v 1.182 2006/09/16 19:15:03 rmagick Exp $ */
/* $Id: rmimage.c,v 1.183 2006/09/27 21:26:35 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmimage.c
Expand Down Expand Up @@ -5523,6 +5523,7 @@ Image_inspect(VALUE self)
return rb_str_new2(buffer);
}


/*
Method: Image#interlace
Purpose: get the interlace attribute
Expand All @@ -5537,6 +5538,7 @@ Image_interlace(VALUE self)
return InterlaceType_new(image->interlace);
}


/*
Method: Image#interlace=
Purpose: set the interlace attribute
Expand All @@ -5552,6 +5554,7 @@ Image_interlace_eq(VALUE self, VALUE interlace)
return self;
}


/*
Method: Image#iptc_profile
Purpose: Return the IPTC profile as a String.
Expand Down Expand Up @@ -7039,6 +7042,47 @@ Image_pixel_color(
return Pixel_from_PixelPacket(&old_color);
}


/*
Method: Image.pixel_interpolation_method
Image.pixel_interpolation_method=method
Purpose: Get/set the "interpolate" field in the Image structure.
Ref: Image.interpolate_pixel_color
*/
VALUE
Image_pixel_interpolation_method(VALUE self)
{
#if defined(HAVE_INTERPOLATEPIXELCOLOR)
Image *image;

Data_Get_Struct(self, Image, image);
return InterpolatePixelMethod_new(image->interpolate);

#else
rm_not_implemented();
return (VALUE)0;
#endif
}


VALUE
Image_pixel_interpolation_method_eq(VALUE self, VALUE method)
{
#if defined(HAVE_INTERPOLATEPIXELCOLOR)
Image *image;

rm_check_frozen(self);
Data_Get_Struct(self, Image, image);
VALUE_TO_ENUM(method, image->interpolate, InterpolatePixelMethod);
return self;

#else
rm_not_implemented();
return (VALUE)0;
#endif
}


#if 0
/*
Method: Image.plasma(x1, y1, x2, y2, attenuate, depth)
Expand Down
18 changes: 16 additions & 2 deletions ext/RMagick/rmmain.c
@@ -1,4 +1,4 @@
/* $Id: rmmain.c,v 1.145 2006/09/16 19:15:03 rmagick Exp $ */
/* $Id: rmmain.c,v 1.146 2006/09/27 21:26:35 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmmain.c
Expand Down Expand Up @@ -714,6 +714,7 @@ Init_RMagick(void)
DCL_ATTR_WRITER(Image, opacity)
DCL_ATTR_ACCESSOR(Image, orientation)
DCL_ATTR_ACCESSOR(Image, page)
DCL_ATTR_ACCESSOR(Image, pixel_interpolation_method)
#if defined(HAVE_IMAGE_QUALITY)
DCL_ATTR_READER(Image, quality)
#endif
Expand Down Expand Up @@ -1504,6 +1505,19 @@ Init_RMagick(void)
ENUMERATOR(PartitionInterlace)
END_ENUM

#if defined(HAVE_INTERPOLATEPIXELCOLOR)
DEF_ENUM(InterpolatePixelMethod)
ENUMERATOR(UndefinedInterpolatePixel)
ENUMERATOR(AverageInterpolatePixel)
ENUMERATOR(BicubicInterpolatePixel)
ENUMERATOR(BilinearInterpolatePixel)
ENUMERATOR(FilterInterpolatePixel)
ENUMERATOR(IntegerInterpolatePixel)
ENUMERATOR(MeshInterpolatePixel)
ENUMERATOR(NearestNeighborInterpolatePixel)
END_ENUM
#endif

#if defined(HAVE_COMPAREIMAGELAYERS)
DEF_ENUM(MagickLayerMethod)
ENUMERATOR(UndefinedLayer)
Expand Down Expand Up @@ -1846,7 +1860,7 @@ static void version_constants(void)
rb_define_const(Module_Magick, "Version", str);

sprintf(long_version,
"This is %s ($Date: 2006/09/16 19:15:03 $) Copyright (C) 2006 by Timothy P. Hunter\n"
"This is %s ($Date: 2006/09/27 21:26:35 $) Copyright (C) 2006 by Timothy P. Hunter\n"
"Built with %s\n"
"Built for %s\n"
"Web page: http://rmagick.rubyforge.org\n"
Expand Down
61 changes: 60 additions & 1 deletion ext/RMagick/rmutil.c
@@ -1,4 +1,4 @@
/* $Id: rmutil.c,v 1.82 2006/08/28 22:21:29 rmagick Exp $ */
/* $Id: rmutil.c,v 1.83 2006/09/27 21:26:36 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmutil.c
Expand Down Expand Up @@ -1075,6 +1075,27 @@ Color_Name_to_PixelPacket(PixelPacket *color, VALUE name_arg)
}
}


/*
Extern: Pixel_from_MagickPixelPacket
Purpose: Create a Magick::Pixel from a MagickPixelPacket structure
*/
#if defined(HAVE_MAGICKPIXELPACKET)
VALUE
Pixel_from_MagickPixelPacket(MagickPixelPacket *mpp)
{
PixelPacket pixel;

pixel.red = RoundToQuantum(mpp->red);
pixel.green = RoundToQuantum(mpp->green);
pixel.blue = RoundToQuantum(mpp->blue);
pixel.opacity = RoundToQuantum(mpp->opacity);

return Pixel_from_PixelPacket(&pixel);
}
#endif


/*
Extern: AffineMatrix_to_AffineMatrix
Purpose: Convert a Magick::AffineMatrix object to a AffineMatrix structure.
Expand Down Expand Up @@ -1568,6 +1589,44 @@ InterlaceType_new(InterlaceType interlace)
}


/*
Static: InterpolatePixelMethod_name
Purpose: Return the name of a InterpolatePixelMethod enum as a string
*/
#if defined(HAVE_INTERPOLATEPIXELCOLOR)
static const char *
InterpolatePixelMethod_name(InterpolatePixelMethod interpolate)
{
switch(interpolate)
{
default:
ENUM_TO_NAME(UndefinedInterpolatePixel)
ENUM_TO_NAME(AverageInterpolatePixel)
ENUM_TO_NAME(BicubicInterpolatePixel)
ENUM_TO_NAME(BilinearInterpolatePixel)
ENUM_TO_NAME(FilterInterpolatePixel)
ENUM_TO_NAME(IntegerInterpolatePixel)
ENUM_TO_NAME(MeshInterpolatePixel)
ENUM_TO_NAME(NearestNeighborInterpolatePixel)
}
}


/*
External: InterpolatePixelMethod_new
Purpose: Construct an InterpolatePixelMethod enum object for the specified value.
*/
VALUE
InterpolatePixelMethod_new(InterpolatePixelMethod interpolate)
{
const char *name;

name = InterpolatePixelMethod_name(interpolate);
return rm_enum_new(Class_InterpolatePixelMethod, ID2SYM(rb_intern(name)), INT2FIX(interpolate));
}
#endif


/*
External: MagickLayerMethod_new
Purpose: Construct an MagickLayerMethod enum object for the specified value.
Expand Down

0 comments on commit fffb37d

Please sign in to comment.