<- previous    index    next ->

Lecture 28, output Jpeg, PostScript, png

Often you or a user may desire an output file format other than
a screen capture. There are many reasons such as better resolution,
anti aliasing, better color or conversion of color to greyscale.

A library is available for including in your "C" program to be
able to both input and output Jpeg files.
All WEB browsers handle  *.jpg  files and these files can be
compressed to various degrees to get a size verses detail trade off.

Get the Jpeg source code for reading and writing via:
jpegsrcv6b.tgz worked for me on Linux.
jpegsrcv6b.zip can be made to work on MS Windows.

An example use of the above jpeg library for writing a .jpg file is:
write_jpg_file.c from my draw program.


Capture the pixels using the method as demonstrated for Gif output.
Use Jpeg sample program to call routines in libjpeg to write file.


PostScript is a graphical programming language for printers.
PostScript can be generated by your program. A sample of PostScript
routines is available. Note that a PostScript file is plain text.
A PostScript file may be edited similar to any programming language.
Well, PostScript can be used as a programming language although that
is not the primary use.

PostScript for printing greyscale of a 3D color rendered image:
draw_post.h function prototypes
draw_post.c "C" code that writes  *.ps file
test_post.c test program for above files
test_post.ps PostScript output as text
Postscript will not display in some browsers.
Convert postscript .ps  to pdf .pdf using:
  ps2pdfwr  xxx.ps  xxx.pdf
test_post.pdf

draw_postscript.c example use from 3D data structure

drawps.cc Program to convert the output of an
object oriented 2D digital logic schematic editor to a PostScript file.
This program reads a  .draw  ASCII file that the user of the editor saved.


PostScript for printing greyscale of a 3D color rendered image, java:
draw_post.java java calls
test_draw_post.java test program for above files
test_draw_post.out debug output
test_draw_post.ps PostScript output as text

Use Goggle to search for "A First Guide to PostScript"  then
find a more complete manual, big, searching for
"Adobe PostScript Programming Manual"

Basic PostScript is easy to write. Most PostScript files are hard
to read because of the extensive use of unique macros.
Note that draw_post.c has the original PostScript
commented out, and now writes much smaller files using macros.
"Smaller" is a joke when it comes to rendered 3D graphics, these
PostScript files are typically large, 1MB or more.

Note that I have only used greyscale PostScript. There are a few
color PostScript printers available and the cost are coming down.
The conversion from RGB to greyscale 'shade' where RGB are in the
range 0.0 to 1.0 and shade is in the range 0.0 to 1.0 is:

  shade = 0.299 * R + 0.587 * G + 0.114 * B

The Postscript page for 8-1/2 by 11 paper in portrait orientation
would have x coordinates from 0 to 612 (8.5 * 72) and y coordinates
from 0 to 792 (11 * 72). But, leave a margin because most printers
will not print to the edge of the page. For 1/2 inch boarders,
scale and offset the scene to x in 36 to 576 and to y in 36 to 756.


png graphic files can be read and written easily in Java.
 Viewer.java  reads and displays
a  .png file.

 PNGwrite.java  writes a .png file.
This sample code shows that whatever was used for "paint" must be
used again to build an internal buffered image that can be written
out as a  .png file. Other file types such as .jpg are available also.

The commands:
  javac Viewer.java
  java  Viewer colorw.png
  javac PNGwrite.java
  java  PNGwrite xxx.png
  java  Viewer   xxx.png
demonstrate the capabilities of both programs.

colorw.png is


xxx.png is


I have made many interesting shapes, here is one


 test_shaper.py3 source code 

    <- previous    index    next ->

Other links

Many web sites on Java GUI, AWT, Swing, etc.
Many web sites on Python wx, tk, qt, etc.

Go to top