wiretap 0.1 → 0.1.2

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.
Files changed (91) hide show
  1. data/README +2 -1
  2. data/ext/Makefile +27 -24
  3. data/ext/audio_format.cpp +10 -8
  4. data/ext/charstream.h +41 -0
  5. data/ext/extconf.rb +8 -10
  6. data/ext/frame_io.cpp +120 -0
  7. data/ext/frame_io.h +45 -0
  8. data/ext/image_format.cpp +49 -169
  9. data/ext/image_io.cpp +466 -0
  10. data/ext/image_io.h +73 -0
  11. data/ext/node.cpp +71 -48
  12. data/ext/nodeframes.cpp +36 -34
  13. data/ext/nodemetadata.cpp +21 -3
  14. data/ext/server.cpp +2 -2
  15. data/ext/serverlist.cpp +20 -8
  16. data/ext/wiretap.cpp +11 -8
  17. data/ext/wiretap.h +17 -13
  18. data/lib/wiretap.rb +65 -5
  19. data/test_new/common.rb +8 -0
  20. data/{test/wiretap-images → test_new/fixtures/img/ppm-8bit}/01.ppm +0 -0
  21. data/test_new/fixtures/raw/cube_2k_12bitP_1f/0.stoneimage +0 -0
  22. data/test_new/fixtures/raw/cube_2k_8bit_1f/0.stoneimage +0 -0
  23. data/test_new/fixtures/raw/cube_SD_10bit_5f/0.stoneimage +0 -0
  24. data/test_new/fixtures/raw/cube_SD_10bit_5f/1.stoneimage +0 -0
  25. data/test_new/fixtures/raw/cube_SD_10bit_5f/2.stoneimage +0 -0
  26. data/test_new/fixtures/raw/cube_SD_10bit_5f/3.stoneimage +0 -0
  27. data/test_new/fixtures/raw/cube_SD_10bit_5f/4.stoneimage +0 -0
  28. data/test_new/fixtures/raw/cube_SD_12bitP_5f/0.stoneimage +0 -0
  29. data/test_new/fixtures/raw/cube_SD_12bitP_5f/1.stoneimage +0 -0
  30. data/test_new/fixtures/raw/cube_SD_12bitP_5f/2.stoneimage +0 -0
  31. data/test_new/fixtures/raw/cube_SD_12bitP_5f/3.stoneimage +0 -0
  32. data/test_new/fixtures/raw/cube_SD_12bitP_5f/4.stoneimage +0 -0
  33. data/test_new/fixtures/raw/cube_SD_12bitU_5f/0.stoneimage +0 -0
  34. data/test_new/fixtures/raw/cube_SD_12bitU_5f/1.stoneimage +0 -0
  35. data/test_new/fixtures/raw/cube_SD_12bitU_5f/2.stoneimage +0 -0
  36. data/test_new/fixtures/raw/cube_SD_12bitU_5f/3.stoneimage +0 -0
  37. data/test_new/fixtures/raw/cube_SD_12bitU_5f/4.stoneimage +0 -0
  38. data/test_new/fixtures/raw/cube_SD_8bit_8f/0.stoneimage +0 -0
  39. data/test_new/fixtures/raw/cube_SD_8bit_8f/1.stoneimage +0 -0
  40. data/test_new/fixtures/raw/cube_SD_8bit_8f/2.stoneimage +0 -0
  41. data/test_new/fixtures/raw/cube_SD_8bit_8f/3.stoneimage +0 -0
  42. data/test_new/fixtures/raw/cube_SD_8bit_8f/4.stoneimage +0 -0
  43. data/test_new/fixtures/raw/cube_SD_8bit_8f/5.stoneimage +0 -0
  44. data/test_new/fixtures/raw/cube_SD_8bit_8f/6.stoneimage +0 -0
  45. data/test_new/fixtures/raw/cube_SD_8bit_8f/7.stoneimage +0 -0
  46. data/{test/wiretap-images/b1.stonesound → test_new/fixtures/raw-snd/simple.stonesound} +0 -0
  47. data/{test/wiretap-images/output.wav → test_new/fixtures/snd/simple-wave.wav} +0 -0
  48. data/test_new/test_audio_conversions.rb +28 -0
  49. data/test_new/test_image_conversions.rb +132 -0
  50. data/test_new/test_parts/connect_to_test_host.rb +27 -0
  51. data/test_new/test_parts/constants.rb +7 -0
  52. data/test_new/test_parts/create_test_project.rb +37 -0
  53. data/test_new/test_parts/raw_formats_and_uploads.rb +170 -0
  54. data/test_new/test_parts/server_list.rb +20 -0
  55. data/test_new/test_parts/simple_node_lookup_and_browsing.rb +76 -0
  56. data/test_new/test_suite.rb +70 -0
  57. data/{test/convert.rb → test_new/test_thread_worker.rb} +2 -3
  58. metadata +71 -61
  59. data/ext/bmp.cpp +0 -65
  60. data/ext/image.h +0 -27
  61. data/ext/ppm.cpp +0 -132
  62. data/ext/sgi.cpp +0 -69
  63. data/test/audio.rb +0 -27
  64. data/test/image.rb +0 -101
  65. data/test/read_frames.rb +0 -142
  66. data/test/wiretap-images/32bit.stoneimage +0 -621
  67. data/test/wiretap-images/36bit.stoneimage +0 -1036
  68. data/test/wiretap-images/48bit.stoneimage +1 -800
  69. data/test/wiretap-images/a.stoneimage +0 -0
  70. data/test/wiretap-images/a0.stoneimage +0 -0
  71. data/test/wiretap-images/a1.stoneimage +0 -0
  72. data/test/wiretap-images/a2.stoneimage +0 -0
  73. data/test/wiretap-images/a3.stoneimage +0 -0
  74. data/test/wiretap-images/a4.stoneimage +0 -0
  75. data/test/wiretap-images/importable-seq/00000001.ppm +0 -0
  76. data/test/wiretap-images/importable-seq/00000002.ppm +0 -0
  77. data/test/wiretap-images/importable-seq/00000003.ppm +0 -0
  78. data/test/wiretap-images/importable-seq/00000004.ppm +0 -0
  79. data/test/wiretap-images/importable-seq/00000005.ppm +0 -0
  80. data/test/wiretap-images/importable-seq/00000006.ppm +0 -0
  81. data/test/wiretap-images/importable-seq/00000007.ppm +0 -0
  82. data/test/wiretap-images/importable-seq/00000008.ppm +0 -0
  83. data/test/wiretap-images/importable-seq/00000009.ppm +0 -0
  84. data/test/wiretap-images/importable-seq/00000010.ppm +0 -0
  85. data/test/wiretap-images/importable-seq/00000011.ppm +0 -0
  86. data/test/wiretap-images/importable-seq/00000012.ppm +0 -0
  87. data/test/wiretap-images/monsters_001.tif +0 -0
  88. data/test/wiretap-images/monsters_002.tif +0 -0
  89. data/test/wiretap-images/monsters_003.tif +0 -0
  90. data/test/wiretap-images/output.mov +0 -0
  91. data/test/write_frames.rb +0 -82
@@ -0,0 +1,76 @@
1
+ module TestSimpleNodeLookupAndBrowsing
2
+ def test_03_simple_node_lookup_and_browsing
3
+ @root = @server.root
4
+ assert_kind_of Wiretap::Node, @root, "Root of the server should be a Wiretap::RootNode"
5
+ assert_equal @test_host + '//', @root.uri, "Root of the server should have the uri of #{@test_host}//"
6
+ assert_equal '/', @root.id, "Root of the server should have the ID of /"
7
+
8
+ assert_kind_of Wiretap::NodeChildren, @root.children, "Root should have NodeChildren as children"
9
+ assert_equal @root.children.length, @root.children.count, "NodeChildre#length should equal NodeChildren#count"
10
+ assert (@root.children.length > 0), "Root should have at least 1 node"
11
+ assert_equal @server, @root.server, "A root node should provide the handle to the server that it is attached to"
12
+
13
+ assert !@root.reel?, "Root node is not a reel"
14
+ assert !@root.library?, "Root node is not a library"
15
+ assert !@root.clip?, "Root node is not a clip"
16
+ assert !@root.project?, "Root node is not a project"
17
+ assert_nil @root.parent, "Root node should not have a parent"
18
+
19
+ assert_kind_of Wiretap::Volume, @root.children[0], "The first child should be a Volume node"
20
+ assert_kind_of Wiretap::Volume, @root[0], "The first child should be a Volume node and accessible via parent[]"
21
+
22
+ @volume = @root.children[0]
23
+ assert_equal "stonefs", @volume.name, "Most likely the first child should be called /stonefs :-)"
24
+ assert_kind_of Wiretap::Node, @volume.parent, "The parent method should return the node above this one"
25
+ assert_equal "#{@test_host}//", @volume.parent.uri, "And this should be the root node of the server"
26
+ assert_equal @server, @volume.server, "A volume should provide the handle to the server that it is attached to"
27
+
28
+ @project = @volume.children[0]
29
+ assert_kind_of Wiretap::Project, @project, "The first node of the volume should be a project"
30
+
31
+ assert_equal @project, @volume[0], "The child node shoud be accessible directly via []"
32
+ assert_kind_of Wiretap::NodeChildren, @project.children, "Project should have NodeChildren as children"
33
+
34
+ assert_kind_of String, @project.name, "The project should have a name and it should be a String"
35
+ proj_uri = "#{@test_host}//#{@volume.name}/#{@project.name}"
36
+ assert_equal proj_uri, @project.uri, "The project should have the uri #{proj_uri}"
37
+
38
+ assert_equal @project, @server.find("//#{@volume.name}/#{@project.name}"), "The server should support name-based lookup via uri"
39
+ assert_equal @project, @volume.find(@project.name), "The volume node should support name-based lookup via name"
40
+
41
+ @root_meta, @project_meta = @root.metadata, @project.meta
42
+
43
+ assert_kind_of Wiretap::NodeMetaData, @root_meta
44
+ assert_kind_of Array, @root_meta.streams
45
+ assert @root_meta.streams.empty?, "Root metadata streams are most likely empty"
46
+
47
+ assert_kind_of Wiretap::NodeMetaData, @project_meta
48
+ assert @root_meta.streams.empty?, "Project metadata streams are most likely empty (unless this is a 2007 server)"
49
+
50
+ # Now try to find a project that has some libraries
51
+ @volume.children.each do | p |
52
+ @project = p and break if p.children.any?
53
+ end
54
+
55
+ # We proceed only of this project HAS children (by occasion)
56
+ unless @project
57
+ $stderr.puts "We could not find any projects that have libraries on #{@test_host}, so the test will be skipped"
58
+ return
59
+ end
60
+
61
+ @lib = @project[0]
62
+ assert_equal @lib, @project.children[0], "node[i] and node.children[i] should return equivalent results"
63
+ assert_kind_of Wiretap::Library, @lib, "A child of a project can only be a Library"
64
+
65
+ assert @lib.library?, "Library node is a library"
66
+ assert !@lib.reel?, "Library node is not a reel"
67
+ assert !@lib.clip?, "Library node is not a clip"
68
+ assert !@lib.project?, "Library node is not a project"
69
+ assert_equal @project, @lib.parent, "Library node should have the project as parent"
70
+ assert_kind_of String, @lib.name, "Library node should have a name in a String"
71
+
72
+ return if @lib.name.empty?
73
+ assert_equal @lib, @project[0], "The library fetched by index from the project should be equivalent to the one we retrieved"
74
+ assert_equal @lib, @project[@lib.name], "The library fetched by name from the project should be equivalent to the one we retrieved"
75
+ end
76
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/common'
2
+
3
+ class RubyWiretapTest < Test::Unit::TestCase
4
+ OLD_SERVER = " This functionality is only supported in hosts running 2007."
5
+ CLIP_TYPE_METHODS = %(
6
+ node?
7
+ clip?
8
+ root?
9
+ desktop?
10
+ project?
11
+ library?
12
+ user?
13
+ audio?
14
+ hires?
15
+ lowres?
16
+ slate?
17
+ )
18
+ HAS_OPEN = (RUBY_PLATFORM =~ /darwin/i) ? true : false
19
+
20
+ modules_dir = File.dirname(__FILE__) + '/test_parts'
21
+ Dir.entries(modules_dir).grep(/\.rb$/).each do | p |
22
+ require File.join(modules_dir, p)
23
+ modname = p.gsub(/\.rb$/, '')
24
+ self.send(:include, Inflector::camelize("test_" + modname).constantize)
25
+ end
26
+
27
+ def setup
28
+ @test_host = ENV['RUBY_WIRETAP_TEST_HOST'] || 'Backdraft'
29
+ @test_project_name = ENV['RUBY_WIRETAP_TEST_PROJECT'] || "RubyWiretapTest"
30
+ @test_library = ENV['RUBY_WIRETAP_TEST_LIBRARY'] || "Default"
31
+ @test_run = ENV['RUBY_WIRETAP_TEST_RUN'] || Time.now.to_i.to_s
32
+
33
+ @server = Wiretap::Server.new(@test_host)
34
+ @volume = @server.root[0]
35
+ @deletables = []
36
+
37
+ end
38
+
39
+ def teardown
40
+ begin
41
+ @server.close! if @server
42
+ rescue Wiretap::Error # if the connecton has been closed in the test itself
43
+ end
44
+
45
+ while(elem = @deletables.pop) do
46
+ begin
47
+ # We run destroy twice here to ascertain that it does not do anything nasty
48
+ elem.destroy
49
+ elem.destroy
50
+ rescue Wiretap::Error
51
+ end
52
+ end
53
+ end
54
+
55
+ def test_07_ppm_uploads
56
+ # flunk
57
+ end
58
+
59
+ private
60
+ def open_images_in_viewer(imgs, specialty = nil)
61
+ if imgs.any?
62
+ $stderr.puts "Don't be scared - after a few seconds some images will open in your image editor. Take care to examine them
63
+ carefully - you should see a rotating color cube! #{specialty}"
64
+ sleep 5
65
+ imgs.each do | c |
66
+ `open #{c}` if HAS_OPEN
67
+ end
68
+ end
69
+ end
70
+ end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../lib/wiretap'
3
3
  require 'benchmark'
4
4
 
5
5
 
6
- class ConvertTest < Test::Unit::TestCase
6
+ class ThreadWorkerTest < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  @temp_outdir = "/tmp/wiretap_tests/thread_convert"
@@ -11,8 +11,7 @@ class ConvertTest < Test::Unit::TestCase
11
11
  `mkdir -p #{@temp_outdir} 2>/dev/null`
12
12
  end
13
13
 
14
-
15
- def test_convert
14
+ def xtest_convert
16
15
  num = 1
17
16
  iteration = 0
18
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: wiretap
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2007-01-23 00:00:00 +03:00
6
+ version: 0.1.2
7
+ date: 2007-02-01 00:00:00 +01:00
8
8
  summary: WireTap driver
9
9
  require_paths:
10
10
  - lib
11
- email: max@maxidoors.ru
11
+ email: tools@hecticelectric.nl
12
12
  homepage: http://rubyforge.org/projects/wiretap/
13
13
  rubyforge_project: wiretap
14
14
  description:
@@ -25,72 +25,82 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
- post_install_message:
29
28
  authors:
30
- - Max Lapshin
29
+ - Max Lapshin, Julik Tarkhanov, HecticElectric BV
31
30
  files:
32
- - test/audio.rb
33
- - test/convert.rb
34
- - test/image.rb
35
- - test/read_frames.rb
36
- - test/wiretap-images
37
- - test/wiretap_root
38
- - test/write_frames.rb
39
- - test/wiretap-images/01.ppm
40
- - test/wiretap-images/32bit.stoneimage
41
- - test/wiretap-images/36bit.stoneimage
42
- - test/wiretap-images/48bit.stoneimage
43
- - test/wiretap-images/a.stoneimage
44
- - test/wiretap-images/a0.stoneimage
45
- - test/wiretap-images/a1.stoneimage
46
- - test/wiretap-images/a2.stoneimage
47
- - test/wiretap-images/a3.stoneimage
48
- - test/wiretap-images/a4.stoneimage
49
- - test/wiretap-images/b1.stonesound
50
- - test/wiretap-images/importable-seq
51
- - test/wiretap-images/monsters_001.tif
52
- - test/wiretap-images/monsters_002.tif
53
- - test/wiretap-images/monsters_003.tif
54
- - test/wiretap-images/output.mov
55
- - test/wiretap-images/output.wav
56
- - test/wiretap-images/importable-seq/00000001.ppm
57
- - test/wiretap-images/importable-seq/00000002.ppm
58
- - test/wiretap-images/importable-seq/00000003.ppm
59
- - test/wiretap-images/importable-seq/00000004.ppm
60
- - test/wiretap-images/importable-seq/00000005.ppm
61
- - test/wiretap-images/importable-seq/00000006.ppm
62
- - test/wiretap-images/importable-seq/00000007.ppm
63
- - test/wiretap-images/importable-seq/00000008.ppm
64
- - test/wiretap-images/importable-seq/00000009.ppm
65
- - test/wiretap-images/importable-seq/00000010.ppm
66
- - test/wiretap-images/importable-seq/00000011.ppm
67
- - test/wiretap-images/importable-seq/00000012.ppm
68
- - test/wiretap_root/192.168.171.17
69
- - test/wiretap_root/192.168.171.208
70
- - test/wiretap_root/192.168.171.17/stonefs
71
- - test/wiretap_root/192.168.171.17/stonefs/Julik
72
- - test/wiretap_root/192.168.171.17/stonefs/Julik/Default
73
- - test/wiretap_root/192.168.171.17/stonefs/Julik/Default/freckles_8bit_snd
74
- - test/wiretap_root/192.168.171.17/stonefs/Julik/Default/toyota_10bit
75
- - test/wiretap_root/192.168.171.17/stonefs/Julik/Default/toyota_12bit
76
- - test/wiretap_root/192.168.171.17/stonefs/Julik/Default/freckles_8bit_snd/freckles_8bit_snd (audio)
77
- - test/wiretap_root/192.168.171.17/stonefs/Julik/Default/freckles_8bit_snd/freckles_8bit_snd (audio)/freckles_8bit_snd (stream)
31
+ - test_new/common.rb
32
+ - test_new/fixtures
33
+ - test_new/test_audio_conversions.rb
34
+ - test_new/test_image_conversions.rb
35
+ - test_new/test_parts
36
+ - test_new/test_suite.rb
37
+ - test_new/test_thread_worker.rb
38
+ - test_new/fixtures/img
39
+ - test_new/fixtures/raw
40
+ - test_new/fixtures/raw-snd
41
+ - test_new/fixtures/snd
42
+ - test_new/fixtures/img/ppm-8bit
43
+ - test_new/fixtures/img/sgi-16bit-rle
44
+ - test_new/fixtures/img/sgi-16bit-std
45
+ - test_new/fixtures/img/sgi-8bit-rle
46
+ - test_new/fixtures/img/sgi-8bit-std
47
+ - test_new/fixtures/img/ppm-8bit/01.ppm
48
+ - test_new/fixtures/raw/cube_2k_12bitP_1f
49
+ - test_new/fixtures/raw/cube_2k_8bit_1f
50
+ - test_new/fixtures/raw/cube_SD_10bit_5f
51
+ - test_new/fixtures/raw/cube_SD_12bitP_5f
52
+ - test_new/fixtures/raw/cube_SD_12bitU_5f
53
+ - test_new/fixtures/raw/cube_SD_8bit_8f
54
+ - test_new/fixtures/raw/cube_2k_12bitP_1f/0.stoneimage
55
+ - test_new/fixtures/raw/cube_2k_8bit_1f/0.stoneimage
56
+ - test_new/fixtures/raw/cube_SD_10bit_5f/0.stoneimage
57
+ - test_new/fixtures/raw/cube_SD_10bit_5f/1.stoneimage
58
+ - test_new/fixtures/raw/cube_SD_10bit_5f/2.stoneimage
59
+ - test_new/fixtures/raw/cube_SD_10bit_5f/3.stoneimage
60
+ - test_new/fixtures/raw/cube_SD_10bit_5f/4.stoneimage
61
+ - test_new/fixtures/raw/cube_SD_12bitP_5f/0.stoneimage
62
+ - test_new/fixtures/raw/cube_SD_12bitP_5f/1.stoneimage
63
+ - test_new/fixtures/raw/cube_SD_12bitP_5f/2.stoneimage
64
+ - test_new/fixtures/raw/cube_SD_12bitP_5f/3.stoneimage
65
+ - test_new/fixtures/raw/cube_SD_12bitP_5f/4.stoneimage
66
+ - test_new/fixtures/raw/cube_SD_12bitU_5f/0.stoneimage
67
+ - test_new/fixtures/raw/cube_SD_12bitU_5f/1.stoneimage
68
+ - test_new/fixtures/raw/cube_SD_12bitU_5f/2.stoneimage
69
+ - test_new/fixtures/raw/cube_SD_12bitU_5f/3.stoneimage
70
+ - test_new/fixtures/raw/cube_SD_12bitU_5f/4.stoneimage
71
+ - test_new/fixtures/raw/cube_SD_8bit_8f/0.stoneimage
72
+ - test_new/fixtures/raw/cube_SD_8bit_8f/1.stoneimage
73
+ - test_new/fixtures/raw/cube_SD_8bit_8f/2.stoneimage
74
+ - test_new/fixtures/raw/cube_SD_8bit_8f/3.stoneimage
75
+ - test_new/fixtures/raw/cube_SD_8bit_8f/4.stoneimage
76
+ - test_new/fixtures/raw/cube_SD_8bit_8f/5.stoneimage
77
+ - test_new/fixtures/raw/cube_SD_8bit_8f/6.stoneimage
78
+ - test_new/fixtures/raw/cube_SD_8bit_8f/7.stoneimage
79
+ - test_new/fixtures/raw-snd/simple.stonesound
80
+ - test_new/fixtures/snd/simple-wave.wav
81
+ - test_new/test_parts/connect_to_test_host.rb
82
+ - test_new/test_parts/constants.rb
83
+ - test_new/test_parts/create_test_project.rb
84
+ - test_new/test_parts/raw_formats_and_uploads.rb
85
+ - test_new/test_parts/server_list.rb
86
+ - test_new/test_parts/simple_node_lookup_and_browsing.rb
78
87
  - lib/wiretap.rb
79
88
  - ext/audio_format.cpp
80
- - ext/bmp.cpp
89
+ - ext/charstream.h
81
90
  - ext/extconf.rb
82
91
  - ext/format.cpp
83
- - ext/image.h
92
+ - ext/frame_io.cpp
93
+ - ext/frame_io.h
84
94
  - ext/image_format.cpp
95
+ - ext/image_io.cpp
96
+ - ext/image_io.h
85
97
  - ext/Makefile
86
98
  - ext/node.cpp
87
99
  - ext/nodechildren.cpp
88
100
  - ext/nodeframes.cpp
89
101
  - ext/nodemetadata.cpp
90
- - ext/ppm.cpp
91
102
  - ext/server.cpp
92
103
  - ext/serverlist.cpp
93
- - ext/sgi.cpp
94
104
  - ext/testserver
95
105
  - ext/thread_worker.cpp
96
106
  - ext/wiretap.cpp
@@ -106,11 +116,11 @@ files:
106
116
  - README
107
117
  - LICENSE
108
118
  test_files:
109
- - test/audio.rb
110
- - test/convert.rb
111
- - test/image.rb
112
- - test/read_frames.rb
113
- - test/write_frames.rb
119
+ - test_new/common.rb
120
+ - test_new/test_audio_conversions.rb
121
+ - test_new/test_image_conversions.rb
122
+ - test_new/test_suite.rb
123
+ - test_new/test_thread_worker.rb
114
124
  rdoc_options:
115
125
  - --main=README
116
126
  - --line-numbers
data/ext/bmp.cpp DELETED
@@ -1,65 +0,0 @@
1
- #include "wiretap.h"
2
- static void write_int32_le_value(int value, bitstream_writer writer, void *data) {
3
- writer(data, value >> 0 & 0xFF);
4
- writer(data, value >> 8 & 0xFF);
5
- writer(data, value >> 16& 0xFF);
6
- writer(data, value >> 24& 0xFF);
7
- }
8
-
9
- static void write_int16_le_value(short value, bitstream_writer writer, void *data) {
10
- writer(data, value >> 0 & 0xFF);
11
- writer(data, value >> 8 & 0xFF);
12
- }
13
-
14
- void write_string_value(char* value, bitstream_writer writer, void *data) {
15
- while(value && *value) {
16
- writer(data, *value);
17
- value++;
18
- }
19
- }
20
-
21
-
22
- static int wiretap_write_bmp_header(int width, int height, bitstream_writer writer, void *data) {
23
- const int header_size = 54;
24
- int size = header_size + width * height * 3;
25
- write_string_value("BM", writer, data); // 0,1
26
- write_int32_le_value(size, writer, data); // 2,3,4,5
27
- write_int32_le_value(0, writer, data); // 6,7,8,9: reserved data
28
- write_int32_le_value(header_size, writer, data); // 10,11,12,13: Image header ends.
29
- write_int32_le_value(40, writer, data); // 14,15,16,17: Image information size
30
- write_int32_le_value(width, writer, data); // 18,19,20,21: Width
31
- write_int32_le_value(height, writer, data); // 22,23,24,25: Height
32
- write_int16_le_value(1, writer, data); // 26,27: Number of color planes
33
- write_int16_le_value(24, writer, data); // 28,29: Bits per pixel. We write only 24 bit images
34
- write_int32_le_value(0, writer, data); // 30,31,32,33: Compression schema. None
35
- write_int32_le_value(width*height*3, writer, data); // 34,35,36,37: raw data size. 3 bytes per pixel.
36
- write_int32_le_value(2834, writer, data); // 38,39,40,41: horisontal resolution. Perhaprs 72 dpi. I don't know
37
- write_int32_le_value(2834, writer, data); // 42,43,44,45: vertical resolution
38
- write_int32_le_value(0, writer, data); // 46,47,48,49: number of colors
39
- write_int32_le_value(0, writer, data); // 50,51,52,53: number of important colors
40
- return 0;
41
- }
42
-
43
-
44
-
45
- bool wiretap_write_frame_bmp(int width, int height, int bpp, unsigned char* frame, FILE* f) {
46
- filestream stream;
47
- memset(&stream, 0, sizeof(stream));
48
- stream.f = f;
49
-
50
- wiretap_write_bmp_header(width, height, write_to_file, (void *)&stream);
51
- wiretap_write_image_data(width, height, bpp, frame, write_to_file_bgr, (void *)&stream);
52
-
53
- return 0;
54
- }
55
-
56
- void write_to_file_bgr(void *stream, unsigned char channel) {
57
- filestream* data = (filestream *)stream;
58
- data->buffer[2 - data->count] = channel;
59
- data->count++;
60
- if(data->count == 3) {
61
- fwrite(data->buffer, sizeof(data->buffer), 1, data->f);
62
- data->count = 0;
63
- }
64
- }
65
-
data/ext/image.h DELETED
@@ -1,27 +0,0 @@
1
- #ifndef _WIRETAP_IMAGE_H_
2
- #define _WIRETAP_IMAGE_H_
3
-
4
- typedef struct _memstream {
5
- unsigned char* ptr;
6
- } memstream;
7
- typedef struct _filestream {
8
- int count;
9
- unsigned char buffer[3];
10
- FILE* f;
11
- } filestream;
12
-
13
- void write_to_memory(void *stream, unsigned char channel);
14
- void write_to_file(void* file, unsigned char channel);
15
- void write_to_file_bgr(void* file, unsigned char channel);
16
- typedef void (*bitstream_writer)(void *data, unsigned char channel);
17
- void write_string_value(char* value, bitstream_writer writer, void *data);
18
-
19
-
20
- bool wiretap_write_frame_bmp(int width, int height, int bpp, unsigned char* frame, FILE* f);
21
- bool wiretap_write_frame_sgi(int width, int height, int bpp, unsigned char* frame, FILE* f);
22
-
23
- int wiretap_write_image_data(int width, int height, int bpp, const unsigned char* frame, bitstream_writer writer, void *data);
24
-
25
- #endif /* _WIRETAP_IMAGE_H_ */
26
-
27
-
data/ext/ppm.cpp DELETED
@@ -1,132 +0,0 @@
1
- #include "wiretap.h"
2
-
3
-
4
-
5
- static int extract_int(FILE* f) {
6
- char buffer[256];
7
- int pos = 0;
8
- char c;
9
- while(!feof(f)) {
10
- c = fgetc(f);
11
- if(!isalnum(c)) {
12
- break;
13
- }
14
- buffer[pos++] = c;
15
- }
16
- buffer[pos] = '\0';
17
- return atoi(buffer);
18
- }
19
-
20
- bool ppm_read_format(FILE* f, WireTapClipFormat* format) {
21
- extract_int(f);
22
-
23
- int width = extract_int(f);
24
- if(format) {
25
- format->setWidth(width);
26
- }
27
-
28
- int height = extract_int(f);
29
- if(format) {
30
- format->setHeight(height);
31
- }
32
-
33
- int maxval = extract_int(f);
34
- if(maxval > 255) {
35
- THROW("Decoding 16bit PPM files is not supported");
36
- }
37
-
38
- if(format) {
39
- format->setBitsPerPixel(24);
40
- format->setNumChannels(3);
41
- format->setFrameBufferSize((format->bitsPerPixel()/8)*width*height);
42
- format->setFrameRate(25);
43
- WireTapClipFormat::ScanFormat scan_format = format->strToScanFormat("progressive");
44
- format->setScanFormat(scan_format);
45
- format->setFormatTag("rgb");
46
- format->setMetaDataTag("IFFFS_XML");
47
- format->setMetaData("<IFFFS_XML Version=\"1.0\"><ClipData></ClipData></IFFFS_XML>");
48
- }
49
-
50
- return true;
51
- }
52
-
53
-
54
- bool ppm_read_image(FILE* f, unsigned char* frame, int width, int height, int bpp) {
55
- size_t row_size = width*3;
56
-
57
- for(int i = 0; i < height; i++) {
58
- size_t read_bytes = fread(frame + (height - 1 - i)*row_size, 1, row_size, f);
59
- if(read_bytes != row_size) {
60
- rb_warn("Read %d bytes, expected %d. Step: %d", read_bytes, row_size, i);
61
- return false;
62
- }
63
- }
64
-
65
- return true;
66
- }
67
-
68
-
69
- /*
70
- * Extract Wiretap clip format from PPM file. The format will inherit the bit depths of the image and allocate
71
- * the framebuffer size into which the imported image will fit
72
- *
73
- * @clipformat = Wiretap::PPM.format("test/wiretap-images/01.ppm")
74
- */
75
- static VALUE wiretap_get_ppm_format(VALUE self, VALUE input) {
76
-
77
- FILE* infile = fopen(CSTR(input), "r");
78
- if(!infile) {
79
- THROW("Couldn't open file %s for reading", CSTR(input));
80
- }
81
- WireTapClipFormat format;
82
- if(!ppm_read_format(infile, &format)) {
83
- fclose(infile);
84
- return Qfalse;
85
- }
86
- fclose(infile);
87
- VALUE clip_format = rb_funcall(cClipFormat, rb_intern("new"), 0);
88
- DATA_PTR(clip_format) = new WireTapClipFormat(format);
89
- return clip_format;
90
- }
91
-
92
- /*
93
- * Convert a PPM file to an SGI file
94
- *
95
- * Wiretap::PPM.to_sgi("test/wiretap-images/01.ppm", "/tmp/a.sgi")
96
- */
97
- static VALUE wiretap_convert_ppm_to_sgi(VALUE self, VALUE input, VALUE output) {
98
- Check_Type(input, T_STRING);
99
- Check_Type(output, T_STRING);
100
- FILE* infile = fopen(CSTR(input), "r");
101
- if(!infile) {
102
- THROW("Couldn't open file %s for read", CSTR(input));
103
- }
104
- WireTapClipFormat format;
105
- if(!ppm_read_format(infile, &format)) {
106
- fclose(infile);
107
- rb_warn("Couldn't read PPM format from file %s", CSTR(input));
108
- return Qfalse;
109
- }
110
-
111
- unsigned char frame[format.frameBufferSize()];
112
- if(!ppm_read_image(infile, frame, format.width(), format.height(), format.bitsPerPixel())) {
113
- fclose(infile);
114
- rb_warn("Couldn't read PPM image data from file %s", CSTR(input));
115
- return Qfalse;
116
- }
117
- fclose(infile);
118
-
119
- if(!wiretap_write_image_frame(format.width(), format.height(), format.bitsPerPixel(), frame, CSTR(output))) {
120
- rb_warn("Couldn't dump image to file %s", CSTR(output));
121
- return Qfalse;
122
- }
123
- return Qtrue;
124
- }
125
-
126
-
127
- void Init_ppm() {
128
- mPPM = rb_define_module_under(mWiretap, "PPM");
129
-
130
- rb_define_singleton_method(mPPM, "to_sgi", VALUEFUNC(wiretap_convert_ppm_to_sgi), 2);
131
- rb_define_singleton_method(mPPM, "format", VALUEFUNC(wiretap_get_ppm_format), 1);
132
- }
data/ext/sgi.cpp DELETED
@@ -1,69 +0,0 @@
1
- #include "wiretap.h"
2
-
3
-
4
- static void write_channel(int width, int height, int number, unsigned char* frame, FILE* f) {
5
- std::auto_ptr<unsigned char> buffer(new unsigned char[width*height]);
6
- for(int i = 0; i < width*height; i++) {
7
- buffer.get()[i] = frame[3*i + number];
8
- }
9
- fwrite(buffer.get(), width*height, 1, f);
10
- }
11
-
12
- static void write_int32_be_value(int value, bitstream_writer writer, void *data) {
13
- writer(data, value >> 24& 0xFF);
14
- writer(data, value >> 16& 0xFF);
15
- writer(data, value >> 8 & 0xFF);
16
- writer(data, value >> 0 & 0xFF);
17
- }
18
- static void write_int16_be_value(short value, bitstream_writer writer, void *data) {
19
- writer(data, value >> 8 & 0xFF);
20
- writer(data, value >> 0 & 0xFF);
21
- }
22
-
23
- static int wiretap_write_sgi_header(int width, int height, bitstream_writer writer, void *data) {
24
- //const int header_size = 512;
25
- const int header_padding = 404;
26
- const int magic = 474;
27
-
28
- write_int16_be_value(magic, writer, data); // Magic 474
29
- writer(data, 0); // 0 for uncompressed
30
- writer(data, 1); // 1 for 1 byte per channel. 24 bit picture
31
- write_int16_be_value(3, writer, data); // 3 dimensions - one plain image with multiple channels
32
- write_int16_be_value(width, writer, data);
33
- write_int16_be_value(height, writer, data);
34
- write_int16_be_value(3, writer, data); // 3 for RGB mode: 3 channels
35
- write_int32_be_value(0, writer, data); // minimum pixel value
36
- write_int32_be_value(0xFF, writer, data); // maximum pixel value
37
- write_int32_be_value(0, writer, data); // dummy
38
-
39
- char image_name[80] = "Ruby wiretap encoded";
40
- for(size_t i = 0; i < sizeof(image_name); i++) {
41
- writer(data, image_name[i]);
42
- }
43
-
44
- write_int32_be_value(0, writer, data); // colormap is in normal mode (0)
45
- for(int i = 0; i < header_padding; i++) {
46
- writer(data, 0);
47
- }
48
- return 0;
49
- }
50
-
51
-
52
- bool wiretap_write_frame_sgi(int width, int height, int bpp, unsigned char* frame, FILE* f) {
53
- filestream stream;
54
- memstream mem;
55
- std::auto_ptr<unsigned char> buffer(new unsigned char[width*height*3]);
56
- memset(&stream, 0, sizeof(stream));
57
- memset(&mem, 0, sizeof(mem));
58
- mem.ptr = buffer.get();
59
- stream.f = f;
60
-
61
- wiretap_write_sgi_header(width, height, write_to_file, (void *)&stream);
62
- wiretap_write_image_data(width, height, bpp, frame, write_to_memory, (void *)&mem);
63
-
64
- write_channel(width, height, 0, buffer.get(), f);
65
- write_channel(width, height, 1, buffer.get(), f);
66
- write_channel(width, height, 2, buffer.get(), f);
67
- return 0;
68
- }
69
-
data/test/audio.rb DELETED
@@ -1,27 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/wiretap'
3
-
4
- class AudioTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @samples = 48000
8
- @rate = 48000.0
9
- @bps = 32
10
- @temp_outdir = "/tmp/wiretap_tests"
11
- FileUtils.mkdir(@temp_outdir) rescue nil
12
- end
13
-
14
- def test_read_audio
15
- File.open(File.dirname(__FILE__) + "/wiretap-images/b1.stonesound") do |f|
16
- Wiretap.dump_audio_data(@samples, @rate, @bps, :dlaudio_float, f.read(@samples*@bps/8), "#{@temp_outdir}/b1.aiff")
17
- assert_equal "#{@temp_outdir}/b1.aiff: IFF data, AIFF audio\n", `file #{@temp_outdir}/b1.aiff`
18
- end
19
- end
20
-
21
- def test_get_format
22
- assert @format = Wiretap.audio_format(File.dirname(__FILE__) + "/wiretap-images/output.wav")
23
- assert_equal 16, @format.bps
24
- assert_equal 48000.0, @format.rate
25
- assert_equal 97280, @format.samples
26
- end
27
- end