papirus 0.2.1 → 0.3.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/README.md +53 -12
- data/README.rdoc +1 -1
- data/lib/papirus.rb +4 -1
- data/lib/papirus/rmagick.rb +28 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e4a81e5d2a007320dd5fe508cfd8f28e0136265
|
4
|
+
data.tar.gz: dcedbd0e7fee34467acf974839bf0cd715a1cf6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e46eda4b6c84f40fd1f7183a2ebafd5ec1cdc4c454366c73e6228f5af17975e4e79a5e438cd46a2c39cc710b0af903f289a388b3eb0a4c50934496e48aa658
|
7
|
+
data.tar.gz: 91e93335743a1d73742d3ad98101ffa0dfd8a00e5db9a00f593d5e53df69b018308c82b04f533bae1d433e22a5888cb6e003c847e1d8f58cede0c038578488b6
|
data/README.md
CHANGED
@@ -32,22 +32,22 @@ require 'papirus'
|
|
32
32
|
display = PaPiRus::Display.new()
|
33
33
|
```
|
34
34
|
|
35
|
-
# Playing with
|
35
|
+
# Playing with Chunky_PNG
|
36
36
|
|
37
|
-
|
38
|
-
require 'rmagick'
|
37
|
+
First install chunky_png
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
```bash
|
40
|
+
$ (OSX) brew install chunky_png
|
41
|
+
$ (debian/ubuntu) sudo apt-get install chunky_png
|
42
|
+
$ (Windows) no idea (did not use windows for 20 year, yes that is possible)
|
43
|
+
$ gem install chunky_png
|
43
44
|
```
|
44
45
|
|
45
|
-
|
46
|
+
The, start an irb session to play around
|
46
47
|
```ruby
|
47
|
-
git clone https://github.com/mmolhoek/papirus
|
48
48
|
irb
|
49
49
|
require 'papirus'
|
50
|
-
|
50
|
+
require 'papirus/chunky' # add's to_bit_stream function to chucky
|
51
51
|
|
52
52
|
#lets get a clean png of the size of the display to play with using chunky_png
|
53
53
|
image = ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE)
|
@@ -94,11 +94,52 @@ Partial update:
|
|
94
94
|
|
95
95
|
```display.show(image.to_bit_stream, 'P')```
|
96
96
|
|
97
|
-
## Load an image from a png file
|
97
|
+
## Load an image from a png file with convert and chunky
|
98
|
+
|
99
|
+
First, let's use Image Magick's `convert` tool to convert any image into a b/w image the way the diplay likes it
|
100
|
+
```bash
|
101
|
+
convert in.jpg -resize '264x176' -gravity center -extent '264x176' -colorspace gray -colors 2 -type bilevel out.png
|
102
|
+
```
|
103
|
+
|
104
|
+
Where
|
105
|
+
* the -resize scales the image to fit the display
|
106
|
+
* The -gravity and -extent combination (order is important!) makes sure the image stays at the size of the display and in the centre
|
107
|
+
* The -colorspace -colors -type combi makes the image a 1-bit grayscale b/w image
|
108
|
+
|
109
|
+
Then we use chucky with our extension to show
|
98
110
|
|
99
111
|
```ruby
|
100
|
-
|
101
|
-
|
112
|
+
irb
|
113
|
+
require 'papirus'
|
114
|
+
require 'papirus/chunky'
|
115
|
+
display = PaPiRus::Display.new()
|
116
|
+
image = ChunkyPNG::Image.from_file('out.png')
|
117
|
+
display.show(image.to_bit_stream(true))
|
118
|
+
```
|
119
|
+
result:
|
120
|
+

|
121
|
+
|
122
|
+
# Playing with RMagic (does not work yet), did not figure out right command
|
123
|
+
|
124
|
+
First install rmagick
|
125
|
+
|
126
|
+
```bash
|
127
|
+
$ # install native Image Magick library
|
128
|
+
$ (OSX) brew install imagemagick@6 && brew link imagemagick@6 --force
|
129
|
+
$ (debian/ubuntu) sudo apt-get install imagemagick
|
130
|
+
$ (Windows) no idea (did not use windows for 20 year, yes that is possible)
|
131
|
+
$ # install the gem that talks to the native Image Magick library
|
132
|
+
$ gem install rmagick
|
133
|
+
```
|
134
|
+
|
135
|
+
The, start an irb session to play around
|
136
|
+
```ruby
|
137
|
+
require 'papirus'
|
138
|
+
require 'papirus/rmagick'
|
139
|
+
|
140
|
+
display = PaPiRus::Display.new()
|
141
|
+
img = Magick::Image::read('/path/to/img/file.(png|jpg|etc').first
|
142
|
+
img.to_papirus(display)
|
102
143
|
```
|
103
144
|
|
104
145
|
## Testing without a PAPiRus display
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= papirus
|
2
2
|
|
3
3
|
This gem can be used to communicate with the {PaPiRus}[https://github.com/PiSupply/PaPiRus] display.
|
4
|
-
Checkout {GitHub}[http://github.com/mmolhoek/papirus] for examples
|
4
|
+
Checkout {GitHub}[http://github.com/mmolhoek/papirus] for examples and documentation
|
5
5
|
|
6
6
|
== Contributing to papirus
|
7
7
|
|
data/lib/papirus.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module PaPiRus
|
2
|
+
# The {PaPiRus::Display} can be use to send image data to the
|
3
|
+
# epd fuse driver
|
2
4
|
class Display
|
3
|
-
attr_reader :epd_path, :width, :height, :panel, :cog, :film, :auto, :allowed_commands
|
5
|
+
attr_reader :epd_path, :width, :height, :panel, :cog, :film, :auto, :allowed_commands, :display_path
|
4
6
|
attr_accessor :rotation, :inverse, :image
|
5
7
|
|
6
8
|
def initialize(epd_path: '/dev/epd', width: 200, height: 96, panel: 'EPD 2.0', cog: 0, film: 0, auto: false, inverse: false, rotation: 0)
|
@@ -53,6 +55,7 @@ module PaPiRus
|
|
53
55
|
#and update the properties accordingly
|
54
56
|
if File.exists?(File.join(@epd_path, 'panel'))
|
55
57
|
info = File.read(File.join(@epd_path, 'panel'))
|
58
|
+
@display_path = File.join([@epd_path, 'LE', 'display'])
|
56
59
|
if match = info.match(/^([A-Za-z]+\s+\d+\.\d+)\s+(\d+)x(\d+)\s+COG\s+(\d+)\s+FILM\s+(\d+)\s*$/)
|
57
60
|
@panel, @width, @height, @cog, @film = match.captures.each_with_index.map{|val, index| index > 0 ? val.to_i : val}
|
58
61
|
else
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
|
3
|
+
class Magick::Image
|
4
|
+
# Send's any image to the PAPiRus display, if it is found
|
5
|
+
# image is rescaled to fit the display (positioning it mid center)
|
6
|
+
# @param display[PaPiRus::Display] The {PaPiRus::Display} object
|
7
|
+
def to_papirus(display)
|
8
|
+
# Resize to fit the screen
|
9
|
+
resized = resize_to_fit(display.width, display.height)
|
10
|
+
# Reduce the image to a limited number of colors for a "poster" effect, brings it donw to 4-bit 16 colors
|
11
|
+
posterized = resized.posterize(2)
|
12
|
+
#now, as the display expects a file with all pixels set, we need to extend the image to the display size
|
13
|
+
#if it is smaller in either width or height or both
|
14
|
+
if (posterize.columns != display.width or posterize.rows != display.height)
|
15
|
+
# extent fill color
|
16
|
+
posterized.background_color = "#FFFFFF"
|
17
|
+
# calculate necessary translation to center image on background
|
18
|
+
x = (posterized.columns - display.width) / 2
|
19
|
+
y = (posterized.rows - display.height) / 2
|
20
|
+
# now, 'extent' the image to the correct size with the image centered
|
21
|
+
posterized = posterized.extent(display.width, display.height, x, y)
|
22
|
+
end
|
23
|
+
# Now, make grayscale with only 2 colors, b/w, brings it down to 1-bit 2 colors
|
24
|
+
quantized = posterized.quantize(2, Magick::GRAYColorspace)
|
25
|
+
#return the raw image data
|
26
|
+
quantized.write(display.display_path){self.format='DIB'} #DIB=Device Independant Binary, as in , no headers, just raw data
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: papirus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mischa Molhoek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- README.rdoc
|
97
97
|
- lib/papirus.rb
|
98
98
|
- lib/papirus/chunky.rb
|
99
|
+
- lib/papirus/rmagick.rb
|
99
100
|
homepage: http://github.com/mmolhoek/papirus
|
100
101
|
licenses:
|
101
102
|
- MIT
|
@@ -116,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
117
|
version: '0'
|
117
118
|
requirements: []
|
118
119
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.6.13
|
120
121
|
signing_key:
|
121
122
|
specification_version: 4
|
122
123
|
summary: ruby gem to access the PaPiRus display
|