Ticket #2977 (new enhancement)

Opened 12 years ago

Last modified 10 years ago

Show images with img2txt helper (libcaca utility)

Reported by: szaszg Owned by:
Priority: major Milestone: Future Releases
Component: mcview Version: master
Keywords: Cc: gotar@…, egmont@…, mooffie@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

IMHO will be nice if mc can show images in quick view mode.
It will be done if we convert images to ANSI color text files (with libcaca img2txt utility), and mcview can show ANSI colored text files. (and we fix mcview magic mode bug, see Ticket#2976)

We can use sfs (1) and image.sh (2) to convert images to ANSI colored text.
We can use nroff highliting mode (3) to show images.
We should fix mcview magic mode bug (4).
We should add a new hotkey to switch "Format"/"Unformat", because in quick view mode F9 do menu PullDn (5)

So i attach a patch:

util.{h,c}:

-a new compression type COMPRESS_IMG to handle sfs type image conversion (related to 1)
-detect GIF, PNG, JPEG magic in get_compression_type() function (rel. 1)
-new decompress extension /img in decompress_extension() function (rel. 1)

sfs.ini:

-new img "decomress helper" img2txt (rel .1)

image.sh:

-detect img2txt utility and use it for JPEG and other (*) images (rel .2)
-print exif data (if any) after image to keep imege at top

internal.h:

-text wrap can broke images, so we defined a test (WRAP_MODE_DISABLED() and TEXT_WRAP_MODE()) to avoid text wrap when show ANSI colored text (rel. 3)
-new enum (nroff_high_type) to select different highliting modes (e.g. ANSI :)
-new member in view struct (nroff_high_type) to cache the result of highlite rule detection

lib.c:

-initialize nroff_high_type for views in mcview_toggle_magic_mode() function (rel. 3)


display.c:

-use mcview_display_ansi() if mcview in nroff_mode and file is ANSI colored (view->nroff_high_type) (rel. 3)

mcviewer.c:

-initialize nroff_high_type for new views in mcview_new() function (rel. 3)
-fix mcview magic_mode bug in mcview_load() function (as in Ticket#2976) (rel. 4)

move.c:

-"if (view->text_wrap_mode)" and similars changed to "if (TEXT_WRAP_MODE(view))" to avoid text wrap when show images (see note 1) (rel. 3)

nroff.c:

-check nroff_high_type (if not checked yet) and do ANSI colored display if needed (this is the optimal place to check) check result saved and later (if user play F9) display.c call directly the ANSI function...

Makefile.am:

-add ansi.c (rel. 3)

ansi.c:

-new function get_nroff_high_type() detect ANSI color escape sequences in the first 256 byte if file size less than 1M (avoid playing big files) (rel. 3)
-new function mcview_display_ansi() to display ANSI colored text files (see note 2) (rel. 3)


After make install i add ctrl-t to NroffMode in mc.keymap, so now i can switch "Format"/"Unformat" mode on quick view panel. (rel. 5)
==================================

So...

  1. start up mc
  2. switch quick view ctrl-x ctrl-q
  3. browse an image (jpeg, gif, png)
  4. switch to quick view (TAB)
  5. press ctrl-t (should be set as i mentioned before)
  6. 8-o
  7. switch back to file list (TAB)
  8. just browse your photos ;-)

If you open an image in viewer F3, you can see the identify line the image and exif tags (jpeg only)

Notes:

  1. all other "if (view->text_wrap_mode)" and similars changed to "if (TEXT_WRAP_MODE(view))" in files
  1. mcviewer_display_ansi() is similar to mciewer_display_text() but: -detects ANSI color sequences ^[#;#;#m when # is 0,1,5 or 30-37, or 40-47 -it uses a 128 byte length puffer, so color sequences larger than 128 byte not detected (there is no any reason to somebody use as long sequences) -if escape seq. not an ANSI color (e.g. cursor movement, etc...), or too large then displayed as in mciewer_display_text(). -it can use as many color pairs as the underlaying terminal(emulator) allow (usually 256), but mc allocate some color pair before. So in same cases (e.g. mc use "underlined" colors, and text file has 256 different color pair) this number may not enough and mcview show some "default" colored caracter instead of the "real" color. -it use a special escape sequence (^[9999m), to detect the end-of-image and switch back to normal colors. (image.sh use this thing to show up exif data in normal colors)

Attachments

mc.qview1.diff (20.6 KB) - added by szaszg 12 years ago.
this patch fixup ticket#2976 too'
mc.qview2.diff (19.4 KB) - added by szaszg 12 years ago.
only this changes (there is no part included for fixup #2976)
durer_rabbit.png (51.3 KB) - added by szaszg 12 years ago.
viewing Dürer's rabbit in mcviewer
mc_logo.png (58.7 KB) - added by szaszg 12 years ago.
viewing MC's logo in a quick view panel

Change History

Changed 12 years ago by szaszg

this patch fixup ticket#2976 too'

Changed 12 years ago by szaszg

only this changes (there is no part included for fixup #2976)

Changed 12 years ago by szaszg

viewing Dürer's rabbit in mcviewer

Changed 12 years ago by szaszg

viewing MC's logo in a quick view panel

comment:1 Changed 12 years ago by angel_il

ANSI?! cool, must have!

comment:2 Changed 12 years ago by gotar

  • Cc gotar@… added

comment:3 follow-up: ↓ 5 Changed 10 years ago by egmont

See also #1849 (especially comment 6), #3250, #3264.

comment:4 Changed 10 years ago by egmont

  • Cc egmont@… added

comment:5 in reply to: ↑ 3 Changed 10 years ago by szaszg

Replying to egmont:

See also #1849 (especially comment 6), #3250, #3264.

Sorry boys, but i'm not longer motivated to post anything into mc...
Please have a look at #3004 especially comment 6 (3004#comment:6).

comment:6 Changed 10 years ago by mooffie

  • Cc mooffie@… added
Note: See TracTickets for help on using tickets.