rszr 1.4.0 → 1.5.1
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 +4 -4
- data/README.md +8 -0
- data/ext/rszr/errors.h +1 -0
- data/ext/rszr/image.c +68 -12
- data/ext/rszr/image.h +4 -0
- data/lib/rszr/image.rb +11 -0
- data/lib/rszr/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f2a52f40e9ac6688345bcb8fcd3a27b14a7e9e50783751c0067a8eb678414cd
|
|
4
|
+
data.tar.gz: 6845fdceafd2abc6bc6ff1daca9186d930f7f9c27ce5f607dfa4e0be049cd98b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd6170c8710307867de88a376edd1635d1afa239719e76a1c5dca13e5b0936b617f8f4b5183d2ede01825102cea3a9a343bf3508bed88a948c685560e645afb7
|
|
7
|
+
data.tar.gz: 55874169e944187bea206565fe823b4fb49f52d8dd25e633eb20a00a8359258bab037584712ac2337046ac5a250e83563752918a4ab3b769be26ac2af4c2d6df
|
data/README.md
CHANGED
|
@@ -238,6 +238,14 @@ image.contrast(0.5)
|
|
|
238
238
|
|
|
239
239
|
# gamma
|
|
240
240
|
image.gamma(1.1)
|
|
241
|
+
|
|
242
|
+
# convert to grayscale (automatic mode)
|
|
243
|
+
image.desaturate
|
|
244
|
+
|
|
245
|
+
# convert to grayscale with mode
|
|
246
|
+
image.desaturate(:lightness)
|
|
247
|
+
image.desaturate(:luminosity)
|
|
248
|
+
image.desaturate(:average)
|
|
241
249
|
```
|
|
242
250
|
|
|
243
251
|
### Image auto orientation
|
data/ext/rszr/errors.h
CHANGED
|
@@ -6,6 +6,7 @@ void rszr_raise_load_error(Imlib_Load_Error error);
|
|
|
6
6
|
void rszr_raise_save_error(Imlib_Load_Error error);
|
|
7
7
|
|
|
8
8
|
extern VALUE eRszrError;
|
|
9
|
+
extern VALUE eRszrInternalError;
|
|
9
10
|
extern VALUE eRszrFileNotFound;
|
|
10
11
|
extern VALUE eRszrTransformationError;
|
|
11
12
|
extern VALUE eRszrErrorWithMessage;
|
data/ext/rszr/image.c
CHANGED
|
@@ -27,14 +27,14 @@ static void rszr_image_deallocate(rszr_image_handle * handle)
|
|
|
27
27
|
rszr_free_image(handle->image);
|
|
28
28
|
handle->image = NULL;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
xfree(handle);
|
|
31
31
|
// fprintf(stderr, "\n");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
static VALUE rszr_image_s_allocate(VALUE klass)
|
|
35
35
|
{
|
|
36
|
-
rszr_image_handle * handle
|
|
37
|
-
return
|
|
36
|
+
rszr_image_handle * handle;
|
|
37
|
+
return Data_Make_Struct(klass, rszr_image_handle, NULL, rszr_image_deallocate, handle);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
|
|
@@ -49,6 +49,13 @@ static VALUE rszr_image__initialize(VALUE self, VALUE rb_width, VALUE rb_height)
|
|
|
49
49
|
|
|
50
50
|
handle->image = imlib_create_image(FIX2INT(rb_width), FIX2INT(rb_height));
|
|
51
51
|
|
|
52
|
+
if (!handle->image) {
|
|
53
|
+
rb_raise(eRszrInternalError, "error creating image");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
imlib_context_set_image(handle->image);
|
|
57
|
+
imlib_image_clear();
|
|
58
|
+
|
|
52
59
|
return self;
|
|
53
60
|
}
|
|
54
61
|
|
|
@@ -394,6 +401,54 @@ static VALUE rszr_image__sharpen_bang(VALUE self, VALUE rb_radius)
|
|
|
394
401
|
}
|
|
395
402
|
|
|
396
403
|
|
|
404
|
+
static void rszr_desaturate_pixel(rszr_raw_pixel * pixel, int mode)
|
|
405
|
+
{
|
|
406
|
+
uint8_t grey;
|
|
407
|
+
if (mode == 2 || (mode == 0 && (pixel->blue > pixel->red && pixel->blue > pixel->green))) {
|
|
408
|
+
// lightness
|
|
409
|
+
grey = (pixel->blue + (pixel->red > pixel->green ? pixel->green : pixel->red)) / 2;
|
|
410
|
+
} else if (mode == 1 || mode == 0) {
|
|
411
|
+
// luminosity
|
|
412
|
+
grey = 0.21 * pixel->red + 0.72 * pixel->green + 0.07 * pixel->blue;
|
|
413
|
+
} else {
|
|
414
|
+
// average
|
|
415
|
+
grey = (pixel->red + pixel->green + pixel->blue) / 3;
|
|
416
|
+
}
|
|
417
|
+
pixel->red = grey;
|
|
418
|
+
pixel->green = grey;
|
|
419
|
+
pixel->blue = grey;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
static VALUE rszr_image__desaturate_bang(VALUE self, VALUE rb_mode)
|
|
423
|
+
{
|
|
424
|
+
rszr_image_handle * handle;
|
|
425
|
+
rszr_raw_pixel * pixels;
|
|
426
|
+
uint64_t size;
|
|
427
|
+
int mode;
|
|
428
|
+
|
|
429
|
+
mode = NUM2INT(rb_mode);
|
|
430
|
+
|
|
431
|
+
Data_Get_Struct(self, rszr_image_handle, handle);
|
|
432
|
+
|
|
433
|
+
imlib_context_set_image(handle->image);
|
|
434
|
+
|
|
435
|
+
pixels = (rszr_raw_pixel *) imlib_image_get_data();
|
|
436
|
+
if (pixels == NULL) {
|
|
437
|
+
rb_raise(eRszrTransformationError, "error desaturating image");
|
|
438
|
+
return Qnil;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
size = imlib_image_get_width() * imlib_image_get_height();
|
|
442
|
+
for (uint64_t i = 0; i < size; i++) {
|
|
443
|
+
rszr_desaturate_pixel(&pixels[i], mode);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
imlib_image_put_back_data((uint32_t *) pixels);
|
|
447
|
+
|
|
448
|
+
return self;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
|
|
397
452
|
static Imlib_Image rszr_create_cropped_scaled_image(const Imlib_Image image, VALUE rb_src_x, VALUE rb_src_y, VALUE rb_src_w, VALUE rb_src_h, VALUE rb_dst_w, VALUE rb_dst_h)
|
|
398
453
|
{
|
|
399
454
|
Imlib_Image resized_image;
|
|
@@ -688,15 +743,16 @@ void Init_rszr_image()
|
|
|
688
743
|
rb_define_protected_method(cImage, "_format", rszr_image__format_get, 0);
|
|
689
744
|
rb_define_protected_method(cImage, "_format=", rszr_image__format_set, 1);
|
|
690
745
|
|
|
691
|
-
rb_define_private_method(cImage, "_initialize",
|
|
692
|
-
rb_define_private_method(cImage, "_resize",
|
|
693
|
-
rb_define_private_method(cImage, "_crop",
|
|
694
|
-
rb_define_private_method(cImage, "_turn!",
|
|
695
|
-
rb_define_private_method(cImage, "_rotate",
|
|
696
|
-
rb_define_private_method(cImage, "_sharpen!",
|
|
697
|
-
rb_define_private_method(cImage, "
|
|
698
|
-
rb_define_private_method(cImage, "
|
|
699
|
-
rb_define_private_method(cImage, "
|
|
746
|
+
rb_define_private_method(cImage, "_initialize", rszr_image__initialize, 2);
|
|
747
|
+
rb_define_private_method(cImage, "_resize", rszr_image__resize, 7);
|
|
748
|
+
rb_define_private_method(cImage, "_crop", rszr_image__crop, 5);
|
|
749
|
+
rb_define_private_method(cImage, "_turn!", rszr_image__turn_bang, 1);
|
|
750
|
+
rb_define_private_method(cImage, "_rotate", rszr_image__rotate, 2);
|
|
751
|
+
rb_define_private_method(cImage, "_sharpen!", rszr_image__sharpen_bang, 1);
|
|
752
|
+
rb_define_private_method(cImage, "_desaturate!", rszr_image__desaturate_bang, 1);
|
|
753
|
+
rb_define_private_method(cImage, "_pixel", rszr_image__pixel_get, 2);
|
|
754
|
+
rb_define_private_method(cImage, "_blend", rszr_image__blend, 11);
|
|
755
|
+
rb_define_private_method(cImage, "_rectangle!", rszr_image__rectangle_bang, 5);
|
|
700
756
|
|
|
701
757
|
rb_define_private_method(cImage, "_save", rszr_image__save, 4);
|
|
702
758
|
}
|
data/ext/rszr/image.h
CHANGED
data/lib/rszr/image.rb
CHANGED
|
@@ -2,6 +2,7 @@ module Rszr
|
|
|
2
2
|
class Image
|
|
3
3
|
GRAVITIES = [true, :center, :n, :nw, :w, :sw, :s, :se, :e, :ne].freeze
|
|
4
4
|
BLENDING_MODES = %i[copy add subtract reshade].freeze
|
|
5
|
+
DESATURATION_MODES = %i[dynamic luminosity lightness average].freeze
|
|
5
6
|
|
|
6
7
|
extend Identification
|
|
7
8
|
include Buffered
|
|
@@ -119,6 +120,16 @@ module Rszr
|
|
|
119
120
|
_sharpen!(-radius)
|
|
120
121
|
end
|
|
121
122
|
|
|
123
|
+
def desaturate!(mode = :dynamic)
|
|
124
|
+
_mode = DESATURATION_MODES.index(mode)
|
|
125
|
+
raise ArgumentError, 'illegal mode' unless _mode
|
|
126
|
+
_desaturate!(_mode);
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def desaturate(*args, **opts)
|
|
130
|
+
dup.desaturate!(*args, **opts)
|
|
131
|
+
end
|
|
132
|
+
|
|
122
133
|
def filter(filter_expr)
|
|
123
134
|
dup.filter!(filter_expr)
|
|
124
135
|
end
|
data/lib/rszr/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rszr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthias Grosser
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Fast image resizer - do one thing and do it fast.
|
|
14
13
|
email:
|
|
@@ -48,7 +47,6 @@ homepage: https://github.com/mtgrosser/rszr
|
|
|
48
47
|
licenses:
|
|
49
48
|
- MIT
|
|
50
49
|
metadata: {}
|
|
51
|
-
post_install_message:
|
|
52
50
|
rdoc_options: []
|
|
53
51
|
require_paths:
|
|
54
52
|
- lib
|
|
@@ -65,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
65
63
|
version: '0'
|
|
66
64
|
requirements:
|
|
67
65
|
- imlib2
|
|
68
|
-
rubygems_version:
|
|
69
|
-
signing_key:
|
|
66
|
+
rubygems_version: 4.0.3
|
|
70
67
|
specification_version: 4
|
|
71
68
|
summary: Fast image resizer
|
|
72
69
|
test_files: []
|