rmagick 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
- /* $Id: rmmain.c,v 1.90 2005/06/19 20:26:34 rmagick Exp $ */
1
+ /* $Id: rmmain.c,v 1.95 2005/09/07 21:51:45 rmagick Exp $ */
2
2
  /*============================================================================\
3
3
  | Copyright (C) 2005 by Timothy P. Hunter
4
4
  | Name: rmmain.c
@@ -691,7 +691,7 @@ Init_RMagick(void)
691
691
  rb_define_method(Class_Image, "grey?", Image_gray_q, 0);
692
692
  rb_define_method(Class_Image, "grayscale_pseudo_class", Image_grayscale_pseudo_class, -1);
693
693
  rb_define_method(Class_Image, "implode", Image_implode, -1);
694
- rb_define_method(Class_Image, "import_pixels", Image_import_pixels, 6);
694
+ rb_define_method(Class_Image, "import_pixels", Image_import_pixels, -1);
695
695
  rb_define_method(Class_Image, "initialize_copy", Image_init_copy, 1);
696
696
  rb_define_method(Class_Image, "inspect", Image_inspect, 0);
697
697
  rb_define_method(Class_Image, "level", Image_level, -1);
@@ -784,7 +784,7 @@ Init_RMagick(void)
784
784
  rb_define_alias(Class_ImageList, "__display__", "display");
785
785
 
786
786
  // Define an alias for Array's "map" method.
787
- rb_define_alias(Class_ImageList, "__map__", "map");
787
+ rb_define_alias(Class_ImageList, "__ary_map__", "map");
788
788
 
789
789
  rb_define_method(Class_ImageList, "animate", ImageList_animate, -1);
790
790
  rb_define_method(Class_ImageList, "append", ImageList_append, 1);
@@ -1077,6 +1077,9 @@ Init_RMagick(void)
1077
1077
  #if defined(HAVE_INDEXCHANNEL)
1078
1078
  ENUMERATOR(IndexChannel) // 5.5.8
1079
1079
  #endif
1080
+ #if defined(HAVE_GRAYCHANNEL)
1081
+ ENUMERATOR(GrayChannel)
1082
+ #endif
1080
1083
  #if defined(HAVE_ALLCHANNELS)
1081
1084
  ENUMERATOR(AllChannels)
1082
1085
  #endif
@@ -1195,6 +1198,8 @@ Init_RMagick(void)
1195
1198
  ENUMERATOR(XorCompositeOp)
1196
1199
 
1197
1200
  #if defined(HAVE_COLORDODGECOMPOSITEOP)
1201
+ ENUMERATOR(BlendCompositeOp)
1202
+ ENUMERATOR(ColorBurnCompositeOp)
1198
1203
  ENUMERATOR(ColorDodgeCompositeOp)
1199
1204
  ENUMERATOR(ExclusionCompositeOp)
1200
1205
  ENUMERATOR(HardLightCompositeOp)
@@ -1215,7 +1220,8 @@ Init_RMagick(void)
1215
1220
  #endif
1216
1221
  ENUMERATOR(LosslessJPEGCompression)
1217
1222
  ENUMERATOR(LZWCompression)
1218
- ENUMERATOR(RunlengthEncodedCompression)
1223
+ ENUMERATOR(RLECompression) // preferred
1224
+ ENUMERATOR(RunlengthEncodedCompression) // deprecated
1219
1225
  ENUMERATOR(ZipCompression)
1220
1226
  END_ENUM
1221
1227
 
@@ -1419,6 +1425,20 @@ Init_RMagick(void)
1419
1425
  ENUMERATOR(PixelsPerCentimeterResolution)
1420
1426
  END_ENUM
1421
1427
 
1428
+ // StorageType
1429
+ DEF_ENUM(StorageType)
1430
+ ENUMERATOR(UndefinedPixel)
1431
+ ENUMERATOR(CharPixel)
1432
+ ENUMERATOR(DoublePixel)
1433
+ ENUMERATOR(FloatPixel)
1434
+ ENUMERATOR(IntegerPixel)
1435
+ ENUMERATOR(LongPixel)
1436
+ #if defined(HAVE_QUANTUMPIXEL)
1437
+ ENUMERATOR(QuantumPixel)
1438
+ #endif
1439
+ ENUMERATOR(ShortPixel)
1440
+ END_ENUM
1441
+
1422
1442
  // StretchType constants
1423
1443
  DEF_ENUM(StretchType)
1424
1444
  ENUMERATOR(NormalStretch)
@@ -1538,7 +1558,7 @@ static void version_constants(void)
1538
1558
 
1539
1559
  rb_define_const(Module_Magick, "Version", rb_str_new2(PACKAGE_STRING));
1540
1560
  sprintf(long_version,
1541
- "This is %s ($Date: 2005/06/19 20:26:34 $) Copyright (C) 2005 by Timothy P. Hunter\n"
1561
+ "This is %s ($Date: 2005/09/07 21:51:45 $) Copyright (C) 2005 by Timothy P. Hunter\n"
1542
1562
  "Built with %s\n"
1543
1563
  "Built for %s\n"
1544
1564
  "Web page: http://rmagick.rubyforge.org\n"
@@ -1,4 +1,4 @@
1
- /* $Id: rmutil.c,v 1.53 2005/06/21 22:55:01 rmagick Exp $ */
1
+ /* $Id: rmutil.c,v 1.57 2005/09/07 21:51:45 rmagick Exp $ */
2
2
  /*============================================================================\
3
3
  | Copyright (C) 2005 by Timothy P. Hunter
4
4
  | Name: rmutil.c
@@ -11,7 +11,7 @@
11
11
 
12
12
  static const char *Compliance_Const_Name(ComplianceType *);
13
13
  static const char *StyleType_Const_Name(StyleType);
14
- static const char *StretchType_Const_Name(StretchType);
14
+ static const char *StretchType_name(StretchType);
15
15
  static void Color_Name_to_PixelPacket(PixelPacket *, VALUE);
16
16
  static VALUE Enum_type_values(VALUE);
17
17
  static VALUE Enum_type_inspect(VALUE);
@@ -191,7 +191,7 @@ arg_is_number(VALUE arg)
191
191
  static VALUE
192
192
  rescue_not_str(VALUE arg)
193
193
  {
194
- rb_raise(rb_eArgError, "argument must be a number or a string in the form 'NN%' (%s given)",
194
+ rb_raise(rb_eTypeError, "argument must be a number or a string in the form 'NN%' (%s given)",
195
195
  rb_class2name(CLASS_OF(arg)));
196
196
  }
197
197
 
@@ -1074,6 +1074,193 @@ ComplianceType_new(ComplianceType compliance)
1074
1074
  return rm_enum_new(Class_ComplianceType, ID2SYM(rb_intern(name)), INT2FIX(compliance));
1075
1075
  }
1076
1076
 
1077
+
1078
+ /*
1079
+ External: CompositeOperator_new
1080
+ Purpose: Construct a CompositeOperator enum object for the specified value
1081
+ */
1082
+ VALUE
1083
+ CompositeOperator_new(CompositeOperator op)
1084
+ {
1085
+ const char *name;
1086
+
1087
+ switch (op)
1088
+ {
1089
+ default:
1090
+ case UndefinedCompositeOp:
1091
+ name = "UndefinedCompositeOp";
1092
+ break;
1093
+ case NoCompositeOp:
1094
+ name = "NoCompositeOp";
1095
+ break;
1096
+ case AddCompositeOp:
1097
+ name = "AddCompositeOp";
1098
+ break;
1099
+ case AtopCompositeOp:
1100
+ name = "AtopCompositeOp";
1101
+ break;
1102
+ case BumpmapCompositeOp:
1103
+ name = "BumpmapCompositeOp";
1104
+ break;
1105
+ case ClearCompositeOp:
1106
+ name = "ClearCompositeOp";
1107
+ break;
1108
+ #if defined(HAVE_COLORDODGECOMPOSITEOP)
1109
+ case ColorBurnCompositeOp:
1110
+ name = "ColorBurnCompositeOp";
1111
+ break;
1112
+ case BlendCompositeOp:
1113
+ name = "BlendCompositeOp";
1114
+ break;
1115
+ case ColorDodgeCompositeOp:
1116
+ name = "ColorDodgeCompositeOp";
1117
+ break;
1118
+ case ExclusionCompositeOp:
1119
+ name = "ExclusionCompositeOp";
1120
+ break;
1121
+ case HardLightCompositeOp:
1122
+ name = "HardLightCompositeOp";
1123
+ break;
1124
+ case SoftLightCompositeOp:
1125
+ name = "SoftLightCompositeOp";
1126
+ break;
1127
+ #endif
1128
+ case ColorizeCompositeOp:
1129
+ name = "ColorizeCompositeOp";
1130
+ break;
1131
+ case CopyBlueCompositeOp:
1132
+ name = "CopyBlueCompositeOp";
1133
+ break;
1134
+ case CopyCompositeOp:
1135
+ name = "CopyCompositeOp";
1136
+ break;
1137
+ #if defined(HAVE_COPYCYANCOMPOSITEOP) // CYMK added 5.5.7
1138
+ case CopyCyanCompositeOp:
1139
+ name = "CopyCyanCompositeOp";
1140
+ break;
1141
+ case CopyMagentaCompositeOp:
1142
+ name = "CopyMagentaCompositeOp";
1143
+ break;
1144
+ case CopyYellowCompositeOp:
1145
+ name = "CopyYellowCompositeOp";
1146
+ break;
1147
+ case CopyBlackCompositeOp:
1148
+ name = "CopyBlackCompositeOp";
1149
+ break;
1150
+ #endif
1151
+ case CopyGreenCompositeOp:
1152
+ name = "CopyGreenCompositeOp";
1153
+ break;
1154
+ case CopyOpacityCompositeOp:
1155
+ name = "CopyOpacityCompositeOp";
1156
+ break;
1157
+ case CopyRedCompositeOp:
1158
+ name = "CopyRedCompositeOp";
1159
+ break;
1160
+ case DarkenCompositeOp:
1161
+ name = "DarkenCompositeOp";
1162
+ break;
1163
+ #if defined(HAVE_DSTCOMPOSITEOP)
1164
+ case DstAtopCompositeOp:
1165
+ name = "DstAtopCompositeOp";
1166
+ break;
1167
+ case DstCompositeOp:
1168
+ name = "DstCompositeOp";
1169
+ break;
1170
+ case DstInCompositeOp:
1171
+ name = "DstInCompositeOp";
1172
+ break;
1173
+ case DstOutCompositeOp:
1174
+ name = "DstOutCompositeOp";
1175
+ break;
1176
+ case DstOverCompositeOp:
1177
+ name = "DstOverCompositeOp";
1178
+ break;
1179
+ #endif
1180
+ case DifferenceCompositeOp:
1181
+ name = "DifferenceCompositeOp";
1182
+ break;
1183
+ case DisplaceCompositeOp:
1184
+ name = "DisplaceCompositeOp";
1185
+ break;
1186
+ case DissolveCompositeOp:
1187
+ name = "DissolveCompositeOp";
1188
+ break;
1189
+ case HueCompositeOp:
1190
+ name = "HueCompositeOp";
1191
+ break;
1192
+ case InCompositeOp:
1193
+ name = "InCompositeOp";
1194
+ break;
1195
+ case LightenCompositeOp:
1196
+ name = "LightenCompositeOp";
1197
+ break;
1198
+ case LuminizeCompositeOp:
1199
+ name = "LuminizeCompositeOp";
1200
+ break;
1201
+ case MinusCompositeOp:
1202
+ name = "MinusCompositeOp";
1203
+ break;
1204
+ case ModulateCompositeOp:
1205
+ name = "ModulateCompositeOp";
1206
+ break;
1207
+ case MultiplyCompositeOp:
1208
+ name = "MultiplyCompositeOp";
1209
+ break;
1210
+ case OutCompositeOp:
1211
+ name = "OutCompositeOp";
1212
+ break;
1213
+ case OverCompositeOp:
1214
+ name = "OverCompositeOp";
1215
+ break;
1216
+ case OverlayCompositeOp:
1217
+ name = "OverlayCompositeOp";
1218
+ break;
1219
+ case PlusCompositeOp:
1220
+ name = "PlusCompositeOp";
1221
+ break;
1222
+ #if defined(HAVE_REPLACECOMPOSITEOP) // Added 5.5.8
1223
+ case ReplaceCompositeOp:
1224
+ name = "ReplaceCompositeOp";
1225
+ break;
1226
+ #endif
1227
+ case SaturateCompositeOp:
1228
+ name = "SaturateCompositeOp";
1229
+ break;
1230
+ case ScreenCompositeOp:
1231
+ name = "ScreenCompositeOp";
1232
+ break;
1233
+ #if defined(HAVE_DSTCOMPOSITEOP)
1234
+ case SrcAtopCompositeOp:
1235
+ name = "SrcAtopCompositeOp";
1236
+ break;
1237
+ case SrcCompositeOp:
1238
+ name = "SrcCompositeOp";
1239
+ break;
1240
+ case SrcInCompositeOp:
1241
+ name = "SrcInCompositeOp";
1242
+ break;
1243
+ case SrcOutCompositeOp:
1244
+ name = "SrcOutCompositeOp";
1245
+ break;
1246
+ case SrcOverCompositeOp:
1247
+ name = "SrcOverCompositeOp";
1248
+ break;
1249
+ #endif
1250
+ case SubtractCompositeOp:
1251
+ name = "SubtractCompositeOp";
1252
+ break;
1253
+ case ThresholdCompositeOp:
1254
+ name = "ThresholdCompositeOp";
1255
+ break;
1256
+ case XorCompositeOp:
1257
+ name = "XorCompositeOp";
1258
+ break;
1259
+ }
1260
+
1261
+ return rm_enum_new(Class_CompositeOperator, ID2SYM(rb_intern(name)), INT2FIX(op));
1262
+ }
1263
+
1077
1264
  /*
1078
1265
  * External: CompressionType_new
1079
1266
  Purpose: Construct a CompressionTYpe enum object for the specified value
@@ -1122,7 +1309,36 @@ CompressionType_new(CompressionType ct)
1122
1309
  }
1123
1310
 
1124
1311
  /*
1125
- External: FilterTypes#new
1312
+ External: DisposeType.new
1313
+ Purpose: Construct a DisposeType enum object for the specified value..new
1314
+ */
1315
+ VALUE
1316
+ DisposeType_new(DisposeType type)
1317
+ {
1318
+ const char *name;
1319
+
1320
+ switch(type)
1321
+ {
1322
+ default:
1323
+ case UndefinedDispose:
1324
+ name = "UndefinedDispose";
1325
+ break;
1326
+ case BackgroundDispose:
1327
+ name = "BackgroundDispose";
1328
+ break;
1329
+ case NoneDispose:
1330
+ name = "NoneDispose";
1331
+ break;
1332
+ case PreviousDispose:
1333
+ name = "PreviousDispose";
1334
+ break;
1335
+ }
1336
+
1337
+ return rm_enum_new(Class_DisposeType, ID2SYM(rb_intern(name)), INT2FIX(type));
1338
+ }
1339
+
1340
+ /*
1341
+ External: FilterTypes.new
1126
1342
  Purpose: Construct an FilterTypes enum object for the specified value
1127
1343
  */
1128
1344
  VALUE
@@ -1189,7 +1405,7 @@ FilterTypes_new(FilterTypes type)
1189
1405
 
1190
1406
 
1191
1407
  /*
1192
- External: EndianType#new
1408
+ External: EndianType.new
1193
1409
  Purpose: Construct an EndianType enum object
1194
1410
  */
1195
1411
  VALUE
@@ -1216,7 +1432,7 @@ EndianType_new(EndianType type)
1216
1432
 
1217
1433
 
1218
1434
  /*
1219
- External: ImageType#new
1435
+ External: ImageType.new
1220
1436
  Purpose: Construct an ImageType enum object for the specified value
1221
1437
  */
1222
1438
  VALUE
@@ -1788,7 +2004,7 @@ StretchType_new(StretchType stretch)
1788
2004
  {
1789
2005
  const char *name;
1790
2006
 
1791
- name = StretchType_Const_Name(stretch);
2007
+ name = StretchType_name(stretch);
1792
2008
  return rm_enum_new(Class_StretchType, ID2SYM(rb_intern(name)), INT2FIX(stretch));
1793
2009
  }
1794
2010
 
@@ -1935,7 +2151,7 @@ Font_to_s(VALUE self)
1935
2151
  ti.description,
1936
2152
  ti.family,
1937
2153
  StyleType_Const_Name(ti.style),
1938
- StretchType_Const_Name(ti.stretch),
2154
+ StretchType_name(ti.stretch),
1939
2155
  weight,
1940
2156
  ti.encoding ? ti.encoding : "",
1941
2157
  ti.foundry ? ti.foundry : "",
@@ -2365,13 +2581,55 @@ Statistics_new(ImageStatistics *stats)
2365
2581
  }
2366
2582
  #endif // HAVE_GETIMAGESTATISTICS
2367
2583
 
2584
+ /*
2585
+ Extern: StorageType_name
2586
+ Purpose: Return the string representation of a StorageType value
2587
+ */
2588
+ const char *
2589
+ StorageType_name(StorageType type)
2590
+ {
2591
+ const char *name;
2592
+
2593
+ switch (type)
2594
+ {
2595
+ default:
2596
+ case UndefinedPixel:
2597
+ name = "UndefinedPixel";
2598
+ break;
2599
+ case CharPixel:
2600
+ name = "CharPixel";
2601
+ break;
2602
+ case DoublePixel:
2603
+ name = "DoublePixel";
2604
+ break;
2605
+ case FloatPixel:
2606
+ name = "FloatPixel";
2607
+ break;
2608
+ case IntegerPixel:
2609
+ name = "IntegerPixel";
2610
+ break;
2611
+ case LongPixel:
2612
+ name = "LongPixel";
2613
+ break;
2614
+ #if defined(HAVE_QUANTUMPIXEL)
2615
+ case QuantumPixel:
2616
+ name = "QuantumPixel";
2617
+ break;
2618
+ #endif
2619
+ case ShortPixel:
2620
+ name = "ShortPixel";
2621
+ break;
2622
+ }
2623
+
2624
+ return name;
2625
+ }
2368
2626
 
2369
2627
  /*
2370
- Static: StretchType_Const_Name
2628
+ Static: StretchType_name
2371
2629
  Purpose: Return the string representation of a StretchType value
2372
2630
  */
2373
2631
  static const char *
2374
- StretchType_Const_Name(StretchType stretch)
2632
+ StretchType_name(StretchType stretch)
2375
2633
  {
2376
2634
  switch (stretch)
2377
2635
  {
data/install.rb CHANGED
@@ -34,9 +34,12 @@ end
34
34
  ### end compat.rb
35
35
  ### begin config.rb
36
36
 
37
- if i = ARGV.index(/\A--rbconfig=/) then
37
+ i = ARGV.detect { |arg| arg =~ /\A--rbconfig=/ }
38
+
39
+ if i then
40
+ i =~ /\A--rbconfig=/
38
41
  file = $'
39
- ARGV.delete_at(i)
42
+ ARGV.delete_if { |arg| arg == i }
40
43
  require file
41
44
  else
42
45
  require 'rbconfig'
@@ -1,4 +1,4 @@
1
- # $Id: RMagick.rb,v 1.25 2005/07/12 23:34:04 rmagick Exp $
1
+ # $Id: RMagick.rb,v 1.32 2005/08/25 23:32:17 rmagick Exp $
2
2
  #==============================================================================
3
3
  # Copyright (C) 2005 by Timothy P. Hunter
4
4
  # Name: RMagick.rb
@@ -163,13 +163,13 @@ class Draw
163
163
  ObliqueStyle.to_i => 'oblique',
164
164
  AnyStyle.to_i => 'all'
165
165
  }
166
-
166
+
167
167
  private
168
168
  def enquote(str)
169
169
  if str.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(str)
170
- return str
170
+ return str
171
171
  else
172
- return '"' + str + '"'
172
+ return '"' + str + '"'
173
173
  end
174
174
  end
175
175
 
@@ -540,19 +540,19 @@ class Draw
540
540
  def text(x, y, text)
541
541
  if text.to_s.empty?
542
542
  raise ArgumentError, "missing text argument"
543
- end
544
- if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
545
- ; # text already quoted
546
- elsif !text['\'']
547
- text = '\''+text+'\''
548
- elsif !text['"']
549
- text = '"'+text+'"'
550
- elsif !(text['{'] || text['}'])
551
- text = '{'+text+'}'
552
- else
553
- # escape existing braces, surround with braces
554
- text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
555
- end
543
+ end
544
+ if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
545
+ ; # text already quoted
546
+ elsif !text['\'']
547
+ text = '\''+text+'\''
548
+ elsif !text['"']
549
+ text = '"'+text+'"'
550
+ elsif !(text['{'] || text['}'])
551
+ text = '{'+text+'}'
552
+ else
553
+ # escape existing braces, surround with braces
554
+ text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
555
+ end
556
556
  primitive "text #{x},#{y} #{text}"
557
557
  end
558
558
 
@@ -686,6 +686,7 @@ class Image
686
686
  # Make all pixels transparent.
687
687
  def matte_reset!
688
688
  self.opacity = Magick::TransparentOpacity
689
+ self
689
690
  end
690
691
 
691
692
  # Replace matching neighboring pixels with texture pixels
@@ -763,6 +764,12 @@ class Image
763
764
  attr_accessor :dirty
764
765
 
765
766
  def initialize(img, x, y, width, height)
767
+ if width <= 0 || height <= 0
768
+ raise ArgumentError, "invalid geometry (#{width}x#{height}+#{x}+#{y})"
769
+ end
770
+ if x < 0 || y < 0 || (x+width) > img.columns || (y+height) > img.rows
771
+ raise RangeError, "geometry (#{width}x#{height}+#{x}+#{y}) exceeds image boundary"
772
+ end
766
773
  @view = img.get_pixels(x, y, width, height)
767
774
  @img = img
768
775
  @x = x
@@ -1009,11 +1016,16 @@ protected
1009
1016
  unless obj.kind_of? Magick::Image
1010
1017
  raise ArgumentError, "Magick::Image required (#{obj.class} given)"
1011
1018
  end
1019
+ true
1012
1020
  end
1013
1021
 
1014
1022
  # Ensure array is always an array of Magick::Image objects
1015
1023
  def is_a_image_array(ary)
1024
+ unless ary.respond_to? :each
1025
+ raise ArgumentError, "Magick::ImageList or array of Magick::Images required (#{ary.class} given)"
1026
+ end
1016
1027
  ary.each { |obj| is_a_image obj }
1028
+ true
1017
1029
  end
1018
1030
 
1019
1031
  # Find old current image, update @scene
@@ -1041,12 +1053,20 @@ public
1041
1053
 
1042
1054
  # Allow scene to be set to nil
1043
1055
  def scene=(n)
1044
- if (length == 0 && n != nil) || (length > 0 && n == nil)
1056
+ if n.nil?
1057
+ raise IndexError, "scene number out of bounds" unless length == 0
1058
+ @scene = nil
1059
+ return @scene
1060
+ elsif length == 0
1045
1061
  raise IndexError, "scene number out of bounds"
1046
- elsif (length == 0) || (Integer(n) < 0) || (Integer(n) > length - 1)
1062
+ end
1063
+
1064
+ n = Integer(n)
1065
+ if n < 0 || n > length - 1
1047
1066
  raise IndexError, "scene number out of bounds"
1048
1067
  end
1049
- @scene = Integer(n)
1068
+ @scene = n
1069
+ return @scene
1050
1070
  end
1051
1071
 
1052
1072
  def [](*args)
@@ -1059,15 +1079,17 @@ public
1059
1079
 
1060
1080
  def []=(*args)
1061
1081
  if args.length == 3 # f[start,length] = [f1,f2...]
1062
- is_a_image_array args[2]
1082
+ args[2].kind_of?(Magick::Image) || is_a_image_array(args[2])
1063
1083
  super
1064
- if args[1] > 0
1065
- @scene = args[0] + args[1] - 1
1066
- else # inserts elements if length == 0
1084
+ args[0] = args[0] + length if (args[0] < 0)
1085
+ args[1] = length - args[0] if (args[0] + args[1] > length)
1086
+ if args[2].kind_of?(Magick::Image)
1087
+ @scene = args[0]
1088
+ else
1067
1089
  @scene = args[0] + args[2].length - 1
1068
1090
  end
1069
1091
  elsif args[0].kind_of? Range # f[first..last] = [f1,f2...]
1070
- is_a_image_array args[1]
1092
+ args[1].kind_of?(Magick::Image) || is_a_image_array(args[1])
1071
1093
  super
1072
1094
  @scene = args[0].end
1073
1095
  else # f[index] = f1
@@ -1187,49 +1209,61 @@ public
1187
1209
  return a
1188
1210
  end
1189
1211
 
1190
- def fill(obj, *args)
1191
- is_a_image obj
1212
+ def fill(*args, &block)
1213
+ is_a_image args[0] unless block_given?
1192
1214
  cfid = self[@scene].__id__ rescue nil
1193
- a = super
1215
+ super
1216
+ is_a_image_array self
1194
1217
  set_cf cfid
1195
- return a
1218
+ return self
1196
1219
  end
1197
1220
 
1198
- if Array.instance_methods(false).include? 'fetch' then
1199
- def fetch(*args,&block)
1200
- super
1201
- end
1221
+ def find_all(&block)
1222
+ cfid = self[@scene].__id__ rescue nil
1223
+ a = super
1224
+ a.set_cf cfid
1225
+ return a
1202
1226
  end
1203
1227
 
1204
- if Array.instance_methods(false).include? 'insert' then
1228
+ if self.superclass.instance_methods.include? 'insert' then
1205
1229
  def insert(*args)
1230
+ raise(ArgumentError, "can't insert nil") unless args.length > 1
1231
+ is_a_image_array args[1,args.length-1]
1206
1232
  cfid = self[@scene].__id__ rescue nil
1207
- a = self.class.new.replace super
1208
- a.set_cf cfid
1209
- return a
1233
+ super
1234
+ set_cf cfid
1235
+ return self
1210
1236
  end
1211
1237
  end
1212
1238
 
1213
- # __map__ is a synonym for Array#map. We've used an alias
1214
- # so it doesn't conflict with our own map method.
1215
- if Array.instance_methods(false).include? '__map__' then
1216
- def __map__(&block)
1217
- cfid = self[@scene].__id__ rescue nil
1218
- a = self.class.new.replace super
1219
- a.set_cf cfid
1220
- return a
1239
+ # Enumerable (or Array) has a #map method that conflicts with our
1240
+ # own #map method. RMagick.so has defined a synonym for that #map
1241
+ # called Array#__ary_map__. Here, we define Magick::ImageList#__map__
1242
+ # to allow the use of the Enumerable/Array#map method on ImageList objects.
1243
+ def __map__(&block)
1244
+ cfid = self[@scene].__id__ rescue nil
1245
+ ensure_image = Proc.new do |img|
1246
+ rv = block.call(img)
1247
+ is_a_image rv
1248
+ return rv
1221
1249
  end
1250
+ a = self.class.new.replace __ary_map__(&ensure_image)
1251
+ a.set_cf cfid
1252
+ return a
1222
1253
  end
1223
1254
 
1224
1255
  def map!(&block)
1225
- super
1226
- is_a_image_array self
1227
- self
1256
+ ensure_image = Proc.new do |img|
1257
+ rv = block.call(img)
1258
+ is_a_image rv
1259
+ return rv
1260
+ end
1261
+ super(&ensure_image)
1228
1262
  end
1229
1263
 
1230
1264
  def pop
1231
1265
  cfid = self[@scene].__id__ rescue nil
1232
- a = super
1266
+ a = super # can return nil
1233
1267
  set_cf cfid
1234
1268
  return a
1235
1269
  end
@@ -1241,18 +1275,16 @@ public
1241
1275
  self
1242
1276
  end
1243
1277
 
1244
- if Array.instance_methods(false).include? 'reject' then
1245
- def reject(&block)
1246
- cfid = self[@scene].__id__ rescue nil
1247
- a = super
1248
- set_cf cfid
1249
- return a
1250
- end
1278
+ def reject(&block)
1279
+ cfid = self[@scene].__id__ rescue nil
1280
+ a = self.class.new.replace super
1281
+ a.set_cf cfid
1282
+ return a
1251
1283
  end
1252
1284
 
1253
1285
  def reject!(&block)
1254
1286
  cfid = self[@scene].__id__ rescue nil
1255
- a = super
1287
+ a = super # can return nil
1256
1288
  set_cf cfid
1257
1289
  return a
1258
1290
  end
@@ -1266,6 +1298,9 @@ public
1266
1298
  cfid = self[@scene].__id__ rescue nil
1267
1299
  end
1268
1300
  super
1301
+ # set_cf will fail if the new list has fewer images
1302
+ # than the scene number indicates.
1303
+ @scene = self.length == 0 ? nil : 0
1269
1304
  set_cf cfid
1270
1305
  self
1271
1306
  end
@@ -1284,13 +1319,11 @@ public
1284
1319
  return a
1285
1320
  end
1286
1321
 
1287
- if Array.instance_methods(false).include? 'select' then
1288
- def select(*args,&block)
1289
- cfid = self[@scene].__id__ rescue nil
1290
- a = super
1291
- a.set_cf cfid
1292
- return a
1293
- end
1322
+ def select(&block)
1323
+ cfid = self[@scene].__id__ rescue nil
1324
+ a = self.class.new.replace super
1325
+ a.set_cf cfid
1326
+ return a
1294
1327
  end
1295
1328
 
1296
1329
  def shift
@@ -1351,11 +1384,24 @@ public
1351
1384
  r = self[x] <=> other[x]
1352
1385
  return r unless r == 0
1353
1386
  end
1387
+ if @scene.nil? && other.scene.nil?
1388
+ return 0
1389
+ elsif @scene.nil? && ! other.scene.nil?
1390
+ raise TypeError, "cannot convert nil into #{other.scene.class}"
1391
+ elsif ! @scene.nil? && other.scene.nil?
1392
+ raise TypeError, "cannot convert nil into #{self.scene.class}"
1393
+ end
1354
1394
  r = self.scene <=> other.scene
1355
1395
  return r unless r == 0
1356
1396
  return self.length <=> other.length
1357
1397
  end
1358
1398
 
1399
+ def clone
1400
+ ditto = dup
1401
+ ditto.freeze if frozen?
1402
+ return ditto
1403
+ end
1404
+
1359
1405
  # Make a deep copy
1360
1406
  def copy
1361
1407
  ditto = self.class.new
@@ -1381,6 +1427,14 @@ public
1381
1427
  each { |f| f.delay = Integer(d) }
1382
1428
  end
1383
1429
 
1430
+ def dup
1431
+ ditto = self.class.new
1432
+ each {|img| ditto << img}
1433
+ ditto.scene = @scene
1434
+ ditto.taint if tainted?
1435
+ return ditto
1436
+ end
1437
+
1384
1438
  def from_blob(*blobs, &block)
1385
1439
  if (blobs.length == 0)
1386
1440
  raise ArgumentError, "no blobs given"
@@ -1413,6 +1467,7 @@ public
1413
1467
 
1414
1468
  # Set the number of iterations of an animated GIF
1415
1469
  def iterations=(n)
1470
+ n = Integer(n)
1416
1471
  if n < 0 || n > 65535
1417
1472
  raise ArgumentError, "iterations must be between 0 and 65535"
1418
1473
  end
@@ -1431,8 +1486,8 @@ public
1431
1486
  else
1432
1487
  super
1433
1488
  end
1434
- rescue NameError
1435
- raise NameError, "undefined method `#{methID.id2name}' for #{self.class}"
1489
+ rescue NoMethodError
1490
+ raise NoMethodError, "undefined method `#{methID.id2name}' for #{self.class}"
1436
1491
  rescue Exception
1437
1492
  $@.delete_if { |s| /:in `send'$/.match(s) || /:in `method_missing'$/.match(s) }
1438
1493
  raise