discreet_proxy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.document +5 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +29 -0
  5. data/Rakefile +28 -0
  6. data/bin/flame_proxy_icon +30 -0
  7. data/discreet_proxy.gemspec +79 -0
  8. data/lib/discreet_proxy.rb +207 -0
  9. data/test/converted_png_proxies/Kanaty.stabilizer.p.p.png +0 -0
  10. data/test/converted_png_proxies/Medianize.stabilizer.p.p.png +0 -0
  11. data/test/converted_png_proxies/Portretten_Erasmusbrug_Pts.stabilizer.p.p.png +0 -0
  12. data/test/converted_png_proxies/Ripples.glsl.p.p.png +0 -0
  13. data/test/converted_png_proxies/Tezt_flame_5_trackers.stabilizer.p.p.png +0 -0
  14. data/test/converted_png_proxies/doberman.batch.p.p.png +0 -0
  15. data/test/converted_png_proxies/e292_v02.batch.p.p.png +0 -0
  16. data/test/converted_png_proxies/e292_v02shadow.batch.p.p.png +0 -0
  17. data/test/converted_png_proxies/spontaan.stabilizer.p.p.png +0 -0
  18. data/test/converted_png_proxies/spontaan2.stabilizer.p.p.png +0 -0
  19. data/test/converted_png_proxies/t2.batch.p.p.png +0 -0
  20. data/test/helper.rb +15 -0
  21. data/test/test_cli.rb +42 -0
  22. data/test/test_discreet_proxy.rb +90 -0
  23. data/test/test_proxies/Kanaty.stabilizer.p +0 -0
  24. data/test/test_proxies/Medianize.stabilizer.p +0 -0
  25. data/test/test_proxies/Portretten_Erasmusbrug_Pts.stabilizer.p +0 -0
  26. data/test/test_proxies/Ripples.glsl.p +0 -0
  27. data/test/test_proxies/Tezt_flame_5_trackers.stabilizer.p +0 -0
  28. data/test/test_proxies/doberman.batch.p +0 -0
  29. data/test/test_proxies/e292_v02.batch.p +0 -0
  30. data/test/test_proxies/e292_v02shadow.batch.p +0 -0
  31. data/test/test_proxies/spontaan.stabilizer.p +0 -0
  32. data/test/test_proxies/spontaan2.stabilizer.p +0 -0
  33. data/test/test_proxies/t2.batch.p +0 -0
  34. metadata +136 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "chunky_png"
4
+
5
+ group :development do
6
+ gem "rake"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "cli_test"
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Julik
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = discreet_proxy
2
+
3
+ Writes and reads Flame/Smoke proxy files (.p) using ChunkyPNG.
4
+
5
+ To read every .p file on your Flame system and write it out as a PNG preview to the /tmp
6
+
7
+ Dir.glob("/usr/discreet/project/**/*.p").each do | icon_path |
8
+ proxy = DiscreetProxy.from_file(icon_path)
9
+ dest_path = "/tmp/" + File.basename(icon_path) + ".png"
10
+ proxy.save_png(icon_path)
11
+ end
12
+
13
+ Also you can use the builtin `flame_proxy_icon` binary to convert to and from the format.
14
+
15
+ == Contributing to discreet_proxy
16
+
17
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
18
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
19
+ * Fork the project
20
+ * Start a feature/bugfix branch
21
+ * Commit and push until you are happy with your contribution
22
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
23
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2011 Julik Tarkhanov. See LICENSE.txt for
28
+ further details.
29
+
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'jeweler'
5
+ require './lib/discreet_proxy'
6
+
7
+ Jeweler::Tasks.new do |gem|
8
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
9
+ gem.version = DiscreetProxy::VERSION
10
+ gem.name = "discreet_proxy"
11
+ gem.homepage = "http://github.com/julik/discreet_proxy"
12
+ gem.license = "MIT"
13
+ gem.summary = %Q{Parses and creates Flame/Smoke .p proxy icon files}
14
+ gem.email = "me@julik.nl"
15
+ gem.authors = ["Julik Tarkhanov"]
16
+ gem.executables = ["flame_proxy_icon"]
17
+ # dependencies defined in Gemfile
18
+ end
19
+ Jeweler::RubygemsDotOrgTasks.new
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ task :default => :test
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + "/../lib/discreet_proxy"
4
+ require "optparse"
5
+
6
+ $from_png = false
7
+ $error = true
8
+ OptionParser.new do | op |
9
+ op.banner = "Usage: flame_proxy_icon --png convert_from_this_png.png"
10
+ op.on("--from-png", "Generate a .p proxy from a PNG file") { $from_png = true; $error = false}
11
+ op.on("--from-icon", "Generate a .png file from a proxy .p file") { $from_png = false; $error = false}
12
+ end.parse!
13
+
14
+ ARGV.each do | filename_to_convert |
15
+ if $from_png
16
+ destination_filename = filename_to_convert.gsub(/\.png$/, '.p')
17
+ png = ChunkyPNG::Image.from_file(filename_to_convert)
18
+ proxy = DiscreetProxy.from_png(png)
19
+ proxy.save(destination_filename)
20
+ else
21
+ destination_filename = filename_to_convert.gsub(/\.p$/, '.png')
22
+ proxy = DiscreetProxy.from_file(filename_to_convert)
23
+ proxy.save_png(destination_filename)
24
+ end
25
+ end
26
+
27
+ if $error
28
+ $stderr.puts "You need to provide the path to the file being converted. Also use the --help option."
29
+ exit(1)
30
+ end
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "discreet_proxy"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Julik Tarkhanov"]
12
+ s.date = "2011-12-10"
13
+ s.email = "me@julik.nl"
14
+ s.executables = ["flame_proxy_icon"]
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "bin/flame_proxy_icon",
26
+ "lib/discreet_proxy.rb",
27
+ "test/converted_png_proxies/Kanaty.stabilizer.p.p.png",
28
+ "test/converted_png_proxies/Medianize.stabilizer.p.p.png",
29
+ "test/converted_png_proxies/Portretten_Erasmusbrug_Pts.stabilizer.p.p.png",
30
+ "test/converted_png_proxies/Ripples.glsl.p.p.png",
31
+ "test/converted_png_proxies/Tezt_flame_5_trackers.stabilizer.p.p.png",
32
+ "test/converted_png_proxies/doberman.batch.p.p.png",
33
+ "test/converted_png_proxies/e292_v02.batch.p.p.png",
34
+ "test/converted_png_proxies/e292_v02shadow.batch.p.p.png",
35
+ "test/converted_png_proxies/spontaan.stabilizer.p.p.png",
36
+ "test/converted_png_proxies/spontaan2.stabilizer.p.p.png",
37
+ "test/converted_png_proxies/t2.batch.p.p.png",
38
+ "test/helper.rb",
39
+ "test/test_discreet_proxy.rb",
40
+ "test/test_proxies/Kanaty.stabilizer.p",
41
+ "test/test_proxies/Medianize.stabilizer.p",
42
+ "test/test_proxies/Portretten_Erasmusbrug_Pts.stabilizer.p",
43
+ "test/test_proxies/Ripples.glsl.p",
44
+ "test/test_proxies/Tezt_flame_5_trackers.stabilizer.p",
45
+ "test/test_proxies/doberman.batch.p",
46
+ "test/test_proxies/e292_v02.batch.p",
47
+ "test/test_proxies/e292_v02shadow.batch.p",
48
+ "test/test_proxies/spontaan.stabilizer.p",
49
+ "test/test_proxies/spontaan2.stabilizer.p",
50
+ "test/test_proxies/t2.batch.p"
51
+ ]
52
+ s.homepage = "http://github.com/julik/discreet_proxy"
53
+ s.licenses = ["MIT"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = "1.8.11"
56
+ s.summary = "Parses and creates Flame/Smoke .p proxy icon files"
57
+
58
+ if s.respond_to? :specification_version then
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<chunky_png>, [">= 0"])
63
+ s.add_development_dependency(%q<rake>, [">= 0"])
64
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
66
+ else
67
+ s.add_dependency(%q<chunky_png>, [">= 0"])
68
+ s.add_dependency(%q<rake>, [">= 0"])
69
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
71
+ end
72
+ else
73
+ s.add_dependency(%q<chunky_png>, [">= 0"])
74
+ s.add_dependency(%q<rake>, [">= 0"])
75
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,207 @@
1
+ require "chunky_png"
2
+
3
+ # The whole module for making and reading Flame proxy icon files
4
+ module DiscreetProxy
5
+ VERSION = "0.0.1"
6
+
7
+ # Parse a .p file and return a Proxy
8
+ def self.from_file(path)
9
+ File.open(path, "rb") {|f| from_io(f) }
10
+ end
11
+
12
+ # Creates a proxy object from a passed ChunkyPNG
13
+ def self.from_png(png)
14
+ p = Proxy.new(png.width, png.height)
15
+ (0...png.width).each do | x |
16
+ (0...png.height).each do | y |
17
+ p[x,y] = png[x,y]
18
+ end
19
+ end
20
+ p
21
+ end
22
+
23
+ # Parses out the proxy contained in the passed IO object
24
+ def self.from_io(io)
25
+ pat = "na6nnn"
26
+
27
+ magik, version_bswap, width, height, depth, _ = io.read(40).unpack(pat)
28
+ raise "The passed data did not start with the magic bytes #{MAGIC}" if magik != MAGIC
29
+
30
+ # This version check is busted for now, somehow
31
+ ver = version_bswap.reverse.unpack("e").pop
32
+ $stderr.puts "The passed version #{ver} is suspicious" if (ver - PROXY_VERSION).abs > 0.0001
33
+ raise "Unknown proxy depth #{depth}" if depth != PROXY_DEPTH
34
+
35
+ p = Proxy.new(width, height)
36
+ p.fill_pixbuf(io)
37
+ return p
38
+ end
39
+
40
+ MAGIC = 0xfaf0
41
+ PROXY_VERSION = 1.10003
42
+ PROXY_DEPTH = 130
43
+ VERSION_BSWAP = "\x00\x00?\x8C\xCC\xCD"
44
+ DEFAULT_WIDTH = 126
45
+ DEFAULT_HEIGHT = 92
46
+
47
+ # Here's what Autodesk has to say:
48
+ #
49
+ # You can use Flame to create a proxy of your effect, but if you don't have access to Flame,
50
+ # or want to create proxies programmatically, you
51
+ # can use the following header (byteswap). The standard width and height of the proxy is 126x92, and the
52
+ # file is RGB 8-bit. Save your proxy files as .p, and place them in the same folder as your .glsl and .xml
53
+ # files of the same name.
54
+ #
55
+ #typedef struct {
56
+ # unsigned short Magic;
57
+ # float Version; // 6 bytes long
58
+ # short Width;
59
+ # short Height;
60
+ # short Depth;
61
+ # float Unused [ 6 ];
62
+ #} LibraryProxyHeaderStruct;
63
+ # and this bitch is 6 bytes aligned
64
+ #
65
+ ##define MAGIC 0xfaf0
66
+ ##define PROXY_VERSION 1.1f
67
+ ##define PROXY_DEPTH 130
68
+ #
69
+ # This class represents such a proxy.
70
+ class Proxy
71
+
72
+ # Image dimensions, standard is 126x92
73
+ attr_reader :width, :height
74
+
75
+ # Array of rows with each row being an array of 3-valut RGB triplets
76
+ attr_reader :rows
77
+
78
+ def initialize(w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT)
79
+ @width, @height = w.to_i, h.to_i
80
+ # Blank out the pixel values with black
81
+ generate_black
82
+ end
83
+
84
+ def to_png
85
+ png = ChunkyPNG::Image.new(@width, @height)
86
+ png.metadata["Software"] = "Ruby DiscreetProxy converter/chunky_png"
87
+ @rows.each_with_index do | row, row_idx |
88
+ row.each_with_index do | pix, col_idx |
89
+ png[col_idx, row_idx] = pix
90
+ end
91
+ end
92
+ png
93
+ end
94
+
95
+ # Get an array of the [r,g,b] pixel values at the specific coordinate
96
+ def [](left, top)
97
+ png_color_int = @rows[top][left]
98
+ unpack_rgb(png_color_int)
99
+ end
100
+
101
+ # Set the color value at the specific coordinate. If the passed value is a single
102
+ # integer, it gets interpreted as a PNG color value. If a triplet array with three
103
+ # components is passed it's interpreted as RGB
104
+ def []=(x, y, *rgb)
105
+ color = rgb.flatten
106
+
107
+ # Check for raw pixel value
108
+ if color.length == 1 && color[0].is_a?(Numeric)
109
+ @rows[y][x] = color[0]
110
+ else
111
+ r, g, b = color.map{|e| e.to_i }
112
+ @rows[y][x] = pack_rgb(r, g ,b)
113
+ end
114
+ end
115
+
116
+ # Compose a string with the entire contents of a proxy file
117
+ def to_dotp
118
+ # Pack the header
119
+ buf = StringIO.new(0xFF.chr * 40)
120
+ byteswap_version = [PROXY_VERSION].pack("e").reverse
121
+ header = [MAGIC, VERSION_BSWAP, width, height, PROXY_DEPTH].pack("na6nnn")
122
+ buf.write(header)
123
+ buf.seek(40)
124
+
125
+ # Now... all the reverses come in reverse
126
+ @rows.reverse.each do | returning_row |
127
+ returning_row.each do | pix |
128
+ rgb = unpack_rgb(pix).pack("CCC")
129
+ buf.write(rgb)
130
+ end
131
+ # Then write the padding
132
+ buf.write(0x00.chr * row_pad)
133
+ end
134
+
135
+ buf.string
136
+ end
137
+
138
+ # Once the proxy metadata is known, this method can parse out the actual pixel data
139
+ # from the passed IO
140
+ def fill_pixbuf(io)
141
+ @rows = []
142
+
143
+ # Data comes in row per row, starting on lower left with
144
+ # the values in the row being mirrored
145
+ per_row = (@width.to_i + row_pad) * 3
146
+ total_size = (per_row * @height) + 1
147
+ # First byteswap is when reading rows. We want to read from
148
+ # the bottom, so...
149
+ blob = StringIO.new(io.read(total_size).reverse)
150
+
151
+ @height.times do
152
+ # At the end of each row (thus at the beginning byteswap),
153
+ # 2 bytes contain garbage since rows are aligned
154
+ # to start at 8-complement byte offsets. If they are not discarded this disturbs
155
+ # the RGB cadence of the other values.
156
+ skip = blob.read(row_pad)
157
+
158
+ row = []
159
+ row_data = blob.read(@width.to_i * 3)
160
+ row_data = StringIO.new(row_data.to_s)
161
+
162
+ # Read 3x8bit for each pixel
163
+ @width.times do
164
+ # And guess what - here they are reversed too! How awesome is that!
165
+ rgb = (row_data.read(3) || "AAA").unpack("CCC").reverse
166
+ row.push(pack_rgb(*rgb))
167
+ end
168
+
169
+ # Abd the row itself is reversed too
170
+ @rows.push(row.reverse)
171
+ end
172
+ end
173
+
174
+ # Save out the .p file
175
+ def save(filename)
176
+ File.open(filename, 'wb') { |io| io.write(to_dotp) }
177
+ end
178
+
179
+ # Save out the PNG version of the file
180
+ def save_png(filename)
181
+ to_png.save(filename)
182
+ end
183
+
184
+ private
185
+
186
+ # Rows start at 8-byte aligned boundaries. BUT due to the
187
+ # fact that this is a BDSM Silicon Graphics format the start of the row is END of the image.
188
+ def row_pad
189
+ @row_pad ||= ((@width * 3) % 8)
190
+ end
191
+
192
+ def pack_rgb(r,g,b)
193
+ ChunkyPNG::Color.rgb(r.to_i, g.to_i, b.to_i)
194
+ end
195
+
196
+ def unpack_rgb(rgb)
197
+ [ChunkyPNG::Color.r(rgb), ChunkyPNG::Color.g(rgb), ChunkyPNG::Color.b(rgb)]
198
+ end
199
+
200
+ def generate_black
201
+ @rows = []
202
+ row = [0] * @width
203
+ @height.times{ @rows.push(row.dup) }
204
+ end
205
+ end
206
+
207
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'discreet_proxy'
15
+
data/test/test_cli.rb ADDED
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/helper'
2
+ require "cli_test"
3
+
4
+ class CliTest < Test::Unit::TestCase
5
+ TEMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp")
6
+ BIN_P = File.expand_path(File.dirname(__FILE__) + "/../bin/flame_proxy_icon")
7
+
8
+ def setup
9
+ Dir.mkdir(TEMP_DIR) unless File.exist?(TEMP_DIR)
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm_rf(TEMP_DIR)
14
+ end
15
+
16
+ # Run the tracksperanto binary with passed options, and return [exit_code, stdout_content, stderr_content]
17
+ def cli(commandline_arguments)
18
+ CLITest.new(BIN_P).run(commandline_arguments)
19
+ end
20
+
21
+ def test_cli_with_no_args_produces_usage
22
+ status, o, e = cli('')
23
+ assert_equal 1, status
24
+ assert_match /Also use the --help option/, e
25
+ end
26
+
27
+ def test_cli_from_png
28
+ FileUtils.cp(File.dirname(__FILE__) + "/converted_png_proxies/Kanaty.stabilizer.p.p.png", TEMP_DIR)
29
+ status, o, e = cli("--from-png #{TEMP_DIR}/Kanaty.stabilizer.p.p.png")
30
+ assert status.zero?, e
31
+ assert File.exist?(TEMP_DIR + "/Kanaty.stabilizer.p.p.p")
32
+ end
33
+
34
+ def test_cli_from_p
35
+ FileUtils.cp(File.dirname(__FILE__) + "/test_proxies/Kanaty.stabilizer.p", TEMP_DIR)
36
+
37
+ status, o, e = cli("--from-icon #{TEMP_DIR}/Kanaty.stabilizer.p")
38
+ assert status.zero?, e
39
+ assert File.exist?(TEMP_DIR + "/Kanaty.stabilizer.png")
40
+ end
41
+
42
+ end
@@ -0,0 +1,90 @@
1
+ require 'helper'
2
+
3
+ class TestDiscreetProxy < Test::Unit::TestCase
4
+ def test_reading
5
+ f = DiscreetProxy.from_file(File.dirname(__FILE__) + "/test_proxies/e292_v02.batch.p")
6
+ assert_equal 126, f.width, "Width should be correct"
7
+ assert_equal 92, f.height, "Height should be correct"
8
+ end
9
+
10
+ def test_reading_from_io
11
+ chunk = File.read(File.dirname(__FILE__) + "/test_proxies/e292_v02.batch.p")
12
+ io = StringIO.new(chunk)
13
+ f = DiscreetProxy.from_io(io)
14
+ assert_equal 126, f.width, "Width should be correct"
15
+ assert_equal 92, f.height, "Height should be correct"
16
+ end
17
+
18
+ def test_to_dotp
19
+ Dir.glob(File.dirname(__FILE__) + "/test_proxies/*.p").each do | f |
20
+ proxy = DiscreetProxy.from_file(f)
21
+ repl = '/tmp/%s.p' % File.basename(f)
22
+ message = "Roundtripping #{File.basename(f)}"
23
+
24
+ pixdata = proxy.to_dotp # Package up
25
+ proxy_roundtrip = DiscreetProxy.from_io(StringIO.new(pixdata))
26
+ assert_equal proxy_roundtrip.to_png, proxy.to_png, message
27
+ end
28
+ end
29
+
30
+ def test_pixmap_values
31
+ path = File.dirname(__FILE__) + "/test_proxies/Kanaty.stabilizer.p"
32
+ proxy = DiscreetProxy.from_file(path)
33
+ assert_equal [46, 68, 69], proxy[23,78]
34
+
35
+ proxy[23,78] = [50, 50, 50]
36
+
37
+ assert_equal [50,50,50], proxy[23,78]
38
+ assert_equal [43, 67, 69], proxy[23,79], "Should not have touched the values in another row"
39
+ end
40
+
41
+ def test_initialize_default
42
+ proxy = DiscreetProxy::Proxy.new
43
+ assert_equal 126, proxy.width
44
+ assert_equal 92, proxy.height
45
+ assert_equal [0,0,0], proxy[15,18]
46
+ end
47
+
48
+ def test_to_png
49
+ Dir.glob(File.dirname(__FILE__) + "/test_proxies/*.p").each do | f |
50
+ proxy = DiscreetProxy.from_file(f)
51
+ png_path = File.dirname(__FILE__) + "/converted_png_proxies/%s.p.png" % File.basename(f)
52
+ chunky_png = proxy.to_png
53
+ assert_equal chunky_png, ChunkyPNG::Image.from_file(png_path)
54
+ end
55
+ end
56
+
57
+ def test_from_png
58
+ f = File.dirname(__FILE__) + "/converted_png_proxies/Kanaty.stabilizer.p.p.png"
59
+ png = ChunkyPNG::Image.from_file(f)
60
+ proxy = DiscreetProxy.from_png(png)
61
+ roundtrip_png = proxy.to_png
62
+
63
+ dest = '/tmp/foo_%s' % File.basename(f)
64
+ assert_equal png, roundtrip_png
65
+ end
66
+
67
+ TEST_OUTPUT = "./test.p"
68
+ TEST_PNG = "./test.png"
69
+
70
+ def unlink_testfiles
71
+ [TEST_OUTPUT, TEST_PNG].each{|f| File.unlink(f) if File.exist?(f) }
72
+ end
73
+ alias_method :setup, :unlink_testfiles
74
+ alias_method :teardown, :unlink_testfiles
75
+
76
+ def test_save
77
+ path = File.dirname(__FILE__) + "/test_proxies/Kanaty.stabilizer.p"
78
+ proxy = DiscreetProxy.from_file(path)
79
+ proxy.save(TEST_OUTPUT)
80
+ assert File.exist?(TEST_OUTPUT)
81
+ end
82
+
83
+ def test_save_png
84
+ path = File.dirname(__FILE__) + "/test_proxies/Kanaty.stabilizer.p"
85
+ proxy = DiscreetProxy.from_file(path)
86
+ proxy.save_png(TEST_PNG)
87
+ assert File.exist?(TEST_PNG)
88
+ assert_equal ChunkyPNG::Image.from_file(TEST_PNG), proxy.to_png
89
+ end
90
+ end
Binary file
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discreet_proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Julik Tarkhanov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chunky_png
16
+ requirement: &10772190 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *10772190
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &10771470 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *10771470
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &10770310 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *10770310
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &10770060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *10770060
58
+ - !ruby/object:Gem::Dependency
59
+ name: cli_test
60
+ requirement: &10769750 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *10769750
69
+ description:
70
+ email: me@julik.nl
71
+ executables:
72
+ - flame_proxy_icon
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - bin/flame_proxy_icon
84
+ - discreet_proxy.gemspec
85
+ - lib/discreet_proxy.rb
86
+ - test/converted_png_proxies/Kanaty.stabilizer.p.p.png
87
+ - test/converted_png_proxies/Medianize.stabilizer.p.p.png
88
+ - test/converted_png_proxies/Portretten_Erasmusbrug_Pts.stabilizer.p.p.png
89
+ - test/converted_png_proxies/Ripples.glsl.p.p.png
90
+ - test/converted_png_proxies/Tezt_flame_5_trackers.stabilizer.p.p.png
91
+ - test/converted_png_proxies/doberman.batch.p.p.png
92
+ - test/converted_png_proxies/e292_v02.batch.p.p.png
93
+ - test/converted_png_proxies/e292_v02shadow.batch.p.p.png
94
+ - test/converted_png_proxies/spontaan.stabilizer.p.p.png
95
+ - test/converted_png_proxies/spontaan2.stabilizer.p.p.png
96
+ - test/converted_png_proxies/t2.batch.p.p.png
97
+ - test/helper.rb
98
+ - test/test_cli.rb
99
+ - test/test_discreet_proxy.rb
100
+ - test/test_proxies/Kanaty.stabilizer.p
101
+ - test/test_proxies/Medianize.stabilizer.p
102
+ - test/test_proxies/Portretten_Erasmusbrug_Pts.stabilizer.p
103
+ - test/test_proxies/Ripples.glsl.p
104
+ - test/test_proxies/Tezt_flame_5_trackers.stabilizer.p
105
+ - test/test_proxies/doberman.batch.p
106
+ - test/test_proxies/e292_v02.batch.p
107
+ - test/test_proxies/e292_v02shadow.batch.p
108
+ - test/test_proxies/spontaan.stabilizer.p
109
+ - test/test_proxies/spontaan2.stabilizer.p
110
+ - test/test_proxies/t2.batch.p
111
+ homepage: http://github.com/julik/discreet_proxy
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 1.8.11
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Parses and creates Flame/Smoke .p proxy icon files
136
+ test_files: []