fast_thumbhash 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/ext/fast_thumbhash/fast_thumbhash.c +18 -13
- data/ext/fast_thumbhash/fast_thumbhash.h +1 -1
- data/lib/fast_thumbhash/version.rb +1 -1
- data/lib/fast_thumbhash.rb +11 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60904812112ec4cbab475e36e04f7634c96cb36946d5c3e178ccbfe1ca985727
|
4
|
+
data.tar.gz: d195d956dcbc219971be4d25fbb486fb5d61515a1a9ea33c03ec184bb97c4a5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae83b2dd113977b72d4b89207c41119038b062b73d4d07e67864391764f6a6d3ef2791ac323c8ef2851a83c57c3cf9cefaca1c8feca6f717bcfe30ce177dcdb3
|
7
|
+
data.tar.gz: 3ffb0c9274880eb74092c866b1a618ca315a94348c4725f1e64ebba474982708e9d99f6d30e88d76352a8d6f3cad45ccabc92747e2e3d743c94baa6eeee83b14
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -92,7 +92,7 @@ w, h, rgba = described_class.thumbhash_to_rgba(
|
|
92
92
|
|
93
93
|
##### `fill_mode`
|
94
94
|
|
95
|
-
The `fill_mode` option specifies how to fill in any transparent areas in your image with a color of your choice. When `fill_mode` is `:solid`, you need to pass an additional `fill_color` option to specify the actual RGBA color to use. When `fill_mode` is `:blur`, the excess space will be filled with a blurred version of the original image itself.
|
95
|
+
The `fill_mode` option specifies how to fill in any transparent areas in your image with a color of your choice. When `fill_mode` is `:solid`, you need to pass an additional `fill_color` option to specify the actual RGBA color to use. When `fill_mode` is `:blur`, the excess space will be filled with a blurred version of the original image itself. When `fill_image` is `:clamp`, the excess space is filled with extended pixels from the edge of the image.
|
96
96
|
|
97
97
|
```ruby
|
98
98
|
w, h, rgba = described_class.thumbhash_to_rgba(
|
@@ -379,7 +379,7 @@ void thumbhash_to_rgba(
|
|
379
379
|
|
380
380
|
double r, g, b, a;
|
381
381
|
|
382
|
-
if (fill_mode ==
|
382
|
+
if (fill_mode == CLAMP) {
|
383
383
|
if (x < 0)
|
384
384
|
{
|
385
385
|
x = 0;
|
@@ -398,7 +398,9 @@ void thumbhash_to_rgba(
|
|
398
398
|
}
|
399
399
|
}
|
400
400
|
|
401
|
-
|
401
|
+
bool inside_image = x >= 0 && x <= 1.0 && y >= 0 && y <= 1.0;
|
402
|
+
|
403
|
+
if (inside_image) {
|
402
404
|
double l = l_dc, p = p_dc, q = q_dc;
|
403
405
|
a = a_dc;
|
404
406
|
|
@@ -453,9 +455,9 @@ void thumbhash_to_rgba(
|
|
453
455
|
r = (3.0 * l - b + q) / 2.0;
|
454
456
|
g = r - q;
|
455
457
|
} else {
|
456
|
-
r =
|
457
|
-
g =
|
458
|
-
b =
|
458
|
+
r = 255;
|
459
|
+
g = 255;
|
460
|
+
b = 255;
|
459
461
|
a = 0;
|
460
462
|
}
|
461
463
|
|
@@ -466,14 +468,17 @@ void thumbhash_to_rgba(
|
|
466
468
|
fmax(0, 255 * fmin(1, a))
|
467
469
|
};
|
468
470
|
|
469
|
-
if (
|
470
|
-
|
471
|
-
double
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
rgba[i
|
471
|
+
if (fill_color && fill_color[3] > 0) {
|
472
|
+
double top_a = (double) top[3] / 255.0;
|
473
|
+
double fill_color_a = (double) fill_color[3] / 255.0;
|
474
|
+
double inverse_top_a = 1.0 - top_a;
|
475
|
+
double sum_a = top_a + fill_color_a * inverse_top_a;
|
476
|
+
|
477
|
+
// Alpha compositing (top over fill_color)
|
478
|
+
rgba[i] = roundf(((double) top[0] * top_a + (double) fill_color[0] * fill_color_a * inverse_top_a) / sum_a);
|
479
|
+
rgba[i+1] = roundf(((double) top[1] * top_a + (double) fill_color[1] * fill_color_a * inverse_top_a) / sum_a);
|
480
|
+
rgba[i+2] = roundf(((double) top[2] * top_a + (double) fill_color[2] * fill_color_a * inverse_top_a) / sum_a);
|
481
|
+
rgba[i+3] = roundf(sum_a * 255.0);
|
477
482
|
} else {
|
478
483
|
rgba[i] = top[0];
|
479
484
|
rgba[i+1] = top[1];
|
data/lib/fast_thumbhash.rb
CHANGED
@@ -8,8 +8,8 @@ module FastThumbhash
|
|
8
8
|
thumbhash,
|
9
9
|
max_size: nil,
|
10
10
|
size: nil,
|
11
|
-
fill_mode: :
|
12
|
-
fill_color:
|
11
|
+
fill_mode: :solid,
|
12
|
+
fill_color: [255, 255, 255, 0],
|
13
13
|
homogeneous_transform: nil,
|
14
14
|
saturation: 0
|
15
15
|
)
|
@@ -28,22 +28,19 @@ module FastThumbhash
|
|
28
28
|
binary_thumbhash,
|
29
29
|
max_size: nil,
|
30
30
|
size: nil,
|
31
|
-
fill_mode: :
|
32
|
-
fill_color:
|
31
|
+
fill_mode: :solid,
|
32
|
+
fill_color: [255, 255, 255, 0],
|
33
33
|
homogeneous_transform: nil,
|
34
34
|
saturation: 0
|
35
35
|
)
|
36
36
|
!max_size.nil? ^ !size.nil? or
|
37
37
|
raise ArgumentError, "Pass either the `max_size` option, or an explicit `size`"
|
38
38
|
|
39
|
-
%i[solid blur
|
39
|
+
%i[solid blur clamp].include?(fill_mode) or
|
40
40
|
raise ArgumentError, "Invalid `fill_mode` option"
|
41
41
|
|
42
42
|
fill_color_pointer =
|
43
|
-
if
|
44
|
-
fill_color or
|
45
|
-
raise ArgumentError, "`fill_color` is required if fill_mode = :solid"
|
46
|
-
|
43
|
+
if fill_color
|
47
44
|
fill_color.length == 4 or
|
48
45
|
raise ArgumentError, "You need to pass [r, g, b, a] to the `fill_color` option"
|
49
46
|
|
@@ -52,6 +49,8 @@ module FastThumbhash
|
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
52
|
+
raise ArgumentError, "Option `fill_color` is required for :solid fill_mode" if fill_mode == :solid && fill_color.nil?
|
53
|
+
|
55
54
|
transform_pointer =
|
56
55
|
if homogeneous_transform
|
57
56
|
(homogeneous_transform.size == 3 && homogeneous_transform.all? { |row| row.size == 3 }) or
|
@@ -143,9 +142,9 @@ module FastThumbhash
|
|
143
142
|
ffi_lib File.join(File.expand_path(__dir__), "fast_thumbhash.#{RbConfig::CONFIG["DLEXT"]}")
|
144
143
|
|
145
144
|
enum :fill_mode, [
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
145
|
+
:solid, 0,
|
146
|
+
:blur,
|
147
|
+
:clamp
|
149
148
|
]
|
150
149
|
|
151
150
|
attach_function :thumb_size, %i[pointer uint8 pointer], :size_t
|