Archive for December 21st, 2011

HP8591 Spectrum Analyzer Screen Dump Sizes

The script I use to fetch screen dumps from my HP8591 spectrum analyzer works fine, but it turns out that the screen images have (at least) two sizes.

The hp2xx program converts the screen dumps from HP-GL text files to PNG bitmaps:

for f in *hgl ; do hp2xx -m png -c 1436 "$f" ; done

The usual size is 593x414 pixels:

SMD 470 pF - Comm Spec

SMD 470 pF - Comm Spec

The other size is 593x395 pixels:

SMD 470 pF - Surplus

SMD 470 pF - Surplus

As nearly as I can tell, the spectrum analyzer mashes the Y coordinate when any of the soft keys along the right edge have reverse-video highlights, which print as outlined boxes. There may be other sizes; those are the two I’ve stumbled over so far. This doesn’t much matter unless I’m using the images in a column, in which case it’s awkward to have two sizes: a one-size-fits-all script to trim off the soft keys doesn’t produce the proper results.

Musing on how to figure this programmatically…

The file command gives the pixel dimensions, with the file name (which may contain blanks: so sue me) set off  with a colon:

file "SMD 470 pF - Surplus.png"
SMD 470 pF - Surplus.png: PNG image, 593 x 395, 8-bit colormap, non-interlaced

Judicious application of cut extracts the relevant numbers, albeit with a trailing comma that requires another pass through the grinder:

file "SMD 470 pF - Surplus.png" | cut -d\: -f2 | cut -d\  -f4,6
593 395,

Although I think a sed script might be better, that requires more skull sweat than I have available right now.

Given that, then an appropriate mogrify would crop off the softkey labels; the first one is what’s in the script right now:

mogrify -crop "540x414+0+0" SMD\ 470\ pF\ -\ Comm\ Spec.png
mogrify -crop "515x395+0+0" SMD\ 470\ pF\ -\ Surplus.png

Which looks like this:

SMD 470 pF - Comm Spec cropped

SMD 470 pF - Comm Spec cropped

The two sizes come out pretty close to the same 1.3 aspect ratio, but resizing the smaller one to match the larger doesn’t work well:

convert -resize '540x414+0+0!' SMD\ 470\ pF\ -\ Surplus.png SMD\ 470\ pF\ -\ Surplus\ resized.png

You need single quotes around the geometry parameter to prevent Bash (or Dash or whatever) from gnawing on the bang character (yes, that’s how you pronounce “!”).

The images are lossless PNGs because they consist entirely of single-pixel lines and characters; alas, resizing by non-integer factors close to 1.0 introduces nasty picket-fence aliasing artifacts:

Resize x 1.049

Resize x 1.049

I resize the pix by a nice, even factor of two (which also adds aliasing artifacts, but in small and very regular doses) and set the dots/inch value so the images print at about the right size without further hassle along the production pipeline:

mogrify -density 300 -resize 200% whatever.png

Which looks like this:

Resize 2.00

Resize 2.00

Resizing from the smaller images to (roughly) the final size in one step doesn’t look quite so awful:

convert -density 300 -resize 209% "SMD 470 pF - Surplus.png" "SMD 470 pF - Surplus large.png"

Like this, still with a distinctly garbled dBm:

Resize 2.09

Resize 2.09

But it’s decidedly better than this result from a two-step enlargement, although not as wonderful as one might like:

Resize x 1.049 x 2.00

Resize x 1.049 x 2.00

So the script needs a tweak for the file sizes, but …

Memo to Self: It’d be simpler to not have highlighted softkeys when doing screen dumps!

7 Comments