Sunday, November 8, 2009

zgv'ing Again

When I started the series of posts on console tools for PDF files, I had another computer, and it handled graphics from the console differently. The chipset on the old computer was directly supported by SVGAlib and everything was working fine as far as I was concerned. When I upgraded to the current computer I found many of the graphics programs I was using needed to be shifted over to using frame buffer drivers or versions, as the video chipset on this PC seemed to be marginally (or in some instances brittly) supported in Linux. In some instances this was a gain, one example being w3m, which I can if so choosing run as a graphical web browser. In a couple of instances, zgv and svncviewer, I had to do without a console program and use an X program.

zgv is one of the more amazing graphic applications that run from the raw console in Linux. Perhaps even more amazing than watching videos in a naked command line interface. It is an image viewer that can be used on single images, slide shows, or a directory of image files, handling most of the formats we are familiar with. It has some simple image processing capabilities, and when navigating a directory of images, can generate thumbnails of all the images and can present a graphical navigation interface with these thumbnails. The alternate viewer 'fbi' (Frame Buffer Imageviewer) if fine, but to date simply lacks some of the many capabilities of zgv. I first encountered zgv as a default image viewer for text browsers such as Lynx and w3m.

It's been over a year since I got the new computer, and the other morning, I decided to try to see if there was some way to revive use of zgv. It never failed to run, but in maybe half the images colors were distorted beyond reasonable use - something like solarization of color phototgraphic film - great if you want an LSD/Timothy Leary effect but not for daily use.

In the SVGAlib configuration file, I'd hardcoded use of the framebuffer driver (as opposed to SVGAlib choosing one of the supported chipsets) by uncommenting the line:


chipset FBDEV           # Use kernel fbdev, instead of direct hardware.

in the file /etc/vga/libvga.config. With this, applications that use SVGAlib will now indirectly use the video framebuffer. I rummaged around a bit through the zgv man pages, trying various things. One clue I searched on to see if there was something that might get it working consistently was the word 'force'. My notion was that perhaps something was being misinterpreted by the program and it 'forcing' some initial condition might solve the problem. I finally found a switch '--force-viewer-8bit' (or briefly '-j') that seems to do the trick. No solarization effects. It may be that some images could be displayed with greater sharpness or color accuracy, '8bit' throwing away parts of 16/24 bits of pixel information, but everything *looks* reasonable. Nothing is reduced to psychedelic poster (or even comicbook) appearence. The worst thing I've encountered so far is that after looking at information on the image file sometimes I need to refresh the display with a CTL-L or CTL-R, but this is a minor point. To make this default behaviour, edit the file /etc/zgv.conf and add the line:

force-viewer-8bit on

A few other settings I include in the file (you can look them up in the man page) are:

zoom on
centre on
auto-mode-fit on
jpeg-speed 1
mousescale 2.0
mouse on
block-cursor on
fs-perfect-cols on
jpeg-index-style 3
fs-thick-text on

A couple that apparently must be left out of the configuration file and placed among command line switches are:

#  show-dimensions on
# reload-delay 1000000
#   - fatal in this file

A few of the more important commands of zgv:

?        -  help
ESC      -  return to previous mode (eventually exiting)
Enter    -  go to the next image
v        -  toggle file selector mode between graphical or text
/        -  help for video modes available
:        -  display file information
;        -  reset brightness/contract/etc. to default
Alt-u    -  generate/update thumbnail images
Ctrl-I   -  start a slide show of files tagged in file selector mode.
Ctrl-R   -  refresh view/directory
Ctrl-L   -  refresh view/directory
Right Mouse button  -  context sensitive menu
Left  Mouse button  -  select an image or directory in file selector/directory view mode

You can navigate the file selector or large images with cursor, vi or (what I think are) WordStar keys. I leave exploring the various zooming, rotating, mirroring, flipping, contrast, brightness, gamma, rendering and file tagging capabilities to you, the reader. The ironic reality is that using this as the viewer for a text mode web browser, the surfer has more control over image viewing than any I've encountered with so called graphical web browsers.

A few of the command line switches can be of use. The '--reload-delay 100000' mentioned above effectively sets the default slide show interval to totally at the users decision to move on, instead of the default 4-sec. '--show-dimensions' (or -s) causes zgv to print the dimensions of displayed files to standard out, perhaps to pass on to some program for image processing. '-T' causes zgv to print the names of tagged files to standard out, where they could (for instance) be passed on via a script to CUPS and printed out, or copied/moved to a holding directory. And this really is the tie-in with these article with on .pdf. After using ghostscript to convert the pages of a pdf document to images, you can browse through them with zgv in file selector mode, tag some, and have them printed out.

Friday, October 2, 2009

With bmv ...

When I first started this series of posts on command line access to pdf files I had a different computer, one that was pretty compatible with SVGALib tools. The newer computer seems to work with SVGALib with extreme unpredictability. There seems to be decision 'out there' to not bother with keeping SVGALib current, to try and shift things towards use of frame buffers, which seem to work fine on the new PC> A while back I became aware of a frame buffer based tool for viewing postscript files called bmv. To take advantage of in pdfmenu, I added some lines:
alias PDFTOPS='/usr/bin/pdftops  '  ;
alias BMV='/usr/bin/bmv -m1 -v13 '  ;
    #       the -m/-v values were tuned by tests to what seemed
    #       to work best on my computer for typical .pdf files.
..........
 10 )
    THEPSFILE="${INSIDEFILE#/tmp/}"  ;
    THEPSFILE="/tmp/${THEPSFILE%.pdf}.ps"  ;
    RM  ${THEPSFILE}  ;
    PDFTOPS  ${INSIDEFILE}   ${THEPSFILE}  ;
    BMV      ${THEPSFILE}  ;
    RM ${THEPSFILE}  ;
    ;;
  
and appropriate entries to the select menu. bmv is fairly easy to figure out how to navigate. In general, I'm satisfied with it's job of showing .pdf files.

Monday, January 19, 2009

pdfmenu

As you may have figured out by now, I created a master script for handling pdf files when in text consoles. I've put this up at http://www.lafn.org/~aw585/pdfmenu. There are probably many improvements that can be made to this but it provides a simple way to attack pdf files.

firefox -new-tab ......

I used to use one of my 26 bookmark files of Lynx to pass URLs from web browseing in Lynx to Firefox. I had that particular file bookmarked by Firefox, and could simply bookmark a url to the "F" bookmarkfile from Lynx, then when I swapped to Firefox pull up that file from Firefox's bookmarks, then seek out the particular URL in question. I thought that was pretty slick, saving a lot of scratch paper moving the URL from a text console to GUI environment, but I've since done better.

Looking over the man page for Firefox, I found there was provision for sending URL's to already running instances of 'fox. After a bit of experimentation, I found that this could be done from text consoles, and was not restricted to being issued from the GUI environment. With this information, I added these lines to my Lynx externals in /etc/lynx-cur/lynx.cfg:

EXTERNAL:http:firefox -new-tab %s --display=\:0.0 ; sudo chvt 11 :TRUE

EXTERNAL:http:firefox -new-window %s --display=\:0.0 ; sudo chvt 11 :TRUE

The '-new-tab' and '-new-window' switches are pretty self explanatory. --display tells which X display to use, which could is theory be more complex than most people use. It should be pointed out that it was necessary to escape the colons with this parameter so as not to confuse Lynx. The part starting with 'sudo ...' might be unfamiliar to some. chvt is a command to switch to other virtual consoles. Currently it seems to be limited to those setup by inittab or it's equivalent, and requires root privilages to function. I've sudo configured to run it without needing any password. Anyway, one curious thing is that it can switch you to your GUI, which in my case is console 11 - you'd need to adjust it to your situation, usually console 7.

I'm putting this article in my series on handling pdf files in text consoles because you can use this to pass the location of a file to Firefox from a console and let it handle the file however you have Firefox configured to. The fact of the matter is though that almost any thing can easily be passed from Lynx to Firefox this way not just pdf files. This has accessability implications in that someone who may out of neccessity use Lynx can with this use Firefox as a simplified interface to running various media types in the GUI environment. They could have their GUI configured to automaticly launch FireFox when it starts, and perhaps set things up so that when finished the switch back to the console and restart X rather than bother trying to navigate the GUI. This is pretty crude, but it might serve their needs. One complication might be the need to locate a start button, such as sites like YouTube have, but perhaps even this might be overcome. Anyway only the future will tell.

5) with fbgs / Investigating fbi

When I started this series of articles on handling pdf in text consoles, I had a different computer, using different tools for video content in consoles. Since then I've started using a frame buffer, and a tool for using a frame buffer to view .pdf's, fbgs came to my attention. fbgs is actually a script to glue actions by ghostscript and fbi, "Frame Buffer Imageviewer" together. fbgs accepts most of the flags for fbi, and a few of it's own. The most significant of it's own, to me, seems to be '-c', to render in color. fbi itself is a fairly straightforward tool, the most important command when using it being 'h', to toggle the help display on/off. Once you've got the help displayed, you can do most anything with it. fbi seems to be more minimalist oriented where the svgalib using zgv imageviewer is a 'kitchen sink' tool, loaded with features. zgv can be compiled with sdl, "Simple DirectMedia Layer" support instead of straight svgalib, so that it can use framebuffer images display, but I haven't done that yet, and it is another story.