pikl 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -3
- data/Manifest.txt +1 -1
- data/README.txt +16 -4
- data/Rakefile +1 -1
- data/config/hoe.rb +4 -8
- data/ext/pikl/extconf.rb +3 -2
- data/ext/pikl/pikl.h +1 -1
- data/ext/pikl/pikl_effect.h +0 -4
- data/ext/pikl/pikl_private.h +3 -1
- data/ext/pikl/pikl_rotate.c +12 -12
- data/lib/pikl/const.rb +10 -5
- data/lib/pikl/ext.rb +4 -1
- data/lib/pikl/image.rb +13 -2
- data/lib/pikl/pikl.dll +0 -0
- data/lib/pikl/version.rb +1 -1
- data/test/sample.jpg +0 -0
- data/test/test_pikl_image.rb +8 -2
- metadata +48 -42
- data/test/test_pikl.rb +0 -13
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
= pikl
|
2
2
|
|
3
|
-
Pikl is an image librarry. This library aims
|
3
|
+
Pikl is an image librarry for ruby. This library aims easily image processing. Supports JPEG, PNG and BITMAP.
|
4
4
|
|
5
5
|
=== Installation of pikl
|
6
6
|
|
7
7
|
The simplest way is to install the gem:
|
8
8
|
|
9
9
|
$ sudo gem install pikl
|
10
|
+
|
11
|
+
To use option for libjpeg and libpng directories:
|
12
|
+
|
13
|
+
$ sudo gem install pikl -- --with-opt-dir=path/to/libraries
|
10
14
|
|
11
15
|
== SYNOPSIS:
|
12
16
|
|
17
|
+
Basic use of pikl:
|
13
18
|
require "pikl"
|
14
19
|
Pikl::Image.open('path/to/image.jpg') do |img|
|
15
20
|
img.trim(10,5,-10,-5)
|
16
21
|
img.save('path/to/output.png', :png)
|
17
22
|
end
|
18
23
|
|
24
|
+
Use method chain for processing image:
|
25
|
+
require "pikl"
|
26
|
+
Pikl::Image.open('path/to/image.jpg') do |img|
|
27
|
+
img.resize(120,:auto).rotate(90).save('path/to/output.png')
|
28
|
+
end
|
29
|
+
|
30
|
+
|
19
31
|
== REQUIREMENTS:
|
20
32
|
|
21
33
|
Currently, pikl-core (implemented with C) depends on the following libraries:
|
@@ -23,14 +35,14 @@ Currently, pikl-core (implemented with C) depends on the following libraries:
|
|
23
35
|
* libjpeg
|
24
36
|
* libpng
|
25
37
|
|
26
|
-
notice: pikl use binary library on windows. so these libraries aren't necessary.
|
38
|
+
notice: pikl use binary library on windows. so these libraries aren't necessary on windows.
|
27
39
|
|
28
40
|
== LICENSE:
|
29
41
|
|
30
42
|
(The MIT License)
|
31
43
|
|
32
|
-
Copyright (c) 2008 pikl Ryota Maruko
|
33
|
-
Copyright (c) 2008
|
44
|
+
Copyright (c) 2008 pikl.rb Ryota Maruko
|
45
|
+
Copyright (c) 2008 pikl.so Keiko Soejima
|
34
46
|
|
35
47
|
Permission is hereby granted, free of charge, to any person obtaining
|
36
48
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
data/config/hoe.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'pikl/version'
|
2
2
|
|
3
3
|
AUTHOR = 'Ryota Maruko' # can also be an array of Authors
|
4
|
-
EMAIL = "
|
5
|
-
DESCRIPTION = "
|
4
|
+
EMAIL = ""
|
5
|
+
DESCRIPTION = "Pikl is an image librarry for ruby. This library aims easily image processing. Supports JPEG, PNG and BITMAP."
|
6
6
|
GEM_NAME = 'pikl' # what ppl will type to install your gem
|
7
7
|
RUBYFORGE_PROJECT = 'pikl' # The unix name for your project
|
8
8
|
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
@@ -27,7 +27,6 @@ Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
27
27
|
RUBYFORGE_USERNAME.replace @config["username"]
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
30
|
REV = nil
|
32
31
|
# UNCOMMENT IF REQUIRED:
|
33
32
|
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
@@ -59,11 +58,8 @@ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
59
58
|
# == Optional
|
60
59
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
61
60
|
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
62
|
-
|
63
|
-
|
64
|
-
:extensions => ['ext/pikl/extconf.rb'],
|
65
|
-
} # A hash of extra values to set in the gemspec.
|
66
|
-
|
61
|
+
p.spec_extras = (PACKAGE_PLATFORM =~ /mswin32/) ? {} : { :extensions => ['ext/pikl/extconf.rb'] }
|
62
|
+
# A hash of extra values to set in the gemspec.
|
67
63
|
end
|
68
64
|
|
69
65
|
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
data/ext/pikl/extconf.rb
CHANGED
@@ -6,11 +6,12 @@
|
|
6
6
|
--with-png-include=dir
|
7
7
|
--with-png-lib=dir
|
8
8
|
=end
|
9
|
+
|
9
10
|
require 'mkmf'
|
11
|
+
require 'rbconfig'
|
10
12
|
|
11
13
|
dir_config('jpeg')
|
12
14
|
dir_config('png')
|
13
|
-
if have_header('jpeglib.h')
|
15
|
+
if have_header('jpeglib.h') && have_library('jpeg') && have_header('png.h') && have_library('png')
|
14
16
|
create_makefile('pikl/pikl')
|
15
17
|
end
|
16
|
-
|
data/ext/pikl/pikl.h
CHANGED
@@ -124,7 +124,7 @@ PKLExport int pkl_height(PKLImage pkl);
|
|
124
124
|
PKLExport int pkl_trim(PKLImage pkl, int sx, int sy, int width, int height);
|
125
125
|
|
126
126
|
/*!
|
127
|
-
|
127
|
+
左回り90度単位で回転します。<br>
|
128
128
|
@param pkl [in] PKLImageオブジェクト
|
129
129
|
@param angle [in] 回転角度(PKL_ANGLE参照)
|
130
130
|
@return 成功した場合は0。失敗した場合は真を返します。
|
data/ext/pikl/pikl_effect.h
CHANGED
data/ext/pikl/pikl_private.h
CHANGED
@@ -5,7 +5,9 @@
|
|
5
5
|
#define PKL_RGB(v) v<0?0:v>255?255:v
|
6
6
|
#define PKL_CHANNEL 4
|
7
7
|
#define PKL_COLOR 256
|
8
|
-
|
8
|
+
#ifndef M_PI
|
9
|
+
#define M_PI 3.14159265358979323846
|
10
|
+
#endif
|
9
11
|
//=============================================================================
|
10
12
|
// PKLImage
|
11
13
|
//=============================================================================
|
data/ext/pikl/pikl_rotate.c
CHANGED
@@ -15,14 +15,14 @@ PKLExport int pkl_rotate(PKLImage pkl, PKL_ANGLE angle)
|
|
15
15
|
case PKL_ANGLE_000:
|
16
16
|
return(0);
|
17
17
|
case PKL_ANGLE_090:
|
18
|
-
rcos =
|
19
|
-
rsin =
|
18
|
+
rcos = 0;
|
19
|
+
rsin = 1;
|
20
20
|
width = pkl->height;
|
21
21
|
height = pkl->width;
|
22
|
-
sx =
|
23
|
-
sy =
|
24
|
-
ex =
|
25
|
-
ey =
|
22
|
+
sx = 0;
|
23
|
+
sy = -(pkl->width-1);
|
24
|
+
ex = pkl->height-1;
|
25
|
+
ey = 0;
|
26
26
|
break;
|
27
27
|
case PKL_ANGLE_180:
|
28
28
|
rcos = -1;
|
@@ -35,14 +35,14 @@ PKLExport int pkl_rotate(PKLImage pkl, PKL_ANGLE angle)
|
|
35
35
|
ey = 0;
|
36
36
|
break;
|
37
37
|
case PKL_ANGLE_270:
|
38
|
-
rcos =
|
39
|
-
rsin = 1;
|
38
|
+
rcos = 0;
|
39
|
+
rsin = -1;
|
40
40
|
width = pkl->height;
|
41
41
|
height = pkl->width;
|
42
|
-
sx =
|
43
|
-
sy =
|
44
|
-
ex =
|
45
|
-
ey =
|
42
|
+
sx = -(pkl->height-1);
|
43
|
+
sy = 0;
|
44
|
+
ex = 0;
|
45
|
+
ey = pkl->width-1;
|
46
46
|
break;
|
47
47
|
default:
|
48
48
|
return(1);
|
data/lib/pikl/const.rb
CHANGED
@@ -12,17 +12,22 @@ module Pikl
|
|
12
12
|
ANGLE270 = 3
|
13
13
|
|
14
14
|
SAMPLE_NN = 1 #nearest neighbor
|
15
|
-
|
16
|
-
|
15
|
+
SAMPLE_BL = 2 #bilinear
|
16
|
+
SAMPLE_BC = 3 #bicubic
|
17
17
|
SAMPLE_PA = 4 #pixcel average(reduce only)
|
18
18
|
SAMPLE_LZ = 5 #lanczos
|
19
|
-
|
19
|
+
|
20
20
|
SAMPLES = {
|
21
21
|
:nearest_neighbor => SAMPLE_NN,
|
22
|
+
:bilinear => SAMPLE_BL,
|
22
23
|
:bicubic => SAMPLE_BC,
|
23
|
-
:bicubic2 => SAMPLE_BC2,
|
24
24
|
:pixcel_averate => SAMPLE_PA,
|
25
|
-
:
|
25
|
+
:lanczos => SAMPLE_LZ,
|
26
|
+
:nn => SAMPLE_NN,
|
27
|
+
:bl => SAMPLE_BL,
|
28
|
+
:bc => SAMPLE_BC,
|
29
|
+
:pa => SAMPLE_PA,
|
30
|
+
:lz => SAMPLE_LZ,
|
26
31
|
}
|
27
32
|
|
28
33
|
ROTATE_ANGLE = {
|
data/lib/pikl/ext.rb
CHANGED
@@ -5,7 +5,9 @@ module Pikl
|
|
5
5
|
|
6
6
|
module Ext
|
7
7
|
extend DL::Importable
|
8
|
-
|
8
|
+
|
9
|
+
dlext = (RbConfig::CONFIG["host_os"] == 'mswin32') ? 'dll' : RbConfig::CONFIG['DLEXT']
|
10
|
+
dlload "#{File.dirname(__FILE__)}/pikl.#{dlext}"
|
9
11
|
|
10
12
|
typealias("KKImage", "void")
|
11
13
|
typealias("PKL_FORMAT", "int")
|
@@ -28,5 +30,6 @@ module Pikl
|
|
28
30
|
extern "int pkl_brightness(PKLImage*, int)"
|
29
31
|
extern "int pkl_hls(PKLImage*, double, double, double)"
|
30
32
|
extern "int pkl_gamma(PKLImage*, double)"
|
33
|
+
|
31
34
|
end
|
32
35
|
end
|
data/lib/pikl/image.rb
CHANGED
@@ -22,7 +22,7 @@ module Pikl
|
|
22
22
|
|
23
23
|
def save(outpath, format = nil, compress = nil)
|
24
24
|
raise Pikl::ImageProcessException.new("image already closed.") unless @pkl_image
|
25
|
-
format ||=
|
25
|
+
format ||= (split_extensions(outpath) || @format)
|
26
26
|
validate_format(format)
|
27
27
|
if compress
|
28
28
|
validate_compress(compress)
|
@@ -30,6 +30,7 @@ module Pikl
|
|
30
30
|
end
|
31
31
|
Ext.pkl_save(@pkl_image, File.expand_path(outpath), EXTENSIONS_FORMATS[format.to_s] || format.to_i)
|
32
32
|
self.close unless(@block)
|
33
|
+
@pkl_image
|
33
34
|
end
|
34
35
|
|
35
36
|
def close()
|
@@ -55,6 +56,8 @@ module Pikl
|
|
55
56
|
dist_y = trim_dist(y, self.height, dist_y)
|
56
57
|
|
57
58
|
Ext.pkl_trim(@pkl_image, x, y, dist_x, dist_y)
|
59
|
+
|
60
|
+
self
|
58
61
|
end
|
59
62
|
|
60
63
|
def trim_dist(start, dist_from, dist_to)
|
@@ -70,9 +73,10 @@ module Pikl
|
|
70
73
|
def rotate(angle)
|
71
74
|
validate_rotate(angle)
|
72
75
|
Ext.pkl_rotate(@pkl_image, ROTATE_ANGLE[angle.to_i])
|
76
|
+
self
|
73
77
|
end
|
74
78
|
|
75
|
-
def resize(width, height, sample = :
|
79
|
+
def resize(width, height, sample = :pixcel_averate)
|
76
80
|
validate_auto(width,height)
|
77
81
|
|
78
82
|
case sample.class.name
|
@@ -86,6 +90,7 @@ module Pikl
|
|
86
90
|
validate_resize(width, height)
|
87
91
|
|
88
92
|
Ext.pkl_resize(@pkl_image, width, height, sample)
|
93
|
+
self
|
89
94
|
end
|
90
95
|
|
91
96
|
# threshold=0-255
|
@@ -101,6 +106,7 @@ module Pikl
|
|
101
106
|
# ※画質によりこの通りではありません。-10..10の範囲より小さくなる可能性があります。
|
102
107
|
def unshapmask(threshold, edge)
|
103
108
|
Ext.pkl_unsharp(@pkl_image, threshold.to_i, edge.to_f)
|
109
|
+
self
|
104
110
|
end
|
105
111
|
|
106
112
|
# コントラスト調整
|
@@ -114,6 +120,7 @@ module Pikl
|
|
114
120
|
# * rateが0未満の時は直線的に平坦化されます
|
115
121
|
def contrast(rate)
|
116
122
|
Ext.pkl_contrast(@pkl_image, rate.to_f)
|
123
|
+
self
|
117
124
|
end
|
118
125
|
|
119
126
|
# レベル補正
|
@@ -123,6 +130,7 @@ module Pikl
|
|
123
130
|
# high = 全ピクセル数に対して、切り捨てる明るい色の総数の割合(0-100%)
|
124
131
|
def level(low, high, coeff)
|
125
132
|
Ext.pkl_level(@pkl_image, low.to_f, high.to_f, coeff.to_f)
|
133
|
+
self
|
126
134
|
end
|
127
135
|
|
128
136
|
# 明るさ調整
|
@@ -131,6 +139,7 @@ module Pikl
|
|
131
139
|
# colorに-255を指定すると、ただの黒い画像になります。
|
132
140
|
def brightness(color)
|
133
141
|
Ext.pkl_brightness(@pkl_image, color.to_i)
|
142
|
+
self
|
134
143
|
end
|
135
144
|
|
136
145
|
# 輝度(明るさ)・彩度(鮮やかさ)・色相(色合い)調整
|
@@ -140,6 +149,7 @@ module Pikl
|
|
140
149
|
# hd(色相) 360.0度回転(R=113.2/Ye=173.0/G=225.0/Cy=293.2/B=353.0/Mg=45.0).360の倍数では変化なし
|
141
150
|
def hls(ym, sm ,hd)
|
142
151
|
Ext.pkl_hls(@pkl_image, ym.to_f, sm.to_f, hd.to_f)
|
152
|
+
self
|
143
153
|
end
|
144
154
|
|
145
155
|
# ガンマ補正
|
@@ -150,6 +160,7 @@ module Pikl
|
|
150
160
|
# 1.0を指定した時は調整されません。
|
151
161
|
def gamma(gm)
|
152
162
|
Ext.pkl_gamma(@pkl_image, gm.to_f)
|
163
|
+
self
|
153
164
|
end
|
154
165
|
|
155
166
|
# regular expressions to try for identifying extensions
|
data/lib/pikl/pikl.dll
ADDED
Binary file
|
data/lib/pikl/version.rb
CHANGED
data/test/sample.jpg
CHANGED
Binary file
|
data/test/test_pikl_image.rb
CHANGED
@@ -5,8 +5,8 @@ class TestPiklImage < Test::Unit::TestCase
|
|
5
5
|
SAMPLE_IMAGE = File.dirname(__FILE__) + '/sample.jpg'
|
6
6
|
SAMPLE_OUTPUT = File.dirname(__FILE__) + '/output.jpg'
|
7
7
|
|
8
|
-
SAMPLE_IMAGE_W =
|
9
|
-
SAMPLE_IMAGE_H =
|
8
|
+
SAMPLE_IMAGE_W = 120
|
9
|
+
SAMPLE_IMAGE_H = 160
|
10
10
|
|
11
11
|
def setup
|
12
12
|
|
@@ -258,5 +258,11 @@ class TestPiklImage < Test::Unit::TestCase
|
|
258
258
|
img.save(SAMPLE_OUTPUT,Pikl::JPEG,5)
|
259
259
|
end
|
260
260
|
end
|
261
|
+
|
262
|
+
def test_method_chain
|
263
|
+
Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
264
|
+
img.trim(5,10,:auto,:auto).rotate(90).resize(50,:auto).unshapmask(10,3).contrast(10).level(5,5,1.2).brightness(10).hls(0.1,0.1,355).gamma(1.2).save(SAMPLE_OUTPUT)
|
265
|
+
end
|
266
|
+
end
|
261
267
|
|
262
268
|
end
|
metadata
CHANGED
@@ -1,35 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.2
|
3
|
-
specification_version: 1
|
4
2
|
name: pikl
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2008-05-01 00:00:00 +09:00
|
8
|
-
summary: Simple Image Lib.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
- ext
|
12
|
-
email:
|
13
|
-
- FIXME email
|
14
|
-
homepage: http://pikl.rubyforge.org
|
15
|
-
rubyforge_project: pikl
|
16
|
-
description: Simple Image Lib.
|
17
|
-
autorequire:
|
18
|
-
default_executable:
|
19
|
-
bindir: bin
|
20
|
-
has_rdoc: true
|
21
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
22
|
-
requirements:
|
23
|
-
- - ">"
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: 0.0.0
|
26
|
-
version:
|
4
|
+
version: 0.2.0
|
27
5
|
platform: ruby
|
28
|
-
signing_key:
|
29
|
-
cert_chain:
|
30
|
-
post_install_message:
|
31
6
|
authors:
|
32
7
|
- Ryota Maruko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-02 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Pikl is an image librarry for ruby. This library aims easily image processing. Supports JPEG, PNG and BITMAP.
|
17
|
+
email:
|
18
|
+
- ""
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions:
|
22
|
+
- ext/pikl/extconf.rb
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.txt
|
25
|
+
- License.txt
|
26
|
+
- Manifest.txt
|
27
|
+
- README.txt
|
33
28
|
files:
|
34
29
|
- History.txt
|
35
30
|
- License.txt
|
@@ -62,29 +57,40 @@ files:
|
|
62
57
|
- lib/pikl/errors.rb
|
63
58
|
- lib/pikl/ext.rb
|
64
59
|
- lib/pikl/image.rb
|
60
|
+
- lib/pikl/pikl.dll
|
65
61
|
- lib/pikl/version.rb
|
66
62
|
- setup.rb
|
67
63
|
- test/sample.jpg
|
68
64
|
- test/test_helper.rb
|
69
|
-
- test/test_pikl.rb
|
70
|
-
- test/test_pikl_image.rb
|
71
|
-
test_files:
|
72
|
-
- test/test_helper.rb
|
73
|
-
- test/test_pikl.rb
|
74
65
|
- test/test_pikl_image.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://pikl.rubyforge.org
|
68
|
+
post_install_message:
|
75
69
|
rdoc_options:
|
76
70
|
- --main
|
77
71
|
- README.txt
|
78
|
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
- ext
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
87
|
requirements: []
|
88
88
|
|
89
|
-
|
90
|
-
|
89
|
+
rubyforge_project: pikl
|
90
|
+
rubygems_version: 1.0.1
|
91
|
+
signing_key:
|
92
|
+
specification_version: 2
|
93
|
+
summary: Pikl is an image librarry for ruby. This library aims easily image processing. Supports JPEG, PNG and BITMAP.
|
94
|
+
test_files:
|
95
|
+
- test/test_helper.rb
|
96
|
+
- test/test_pikl_image.rb
|