/** * Construct a new imagelist object from a list of images. * * No Ruby usage (internal function) * * Notes: * - Sets \@scene to 0. * * @param images the images * @return a new imagelist * @see images_from_imagelist */ VALUE rm_imagelist_from_images(Image *images) { VALUE new_imagelist; Image *image; if (!images) { rb_bug("rm_imagelist_from_images called with NULL argument"); } new_imagelist = ImageList_new(); while (images) { image = RemoveFirstImageFromList(&images); imagelist_push(new_imagelist, rm_image_new(image)); } (void) rb_iv_set(new_imagelist, "@scene", INT2FIX(0)); RB_GC_GUARD(new_imagelist); return new_imagelist; }
/** * Call QuantizeImages. * * Ruby usage: * - @verbatim ImageList#quantize @endverbatim * - @verbatim ImageList#quantize(number_colors) @endverbatim * - @verbatim ImageList#quantize(number_colors, colorspace) @endverbatim * - @verbatim ImageList#quantize(number_colors, colorspace, dither) @endverbatim * - @verbatim ImageList#quantize(number_colors, colorspace, dither, tree_depth) @endverbatim * - @verbatim ImageList#quantize(number_colors, colorspace, dither, tree_depth, measure_error) @endverbatim * * Notes: * - Default number_colors is 256 * - Default coorspace is Magick::RGBColorsapce * - Default dither is true * - Default tree_depth is 0 * - Default measure_error is false * - Sets \@scene to the same value as self.scene * * @param argc number of input arguments * @param argv array of input arguments * @param self this object * @return a new ImageList with quantized images */ VALUE ImageList_quantize(int argc, VALUE *argv, VALUE self) { Image *images, *new_images; Image *new_image; QuantizeInfo quantize_info; ExceptionInfo *exception; VALUE new_imagelist, scene; GetQuantizeInfo(&quantize_info); switch (argc) { case 5: quantize_info.measure_error = (MagickBooleanType) RTEST(argv[4]); case 4: quantize_info.tree_depth = (unsigned long)NUM2INT(argv[3]); case 3: #if defined(HAVE_TYPE_DITHERMETHOD) && defined(HAVE_ENUM_NODITHERMETHOD) if (rb_obj_is_kind_of(argv[2], Class_DitherMethod)) { VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod); quantize_info.dither = quantize_info.dither_method != NoDitherMethod; } #else quantize_info.dither = (MagickBooleanType) RTEST(argv[2]); #endif case 2: VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType); case 1: quantize_info.number_colors = NUM2ULONG(argv[0]); case 0: break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc); break; } // Convert image array to image sequence, clone image sequence. exception = AcquireExceptionInfo(); images = images_from_imagelist(self); new_images = CloneImageList(images, exception); rm_split(images); rm_check_exception(exception, new_images, DestroyOnError); rm_ensure_result(new_images); (void) QuantizeImages(&quantize_info, new_images); rm_check_exception(exception, new_images, DestroyOnError); (void) DestroyExceptionInfo(exception); // Create new ImageList object, convert mapped image sequence to images, // append to images array. new_imagelist = ImageList_new(); while ((new_image = RemoveFirstImageFromList(&new_images))) { imagelist_push(new_imagelist, rm_image_new(new_image)); } // Set @scene in new ImageList object to same value as in self. scene = rb_iv_get(self, "@scene"); (void) rb_iv_set(new_imagelist, "@scene", scene); RB_GC_GUARD(new_imagelist); RB_GC_GUARD(scene); return new_imagelist; }
/* Method: ImageList#quantize(<number_colors<, colorspace<, dither<, tree_depth<, measure_error>>>>>) defaults: 256, Magick::RGBColorspace, true, 0, false Purpose: call QuantizeImages Returns: a new ImageList with quantized images. 'scene' is set to the same value as self.scene */ VALUE ImageList_quantize(int argc, VALUE *argv, VALUE self) { Image *images, *new_images; Image *new_image; QuantizeInfo quantize_info; ExceptionInfo exception; volatile VALUE new_imagelist, scene; GetQuantizeInfo(&quantize_info); switch (argc) { case 5: quantize_info.measure_error = (MagickBooleanType) RTEST(argv[4]); case 4: quantize_info.tree_depth = (unsigned long)NUM2INT(argv[3]); case 3: quantize_info.dither = (MagickBooleanType) RTEST(argv[2]); case 2: VALUE_TO_ENUM(argv[1], quantize_info.colorspace, ColorspaceType); case 1: quantize_info.number_colors = NUM2ULONG(argv[0]); case 0: break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 5)", argc); break; } if (imagelist_length(self) == 0L) { rb_raise(rb_eArgError, "no images in this image list"); } // Convert image array to image sequence, clone image sequence. GetExceptionInfo(&exception); images = images_from_imagelist(self); new_images = CloneImageList(images, &exception); rm_split(images); rm_check_exception(&exception, new_images, DestroyOnError); (void) DestroyExceptionInfo(&exception); rm_ensure_result(new_images); (void) QuantizeImages(&quantize_info, new_images); rm_check_exception(&exception, new_images, DestroyOnError); // Create new ImageList object, convert mapped image sequence to images, // append to images array. new_imagelist = ImageList_new(); while ((new_image = ShiftImageList(&new_images))) { imagelist_push(new_imagelist, rm_image_new(new_image)); } // Set @scene in new ImageList object to same value as in self. scene = rb_iv_get(self, "@scene"); (void) rb_iv_set(new_imagelist, "@scene", scene); return new_imagelist; }