simple_bmp 0.0.3 → 0.1.0
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.
- checksums.yaml +4 -4
- data/lib/simple_bmp.rb +33 -10
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d84f668c6933430316c3ac409ecc577b7fb71924
|
4
|
+
data.tar.gz: cf46732f084471b98c9f106fedfa781451b6e432
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66d1d770f7bbd94fb8b36356f0c9c77d1871d2ca8ec1f720283126dca9a892257f2f41774d26d185fa5ee45714dfe63536b3c7c621f7b5a764a83feaa512d7ed
|
7
|
+
data.tar.gz: 97ecd52f84f73ef570d0dbdadfe5359b6ef5fc87875b6786c8b475724f68d9be75a922240eb395ca723b5d7e378fee722c95eeb3d973d2240a2edf8196313cf6
|
data/lib/simple_bmp.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
|
+
##
|
2
|
+
# Currently there are no need of classes -- just a single public module method.
|
3
|
+
#
|
4
|
+
|
1
5
|
module SimpleBMP
|
2
|
-
|
3
|
-
|
4
|
-
#
|
6
|
+
|
7
|
+
##
|
8
|
+
# Pixels is either two or three dimensional array:
|
9
|
+
# pixels: [height x width x 3] of 0..255 for RGB
|
10
|
+
# pixels: [height x width] of 0..255 for grayscale
|
11
|
+
# Two-dimensional will be processed as it's three, where R, G anb B are equal.
|
12
|
+
#
|
13
|
+
# Examples of exporting a single pixel image which is almost gray:
|
14
|
+
# export [[100]], "temp.bmp"
|
15
|
+
# export [[[90,100,110]]], "temp.bmp"
|
16
|
+
#--
|
17
|
+
# we use BITMAPINFOHEADER (40 bytes), because BITMAPCOREHEADER (12 bytes) can't 1 channel
|
18
|
+
|
5
19
|
def self.export pixels, filename = "temp.bmp"
|
6
20
|
bitmap_width = pixels.first.size
|
7
21
|
bitmap_height = pixels.size
|
8
22
|
=begin
|
23
|
+
--
|
9
24
|
hsv2bgr = lambda do |(h,s,v)|
|
10
25
|
a = (v - vmin = (100-s)*v/100)*(h % 60)/60.0
|
11
26
|
vinc, vdec = vmin + a, v - a
|
@@ -20,18 +35,26 @@ module SimpleBMP
|
|
20
35
|
end
|
21
36
|
=end
|
22
37
|
pixel_array = pixels.reverse.flat_map do |row|
|
23
|
-
|
38
|
+
#--
|
39
|
+
# row_bytes = row.map(&hsv2bgr).flatten
|
24
40
|
row_bytes = row.flat_map{ |pixel| pixel.is_a?(Array) ? pixel : [pixel]*3 }
|
25
41
|
row_bytes.fill 0, row_bytes.size .. (row_bytes.size + 3) / 4 * 4 - 1
|
26
42
|
end
|
27
|
-
|
43
|
+
|
44
|
+
#--
|
45
|
+
# 12=>BITMAPCOREHEADER, 40=>BITMAPINFOHEADER
|
46
|
+
dib_header_size = 12
|
47
|
+
file_size = 14 + dib_header_size + pixel_array.size
|
28
48
|
|
29
49
|
open(filename, "wb") do |file|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
50
|
+
#--
|
51
|
+
# Bitmap file header
|
52
|
+
file.write ["BM", file_size, 14 + dib_header_size].pack "A2qi" # "A2QL"
|
53
|
+
#--
|
54
|
+
# DIB header
|
55
|
+
# file.write [dib_header_size, bitmap_width, bitmap_height, 1, 24].pack "LllSS"
|
56
|
+
# file.write [0, 0, 1, 1, 0, 0].pack "LLllLL"
|
57
|
+
file.write [dib_header_size, bitmap_width, bitmap_height, 1, 24].pack "LSSSS"
|
35
58
|
file.write pixel_array.pack "C*"
|
36
59
|
end
|
37
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_bmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
@@ -10,7 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: As simple as you really need. You get only 40 bytes type header, and
|
14
|
+
currently only either RGB or Grayscale. If it seems to work under <=1.8.7, let me
|
15
|
+
know -- I'll update gemspec.
|
14
16
|
email: nakilon@gmail.com
|
15
17
|
executables: []
|
16
18
|
extensions: []
|
@@ -29,7 +31,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
31
|
requirements:
|
30
32
|
- - '>='
|
31
33
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
34
|
+
version: 2.0.0
|
33
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
36
|
requirements:
|
35
37
|
- - '>='
|