pikl 0.2.6-x86-mswin32 → 0.2.7-x86-mswin32
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.
- data/History.txt +4 -0
- data/ext/pikl/pikl.h +446 -77
- data/ext/pikl/pikl_bitmap.c +2 -0
- data/ext/pikl/pikl_effect.c +63 -14
- data/ext/pikl/pikl_io.c +2 -0
- data/ext/pikl/pikl_png.c +13 -10
- data/ext/pikl/pikl_png.h +1 -1
- data/ext/pikl/pikl_private.h +6 -1
- data/ext/pikl/pikl_resize.c +3 -3
- data/ext/pikl/pikl_rotate2.c +2 -2
- data/lib/pikl/ext.rb +4 -0
- data/lib/pikl/image.rb +44 -7
- data/lib/pikl/version.rb +1 -1
- data/test/test_pikl_image.rb +49 -3
- metadata +2 -2
data/History.txt
CHANGED
data/ext/pikl/pikl.h
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
*/
|
1
|
+
/*=============================================================================
|
2
|
+
ImageLibrary 'pikl'
|
3
|
+
author: soe(soezimaster@gmail.com)
|
4
|
+
date: 2008.4
|
5
|
+
===============================================================================*/
|
7
6
|
#ifndef _LIB_PIKL_
|
8
7
|
#define _LIB_PIKL_
|
9
8
|
|
@@ -18,44 +17,47 @@
|
|
18
17
|
extern "C" {
|
19
18
|
#endif
|
20
19
|
|
21
|
-
|
22
|
-
#define PKL_VERSION "libpikl 0.1"
|
20
|
+
#define PKL_VERSION "libpikl 0.3.2"
|
23
21
|
|
24
22
|
// PKLImage
|
25
23
|
typedef struct _PKLImage * PKLImage;
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
gray
|
31
|
-
* color-typeのYCbCrおよびYCC
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
*
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
//=============================================================================
|
26
|
+
// support format & color
|
27
|
+
// JPEG:
|
28
|
+
// gray/rgb/cmyk
|
29
|
+
// * color-typeのYCbCrおよびYCCには読み取りも保存も対応していない
|
30
|
+
//
|
31
|
+
// PNG:
|
32
|
+
// gray/gray-alpha/rgb/rgb-alpha/palette
|
33
|
+
// * alphaは読取は可能だが、保存はできない
|
34
|
+
// * paletteはRGBとして扱われる
|
35
|
+
//
|
36
|
+
// BMP(windows bitmap):
|
37
|
+
// 24bit + non-compress only
|
38
|
+
//=============================================================================
|
39
39
|
typedef enum {
|
40
|
-
PKL_FORMAT_ERROR,
|
41
|
-
PKL_FORMAT_JPEG,
|
42
|
-
PKL_FORMAT_PNG,
|
43
|
-
PKL_FORMAT_BITMAP
|
40
|
+
PKL_FORMAT_ERROR, // error
|
41
|
+
PKL_FORMAT_JPEG, // jpeg
|
42
|
+
PKL_FORMAT_PNG, // png
|
43
|
+
PKL_FORMAT_BITMAP // windows bitmap
|
44
44
|
} PKL_FORMAT;
|
45
45
|
|
46
|
-
/*! color type */
|
47
46
|
typedef enum {
|
48
|
-
PKL_UNKNOWN,
|
49
|
-
PKL_BLACKWHITE,
|
50
|
-
PKL_GRAYSCALE,
|
51
|
-
PKL_RGB,
|
52
|
-
PKL_RGBA,
|
53
|
-
PKL_YCbCr,
|
54
|
-
PKL_CMYK,
|
55
|
-
PKL_YCCK
|
47
|
+
PKL_UNKNOWN, // error
|
48
|
+
PKL_BLACKWHITE, // non support
|
49
|
+
PKL_GRAYSCALE, // gray scale
|
50
|
+
PKL_RGB, // 24bit RGB
|
51
|
+
PKL_RGBA, // not support!
|
52
|
+
PKL_YCbCr, // not support!
|
53
|
+
PKL_CMYK, // CMYK(for jpeg)
|
54
|
+
PKL_YCCK // non support
|
56
55
|
} PKL_COLOR_SPACE;
|
57
56
|
|
58
|
-
|
57
|
+
//=============================================================================
|
58
|
+
// 回転角度(右回り)
|
59
|
+
// * pkl_rotateで使用
|
60
|
+
//=============================================================================
|
59
61
|
typedef enum {
|
60
62
|
PKL_ANGLE_000,
|
61
63
|
PKL_ANGLE_090,
|
@@ -63,18 +65,18 @@ typedef enum {
|
|
63
65
|
PKL_ANGLE_270
|
64
66
|
} PKL_ANGLE;
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
//=============================================================================
|
69
|
+
// サンプリングパターン
|
70
|
+
// * 全てのサンプリングパターンで拡大縮小対応
|
71
|
+
// * 但し、pixcel-averageで拡大をする場合は、lanczosと品質は同じ
|
72
|
+
//=============================================================================
|
71
73
|
typedef enum {
|
72
74
|
PKL_SAMPLE_ERROR,
|
73
|
-
PKL_SAMPLE_NN,
|
74
|
-
PKL_SAMPLE_BL,
|
75
|
-
PKL_SAMPLE_BC,
|
76
|
-
PKL_SAMPLE_PA,
|
77
|
-
PKL_SAMPLE_LZ
|
75
|
+
PKL_SAMPLE_NN, // nearest neighbor
|
76
|
+
PKL_SAMPLE_BL, // bilinear
|
77
|
+
PKL_SAMPLE_BC, // bicubic
|
78
|
+
PKL_SAMPLE_PA, // pixcel-average
|
79
|
+
PKL_SAMPLE_LZ // lanczos
|
78
80
|
} PKL_SAMPLE;
|
79
81
|
|
80
82
|
//=============================================================================
|
@@ -109,6 +111,40 @@ PKLExport int pkl_width(PKLImage pkl);
|
|
109
111
|
*/
|
110
112
|
PKLExport int pkl_height(PKLImage pkl);
|
111
113
|
|
114
|
+
|
115
|
+
/*!
|
116
|
+
PNG/JPEG保存時の圧縮率<br>
|
117
|
+
@param pkl [in] PKLImageオブジェクト
|
118
|
+
@param level [in]
|
119
|
+
0(無圧縮) .. 10(最高圧縮)。
|
120
|
+
指定がない場合は、デフォルトレベルが設定されます。
|
121
|
+
@return 成功した場合は0。失敗した場合は真を返します。
|
122
|
+
*/
|
123
|
+
PKLExport int pkl_compress(PKLImage pkl, int level);
|
124
|
+
|
125
|
+
//=============================================================================
|
126
|
+
// pkl_save
|
127
|
+
//=============================================================================
|
128
|
+
/*
|
129
|
+
保存<br>
|
130
|
+
@param pkl [in] PKLImageオブジェクト
|
131
|
+
@param out [in] 保存ファイル名
|
132
|
+
@param format [in] 保存フォーマット(PKL_FORMAT参照)
|
133
|
+
@return 成功した場合は0。失敗した場合は真を返します。
|
134
|
+
*/
|
135
|
+
PKLExport int pkl_save(PKLImage pkl, const char *out, PKL_FORMAT format);
|
136
|
+
|
137
|
+
//=============================================================================
|
138
|
+
// pkl_close
|
139
|
+
//=============================================================================
|
140
|
+
/*!
|
141
|
+
PKLImageオブジェクトの破棄<br>
|
142
|
+
確保していたメモリを全て解放します。用がなくなったら実行するようにしてください。
|
143
|
+
@param pkl [in] PKLImageオブジェクト
|
144
|
+
*/
|
145
|
+
PKLExport void pkl_close(PKLImage pkl);
|
146
|
+
|
147
|
+
|
112
148
|
/*!
|
113
149
|
トリミングします。<br>
|
114
150
|
・パラメータは左上原点です。<br>
|
@@ -146,6 +182,24 @@ PKLExport int pkl_rotate2(PKLImage pkl, float angle, PKL_SAMPLE sample,
|
|
146
182
|
*/
|
147
183
|
PKLExport int pkl_resize(PKLImage pkl, int width, int height, PKL_SAMPLE sample);
|
148
184
|
|
185
|
+
//=============================================================================
|
186
|
+
// affine変換
|
187
|
+
//=============================================================================
|
188
|
+
//*_scale = 変形率の逆数
|
189
|
+
PKLExport void pkl_matrix_scale(PKLImage pkl, double x_scale, double y_scale);
|
190
|
+
|
191
|
+
//angle=左回りの回転角度
|
192
|
+
PKLExport void pkl_matrix_rotate(PKLImage pkl, double angle);
|
193
|
+
|
194
|
+
//正数は上、左方向への移動
|
195
|
+
PKLExport void pkl_matrix_translate(PKLImage pkl, int x, int y);
|
196
|
+
|
197
|
+
PKLExport int pkl_affine(PKLImage pkl, PKL_SAMPLE sampler, int width, int height, int backcolor);
|
198
|
+
//#define pkl_color(a,b,c,d) ((a<<24)+(b<<16)+(c<<8)+d)
|
199
|
+
|
200
|
+
//=============================================================================
|
201
|
+
// エフェクト(ベーシック)
|
202
|
+
//=============================================================================
|
149
203
|
/*!
|
150
204
|
アンシャープ処理<br>
|
151
205
|
@param pkl [in] PKLImageオブジェクト
|
@@ -224,43 +278,358 @@ PKLExport int pkl_brightness(PKLImage pkl, int color);
|
|
224
278
|
*/
|
225
279
|
PKLExport int pkl_hls(PKLImage pkl, double ym, double sm, double hd);
|
226
280
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
1.0より小さい時は暗く、1.0より大きい時は明るく調整されます。
|
233
|
-
1.0を指定した時は調整されません。
|
234
|
-
@return 成功した場合は0。失敗した場合は真を返します。
|
235
|
-
*/
|
281
|
+
/* ガンマ補正 */
|
282
|
+
// gm: 補正係数(>=0.0)
|
283
|
+
// gm<1.0:暗く調整される
|
284
|
+
// gm=1.0:変化しない
|
285
|
+
// gm>1.0:明るく調整される
|
236
286
|
PKLExport int pkl_gamma(PKLImage pkl, double gm);
|
237
287
|
|
238
|
-
|
239
|
-
|
240
|
-
@param pkl [in] PKLImageオブジェクト
|
241
|
-
@param level [in]
|
242
|
-
0(無圧縮) .. 10(最高圧縮)。
|
243
|
-
指定がない場合は、デフォルトレベルが設定されます。
|
244
|
-
@return 成功した場合は0。失敗した場合は真を返します。
|
245
|
-
*/
|
246
|
-
PKLExport int pkl_compress(PKLImage pkl, int level);
|
288
|
+
/* ノイズ除去(median filter) */
|
289
|
+
PKLExport int pkl_noisecut(PKLImage pkl);
|
247
290
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
291
|
+
//=============================================================================
|
292
|
+
// エフェクト2
|
293
|
+
//=============================================================================
|
294
|
+
/* 反転 */
|
295
|
+
PKLExport int pkl_invert(PKLImage pkl);
|
296
|
+
|
297
|
+
//エッジ(輪郭)を強調する
|
298
|
+
//unsharpは画像全体をシャープにするが、これはエッジ部分のみの強調
|
299
|
+
typedef enum {
|
300
|
+
PKL_FOCUS_DETAIL, //弱い
|
301
|
+
PKL_FOCUS_FOCUS, //中間
|
302
|
+
PKL_FOCUS_EDGES //強い
|
303
|
+
} PKL_FOCUS;
|
304
|
+
PKLExport int pkl_focus(PKLImage pkl, PKL_FOCUS type);
|
305
|
+
|
306
|
+
//エンボス
|
307
|
+
typedef enum {
|
308
|
+
PKL_EMBOSS_EMBOSS, //エンボス1
|
309
|
+
PKL_EMBOSS_HEAVY, //エンボス2
|
310
|
+
PKL_EMBOSS_LIGHT, //エンボス3
|
311
|
+
PKL_EMBOSS_LAPLACIAN //輪郭抽出
|
312
|
+
} PKL_EMBOSS;
|
313
|
+
PKLExport int pkl_emboss(PKLImage pkl, PKL_EMBOSS type);
|
314
|
+
|
315
|
+
|
316
|
+
/* 画像の合成 */
|
317
|
+
// parentの上にchildを乗せる
|
318
|
+
// parent: ベース(処理後はこのオブジェクトが更新される)
|
319
|
+
// child: 乗せる画像(このオブジェクトは処理しても不可侵)
|
320
|
+
// xpos,ypos: childを乗せるparent上の座標.
|
321
|
+
// 必ずparent上の座標でなければならない.
|
322
|
+
// *parentとchildは同じカラーモードでなければエラーとなる
|
323
|
+
PKLExport int pkl_composite(PKLImage parent, PKLImage child, int xpos, int ypos);
|
324
|
+
|
325
|
+
/* 画像の合成2 */
|
326
|
+
// pkl_composite()に加え、childイメージ上の1色を透明扱いにできる
|
327
|
+
// parent: ベース(処理後はこのオブジェクトが更新される)
|
328
|
+
// child: 乗せる画像(このオブジェクトは処理しても不可侵)
|
329
|
+
// xpos,ypos: childを乗せるparent上の座標.
|
330
|
+
// 必ずparent上の座標でなければならない.
|
331
|
+
// transcolor: 透明にする色(pkl_colorマクロで生成する)
|
332
|
+
// *parentとchildは同じカラーモードでなければエラーとなる
|
333
|
+
PKLExport int pkl_composite2(PKLImage parent, PKLImage child, int xpos, int ypos, int transcolor);
|
334
|
+
|
335
|
+
/* (安易な)セピア */
|
336
|
+
// red_weight,green_weight,blue_weight:
|
337
|
+
// red,green,blueそれぞれに対しての重み
|
338
|
+
// 値が大きいほど、その色が強く出る
|
339
|
+
// *RGBのみに対応
|
340
|
+
// *セピアっぽくするのであれば、redの重みを1.0として、他の重みを1.0より小さくする
|
341
|
+
PKLExport int pkl_sepia(PKLImage pkl, double red_weight, double green_weight, double blue_weight);
|
342
|
+
|
343
|
+
/* (安易な)油絵化 */
|
344
|
+
// 油絵のようにする
|
345
|
+
// weight: 筆の太さ(というか最頻色走査領域のサイズ)
|
346
|
+
// 例えば、3を指定した場合、近傍3x3の領域の最頻色が選択される
|
347
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
348
|
+
PKLExport int pkl_oilpaint(PKLImage pkl, int weight);
|
349
|
+
|
350
|
+
|
351
|
+
//=============================================================================
|
352
|
+
// Blur(ぼかし)
|
353
|
+
//=============================================================================
|
354
|
+
/* (安易な)ぼかし */
|
355
|
+
// weight: 平均算出領域のサイズ
|
356
|
+
// 例えば、3を指定した場合、近傍3x3の領域の平均色が選択される
|
357
|
+
// 値が大きいほど、ぼかし度は強くなる。
|
358
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
359
|
+
PKLExport int pkl_blur(PKLImage pkl, int weight);
|
360
|
+
|
361
|
+
/* ガウスぼかし */
|
362
|
+
// ガウス関数を使ったぼかし。「画像全体にぼかしが入る」「方向がない」
|
363
|
+
// weight: ぼかし強調度(>0.0)
|
364
|
+
// 値が大きいほど、ぼかし度は強くなる。
|
365
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
366
|
+
PKLExport int pkl_gaussblur(PKLImage pkl, double weight);
|
367
|
+
|
368
|
+
/* 放射状ブラー(radiation) */
|
369
|
+
// x,y: 放射の中心座標(画像範囲内にない場合は中心)
|
370
|
+
// ef: 中心からの強調度(>0.0。値が大きいほど、放射度が強くなる)
|
371
|
+
// weight: ぼかしの強調度(>0)
|
372
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
373
|
+
PKLExport int pkl_rblur(PKLImage pkl, int x, int y, double ef, int weight);
|
374
|
+
|
375
|
+
/* 回転ブラー(angle) */
|
376
|
+
// x,y: 放射の中心座標(画像範囲内にない場合は中心)
|
377
|
+
// ef: 中心からの強調度(>0.0。値が大きいほど、放射度が強くなる)
|
378
|
+
// weight: ぼかしの強調度(>0)
|
379
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
380
|
+
PKLExport int pkl_ablur(PKLImage pkl, int x, int y, double ef, int weight);
|
381
|
+
|
382
|
+
/* うずまきブラー(whirlpool) */
|
383
|
+
// x,y: 放射の中心座標(画像範囲内にない場合は中心)
|
384
|
+
// ef: 中心からの強調度(>0.0。値が大きいほど、放射度が強くなる)
|
385
|
+
// weight: ぼかしの強調度(>0)
|
386
|
+
// angle: 回転角度(0は回転なし)
|
387
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
388
|
+
PKLExport int pkl_wblur(PKLImage pkl, int x, int y, double ef, int weight, double angle);
|
389
|
+
|
390
|
+
/* モーションブラー */
|
391
|
+
// 任意角度での直線ブラー
|
392
|
+
// angle: ぼかす角度
|
393
|
+
// range: ぼかし強調度
|
394
|
+
// *weightを大きくしすぎると、処理が重くなる。注意せよ
|
395
|
+
PKLExport int pkl_mblur(PKLImage pkl, double angle, int weight);
|
396
|
+
|
397
|
+
|
398
|
+
//**************************************************************************
|
399
|
+
// エフェクト3(from 画像処理プログラミング)
|
400
|
+
//**************************************************************************
|
401
|
+
/* イラスト調 */
|
402
|
+
// edge: エッジの重み(0が最もエッジが強い。0..20程度が目安)
|
403
|
+
// gammaint: 絵柄のガンマ評価値(0:暗く評価、100:明るく評価。0..100)
|
404
|
+
PKLExport int pkl_illust(PKLImage pkl, int edge, int gammaint);
|
405
|
+
|
406
|
+
/* エンボス */
|
407
|
+
// mil: ハイライト(1..400)
|
408
|
+
// env: 環境光(1..100)
|
409
|
+
PKLExport int pkl_color_emboss(PKLImage pkl, double mil, double env);
|
410
|
+
|
411
|
+
/* モザイク処理 */
|
412
|
+
// mx,my:モザイクのピクセルサイズ(それぞれ、幅・高さ)
|
413
|
+
// 1以下の時には変化はありません
|
414
|
+
// 画像サイズ以上の時には1色の画像になります
|
415
|
+
PKLExport int pkl_mosaic(PKLImage pkl, int msx, int msy);
|
416
|
+
|
417
|
+
/* ノイズ処理 */
|
418
|
+
PKLExport int pkl_noise(PKLImage pkl, int noise);
|
419
|
+
|
420
|
+
/* VTR調 */
|
421
|
+
//colspace; //行の間隔
|
422
|
+
//gst; //横方向のブレ
|
423
|
+
//cst; //行の色差分
|
424
|
+
PKLExport int pkl_vtr(PKLImage pkl, int colspace, int gst, int cst);
|
425
|
+
|
426
|
+
//**************************************************************************
|
427
|
+
// エフェクト4(実験シリーズ)
|
428
|
+
//**************************************************************************
|
429
|
+
/* 輪郭抽出 */
|
430
|
+
PKLExport int pkl_edgepaint(PKLImage pkl);
|
431
|
+
|
432
|
+
/* ポスタライズ(階調変更)→ブライトネス→ノイズ除去→輪郭抽出 */
|
433
|
+
// level:階調数(1-256) *256を何分割するかということ
|
434
|
+
// up: ポスタライズにより暗めの画像になってしまうので、ブライトネスで適用する色
|
435
|
+
PKLExport int pkl_edgeposter(PKLImage pkl, int level, int up);
|
436
|
+
|
437
|
+
|
438
|
+
/* 格子のずらし配置 */
|
439
|
+
// area:格子のサイズ
|
440
|
+
// shift:格子をずらす範囲
|
441
|
+
PKLExport int pkl_tileslit(PKLImage pkl, int area, int shift);
|
442
|
+
|
443
|
+
|
444
|
+
/* モザイクグリッド */
|
445
|
+
// モザイク化した上でグリッド線を引く
|
446
|
+
// <引数>
|
447
|
+
// msx,msy: モザイクのピクセルサイズ(それぞれ、幅・高さ)
|
448
|
+
// color: グリッド線の調整値
|
449
|
+
// グリッド線色は単色ではなく、モザイク領域の色を元に生成する
|
450
|
+
// colorはモザイク色に加算されるだけ。
|
451
|
+
// 0の時:モザイクと同色になり表出しない
|
452
|
+
// 255の時:いわゆる白線
|
453
|
+
// -255の時:いわゆる黒線
|
454
|
+
PKLExport int pkl_grid(PKLImage pkl, int msx, int msy, int color);
|
455
|
+
|
456
|
+
|
457
|
+
/* kuwahara(from MemoNyanDum) */
|
458
|
+
// kuwaharaオペレータを使った抽象化で油絵のようになる。
|
459
|
+
// pkl_oilpaint()との違いは、エッジがより鮮明であるという点。
|
460
|
+
// <引数>
|
461
|
+
// range: 調整領域(>=2)
|
462
|
+
//
|
463
|
+
// *rangeを大きくしすぎると、処理が重くなる。注意せよ
|
464
|
+
PKLExport int pkl_kuwahara(PKLImage pkl, int range);
|
465
|
+
|
466
|
+
/* アルファブレンド */
|
467
|
+
// parentの上にchildをアルファブレンドで乗せる
|
468
|
+
// <引数>
|
469
|
+
// parent: ベース(処理後はこのオブジェクトが更新される)
|
470
|
+
// child: 乗せる画像(このオブジェクトは処理しても不可侵)
|
471
|
+
// xpos,ypos:childを乗せるparent上の座標.
|
472
|
+
// 必ずparent上の座標でなければならない.
|
473
|
+
// alpha: α値(0-255)
|
474
|
+
// alpha=0の時: childは100%で乗る
|
475
|
+
// alpha=255の時:childは 0%で乗る
|
476
|
+
// <注意>
|
477
|
+
// parentとchildは同じカラーモードでなければエラーとなる
|
478
|
+
PKLExport int pkl_alphablend(PKLImage parent, PKLImage child, int xpos, int ypos, int alpha);
|
479
|
+
|
480
|
+
//アルファブレンド
|
481
|
+
//1との違いは、画像全体に対してアルファを効かせるのでなく
|
482
|
+
//画像の縁ほどアルファを強調するという点
|
483
|
+
PKLExport int pkl_alphablend2(PKLImage parent, PKLImage child, int xpos, int ypos);
|
484
|
+
|
485
|
+
//影付け
|
486
|
+
PKLExport int pkl_shadowframe(PKLImage pkl, int margin, int backcolor, int shadowcolor);
|
487
|
+
|
488
|
+
//輪郭抽出
|
489
|
+
//threshold: 輪郭強調度(値が小さいほど、輪郭判定は荒くなる-->全体が黒くなる)
|
490
|
+
PKLExport int pkl_edge(PKLImage pkl, int threshold);
|
491
|
+
|
492
|
+
typedef enum {
|
493
|
+
PKL_DITHER_NON, //pkl_dithercolorではdefaultとなる
|
494
|
+
PKL_DITHER_FLOYDSTEINBERG, //default
|
495
|
+
PKL_DITHER_STUCCI,
|
496
|
+
PKL_DITHER_SIERRA,
|
497
|
+
PKL_DITHER_JAJUNI
|
498
|
+
} PKL_DITHER;
|
499
|
+
PKLExport int pkl_dither(PKLImage pkl, PKL_DITHER dither);
|
500
|
+
|
501
|
+
//=============================================================================
|
502
|
+
// pattern(パターン)
|
503
|
+
//=============================================================================
|
504
|
+
typedef enum {
|
505
|
+
PKL_PAINT_LINE, //ライン(パターン内の横方向の平均で塗る)(default)
|
506
|
+
PKL_PAINT_AVE, //モザイク(パターン内の平均色で塗る)
|
507
|
+
} PKL_PAINT_TYPE;
|
508
|
+
|
509
|
+
/* 六角形 */
|
510
|
+
// pw,ph: パターンのサイズ
|
511
|
+
// phのサイズをpwの3倍に設定すると、縦横サイズが同じパターンになる
|
512
|
+
// type: 塗り方式
|
513
|
+
PKLExport int pkl_pattern_hexagon(PKLImage pkl, int pw, int ph, PKL_PAINT_TYPE type);
|
514
|
+
|
515
|
+
/* ひし形 */
|
516
|
+
// pw,ph: パターンのサイズ
|
517
|
+
// phのサイズをpwの2倍に設定すると、縦横サイズが同じパターンになる
|
518
|
+
// type: 塗り方式
|
519
|
+
// ex1) pw=10,ph=10にすると横長のパターン
|
520
|
+
// ex2) pw=10,ph=20にすると縦横同じ大きさのパターン
|
521
|
+
// ex3) pw=10,ph=30にすると縦長のパターン
|
522
|
+
PKLExport int pkl_pattern_diamond(PKLImage pkl, int pw, int ph, PKL_PAINT_TYPE type);
|
523
|
+
|
524
|
+
/* 円 */
|
525
|
+
// pw,ph: パターンのサイズ
|
526
|
+
// phのサイズをpwの3倍に設定すると、縦横サイズが同じパターンになる
|
527
|
+
// type: 塗り方式
|
528
|
+
PKLExport int pkl_pattern_circle(PKLImage pkl, int pw, int ph, PKL_PAINT_TYPE type);
|
529
|
+
|
530
|
+
/* レンガ */
|
531
|
+
// pw,ph: パターンのサイズ
|
532
|
+
// phのサイズをpwの4倍に設定すると、縦横サイズが同じパターンになる
|
533
|
+
// type: 塗り方式
|
534
|
+
PKLExport int pkl_pattern_brick(PKLImage pkl, int pw, int ph, PKL_PAINT_TYPE type);
|
535
|
+
|
536
|
+
|
537
|
+
/* ボロノイ分割(タイプ1) */
|
538
|
+
// zone: ボロノイサイズ(>=2, <w,h)
|
539
|
+
// bordercolor: -1の時は境界線を引かない。境界線色はpkl_colorで作る
|
540
|
+
// test: 真の時、分割シュミレーション図を出力する
|
541
|
+
PKLExport int pkl_voronoi_type1(PKLImage pkl, int zone, int bordercolor, int test);
|
542
|
+
|
543
|
+
|
544
|
+
/* ボロノイ分割(タイプ2) */
|
545
|
+
// count: 母点数(>=10)
|
546
|
+
// bordercolor: -1の時は境界線を引かない。境界線色はpkl_colorで作る
|
547
|
+
// test: 真の時、分割シュミレーション図を出力する
|
548
|
+
//
|
549
|
+
// *type1との違いは、母点がよりランダムに配置されるという点
|
550
|
+
PKLExport int pkl_voronoi_type2(PKLImage pkl, int count, int bordercolor, int test);
|
551
|
+
|
552
|
+
|
553
|
+
//=============================================================================
|
554
|
+
// decrease(減色)
|
555
|
+
//=============================================================================
|
556
|
+
/* メディアンカット */
|
557
|
+
// ncolors: 色数(1..256)
|
558
|
+
// dither: 真の時dither処理する
|
559
|
+
// *RGBのみ
|
560
|
+
// *設定した色数で保存するには、PNGかBMPにする必要がある(JPEGは非可逆のため)
|
561
|
+
PKLExport int pkl_mediancut(PKLImage pkl, int ncolors, int dither);
|
562
|
+
|
563
|
+
/* Neural-Net Quantization */
|
564
|
+
// ncolors: 色数(1..256)
|
565
|
+
// sample: sampling factor(1..30) 1=slowest/best, 30=fastest
|
566
|
+
// *設定した色数で保存するには、PNGかBMPにする必要がある(JPEGは非可逆のため)
|
567
|
+
// *メディアンカットより質のいい減色ができるが遅い。
|
568
|
+
PKLExport int pkl_neuquant(PKLImage pkl, int ncolors, int sample);
|
569
|
+
|
570
|
+
/* Xiaolin Wu */
|
571
|
+
// ncolors::色数(1..256)
|
572
|
+
// *設定した色数で保存するには、PNGかBMPにする必要がある(JPEGは非可逆のため)
|
573
|
+
PKLExport int pkl_wu(PKLImage pkl, int ncolors);
|
574
|
+
|
575
|
+
|
576
|
+
/* ポスタライズ(階調変更) */
|
577
|
+
// level:階調数(1-256) *256を何分割するかということ
|
578
|
+
PKLExport int pkl_posterize(PKLImage pkl, int level);
|
579
|
+
|
580
|
+
|
581
|
+
/* 色数削減 */
|
582
|
+
// 単純にlevelで指定した下位ビットを削除する。
|
583
|
+
// level: 無効にする下位ビット数(0-255)
|
584
|
+
PKLExport int pkl_cutcolor(PKLImage pkl, int level);
|
585
|
+
|
586
|
+
|
587
|
+
//=============================================================================
|
588
|
+
// scrap(スクラップ)
|
589
|
+
// Junkiさんところを参考に作ったものや試行錯誤品
|
590
|
+
//=============================================================================
|
591
|
+
/* 渦巻き */
|
592
|
+
// factor: 渦巻き度合い(絶対値で1以下の範囲で指定する。0に近いほど、ゆるやかな渦巻きになる)
|
593
|
+
// * 負数と正数の違いは回転方向
|
594
|
+
// x,y: 渦巻きの中心点(座標が画像内に収まらない場合は、中心となる)
|
595
|
+
// backcolor:背景色
|
596
|
+
// * Junkiさんとことの違いは、ピクセル生成時にバイリニアしていないこと。なので、粗い画像になる
|
597
|
+
PKLExport int pkl_swirl(PKLImage pkl, double factor, int x, int y, int backcolor);
|
598
|
+
|
599
|
+
/* wave */
|
600
|
+
// factor:周期
|
601
|
+
// frequency:振幅
|
602
|
+
typedef enum {
|
603
|
+
PKL_WAVE_HORZ, //横方向のwave
|
604
|
+
PKL_WAVE_VERT, //縦方向のwave
|
605
|
+
PKL_WAVE_BOTH //縦横のwave
|
606
|
+
} PKL_WAVE;
|
607
|
+
PKLExport int pkl_wave(PKLImage pkl, PKL_WAVE mode, double factor, double frequency);
|
608
|
+
|
609
|
+
|
610
|
+
/* さほど美しくないドット絵 */
|
611
|
+
// 円の描画を自力でやっているので、微妙な仕上がり品。
|
612
|
+
// zone:ドット化する領域の一辺のサイズ(3..10)
|
613
|
+
// color:ドットの色(pkl_colorで作る)
|
614
|
+
PKLExport int pkl_dots(PKLImage pkl, int zone, int color);
|
615
|
+
|
616
|
+
|
617
|
+
/* フォトフレーム分割 */
|
618
|
+
// イメージを分割し、フォトフレームのようにする
|
619
|
+
// backcolor: 背景色
|
620
|
+
// wbs,hbs: オリジナルイメージの縦横分割数(>0)
|
621
|
+
// margin: キャンバスのマージン(上下左右の空間)(>0)
|
622
|
+
// frame: フレームの太さ(>=1)
|
623
|
+
PKLExport int pkl_splitframe(PKLImage pkl, int backcolor, int wbs, int hbs, int margin, int frame);
|
624
|
+
|
625
|
+
/* カラーディザー */
|
626
|
+
//weight: 誤差点に確定しなかった色に対する加算色
|
627
|
+
// +255以上の時は完全な白
|
628
|
+
// -255以下の時は完全な黒
|
629
|
+
PKLExport int pkl_colordither(PKLImage pkl, int weight);
|
630
|
+
|
631
|
+
PKLExport int pkl_ttt(PKLImage pkl);
|
256
632
|
|
257
|
-
/*!
|
258
|
-
PKLImageオブジェクトの破棄<br>
|
259
|
-
確保していたメモリを全て解放します。用がなくなったら実行するようにしてください。
|
260
|
-
@param pkl [in] PKLImageオブジェクト
|
261
|
-
@return 成功した場合は0。失敗した場合は真を返します。
|
262
|
-
*/
|
263
|
-
PKLExport void pkl_close(PKLImage pkl);
|
264
633
|
|
265
634
|
#if defined __cplusplus
|
266
635
|
}
|
data/ext/pikl/pikl_bitmap.c
CHANGED
data/ext/pikl/pikl_effect.c
CHANGED
@@ -7,7 +7,7 @@ PKLExport int pkl_unsharp(PKLImage pkl, int threshold, double edge)
|
|
7
7
|
{
|
8
8
|
int i, j, p, q, k;
|
9
9
|
int cnt, value, stock[PKL_CHANNEL];
|
10
|
-
unsigned char *wrk;
|
10
|
+
unsigned char *wrk, *s;
|
11
11
|
|
12
12
|
wrk = malloc(pkl->height * pkl->width * pkl->channel);
|
13
13
|
if(!wrk) return(1);
|
@@ -26,15 +26,15 @@ PKLExport int pkl_unsharp(PKLImage pkl, int threshold, double edge)
|
|
26
26
|
}
|
27
27
|
}
|
28
28
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
s = &wrk[(i * pkl->width + j) * pkl->channel];
|
30
|
+
for(k=0; k<pkl->channel; k++)
|
31
|
+
*s++ = stock[k] / cnt;
|
32
32
|
}
|
33
33
|
}
|
34
34
|
|
35
35
|
for(i=0; i<pkl->height*pkl->width*pkl->channel; i++){
|
36
36
|
value = abs(pkl->image[i]-wrk[i])<threshold ? pkl->image[i] : pkl->image[i]+(pkl->image[i]-wrk[i])*edge;
|
37
|
-
pkl->image[i] =
|
37
|
+
pkl->image[i] = PKL_COLOR_CLIP(value);
|
38
38
|
}
|
39
39
|
free(wrk);
|
40
40
|
return(0);
|
@@ -54,17 +54,18 @@ PKLExport int pkl_contrast(PKLImage pkl, int rate)
|
|
54
54
|
//�d�݂������̎��͒����I�ɕ��R��
|
55
55
|
for(i=0; i<PKL_COLOR; i++){
|
56
56
|
value = i + (i-127) * rate/127;
|
57
|
-
ct[i] =
|
57
|
+
ct[i] = PKL_COLOR_CLIP(value);
|
58
58
|
}
|
59
59
|
}else{
|
60
60
|
//�d�݂������̎��͎��g��
|
61
61
|
for(i=0; i<PKL_COLOR; i++){
|
62
62
|
value = i - rate*rate/127 * sin(M_PI/2+M_PI*i/255);
|
63
|
-
ct[i] =
|
63
|
+
ct[i] = PKL_COLOR_CLIP(value);
|
64
64
|
}
|
65
65
|
}
|
66
66
|
|
67
|
-
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++)
|
67
|
+
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++)
|
68
|
+
pkl->image[i] = ct[pkl->image[i]];
|
68
69
|
|
69
70
|
return(0);
|
70
71
|
}
|
@@ -110,7 +111,7 @@ PKLExport int pkl_level(PKLImage pkl, double low, double high, double coeff)
|
|
110
111
|
for(i=0; i<pkl->width*pkl->height; i++){
|
111
112
|
for(j=0; j<pkl->channel; j++){
|
112
113
|
value = ((coeff * pkl->image[i*pkl->channel+j])-hst[j].min)/(hst[j].max-hst[j].min) * 255;
|
113
|
-
pkl->image[i*pkl->channel+j] =
|
114
|
+
pkl->image[i*pkl->channel+j] = PKL_COLOR_CLIP(value);
|
114
115
|
}
|
115
116
|
}
|
116
117
|
|
@@ -124,7 +125,7 @@ PKLExport int pkl_brightness(PKLImage pkl, int color)
|
|
124
125
|
{
|
125
126
|
int i;
|
126
127
|
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++){
|
127
|
-
pkl->image[i] =
|
128
|
+
pkl->image[i] = PKL_COLOR_CLIP(pkl->image[i] + color);
|
128
129
|
}
|
129
130
|
return(0);
|
130
131
|
}
|
@@ -164,9 +165,9 @@ PKLExport int pkl_hls(PKLImage pkl, double ym, double sm, double hd)
|
|
164
165
|
c1 = s * sin(M_PI * h / 180.0);
|
165
166
|
c2 = s * cos(M_PI * h / 180.0);
|
166
167
|
|
167
|
-
pkl->image[i*pkl->channel] =
|
168
|
-
pkl->image[i*pkl->channel+1] =
|
169
|
-
pkl->image[i*pkl->channel+2] =
|
168
|
+
pkl->image[i*pkl->channel] = PKL_COLOR_CLIP(c1 + y);
|
169
|
+
pkl->image[i*pkl->channel+1] = PKL_COLOR_CLIP(y - (0.299*c1 + 0.114*c2)/0.587);
|
170
|
+
pkl->image[i*pkl->channel+2] = PKL_COLOR_CLIP(c2 + y);
|
170
171
|
}
|
171
172
|
return(0);
|
172
173
|
}
|
@@ -182,10 +183,58 @@ PKLExport int pkl_gamma(PKLImage pkl, double gm)
|
|
182
183
|
if(gm < 0.0) return(1);
|
183
184
|
|
184
185
|
for(i=0; i<PKL_COLOR; i++)
|
185
|
-
gt[i] =
|
186
|
+
gt[i] = PKL_COLOR_CLIP(255.0 * pow(i/255.0, 1.0/gm));
|
186
187
|
|
187
188
|
for(i=0; i<pkl->width*pkl->height*pkl->channel; i++)
|
188
189
|
pkl->image[i] = gt[pkl->image[i]];
|
189
190
|
|
190
191
|
return(0);
|
191
192
|
}
|
193
|
+
|
194
|
+
//=============================================================================
|
195
|
+
// pkl_noisecut(median filter)
|
196
|
+
//=============================================================================
|
197
|
+
PKLExport int pkl_noisecut(PKLImage pkl)
|
198
|
+
{
|
199
|
+
unsigned char *wrk, *p, sort[PKL_CHANNEL][9], median[PKL_CHANNEL];
|
200
|
+
int i, j, tx, ty, k, clipx, clipy, rd, s, t, n;
|
201
|
+
|
202
|
+
wrk = malloc(pkl->width*pkl->height*pkl->channel);
|
203
|
+
if(!wrk) return(1);
|
204
|
+
memset(wrk, 0, pkl->width*pkl->height*pkl->channel);
|
205
|
+
|
206
|
+
for(i=0; i<pkl->height; i++){
|
207
|
+
for(j=0; j<pkl->width; j++){
|
208
|
+
rd=0;
|
209
|
+
for(ty=-1; ty<=1; ty++){
|
210
|
+
for(tx=-1; tx<=1; tx++){
|
211
|
+
clipx = j+tx < 0 ? 0 : j+tx>=pkl->width ? pkl->width-1 : j+tx;
|
212
|
+
clipy = i+ty < 0 ? 0 : i+ty>=pkl->height ? pkl->height-1 : i+ty;
|
213
|
+
p = &pkl->image[(clipy*pkl->width+clipx)*pkl->channel];
|
214
|
+
for(k=0; k<pkl->channel; k++)
|
215
|
+
sort[k][rd] = *p++;
|
216
|
+
rd++;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
//�����l�T��
|
220
|
+
for(k=0; k<pkl->channel; k++){
|
221
|
+
for(s=0; s<5; s++){
|
222
|
+
for(t=1,n=0,median[k]=sort[k][0]; t<9; t++){
|
223
|
+
if(median[k]<sort[k][t]){
|
224
|
+
median[k]=sort[k][t];
|
225
|
+
n=t;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
sort[k][n]=0;
|
229
|
+
}
|
230
|
+
}
|
231
|
+
p= &wrk[(i*pkl->width+j)*pkl->channel];
|
232
|
+
for(k=0; k<pkl->channel; k++) *p++=median[k];
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
free(pkl->image);
|
237
|
+
pkl->image = wrk;
|
238
|
+
return(0);
|
239
|
+
}
|
240
|
+
|
data/ext/pikl/pikl_io.c
CHANGED
data/ext/pikl/pikl_png.c
CHANGED
@@ -24,11 +24,11 @@ int load_png(PKLImage pkl, FILE *image)
|
|
24
24
|
return(1);
|
25
25
|
}
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
if( setjmp(png_jmpbuf(png_ptr)) ){
|
28
|
+
png_destroy_info_struct(png_ptr, &info_ptr);
|
29
|
+
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
30
|
+
return(1);
|
31
|
+
}
|
32
32
|
|
33
33
|
png_init_io(png_ptr, image);
|
34
34
|
png_read_info(png_ptr, info_ptr);
|
@@ -66,6 +66,9 @@ int save_png(PKLImage pkl, FILE *image)
|
|
66
66
|
png_infop info_ptr;
|
67
67
|
int i;
|
68
68
|
|
69
|
+
if(pkl->color!=PKL_RGB &&
|
70
|
+
pkl->color!=PKL_GRAYSCALE) return(1);
|
71
|
+
|
69
72
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
70
73
|
if(!png_ptr) return(1);
|
71
74
|
|
@@ -75,11 +78,11 @@ int save_png(PKLImage pkl, FILE *image)
|
|
75
78
|
return(1);
|
76
79
|
}
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
if( setjmp(png_jmpbuf(png_ptr)) ){
|
82
|
+
png_destroy_info_struct(png_ptr, &info_ptr);
|
83
|
+
png_destroy_write_struct(&png_ptr, &info_ptr);
|
84
|
+
return(1);
|
85
|
+
}
|
83
86
|
|
84
87
|
png_init_io(png_ptr, image);
|
85
88
|
info_ptr->width = pkl->width;
|
data/ext/pikl/pikl_png.h
CHANGED
data/ext/pikl/pikl_private.h
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#define _LIB_PIKL_PRIVATE_
|
3
3
|
|
4
4
|
#define PKL_MINMAX(a,b,i) (((a>=i)?a:((b<=i)?b:i)))
|
5
|
-
#define
|
5
|
+
#define PKL_COLOR_CLIP(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
|
@@ -19,6 +19,11 @@ struct _PKLImage {
|
|
19
19
|
unsigned char *image;
|
20
20
|
PKL_FORMAT format;
|
21
21
|
int compress;
|
22
|
+
|
23
|
+
//affine
|
24
|
+
double x_scale, y_scale;
|
25
|
+
double angle;
|
26
|
+
double x_trns, y_trns;
|
22
27
|
};
|
23
28
|
|
24
29
|
#endif
|
data/ext/pikl/pikl_resize.c
CHANGED
@@ -99,7 +99,7 @@ static int resize_bl(PKLImage pkl, int width, int height)
|
|
99
99
|
sy = ((int)py+wy<0) ? pkl->height+((int)py+wy)%pkl->height-1 : ((int)py+wy)%pkl->height;
|
100
100
|
for(k=0; k<pkl->channel; k++){
|
101
101
|
wrk[(i*width+j)*pkl->channel+k] =
|
102
|
-
|
102
|
+
PKL_COLOR_CLIP(wrk[(i*width+j)*pkl->channel+k] + pkl->image[(sy*pkl->width+sx)*pkl->channel+k] * f[wy*2+wx]);
|
103
103
|
}
|
104
104
|
}
|
105
105
|
}
|
@@ -146,7 +146,7 @@ static int resize_bc(PKLImage pkl, int width, int height)
|
|
146
146
|
for(k=0; k<pkl->channel; k++) data[k]+=pkl->image[(y0*pkl->width+x0)*pkl->channel+k]*wx*wy;
|
147
147
|
}
|
148
148
|
}
|
149
|
-
for(k=0; k<pkl->channel; k++) wrk[(i*width+j)*pkl->channel+k]=
|
149
|
+
for(k=0; k<pkl->channel; k++) wrk[(i*width+j)*pkl->channel+k]=PKL_COLOR_CLIP(data[k]);
|
150
150
|
}
|
151
151
|
}
|
152
152
|
free(pkl->image);
|
@@ -198,7 +198,7 @@ static int resize_pa(PKLImage pkl, int width, int height)
|
|
198
198
|
}
|
199
199
|
}
|
200
200
|
for(k=0; k<pkl->channel; k++)
|
201
|
-
wrk[(i*width+j)*pkl->channel+k] =
|
201
|
+
wrk[(i*width+j)*pkl->channel+k] = PKL_COLOR_CLIP(ixg[k]/(zx*zy));
|
202
202
|
}
|
203
203
|
}
|
204
204
|
free(pkl->image);
|
data/ext/pikl/pikl_rotate2.c
CHANGED
@@ -159,7 +159,7 @@ static int pkl_rotate_bl(PKLImage pkl, float angle, unsigned char *backcolor)
|
|
159
159
|
if(px>=0 && px<pkl->width && py>=0 && py<pkl->height){
|
160
160
|
for(k=0; k<pkl->channel; k++){
|
161
161
|
wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] =
|
162
|
-
|
162
|
+
PKL_COLOR_CLIP(wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] +
|
163
163
|
pkl->image[(sy*pkl->width+sx)*pkl->channel+k] * f[wy*2+wx]);
|
164
164
|
}
|
165
165
|
}else{
|
@@ -226,7 +226,7 @@ static int pkl_rotate_bc(PKLImage pkl, float angle, unsigned char *backcolor)
|
|
226
226
|
|
227
227
|
if(sx>=0 && sx<pkl->width && sy>=0 && sy<pkl->height){
|
228
228
|
for(k=0; k<pkl->channel; k++)
|
229
|
-
wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] =
|
229
|
+
wrk[((i-rect.top)*width+j-rect.left)*pkl->channel+k] = PKL_COLOR_CLIP(data[k]);
|
230
230
|
}else{
|
231
231
|
memcpy(&wrk[((i-rect.top)*width+j-rect.left)*pkl->channel], back, pkl->channel);
|
232
232
|
}
|
data/lib/pikl/ext.rb
CHANGED
@@ -33,5 +33,9 @@ module Pikl
|
|
33
33
|
extern "int pkl_hls(PKLImage*, double, double, double)"
|
34
34
|
extern "int pkl_gamma(PKLImage*, double)"
|
35
35
|
|
36
|
+
extern "int pkl_mosaic(PKLImage *, int, int)"
|
37
|
+
extern "int pkl_composite(PKLImage *, PKLImage *, int, int)"
|
38
|
+
extern "int pkl_mediancut(PKLImage *, int, int)"
|
39
|
+
extern "int pkl_alphablend(PKLImage *, PKLImage *, int, int, int)"
|
36
40
|
end
|
37
41
|
end
|
data/lib/pikl/image.rb
CHANGED
@@ -16,6 +16,10 @@ module Pikl
|
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
+
def rawdata
|
20
|
+
@pkl_image
|
21
|
+
end
|
22
|
+
|
19
23
|
def initialize( inpath )
|
20
24
|
@pkl_image = Ext.pkl_open(File.expand_path(inpath))
|
21
25
|
end
|
@@ -28,7 +32,7 @@ module Pikl
|
|
28
32
|
validate_compress(compress)
|
29
33
|
Ext.pkl_compress(@pkl_image, compress.to_i)
|
30
34
|
end
|
31
|
-
Ext.pkl_save(@pkl_image, File.expand_path(outpath), EXTENSIONS_FORMATS[format.to_s] || format.to_i)
|
35
|
+
Ext.pkl_save(@pkl_image, File.expand_path(outpath), EXTENSIONS_FORMATS[format.to_s.downcase] || format.to_i)
|
32
36
|
self.close unless(@block)
|
33
37
|
@pkl_image
|
34
38
|
end
|
@@ -195,17 +199,50 @@ module Pikl
|
|
195
199
|
self
|
196
200
|
end
|
197
201
|
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
# gm=0以上の値が指定できます。
|
202
|
-
# 1.0より小さい時は暗く、1.0より大きい時は明るく調整されます。
|
203
|
-
# 1.0を指定した時は調整されません。
|
202
|
+
# gamma correction
|
203
|
+
# _gm_ :: compensating rate.
|
204
|
+
# gm must be >= 0 and image is neutral if gm value is 1.0.
|
204
205
|
def gamma(gm)
|
205
206
|
Ext.pkl_gamma(@pkl_image, gm.to_f)
|
206
207
|
self
|
207
208
|
end
|
208
209
|
|
210
|
+
# mosaic effect
|
211
|
+
# _width_ :: width for mosaic unit.
|
212
|
+
# _height_ :: height for mosaic unit.
|
213
|
+
def mosaic(width, height)
|
214
|
+
Ext.pkl_mosaic(@pkl_image, width, height)
|
215
|
+
self
|
216
|
+
end
|
217
|
+
|
218
|
+
# compose image
|
219
|
+
# _image_ :: another pikl image object.
|
220
|
+
# _xpos_ :: left position of composing image.
|
221
|
+
# _ypos_ :: top position of composing image.
|
222
|
+
def compose(image, xpos, ypos)
|
223
|
+
Ext.pkl_composite(@pkl_image, image.rawdata, xpos, ypos)
|
224
|
+
self
|
225
|
+
end
|
226
|
+
|
227
|
+
# mediancut to decrease colors.
|
228
|
+
# _ncolors_ :: num of colors.(1..256)
|
229
|
+
# _dither_ :: dither. true/false
|
230
|
+
def mediancut(ncolors, dither)
|
231
|
+
dither = dither ? 1 : 0
|
232
|
+
Ext.pkl_mediancut(@pkl_image, 4, dither)
|
233
|
+
self
|
234
|
+
end
|
235
|
+
|
236
|
+
# alphablend
|
237
|
+
# _image_ :: another pikl image object.
|
238
|
+
# _xpos_ :: left position of blend image.
|
239
|
+
# _ypos_ :: top position of blend image.
|
240
|
+
# _alpha_ :: alpha: α-value(0-255). 255 is complete transparent.
|
241
|
+
def alphablend(image, xpos, ypos, alpha)
|
242
|
+
Ext.pkl_alphablend(@pkl_image, image.rawdata, xpos, ypos, alpha);
|
243
|
+
self
|
244
|
+
end
|
245
|
+
|
209
246
|
# regular expressions to try for identifying extensions
|
210
247
|
def split_extensions(path)
|
211
248
|
filename = path.split('/').last
|
data/lib/pikl/version.rb
CHANGED
data/test/test_pikl_image.rb
CHANGED
@@ -194,7 +194,7 @@ class TestPiklImage < Test::Unit::TestCase
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
def
|
197
|
+
def test_fit_inner2
|
198
198
|
# vertical-inner
|
199
199
|
Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
200
200
|
img.fit(20,100)
|
@@ -363,10 +363,56 @@ class TestPiklImage < Test::Unit::TestCase
|
|
363
363
|
end
|
364
364
|
end
|
365
365
|
|
366
|
-
|
366
|
+
# mosaic effect
|
367
|
+
# _width_ :: width for mosaic unit.
|
368
|
+
# _height_ :: height for mosaic unit.
|
369
|
+
def test_mosaic
|
367
370
|
Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
368
|
-
img.
|
371
|
+
img.mosaic(3,3)
|
369
372
|
end
|
370
373
|
end
|
374
|
+
|
375
|
+
# compose image
|
376
|
+
# _image_ :: another pikl image object.
|
377
|
+
# _xpos_ :: left position of composing image.
|
378
|
+
# _ypos_ :: top position of composing image.
|
379
|
+
# def test_compose
|
380
|
+
# Pikl::Image.open(SAMPLE_IMAGE) do |img2|
|
381
|
+
# Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
382
|
+
# img.compose(img2,3,3)
|
383
|
+
# end
|
384
|
+
# end
|
385
|
+
# end
|
386
|
+
|
387
|
+
# # mediancut to decrease colors.
|
388
|
+
# # _ncolors_ :: num of colors.(1..256)
|
389
|
+
# # _dither_ :: dither. true/false
|
390
|
+
# def test_mediancut
|
391
|
+
# Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
392
|
+
# img.mediancut(256,true)
|
393
|
+
# end
|
394
|
+
# end
|
395
|
+
|
396
|
+
# alphablend
|
397
|
+
# _image_ :: another pikl image object.
|
398
|
+
# _xpos_ :: left position of blend image.
|
399
|
+
# _ypos_ :: top position of blend image.
|
400
|
+
# _alpha_ :: alpha: α-value(0-255). 255 is complete transparent.
|
401
|
+
def test_alphablend
|
402
|
+
Pikl::Image.open(SAMPLE_IMAGE) do |img2|
|
403
|
+
Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
404
|
+
img.alphablend(img2,0,0,200)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
# def test_method_chain
|
410
|
+
# Pikl::Image.open(SAMPLE_IMAGE) do |img2|
|
411
|
+
# Pikl::Image.open(SAMPLE_IMAGE) do |img|
|
412
|
+
# 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).mosaic(3,3).mediancut(256,true).compose(img2,10,10).save(SAMPLE_OUTPUT)
|
413
|
+
# end
|
414
|
+
# end
|
415
|
+
# end
|
416
|
+
|
371
417
|
|
372
418
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pikl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: x86-mswin32
|
6
6
|
authors:
|
7
7
|
- Ryota Maruko
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-27 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|