Class: Pikl::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/pikl/image.rb,
lib/pikl/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inpath) ⇒ Image

Returns a new instance of Image.



23
24
25
# File 'lib/pikl/image.rb', line 23

def initialize( inpath )
  @pkl_image = Ext.pkl_open(File.expand_path(inpath))
end

Class Method Details

.open(inpath, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pikl/image.rb', line 5

def self.open(inpath, &block)
  image = Pikl::Image.new(inpath)
  image.instance_variable_set(:@block,block)
  
  return image unless block_given?

  begin
    block.call(image)
  ensure
    image.close if image
  end

end

Instance Method Details

#ablur(x = -1,, y = -1,, ef = 30.0, weight = 5) ⇒ Object



217
218
219
# File 'lib/pikl/filter.rb', line 217

def ablur(x=-1, y=-1, ef=30.0, weight=5)
  Ext.pkl_ablur(@pkl_image, x.to_i, y.to_i, ef.to_f, weight.to_i)
end

#affine(width, height, color, xscale, yscale, angle, x, y, sample = :bilinear) ⇒ Object



360
361
362
363
364
365
# File 'lib/pikl/filter.rb', line 360

def affine(width, height, color, xscale, yscale, angle, x, y, sample=:bilinear)
  error("invalid parameter. # => #{type}") unless SAMPLES.include?(sample)
  error("invalid parameter. # => #{color}") unless color != nil
  error("invalid parameter. # => #{color}") unless color.class.name == 'Pikl::Color'
  Ext.pkl_affine(@pkl_image, SAMPLES[sample], width.to_i, height.to_i, color.rawdata, xscale.to_f, yscale.to_f, angle.to_f, x.to_i, y.to_i)
end

#alphablend(image, xpos, ypos, alpha) ⇒ Object

alphablend

image

another pikl image object.

xpos

left position of blend image.

ypos

top position of blend image.

alpha

alpha: α-value(0-255). 255 is complete transparent.



62
63
64
65
# File 'lib/pikl/filter.rb', line 62

def alphablend(image, xpos, ypos, alpha)
  Ext.pkl_alphablend(@pkl_image, image.rawdata, xpos, ypos, alpha);
  self
end

#alphaedge(level = 8, low = 1.5, high = 1.5, coeff = 1.0, threshold = 50, alpha = 80) ⇒ Object

手書き風



81
82
83
84
85
86
# File 'lib/pikl/filter.rb', line 81

def alphaedge(level=8, low=1.5, high=1.5, coeff=1.0, threshold=50, alpha=80)
  error("invalid parameter. # => #{level}") if level<1 || level>256
  error("invalid parameter. # => #{threshold}") if threshold<0 || threshold>80
  error("invalid parameter. # => #{alpha}") if alpha<0 || alpha>=256
  Ext.pkl_alphaedge(@pkl_image, level.to_i, low.to_f, high.to_f, coeff.to_f, threshold.to_i, alpha.to_i)
end

#blackwhite(level = 127) ⇒ Object



280
281
282
# File 'lib/pikl/filter.rb', line 280

def blackwhite(level=127)
  Ext.pkl_2c(@pkl_image, level.to_i)
end

#blot(level = 3) ⇒ Object

blot



155
156
157
# File 'lib/pikl/filter.rb', line 155

def blot(level=3)
  Ext.pkl_noise(@pkl_image, level.to_i)
end

#blur(weight) ⇒ Object



205
206
207
# File 'lib/pikl/filter.rb', line 205

def blur(weight)
  Ext.pkl_blur(@pkl_image, weight.to_i)
end

#brightness(color) ⇒ Object

明るさ調整



27
28
29
30
# File 'lib/pikl/filter.rb', line 27

def brightness(color)
  Ext.pkl_brightness(@pkl_image, color.to_i)
  self
end

#canvas(width, height, colorspace, color) ⇒ Object

新規のキャンバスを作成する



216
217
218
219
220
221
222
223
224
# File 'lib/pikl/image.rb', line 216

def canvas(width, height, colorspace, color)
  self.close
  error("invalid parameter. # => #{color}") if color.nil?
  error("invalid parameter. # => #{color}") if color.class.name != 'Pikl::Color'
  error("invalid parameter. # => #{colorspace}") unless COLORSPACE.include?(colorspace)
  validate_pix(width)
  validate_pix(height)
  @pkl_image = Ext.pkl_canvas(width, height, COLORSPACE[colorspace], color.rawdata)
end

#closeObject



40
41
42
43
# File 'lib/pikl/image.rb', line 40

def close()
  Ext.pkl_close(@pkl_image) if @pkl_image
  @pkl_image = nil
end

#color_emboss(mil, env) ⇒ Object



345
346
347
# File 'lib/pikl/filter.rb', line 345

def color_emboss(mil, env)
  Ext.pkl_color_emboss(@pkl_image, mil.to_f, env.to_f)
end

#color_int(colorstr) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/pikl/image.rb', line 100

def color_int(colorstr)
  validate_color(colorstr)
  cs = colorstr.gsub(/^#/,"")
  color = []
  0.step(6,2) do |i|
    color << ( cs[i,2].to_s.empty? ? "FF" : cs[i,2] )
  end
  color.map!{|c| c.hex}
end

#colordither(weight) ⇒ Object



333
334
335
# File 'lib/pikl/filter.rb', line 333

def colordither(weight)
  Ext.pkl_colordither(@pkl_image, weight.to_i)
end

#colorspaceObject

カラースペースを返す



247
248
249
250
251
252
253
# File 'lib/pikl/image.rb', line 247

def colorspace
  nil unless(@pkl_image)
  COLORSPACE.find{ |k, v|
    v == Ext.pkl_colorspace(@pkl_image)
    return k
  }
end

#compose(image, xpos, ypos) ⇒ Object

compose image

image

another pikl image object.

xpos

left position of composing image.

ypos

top position of composing image.



52
53
54
55
# File 'lib/pikl/filter.rb', line 52

def compose(image, xpos, ypos)
  Ext.pkl_composite(@pkl_image, image.rawdata, xpos, ypos)
  self
end

#contourObject



181
182
183
# File 'lib/pikl/filter.rb', line 181

def contour
  Ext.pkl_contour(@pkl_image)
end

#contrast(rate) ⇒ Object

コントラスト調整



14
15
16
17
18
# File 'lib/pikl/filter.rb', line 14

def contrast(rate)
  error("invalid parameter. # => #{rate}") if rate<-127 || rate>127
  Ext.pkl_contrast(@pkl_image, rate.to_i)
  self
end

#countObject

色数を数える



242
243
244
# File 'lib/pikl/image.rb', line 242

def count
  Ext.pkl_count(@pkl_image) if(@pkl_image)
end

#crayon(factor = 15.0, bv1 = 3, bv2 = 2, alpha = 80) ⇒ Object

クレヨン風



89
90
91
92
93
# File 'lib/pikl/filter.rb', line 89

def crayon(factor=15.0, bv1=3, bv2=2, alpha=80)
  error("invalid parameter. # => #{factor}") if factor.to_f<5.0 || factor.to_f>80.0
  error("invalid parameter. # => #{alpha}") if alpha<0 || alpha>=256
  Ext.pkl_crayon(@pkl_image, factor.to_f, bv1.to_i, bv2.to_i, alpha.to_i)
end

#cutcolor(level) ⇒ Object



266
267
268
# File 'lib/pikl/filter.rb', line 266

def cutcolor(level)
  Ext.pkl_cutcolor(@pkl_image, level)
end

#dither(type = :floydsteinberg) ⇒ Object

dither



165
166
167
168
# File 'lib/pikl/filter.rb', line 165

def dither(type=:floydsteinberg)
  error("invalid parameter. # => #{type}") unless DITHER.include?(type)
  Ext.pkl_dither(@pkl_image, DITHER[type])
end

#dots(zone, color) ⇒ Object



327
328
329
330
331
# File 'lib/pikl/filter.rb', line 327

def dots(zone, color)
  error("invalid parameter. # => #{color}") unless color != nil
  error("invalid parameter. # => #{color}") unless color.class.name == 'Pikl::Color'
  Ext.pkl_dots(@pkl_image, zone, color.rawdata)
end

#dup(src) ⇒ Object

複製



209
210
211
212
213
# File 'lib/pikl/image.rb', line 209

def dup(src)
  self.close
  error("invalid parameter. # => #{src}") unless src.class.name == 'Pikl::Image'
  @pkl_image = Ext.pkl_dup(src.rawdata)
end

#edge(threshold = 15) ⇒ Object

edge

threshold=0..30


177
178
179
# File 'lib/pikl/filter.rb', line 177

def edge(threshold=15)
  Ext.pkl_edge(@pkl_image, threshold.to_i)
end

#edgepaint(edge = 1) ⇒ Object

edgepaint



171
172
173
# File 'lib/pikl/filter.rb', line 171

def edgepaint(edge=1)
  Ext.pkl_edgepaint(@pkl_image, edge.to_i)
end

#edgeposter(level = 4, low = 1.5, high = 1.5, coeff = 1.0, edge = 1) ⇒ Object

ポスター風



96
97
98
99
100
# File 'lib/pikl/filter.rb', line 96

def edgeposter(level=4, low=1.5, high=1.5, coeff=1.0, edge=1)
  error("invalid parameter. # => #{level}") if level<2 || level>8
  error("invalid parameter. # => #{edge}") if edge<0 || edge>5
  Ext.pkl_edgeposter(@pkl_image, level.to_i, low.to_f, high.to_f, coeff.to_f, edge.to_i)
end

#emboss(type = :light) ⇒ Object



190
191
192
193
# File 'lib/pikl/filter.rb', line 190

def emboss(type=:light)
  error("invalid parameter. # => #{type}") unless EMBOSS.include?(type)
  Ext.pkl_emboss(@pkl_image, EMBOSS[type])
end

#emboss2(mask, w, h, factor = 1.0, offset = 0) ⇒ Object



195
196
197
198
199
# File 'lib/pikl/filter.rb', line 195

def emboss2(mask, w, h, factor=1.0, offset=0)
  error("invalid parameter. # => #{mask}") unless mask.class.name == 'Array'
  error("invalid parameter. # => #{mask} or #{w} or #{h}") unless mask.length == w.to_i*h.to_i
  Ext.pkl_emboss2(@pkl_image, mask, w.to_i, h.to_i, factor.to_f, offset.to_i)
end

#error(message) ⇒ Object



194
195
196
197
# File 'lib/pikl/image.rb', line 194

def error(message)
  #self.close
  raise Pikl::ParameterException.new(message)
end

#fantasy(edgeweight, mix, saturation, hue) ⇒ Object



337
338
339
# File 'lib/pikl/filter.rb', line 337

def fantasy(edgeweight, mix, saturation, hue)
  Ext.pkl_sobelpaint(@pkl_image, edgeweight.to_i, mix.to_f, saturation.to_f, hue.to_f)
end

#fdopen(fd) ⇒ Object

オープン済みファイルディスクリプタからPiklを生成する



202
203
204
205
206
# File 'lib/pikl/image.rb', line 202

def fdopen(fd)
  self.close
  error("invalid parameter. # => #{fd}") unless fd.class.name == 'File'
  @pkl_image = Ext.pkl_fdopen(fd)
end

#film(color, trans) ⇒ Object



310
311
312
313
314
# File 'lib/pikl/filter.rb', line 310

def film(color, trans)
  error("invalid parameter. # => #{color}") unless color != nil
  error("invalid parameter. # => #{color}") unless color.class.name == 'Pikl::Color'
  Ext.pkl_film(@pkl_image, color.rawdata, trans.to_i)
end

#fit(width, height, mode = :inner) ⇒ Object



85
86
87
88
# File 'lib/pikl/image.rb', line 85

def fit(width, height, mode = :inner)
  validate_fit_mode(mode)
  self.send("fit_#{mode.to_s}", width, height)
end

#fit_inner(width, height) ⇒ Object



90
91
92
93
# File 'lib/pikl/image.rb', line 90

def fit_inner(width, height)
  to_w, to_h = ((width.to_f / self.width.to_f) < (height.to_f / self.height.to_f)) ? [width, :auto] : [:auto, height]
  resize(to_w,to_h)
end

#fit_outer(width, height) ⇒ Object



95
96
97
98
# File 'lib/pikl/image.rb', line 95

def fit_outer(width, height)
  to_w, to_h = ((width.to_f / self.width.to_f) > (height.to_f / self.height.to_f)) ? [width, :auto] : [:auto, height]
  resize(to_w,to_h)
end

#focus(type = :detail) ⇒ Object



185
186
187
188
# File 'lib/pikl/filter.rb', line 185

def focus(type=:detail)
  error("invalid parameter. # => #{type}") unless FOCUS.include?(type)
  Ext.pkl_focus(@pkl_image, FOCUS[type])
end

#formatObject



53
54
55
# File 'lib/pikl/image.rb', line 53

def format
  Ext.pkl_format(@pkl_image) if(@pkl_image)
end

#gamma(gm) ⇒ Object

gamma correction

gm

compensating rate.

gm must be >= 0 and image is neutral if gm value is 1.0.



43
44
45
46
# File 'lib/pikl/filter.rb', line 43

def gamma(gm)
  Ext.pkl_gamma(@pkl_image, gm.to_f)
  self
end

#gaussblur(weight) ⇒ Object



209
210
211
# File 'lib/pikl/filter.rb', line 209

def gaussblur(weight)
  Ext.pkl_gaussblur(@pkl_image, weight.to_f)
end

#getcolor(x, y, colormodel) ⇒ Object

特定ピクセルの色を取り出す



256
257
258
259
260
261
# File 'lib/pikl/image.rb', line 256

def getcolor(x, y, colormodel)
  nil unless(@pkl_image)
  validate_position(x, y)
  error("invalid parameter. # => #{colormodel}") unless COLORMODEL.include?(colormodel)
  Ext.pkl_get_color(@pkl_image, x, y, COLORMODEL[colormodel])
end

#getpixel(x, y) ⇒ Object

特定ピクセルの色を取り出す



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/pikl/image.rb', line 274

def getpixel(x, y)
  return unless @pkl_image
  validate_position(x, y)
  color = Ext.pkl_get_pixel(self.rawdata, x, y)
  
  case self.colorspace
    when :GRAY
      v = { 'gray' => Ext.pkl_color(color, COLORMODEL[:gray]) }
    when :RGB
      v = {
        'red'   => Ext.pkl_color(color, COLORMODEL[:red]),
        'green' => Ext.pkl_color(color, COLORMODEL[:green]),
        'blue'  => Ext.pkl_color(color, COLORMODEL[:blue]) }
    when :CMYK
      v = {
        'cyan'    => Ext.pkl_color(color, COLORMODEL[:cyan]),
        'magenta' => Ext.pkl_color(color, COLORMODEL[:magenta]),
        'yellow'  => Ext.pkl_color(color, COLORMODEL[:yellow]),
        'black'   => Ext.pkl_color(color, COLORMODEL[:black]) }
    else
      v=nil
  end
  Ext.pkl_color_close(color)
  return v
end

#gray(type = :nrm) ⇒ Object



275
276
277
278
# File 'lib/pikl/filter.rb', line 275

def gray(type=:nrm)
  error("invalid parameter. # => #{type}") unless GRAY.include?(type)
  Ext.pkl_gray(@pkl_image, GRAY[type])
end

#grid(msx, msy, color) ⇒ Object



257
258
259
# File 'lib/pikl/filter.rb', line 257

def grid(msx, msy, color)
  Ext.pkl_grid(@pkl_image, msx.to_i, msy.to_i, color.to_i)
end

#heightObject



49
50
51
# File 'lib/pikl/image.rb', line 49

def height
  Ext.pkl_height(@pkl_image) if(@pkl_image)
end

#hls(ym, sm, hd) ⇒ Object

輝度(明るさ)・彩度(鮮やかさ)・色相(色合い)調整



33
34
35
36
37
38
# File 'lib/pikl/filter.rb', line 33

def hls(ym, sm ,hd)
  error("invalid parameter. # => #{ym}") if ym.to_f<-1.0 || ym.to_f>1.0
  error("invalid parameter. # => #{sm}") if sm.to_f<-1.0 || sm.to_f>1.0
  Ext.pkl_hls(@pkl_image, ym.to_f, sm.to_f, hd.to_f)
  self
end

#hydrangea(zone = 10, low = 1.5, high = 1.5, coeff = 1.0, mil = 50, env = 70) ⇒ Object

あじさい風



103
104
105
106
107
# File 'lib/pikl/filter.rb', line 103

def hydrangea(zone=10, low=1.5, high=1.5, coeff=1.0, mil=50, env=70)
  error("invalid parameter. # => #{mil}") if mil.to_f<1 || mil.to_f>400
  error("invalid parameter. # => #{env}") if env.to_f<1 || env.to_f>100
  Ext.pkl_hydrangea(@pkl_image, zone.to_i, low.to_f, high.to_f, coeff.to_f, mil.to_f, env.to_f)
end

#illust(gap, edge, gammaint) ⇒ Object



341
342
343
# File 'lib/pikl/filter.rb', line 341

def illust(gap, edge, gammaint)
  Ext.pkl_illust(@pkl_image, gap.to_i, edge.to_i, gammaint.to_i)
end

#invertObject

反転



76
77
78
# File 'lib/pikl/filter.rb', line 76

def invert
  Ext.pkl_invert(@pkl_image) if(@pkl_image)
end

#is_horizontal?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/pikl/image.rb', line 135

def is_horizontal?
  self.height <= self.width
end

#is_vertical?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/pikl/image.rb', line 131

def is_vertical?
  self.height > self.width
end

#kuwahara(weight = 3) ⇒ Object

kuwahara



149
150
151
152
# File 'lib/pikl/filter.rb', line 149

def kuwahara(weight=3)
  error("invalid parameter. # => #{weight}") if weight.to_i<2 || weight.to_i>5
  Ext.pkl_kuwahara(@pkl_image, weight.to_i)
end

#level(low, high, coeff) ⇒ Object

レベル補正



21
22
23
24
# File 'lib/pikl/filter.rb', line 21

def level(low, high, coeff)
  Ext.pkl_level(@pkl_image, low.to_f, high.to_f, coeff.to_f)
  self
end

#mblur(angle, weight) ⇒ Object



225
226
227
# File 'lib/pikl/filter.rb', line 225

def mblur(angle, weight)
  Ext.pkl_mblur(@pkl_image, angle.to_f, weight.to_i)
end

#mosaic(width, height) ⇒ Object

mosaic effect

width

width for mosaic unit.

height

height for mosaic unit.



70
71
72
73
# File 'lib/pikl/filter.rb', line 70

def mosaic(width, height)
  Ext.pkl_mosaic(@pkl_image, width, height)
  self
end

#noisecutObject



201
202
203
# File 'lib/pikl/filter.rb', line 201

def noisecut
  Ext.pkl_noisecut(@pkl_image)
end

#oilpaint(weight = 3) ⇒ Object

oilpaint



143
144
145
146
# File 'lib/pikl/filter.rb', line 143

def oilpaint(weight=3)
  error("invalid parameter. # => #{weight}") if weight.to_i<2 || weight.to_i>6
  Ext.pkl_oilpaint(@pkl_image, weight.to_i)
end

#output(fd, format, compress = nil) ⇒ Object

オープン済みファイルディスクリプタ(もしくはIO)にイメージを書き出す



227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/pikl/image.rb', line 227

def output(fd, format, compress=nil)
  raise Pikl::ImageProcessException.new("image already closed.") unless @pkl_image
  error("invalid parameter. # => #{fd}") unless ['File', 'IO'].include?(fd.class.name)
  validate_format(format)
  if compress
    validate_compress(compress)
    Ext.pkl_compress(@pkl_image, compress.to_i)
  end
  
  Ext.pkl_output(@pkl_image, fd, EXTENSIONS_FORMATS[format.to_s.downcase] || format.to_i)
  self.close unless(@block)
  @pkl_image
end

#pattern(width, height, pattern = :p_hexagon, paint = :ave) ⇒ Object



349
350
351
352
353
# File 'lib/pikl/filter.rb', line 349

def pattern(width, height, pattern=:p_hexagon, paint=:ave)
  error("invalid parameter. # => #{pattern}") unless PATTERN.include?(pattern)
  error("invalid parameter. # => #{paint}") unless PAINT.include?(paint)
  Ext.pkl_pattern(@pkl_image, width.to_i, height.to_i, PATTERN[pattern], PAINT[paint])
end

#pixelate(ms) ⇒ Object



253
254
255
# File 'lib/pikl/filter.rb', line 253

def pixelate(ms)
  Ext.pkl_pixelate(@pkl_image, ms.to_i)
end

#posterize(level) ⇒ Object



261
262
263
264
# File 'lib/pikl/filter.rb', line 261

def posterize(level)
  error("invalid parameter. # => #{level}") unless level>1 && level<256
  Ext.pkl_posterize(@pkl_image, level.to_i)
end

#randomshadow(child, x, y, margin, shadowcolor = nil) ⇒ Object



244
245
246
247
248
249
250
251
# File 'lib/pikl/filter.rb', line 244

def randomshadow(child, x, y, margin, shadowcolor=nil)
  error("invalid parameter. # => #{child}") unless child.class.name == 'Pikl::Image'
  _shadowcolor = nil
  unless shadowcolor.nil?
    _shadowcolor = shadowcolor.rawdata if shadowcolor.class.name == 'Pikl::Color'
  end
  Pikl::Ext.pkl_randomshadow(@pkl_image, child.rawdata, x.to_i, y.to_i, margin.to_i, _shadowcolor)
end

#rawdataObject



19
20
21
# File 'lib/pikl/image.rb', line 19

def rawdata
  @pkl_image
end

#rblur(x = -1,, y = -1,, ef = 30.0, weight = 5) ⇒ Object



213
214
215
# File 'lib/pikl/filter.rb', line 213

def rblur(x=-1, y=-1, ef=30.0, weight=5)
  Ext.pkl_rblur(@pkl_image, x.to_i, y.to_i, ef.to_f, weight.to_i)
end

#resize(width, height, sample = :pixcel_averate) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/pikl/image.rb', line 114

def resize(width, height, sample = :pixcel_averate)
  validate_auto(width,height)

  case sample.class.name
  when 'Symbol', 'String'
    sample = SAMPLES[sample.to_sym]
  end
  
  width = self.width * height / self.height if(width == :auto)
  height = self.height * width / self.width if(height == :auto)
  
  validate_resize(width, height)

  Ext.pkl_resize(@pkl_image, width, height, sample)
  self
end

#rgbObject

cmyk-model only



271
272
273
# File 'lib/pikl/filter.rb', line 271

def rgb
  Ext.pkl_rgb(@pkl_image)
end

#rinkaku(factor = 30.0) ⇒ Object

凝った輪郭



110
111
112
# File 'lib/pikl/filter.rb', line 110

def rinkaku(factor=30.0)
  Ext.pkl_rinkaku(@pkl_image, factor.to_f)
end

#rotate(angle, backcolor = "#FFFFFF", sample = :bilinear) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/pikl/image.rb', line 77

def rotate(angle, backcolor = "#FFFFFF", sample = :bilinear)
  ci = color_int(backcolor)
  color = Ext.pkl_color_rgb(ci[0], ci[1], ci[2])
  Ext.pkl_rotate(@pkl_image, angle.to_f, SAMPLES[sample.to_sym], color)
  Ext.pkl_color_close(color)
  self
end

#save(outpath, format = nil, compress = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pikl/image.rb', line 27

def save(outpath, format = nil, compress = nil)
  raise Pikl::ImageProcessException.new("image already closed.") unless @pkl_image
  format ||= (split_extensions(outpath) || @format)
  validate_format(format)
  if compress
    validate_compress(compress)
    Ext.pkl_compress(@pkl_image, compress.to_i)
  end
  Ext.pkl_save(@pkl_image, File.expand_path(outpath), EXTENSIONS_FORMATS[format.to_s.downcase] || format.to_i)
  self.close unless(@block)
  @pkl_image
end

#sepia(red_weight, green_weight, blue_weight) ⇒ Object

sepia



135
136
137
138
139
140
# File 'lib/pikl/filter.rb', line 135

def sepia(red_weight, green_weight, blue_weight)
  error("invalid parameter. # => #{red_weight}") if red_weight.to_f<0.0 || red_weight.to_f>1.0
  error("invalid parameter. # => #{green_weight}") if green_weight.to_f<0.0 || green_weight.to_f>1.0
  error("invalid parameter. # => #{blue_weight}") if blue_weight.to_f<0.0 || blue_weight.to_f>1.0
  Ext.pkl_sepia(@pkl_image, red_weight.to_f, green_weight.to_f, blue_weight.to_f)
end

#setcolor(x, y, colormodel, color) ⇒ Object

特定ピクセルに色をセットする



264
265
266
267
268
269
270
271
# File 'lib/pikl/image.rb', line 264

def setcolor(x, y, colormodel, color)
  nil unless(@pkl_image)
  validate_position(x, y)
  error("invalid parameter. # => #{colormodel}") unless COLORMODEL.include?(colormodel)
  validate_numeric(color)
  error("invalid parameter. # => #{color}") unless color>=0 && color<=255
  Ext.pkl_set_color(@pkl_image, x, y, COLORMODEL[colormodel], color)
end

#setpixel(x, y, color, auto = true) ⇒ Object

特定ピクセルに色を設定する



301
302
303
304
305
306
307
308
# File 'lib/pikl/image.rb', line 301

def setpixel(x, y, color, auto=true)
  return unless @pkl_image
  validate_position(x, y)
  error("invalid parameter. # => #{color}") if color.nil?
  error("invalid parameter. # => #{color}") if color.class.name != 'Pikl::Color'
  Ext.pkl_set_pixel(@pkl_image, x, y, color.rawdata)
  color.close if(auto)
end

#shadowframe(margin, backcolor = nil, shadowcolor = nil) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/pikl/filter.rb', line 229

def shadowframe(margin, backcolor=nil, shadowcolor=nil)
  _backcolor = nil
  unless backcolor.nil?
    _backcolor = backcolor.rawdata if backcolor.class.name == 'Pikl::Color'
  end

  _shadowcolor = nil
  unless shadowcolor.nil?
    _shadowcolor = shadowcolor.rawdata if shadowcolor.class.name == 'Pikl::Color'
  end
  
  Ext.pkl_shadowframe(@pkl_image, margin.to_i, _backcolor, _shadowcolor)
end

#split_extensions(path) ⇒ Object

regular expressions to try for identifying extensions



140
141
142
143
# File 'lib/pikl/image.rb', line 140

def split_extensions(path)
  filename = path.split('/').last
  (filename =~ %r|.+\.([a-z,A-Z]+)$|) ? $1 : nil
end

#splitframe(backcolor, wbs, hbs, margin, frame) ⇒ Object



288
289
290
291
292
# File 'lib/pikl/filter.rb', line 288

def splitframe(backcolor, wbs, hbs, margin, frame)
  error("invalid parameter. # => #{backcolor}") unless backcolor != nil
  error("invalid parameter. # => #{backcolor}") unless backcolor.class.name == 'Pikl::Color'
  Ext.pkl_splitframe(@pkl_image, backcolor.rawdata, wbs.to_i, hbs.to_i, margin.to_i, frame.to_i)
end

#swirl(factor, x, y, color) ⇒ Object



316
317
318
319
320
# File 'lib/pikl/filter.rb', line 316

def swirl(factor, x, y, color)
  error("invalid parameter. # => #{color}") unless color != nil
  error("invalid parameter. # => #{color}") unless color.class.name == 'Pikl::Color'
  Ext.pkl_swirl(@pkl_image, factor.to_f, x.to_i, y.to_i, color.rawdata)
end

#tile(msx, msy, level, type = :t_rect) ⇒ Object



355
356
357
358
# File 'lib/pikl/filter.rb', line 355

def tile(msx, msy, level, type=:t_rect)
  error("invalid parameter. # => #{type}") unless TILE.include?(type)
  Ext.pkl_tile(@pkl_image, TILE[type], msx.to_i, msy.to_i, level.to_i)
end

#tileslit(area, shift) ⇒ Object



284
285
286
# File 'lib/pikl/filter.rb', line 284

def tileslit(area, shift)
  Ext.pkl_tileslit(@pkl_image, area.to_i, shift.to_i)
end

#trim(x, y, dist_x, dist_y) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/pikl/image.rb', line 57

def trim(x, y, dist_x, dist_y)
  validate_trim(x, y, dist_x, dist_y)
  dist_x = trim_dist(x, self.width, dist_x)
  dist_y = trim_dist(y, self.height, dist_y)
        
  Ext.pkl_trim(@pkl_image, x, y, dist_x, dist_y)
  
  self
end

#trim_dist(start, dist_from, dist_to) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/pikl/image.rb', line 67

def trim_dist(start, dist_from, dist_to)
  if dist_to == :auto || dist_to > (dist_from - start)
    dist_to = dist_from - start
  elsif dist_to < 0
    dist_to += (dist_from - start)
  else
    dist_to
  end
end

#unshapmask(threshold, edge) ⇒ Object

unshapmask



6
7
8
9
10
11
# File 'lib/pikl/filter.rb', line 6

def unshapmask(threshold, edge)
  error("invalid parameter. # => #{threshold}") if threshold.to_i<0 || threshold.to_i>255
  error("invalid parameter. # => #{edge}") if edge.to_f<-10.0 || edge.to_f>10.0
  Ext.pkl_unsharp(@pkl_image, threshold.to_i, edge.to_f)
  self
end

#validate_auto(width, height) ⇒ Object



145
146
147
# File 'lib/pikl/image.rb', line 145

def validate_auto(width, height)
  error("invalid :autoto in the both of width and height.") if(width == :auto && height == :auto)
end

#validate_color(v) ⇒ Object



110
111
112
# File 'lib/pikl/image.rb', line 110

def validate_color(v)
  error("invalid color parameter. # => #{v}") unless  /^#[a-f|A-F|0-9]+$/ =~ v.to_s
end

#validate_compress(v) ⇒ Object



185
186
187
188
# File 'lib/pikl/image.rb', line 185

def validate_compress(v)
  error("invalid compress parameter. # => #{v}") unless /^\d+$/ =~ v.to_s
  error("invalid compress parameter. # => #{v}") unless v.to_i >= 0 && v.to_i <= 10
end

#validate_fit_mode(v) ⇒ Object



190
191
192
# File 'lib/pikl/image.rb', line 190

def validate_fit_mode(v)
    error("invalid fit parameter. # => #{v}") unless [:inner, :outer].include?(v)
end

#validate_format(ext) ⇒ Object

validate identifying extensions



150
151
152
# File 'lib/pikl/image.rb', line 150

def validate_format(ext)
  error(ext) unless (ext || EXTENSIONS.include?(ext.to_s.downcase) || FORMATS.include?(ext.to_i))
end

#validate_numeric(*args) ⇒ Object



178
179
180
181
182
183
# File 'lib/pikl/image.rb', line 178

def validate_numeric(*args)
  args = [args] unless args.is_a?(Array)
  args.each do |v|
    error("invalid parameter. # => #{v}") unless /^[-\d]+$/ =~ v.to_s
  end      
end

#validate_pix(value, allow_minus = false) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/pikl/image.rb', line 170

def validate_pix(value, allow_minus = false)
  return if value == :auto
  validate_numeric(value)
  error("value is outside the range.  #{value}") if value == 0
  error("value is outside the range.  #{value}") if !allow_minus && value < 0
  error("value is outside the range.  #{value}") if value > PIX_LIMIT
end

#validate_position(x, y) ⇒ Object



310
311
312
313
314
315
# File 'lib/pikl/image.rb', line 310

def validate_position(x, y)
  validate_numeric(x)
  validate_numeric(y)
  error("value is outside the range.  #{x}") if x<0 || x>=self.width
  error("value is outside the range.  #{y}") if y<0 || y>=self.height
end

#validate_resize(width, height) ⇒ Object



164
165
166
167
168
# File 'lib/pikl/image.rb', line 164

def validate_resize(width, height)
  validate_auto(width, height)
  validate_pix(width)
  validate_pix(height)
end

#validate_trim(x, y, dist_x, dist_y) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/pikl/image.rb', line 154

def validate_trim(x, y, dist_x, dist_y)
  validate_numeric(x, y)
  
  validate_pix(dist_x, true)
  validate_pix(dist_y, true)

  error("left is outside the range.  #{x}") if x > self.width.to_i
  error("top is outside the range.  #{y}") if y > self.height.to_i
end

#vaseline(radius, x = -1,, y = -1)) ⇒ Object



300
301
302
# File 'lib/pikl/filter.rb', line 300

def vaseline(radius, x=-1, y=-1)
  Ext.pkl_vaseline(@pkl_image, radius.to_i, x.to_i, y.to_i)
end

#vignette(color, trans, radius, x = -1,, y = -1)) ⇒ Object



294
295
296
297
298
# File 'lib/pikl/filter.rb', line 294

def vignette(color, trans, radius, x=-1, y=-1)
  error("invalid parameter. # => #{color}") unless color != nil
  error("invalid parameter. # => #{color}") unless color.class.name == 'Pikl::Color'
  Ext.pkl_vignette(@pkl_image, color.rawdata, trans.to_i, radius.to_i, x.to_i, y.to_i)
end

#voronoi_count(count, color = nil, edge = false) ⇒ Object

voronoi-count



125
126
127
128
129
130
131
132
# File 'lib/pikl/filter.rb', line 125

def voronoi_count(count, color=nil, edge=false)
  _color = nil
  unless color.nil?
    _color=color.rawdata if color.class.name == 'Pikl::Color'
  end
  _edge = edge ? 1 : 0
  Pikl::Ext.pkl_voronoi_count(@pkl_image, count.to_i, _color, _edge)
end

#voronoi_zone(zone, color = nil, edge = false) ⇒ Object

voronoi-zone



115
116
117
118
119
120
121
122
# File 'lib/pikl/filter.rb', line 115

def voronoi_zone(zone, color=nil, edge=false)
  _color = nil
  unless color.nil?
    _color=color.rawdata if color.class.name == 'Pikl::Color'
  end
  _edge = edge ? 1 : 0
  Ext.pkl_voronoi_zone(@pkl_image, zone.to_i, _color, _edge)
end

#vtr(colspace = 3, gst = 10, cst = 10) ⇒ Object

vtr



160
161
162
# File 'lib/pikl/filter.rb', line 160

def vtr(colspace=3, gst=10, cst=10)
  Ext.pkl_vtr(@pkl_image, colspace.to_i, gst.to_i, cst.to_i)
end

#vv(color, trans, radius, x = -1,, y = -1)) ⇒ Object



304
305
306
307
308
# File 'lib/pikl/filter.rb', line 304

def vv(color, trans, radius, x=-1, y=-1)
  error("invalid parameter. # => #{color}") unless color != nil
  error("invalid parameter. # => #{color}") unless color.class.name == 'Pikl::Color'
  Ext.pkl_vv(@pkl_image, color.rawdata, trans.to_i, radius.to_i, x.to_i, y.to_i)
end

#wave(factor, frequency, type = :both) ⇒ Object



322
323
324
325
# File 'lib/pikl/filter.rb', line 322

def wave(factor, frequency, type=:both)
  error("invalid parameter. # => #{type}") unless WAVE.include?(type)
  Ext.pkl_wave(@pkl_image, WAVE[type], factor.to_f, frequency.to_f)
end

#wblur(x = -1,, y = -1,, ef = 30.0, weight = 5, angle = 45.0) ⇒ Object



221
222
223
# File 'lib/pikl/filter.rb', line 221

def wblur(x=-1, y=-1, ef=30.0, weight=5, angle=45.0)
  Ext.pkl_wblur(@pkl_image, x.to_i, y.to_i, ef.to_f, weight.to_i, angle.to_f)
end

#widthObject



45
46
47
# File 'lib/pikl/image.rb', line 45

def width
  Ext.pkl_width(@pkl_image) if(@pkl_image)
end