sugar_png 0.0.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -4
- data/Gemfile.lock +77 -24
- data/README.md +105 -0
- data/README.md.tpl +99 -0
- data/Rakefile +41 -6
- data/VERSION +1 -1
- data/data/1-dump-hex.rb +22 -0
- data/data/2-marshal-test.rb +22 -0
- data/data/3-hex2marshal.rb +71 -0
- data/data/font/00 +0 -0
- data/data/font/01 +0 -0
- data/data/font/02 +0 -0
- data/data/font/03 +0 -0
- data/data/font/04 +0 -0
- data/data/font/05 +0 -0
- data/data/font/06 +0 -0
- data/data/font/07 +0 -0
- data/data/font/09 +0 -0
- data/data/font/0a +0 -0
- data/data/font/0b +0 -0
- data/data/font/0c +0 -0
- data/data/font/0d +0 -0
- data/data/font/0e +0 -0
- data/data/font/0f +0 -0
- data/data/font/10 +0 -0
- data/data/font/11 +0 -0
- data/data/font/12 +0 -0
- data/data/font/13 +0 -0
- data/data/font/14 +0 -0
- data/data/font/15 +0 -0
- data/data/font/16 +0 -0
- data/data/font/17 +0 -0
- data/data/font/18 +0 -0
- data/data/font/19 +0 -0
- data/data/font/1a +0 -0
- data/data/font/1b +0 -0
- data/data/font/1c +0 -0
- data/data/font/1d +0 -0
- data/data/font/1e +0 -0
- data/data/font/1f +0 -0
- data/data/font/20 +0 -0
- data/data/font/21 +0 -0
- data/data/font/22 +0 -0
- data/data/font/23 +0 -0
- data/data/font/24 +0 -0
- data/data/font/25 +0 -0
- data/data/font/26 +0 -0
- data/data/font/27 +0 -0
- data/data/font/28 +0 -0
- data/data/font/29 +0 -0
- data/data/font/2a +0 -0
- data/data/font/2b +0 -0
- data/data/font/2c +0 -0
- data/data/font/2d +0 -0
- data/data/font/2e +0 -0
- data/data/font/2f +0 -0
- data/data/font/30 +0 -0
- data/data/font/31 +0 -0
- data/data/font/32 +0 -0
- data/data/font/33 +0 -0
- data/data/font/34 +0 -0
- data/data/font/35 +0 -0
- data/data/font/36 +0 -0
- data/data/font/37 +0 -0
- data/data/font/38 +0 -0
- data/data/font/39 +0 -0
- data/data/font/3a +0 -0
- data/data/font/3b +0 -0
- data/data/font/3c +0 -0
- data/data/font/3d +0 -0
- data/data/font/3e +0 -0
- data/data/font/3f +0 -0
- data/data/font/40 +0 -0
- data/data/font/41 +0 -0
- data/data/font/42 +0 -0
- data/data/font/43 +0 -0
- data/data/font/44 +0 -0
- data/data/font/45 +0 -0
- data/data/font/46 +0 -0
- data/data/font/47 +0 -0
- data/data/font/48 +0 -0
- data/data/font/49 +0 -0
- data/data/font/4a +0 -0
- data/data/font/4b +0 -0
- data/data/font/4c +0 -0
- data/data/font/4d +0 -0
- data/data/font/4e +0 -0
- data/data/font/4f +0 -0
- data/data/font/50 +0 -0
- data/data/font/51 +0 -0
- data/data/font/52 +0 -0
- data/data/font/53 +0 -0
- data/data/font/54 +0 -0
- data/data/font/55 +0 -0
- data/data/font/56 +0 -0
- data/data/font/57 +0 -0
- data/data/font/58 +0 -0
- data/data/font/59 +0 -0
- data/data/font/5a +0 -0
- data/data/font/5b +0 -0
- data/data/font/5c +0 -0
- data/data/font/5d +0 -0
- data/data/font/5e +0 -0
- data/data/font/5f +0 -0
- data/data/font/60 +0 -0
- data/data/font/61 +0 -0
- data/data/font/62 +0 -0
- data/data/font/63 +0 -0
- data/data/font/64 +0 -0
- data/data/font/65 +0 -0
- data/data/font/66 +0 -0
- data/data/font/67 +0 -0
- data/data/font/68 +0 -0
- data/data/font/69 +0 -0
- data/data/font/6a +0 -0
- data/data/font/6b +0 -0
- data/data/font/6c +0 -0
- data/data/font/6d +0 -0
- data/data/font/6e +0 -0
- data/data/font/6f +0 -0
- data/data/font/70 +0 -0
- data/data/font/71 +0 -0
- data/data/font/72 +0 -0
- data/data/font/73 +0 -0
- data/data/font/74 +0 -0
- data/data/font/75 +0 -0
- data/data/font/76 +0 -0
- data/data/font/77 +0 -0
- data/data/font/78 +0 -0
- data/data/font/79 +0 -0
- data/data/font/7a +0 -0
- data/data/font/7b +0 -0
- data/data/font/7c +0 -0
- data/data/font/7d +0 -0
- data/data/font/7e +0 -0
- data/data/font/7f +0 -0
- data/data/font/80 +0 -0
- data/data/font/81 +0 -0
- data/data/font/82 +0 -0
- data/data/font/83 +0 -0
- data/data/font/84 +0 -0
- data/data/font/85 +0 -0
- data/data/font/86 +0 -0
- data/data/font/87 +0 -0
- data/data/font/88 +0 -0
- data/data/font/89 +0 -0
- data/data/font/8a +0 -0
- data/data/font/8b +0 -0
- data/data/font/8c +0 -0
- data/data/font/8d +0 -0
- data/data/font/8e +0 -0
- data/data/font/8f +0 -0
- data/data/font/90 +0 -0
- data/data/font/91 +0 -0
- data/data/font/92 +0 -0
- data/data/font/93 +0 -0
- data/data/font/94 +0 -0
- data/data/font/95 +0 -0
- data/data/font/96 +0 -0
- data/data/font/97 +0 -0
- data/data/font/98 +0 -0
- data/data/font/99 +0 -0
- data/data/font/9a +0 -0
- data/data/font/9b +0 -0
- data/data/font/9c +0 -0
- data/data/font/9d +0 -0
- data/data/font/9e +0 -0
- data/data/font/9f +0 -0
- data/data/font/a0 +0 -0
- data/data/font/a1 +0 -0
- data/data/font/a2 +0 -0
- data/data/font/a3 +0 -0
- data/data/font/a4 +0 -0
- data/data/font/a5 +0 -0
- data/data/font/a6 +0 -0
- data/data/font/a7 +0 -0
- data/data/font/a8 +0 -0
- data/data/font/a9 +0 -0
- data/data/font/aa +0 -0
- data/data/font/ac +0 -0
- data/data/font/ad +0 -0
- data/data/font/ae +0 -0
- data/data/font/af +0 -0
- data/data/font/b0 +0 -0
- data/data/font/b1 +0 -0
- data/data/font/b2 +0 -0
- data/data/font/b3 +0 -0
- data/data/font/b4 +0 -0
- data/data/font/b5 +0 -0
- data/data/font/b6 +0 -0
- data/data/font/b7 +0 -0
- data/data/font/b8 +0 -0
- data/data/font/b9 +0 -0
- data/data/font/ba +0 -0
- data/data/font/bb +0 -0
- data/data/font/bc +0 -0
- data/data/font/bd +0 -0
- data/data/font/be +0 -0
- data/data/font/bf +0 -0
- data/data/font/c0 +0 -0
- data/data/font/c1 +0 -0
- data/data/font/c2 +0 -0
- data/data/font/c3 +0 -0
- data/data/font/c4 +0 -0
- data/data/font/c5 +0 -0
- data/data/font/c6 +0 -0
- data/data/font/c7 +0 -0
- data/data/font/c8 +0 -0
- data/data/font/c9 +0 -0
- data/data/font/ca +0 -0
- data/data/font/cb +0 -0
- data/data/font/cc +0 -0
- data/data/font/cd +0 -0
- data/data/font/ce +0 -0
- data/data/font/cf +0 -0
- data/data/font/d0 +0 -0
- data/data/font/d1 +0 -0
- data/data/font/d2 +0 -0
- data/data/font/d3 +0 -0
- data/data/font/d4 +0 -0
- data/data/font/d5 +0 -0
- data/data/font/d6 +0 -0
- data/data/font/d7 +0 -0
- data/data/font/f9 +0 -0
- data/data/font/fa +0 -0
- data/data/font/fb +0 -0
- data/data/font/fc +0 -0
- data/data/font/fd +0 -0
- data/data/font/fe +0 -0
- data/data/font/ff +0 -0
- data/data/unifont-5.1.20080820.7z +0 -0
- data/data/unused-4-read-tar.rb +49 -0
- data/lib/sugar_png.rb +164 -2
- data/lib/sugar_png/border.rb +20 -0
- data/lib/sugar_png/color.rb +118 -0
- data/lib/sugar_png/datastream.rb +2 -17
- data/lib/sugar_png/dyn_accessor.rb +28 -0
- data/lib/sugar_png/font.rb +44 -0
- data/lib/sugar_png/glyph.rb +36 -0
- data/lib/sugar_png/image.rb +104 -0
- data/samples/damaged_chunk.png +0 -0
- data/samples/damaged_signature.png +0 -0
- data/samples/png_suite/f00n0g08_reference.png +0 -0
- data/samples/png_suite/f00n2c08_reference.png +0 -0
- data/samples/png_suite/f01n0g08_reference.png +0 -0
- data/samples/png_suite/f01n2c08_reference.png +0 -0
- data/samples/png_suite/f02n0g08_reference.png +0 -0
- data/samples/png_suite/f02n2c08_reference.png +0 -0
- data/samples/png_suite/f03n0g08_reference.png +0 -0
- data/samples/png_suite/f03n2c08_reference.png +0 -0
- data/samples/png_suite/f04n0g08_reference.png +0 -0
- data/samples/png_suite/f04n2c08_reference.png +0 -0
- data/samples/readme/explicit_image_dimensions_bg_color.png +0 -0
- data/samples/readme/hello_world.png +0 -0
- data/samples/readme/japanese_text_with_rainbow_borders_zoomed_4x.png +0 -0
- data/samples/readme/pixels_can_be_set_using_ranges_enumerators_arrays.png +0 -0
- data/samples/readme/playing_with_transparency_16_bit_color_depth.png +0 -0
- data/samples/readme/white_noise.png +0 -0
- data/samples/rgba.tar.bz2 +0 -0
- data/samples/text_chunk.png +0 -0
- data/samples/ztxt_chunk.png +0 -0
- data/spec/color_spec.rb +81 -0
- data/spec/font_spec.rb +82 -0
- data/spec/magic/border_spec.rb +49 -0
- data/spec/magic/create_spec.rb +42 -0
- data/spec/magic/pixels_spec.rb +73 -0
- data/spec/magic/text_spec.rb +113 -0
- data/spec/magic/zoom_spec.rb +38 -0
- data/spec/png_suite_spec.rb +145 -0
- data/spec/spec_helper.rb +45 -1
- data/spec/sugar_png/datastream_spec.rb +32 -0
- data/spec/support/png_suite.rb +44 -0
- data/sugar_png.gemspec +295 -28
- metadata +331 -50
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
fname = ARGV.first || "unifont-5.1.20080820.hex"
|
4
|
+
|
5
|
+
want = ARGV[1] && ARGV[1].to_i(16)
|
6
|
+
|
7
|
+
h = {}
|
8
|
+
a = []
|
9
|
+
dedup = {}
|
10
|
+
aa = []
|
11
|
+
|
12
|
+
File.read(fname).each_line do |line|
|
13
|
+
idx, data = line.strip.split(':',2)
|
14
|
+
idx = idx.to_i(16)
|
15
|
+
s = data.scan(/../).map{ |x| x.to_i(16).chr }.join
|
16
|
+
s = (dedup[s] ||= s)
|
17
|
+
# unless s.split('').uniq == ["\x00"]
|
18
|
+
h[idx] = s
|
19
|
+
a[idx] = s
|
20
|
+
aa[idx >> 8] ||= []
|
21
|
+
aa[idx >> 8][idx & 0xff] = s
|
22
|
+
# end
|
23
|
+
end
|
24
|
+
|
25
|
+
puts "[=] #{aa.size} pages"
|
26
|
+
puts "[=] #{aa.uniq.size} unique pages"
|
27
|
+
|
28
|
+
# dedup pages
|
29
|
+
aa.each_with_index do |page,idx|
|
30
|
+
(idx+1).upto(aa.size-1) do |idx2|
|
31
|
+
aa[idx2] = page if aa[idx2] == page
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "[=] #{h.size} non-empty chars"
|
36
|
+
puts "[=] #{h.values.uniq.size} unique chars"
|
37
|
+
|
38
|
+
puts "[=] #{h.values.join.size} bytes raw data size"
|
39
|
+
|
40
|
+
data = Marshal.dump(h)
|
41
|
+
puts "[=] #{data.size} bytes marshaled hash"
|
42
|
+
|
43
|
+
data = Marshal.dump(a)
|
44
|
+
puts "[=] #{data.size} bytes marshaled array"
|
45
|
+
|
46
|
+
data = Marshal.dump(aa)
|
47
|
+
puts "[=] #{data.size} bytes marshaled array2"
|
48
|
+
|
49
|
+
# .index header = 512 bytes
|
50
|
+
# .index data = 1024 bytes (256 pages of 4 bytes each)
|
51
|
+
# first file header = 512 bytes
|
52
|
+
#index = ''
|
53
|
+
#offset = 512 + 1024 + 512
|
54
|
+
aa.each_with_index do |a,pageno|
|
55
|
+
# skip empty pages and pages entirely of one glyph (most likely Unassigned ones)
|
56
|
+
next if a.nil? || a.empty? || a.uniq.size == 1
|
57
|
+
fname = "font/%02x" % pageno
|
58
|
+
data = Marshal.dump(a)
|
59
|
+
puts "[.] #{fname}: #{data.size}"
|
60
|
+
File.open(fname, "wb"){ |f| f << data }
|
61
|
+
|
62
|
+
# index << [offset].pack('V')
|
63
|
+
#
|
64
|
+
# size = data.size
|
65
|
+
# if size & 0x1ff != 0
|
66
|
+
# size = (size|0x1ff) + 1
|
67
|
+
# end
|
68
|
+
# offset += size+512 # add TAR header size
|
69
|
+
end
|
70
|
+
|
71
|
+
#File.open('data/.index','wb'){ |f| f<<index }
|
data/data/font/00
ADDED
Binary file
|
data/data/font/01
ADDED
Binary file
|
data/data/font/02
ADDED
Binary file
|
data/data/font/03
ADDED
Binary file
|
data/data/font/04
ADDED
Binary file
|
data/data/font/05
ADDED
Binary file
|
data/data/font/06
ADDED
Binary file
|
data/data/font/07
ADDED
Binary file
|
data/data/font/09
ADDED
Binary file
|
data/data/font/0a
ADDED
Binary file
|
data/data/font/0b
ADDED
Binary file
|
data/data/font/0c
ADDED
Binary file
|
data/data/font/0d
ADDED
Binary file
|
data/data/font/0e
ADDED
Binary file
|
data/data/font/0f
ADDED
Binary file
|
data/data/font/10
ADDED
Binary file
|
data/data/font/11
ADDED
Binary file
|
data/data/font/12
ADDED
Binary file
|
data/data/font/13
ADDED
Binary file
|
data/data/font/14
ADDED
Binary file
|
data/data/font/15
ADDED
Binary file
|
data/data/font/16
ADDED
Binary file
|
data/data/font/17
ADDED
Binary file
|
data/data/font/18
ADDED
Binary file
|
data/data/font/19
ADDED
Binary file
|
data/data/font/1a
ADDED
Binary file
|
data/data/font/1b
ADDED
Binary file
|
data/data/font/1c
ADDED
Binary file
|
data/data/font/1d
ADDED
Binary file
|
data/data/font/1e
ADDED
Binary file
|
data/data/font/1f
ADDED
Binary file
|
data/data/font/20
ADDED
Binary file
|
data/data/font/21
ADDED
Binary file
|
data/data/font/22
ADDED
Binary file
|
data/data/font/23
ADDED
Binary file
|
data/data/font/24
ADDED
Binary file
|
data/data/font/25
ADDED
Binary file
|
data/data/font/26
ADDED
Binary file
|
data/data/font/27
ADDED
Binary file
|
data/data/font/28
ADDED
Binary file
|
data/data/font/29
ADDED
Binary file
|
data/data/font/2a
ADDED
Binary file
|
data/data/font/2b
ADDED
Binary file
|
data/data/font/2c
ADDED
Binary file
|
data/data/font/2d
ADDED
Binary file
|
data/data/font/2e
ADDED
Binary file
|
data/data/font/2f
ADDED
Binary file
|
data/data/font/30
ADDED
Binary file
|
data/data/font/31
ADDED
Binary file
|
data/data/font/32
ADDED
Binary file
|
data/data/font/33
ADDED
Binary file
|
data/data/font/34
ADDED
Binary file
|
data/data/font/35
ADDED
Binary file
|
data/data/font/36
ADDED
Binary file
|
data/data/font/37
ADDED
Binary file
|
data/data/font/38
ADDED
Binary file
|
data/data/font/39
ADDED
Binary file
|
data/data/font/3a
ADDED
Binary file
|
data/data/font/3b
ADDED
Binary file
|
data/data/font/3c
ADDED
Binary file
|
data/data/font/3d
ADDED
Binary file
|
data/data/font/3e
ADDED
Binary file
|
data/data/font/3f
ADDED
Binary file
|
data/data/font/40
ADDED
Binary file
|
data/data/font/41
ADDED
Binary file
|
data/data/font/42
ADDED
Binary file
|
data/data/font/43
ADDED
Binary file
|
data/data/font/44
ADDED
Binary file
|
data/data/font/45
ADDED
Binary file
|
data/data/font/46
ADDED
Binary file
|
data/data/font/47
ADDED
Binary file
|
data/data/font/48
ADDED
Binary file
|
data/data/font/49
ADDED
Binary file
|
data/data/font/4a
ADDED
Binary file
|
data/data/font/4b
ADDED
Binary file
|
data/data/font/4c
ADDED
Binary file
|
data/data/font/4d
ADDED
Binary file
|
data/data/font/4e
ADDED
Binary file
|
data/data/font/4f
ADDED
Binary file
|
data/data/font/50
ADDED
Binary file
|
data/data/font/51
ADDED
Binary file
|
data/data/font/52
ADDED
Binary file
|
data/data/font/53
ADDED
Binary file
|
data/data/font/54
ADDED
Binary file
|
data/data/font/55
ADDED
Binary file
|
data/data/font/56
ADDED
Binary file
|
data/data/font/57
ADDED
Binary file
|
data/data/font/58
ADDED
Binary file
|
data/data/font/59
ADDED
Binary file
|
data/data/font/5a
ADDED
Binary file
|
data/data/font/5b
ADDED
Binary file
|
data/data/font/5c
ADDED
Binary file
|
data/data/font/5d
ADDED
Binary file
|
data/data/font/5e
ADDED
Binary file
|
data/data/font/5f
ADDED
Binary file
|
data/data/font/60
ADDED
Binary file
|
data/data/font/61
ADDED
Binary file
|
data/data/font/62
ADDED
Binary file
|
data/data/font/63
ADDED
Binary file
|
data/data/font/64
ADDED
Binary file
|
data/data/font/65
ADDED
Binary file
|
data/data/font/66
ADDED
Binary file
|
data/data/font/67
ADDED
Binary file
|
data/data/font/68
ADDED
Binary file
|
data/data/font/69
ADDED
Binary file
|
data/data/font/6a
ADDED
Binary file
|
data/data/font/6b
ADDED
Binary file
|
data/data/font/6c
ADDED
Binary file
|
data/data/font/6d
ADDED
Binary file
|
data/data/font/6e
ADDED
Binary file
|
data/data/font/6f
ADDED
Binary file
|
data/data/font/70
ADDED
Binary file
|
data/data/font/71
ADDED
Binary file
|
data/data/font/72
ADDED
Binary file
|
data/data/font/73
ADDED
Binary file
|
data/data/font/74
ADDED
Binary file
|
data/data/font/75
ADDED
Binary file
|
data/data/font/76
ADDED
Binary file
|
data/data/font/77
ADDED
Binary file
|
data/data/font/78
ADDED
Binary file
|
data/data/font/79
ADDED
Binary file
|
data/data/font/7a
ADDED
Binary file
|
data/data/font/7b
ADDED
Binary file
|
data/data/font/7c
ADDED
Binary file
|
data/data/font/7d
ADDED
Binary file
|
data/data/font/7e
ADDED
Binary file
|
data/data/font/7f
ADDED
Binary file
|
data/data/font/80
ADDED
Binary file
|
data/data/font/81
ADDED
Binary file
|
data/data/font/82
ADDED
Binary file
|
data/data/font/83
ADDED
Binary file
|
data/data/font/84
ADDED
Binary file
|
data/data/font/85
ADDED
Binary file
|
data/data/font/86
ADDED
Binary file
|
data/data/font/87
ADDED
Binary file
|
data/data/font/88
ADDED
Binary file
|
data/data/font/89
ADDED
Binary file
|
data/data/font/8a
ADDED
Binary file
|
data/data/font/8b
ADDED
Binary file
|
data/data/font/8c
ADDED
Binary file
|
data/data/font/8d
ADDED
Binary file
|
data/data/font/8e
ADDED
Binary file
|
data/data/font/8f
ADDED
Binary file
|
data/data/font/90
ADDED
Binary file
|
data/data/font/91
ADDED
Binary file
|
data/data/font/92
ADDED
Binary file
|
data/data/font/93
ADDED
Binary file
|
data/data/font/94
ADDED
Binary file
|
data/data/font/95
ADDED
Binary file
|
data/data/font/96
ADDED
Binary file
|
data/data/font/97
ADDED
Binary file
|
data/data/font/98
ADDED
Binary file
|
data/data/font/99
ADDED
Binary file
|
data/data/font/9a
ADDED
Binary file
|
data/data/font/9b
ADDED
Binary file
|
data/data/font/9c
ADDED
Binary file
|