[OT] JPEG + graphs == hideous
[OT] JPEG + graphs == hideous
Posted Jan 9, 2008 22:11 UTC (Wed) by roelofs (guest, #2599)Parent article: What is RCU? Part 2: Usage
Please avoid using JPEG for anything but continuous-tone or photographic images. Of the common image formats, it is, by far, the worst possible choice for simple graphics like your diagrams and graphs. (Use PNG or GIF instead.) Leaving aside the visible flaws (e.g., note the splotchy green boxes with black text), you're also necessarily increasing the data size by an order of magnitude before compressing it, and I'm not aware of any compression algorithm that can make up the difference--certainly JPEG can't. In other words, not only is the quality worse, the files are bigger, too.
Btw, in case it wasn't obvious--and it's not to some people--don't convert your JPEGs to PNG or GIF to do the comparisons; the damage is already done. Save to a lossless format from the start. Virtually all Linux graphing and diagramming tools support PNG natively, and most now support GIF again, too. (Also make sure you save to "8-bit"/colormapped PNG, not 24-bit/RGB; zlib can't recover from the 3x-12x increase in size any more than JPEG can.)
Greg
Posted Jan 10, 2008 20:08 UTC (Thu)
by PaulMcKenney (✭ supporter ✭, #9624)
[Link] (5 responses)
Posted Jan 11, 2008 1:24 UTC (Fri)
by PaulMcKenney (✭ supporter ✭, #9624)
[Link] (4 responses)
Posted Jan 11, 2008 3:12 UTC (Fri)
by roelofs (guest, #2599)
[Link] (3 responses)
Anyway, I'm most familiar with gnuplot, which has both "png" and "gif" terminal types; a simple set terminal png or set terminal gif command will select one of them, and you can set the filename with set out 'foo.png', for example. Then replot or whatever you normally do.
xfig is a vector editor that uses its own .fig format by default, but it can export to all sorts of things, including PNG and GIF, if you've got the requisite helper apps installed. I think I've used it about once--and more than a decade ago at that--but according to the manual, you just bring up the export menu and select "Language" (a.k.a. output format) from the dropdown at the top. Alternatively, you can set the Fig.exportLanguage resource in your .Xdefaults file. Or you could just save to PostScript and use Ghostscript to convert to PNG or GIF, or ps2pdf and your favorite PDF viewer, or use a screen-capture utility.
I haven't used GNOME's screenshot function and don't actually have a GNOME desktop handy anymore (Slackware dropped it :-) ), but I'd bet it's based on imlib2, which has had PNG support pretty much forever. Alternatively, if you've got PBMPLUS/NetPBM installed, you can do xwd -out foo.xwd (and click on relevant window) and then xwdtopnm foo.xwd | pnmtopng > foo.png (or similar). No doubt ImageMagick/GraphicsMagick are also capable of doing such conversions. And then there's XV, which I currently sort of maintain (for loose definitions of "maintain"); it's not Free software, but it's really well written and can capture screenshots and write them out in many formats.
Greg
Posted Jan 11, 2008 5:35 UTC (Fri)
by PaulMcKenney (✭ supporter ✭, #9624)
[Link] (2 responses)
For xfig, how about this
.gif, as opposed to the six-times-bigger
.jpg?
For gnuplot, how about this
.gif,
as opposed to the nine-times-bigger
.jpg?
Now I just have to remember to cut-and-paste from the right set of scripts for next time!
Posted Jan 11, 2008 6:42 UTC (Fri)
by roelofs (guest, #2599)
[Link] (1 responses)
Indeed--and notice how the red dashed line is so much brighter now, and the black-on-green text is far sharper? JPEG hates sharp boundaries. (Gibbs' phenomenon and all.)
For gnuplot, how about this .gif, as opposed to the nine-times-bigger .jpg?
You (or gnuplot) must have used a very high quality setting for the JPEG, because that nine-times-bigger JPEG is actually grayscale (i.e., nominally one-third the raw data, or at least one-half given the usual YCbCr subsampling of the color channels in a three-component JPEG). Indeed, it's so high-quality that it has only four gray shades in it (two white, two black) and is visibly flawless even to my eye.
Just for jollies, I converted your images to PNG (gif2png -s rwlock*.gif) and then ran them through pngcrush (pngcrush -brute -e -crb.png -rem alla rwlock*.png). Here are the results:
In short, more than a factor of 15 smaller than the JPEGs, yet perfect quality. (These are the kinds of images for which PNG was designed.)
Greg
Posted Jan 15, 2008 6:13 UTC (Tue)
by PaulMcKenney (✭ supporter ✭, #9624)
[Link]
[OT] JPEG + graphs == hideous
Please accept my apologies for the excessive bandwidth and low quality! For my future
reference, if you have a recommended sequence of commands to get xfig, gnuplot, and Gnome's
screenshot capability to generate optimal images, please let me know.
[OT] JPEG + graphs == hideous
(You have to understand that I started out doing character-graphics plots on machines that
didn't even support lower-case alphabetic characters. So I cannot trust my own judgement and
aesthetics with these new-fangled bit-map plots. Even the jpegs look wonderful to me!)
No apologies necessary! Sorry if I was a little strident, but this comes up over and over again, and it seemed like the time was ripe for a public-service announcement. ;-) (And while bandwidth is far less of an issue these days than it was 15 years ago, I'm still an efficiency geek. Why use 3 KB when 1 KB would suffice?)
[OT] JPEG + graphs == hideous
Well, there certainly still are geographies where the bandwidth is quite restricted, so I cannot complain.
[OT] JPEG + graphs == hideous
For xfig, how about this .gif, as opposed to the six-times-bigger .jpg?
[OT] JPEG + graphs == hideous
44965 Jan 10 21:13 rwlockRCUupdate.jpg // 24-bit, 504 x 350 (xfig)
7266 Jan 10 21:10 rwlockRCUupdate.gif // 3-bit palette
3350 Jan 10 22:13 rwlockRCUupdate.png // 4-bit palette (gif2png)
2867 Jan 10 22:13 rwlockRCUupdate-crb.png // 4-bit palette (pngcrush)
45664 Jan 10 21:22 rwlockRCUperfwtPREEMPT.jpg // 8-bit, 640 x 480 (gnuplot)
4940 Jan 10 21:22 rwlockRCUperfwtPREEMPT.gif // 1-bit palette
3326 Jan 10 22:13 rwlockRCUperfwtPREEMPT.png // 1-bit grayscale (gif2png)
2967 Jan 10 22:13 rwlockRCUperfwtPREEMPT-crb.png // 1-bit grayscale (pngcrush)
[OT] JPEG + graphs == hideous
Cool! I just installed pngcrush, will try it out!