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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/ext/oil/resample.c +29 -29
  4. data/lib/oil.rb +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b39dd91704802e2731a0f67da4743ae67c0535ed
4
- data.tar.gz: 9f7767d654f542c11a9fec84f3dc4c097004755c
3
+ metadata.gz: e7ab475c778d9843d41134e7ad33cb989be6364e
4
+ data.tar.gz: 91ac3a1eef0a7869e6282116b6de9fea04bb7b89
5
5
  SHA512:
6
- metadata.gz: 2a862073a15ee977727398689263311dd9868c6c66d518cc840a1e5c7a81f638246b62b1d5d32a4dc2a28d8205a36f4327463a025b4dcb67f491711c19f5d2d5
7
- data.tar.gz: 14da2b6aea208767826869a19c6fe8ba4824f15fba435ca1e8862adfe8d19603ce3e7e5a48e66cd693a3afa65c9ee923f6834ac49515c7a6751cd8f23b4e12dd
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.2') do |s|
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.'
@@ -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
- static long calc_tap_mult(long dim_in, long dim_out)
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 1;
116
+ return TAPS;
111
117
  }
112
- return dim_in / dim_out;
113
- }
114
118
 
115
- /**
116
- * Given input and output dimension, calculate the total number of taps that
117
- * will be needed to calculate an output sample.
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 tap_mult)
174
+ static void calc_coeffs(fix1_30 *coeffs, float tx, long taps)
174
175
  {
175
- long i, taps, total;
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
- taps = tap_mult * TAPS;
182
+ tap_mult = (double)taps / TAPS;
182
183
  tx = 1 - tx - taps / 2;
183
184
 
184
- for (i=0; i<taps-1; i++) {
185
- tmp = catrom(fabs(tx) / tap_mult) / tap_mult;
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 += tmp_fixed;
189
+ total += tmp;
189
190
  tx += 1;
190
191
  }
191
192
 
192
- coeffs[taps-1] = ONE_FIX1_30 - total;
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, tap_mult);
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, tap_mult;
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
- tap_mult = calc_tap_mult(in_width, out_width);
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, tap_mult);
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
@@ -1,5 +1,5 @@
1
1
  module Oil
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
 
4
4
  def self.sniff_signature(io)
5
5
  a = io.getc
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.2
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-25 00:00:00.000000000 Z
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.4
57
+ rubygems_version: 2.4.5
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: Resize JPEG and PNG images.