ext/RMagick/rmimage.c in rmagick-2.7.0 vs ext/RMagick/rmimage.c in rmagick-2.7.1

- old
+ new

@@ -1,6 +1,6 @@ -/* $Id: rmimage.c,v 1.322 2008/09/28 00:23:10 rmagick Exp $ */ +/* $Id: rmimage.c,v 1.328 2008/10/30 22:23:39 rmagick Exp $ */ /*============================================================================\ | Copyright (C) 2008 by Timothy P. Hunter | Name: rmimage.c | Author: Tim Hunter | Purpose: Image class method definitions for RMagick @@ -1526,10 +1526,12 @@ // If an error occurs, IM will call our error handler and we raise an exception. image = XImportImage(image_info, &ximage_info); rm_check_image_exception(image, DestroyOnError); rm_ensure_result(image); + rm_set_user_artifact(image, image_info); + return rm_image_new(image); } /* @@ -2935,11 +2937,11 @@ } GetExceptionInfo(&exception); // This is based on ConstituteImage in IM 5.5.7 - image = AllocateImage(NULL); + image = AcquireImage(NULL); if (!image) { rb_raise(rb_eNoMemError, "not enough memory to continue."); } @@ -5035,10 +5037,11 @@ rm_check_exception(&exception, images, DestroyOnError); (void) DestroyExceptionInfo(&exception); rm_ensure_result(images); + rm_set_user_artifact(images, info); return array_from_images(images); } @@ -5322,11 +5325,11 @@ green, and blue intensities. */ VALUE Image_gray_q(VALUE self) { - return has_attribute(self, IsGrayImage); + return has_attribute(self, (MagickBooleanType (*)(const Image *, ExceptionInfo *))IsGrayImage); } /* Method: Image#histogram? @@ -5656,10 +5659,28 @@ { x += sprintf(buffer+x, " %lub", (unsigned long) GetBlobSize(image)); } } + +#if defined(HAVE_SETIMAGEARTIFACT) + if (len-1-x > 6) + { + size_t value_l; + const char *value = GetImageArtifact(image, "user"); + if (value) + { + strcpy(buffer+x, " user:"); + x += 6; + value_l = len - x - 1; + value_l = min(strlen(value), value_l); + memcpy(buffer+x, value, value_l); + x += value_l; + } + } +#endif + assert(x < (int)(len-1)); buffer[x] = '\0'; return; } @@ -6076,11 +6097,11 @@ char *blob; long length; class = class; // Suppress "never referenced" message from icc - info = CloneImageInfo(NULL); + info = CloneImageInfo(NULL); blob = rm_str2cstr(str, &length); // Must be as least as big as the 1st 4 fields in DumpedImage if (length <= (long)(sizeof(DumpedImage)-MaxTextExtent)) @@ -6682,11 +6703,11 @@ QuantumRange. */ VALUE Image_monochrome_q(VALUE self) { - return has_attribute(self, IsMonochromeImage); + return has_attribute(self, (MagickBooleanType (*)(const Image *, ExceptionInfo *))IsMonochromeImage); } /* Method: Image#montage @@ -6872,16 +6893,18 @@ // Create a new Info object to use when creating this image. info_obj = rm_info_new(); Data_Get_Struct(info_obj, Info, info); - image = AllocateImage(info); + image = AcquireImage(info); if (!image) { rb_raise(rb_eNoMemError, "not enough memory to continue"); } + rm_set_user_artifact(image, info); + // NOW store a real image in the image object. UPDATE_DATA_PTR(self, image); SetImageExtent(image, cols, rows); @@ -8002,12 +8025,12 @@ Image *images; ExceptionInfo exception; class = class; // defeat gcc message - // Create a new Info structure for this read/ping - info_obj = rm_info_new(); + // Create a new Info structure for this read/ping + info_obj = rm_info_new(); Data_Get_Struct(info_obj, Info, info); if (TYPE(file) == T_FILE) { OpenFile *fptr; @@ -8031,11 +8054,11 @@ GetExceptionInfo(&exception); images = (reader)(info, &exception); rm_check_exception(&exception, images, DestroyOnError); - + rm_set_user_artifact(images, info); (void) DestroyExceptionInfo(&exception); return array_from_images(images); } @@ -8142,10 +8165,11 @@ magick_free((void *)blob); rm_check_exception(&exception, images, DestroyOnError); (void) DestroyExceptionInfo(&exception); + rm_set_user_artifact(images, info); return array_from_images(images); } @@ -10048,10 +10072,28 @@ return Image_number_colors(self); } /* + Method: Image#total_ink_density + Purpose: Return value from GetImageTotalInkDensity + Notes: Raises an exception if the image is not CMYK +*/ +VALUE +Image_total_ink_density(VALUE self) +{ + Image *image; + double density; + + image = rm_check_destroyed(self); + density = GetImageTotalInkDensity(image); + rm_check_image_exception(image, RetainOnError); + return rb_float_new(density); +} + + +/* Method: Image#transparent(color-name<, opacity>) Image#transparent(pixel<, opacity>) Purpose: Call TransparentPaintImage Notes: Can use Magick::OpaqueOpacity or Magick::TransparentOpacity, or any value >= 0 && <= QuantumRange. The default is @@ -11279,28 +11321,12 @@ trace_args[0] = ID2SYM(rb_intern(which)); build_inspect_string(image, buffer, sizeof(buffer)); trace_args[1] = rb_str_new2(buffer); -#if SIZEOF_IMAGE_ > 4 -#if HAVE_TYPE_UNSIGNED_LONG_LONG - n = sprintf(buffer, "%016llx", (unsigned long long)image); -#elif HAVE_TYPE_UINT64_T - n = sprintf(buffer, "%016llx", (uint64_t)image); -#elif HAVE_TYPE_UINTMAX_T - n = sprintf(buffer, "%016llx", (uintmax_t)image); -#elif HAVE_TYPE___INT64 - n = sprintf(buffer, "%016llx", (__int64)image); -#elif SIZEOF_UNSIGNED_LONG == 8 - n = sprintf(buffer, "%016lx", (unsigned long)image); -#else -#error "No 64-bit type detected." -#endif -#else - n = sprintf(buffer, "%08lx", (unsigned long)image); -#endif + n = sprintf(buffer, "%p", (void *)image); buffer[n] = '\0'; - trace_args[2] = rb_str_new2(buffer); + trace_args[2] = rb_str_new2(buffer+2); // don't use leading 0x trace_args[3] = ID2SYM(THIS_FUNC()); (void) rb_funcall2(trace, rm_ID_call, 4, (VALUE *)trace_args); } }