rixmap 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 +7 -0
- data/LICENSE.txt +38 -0
- data/README.markdown +74 -0
- data/Rakefile +156 -0
- data/lib/rixmap/format/bmp.rb +326 -0
- data/lib/rixmap/format/pcx.rb +438 -0
- data/lib/rixmap/format/png/chunk.rb +239 -0
- data/lib/rixmap/format/png/imageio.rb +288 -0
- data/lib/rixmap/format/png.rb +78 -0
- data/lib/rixmap/format/xpm.rb +446 -0
- data/lib/rixmap/format.rb +10 -0
- data/lib/rixmap/version.rb +26 -0
- data/lib/rixmap.rb +24 -0
- data/spec/binary_spec.rb +12 -0
- data/spec/color_spec.rb +76 -0
- data/spec/image_spec.rb +297 -0
- data/spec/mode_spec.rb +71 -0
- data/spec/palette_spec.rb +77 -0
- data/src/chollas/LICENSE.txt +38 -0
- data/src/chollas/README.md +23 -0
- data/src/chollas/alloc.hxx +62 -0
- data/src/chollas/endian.hxx +42 -0
- data/src/chollas/raser.hxx +113 -0
- data/src/chollas/utilities.hxx +58 -0
- data/src/extconf.rb +47 -0
- data/src/rixmap/binary.hxx +19 -0
- data/src/rixmap/channel.hxx +42 -0
- data/src/rixmap/color.hxx +222 -0
- data/src/rixmap/common.hxx +58 -0
- data/src/rixmap/image.hxx +371 -0
- data/src/rixmap/mode.hxx +351 -0
- data/src/rixmap/palette.hxx +220 -0
- data/src/rixmap.hxx +19 -0
- data/src/rixmapcore.cxx +3209 -0
- data/src/rixmapcore.hxx +27 -0
- data/src/rixmapio.cxx +652 -0
- data/src/rixmapio.hxx +25 -0
- data/src/rixmapmain.cxx +24 -0
- data/test/test_bmp.rb +139 -0
- data/test/test_pcx.rb +172 -0
- data/test/test_png.rb +136 -0
- data/test/test_xpm.rb +73 -0
- metadata +128 -0
data/src/rixmapmain.cxx
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
// -*- coding: utf-8 -*-
|
2
|
+
/**
|
3
|
+
* Rixmap - A Ruby Pixmap Imaging Library -
|
4
|
+
*
|
5
|
+
* Rixmapのメインファイル.
|
6
|
+
* ライブラリの初期化ルーチンの呼び出しを定義します.
|
7
|
+
*/
|
8
|
+
#include <ruby.h>
|
9
|
+
#include "rixmapcore.hxx"
|
10
|
+
#include "rixmapio.hxx"
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Rixmapエントリポイント
|
14
|
+
*/
|
15
|
+
extern "C" void Init_rixmap(void) {
|
16
|
+
// 初期化処理実行
|
17
|
+
RixmapCore_Init();
|
18
|
+
RixmapIO_Init();
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
//============================================================================//
|
23
|
+
// $Id: rixmapmain.cxx,v 57b1fb2cd6a6 2014/04/20 12:21:27 chikuchikugonzalez $
|
24
|
+
// vim: set sts=4 ts=4 sw=4 expandtab foldmethod=marker:
|
data/test/test_bmp.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# BMP形式テストスクリプト
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require_relative '../lib/rixmap'
|
7
|
+
require_relative '../lib/rixmap/format/bmp'
|
8
|
+
|
9
|
+
class TestBMPIndexedImage < MiniTest::Unit::TestCase
|
10
|
+
def setup()
|
11
|
+
@palette = Rixmap::Palette.new(256)
|
12
|
+
@image = Rixmap::Image.new(Rixmap::INDEXED, 256, 256, :palette => @palette)
|
13
|
+
n = 0
|
14
|
+
(1..16).each do |i|
|
15
|
+
(1..16).each do |j|
|
16
|
+
i2 = (i - 1) * 16
|
17
|
+
j2 = (j - 1) * 16
|
18
|
+
r = (255 - (Math.sqrt((255 - i2) ** 2 + j2 ** 2)))
|
19
|
+
g = (255 - (Math.sqrt((255 - i2) ** 2 + (255 - j2) ** 2)))
|
20
|
+
b = (255 - (Math.sqrt(i2 ** 2 + j2 ** 2)))
|
21
|
+
@palette[n] = [r, g, b, 255]
|
22
|
+
(((i - 1) * 16)...(i * 16)).each do |x|
|
23
|
+
(((j - 1) * 16)...(j * 16)).each do |y|
|
24
|
+
@image[x, y] = n
|
25
|
+
end
|
26
|
+
end
|
27
|
+
n += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# 通常IO
|
33
|
+
def test_normal()
|
34
|
+
iio = Rixmap::ImageIO.new(:BMP)
|
35
|
+
iio.save('indexed.bmp', @image)
|
36
|
+
img = iio.open('indexed.bmp')
|
37
|
+
assert_equal(@image, img)
|
38
|
+
end
|
39
|
+
|
40
|
+
# TODO 圧縮版を作る
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestBMPGrayScaleImage < MiniTest::Unit::TestCase
|
44
|
+
def setup()
|
45
|
+
@image = Rixmap::Image.new(Rixmap::GRAYSCALE, 256, 256)
|
46
|
+
256.times do |i|
|
47
|
+
256.times do |j|
|
48
|
+
l = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
49
|
+
@image[i, j] = l
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# 通常IO
|
55
|
+
def test_normal()
|
56
|
+
iio = Rixmap::ImageIO.new(:BMP)
|
57
|
+
iio.save('grayscale.bmp', @image)
|
58
|
+
img = iio.open('grayscale.bmp')
|
59
|
+
assert_equal(@image, img)
|
60
|
+
end
|
61
|
+
|
62
|
+
# TODO 圧縮版を作る
|
63
|
+
end
|
64
|
+
|
65
|
+
class TestBMPGrayAlphaImage < MiniTest::Unit::TestCase
|
66
|
+
def setup()
|
67
|
+
@image = Rixmap::Image.new(Rixmap::GRAYALPHA, 256, 256)
|
68
|
+
256.times do |i|
|
69
|
+
256.times do |j|
|
70
|
+
l = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
71
|
+
a = (255 - (Math.sqrt(i ** 2 + (255 - j) ** 2)))
|
72
|
+
@image[i, j] = [l, a]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# 通常IO
|
78
|
+
def test_normal()
|
79
|
+
iio = Rixmap::ImageIO.new(:BMP)
|
80
|
+
iio.save('grayalpha.bmp', @image)
|
81
|
+
img = iio.open('grayalpha.bmp')
|
82
|
+
assert_equal(@image, img)
|
83
|
+
end
|
84
|
+
|
85
|
+
# TODO 圧縮版を作る
|
86
|
+
end
|
87
|
+
|
88
|
+
class TestBMPRGBImage < MiniTest::Unit::TestCase
|
89
|
+
def setup()
|
90
|
+
@image = Rixmap::Image.new(Rixmap::RGB, 256, 256)
|
91
|
+
256.times do |i|
|
92
|
+
256.times do |j|
|
93
|
+
r = (255 - (Math.sqrt((255 - i) ** 2 + j ** 2)))
|
94
|
+
g = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
95
|
+
b = (255 - (Math.sqrt(i ** 2 + j ** 2)))
|
96
|
+
@image[i, j] = [r, g, b]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# 通常IO
|
102
|
+
def test_normal()
|
103
|
+
iio = Rixmap::ImageIO.new(:BMP)
|
104
|
+
iio.save('rgb.bmp', @image)
|
105
|
+
img = iio.open('rgb.bmp')
|
106
|
+
assert_equal(@image, img)
|
107
|
+
end
|
108
|
+
|
109
|
+
# TODO 圧縮版を作る
|
110
|
+
end
|
111
|
+
|
112
|
+
class TestBMPRGBAImage < MiniTest::Unit::TestCase
|
113
|
+
def setup()
|
114
|
+
@image = Rixmap::Image.new(Rixmap::RGBA, 256, 256)
|
115
|
+
256.times do |i|
|
116
|
+
256.times do |j|
|
117
|
+
r = (255 - (Math.sqrt((255 - i) ** 2 + j ** 2)))
|
118
|
+
g = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
119
|
+
b = (255 - (Math.sqrt(i ** 2 + j ** 2)))
|
120
|
+
a = (255 - (Math.sqrt(i ** 2 + (255 - j) ** 2)))
|
121
|
+
@image[i, j] = [r, g, b, a]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# 通常IO
|
127
|
+
def test_normal()
|
128
|
+
iio = Rixmap::ImageIO.new(:BMP)
|
129
|
+
iio.save('rgba.bmp', @image)
|
130
|
+
img = iio.open('rgba.bmp')
|
131
|
+
assert_equal(@image, img)
|
132
|
+
end
|
133
|
+
|
134
|
+
# TODO 圧縮版を作る
|
135
|
+
end
|
136
|
+
|
137
|
+
#==============================================================================#
|
138
|
+
# $Id: test_bmp.rb,v a43e566390cb 2014/04/16 16:03:22 chikuchikugonzalez $
|
139
|
+
# vim: set sts=2 ts=2 sw=2 expandtab:
|
data/test/test_pcx.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# PCX形式テストスクリプト
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require_relative '../lib/rixmap'
|
7
|
+
require_relative '../lib/rixmap/format/pcx'
|
8
|
+
|
9
|
+
class TestPCX8IndexedImage < MiniTest::Unit::TestCase
|
10
|
+
def setup()
|
11
|
+
@palette = Rixmap::Palette.new(256)
|
12
|
+
@image = Rixmap::Image.new(Rixmap::INDEXED, 256, 256, :palette => @palette)
|
13
|
+
n = 0
|
14
|
+
(1..16).each do |i|
|
15
|
+
(1..16).each do |j|
|
16
|
+
i2 = (i - 1) * 16
|
17
|
+
j2 = (j - 1) * 16
|
18
|
+
r = (255 - (Math.sqrt((255 - i2) ** 2 + j2 ** 2)))
|
19
|
+
g = (255 - (Math.sqrt((255 - i2) ** 2 + (255 - j2) ** 2)))
|
20
|
+
b = (255 - (Math.sqrt(i2 ** 2 + j2 ** 2)))
|
21
|
+
@palette[n] = [r, g, b, 255]
|
22
|
+
(((i - 1) * 16)...(i * 16)).each do |x|
|
23
|
+
(((j - 1) * 16)...(j * 16)).each do |y|
|
24
|
+
@image[x, y] = n
|
25
|
+
end
|
26
|
+
end
|
27
|
+
n += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# 無圧縮 (読み込めないかも)
|
33
|
+
def test_norle()
|
34
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => false)
|
35
|
+
iio.save('indexed1.pcx', @image)
|
36
|
+
img = iio.open('indexed1.pcx')
|
37
|
+
assert_equal(@image, img)
|
38
|
+
end
|
39
|
+
|
40
|
+
# 圧縮 (基本はこっち)
|
41
|
+
def test_rle()
|
42
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => true)
|
43
|
+
iio.save('indexed2.pcx', @image)
|
44
|
+
img = iio.open('indexed2.pcx')
|
45
|
+
assert_equal(@image, img)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class TestPCX8GrayScaleImage < MiniTest::Unit::TestCase
|
50
|
+
def setup()
|
51
|
+
@image = Rixmap::Image.new(Rixmap::GRAYSCALE, 256, 256)
|
52
|
+
256.times do |i|
|
53
|
+
256.times do |j|
|
54
|
+
l = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
55
|
+
@image[i, j] = l
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# 無圧縮 (読み込めないかも)
|
61
|
+
def test_norle()
|
62
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => false)
|
63
|
+
iio.save('grayscale1.pcx', @image)
|
64
|
+
img = iio.open('grayscale1.pcx')
|
65
|
+
assert_equal(@image, img)
|
66
|
+
end
|
67
|
+
|
68
|
+
# 圧縮 (基本はこっち)
|
69
|
+
def test_rle()
|
70
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => true)
|
71
|
+
iio.save('grayscale2.pcx', @image)
|
72
|
+
img = iio.open('grayscale2.pcx')
|
73
|
+
assert_equal(@image, img)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class TestPCX16GrayAlphaImage < MiniTest::Unit::TestCase
|
78
|
+
def setup()
|
79
|
+
@image = Rixmap::Image.new(Rixmap::GRAYALPHA, 256, 256)
|
80
|
+
256.times do |i|
|
81
|
+
256.times do |j|
|
82
|
+
l = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
83
|
+
a = (255 - (Math.sqrt(i ** 2 + (255 - j) ** 2)))
|
84
|
+
@image[i, j] = [l, a]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# 無圧縮 (読み込めないかも)
|
90
|
+
def test_norle()
|
91
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => false)
|
92
|
+
iio.save('grayalpha1.pcx', @image)
|
93
|
+
img = iio.open('grayalpha1.pcx')
|
94
|
+
assert_equal(@image, img)
|
95
|
+
end
|
96
|
+
|
97
|
+
# 圧縮 (基本はこっち)
|
98
|
+
def test_rle()
|
99
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => true)
|
100
|
+
iio.save('grayalpha2.pcx', @image)
|
101
|
+
img = iio.open('grayalpha2.pcx')
|
102
|
+
assert_equal(@image, img)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class TestPCX24Image < MiniTest::Unit::TestCase
|
107
|
+
def setup()
|
108
|
+
@image = Rixmap::Image.new(Rixmap::RGB, 256, 256)
|
109
|
+
256.times do |i|
|
110
|
+
256.times do |j|
|
111
|
+
r = (255 - (Math.sqrt((255 - i) ** 2 + j ** 2)))
|
112
|
+
g = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
113
|
+
b = (255 - (Math.sqrt(i ** 2 + j ** 2)))
|
114
|
+
@image[i, j] = [r, g, b]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# 無圧縮 (読み込めないかも)
|
120
|
+
def test_norle()
|
121
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => false)
|
122
|
+
iio.save('rgb1.pcx', @image)
|
123
|
+
img = iio.open('rgb1.pcx')
|
124
|
+
assert_equal(@image, img)
|
125
|
+
end
|
126
|
+
|
127
|
+
# 圧縮 (基本はこっち)
|
128
|
+
def test_rle()
|
129
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => true)
|
130
|
+
iio.save('rgb2.pcx', @image)
|
131
|
+
img = iio.open('rgb2.pcx')
|
132
|
+
assert_equal(@image, img)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class TestPCX32Image < MiniTest::Unit::TestCase
|
137
|
+
def setup()
|
138
|
+
@image = Rixmap::Image.new(Rixmap::RGBA, 256, 256)
|
139
|
+
256.times do |i|
|
140
|
+
256.times do |j|
|
141
|
+
r = (255 - (Math.sqrt((255 - i) ** 2 + j ** 2)))
|
142
|
+
g = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
143
|
+
b = (255 - (Math.sqrt(i ** 2 + j ** 2)))
|
144
|
+
a = (255 - (Math.sqrt(i ** 2 + (255 - j) ** 2)))
|
145
|
+
@image[i, j] = [r, g, b, a]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# 無圧縮 (読み込めないかも)
|
151
|
+
def test_norle()
|
152
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => false)
|
153
|
+
iio.save('rgba1.pcx', @image)
|
154
|
+
img = iio.open('rgba1.pcx')
|
155
|
+
assert_equal(@image, img)
|
156
|
+
end
|
157
|
+
|
158
|
+
# 圧縮 (基本はこっち)
|
159
|
+
def test_rle()
|
160
|
+
iio = Rixmap::ImageIO.new(:PCX, :compression => true)
|
161
|
+
iio.save('rgba2.pcx', @image)
|
162
|
+
img = iio.open('rgba2.pcx')
|
163
|
+
assert_equal(@image, img)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# TODO 透明度付と透明度なしを比較するためにImage#convertを実装したら調整しなおすこと
|
168
|
+
|
169
|
+
|
170
|
+
#==============================================================================#
|
171
|
+
# $Id: test_pcx.rb,v ba835388348b 2014/04/05 17:42:32 chikuchikugonzalez $
|
172
|
+
# vim: set sts=2 ts=2 sw=2 expandtab:
|
data/test/test_png.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# PNG形式テストスクリプト
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require_relative '../lib/rixmap'
|
7
|
+
require_relative '../lib/rixmap/format/png'
|
8
|
+
|
9
|
+
class TestPNGIndexedImage < MiniTest::Unit::TestCase
|
10
|
+
def setup()
|
11
|
+
@palette = Rixmap::Palette.new(256)
|
12
|
+
@image = Rixmap::Image.new(Rixmap::INDEXED, 256, 256, :palette => @palette)
|
13
|
+
n = 0
|
14
|
+
(1..16).each do |i|
|
15
|
+
(1..16).each do |j|
|
16
|
+
i2 = (i - 1) * 16
|
17
|
+
j2 = (j - 1) * 16
|
18
|
+
r = (255 - (Math.sqrt((255 - i2) ** 2 + j2 ** 2)))
|
19
|
+
g = (255 - (Math.sqrt((255 - i2) ** 2 + (255 - j2) ** 2)))
|
20
|
+
b = (255 - (Math.sqrt(i2 ** 2 + j2 ** 2)))
|
21
|
+
@palette[n] = [r, g, b, 255]
|
22
|
+
(((i - 1) * 16)...(i * 16)).each do |x|
|
23
|
+
(((j - 1) * 16)...(j * 16)).each do |y|
|
24
|
+
@image[x, y] = n
|
25
|
+
end
|
26
|
+
end
|
27
|
+
n += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# 通常IO
|
33
|
+
def test_normal()
|
34
|
+
iio = Rixmap::ImageIO.new(:PNG)
|
35
|
+
iio.save('indexed.png', @image)
|
36
|
+
img = iio.open('indexed.png')
|
37
|
+
assert_equal(@image, img)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class TestPNGGrayScaleImage < MiniTest::Unit::TestCase
|
42
|
+
def setup()
|
43
|
+
@image = Rixmap::Image.new(Rixmap::GRAYSCALE, 256, 256)
|
44
|
+
256.times do |i|
|
45
|
+
256.times do |j|
|
46
|
+
l = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
47
|
+
@image[i, j] = l
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# 通常IO
|
53
|
+
def test_normal()
|
54
|
+
iio = Rixmap::ImageIO.new(:PNG)
|
55
|
+
iio.save('grayscale.png', @image)
|
56
|
+
img = iio.open('grayscale.png')
|
57
|
+
assert_equal(@image, img)
|
58
|
+
end
|
59
|
+
|
60
|
+
# TODO 圧縮版を作る
|
61
|
+
end
|
62
|
+
|
63
|
+
class TestPNGGrayAlphaImage < MiniTest::Unit::TestCase
|
64
|
+
def setup()
|
65
|
+
@image = Rixmap::Image.new(Rixmap::GRAYALPHA, 256, 256)
|
66
|
+
256.times do |i|
|
67
|
+
256.times do |j|
|
68
|
+
l = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
69
|
+
a = (255 - (Math.sqrt(i ** 2 + (255 - j) ** 2)))
|
70
|
+
@image[i, j] = [l, a]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# 通常IO
|
76
|
+
def test_normal()
|
77
|
+
iio = Rixmap::ImageIO.new(:PNG)
|
78
|
+
iio.save('grayalpha.png', @image)
|
79
|
+
img = iio.open('grayalpha.png')
|
80
|
+
assert_equal(@image, img)
|
81
|
+
end
|
82
|
+
|
83
|
+
# TODO 圧縮版を作る
|
84
|
+
end
|
85
|
+
|
86
|
+
class TestPNGRGBImage < MiniTest::Unit::TestCase
|
87
|
+
def setup()
|
88
|
+
@image = Rixmap::Image.new(Rixmap::RGB, 256, 256)
|
89
|
+
256.times do |i|
|
90
|
+
256.times do |j|
|
91
|
+
r = (255 - (Math.sqrt((255 - i) ** 2 + j ** 2)))
|
92
|
+
g = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
93
|
+
b = (255 - (Math.sqrt(i ** 2 + j ** 2)))
|
94
|
+
@image[i, j] = [r, g, b]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# 通常IO
|
100
|
+
def test_normal()
|
101
|
+
iio = Rixmap::ImageIO.new(:PNG)
|
102
|
+
iio.save('rgb.png', @image)
|
103
|
+
img = iio.open('rgb.png')
|
104
|
+
assert_equal(@image, img)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class TestPNGRGBAImage < MiniTest::Unit::TestCase
|
109
|
+
def setup()
|
110
|
+
@image = Rixmap::Image.new(Rixmap::RGBA, 256, 256)
|
111
|
+
256.times do |i|
|
112
|
+
256.times do |j|
|
113
|
+
r = (255 - (Math.sqrt((255 - i) ** 2 + j ** 2)))
|
114
|
+
g = (255 - (Math.sqrt((255 - i) ** 2 + (255 - j) ** 2)))
|
115
|
+
b = (255 - (Math.sqrt(i ** 2 + j ** 2)))
|
116
|
+
a = (255 - (Math.sqrt(i ** 2 + (255 - j) ** 2)))
|
117
|
+
@image[i, j] = [r, g, b, a]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# 通常IO
|
123
|
+
def test_normal()
|
124
|
+
iio = Rixmap::ImageIO.new(:PNG)
|
125
|
+
iio.save('rgba.png', @image)
|
126
|
+
img = iio.open('rgba.png')
|
127
|
+
assert_equal(@image, img)
|
128
|
+
end
|
129
|
+
|
130
|
+
# TODO 圧縮版を作る
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
#==============================================================================#
|
135
|
+
# $Id: test_png.rb,v c10e98a1e0fa 2014/04/20 08:17:37 chikuchikugonzalez $
|
136
|
+
# vim: set sts=2 ts=2 sw=2 expandtab:
|
data/test/test_xpm.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# XPM形式テストスクリプト
|
4
|
+
require 'minitest/unit'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require_relative '../lib/rixmap'
|
7
|
+
require_relative '../lib/rixmap/format/xpm'
|
8
|
+
|
9
|
+
class TestXPMImage < MiniTest::Unit::TestCase
|
10
|
+
|
11
|
+
def setup()
|
12
|
+
@palette = Rixmap::Palette.new(256)
|
13
|
+
@image = Rixmap::Image.new(Rixmap::INDEXED, 256, 256, :palette => @palette)
|
14
|
+
n = 0
|
15
|
+
(1..16).each do |i|
|
16
|
+
(1..16).each do |j|
|
17
|
+
i2 = (i - 1) * 16
|
18
|
+
j2 = (j - 1) * 16
|
19
|
+
r = (255 - (Math.sqrt((255 - i2) ** 2 + j2 ** 2)))
|
20
|
+
g = (255 - (Math.sqrt((255 - i2) ** 2 + (255 - j2) ** 2)))
|
21
|
+
b = (255 - (Math.sqrt(i2 ** 2 + j2 ** 2)))
|
22
|
+
@palette[n] = [r, g, b, 255]
|
23
|
+
|
24
|
+
(((i - 1) * 16)...(i * 16)).each do |x|
|
25
|
+
(((j - 1) * 16)...(j * 16)).each do |y|
|
26
|
+
@image[x, y] = n
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
n += 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# XPM1形式での読み書き
|
36
|
+
def test_xpm1io()
|
37
|
+
xpm1io = Rixmap::ImageIO.new(:XPM1)
|
38
|
+
xpm1io.save('indexed.xpm1', @image)
|
39
|
+
xpm1img = xpm1io.open('indexed.xpm1')
|
40
|
+
|
41
|
+
256.times do |x|
|
42
|
+
256.times do |y|
|
43
|
+
assert_equal(@image[x, y], xpm1img[x, y])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
256.times do |n|
|
47
|
+
assert_equal(@palette[n], xpm1img.palette[n])
|
48
|
+
end
|
49
|
+
assert_equal(@image, xpm1img)
|
50
|
+
end
|
51
|
+
|
52
|
+
# XPM2形式での読み書き
|
53
|
+
def test_xpm2io()
|
54
|
+
xpm2io = Rixmap::ImageIO.new(:XPM2)
|
55
|
+
xpm2io.save('indexed.xpm2', @image)
|
56
|
+
xpm2img = xpm2io.open('indexed.xpm2')
|
57
|
+
|
58
|
+
256.times do |x|
|
59
|
+
256.times do |y|
|
60
|
+
assert_equal(@image[x, y], xpm2img[x, y])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
256.times do |n|
|
64
|
+
assert_equal(@palette[n], xpm2img.palette[n])
|
65
|
+
end
|
66
|
+
assert_equal(@image, xpm2img)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
#==============================================================================#
|
72
|
+
# $Id: test_xpm.rb,v 1a9c48b24754 2014/03/30 08:34:48 chikuchikugonzalez $
|
73
|
+
# vim: set sts=2 ts=2 sw=2 expandtab:
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rixmap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- chikuchikugonzalez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - <
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - <
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: |2
|
56
|
+
Rixmap is a cheap pixel-map imaging library for Ruby Language
|
57
|
+
email: chikuchikugonzalez@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- src/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- src/rixmapcore.cxx
|
64
|
+
- src/rixmapio.cxx
|
65
|
+
- src/rixmapmain.cxx
|
66
|
+
- src/rixmap.hxx
|
67
|
+
- src/rixmapcore.hxx
|
68
|
+
- src/rixmapio.hxx
|
69
|
+
- src/rixmap/binary.hxx
|
70
|
+
- src/rixmap/channel.hxx
|
71
|
+
- src/rixmap/color.hxx
|
72
|
+
- src/rixmap/common.hxx
|
73
|
+
- src/rixmap/image.hxx
|
74
|
+
- src/rixmap/mode.hxx
|
75
|
+
- src/rixmap/palette.hxx
|
76
|
+
- src/chollas/LICENSE.txt
|
77
|
+
- src/chollas/README.md
|
78
|
+
- src/chollas/alloc.hxx
|
79
|
+
- src/chollas/endian.hxx
|
80
|
+
- src/chollas/raser.hxx
|
81
|
+
- src/chollas/utilities.hxx
|
82
|
+
- lib/rixmap/format/bmp.rb
|
83
|
+
- lib/rixmap/format/pcx.rb
|
84
|
+
- lib/rixmap/format/png/chunk.rb
|
85
|
+
- lib/rixmap/format/png/imageio.rb
|
86
|
+
- lib/rixmap/format/png.rb
|
87
|
+
- lib/rixmap/format/xpm.rb
|
88
|
+
- lib/rixmap/format.rb
|
89
|
+
- lib/rixmap/version.rb
|
90
|
+
- lib/rixmap.rb
|
91
|
+
- test/test_bmp.rb
|
92
|
+
- test/test_pcx.rb
|
93
|
+
- test/test_png.rb
|
94
|
+
- test/test_xpm.rb
|
95
|
+
- spec/binary_spec.rb
|
96
|
+
- spec/color_spec.rb
|
97
|
+
- spec/image_spec.rb
|
98
|
+
- spec/mode_spec.rb
|
99
|
+
- spec/palette_spec.rb
|
100
|
+
- Rakefile
|
101
|
+
- README.markdown
|
102
|
+
- LICENSE.txt
|
103
|
+
- src/extconf.rb
|
104
|
+
homepage: https://bitbucket.org/chiku2gonzalez/rixmap
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.9.3
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.0.14
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: A Pixmap Imaging Library for Ruby
|
128
|
+
test_files: []
|