pixelflut 0.0.13 → 0.2.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.
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pixelflut
4
- class TextImage
5
- attr_reader :columns, :rows, :to_blob, :changes
6
-
7
- def initialize(width, height)
8
- @columns, @rows = width, height
9
- @row_inc = width * 4
10
- clear
11
- end
12
-
13
- alias width columns
14
- alias height rows
15
-
16
- def clear
17
- @to_blob = Black * (@columns * @rows)
18
- @changes = 1
19
- end
20
-
21
- def changed
22
- @changes = 0
23
- self
24
- end
25
-
26
- # def [](x, y)
27
- # @@to_blob[(4 * (x + @columns * y)) % @data.size, 4].bytes.map! do |b|
28
- # b = b.to_s(16)
29
- # b = '0' + b if b.size == 1
30
- # b
31
- # end.join
32
- # end
33
-
34
- def []=(x, y, rrggbbaa)
35
- @to_blob[(4 * (x + @columns * y)) % @to_blob.size, 4] = as_color(rrggbbaa)
36
- @changes += 1
37
- end
38
-
39
- def draw_rect(x1, y1, x2, y2, rrggbbaa)
40
- x1, x2 = x2, x1 if x1 > x2
41
- y1, y2 = y2, y1 if y1 > y2
42
- color = as_color(rrggbbaa)
43
- pos = (4 * (x1 + @columns * y1)) % @to_blob.size
44
- pattern = color * (x2 - x1 + 1)
45
- (y2 - y1 + 1).times do
46
- @to_blob[pos, pattern.size] = pattern
47
- pos += @row_inc
48
- end
49
- @changes += 1
50
- end
51
-
52
- private
53
-
54
- ZZ = 0.chr.freeze
55
- FF = 0xff.chr.freeze
56
- Black = (ZZ + ZZ + ZZ + FF).freeze
57
-
58
- def as_color(rrggbbaa)
59
- case rrggbbaa.size
60
- when 3 # RGB
61
- (rrggbbaa[0] * 2).to_i(16).chr +
62
- (rrggbbaa[1] * 2).to_i(16).chr +
63
- (rrggbbaa[2] * 2).to_i(16).chr +
64
- FF
65
- when 4 # RGBA
66
- (rrggbbaa[0] * 2).to_i(16).chr +
67
- (rrggbbaa[1] * 2).to_i(16).chr +
68
- (rrggbbaa[2] * 2).to_i(16).chr +
69
- (rrggbbaa[3] * 2).to_i(16).chr
70
- when 6 # RRGGBB
71
- (rrggbbaa[0, 2]).to_i(16).chr +
72
- (rrggbbaa[2, 2]).to_i(16).chr +
73
- (rrggbbaa[4, 2]).to_i(16).chr +
74
- FF
75
- when 8 # RRGGBBAA
76
- (rrggbbaa[0, 2]).to_i(16).chr +
77
- (rrggbbaa[2, 2]).to_i(16).chr +
78
- (rrggbbaa[4, 2]).to_i(16).chr +
79
- (rrggbbaa[6, 2]).to_i(16).chr
80
- else
81
- Black
82
- end
83
- end
84
-
85
- # def pos(x, y)
86
- # (4 * (x + @columns * y)) % @data.size
87
- # end
88
- end
89
- end