Skip to content

Commit

Permalink
Remove web codecs usage
Browse files Browse the repository at this point in the history
It was decoding transparency incorrectly (multiplication wrong?), and I'd rather not have a different code path there for the sake of it
  • Loading branch information
jakearchibald committed Dec 15, 2022
1 parent 97d13de commit 4259427
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/client/lazy-app/Compress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function decodeImage(
}
}
// Otherwise fall through and try built-in decoding for a laugh.
return await builtinDecode(signal, blob, mimeType);
return await builtinDecode(signal, blob);
} catch (err) {
if (err instanceof Error && err.name === 'AbortError') throw err;
console.log(err);
Expand Down
28 changes: 5 additions & 23 deletions src/client/lazy-app/util/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,17 @@ interface DrawableToImageDataOptions {
sh?: number;
}

function getWidth(
drawable: ImageBitmap | HTMLImageElement | VideoFrame,
): number {
if ('displayWidth' in drawable) {
return drawable.displayWidth;
}
return drawable.width;
}

function getHeight(
drawable: ImageBitmap | HTMLImageElement | VideoFrame,
): number {
if ('displayHeight' in drawable) {
return drawable.displayHeight;
}
return drawable.height;
}

export function drawableToImageData(
drawable: ImageBitmap | HTMLImageElement | VideoFrame,
drawable: ImageBitmap | HTMLImageElement,
opts: DrawableToImageDataOptions = {},
): ImageData {
const {
width = getWidth(drawable),
height = getHeight(drawable),
width = drawable.width,
height = drawable.height,
sx = 0,
sy = 0,
sw = getWidth(drawable),
sh = getHeight(drawable),
sw = drawable.width,
sh = drawable.height,
} = opts;

// Make canvas same size as image
Expand Down
10 changes: 0 additions & 10 deletions src/client/lazy-app/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as WebCodecs from '../util/web-codecs';
import { drawableToImageData } from './canvas';

/** If render engine is Safari */
Expand Down Expand Up @@ -139,15 +137,7 @@ export async function blobToImg(blob: Blob): Promise<HTMLImageElement> {
export async function builtinDecode(
signal: AbortSignal,
blob: Blob,
mimeType: string,
): Promise<ImageData> {
// If WebCodecs are supported, use that.
if (await WebCodecs.isTypeSupported(mimeType)) {
assertSignal(signal);
try {
return await abortable(signal, WebCodecs.decode(blob, mimeType));
} catch (e) {}
}
assertSignal(signal);

// Prefer createImageBitmap as it's the off-thread option for Firefox.
Expand Down
33 changes: 0 additions & 33 deletions src/client/lazy-app/util/web-codecs/index.ts

This file was deleted.

60 changes: 0 additions & 60 deletions src/client/lazy-app/util/web-codecs/missing-types.d.ts

This file was deleted.

0 comments on commit 4259427

Please sign in to comment.