implement 'smart' pixelation in chat

Signed-off-by: Shea <[email protected]>
This commit is contained in:
Shea committed 2026-06-05 07:33:53 +03:00
1 parent c119bc261d
commit 9b33efcbfa
6 files changed
+16 -9

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
default: patch
---
Change image rendering to allow enabling anti-aliasing in the image viewer
+2 -2
View File
@@ -359,11 +359,11 @@ function RenderMessageContentInternal({
if (isGif && !autoplayGifs && p.src) {
return (
<ClientSideHoverFreeze src={p.src}>
<Image {...p} loading="lazy" />
<Image info={info} {...p} loading="lazy" />
</ClientSideHoverFreeze>
);
}
return <Image {...p} loading="lazy" />;
return <Image info={info} {...p} loading="lazy" />;
}}
renderViewer={(p) => <ImageViewer {...p} />}
/>
@@ -28,8 +28,6 @@ export const ImageViewer = as<'div', ImageViewerProps>(
const [isPixelated, setIsPixelated] = useState(
isPixelatedRendering(pixelatedImageRendering, info)
);
// oxlint-disable-next-line no-console
console.log(info);
const {
transforms,
@@ -98,7 +96,7 @@ export const ImageViewer = as<'div', ImageViewerProps>(
radii="Pill"
onClick={() => setIsPixelated(!isPixelated)}
aria-label="Toggle Pixelation"
title={`Turn ${isPixelated ? 'Antialiasing' : 'Pixelation'} on`}
title={`Turn ${isPixelated ? 'Anti-aliasing' : 'Pixelation'} on`}
>
<CheckerboardIcon size={20} weight={isPixelated ? 'duotone' : 'fill'} />
</IconButton>
+6 -3
View File
@@ -4,16 +4,19 @@ import classNames from 'classnames';
import { useSetting } from '$state/hooks/settings';
import { isPixelatedRendering, settingsAtom } from '$state/settings';
import * as css from './media.css';
import type { IImageInfo } from '$types/matrix/common';
export const Image = forwardRef<HTMLImageElement, ImgHTMLAttributes<HTMLImageElement>>(
({ className, alt, ...props }, ref) => {
type ImageProps = ImgHTMLAttributes<HTMLImageElement> & { info?: IImageInfo };
export const Image = forwardRef<HTMLImageElement, ImageProps>(
({ className, alt, info, ...props }, ref) => {
const [pixelatedImageRendering] = useSetting(settingsAtom, 'pixelatedImageRendering');
return (
<img
className={classNames(
css.Image,
isPixelatedRendering(pixelatedImageRendering) && css.ImagePixelated,
isPixelatedRendering(pixelatedImageRendering, info) && css.ImagePixelated,
className
)}
alt={alt}
@@ -305,6 +305,7 @@ export const UrlPreviewCard = as<
renderViewer={(p) => <ImageViewer {...p} />}
renderImage={(p) => (
<Image
info={ogImageInfo}
{...p}
style={{
display: 'block',
+1 -1
View File
@@ -63,7 +63,7 @@ export function isPixelatedRendering(
mode: PixelatedImageRenderingMode,
info?: IImageInfo
): boolean {
if (mode === 'smart') return !info || !info.w || !info.h || info.w < 192 || info.h < 192;
if (mode === 'smart') return !!info && !!info.w && !!info.h && (info.w < 192 || info.h < 192);
return mode === 'always';
}