tung-tea 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@ This grab method copies a sub-section of the Bitmap (or all of it if no argument
40
40
  Tea::ImageSaving:
41
41
  * save(path)
42
42
 
43
- The save method saves the Bitmap as an image file.
43
+ The save method saves the Bitmap as an image file. Supported formats: BMP, PNG.
44
44
 
45
45
  Tea::Primitive:
46
46
  * clear()
@@ -94,7 +94,7 @@ This grab method copies a sub-section of the screen (or all of it if no argument
94
94
  Tea::ImageSaving:
95
95
  * save(path)
96
96
 
97
- The save method saves the Screen as an image file.
97
+ The save method saves the Screen as an image file. Supported formats: BMP, PNG.
98
98
 
99
99
  Tea::Primitive:
100
100
  * clear()
@@ -1,5 +1,6 @@
1
1
  # This file holds the ImageSaving mixin.
2
2
 
3
+ require 'RMagick'
3
4
  require 'sdl'
4
5
 
5
6
  require 'tea/c_error'
@@ -33,7 +34,7 @@ module Tea
33
34
  when '.bmp'
34
35
  image_saving_buffer.save_bmp(path)
35
36
  when '.png'
36
- raise Tea::Error, "PNG format not supported for saving yet", caller
37
+ image_saving_cheat_save path
37
38
  else
38
39
  raise Tea::Error, "can't determine image format '#{ext}' for saving", caller
39
40
  end
@@ -45,6 +46,25 @@ module Tea
45
46
  raise Tea::Error, e.message, e.backtrace
46
47
  end
47
48
 
49
+ private
50
+
51
+ # Cheat by using RMagick to save in formats other than BMP.
52
+ def image_saving_cheat_save(path)
53
+ buffer = image_saving_buffer
54
+
55
+ buffer_string = String.new
56
+ for y in 0...buffer.h
57
+ for x in 0...buffer.w
58
+ r, g, b, a = buffer.get_rgba(buffer[x, y])
59
+ buffer_string << r << g << b << a
60
+ end
61
+ end
62
+
63
+ image = Magick::Image.new(buffer.w, buffer.h)
64
+ image.import_pixels 0, 0, buffer.h, buffer.w, 'RGBA', buffer_string, Magick::CharPixel
65
+ image.write path
66
+ end
67
+
48
68
  end
49
69
 
50
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tung-tea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rmagick
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description: "Tea is a library for making simpler games from a simpler age. It's designed with these things in mind: - 0 is better than 1, and 1 is better than 2. - Simplicity beats speed. - Value and convenience can sometimes beat simplicity. - Procedural beats object-oriented in a dead-heat."
26
36
  email: tunginobi@gmail.com
27
37
  executables: []
@@ -81,6 +91,7 @@ files:
81
91
  - lib/tea/o_screen.rb
82
92
  has_rdoc: false
83
93
  homepage: http://github.com/tung/tea
94
+ licenses:
84
95
  post_install_message:
85
96
  rdoc_options:
86
97
  - --charset=UTF-8
@@ -98,10 +109,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
109
  - !ruby/object:Gem::Version
99
110
  version: "0"
100
111
  version:
101
- requirements: []
102
-
112
+ requirements:
113
+ - SDL, SGE
114
+ - imagemagick
103
115
  rubyforge_project:
104
- rubygems_version: 1.2.0
116
+ rubygems_version: 1.3.5
105
117
  signing_key:
106
118
  specification_version: 3
107
119
  summary: A simple game development library for Ruby.