bmp-ruby 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f471d18434ce2bcf8ddc91d2c06608ffff00656
4
+ data.tar.gz: b8ddaeeb73383c30990c1aba1e431f5e9a7d3a33
5
+ SHA512:
6
+ metadata.gz: 65bb05b179b99daf7e5af258776259af10d3fa695d7c624ed5a3674ac625cad4a1e91541b45fb0c2842c7607505c9659b119e08382c53331a73a6409327cde4a
7
+ data.tar.gz: 97537636228b4714a5678f2f07b2137c15c10fb5cb7e2493f16f7219c4cbde18418fac1a7a85919fc80a8871558d9bee4de53a191e7801a6d0154138e253ca7c
@@ -0,0 +1,25 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.testlib = "minitest/unit"
7
+ #
8
+ # at.extra_files << "../some/external/dependency.rb"
9
+ #
10
+ # at.libs << ":../some/external"
11
+ #
12
+ # at.add_exception "vendor"
13
+ #
14
+ # at.add_mapping(/dependency.rb/) do |f, _|
15
+ # at.files_matching(/test_.*rb$/)
16
+ # end
17
+ #
18
+ # %w(TestA TestB).each do |klass|
19
+ # at.extra_class_map[klass] = "test/test_misc.rb"
20
+ # end
21
+ # end
22
+
23
+ # Autotest.add_hook :run_command do |at|
24
+ # system "rake build"
25
+ # end
@@ -0,0 +1,54 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ .DS_Store
53
+ *.swp
54
+ *.swo
@@ -0,0 +1,10 @@
1
+ svelte/*
2
+ .git/*
3
+
4
+ *.swp
5
+ .*.swp
6
+ **/*.swp
7
+ **/.*.swp
8
+
9
+ .DS_Store
10
+ **/.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ # -*- ruby -*-
2
+
3
+ # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
+
5
+ source "https://rubygems.org/"
6
+
7
+ gem "chunky_png", "1.3.8"
8
+ gem "bit-struct", "0.15.0"
9
+
10
+ gem "minitest", "~>5.10", :group => [:development, :test]
11
+ gem "hoe-yard", ">=0.1.3", :group => [:development, :test]
12
+ gem "hoe-ignore", "~>1.0", :group => [:development, :test]
13
+ gem "hoe-bundler", "~>1.2", :group => [:development, :test]
14
+ gem "hoe-gemspec", "~>1.0", :group => [:development, :test]
15
+ gem "hoe-git", "~>1.6", :group => [:development, :test]
16
+ gem "yard", "~>0.8", :group => [:development, :test]
17
+ gem "redcarpet", "~>3.3", :group => [:development, :test]
18
+ gem "hoe", "~>3.16", :group => [:development, :test]
19
+
20
+ # vim: syntax=ruby
@@ -0,0 +1,6 @@
1
+ === 0.0.1 / 2017-03-31
2
+
3
+ * It's alive!
4
+
5
+ * Bornday!
6
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Bordee Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ .autotest
2
+ .gitignore
3
+ .hoeignore
4
+ Gemfile
5
+ History.txt
6
+ LICENSE
7
+ Manifest.txt
8
+ README.md
9
+ Rakefile
10
+ bin/bmp
11
+ lib/bmp.rb
12
+ lib/bmp/obj.rb
13
+ lib/bmp/utils.rb
14
+ lib/bmp/version.rb
15
+ lib/core_ext/array/extract_options.rb
16
+ lib/tasks/bmp.rake
17
+ test/files/input/YVES-framework-opaque-16.png
18
+ test/files/input/YVES-framework-opaque-256.png
19
+ test/files/input/YVES-framework-transparent-16.png
20
+ test/files/input/YVES-framework-transparent-256.png
21
+ test/files/output/.keep
22
+ test/test_bmp.rb
@@ -0,0 +1,134 @@
1
+ # BMP
2
+
3
+ Bitmap generator (bitmap as in BMP image, not bitmap bitset)
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ require 'bmp'
9
+
10
+ # (soon)
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ Command Line
16
+
17
+ ```
18
+ gem install bmp-ruby
19
+ ```
20
+
21
+ Gemfile
22
+
23
+ ```
24
+ gem "bmp-ruby", "~>0.1"
25
+ ```
26
+
27
+ ## Development
28
+
29
+ (soon)
30
+
31
+ ### BMP File Format
32
+
33
+ Adapted from: https://en.wikipedia.org/wiki/BMP_file_format
34
+
35
+ Attribute |Hex Offset |Dec Offset |Size |Hex Value |Value |Description
36
+ ----------------------|-----------|-----------|-----|-------------|-----------------------|-----------
37
+ BMP Header | | | | | |
38
+ signature |0h |0 |2 |42 4D |"BM" |ID field (42h, 4Dh)
39
+ file_size |2h |2 |4 |9A 00 00 00 |154 bytes (122+32) |Size of the BMP file
40
+ reserved_1 |6h |6 |2 |00 00 |Unused |Application specific
41
+ reserved_2 |8h |8 |2 |00 00 |Unused |Application specific
42
+ file_offset |Ah |10 |4 |7A 00 00 00 |122 bytes (14+108). |Offset where the pixel array (bitmap data) can be found
43
+ DIB Header | | | | | |
44
+ dib_header_size |Eh |14 |4 |6C 00 00 00 |108 bytes |Number of bytes in the DIB header (from this point)
45
+ image_width |12h |18 |4 |04 00 00 00 |4 pixels |(left to right order) Width of the bitmap in pixels
46
+ image_height |16h |22 |4 |02 00 00 00 |2 pixels |(bottom to top order) Height of the bitmap in pixels
47
+ planes |1Ah |26 |2 |01 00 |1 plane |Number of color planes being used
48
+ bits_per_pixel |1Ch |28 |2 |20 00 |32 bits |Number of bits per pixel
49
+ compression |1Eh |30 |4 |03 00 00 00 |3 |BI_BITFIELDS, no pixel array compression used
50
+ image_size |22h |34 |4 |20 00 00 00 |32 bytes |Size of the raw bitmap data (including padding)
51
+ x_pixels_per_meter |26h |38 |4 |13 0B 00 00 |2835 px/meter horiz. |Print resolution of the image, 72 DPI × 39.3701 inches per meter yields 2834.6472
52
+ y_pixels_per_meter |2Ah |42 |4 |13 0B 00 00 |2835 px/meter vertical |Print resolution of the image, 72 DPI × 39.3701 inches per meter yields 2834.6472
53
+ number_of_colors |2Eh |46 |4 |00 00 00 00 |0 colors |Number of colors in the palette
54
+ important_colors |32h |50 |4 |00 00 00 00 |0 important colors |0 means all colors are important
55
+ red_channel_bitmask |36h |54 |4 |00 00 FF 00 |00FF0000 in big-endian |Red channel bit mask (valid because BI_BITFIELDS is specified)
56
+ green_channel_bitmask |3Ah |58 |4 |00 FF 00 00 |0000FF00 in big-endian |Green channel bit mask (valid because BI_BITFIELDS is specified)
57
+ blue_channel_bitmask |3Eh |62 |4 |FF 00 00 00 |000000FF in big-endian |Blue channel bit mask (valid because BI_BITFIELDS is specified)
58
+ alpha_channel_bitmask |42h |66 |4 |00 00 00 FF |FF000000 in big-endian |Alpha channel bit mask
59
+ color_space_type |46h |70 |4 |20 6E 69 57 |little-endian "Win " |LCS_WINDOWS_COLOR_SPACE
60
+ color_space_endpoints |4Ah |74 |36 |00 00 00 00\n00 00 00 00\n00 00 00 00\n00 00 00 00\n00 00 00 00\n00 00 00 00\n00 00 00 00\n00 00 00 00|CIEXYZTRIPLE Color Space endpoints |Unused for LCS "Win " or "sRGB"
61
+ red_gamma |6Eh |110 |4 |00 00 00 00 |0 Red Gamma |Unused for LCS "Win " or "sRGB"
62
+ green_gamma |72h |114 |4 |00 00 00 00 |0 Green Gamma |Unused for LCS "Win " or "sRGB"
63
+ blue_gamma |76h |118 |4 |00 00 00 00 |0 Blue Gamma |Unused for LCS "Win " or "sRGB"
64
+
65
+ ### Dev Requirements
66
+
67
+ * [hoe](https://github.com/seattlerb/hoe) gem manager
68
+ * [hoe-bundler] may need `gem install hoe-bundler` installation before using `rake bundler:gemfile`
69
+ * [YARD](http://yardoc.org) docs
70
+ * [redcarpet](https://github.com/vmg/redcarpet) for yardoc
71
+
72
+ [hoe-bundler]: https://github.com/flavorjones/hoe-bundler
73
+
74
+ ### Testing
75
+
76
+ Tests written with [minitest]
77
+
78
+ ```
79
+ rake test
80
+ ```
81
+
82
+ [minitest]: https://github.com/seattlerb/minitest
83
+
84
+ ### Contributing
85
+
86
+ Send tested code.
87
+ Thank you, [contributors]!
88
+
89
+ [contributors]: https://github.com/bordeeinc/bmp-ruby/graphs/contributors
90
+
91
+ ### To Do
92
+
93
+ * (soon)
94
+
95
+ ## License
96
+
97
+ MIT License
98
+
99
+ Copyright (c) 2017 Bordee Inc.
100
+
101
+ Permission is hereby granted, free of charge, to any person obtaining
102
+ a copy of this software and associated documentation files (the
103
+ 'Software'), to deal in the Software without restriction, including
104
+ without limitation the rights to use, copy, modify, merge, publish,
105
+ distribute, sublicense, and/or sell copies of the Software, and to
106
+ permit persons to whom the Software is furnished to do so, subject to
107
+ the following conditions:
108
+
109
+ The above copyright notice and this permission notice shall be
110
+ included in all copies or substantial portions of the Software.
111
+
112
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
113
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
114
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
115
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
116
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
117
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
118
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
119
+
120
+ ## About
121
+
122
+ ![bordee](http://bordee.com/src/img/surf-with-bordee-github.png)
123
+
124
+ BMP is maintained and funded by Bordee Inc.
125
+ The names and logos for Bordee are trademarks of [Bordee Inc.][bordeeinc]
126
+
127
+ [bordeeinc]: http://bordee.com
128
+
129
+ We love open source software!
130
+ See [our other projects][bordee-github]
131
+ and [check out Seattle.rb!][community]
132
+
133
+ [bordee-github]: https://github.com/bordeeinc
134
+ [community]: https://seattlerb.org
@@ -0,0 +1,66 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+ require './lib/bmp/version.rb'
6
+
7
+ Hoe.plugin :gemspec
8
+ Hoe.plugin :minitest
9
+ Hoe.plugin :yard
10
+ Hoe.plugin :bundler
11
+ Hoe.plugin :git
12
+ Hoe.plugin :ignore
13
+
14
+ Hoe.spec "bmp" do
15
+ developer("So Awesome Man", "callme@1800aweso.me")
16
+
17
+ license "MIT" # this matches the license in the README
18
+
19
+ self.email = 'support@bordee.com'
20
+
21
+ self.name = 'bmp-ruby'
22
+ self.version = BMP::VERSION
23
+ self.summary = 'Bitmap generator (bitmap as in BMP image, not bitmap bitset)'
24
+ self.description = self.summary
25
+ self.urls = ['https://github.com/bordeeinc/bmp-ruby']
26
+ self.testlib = :minitest
27
+ self.readme_file = 'README.md'
28
+ self.history_file = 'History.txt'
29
+
30
+ # third-party
31
+ self.yard_title = self.name
32
+ self.yard_markup = 'markdown'
33
+
34
+ self.extra_deps += [
35
+ ['chunky_png', '1.3.8'],
36
+ ['bit-struct', '0.15.0']
37
+ ]
38
+
39
+ self.extra_dev_deps += [
40
+ ["hoe-yard", "~> 0.1"],
41
+ ["hoe-ignore", "~> 1.0"],
42
+ ["hoe-bundler", "~> 1.2"],
43
+ ["hoe-gemspec", "~> 1.0"],
44
+ ["hoe-git", "~> 1.6"],
45
+ ["minitest", "~> 5.9"],
46
+ ["yard", "~> 0.8"],
47
+ ["redcarpet", "~> 3.3"] # yard/markdown
48
+ ]
49
+
50
+ self.clean_globs += [
51
+ '.yardoc',
52
+ 'vendor',
53
+ 'Gemfile.lock',
54
+ '.bundle',
55
+ ]
56
+
57
+ self.spec_extras = {
58
+ :required_ruby_version => '>= 1.9.2'
59
+ }
60
+ end
61
+
62
+ # require rake tasks
63
+ current_dir = File.expand_path(File.dirname(__FILE__))
64
+ Dir.glob(File.join(current_dir, 'lib/tasks/*.rake')).each {|r| import r}
65
+
66
+ # vim: syntax=ruby
data/bin/bmp ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
+ require 'ico'
7
+
8
+ help =<<-EOS.gsub(/^\s*\|/, '').chomp
9
+ |
10
+ |ico-ruby
11
+ |----------------------------------------------
12
+ | Ruby Gem wrapper for the to-ico Node Package
13
+ | Gem #{Ico::VERSION}
14
+ | JS #{Ico::VERSION_JS}
15
+ EOS
16
+
17
+
18
+ ARGV << '-h' if ARGV.empty?
19
+ options = {}
20
+
21
+ parser = OptionParser.new do |opts|
22
+ opts.banner = help + "\n\n usage: ico [options]"
23
+
24
+ opts.on('-s', '--size size', 'Size') do |format|
25
+ options[:size] = size;
26
+ end
27
+
28
+ opts.on('-i', '--input input', 'Input') do |input|
29
+ options[:input] = input;
30
+ end
31
+
32
+ opts.on('-o', '--output output', 'Output') do |output|
33
+ options[:output] = output;
34
+ end
35
+
36
+ opts.on_tail("-h", "--help", "Show this message") do
37
+ puts opts
38
+ puts
39
+ puts
40
+ exit
41
+ end
42
+ end
43
+
44
+ parser.parse!
45
+
46
+ p options
@@ -0,0 +1,45 @@
1
+ require 'core_ext/array/extract_options.rb' unless Array.method_defined?(:extract_options!)
2
+ require 'bit-struct'
3
+ require 'chunky_png'
4
+
5
+ require 'bmp/version'
6
+ require 'bmp/utils'
7
+ require 'bmp/obj'
8
+
9
+ module BMP
10
+ HEADER_SIZE = 54
11
+ BITS_PER_PIXEL = 32
12
+
13
+ # make all methods class-methods
14
+ extend self
15
+
16
+ # PNG to BMP
17
+ #
18
+ # @param input_filename [String] "/path/to/example.png"
19
+ # @param output_filename [String] "/path/to/example_generated.bmp"
20
+ # @return [void]
21
+ #
22
+ def png_to_bmp(input_filename, output_filename)
23
+ bmp = BMP.new(input_filename)
24
+
25
+ IO.write(output_filename, bmp)
26
+ end
27
+
28
+ #
29
+ # @param input_filename [PNG] including path
30
+ # @return [BitStruct]
31
+ #
32
+ def new(input_filename)
33
+ img = ChunkyPNG::Image.from_file(input_filename)
34
+ img_hash = BMP::Utils.parse_image(img)
35
+
36
+ bmp = BMP::Obj.new
37
+ bmp.file_size = img_hash[:file_size]
38
+ bmp.image_size = img_hash[:image_size]
39
+ bmp.image_width = img_hash[:image_width]
40
+ bmp.image_height = img_hash[:image_height]
41
+ bmp.pixel_array = img_hash[:pixel_array]
42
+
43
+ bmp
44
+ end
45
+ end
@@ -0,0 +1,72 @@
1
+ module BMP
2
+ class Obj < BitStruct
3
+ default_options :endian => :little
4
+
5
+ #
6
+ # BMP Header
7
+ #
8
+ char :signature, 16, 'ID field ["BM" (42h, 4Dh)]', :default => 'BM'
9
+ unsigned :file_size, 32, 'Size of the BMP file [(122+N) bytes]'
10
+ unsigned :reserved_1, 16, 'Application specific [unused]', :default => 0
11
+ unsigned :reserved_2, 16, 'Application specific [unused]', :default => 0
12
+
13
+ # Wikipedia:
14
+ #unsigned :file_offset, 32, 'Offset where the pixel array (bitmap data) can be ' +
15
+ # 'found [122 bytes (14+108)]', :default => 122
16
+ # IRL:
17
+ unsigned :file_offset, 32, 'Offset where the pixel array (bitmap data) can be ' +
18
+ 'found [54 bytes (14+40)]', :default => 54
19
+
20
+ #
21
+ # DIB Header
22
+ #
23
+ # Wikipedia:
24
+ #unsigned :dib_header_size, 32, 'Number of bytes in the DIB header (from this point) ' +
25
+ # '[108 bytes]', :default => 108
26
+ # IRL:
27
+ unsigned :dib_header_size, 32, 'Number of bytes in the DIB header (from this point) ' +
28
+ '[40 bytes]', :default => 40
29
+
30
+ unsigned :image_width, 32, 'Width of the bitmap in pixels (left to right order) ' +
31
+ '[pixels]'
32
+ unsigned :image_height, 32, 'Height of the bitmap in pixels (bottom to top order) ' +
33
+ '[pixels]'
34
+ unsigned :planes, 16, 'Number of color planes being used [1 plane]', :default => 1
35
+ unsigned :bits_per_pixel, 16, 'Number of bits per pixel [32 bits]', :default => 32
36
+
37
+ # Wikipedia:
38
+ #unsigned :compression, 32, 'BI_BITFIELDS, no pixel array compression used [3]', :default => 3
39
+ # IRL:
40
+ unsigned :compression, 32, 'BI_BITFIELDS, no pixel array compression used [3]', :default => 0
41
+
42
+ unsigned :image_size, 32, 'Size of the raw bitmap data (including padding)'
43
+ unsigned :x_pixels_per_meter, 32, 'Print resolution of the image, 72 DPI × 39.3701 ' +
44
+ 'inches per meter yields 2834.6472 [2835 pixel/meter ' +
45
+ 'horizontal]', :default => 2835
46
+ unsigned :y_pixels_per_meter, 32, 'Print resolution of the image, 72 DPI × 39.3701 ' +
47
+ 'inches per meter yields 2834.6472 [2835 pixel/meter ' +
48
+ 'horizontal]', :default => 2835
49
+ unsigned :number_of_colors, 32, 'Number of colors in the palette [0 colors]', :default => 0
50
+ unsigned :important_colors, 32, '0 means all colors are important [0]', :default => 0
51
+
52
+ # Wikipedia:
53
+ #hex_octets :red_bitmask, 32, 'Red channel bit mask (valid because BI_BITFIELDS ' +
54
+ # 'is specified) [00FF0000 in big-endian]', :default => "00:00:FF:00", :endian => :big
55
+ #hex_octets :geen_bitmask, 32, 'Green channel bit mask (valid because BI_BITFIELDS ' +
56
+ # 'is specified) [0000FF00 in big-endian]', :default => "00:FF:00:00", :endian => :big
57
+ #hex_octets :blue_bitmask, 32, 'Blue channel bit mask (valid because BI_BITFIELDS ' +
58
+ # 'is specified) [000000FF in big-endian]', :default => "FF:00:00:00", :endian => :big
59
+ #hex_octets :alpha_bitmask, 32, 'Alpha channel bit mask [FF000000 in big-endian]', :default => "00:00:00:FF", :endian => :big
60
+ #char :color_space, 32, 'LCS_WINDOWS_COLOR_SPACE [little-endian "Win "]', :default => 'Win '
61
+ #unsigned :cs_endpoints, 288, 'CIEXYZTRIPLE Color Space endpoints [unused for LCS ' +
62
+ # '"Win " or "sRGB"]', :default => 0
63
+ #unsigned :red_gamma, 32, 'Red Gamma - Unused for LCS "Win " or "sRGB"', :default => 0
64
+ #unsigned :green_gamma, 32, 'Green Gamma - Unused for LCS "Win " or "sRGB"', :default => 0
65
+ #unsigned :blue_gamma, 32, 'Blue Gamma - Unused for LCS "Win " or "sRGB"', :default => 0
66
+ # IRL:
67
+ #nil
68
+
69
+ rest :pixel_array, 'Image Data'
70
+ note ' rest is application defined image data'
71
+ end
72
+ end
@@ -0,0 +1,73 @@
1
+ module BMP
2
+ module Utils
3
+
4
+ extend self
5
+
6
+ # @return [Integer]
7
+ def calc_image_data_size(arg_width, arg_height)
8
+ ((BMP::BITS_PER_PIXEL * arg_width ) / 32.0).ceil * 4 * arg_height
9
+ end
10
+
11
+ def int_to_octets_string_endian_little(int)
12
+ [int].pack("V").each_byte.map {|b| b.to_s(16).rjust(2, '0')}.join(':')
13
+ end
14
+
15
+ def octets_string_endian_little_to_int(octets_str)
16
+ octets_str.split(':').map {|o| o.to_i(16).chr}.join.unpack('V').first
17
+ end
18
+
19
+ # @return [Integer]
20
+ def calc_file_size(img_size, header_size=BMP::HEADER_SIZE)
21
+ img_size + header_size
22
+ end
23
+
24
+ def pixel_array_template(arg_width, arg_height)
25
+ Array.new(arg_height) {Array.new(arg_width) {nil}}
26
+ end
27
+
28
+ def write_pixel_array(img_px)
29
+ str = ''
30
+
31
+ img_px.reverse_each do |row|
32
+ row.each do |color|
33
+ str << pixel_binstring(color)
34
+ end
35
+ end
36
+
37
+ return str
38
+ end
39
+
40
+ def pixel_binstring(rgba_string)
41
+ raise ArgumentError unless rgba_string =~ /\A\h{8}\z/
42
+ [rgba_string].pack("H*")
43
+ end
44
+
45
+ def parse_image(img_in)
46
+ img_width = img_in.width
47
+ img_height = img_in.height
48
+ img_data_size = calc_image_data_size(img_width, img_height)
49
+ img_file_size = calc_file_size(img_data_size)
50
+ img_pixels = pixel_array_template(img_width, img_height)
51
+
52
+ img_height.times do |row|
53
+ img_width.times do |col|
54
+ rgba = ChunkyPNG::Color.to_hex(img_in.get_pixel(row,col), true)[1..-1]
55
+ rr, gg, bb, aa = rgba.scan(/../)
56
+ img_pixels[col][row] = [bb,gg,rr,aa].join
57
+
58
+ #puts row.to_s + ',' + col.to_s + ' => ' + rgba.inspect if @debug
59
+ end
60
+ end
61
+
62
+ hash = {}
63
+ hash[:file_size] = img_file_size
64
+ hash[:image_size] = img_data_size
65
+ hash[:image_width] = img_width
66
+ hash[:image_height] = img_height
67
+ hash[:pixel_array] = write_pixel_array(img_pixels)
68
+
69
+ hash
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module BMP
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,31 @@
1
+ # @note copied from the main Rails repo instead of adding via active_support
2
+ # @see https://github.com/rails/rails/blob/794a70f94485fb64ed1c49ba8532895306e2001c/activesupport/lib/active_support/core_ext/array/extract_options.rb
3
+ class Hash
4
+ # By default, only instances of Hash itself are extractable.
5
+ # Subclasses of Hash may implement this method and return
6
+ # true to declare themselves as extractable. If a Hash
7
+ # is extractable, Array#extract_options! pops it from
8
+ # the Array when it is the last element of the Array.
9
+ def extractable_options?
10
+ instance_of?(Hash)
11
+ end
12
+ end
13
+
14
+ class Array
15
+ # Extracts options from a set of arguments. Removes and returns the last
16
+ # element in the array if it's a hash, otherwise returns a blank hash.
17
+ #
18
+ # def options(*args)
19
+ # args.extract_options!
20
+ # end
21
+ #
22
+ # options(1, 2) # => {}
23
+ # options(1, 2, a: :b) # => {:a=>:b}
24
+ def extract_options!
25
+ if last.is_a?(Hash) && last.extractable_options?
26
+ pop
27
+ else
28
+ {}
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ #require 'FileUtils' unless Object.const_defined?('FileUtils')
2
+ #
3
+ ## in lib/tasks/bmp.rake
4
+ #CURRENT_DIR = File.expand_path(File.dirname(__FILE__))
5
+ #LIB_DIR = File.join(CURRENT_DIR, '..')
6
+ #
7
+ #namespace :bmp do
8
+ #
9
+ #end
File without changes
@@ -0,0 +1,85 @@
1
+ gem "minitest"
2
+ require 'minitest/spec'
3
+ require "minitest/autorun"
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require "bmp"
6
+ #require 'FileUtils' unless Object.const_defined?('FileUtils')
7
+
8
+ def clear_dir_except_dot_keep(dir)
9
+ dir_glob = Dir.glob(File.join(dir, '*'))
10
+
11
+ FileUtils.rm_rf(dir_glob)
12
+ end
13
+
14
+ def ensure_dir_keep(dir)
15
+ FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
16
+ dir_keep = File.join(dir, '.keep')
17
+ FileUtils.touch(dir_keep) unless File.exist?(dir_keep)
18
+ end
19
+
20
+ def reset_dir(dir)
21
+ clear_dir_except_dot_keep(dir)
22
+ ensure_dir_keep(dir)
23
+ end
24
+
25
+ class TestBMP < Minitest::Test
26
+ def setup
27
+ @files = File.join(File.expand_path(File.dirname(__FILE__)), "files")
28
+ @input_dir = File.join(@files, 'input')
29
+ @output_dir = File.join(@files, 'output')
30
+
31
+ reset_dir(@output_dir)
32
+ end
33
+
34
+ def teardown
35
+ reset_dir(@output_dir)
36
+ end
37
+
38
+ def test_png_to_bmp_transparent_16
39
+ input_filename = File.join(@input_dir, 'YVES-framework-transparent-16.png')
40
+ output_filename = File.join(@output_dir, 'YVES-framework-transparent-16.bmp')
41
+
42
+ assert File.exist?(input_filename)
43
+ refute File.exist?(output_filename)
44
+
45
+ BMP.png_to_bmp(input_filename, output_filename)
46
+
47
+ assert File.exist?(output_filename)
48
+ end
49
+
50
+ def test_png_to_bmp_transparent_256
51
+ input_filename = File.join(@input_dir, 'YVES-framework-transparent-256.png')
52
+ output_filename = File.join(@output_dir, 'YVES-framework-transparent-256.bmp')
53
+
54
+ assert File.exist?(input_filename)
55
+ refute File.exist?(output_filename)
56
+
57
+ BMP.png_to_bmp(input_filename, output_filename)
58
+
59
+ assert File.exist?(output_filename)
60
+ end
61
+
62
+ def test_png_to_bmp_opaque_16
63
+ input_filename = File.join(@input_dir, 'YVES-framework-opaque-16.png')
64
+ output_filename = File.join(@output_dir, 'YVES-framework-opaque-16.bmp')
65
+
66
+ assert File.exist?(input_filename)
67
+ refute File.exist?(output_filename)
68
+
69
+ BMP.png_to_bmp(input_filename, output_filename)
70
+
71
+ assert File.exist?(output_filename)
72
+ end
73
+
74
+ def test_png_to_bmp_opaque_256
75
+ input_filename = File.join(@input_dir, 'YVES-framework-opaque-256.png')
76
+ output_filename = File.join(@output_dir, 'YVES-framework-opaque-256.bmp')
77
+
78
+ assert File.exist?(input_filename)
79
+ refute File.exist?(output_filename)
80
+
81
+ BMP.png_to_bmp(input_filename, output_filename)
82
+
83
+ assert File.exist?(output_filename)
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bmp-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - So Awesome Man
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chunky_png
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: bit-struct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.15.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.15.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe-yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: hoe-ignore
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hoe-bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hoe-gemspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hoe-git
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: redcarpet
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: hoe
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.16'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.16'
167
+ description: Bitmap generator (bitmap as in BMP image, not bitmap bitset)
168
+ email: support@bordee.com
169
+ executables:
170
+ - bmp
171
+ extensions: []
172
+ extra_rdoc_files:
173
+ - History.txt
174
+ - Manifest.txt
175
+ - README.md
176
+ files:
177
+ - ".autotest"
178
+ - ".gitignore"
179
+ - ".hoeignore"
180
+ - Gemfile
181
+ - History.txt
182
+ - LICENSE
183
+ - Manifest.txt
184
+ - README.md
185
+ - Rakefile
186
+ - bin/bmp
187
+ - lib/bmp.rb
188
+ - lib/bmp/obj.rb
189
+ - lib/bmp/utils.rb
190
+ - lib/bmp/version.rb
191
+ - lib/core_ext/array/extract_options.rb
192
+ - lib/tasks/bmp.rake
193
+ - test/files/input/YVES-framework-opaque-16.png
194
+ - test/files/input/YVES-framework-opaque-256.png
195
+ - test/files/input/YVES-framework-transparent-16.png
196
+ - test/files/input/YVES-framework-transparent-256.png
197
+ - test/files/output/.keep
198
+ - test/test_bmp.rb
199
+ homepage: https://github.com/bordeeinc/bmp-ruby
200
+ licenses:
201
+ - MIT
202
+ metadata: {}
203
+ post_install_message:
204
+ rdoc_options:
205
+ - "--title"
206
+ - bmp-ruby
207
+ - "--markup"
208
+ - markdown
209
+ - "--quiet"
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: 1.9.2
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 2.2.5
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: Bitmap generator (bitmap as in BMP image, not bitmap bitset)
228
+ test_files: []