ext/RMagick/rmutil.c in rmagick-1.9.3 vs ext/RMagick/rmutil.c in rmagick-1.10.0
- old
+ new
@@ -1,8 +1,8 @@
-/* $Id: rmutil.c,v 1.60 2005/10/13 23:01:29 rmagick Exp $ */
+/* $Id: rmutil.c,v 1.66 2006/01/20 23:59:46 rmagick Exp $ */
/*============================================================================\
-| Copyright (C) 2005 by Timothy P. Hunter
+| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmutil.c
| Author: Tim Hunter
| Purpose: Utility functions for RMagick
\============================================================================*/
@@ -129,10 +129,32 @@
return str;
}
/*
+ * Extern: rm_strcasecmp(s1, s2)
+ * Purpose: compare s1 and s2 ignoring case
+ * Returns: same as strcmp(3)
+*/
+int
+rm_strcasecmp(const char *s1, const char *s2)
+{
+ while (*s1 && *s2)
+ {
+ if (toupper(*s1) != toupper(*s2))
+ {
+ break;
+ }
+ s1 += 1;
+ s2 += 1;
+ }
+ return (int)(*s1 - *s2);
+}
+
+
+
+/*
* Extern: rm_check_ary_len(ary, len)
* Purpose: raise exception if array too short
*/
void
rm_check_ary_len(VALUE ary, int len)
@@ -521,12 +543,10 @@
}
/*
Method: Pixel#fcmp(other[, fuzz[, colorspace]])
Purpose: Compare pixel values for equality
- Notes: The colorspace value is ignored < 5.5.5
- and > 5.5.7.
*/
VALUE
Pixel_fcmp(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_FUZZYCOLORCOMPARE)
@@ -554,11 +574,11 @@
}
Data_Get_Struct(self, Pixel, this);
Data_Get_Struct(argv[0], Pixel, that);
-#if defined(HAVE_FUZZYCOLORCOMPARE)
+#if defined(HAVE_FUZZYCOLORCOMPARE) || defined(HAVE_ISCOLORSIMILAR)
// The FuzzyColorCompare function expects to get the
// colorspace and fuzz parameters from an Image structure.
info = CloneImageInfo(NULL);
if (!info)
@@ -574,11 +594,15 @@
DestroyImageInfo(info);
image->colorspace = colorspace;
image->fuzz = fuzz;
+#if defined(HAVE_ISCOLORSIMILAR)
+ equal = IsColorSimilar(image, this, that);
+#else
equal = FuzzyColorCompare(image, this, that);
+#endif
DestroyImage(image);
#else
equal = FuzzyColorMatch(this, that, fuzz);
#endif
@@ -622,10 +646,24 @@
DEF_PIXEL_CHANNEL_WRITER(blue)
DEF_PIXEL_CHANNEL_WRITER(opacity)
/*
+ Methods: Pixel CMYK attribute accessors
+ Purpose: Get/set Pixel attributes
+ Note: Pixel is Observable. Setters call changed, notify_observers
+ Note: Setters return their argument values for backward compatibility
+ to when Pixel was a Struct class.
+*/
+DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(cyan, red)
+DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(magenta, green)
+DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(yellow, blue)
+DEF_PIXEL_CMYK_CHANNEL_ACCESSOR(black, opacity)
+
+
+
+/*
Method: Pixel#<=>
Purpose: Support Comparable mixin
*/
VALUE Pixel_spaceship(VALUE self, VALUE other)
{
@@ -999,10 +1037,23 @@
VALUE
ColorspaceType_new(ColorspaceType cs)
{
const char *name;
+#if defined(HAVE_REC601YCBCRCOLORSPACE)
+ // GM 1.2 defines this symbol to be equal to YCbCrColorspace, so we
+ // can't use it as a case label. GM wants the string version of this
+ // enumerator to be Rec601YCbCrColorspace (see ColorspaceTypeToString
+ // in colorspace.c) so that's what we return for both versions of the
+ // enumerator.
+ if (cs == Rec601YCbCrColorspace)
+ {
+ return rm_enum_new(Class_ColorspaceType
+ , ID2SYM(rb_intern("Rec601YCbCrColorspace")), INT2FIX(cs));
+ }
+#endif
+
switch(cs)
{
default:
case UndefinedColorspace:
name = "UndefinedColorspace";
@@ -1041,20 +1092,51 @@
name = "CMYKColorspace";
break;
case sRGBColorspace:
name = "sRGBColorspace";
break;
-#if defined(HAVE_HSLCOLORSPACE)
case HSLColorspace:
name = "HSLColorspace";
break;
-#endif
-#if defined(HAVE_HWBCOLORSPACE)
case HWBColorspace:
name = "HWBColorspace";
break;
+#if defined(HAVE_HSBCOLORSPACE)
+ case HSBColorspace:
+ name = "HSBColorspace";
+ break;
#endif
+#if defined(HAVE_LABCOLORSPACE)
+ case LABColorspace:
+ name = "LABColorspace";
+ break;
+#endif
+#if defined(HAVE_CINEONLOGRGBCOLORSPACE)
+ case CineonLogRGBColorspace:
+ name = "CineonLogRGBColorspace";
+ break;
+#endif
+#if defined(HAVE_REC601LUMACOLORSPACE)
+ case Rec601LumaColorspace:
+ name = "Rec601LumaColorspace";
+ break;
+#endif
+#if defined(HAVE_REC709LUMACOLORSPACE)
+ case Rec709LumaColorspace:
+ name = "Rec709LumaColorspace";
+ break;
+#endif
+#if defined(HAVE_REC709YCBCRCOLORSPACE)
+ case Rec709YCbCrColorspace:
+ name = "Rec709YCbCrColorspace";
+ break;
+#endif
+#if defined(HAVE_LOGCOLORSPACE)
+ case LogColorspace:
+ name = "LogColorspace";
+ break;
+#endif
}
return rm_enum_new(Class_ColorspaceType, ID2SYM(rb_intern(name)), INT2FIX(cs));
}
@@ -2424,31 +2506,20 @@
else if (*c & XPMCompliance)
{
*c = XPMCompliance;
return "XPMCompliance";
}
-#if defined(HAVE_NOCOMPLIANCE)
- else if (*c != NoCompliance)
+ else if (*c == NoCompliance)
{
- return "unknown";
- }
- else
- {
*c = NoCompliance;
return "NoCompliance";
}
-#else
- else if (*c != UnknownCompliance)
- {
- return "unknown";
- }
else
{
- *c = UnknownCompliance;
- return "UnknownCompliance";
+ *c = UndefinedCompliance;
+ return "UndefinedCompliance";
}
-#endif
}
#if defined(HAVE_GETIMAGESTATISTICS)
/*
@@ -2761,13 +2832,13 @@
snprintf(msg, sizeof(msg)-1,
#else
sprintf(msg,
#endif
"%s%s%s",
- GET_MSG(severity, reason),
+ GetLocaleExceptionMessage(severity, reason),
description ? ": " : "",
- description ? GET_MSG(severity, description) : "");
+ description ? GetLocaleExceptionMessage(severity, description) : "");
#if defined(HAVE_EXCEPTIONINFO_MODULE)
{
char extra[100];
@@ -2788,13 +2859,13 @@
snprintf(msg, sizeof(msg)-1,
#else
sprintf(msg,
#endif
"RMagick: %s%s%s",
- GET_MSG(severity, reason),
+ GetLocaleExceptionMessage(severity, reason),
description ? ": " : "",
- description ? GET_MSG(severity, description) : "");
+ description ? GetLocaleExceptionMessage(severity, description) : "");
rb_warning(msg);
}
}
@@ -2895,11 +2966,11 @@
else if (!badboy)
{
badboy = image;
}
}
- image = GET_NEXT_IMAGE(image);
+ image = GetNextImageInList(image);
}
if (badboy)
{
if (badboy->exception.severity > WarningException)
@@ -2956,16 +3027,8 @@
{
rb_bug("RMagick FATAL: unseq called with NULL argument.");
}
while (image)
{
-#if HAVE_REMOVEFIRSTIMAGEFROMLIST
(void) RemoveFirstImageFromList(&image);
-#else
- Image *next;
-
- next = GET_NEXT_IMAGE(image);
- image->previous = image->next = NULL;
- image = next;
-#endif
}
}