Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a0432b5

Browse files
authored
Merge pull request #6329 from matrix-org/t3chguy/blurhash-components
2 parents bda83e8 + d8bf618 commit a0432b5

File tree

5 files changed

+12
-63
lines changed

5 files changed

+12
-63
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
},
5555
"dependencies": {
5656
"@babel/runtime": "^7.12.5",
57-
"@types/commonmark": "^0.27.4",
5857
"await-lock": "^2.1.0",
5958
"blurhash": "^1.1.3",
6059
"browser-encrypt-attachment": "^0.3.0",
@@ -92,6 +91,7 @@
9291
"re-resizable": "^6.9.0",
9392
"react": "^17.0.2",
9493
"react-beautiful-dnd": "^13.1.0",
94+
"react-blurhash": "^0.1.3",
9595
"react-dom": "^17.0.2",
9696
"react-focus-lock": "^2.5.0",
9797
"react-transition-group": "^4.4.1",
@@ -124,6 +124,7 @@
124124
"@peculiar/webcrypto": "^1.1.4",
125125
"@sinonjs/fake-timers": "^7.0.2",
126126
"@types/classnames": "^2.2.11",
127+
"@types/commonmark": "^0.27.4",
127128
"@types/counterpart": "^0.18.1",
128129
"@types/diff-match-patch": "^1.0.32",
129130
"@types/flux": "^3.1.9",

src/ContentMessages.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ const MAX_HEIGHT = 600;
4949
const PHYS_HIDPI = [0x00, 0x00, 0x16, 0x25, 0x00, 0x00, 0x16, 0x25, 0x01];
5050

5151
export const BLURHASH_FIELD = "xyz.amorgan.blurhash"; // MSC2448
52-
const BLURHASH_X_COMPONENTS = 6;
53-
const BLURHASH_Y_COMPONENTS = 6;
5452

5553
export class UploadCanceledError extends Error {}
5654

@@ -137,8 +135,9 @@ function createThumbnail(
137135
imageData.data,
138136
imageData.width,
139137
imageData.height,
140-
BLURHASH_X_COMPONENTS,
141-
BLURHASH_Y_COMPONENTS,
138+
// use 4 components on the longer dimension, if square then both
139+
imageData.width >= imageData.height ? 4 : 3,
140+
imageData.height >= imageData.width ? 4 : 3,
142141
);
143142
canvas.toBlob(function(thumbnail) {
144143
resolve({

src/components/views/elements/BlurhashPlaceholder.tsx

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/components/views/messages/MImageBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818

1919
import React, { createRef } from 'react';
2020
import PropTypes from 'prop-types';
21+
import { Blurhash } from "react-blurhash";
2122

2223
import MFileBody from './MFileBody';
2324
import Modal from '../../../Modal';
@@ -29,7 +30,6 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
2930
import InlineSpinner from '../elements/InlineSpinner';
3031
import { replaceableComponent } from "../../../utils/replaceableComponent";
3132
import { mediaFromContent } from "../../../customisations/Media";
32-
import BlurhashPlaceholder from "../elements/BlurhashPlaceholder";
3333
import { BLURHASH_FIELD } from "../../../ContentMessages";
3434

3535
@replaceableComponent("views.messages.MImageBody")
@@ -436,7 +436,7 @@ export default class MImageBody extends React.Component {
436436
// Overidden by MStickerBody
437437
getPlaceholder(width, height) {
438438
const blurhash = this.props.mxEvent.getContent().info[BLURHASH_FIELD];
439-
if (blurhash) return <BlurhashPlaceholder blurhash={blurhash} width={width} height={height} />;
439+
if (blurhash) return <Blurhash hash={blurhash} width={width} height={height} />;
440440
return <div className="mx_MImageBody_thumbnail_spinner">
441441
<InlineSpinner w={32} h={32} />
442442
</div>;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6454,6 +6454,11 @@ react-beautiful-dnd@^13.1.0:
64546454
redux "^4.0.4"
64556455
use-memo-one "^1.1.1"
64566456

6457+
react-blurhash@^0.1.3:
6458+
version "0.1.3"
6459+
resolved "https://registry.yarnpkg.com/react-blurhash/-/react-blurhash-0.1.3.tgz#735f28f8f07fb358d7efe7e7e6dc65a7272bf89e"
6460+
integrity sha512-Q9lqbXg92NU6/2DoIl/cBM8YWL+Z4X66OiG4aT9ozOgjBwx104LHFCH5stf6aF+s0Q9Wf310Ul+dG+VXJltmPg==
6461+
64576462
react-clientside-effect@^1.2.2:
64586463
version "1.2.3"
64596464
resolved "https://registry.yarnpkg.com/react-clientside-effect/-/react-clientside-effect-1.2.3.tgz#95c95f520addfb71743608b990bfe01eb002012b"

0 commit comments

Comments
 (0)