rmagick4j 0.3.4-java → 0.3.9-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/History.txt +84 -0
  3. data/LICENSE.txt +31 -0
  4. data/README.txt +25 -0
  5. data/Rakefile +65 -0
  6. data/lib/magick4j.jar +0 -0
  7. data/lib/{RMagick.rb → rmagick.rb} +574 -405
  8. data/lib/rmagick4j/constants.rb +34 -0
  9. data/lib/rmagick4j/draw.rb +124 -0
  10. data/lib/rmagick4j/enum.rb +120 -0
  11. data/lib/rmagick4j/gradient_fill.rb +14 -0
  12. data/lib/rmagick4j/image.rb +351 -0
  13. data/lib/rmagick4j/image_list.rb +25 -0
  14. data/lib/rmagick4j/pixel.rb +170 -0
  15. data/lib/rmagick4j/rmagick4j.rb +15 -430
  16. data/lib/rmagick4j/texture_fill.rb +14 -0
  17. data/lib/rmagick4j/type_metric.rb +8 -0
  18. data/lib/rmagick4j/version.rb +5 -0
  19. data/lib/rvg/clippath.rb +2 -2
  20. data/lib/rvg/container.rb +2 -2
  21. data/lib/rvg/describable.rb +2 -2
  22. data/lib/rvg/embellishable.rb +2 -2
  23. data/lib/rvg/misc.rb +3 -3
  24. data/lib/rvg/paint.rb +7 -2
  25. data/lib/rvg/pathdata.rb +2 -2
  26. data/lib/rvg/rvg.rb +3 -3
  27. data/lib/rvg/stretchable.rb +15 -3
  28. data/lib/rvg/stylable.rb +2 -2
  29. data/lib/rvg/text.rb +2 -2
  30. data/lib/rvg/transformable.rb +2 -2
  31. data/lib/rvg/units.rb +2 -2
  32. data/test/RMagickTestSuite.rb +129 -0
  33. data/test/eyetests/bullseye.rb +151 -0
  34. data/test/eyetests/doc.rb +79 -0
  35. data/test/eyetests/tests/draw_arc_basic.rb +16 -0
  36. data/test/eyetests/tests/draw_circle_affine.rb +19 -0
  37. data/test/eyetests/tests/draw_circle_basic.rb +16 -0
  38. data/test/eyetests/tests/draw_clip_path.rb +44 -0
  39. data/test/eyetests/tests/draw_ellipse_affine.rb +19 -0
  40. data/test/eyetests/tests/draw_ellipse_basic.rb +16 -0
  41. data/test/eyetests/tests/draw_line_affine.rb +24 -0
  42. data/test/eyetests/tests/draw_line_basic.rb +21 -0
  43. data/test/eyetests/tests/draw_multiline_type_metrics.rb +42 -0
  44. data/test/eyetests/tests/draw_pattern_1.rb +35 -0
  45. data/test/eyetests/tests/draw_polygon_affine.rb +22 -0
  46. data/test/eyetests/tests/draw_polygon_basic.rb +19 -0
  47. data/test/eyetests/tests/draw_polyline_affine.rb +19 -0
  48. data/test/eyetests/tests/draw_polyline_basic.rb +18 -0
  49. data/test/eyetests/tests/draw_pop_push.rb +16 -0
  50. data/test/eyetests/tests/draw_pop_push_translate.rb +22 -0
  51. data/test/eyetests/tests/draw_rectangle_affine.rb +16 -0
  52. data/test/eyetests/tests/draw_rectangle_basic.rb +16 -0
  53. data/test/eyetests/tests/draw_rectangle_narrow.rb +18 -0
  54. data/test/eyetests/tests/draw_rmagick_test_01.rb +35 -0
  55. data/test/eyetests/tests/draw_rmagick_test_02.rb +40 -0
  56. data/test/eyetests/tests/draw_rmagick_test_03.rb +17 -0
  57. data/test/eyetests/tests/draw_rmagick_test_04.rb +21 -0
  58. data/test/eyetests/tests/draw_rotate_01.rb +33 -0
  59. data/test/eyetests/tests/draw_roundrectangle_affine.rb +19 -0
  60. data/test/eyetests/tests/draw_roundrectangle_basic.rb +16 -0
  61. data/test/eyetests/tests/draw_scale_01.rb +33 -0
  62. data/test/eyetests/tests/draw_skewx_01.rb +34 -0
  63. data/test/eyetests/tests/draw_skewy_01.rb +33 -0
  64. data/test/eyetests/tests/draw_stroke_miterlimit.rb +21 -0
  65. data/test/eyetests/tests/effect_blur.rb +9 -0
  66. data/test/eyetests/tests/effect_charcoal.rb +9 -0
  67. data/test/eyetests/tests/effect_edge.rb +9 -0
  68. data/test/eyetests/tests/effect_implode.rb +9 -0
  69. data/test/eyetests/tests/effect_negate.rb +9 -0
  70. data/test/eyetests/tests/effect_negate_true.rb +9 -0
  71. data/test/eyetests/tests/effect_normalize.rb +9 -0
  72. data/test/eyetests/tests/effect_shade.rb +9 -0
  73. data/test/eyetests/tests/effect_solarize.rb +10 -0
  74. data/test/eyetests/tests/effect_wave.rb +9 -0
  75. data/test/eyetests/tests/gradient_fill_horizontal_diagonal_fill.rb +9 -0
  76. data/test/eyetests/tests/gradient_fill_horizontal_fill.rb +9 -0
  77. data/test/eyetests/tests/gradient_fill_point_fill.rb +9 -0
  78. data/test/eyetests/tests/gradient_fill_vertical_diagonal_fill.rb +9 -0
  79. data/test/eyetests/tests/gradient_fill_vertical_fill.rb +9 -0
  80. data/test/eyetests/tests/gruff_accumulator_bar.rb +29 -0
  81. data/test/eyetests/tests/gruff_area_1.rb +16 -0
  82. data/test/eyetests/tests/gruff_area_2.rb +27 -0
  83. data/test/eyetests/tests/gruff_bar_1.rb +29 -0
  84. data/test/eyetests/tests/gruff_bar_2.rb +19 -0
  85. data/test/eyetests/tests/gruff_dot_1.rb +19 -0
  86. data/test/eyetests/tests/gruff_line_1.rb +13 -0
  87. data/test/eyetests/tests/gruff_line_2.rb +20 -0
  88. data/test/eyetests/tests/gruff_net_1.rb +16 -0
  89. data/test/eyetests/tests/gruff_net_2.rb +16 -0
  90. data/test/eyetests/tests/gruff_pie_1.rb +21 -0
  91. data/test/eyetests/tests/gruff_pie_2.rb +22 -0
  92. data/test/eyetests/tests/gruff_scene_1.rb +14 -0
  93. data/test/eyetests/tests/gruff_scene_2.rb +14 -0
  94. data/test/eyetests/tests/gruff_sidebar.rb +32 -0
  95. data/test/eyetests/tests/gruff_sidestacked_bar_1.rb +26 -0
  96. data/test/eyetests/tests/gruff_sidestacked_bar_2.rb +26 -0
  97. data/test/eyetests/tests/gruff_spider_1.rb +22 -0
  98. data/test/eyetests/tests/gruff_spider_2.rb +15 -0
  99. data/test/eyetests/tests/gruff_stacked_area_1.rb +23 -0
  100. data/test/eyetests/tests/gruff_stacked_bar_1.rb +23 -0
  101. data/test/eyetests/tests/gruff_stacked_bar_2.rb +26 -0
  102. data/test/eyetests/tests/hatch_fill.rb +9 -0
  103. data/test/eyetests/tests/image_list_flatten_images.rb +15 -0
  104. data/test/eyetests/tests/new_image.rb +31 -0
  105. data/test/eyetests/tests/path_a_command_01.rb +16 -0
  106. data/test/eyetests/tests/path_a_command_02.rb +19 -0
  107. data/test/eyetests/tests/path_c_command_01.rb +16 -0
  108. data/test/eyetests/tests/path_c_command_02.rb +16 -0
  109. data/test/eyetests/tests/path_complex_01.rb +16 -0
  110. data/test/eyetests/tests/path_espiral_01.rb +29 -0
  111. data/test/eyetests/tests/path_h_command_01.rb +16 -0
  112. data/test/eyetests/tests/path_h_command_02.rb +16 -0
  113. data/test/eyetests/tests/path_l_command_01.rb +16 -0
  114. data/test/eyetests/tests/path_l_command_02.rb +16 -0
  115. data/test/eyetests/tests/path_m_command_01.rb +16 -0
  116. data/test/eyetests/tests/path_m_command_02.rb +16 -0
  117. data/test/eyetests/tests/path_m_command_03.rb +16 -0
  118. data/test/eyetests/tests/path_q_command_01.rb +16 -0
  119. data/test/eyetests/tests/path_q_command_02.rb +16 -0
  120. data/test/eyetests/tests/path_q_command_03.rb +25 -0
  121. data/test/eyetests/tests/path_s_command_01.rb +16 -0
  122. data/test/eyetests/tests/path_s_command_02.rb +16 -0
  123. data/test/eyetests/tests/path_star_01.rb +19 -0
  124. data/test/eyetests/tests/path_t_command_01.rb +16 -0
  125. data/test/eyetests/tests/path_t_command_02.rb +16 -0
  126. data/test/eyetests/tests/path_v_command_01.rb +16 -0
  127. data/test/eyetests/tests/path_v_command_02.rb +16 -0
  128. data/test/eyetests/tests/store_pixel_smiley.rb +123 -0
  129. data/test/eyetests/tests/texture_fill.rb +11 -0
  130. data/test/gruff_tests/test/gruff_test_case.rb +123 -0
  131. data/test/gruff_tests/test/monkey_gruff.rb +7 -0
  132. data/test/gruff_tests/test/test_accumulator_bar.rb +50 -0
  133. data/test/gruff_tests/test/test_area.rb +134 -0
  134. data/test/gruff_tests/test/test_bar.rb +295 -0
  135. data/test/gruff_tests/test/test_base.rb +8 -0
  136. data/test/gruff_tests/test/test_bullet.rb +26 -0
  137. data/test/gruff_tests/test/test_dot.rb +273 -0
  138. data/test/gruff_tests/test/test_legend.rb +68 -0
  139. data/test/gruff_tests/test/test_line.rb +554 -0
  140. data/test/gruff_tests/test/test_mini_bar.rb +33 -0
  141. data/test/gruff_tests/test/test_mini_pie.rb +20 -0
  142. data/test/gruff_tests/test/test_mini_side_bar.rb +37 -0
  143. data/test/gruff_tests/test/test_net.rb +230 -0
  144. data/test/gruff_tests/test/test_photo.rb +41 -0
  145. data/test/gruff_tests/test/test_pie.rb +154 -0
  146. data/test/gruff_tests/test/test_scene.rb +100 -0
  147. data/test/gruff_tests/test/test_side_bar.rb +12 -0
  148. data/test/gruff_tests/test/test_sidestacked_bar.rb +89 -0
  149. data/test/gruff_tests/test/test_spider.rb +216 -0
  150. data/test/gruff_tests/test/test_stacked_area.rb +52 -0
  151. data/test/gruff_tests/test/test_stacked_bar.rb +52 -0
  152. data/test/images/clown.jpg +0 -0
  153. data/test/images/texture.jpg +0 -0
  154. data/test/implemented_methods.rb +18 -0
  155. data/test/spec/draw_spec.rb +43 -0
  156. data/test/spec/features/step_definitions/geometry_steps.rb +22 -0
  157. data/test/spec/features/step_definitions/image_filling_steps.rb +49 -0
  158. data/test/spec/features/support/env.rb +3 -0
  159. data/test/spec/image_constants.rb +76 -0
  160. data/test/spec/image_spec.rb +83 -0
  161. data/test/spec/pixel_spec.rb +89 -0
  162. metadata +333 -45
  163. data/lib/RMagick.jar +0 -0
  164. data/lib/jhlabs-filters.jar +0 -0
@@ -0,0 +1,14 @@
1
+
2
+ module Magick
3
+ class TextureFill
4
+
5
+ def fill(image)
6
+ @fill.fill(image._image)
7
+ end
8
+
9
+ def initialize(image)
10
+ image = image.cur_image if image.respond_to? :cur_image
11
+ @fill = Magick4J.TextureFill.new(image._image)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+
2
+ module Magick
3
+ class TypeMetric
4
+
5
+ attr_accessor :ascent, :descent, :height, :max_advance, :width
6
+
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module RMagick4J
2
+ module Version
3
+ VERSION = '0.3.9'
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: clippath.rb,v 1.3 2007/01/20 17:39:48 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: clippath.rb,v 1.4 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
  module Magick
6
6
  class RVG
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: container.rb,v 1.3 2007/01/20 17:39:49 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: container.rb,v 1.4 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: describable.rb,v 1.3 2007/01/20 17:39:49 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: describable.rb,v 1.4 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: embellishable.rb,v 1.7 2007/01/20 17:39:49 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: embellishable.rb,v 1.8 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -1,5 +1,5 @@
1
- # $Id: misc.rb,v 1.10 2007/01/20 17:39:49 rmagick Exp $
2
- # Copyright (C) 2007 Timothy P. Hunter
1
+ # $Id: misc.rb,v 1.12 2008/02/24 18:26:36 rmagick Exp $
2
+ # Copyright (C) 2008 Timothy P. Hunter
3
3
  module Magick
4
4
  class RVG
5
5
 
@@ -295,7 +295,7 @@ module Magick
295
295
  end
296
296
  first_word = false
297
297
  word.split('').each do |glyph|
298
- case @ctx.text_attrs.glyph_orientation_vertical
298
+ case @ctx.text_attrs.glyph_orientation_vertical.to_i
299
299
  when 0, 90, 270
300
300
  x_shift = (dx - x_rel_coords.shift) / 2
301
301
  when 180
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: paint.rb,v 1.4 2007/01/20 17:39:49 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: paint.rb,v 1.5 2008/02/24 18:26:36 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
  # Defines paint server classes.
6
6
  # Eventually this will include gradients.
@@ -18,6 +18,11 @@ module Magick
18
18
  include Duplicatable
19
19
  include Stylable
20
20
 
21
+ # Return upper-left corner, width, height of viewport in user coordinates.
22
+ # Usually these are the values specified when the Pattern object is
23
+ # created, but they can be changed by a call to the viewbox method.
24
+ attr_reader :x, :y, :width, :height
25
+
21
26
  # Create a pattern that can be used with the :fill or :stroke styles.
22
27
  # The +width+ and +height+ arguments define the viewport.
23
28
  # The pattern will be repeated at <tt>x+m*width</tt> and <tt>y+n*height</tt>
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: pathdata.rb,v 1.3 2007/01/20 17:39:49 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: pathdata.rb,v 1.4 2008/02/24 18:26:37 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -1,7 +1,7 @@
1
1
  #--############################################################################
2
- # $Id: rvg.rb,v 1.8 2007/01/20 17:39:50 rmagick Exp $
2
+ # $Id: rvg.rb,v 1.9 2008/02/24 21:15:24 rmagick Exp $
3
3
  #
4
- # Copyright (C) 2007 by Timothy P. Hunter
4
+ # Copyright (C) 2008 by Timothy P. Hunter
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a
7
7
  # copy of this software and associated documentation files (the
@@ -222,7 +222,7 @@ module Magick
222
222
  @background_fill_opacity = 1.0 # applies only if background_fill= is used
223
223
  @background_position = :scaled
224
224
  @background_pattern, @background_image, @desc, @title, @metadata = nil
225
- @x, @y = 0.0
225
+ @x, @y = 0.0, 0.0
226
226
  @nested = false
227
227
  yield(self) if block_given?
228
228
  end
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: stretchable.rb,v 1.4 2007/01/20 17:39:50 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: stretchable.rb,v 1.6 2008/02/24 21:52:32 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -36,7 +36,7 @@ module Magick
36
36
 
37
37
 
38
38
  # The methods in this module describe the user-coordinate space.
39
- # Only RVG objects are stretchable.
39
+ # RVG and Pattern objects are stretchable.
40
40
  module Stretchable
41
41
 
42
42
  private
@@ -145,6 +145,18 @@ module Magick
145
145
  end
146
146
  raise(ArgumentError, "viewbox width must be > 0 (#{width} given)") unless width >= 0
147
147
  raise(ArgumentError, "viewbox height must be > 0 (#{height} given)") unless height >= 0
148
+
149
+ # return the user-coordinate space attributes if defined
150
+ class << self
151
+ if not defined? @redefined then
152
+ @redefined = true
153
+ define_method(:x) { @vbx_x }
154
+ define_method(:y) { @vbx_y }
155
+ define_method(:width) { @vbx_width}
156
+ define_method(:height) { @vbx_height }
157
+ end
158
+ end
159
+
148
160
  yield(self) if block_given?
149
161
  self
150
162
  end
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: stylable.rb,v 1.4 2007/01/20 17:49:57 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: stylable.rb,v 1.5 2008/02/24 18:26:37 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: text.rb,v 1.5 2007/01/20 17:39:50 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: text.rb,v 1.6 2008/02/24 18:26:37 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
  # Text-related classes
6
6
 
@@ -1,6 +1,6 @@
1
1
  #--
2
- # $Id: transformable.rb,v 1.3 2007/01/20 17:39:50 rmagick Exp $
3
- # Copyright (C) 2007 Timothy P. Hunter
2
+ # $Id: transformable.rb,v 1.4 2008/02/24 18:26:37 rmagick Exp $
3
+ # Copyright (C) 2008 Timothy P. Hunter
4
4
  #++
5
5
 
6
6
  module Magick
@@ -1,5 +1,5 @@
1
- # $Id: units.rb,v 1.3 2007/01/20 17:39:50 rmagick Exp $
2
- # Copyright (C) 2007 Timothy P. Hunter
1
+ # $Id: units.rb,v 1.4 2008/02/24 18:26:37 rmagick Exp $
2
+ # Copyright (C) 2008 Timothy P. Hunter
3
3
  module Magick
4
4
  class RVG
5
5
 
@@ -0,0 +1,129 @@
1
+ puts Time.new
2
+ begin
3
+ require 'rubygems'
4
+ gem PLATFORM == 'java' ? 'rmagick4j' : 'rmagick'
5
+ rescue Exception
6
+ puts "No gems! #{$!}"
7
+ end
8
+ puts Time.new
9
+ require 'RMagick'
10
+ puts Time.new
11
+
12
+ # TODO I know this isn't a real test, but it's what I've got for now.
13
+ # TODO Probably eventually want to hook into RMagick's existing tests.
14
+
15
+ def main
16
+ if ARGV.length > 0
17
+ ARGV.each {|arg| send(arg).display}
18
+ else
19
+ image = addTransparencyWithAMask.raise
20
+ # image = open_clown.blur_image(0, 5)
21
+ open(File.dirname(__FILE__) +'/test.jpg', 'w') do |file|
22
+ file.write(image.to_blob {self.format = 'JPEG'})
23
+ end
24
+ end
25
+ puts Time.new
26
+ end
27
+
28
+ def addRaisedEdges
29
+ open_clown.raise
30
+ end
31
+
32
+ def addText
33
+ clown = open_clown
34
+ text = Magick::Draw.new
35
+ text.annotate(clown, 0, 0, 0, 60, "My friend!") {
36
+ self.gravity = Magick::SouthGravity
37
+ self.pointsize = 48
38
+ self.stroke = 'transparent'
39
+ self.fill = '#0000A9'
40
+ self.font_weight = Magick::BoldWeight
41
+ }
42
+ clown.first
43
+ end
44
+
45
+ def addTransparencyWithAMask
46
+ clown = open_clown.first
47
+ mask = Magick::Image.new(clown.columns, clown.rows) {
48
+ self.background_color = 'black'
49
+ }
50
+ bg = Magick::Image.read("pattern:checkerboard") {
51
+ self.size = "#{clown.columns}x#{clown.rows}"
52
+ }
53
+ bg = bg.first
54
+
55
+ height = clown.rows * 0.8
56
+ width = clown.columns * 0.7
57
+ x = (clown.columns - width) / 2
58
+ y = (clown.rows - height) / 2
59
+
60
+ gc = Magick::Draw.new
61
+ gc.stroke('white').fill('white')
62
+ gc.roundrectangle(x, y, x+width, y+height, 24, 24)
63
+ gc.draw(mask)
64
+
65
+ mask = mask.blur_image(0, 20)
66
+
67
+ mask.matte = false
68
+ clown.matte = true
69
+
70
+ clown = clown.composite(mask, Magick::CenterGravity, Magick::CopyOpacityCompositeOp)
71
+ bg.composite(clown, Magick::CenterGravity, Magick::OverCompositeOp)
72
+ end
73
+
74
+ def addWatermark
75
+ mark = Magick::Image.new(300, 50) do
76
+ self.background_color = 'none'
77
+ end
78
+ gc = Magick::Draw.new
79
+ gc.annotate(mark, 0, 0, 0, 0, "Image by RMagick") do
80
+ self.gravity = Magick::CenterGravity
81
+ self.pointsize = 32
82
+ self.font_family = "Times"
83
+ self.fill = "white"
84
+ self.stroke = "none"
85
+ end
86
+ mark.rotate!(-90)
87
+ clown = open_clown.first
88
+ clown = clown.watermark(mark, 0.15, 0, Magick::EastGravity)
89
+ clown
90
+ end
91
+
92
+ def crop_resized
93
+ open_clown.crop_resized(50, 50)
94
+ end
95
+
96
+ def cropToANewSize
97
+ clown = open_clown
98
+ face = clown.crop(50, 15, 150, 165)
99
+ white_bg = Magick::Image.new(clown.columns, clown.rows)
100
+ white_bg.composite(face, 50, 15, Magick::OverCompositeOp)
101
+ end
102
+
103
+ def flipIt
104
+ open_clown.flip!
105
+ end
106
+
107
+ def makeAThumbnail
108
+ clown = open_clown
109
+ tiny = clown.resize(0.25)
110
+ white_bg = Magick::Image.new(clown.columns, clown.rows)
111
+ white_bg.composite(tiny, Magick::CenterGravity, Magick::OverCompositeOp)
112
+ end
113
+
114
+ def open_clown
115
+ #Magick::ImageList.new("clown.jpg")
116
+ open(File.dirname(__FILE__) + "/clown.jpg") {|file| Magick::ImageList.new.from_blob(file.read)}
117
+ end
118
+
119
+ def rotateToAnyAngle
120
+ clown = open_clown
121
+ clown.rotate(130)
122
+ end
123
+
124
+ def turnItIntoBlackAndWhite
125
+ clown = Magick::ImageList.new("clown.jpg")
126
+ clown.quantize(256, Magick::GRAYColorspace)
127
+ end
128
+
129
+ main
@@ -0,0 +1,151 @@
1
+ TEST_ROOT = File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'java'
4
+ require 'rubygems'
5
+
6
+ #require 'RMagick'
7
+ require 'profligacy/swing'
8
+ require 'profligacy/lel'
9
+ require TEST_ROOT + '/tests/new_image.rb'
10
+ require 'tmpdir'
11
+ Kernel.srand(Time.now.to_i)
12
+ OUTPUT_DIR = File.join(Dir.tmpdir,Kernel.rand(100).to_s)
13
+ Dir.mkdir(OUTPUT_DIR)
14
+
15
+ module Bullseye
16
+ include Profligacy
17
+
18
+ DefaultListModel = javax.swing.DefaultListModel
19
+ ImageIO = javax.imageio.ImageIO
20
+ JButton = javax.swing.JButton
21
+ JFile = java.io.File
22
+ JFrame = javax.swing.JFrame
23
+ JLabel = javax.swing.JLabel
24
+ JList = javax.swing.JList
25
+ JPanel = javax.swing.JPanel
26
+ JScrollPane = javax.swing.JScrollPane
27
+ JTextField = javax.swing.JTextField
28
+
29
+ class ImagePanel < JPanel
30
+ attr_accessor :image_1, :image_2
31
+
32
+ def paint(graphics)
33
+
34
+ unless image_1.nil?
35
+ begin
36
+ pic = load_image(image_1)
37
+ graphics.drawImage(pic, 0, 0, nil)
38
+ rescue
39
+ pic = Magick::Image.new(300, 300)
40
+ pic.background_color = 'red'
41
+ pic.erase!
42
+ graphics.drawImage(pic._image.getImage, 0, 0, nil)
43
+ end
44
+ end
45
+
46
+ unless image_2.nil?
47
+ begin
48
+ pic = load_image(image_2)
49
+ graphics.drawImage(pic, 310, 0, nil)
50
+ rescue
51
+ pic = Magick::Image.new(300, 300)
52
+ pic.background_color = 'red'
53
+ pic.erase!
54
+ graphics.drawImage(pic._image.getImage, 310, 0, nil)
55
+ end
56
+ end
57
+ end
58
+
59
+ def load_image(filename)
60
+ file = JFile.new(filename)
61
+ raise ArgumentError.new("File #{filename} does not exist") unless file.exists
62
+ ImageIO.read(file)
63
+ end
64
+ end
65
+
66
+ class ScriptRunner < Struct.new(:picture_panel, :source)
67
+ def initialize(picture_panel, source)
68
+ super(picture_panel, source)
69
+ @running = false
70
+ end
71
+
72
+ def run_script
73
+ @running = true
74
+ script_name = source.selected_value.downcase.gsub(' ','_')
75
+ selected_script = File.join(TEST_ROOT, 'tests', script_name + '.rb')
76
+ NOTIFIER.notify 'Running script in MRI.'
77
+ output_commands = `sh -c 'ruby #{selected_script} #{OUTPUT_DIR}'`
78
+ NOTIFIER.notify 'Running in JRuby.'
79
+ output_commands += `jruby #{selected_script} #{OUTPUT_DIR}`
80
+ if output_commands == ''
81
+ NOTIFIER.notify 'Done'
82
+ picture_panel.image_1 = File.join(OUTPUT_DIR, script_name + '.jruby.jpg')
83
+ picture_panel.image_2 = File.join(OUTPUT_DIR, script_name + '.mri.jpg')
84
+ picture_panel.repaint
85
+ else
86
+ puts output_commands
87
+ NOTIFIER.notify 'Error'
88
+ end
89
+ @running = false
90
+ end
91
+ end
92
+
93
+ class Notifier < Struct.new(:output)
94
+ def notify(string)
95
+ output.text = string.to_s
96
+ end
97
+ end
98
+
99
+ class ScriptList < JList
100
+ def initialize
101
+ @default_model = DefaultListModel.new
102
+ super(@default_model)
103
+ load_test_scripts
104
+
105
+ self.setSelectedIndex(0)
106
+ end
107
+
108
+ def load_test_scripts
109
+ Dir[File.dirname(__FILE__) + '/tests/*.rb'].sort.each do |script|
110
+ script = script.gsub(/(^.*tests\/|.rb$)/,'').split('_').map{|x| x.capitalize}.join(' ')
111
+ @default_model.addElement(script) unless script == 'New Image'
112
+ end
113
+ end
114
+ end
115
+
116
+ def self.scrollable(component)
117
+ JScrollPane.new component,
118
+ JScrollPane::VERTICAL_SCROLLBAR_AS_NEEDED,
119
+ JScrollPane::HORIZONTAL_SCROLLBAR_NEVER
120
+ end
121
+
122
+ lel = '[ <label_results | <label_scripts ]
123
+ [ (610,300)image_panel | <scripts_list ]
124
+ [ >status | >run_button ]'
125
+
126
+ ui = Swing::LEL.new(JFrame, lel) do |c, i|
127
+ c.label_scripts = JLabel.new('Scripts')
128
+ c.scripts_list = scrollable(scripts = ScriptList.new)
129
+ c.run_button = JButton.new('Run')
130
+ c.label_results = JLabel.new('Results')
131
+ c.image_panel = ImagePanel.new
132
+ c.status = JLabel.new ""
133
+
134
+ Bullseye::NOTIFIER = Notifier.new(c.status)
135
+ script_runner = ScriptRunner.new(c.image_panel, scripts)
136
+ run_script = proc {
137
+ scripts.enabled = c.run_button.enabled = false
138
+ Thread.new do
139
+ NOTIFIER.notify 'Running scripts...'
140
+ script_runner.run_script
141
+ scripts.enabled = c.run_button.enabled = true
142
+ end
143
+ }
144
+
145
+ scripts.addMouseListener { |event| run_script.call if event.click_count == 2 }
146
+ i.run_button = {:action => proc { |t,e| run_script.call } }
147
+ end.build :args => 'Bullseye'
148
+
149
+ ui.default_close_operation = JFrame::EXIT_ON_CLOSE
150
+
151
+ end