Skip to content

Commit

Permalink
Apply pixelated upscale to gallery and slide
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanDrake committed Nov 29, 2022
1 parent 184faa5 commit 9c1a94a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/frontend/containers/ContentView/GalleryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,16 @@ export const Thumbnail = observer(({ file, mounted, forceNoThumbnail }: ItemProp
return <span className="image-loading" />;
} else if (imageSource.tag === 'ready') {
if ('ok' in imageSource.value) {
const is_lowres = file.width < 320 || file.height < 320;
return (
<img
src={encodeFilePath(imageSource.value.ok)}
alt=""
data-file-id={file.id}
onError={handleImageError}
style={
is_lowres && uiStore.upscaleMode == 'pixelated' ? { imageRendering: 'pixelated' } : {}
}
/>
);
} else {
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/containers/ContentView/SlideMode/ZoomPan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
tryPreventDefault,
Vec2,
} from './utils';
import { UpscaleMode } from '../../../stores/UiStore';

const OVERZOOM_TOLERANCE = 0.05;
const DOUBLE_TAP_THRESHOLD = 250;
Expand All @@ -41,6 +42,7 @@ export interface ZoomPanProps {
imageDimension: Dimension;
containerDimension: Dimension;
onClose?: () => void;
upscaleMode: UpscaleMode;

transitionStart?: Transform;
transitionEnd?: Transform;
Expand Down Expand Up @@ -292,7 +294,7 @@ export default class ZoomPan extends React.Component<ZoomPanProps, ZoomPanState>
onWheel: this.handleMouseWheel,
onDragStart: tryPreventDefault,
onContextMenu: tryPreventDefault,
style: imageStyle(this.state),
style: imageStyle(this.state, this.props.upscaleMode),
})}
</div>
);
Expand Down Expand Up @@ -481,9 +483,10 @@ export const CONTAINER_DEFAULT_STYLE = {
margin: 'auto',
};

function imageStyle({ top, left, scale }: ZoomPanState): CSSProperties {
function imageStyle({ top, left, scale }: ZoomPanState, upscaleMode: UpscaleMode): CSSProperties {
return {
transform: `translate3d(${left}px, ${top}px, 0) scale(${scale})`,
imageRendering: scale >= 2 && upscaleMode === 'pixelated' ? 'pixelated' : undefined,
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/frontend/containers/ContentView/SlideMode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const ZoomableImage: React.FC<ZoomableImageProps> = ({
transitionEnd,
onClose,
}: ZoomableImageProps) => {
const { imageLoader } = useStore();
const { imageLoader, uiStore } = useStore();
const { absolutePath, width: imgWidth, height: imgHeight } = file;
// Image src can be set asynchronously: keep track of it in a state
// Needed for image formats not natively supported by the browser (e.g. tiff): will be converted to another format
Expand Down Expand Up @@ -277,6 +277,7 @@ const ZoomableImage: React.FC<ZoomableImageProps> = ({
transitionStart={transitionStart}
transitionEnd={transitionEnd}
onClose={onClose}
upscaleMode={uiStore.upscaleMode}
>
{(props) => (
<img
Expand Down
19 changes: 10 additions & 9 deletions src/frontend/stores/UiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const enum ViewMethod {
}
export type ThumbnailSize = 'small' | 'medium' | 'large' | number;
type ThumbnailShape = 'square' | 'letterbox';
type UpscaleMode = 'smooth' | 'pixelated';
export type UpscaleMode = 'smooth' | 'pixelated';
export const PREFERENCES_STORAGE_KEY = 'preferences';

export interface IHotkeyMap {
Expand Down Expand Up @@ -101,6 +101,7 @@ type PersistentPreferenceFields =
| 'method'
| 'thumbnailSize'
| 'thumbnailShape'
| 'upscaleMode'
| 'hotkeyMap'
| 'isThumbnailTagOverlayEnabled'
| 'isThumbnailFilenameOverlayEnabled'
Expand Down Expand Up @@ -218,10 +219,6 @@ class UiStore {
this.setThumbnailShape('letterbox');
}

@action.bound setUpscaleMode(mode: UpscaleMode) {
this.upscaleMode = mode;
}

@action.bound setUpscaleModeSmooth() {
this.setUpscaleMode('smooth');
}
Expand Down Expand Up @@ -293,10 +290,6 @@ class UiStore {
this.isThumbnailResolutionOverlayEnabled = !this.isThumbnailResolutionOverlayEnabled;
}

@action.bound togglePixelated() {
this.isPixelated = !this.isPixelated;
}

@action.bound toggleRememberSearchQuery() {
this.isRememberSearchEnabled = !this.isRememberSearchEnabled;
}
Expand Down Expand Up @@ -830,6 +823,9 @@ class UiStore {
if (prefs.thumbnailShape) {
this.setThumbnailShape(prefs.thumbnailShape);
}
if (prefs.upscaleMode) {
this.setUpscaleMode(prefs.upscaleMode);
}
this.isThumbnailTagOverlayEnabled = Boolean(prefs.isThumbnailTagOverlayEnabled ?? true);
this.isThumbnailFilenameOverlayEnabled = Boolean(prefs.isThumbnailFilenameOverlayEnabled ?? false); // eslint-disable-line prettier/prettier
this.isThumbnailResolutionOverlayEnabled = Boolean(prefs.isThumbnailResolutionOverlayEnabled ?? false); // eslint-disable-line prettier/prettier
Expand Down Expand Up @@ -884,6 +880,7 @@ class UiStore {
method: this.method,
thumbnailSize: this.thumbnailSize,
thumbnailShape: this.thumbnailShape,
upscaleMode: this.upscaleMode,
hotkeyMap: { ...this.hotkeyMap },
isThumbnailFilenameOverlayEnabled: this.isThumbnailFilenameOverlayEnabled,
isThumbnailTagOverlayEnabled: this.isThumbnailTagOverlayEnabled,
Expand Down Expand Up @@ -946,6 +943,10 @@ class UiStore {
@action private setThumbnailShape(shape: ThumbnailShape) {
this.thumbnailShape = shape;
}

@action private setUpscaleMode(mode: UpscaleMode) {
this.upscaleMode = mode;
}
}

export default UiStore;

0 comments on commit 9c1a94a

Please sign in to comment.