Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/img_display: support raw img preview in kitty #2931

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ranger/ext/img_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,25 @@ def draw(self, path, start_x, start_y, width, height):
if self.needs_late_init:
self._late_init()

dummy, ext = os.path.splitext(path)
if ext == ".ORF":
thumb_ext = ''
try:
import rawpy
except ImportError:
raise ImageDisplayError("Raw image previews in kitty require rawpy")

# convert raw file to tmp thumbnail
with rawpy.imread(path) as raw:
thumb = raw.extract_thumb()
if thumb.format == rawpy.ThumbFormat.JPEG:
thumb_ext = '.jpg'
elif thumb.format == rawpy.ThumbFormat.BITMAP:
thumb_ext = '.tiff'
with NamedTemporaryFile(mode='w+b', prefix='ranger_thumb_', suffix=thumb_ext, delete=False) as tmpf:
tmpf.write(thumb.data)
path = tmpf.name

with warnings.catch_warnings(record=True): # as warn:
warnings.simplefilter('ignore', self.backend.DecompressionBombWarning)
image = self.backend.open(path)
Expand Down
Loading