rsnext/test
Artur Bień 7160af3dba
fix(next/image): washed out blur placeholder (#52583)
Fixes #52548

This PR fixes the issue of the `<Image />` "blur" placeholder where the
placeholder image appears "washed out" and feathered around the edges.

The fix does NOT involve any API changes - only the underlying SVG
filter is updated.
The filter works for any image type (JPEG, GIF, WEBP) no matter if it
contains transparency or not.

## How it works

```html
  <filter id='b' color-interpolation-filters='sRGB'>
    <feMorphology in='SourceAlpha' operator='dilate' radius='15' result='dilate' />
    <feGaussianBlur in='dilate' stdDeviation='15' result='mask' />
    <feGaussianBlur in='SourceGraphic' stdDeviation='20' result='blur' />
    <feComponentTransfer in='blur' result='solid'>
      <feFuncA type='table' tableValues='1 1' />
    </feComponentTransfer>
    <feComposite in2='mask' in='solid' operator='in' result="comp" />
    <feMerge>
      <feMergeNode in="SourceGraphic" />
      <feMergeNode in="comp" />
    </feMerge>
  </filter>
  ```
Currently the underlying filter uses `feComponentTransfer ` to get rid of the feathered edges but only for JPEG images. This is because if alpha channel was to be mapped to 1 for images with transparency in it, all of the transparent pixels would turn black (which is obviously undesirable).

The way I fixed it is by creating a mask from the SourceAlpha (effectively the "shape" of the object in an image), slightly blurring it for a smoother look (feMorphology + feGaussianBlur), and then clipping the `feComponentTransfer` result to the shape of the mask (`<feComposite in2='mask' in='solid' operator='in' result="comp" />`). 

Then finally `feMerge` is used to stack original image and the clipping result from the previous step just to make sure that any left over artifacts from clipping are hidden.

## Result

Here's a comparison between the current implementation (left column), and the filter above (right column)

<img width="614" alt="Screenshot 2023-07-12 at 10 44 56" src="https://github.com/vercel/next.js/assets/28541613/afdc1f88-eb1a-4a21-a88a-06057a875e1b">

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-07-25 21:45:24 -04:00
..
.stats-app chore: remove experimental appDir: true from tests (#52291) 2023-07-05 19:17:29 -07:00
__mocks__ [edge] bump @edge-runtime/* package suite (#49092) 2023-05-31 08:03:20 +00:00
development chore(test): fix flaky tsconfig.json test (#53132) 2023-07-24 14:33:55 -07:00
e2e Temporarily skip flakey action revalidate (#53134) 2023-07-24 15:37:30 -07:00
examples feat(cli): introduce --tailwind flag (#46927) 2023-03-16 16:06:27 +01:00
integration fix(next/image): washed out blur placeholder (#52583) 2023-07-25 21:45:24 -04:00
lib Fix not found hangs the build with overridden node env (#53106) 2023-07-24 21:00:53 +00:00
production Revert "Revert "Separate routing code from render servers (#52492)"" (#53029) 2023-07-21 14:02:52 -07:00
unit fix(edge): allow Request cloning via NextRequest (#53157) 2023-07-25 11:36:39 +00:00
.gitignore ci(workflow): enable test trace upload (#51107) 2023-06-12 17:14:13 +00:00
jest-setup-after-env.ts type check tests (and convert next-test-utils.js to ts) (#51071) 2023-06-23 17:42:50 +00:00
jest.d.ts type check tests (and convert next-test-utils.js to ts) (#51071) 2023-06-23 17:42:50 +00:00
readme.md
test-file.txt

See Testing for more information on how you can run/write/debug tests for Next.js.