ext/RMagick/rmutil.c in rmagick-1.12.0 vs ext/RMagick/rmutil.c in rmagick-1.13.0
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmutil.c,v 1.76 2006/05/27 21:05:59 rmagick Exp $ */
+/* $Id: rmutil.c,v 1.78 2006/06/28 23:07:55 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmutil.c
| Author: Tim Hunter
| Purpose: Utility functions for RMagick
@@ -475,11 +475,11 @@
VALUE
Pixel_from_color(VALUE class, VALUE name)
{
PixelPacket pp;
ExceptionInfo exception;
- boolean okay;
+ MagickBooleanType okay;
class = class; // defeat "never referenced" message from icc
GetExceptionInfo(&exception);
okay = QueryColorDatabase(STRING_PTR(name), &pp, &exception);
@@ -610,10 +610,20 @@
&rgb.red, &rgb.green, &rgb.blue);
return Pixel_from_PixelPacket(&rgb);
}
/*
+ Method: Pixel#eql?
+ Purpose: For use with Hash
+*/
+VALUE
+Pixel_eql_q(VALUE self, VALUE other)
+{
+ return NUM2INT(Pixel_spaceship(self, other)) == 0 ? Qtrue : Qfalse;
+}
+
+/*
Method: Pixel#fcmp(other[, fuzz[, colorspace]])
Purpose: Compare pixel values for equality
*/
VALUE
Pixel_fcmp(int argc, VALUE *argv, VALUE self)
@@ -677,11 +687,35 @@
#endif
return equal ? Qtrue : Qfalse;
}
+
/*
+ Method: Pixel#hash
+ Notes: INT2FIX left-shifts 1 bit. Sacrifice 1 bit
+ from the opacity attribute to the FIXNUM_FLAG.
+*/
+VALUE
+Pixel_hash(VALUE self)
+{
+ Pixel *pixel;
+ unsigned int hash;
+
+ Data_Get_Struct(self, Pixel, pixel);
+
+ hash = ScaleQuantumToChar(pixel->red) << 24;
+ hash += ScaleQuantumToChar(pixel->green) << 16;
+ hash += ScaleQuantumToChar(pixel->blue) << 8;
+ hash += ScaleQuantumToChar(pixel->opacity);
+ hash >>= 1;
+
+ return INT2FIX(hash);
+
+}
+
+/*
Method: Pixel#intensity
Purpose: Return the "intensity" of a pixel
*/
VALUE
Pixel_intensity(VALUE self)
@@ -1026,10 +1060,10 @@
Raises: ArgumentError
*/
static void
Color_Name_to_PixelPacket(PixelPacket *color, VALUE name_arg)
{
- boolean okay;
+ MagickBooleanType okay;
char *name;
ExceptionInfo exception;
GetExceptionInfo(&exception);
name = STRING_PTR(name_arg);