Skip to content

Commit f40ec28

Browse files
matmenclaude
andcommitted
credit Pillow's resampling coefficients and filters, the box blur formula
src/util/resample.ts computes its coefficients as Pillow's precompute_coeffs and uses its box, bilinear and bicubic filters: the header and THIRD_PARTY_NOTICES.md now carry Pillow's copyright and MIT-CMU license. The box sizes of the blur follow Peter Kovesi's formula, as in Ivan Kuckir's boxesForGauss. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJgRK5qpwJEbHPuFv6kgAQ
1 parent f57120d commit f40ec28

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎THIRD_PARTY_NOTICES.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ following projects, under their own licenses. Each derived file says so in its h
1414
| [RFC 6386](https://www.rfc-editor.org/rfc/rfc6386) (VP8 Data Format and Decoding Guide, with the libvpx reference decoder) | `src/codecs/vp8-tables.ts` (probability and quantizer tables), `src/codecs/vp8.ts` (decoding procedures) | BSD-3-Clause |
1515
| [libwebp](https://chromium.googlesource.com/webm/libwebp) | `src/codecs/vp8.ts` (YUV to RGB conversion, "fancy" chroma upsampling), `src/codecs/webp.ts` (animation frame blending) | BSD-3-Clause |
1616
| [FreeType](https://freetype.org) | `src/render/hinting.ts` (behavior and parts of the logic of the TrueType interpreter) | FreeType License |
17+
| [Pillow](https://github.com/python-pillow/Pillow) | `src/util/resample.ts` (filter coefficients, box, bilinear and bicubic filters) | MIT-CMU |
1718

1819
## fflate, Fast CRC32 in JavaScript
1920

@@ -154,3 +155,43 @@ Where the specification leaves details open, its behavior and parts of its logic
154155
interpolation of untouched points (IUP), the handling of near-perpendicular freedom and projection vectors, and the
155156
tolerance of invalid references. FreeType is used under the FreeType License, included as
156157
[licenses/FTL.txt](licenses/FTL.txt).
158+
159+
## Pillow
160+
161+
```
162+
The Python Imaging Library (PIL) is
163+
164+
Copyright © 1997-2011 by Secret Labs AB
165+
Copyright © 1995-2011 by Fredrik Lundh and contributors
166+
167+
Pillow is the friendly PIL fork. It is
168+
169+
Copyright © 2010 by Jeffrey 'Alex' Clark and contributors
170+
171+
Like PIL, Pillow is licensed under the open source MIT-CMU License:
172+
173+
By obtaining, using, and/or copying this software and/or its associated
174+
documentation, you agree that you have read, understood, and will comply
175+
with the following terms and conditions:
176+
177+
Permission to use, copy, modify and distribute this software and its
178+
documentation for any purpose and without fee is hereby granted,
179+
provided that the above copyright notice appears in all copies, and that
180+
both that copyright notice and this permission notice appear in supporting
181+
documentation, and that the name of Secret Labs AB or the author not be
182+
used in advertising or publicity pertaining to distribution of the software
183+
without specific, written prior permission.
184+
185+
SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
186+
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
187+
IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL,
188+
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
189+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
190+
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
191+
PERFORMANCE OF THIS SOFTWARE.
192+
```
193+
194+
The resampling in `src/util/resample.ts` computes its filter coefficients as Pillow's `precompute_coeffs` does (the
195+
filter stretched by the downscaling factor, the source range rounded around each output pixel's center, the weights
196+
normalized) and uses Pillow's box, bilinear and bicubic (a = -0.5) filter functions. The integer passes, the fast
197+
paths and the premultiplied alpha handling are ImageScript's own.

‎src/util/blur.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import { littleEndian, isOpaque, premultiply8, unpremultiply8 } from './alpha.ts';
55

6-
// widths of the three boxes for a gaussian with the given standard deviation
6+
// widths of the three boxes for a gaussian with the given standard deviation: the formula of Peter Kovesi's "Fast
7+
// Almost-Gaussian Filtering" (2010), as in Ivan Kuckir's "Fastest Gaussian Blur" (boxesForGauss)
78
function boxSizes(sigma: number): number[] {
89
const n = 3;
910
let lower = Math.floor(Math.sqrt(12 * sigma * sigma / n + 1));

‎src/util/resample.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*!
2+
* The filter coefficients and the box, bilinear and bicubic filters are translated from Pillow's
3+
* src/libImaging/Resample.c (precompute_coeffs, box_filter, bilinear_filter, bicubic_filter). Copyright © 1997-2011 by
4+
* Secret Labs AB, © 1995-2011 by Fredrik Lundh and contributors, © 2010 by Jeffrey 'Alex' Clark and contributors,
5+
* MIT-CMU License (see THIRD_PARTY_NOTICES.md)
6+
*/
7+
18
// separable convolution resampling (the approach of Pillow's resample.c): the filter is stretched by the
29
// downscaling factor, so shrinking averages every source pixel instead of skipping most of them.
310
// The arithmetic is integer (weights are fixed point numbers), and the vertical pass runs first: its weights are the

0 commit comments

Comments
 (0)