brother_escp 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61a11c65fb3b3a8b52c80e597cdca3e5a0d422fd
4
- data.tar.gz: 2aee66767228566915faf782710bce5673a6e39d
3
+ metadata.gz: 9d8f1c2289adb405f2657967cd33f5949a144b52
4
+ data.tar.gz: 35cf9202fe9882c89b69c329f8cb2cc41b1e1af7
5
5
  SHA512:
6
- metadata.gz: 8dcff64a46a6e61586b3229a9bd11370884854c8daaa51f8993036a5f223c53e9bc457f691eb15f88457914b8907c5e543bf67a416907632ddbedd009a6b0892
7
- data.tar.gz: 0612d490fbcdedc6b05441af62838423018c7d4e003d8337d73cdc6441e60baa5b8e7749814c15bfb20ff8e41165b630a634b0cef6e5c57a61d49e03da0e0d49
6
+ metadata.gz: 7b7fbd2cdc9d0a38ed3a052f8442ed8e665ca656fba7be7172db05d5cd541d931157a584975d0bc3ba7b3986579e46022233841780c737e3fff0f471db75fc9c
7
+ data.tar.gz: f49972c117511694e02e9b7fbc20b9aad472101a459daf3b224be6ece55402486dca57abf59e42660f8da7bfd0fdd6698804dd518e6bacc97cb7485772b05ce5
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.org/butterware/brother_escp.svg?branch=master)](https://travis-ci.org/butterware/brother_escp)
2
+ [![Gem Version](https://badge.fury.io/rb/brother_escp.svg)](https://badge.fury.io/rb/brother_escp)
2
3
 
3
4
  # BrotherEscp
4
5
 
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'bundler', '~> 1.13'
35
35
  spec.add_development_dependency 'rake', '~> 10.0'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
- # spec.add_development_dependency 'simplecov', '~> 3.0'
37
+ spec.add_development_dependency 'simplecov'
38
38
 
39
39
  spec.add_dependency 'chunky_png'
40
40
  end
@@ -34,13 +34,13 @@ module BrotherEscp
34
34
  # @param image [ChunkyPNG::Image] Image to convert
35
35
  # @return [Array] return an array of array, one array for each line, with one element for each byte
36
36
  def convert(image:)
37
- check_image(image: image)
38
- lines = []
39
- line_count = (image.height / line_height_in_pixels)
40
- # BrotherEscp.logger.debug "convert, line_count = #{line_count}"
37
+ lines = []
38
+ line_count = line_count(image: image)
39
+ BrotherEscp.logger.debug "convert, line_count = #{line_count}"
41
40
  0.upto(line_count - 1) do |line_index|
42
41
  lines << create_line(image: image, line_index: line_index)
43
42
  end
43
+ BrotherEscp.logger.debug "convert, size by line: #{lines.map(&:size)}, total: #{lines.map(&:size).inject(:+)}"
44
44
  lines
45
45
  end
46
46
 
@@ -57,12 +57,14 @@ module BrotherEscp
57
57
 
58
58
  private
59
59
 
60
- def check_image(image:)
61
- remain = image.height % line_height_in_pixels
62
- BrotherEscp.logger.warn { "the height (#{image.height}) is not a multiple if #{line_height_in_pixels}, the last #{remain} lines will be ignored." } if remain.positive?
60
+ def line_count(image:)
61
+ line_count = (image.height / line_height_in_pixels)
62
+ line_count += 1 if (image.height % line_height_in_pixels).nonzero?
63
+ line_count
63
64
  end
64
65
 
65
66
  def create_line(image:, line_index:)
67
+ BrotherEscp.logger.debug "create_line: #{line_index}"
66
68
  line = []
67
69
  0.upto(image.width - 1) do |x|
68
70
  0.upto(line_height_in_bytes - 1) do |byte_offset|
@@ -76,13 +78,21 @@ module BrotherEscp
76
78
  bits = String.new('')
77
79
  0.upto(7) do |y_offset|
78
80
  y = (line_index * line_height_in_pixels) + (byte_offset * 8) + y_offset
79
- bit = convert_pixel_to_bw(image[x, y])
81
+ bit = convert_point(image: image, x: x, y: y)
80
82
  # BrotherEscp.logger.debug "convert, line = #{line_index}, byte_offset = #{byte_offset}, x = #{x}, y = #{y}, bit: #{bit}"
81
83
  bits << bit
82
84
  end
83
85
  bits.to_i(2)
84
86
  end
85
87
 
88
+ def convert_point(image:, x:, y:)
89
+ if y >= image.height
90
+ '0'
91
+ else
92
+ convert_pixel_to_bw(image[x, y])
93
+ end
94
+ end
95
+
86
96
  def convert_pixel_to_bw(pixel)
87
97
  r = ChunkyPNG::Color.r(pixel)
88
98
  g = ChunkyPNG::Color.g(pixel)
@@ -92,7 +102,7 @@ module BrotherEscp
92
102
  # BrotherEscp.logger.debug "convert_pixel_to_bw: #{[r, g, b, a]}, px = #{px}"
93
103
  BrotherEscp.logger.warn 'PNG images with alpha are not supported.' unless a == 255
94
104
 
95
- px > 128 ? '0' : '1'
105
+ px > 230 ? '0' : '1'
96
106
  end
97
107
  end
98
108
  end
@@ -2,5 +2,5 @@
2
2
  # Main module
3
3
  module BrotherEscp
4
4
  # Current version
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brother_escp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Bourguignon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-25 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: chunky_png
57
71
  requirement: !ruby/object:Gem::Requirement