simple_bmp 0.2.4 → 0.2.5

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/simple_bmp.rb +29 -7
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d90d75b6ec1571cd0aa6d6d07e6ad2972564fa2
4
- data.tar.gz: 39a0f5d31d5d4cca1365ab592d4d90a2ee7eab1b
3
+ metadata.gz: 37722a69af8145a85114c926dc981231cad3c9dc
4
+ data.tar.gz: 08ccd9a83563014ae0330fb7518949855cff07a8
5
5
  SHA512:
6
- metadata.gz: 6233ec72c8fc2677c092d531733d0d6edf07b221ba310318cf741985490426167f6de16dbd4be3f96a01cc6609b20bdba1ba0ff0aefa58fe0d8e592a25972211
7
- data.tar.gz: c92b8b2d761bc83cb8670e7505e064b6ad1872b6b19b5d0cf84944b2849628e6740d63abd6e81e3eda695c670d576767ad8314ea436799aab49ffbb497b41c23
6
+ metadata.gz: a9ec30589d438a3767f4651aa91e54113c976ed811afea70699c48c66c601c1c26c050216fffc30b27fd1291d0ffa430c1f35f79e9661da736b186b5d3819714
7
+ data.tar.gz: d75387064acdf5e96b19c7ff44f58c1132b6d8665b208f8cc04d1be6d5eb7ceaedd00e1d7b397181c65e6b45161d815c261f6b9014ad75edcb2e75022c890834
@@ -1,5 +1,7 @@
1
1
  # Currently there are no need of classes -- just a single public module method.
2
- # We use only BITMAPCOREHEADER[http://en.wikipedia.org/wiki/BMP_file_format] (12 bytes), because it's enough.
2
+ # Export only to BITMAPCOREHEADER[http://en.wikipedia.org/wiki/BMP_file_format] (12 bytes), because it's enough.
3
+ # Import BITMAPCOREHEADER and 24bpp BITMAPINFOHEADER because MS Paint uses it.
4
+
3
5
 
4
6
  module SimpleBMP
5
7
 
@@ -14,8 +16,9 @@ module SimpleBMP
14
16
  # Examples of exporting a single pixel image which is almost gray:
15
17
  # export [[100]], "temp.bmp"
16
18
  # export [[[90,100,110]]], "temp.bmp"
17
-
18
19
  def self.export pixels, filename = "temp.bmp"
20
+ #fail "pixel array shouldn't be empty" if pixels.empty?
21
+ fail "all pixel array rows should be of the same length" if pixels.map(&:size).uniq.size != 1
19
22
  bitmap_width = pixels.first.size
20
23
  bitmap_height = pixels.size
21
24
  pixel_array = pixels.reverse.flat_map do |row|
@@ -39,20 +42,39 @@ module SimpleBMP
39
42
  end
40
43
  end
41
44
 
42
- # This imports BITMAPCOREHEADER headed RGB bmp images returning a 3-dimentional array.
43
-
45
+ # This imports BITMAPCOREHEADER and 24bpp BITMAPINFOHEADER
46
+ # headed RGB bmp images returning a 3-dimentional array.
44
47
  def self.import filename = "temp.bmp"
45
48
  File.open(filename, "rb") do |file|
46
49
  _, _, shift = file.read(14).unpack("A2qi")
47
- dib_header_size, bitmap_width, bitmap_height = file.read(8).unpack("LSS")
48
- fail "can import only BITMAPCOREHEADER (12 bytes)" unless dib_header_size == 12
50
+ dib_header_size, = file.read(4).unpack("L")
51
+ case dib_header_size
52
+ when 12 ; bitmap_width, bitmap_height = file.read(4).unpack("SS")
53
+ when 40 ; bitmap_width, bitmap_height = file.read(8).unpack("ii")
54
+ else ; fail "can import only BITMAPCOREHEADER (12 bytes) and 24bpp BITMAPINFOHEADER (40 bytes)"
55
+ end
49
56
  file.pos = shift
50
- (file.read(bitmap_height * @@align4[bitmap_width * 3]).unpack("C*")).each_slice(@@align4[bitmap_width * 3]).map do |row|
57
+ (file.read(bitmap_height * @@align4[bitmap_width * 3]).unpack("C*")).
58
+ each_slice(@@align4[bitmap_width * 3]).map do |row|
51
59
  row.each_slice(3).take(bitmap_width).map(&:reverse)
52
60
  end.reverse
53
61
  end
54
62
  end
55
63
 
64
+ # Truncated box modal resizing
65
+ def self.reduce array, **args
66
+ array = array.each_slice(args[:times]).take(array.size/args[:times]).map{ |rows|
67
+ rows.transpose.each_slice(args[:times]).take(array.first.size/args[:times]).map{ |cells|
68
+ cells.flatten(1).group_by{ |i| i }.sort_by{ |i,g| g.size }.last.first
69
+ }
70
+ }
71
+ end
72
+
73
+ # Truncated box modal resizing
74
+ def self.enlarge array, **args
75
+ array = array.flat_map{ |row| [ row.flat_map{ |cell| [cell] * args[:times] } ] * args[:times] }
76
+ end
77
+
56
78
  end
57
79
 
58
80
  =begin
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_bmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: As simple as you really need. Only BITMAPCOREHEADER (12 bytes) header
14
- is used yet, and only 8bpp with no indexing. If it seems to work under <=1.8.7,
15
- let me know -- I'll update gemspec.
13
+ description: As simple as you really need. Uses only 8bpp with no indexing. Imports
14
+ BITMAPCOREHEADER and 24bpp BITMAPINFOHEADER. Exports BITMAPCOREHEADER. If it seems
15
+ to work under <=1.8.7, let me know -- I'll update gemspec.
16
16
  email: nakilon@gmail.com
17
17
  executables: []
18
18
  extensions: []
@@ -23,7 +23,7 @@ homepage: http://rubygems.org/gems/simple_bmp
23
23
  licenses:
24
24
  - MIT
25
25
  metadata: {}
26
- post_install_message:
26
+ post_install_message: 'Thx for install. Now do this: ri SimpleBMP'
27
27
  rdoc_options: []
28
28
  require_paths:
29
29
  - lib
@@ -42,5 +42,5 @@ rubyforge_project:
42
42
  rubygems_version: 2.0.14
43
43
  signing_key:
44
44
  specification_version: 4
45
- summary: A simple BMP renderer
45
+ summary: A simple BMP renderer.
46
46
  test_files: []