oil 0.1.2 → 0.1.3
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/Rakefile +1 -1
- data/ext/oil/resample.c +29 -29
- data/lib/oil.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7ab475c778d9843d41134e7ad33cb989be6364e
|
4
|
+
data.tar.gz: 91ac3a1eef0a7869e6282116b6de9fea04bb7b89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 619ef438853c052c54f9bc3063a2837d097fac003d3f251e24599532425986042b0c970eccce61ecb268ffb891d89f5efe2d0571d3009477b14f455a94daad08
|
7
|
+
data.tar.gz: 933ed077f03c19a12d72bf8eed8eb79c0cbd0ff21905b9269fa17e49c9a859c0c606b1ee35a8f725ecd144cfddecac641857621bc7bbc05a62080d2f9310ea6c
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ Rake::ExtensionTask.new('oil') do |ext|
|
|
6
6
|
ext.lib_dir = 'lib/oil'
|
7
7
|
end
|
8
8
|
|
9
|
-
s = Gem::Specification.new('oil', '0.1.
|
9
|
+
s = Gem::Specification.new('oil', '0.1.3') do |s|
|
10
10
|
s.license = 'MIT'
|
11
11
|
s.summary = 'Resize JPEG and PNG images.'
|
12
12
|
s.description = 'Resize JPEG and PNG images, aiming for fast performance and low memory use.'
|
data/ext/oil/resample.c
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
#include <string.h>
|
6
6
|
#include <stdio.h>
|
7
7
|
|
8
|
+
/**
|
9
|
+
* Bicubic interpolation. 2 base taps on either side.
|
10
|
+
*/
|
8
11
|
#define TAPS 4
|
9
12
|
|
10
13
|
/**
|
@@ -99,26 +102,23 @@ long split_map(unsigned long dim_in, unsigned long dim_out, unsigned long pos,
|
|
99
102
|
}
|
100
103
|
|
101
104
|
/**
|
105
|
+
* Given input and output dimension, calculate the total number of taps that
|
106
|
+
* will be needed to calculate an output sample.
|
107
|
+
*
|
102
108
|
* When we reduce an image by a factor of two, we need to scale our resampling
|
103
109
|
* function by two as well in order to avoid aliasing.
|
104
|
-
*
|
105
|
-
* Calculate the resampling scalar given input and output dimensions.
|
106
110
|
*/
|
107
|
-
|
111
|
+
long calc_taps(long dim_in, long dim_out)
|
108
112
|
{
|
113
|
+
long tmp;
|
114
|
+
|
109
115
|
if (dim_out > dim_in) {
|
110
|
-
return
|
116
|
+
return TAPS;
|
111
117
|
}
|
112
|
-
return dim_in / dim_out;
|
113
|
-
}
|
114
118
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
*/
|
119
|
-
long calc_taps(long dim_in, long dim_out)
|
120
|
-
{
|
121
|
-
return calc_tap_mult(dim_in, dim_out) * TAPS;
|
119
|
+
tmp = dim_in * TAPS / dim_out;
|
120
|
+
/* Round up to the nearest even integer */
|
121
|
+
return tmp + (tmp&1);
|
122
122
|
}
|
123
123
|
|
124
124
|
/**
|
@@ -151,8 +151,9 @@ static uint32_t fix33_30_to_rgba(fix33_30 r, fix33_30 g, fix33_30 b, fix33_30 a)
|
|
151
151
|
*/
|
152
152
|
static float catrom(float x)
|
153
153
|
{
|
154
|
-
if (x<1)
|
154
|
+
if (x<1) {
|
155
155
|
return (3*x*x*x - 5*x*x + 2) / 2;
|
156
|
+
}
|
156
157
|
return (-1*x*x*x + 5*x*x - 8*x + 4) / 2;
|
157
158
|
}
|
158
159
|
|
@@ -170,26 +171,28 @@ static fix1_30 f_to_fix1_30(float x)
|
|
170
171
|
*
|
171
172
|
* The coefficients are stored as fix1_30 fixed point ints in coeffs.
|
172
173
|
*/
|
173
|
-
static void calc_coeffs(fix1_30 *coeffs, float tx, long
|
174
|
+
static void calc_coeffs(fix1_30 *coeffs, float tx, long taps)
|
174
175
|
{
|
175
|
-
long i
|
176
|
-
float tmp;
|
176
|
+
long i;
|
177
|
+
float tmp, total, tap_mult;
|
177
178
|
fix1_30 tmp_fixed;
|
178
179
|
|
179
180
|
total = 0;
|
180
181
|
|
181
|
-
|
182
|
+
tap_mult = (double)taps / TAPS;
|
182
183
|
tx = 1 - tx - taps / 2;
|
183
184
|
|
184
|
-
for (i=0; i<taps
|
185
|
-
tmp = catrom(
|
185
|
+
for (i=0; i<taps; i++) {
|
186
|
+
tmp = catrom(fabsf(tx) / tap_mult);
|
186
187
|
tmp_fixed = f_to_fix1_30(tmp);
|
187
188
|
coeffs[i] = tmp_fixed;
|
188
|
-
total +=
|
189
|
+
total += tmp;
|
189
190
|
tx += 1;
|
190
191
|
}
|
191
192
|
|
192
|
-
|
193
|
+
for (i=0; i<taps; i++) {
|
194
|
+
coeffs[i] /= total;
|
195
|
+
}
|
193
196
|
}
|
194
197
|
|
195
198
|
/**
|
@@ -264,11 +267,9 @@ void strip_scale(void **in, long strip_height, long width, void *out, float ty,
|
|
264
267
|
int cmp, int opts)
|
265
268
|
{
|
266
269
|
fix1_30 *coeffs;
|
267
|
-
long tap_mult;
|
268
270
|
|
269
|
-
tap_mult = strip_height / TAPS;
|
270
271
|
coeffs = malloc(strip_height * sizeof(fix1_30));
|
271
|
-
calc_coeffs(coeffs, ty,
|
272
|
+
calc_coeffs(coeffs, ty, strip_height);
|
272
273
|
|
273
274
|
if (cmp == 4 && (opts & OIL_FILLER)) {
|
274
275
|
yscale_rgbx(width, strip_height, coeffs, (uint32_t **)in,
|
@@ -411,12 +412,11 @@ void xscale(unsigned char *in, long in_width, unsigned char *out,
|
|
411
412
|
{
|
412
413
|
float tx;
|
413
414
|
fix1_30 *coeffs;
|
414
|
-
long i, j, xsmp_i, in_chunk, out_chunk, scale_gcd, taps
|
415
|
+
long i, j, xsmp_i, in_chunk, out_chunk, scale_gcd, taps;
|
415
416
|
unsigned char *out_pos, *rpadv, *tmp;
|
416
417
|
struct padded_sl psl;
|
417
418
|
|
418
|
-
|
419
|
-
taps = tap_mult * TAPS;
|
419
|
+
taps = calc_taps(in_width, out_width);
|
420
420
|
coeffs = malloc(taps * sizeof(fix1_30));
|
421
421
|
|
422
422
|
scale_gcd = gcd(in_width, out_width);
|
@@ -439,7 +439,7 @@ void xscale(unsigned char *in, long in_width, unsigned char *out,
|
|
439
439
|
|
440
440
|
for (i=0; i<out_chunk; i++) {
|
441
441
|
xsmp_i = split_map(in_width, out_width, i, &tx);
|
442
|
-
calc_coeffs(coeffs, tx,
|
442
|
+
calc_coeffs(coeffs, tx, taps);
|
443
443
|
|
444
444
|
xsmp_i += 1 - taps / 2;
|
445
445
|
out_pos = out + i * cmp;
|
data/lib/oil.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy Elliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Resize JPEG and PNG images, aiming for fast performance and low memory
|
14
14
|
use.
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 2.4.
|
57
|
+
rubygems_version: 2.4.5
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Resize JPEG and PNG images.
|