<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<!-- lifted from troff+man by doclifter -->
<refentry id='jpegtran1'>
<refmeta>
<refentrytitle>JPEGTRAN</refentrytitle>
<manvolnum>1E</manvolnum>
<refmiscinfo class='date'>3 August 1997</refmiscinfo>
<refmiscinfo class='source'>IJG</refmiscinfo>
<refmiscinfo class='manual'>NFIS Reference Manual</refmiscinfo>
</refmeta>
<refnamediv id='name'>
<refname>jpegtran</refname>
<refpurpose>lossless transformation of JPEG files</refpurpose>
</refnamediv>
<!-- body begins here -->
<refsynopsisdiv id='synopsis'>
<cmdsynopsis>
  <command>jpegtran</command>    
    <arg choice='opt'><replaceable>options</replaceable></arg>
    <arg choice='opt'><replaceable>filename</replaceable></arg>
    <sbr/>
</cmdsynopsis>
</refsynopsisdiv>


<refsect1 id='description'><title>DESCRIPTION</title>
<para><command>jpegtran</command>
performs various useful transformations of JPEG files.
It can translate the coded representation from one variant of JPEG to another,
for example from baseline JPEG to progressive JPEG or vice versa.  It can also
perform some rearrangements of the image data, for example turning an image
from landscape to portrait format by rotation.</para>

<para><command>jpegtran</command>
works by rearranging the compressed data (DCT coefficients), without
ever fully decoding the image.  Therefore, its transformations are lossless:
there is no image degradation at all, which would not be true if you used
<emphasis remap='B'>djpeg</emphasis>
followed by
<emphasis remap='B'>cjpeg</emphasis>
to accomplish the same conversion.  But by the same token,
<command>jpegtran</command>
cannot perform lossy operations such as changing the image quality.</para>

<para><command>jpegtran</command>
reads the named JPEG/JFIF file, or the standard input if no file is
named, and produces a JPEG/JFIF file on the standard output.</para>
</refsect1>

<refsect1 id='options'><title>OPTIONS</title>
<para>All switch names may be abbreviated; for example,
<option>-optimize</option>
may be written
<option>-opt</option>
or
<option>-o</option>.
Upper and lower case are equivalent.
British spellings are also accepted (e.g.,
<option>-optimise</option>),
though for brevity these are not mentioned below.</para>

<para>To specify the coded JPEG representation used in the output file,
<command>jpegtran</command>
accepts a subset of the switches recognized by
<emphasis remap='B'>cjpeg</emphasis>:</para>
<variablelist remap='TP'>
  <varlistentry>
  <term><option>-optimize</option></term>
  <listitem>
<para>Perform optimization of entropy encoding parameters.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-progressive</option></term>
  <listitem>
<para>Create progressive JPEG file.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-restart</option><replaceable> N</replaceable></term>
  <listitem>
<para>Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
attached to the number.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-scans</option><replaceable> file</replaceable></term>
  <listitem>
<para>Use the scan script given in the specified text file.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>See
<citerefentry><refentrytitle>cjpeg</refentrytitle><manvolnum>1</manvolnum></citerefentry>
for more details about these switches.
If you specify none of these switches, you get a plain baseline-JPEG output
file.  The quality setting and so forth are determined by the input file.</para>

<para>The image can be losslessly transformed by giving one of these switches:</para>
<variablelist remap='TP'>
  <varlistentry>
  <term><option>-flip horizontal</option></term>
  <listitem>
<para>Mirror image horizontally (left-right).</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-flip vertical</option></term>
  <listitem>
<para>Mirror image vertically (top-bottom).</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-rotate 90</option></term>
  <listitem>
<para>Rotate image 90 degrees clockwise.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-rotate 180</option></term>
  <listitem>
<para>Rotate image 180 degrees.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-rotate 270</option></term>
  <listitem>
<para>Rotate image 270 degrees clockwise (or 90 ccw).</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-transpose</option></term>
  <listitem>
<para>Transpose image (across UL-to-LR axis).</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-transverse</option></term>
  <listitem>
<para>Transverse transpose (across UR-to-LL axis).</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>The transpose transformation has no restrictions regarding image dimensions.
The other transformations operate rather oddly if the image dimensions are not
a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
transform complete blocks of DCT coefficient data in the desired way.</para>

<para><command>jpegtran</command>'s
default behavior when transforming an odd-size image is designed
to preserve exact reversibility and mathematical consistency of the
transformation set.  As stated, transpose is able to flip the entire image
area.  Horizontal mirroring leaves any partial iMCU column at the right edge
untouched, but is able to flip all rows of the image.  Similarly, vertical
mirroring leaves any partial iMCU row at the bottom edge untouched, but is
able to flip all columns.  The other transforms can be built up as sequences
of transpose and flip operations; for consistency, their actions on edge
pixels are defined to be the same as the end result of the corresponding
transpose-and-flip sequence.</para>

<para>For practical use, you may prefer to discard any untransformable edge pixels
rather than having a strange-looking strip along the right and/or bottom edges
of a transformed image.  To do this, add the
<option>-trim</option>
switch:</para>
<variablelist remap='TP'>
  <varlistentry>
  <term><option>-trim</option></term>
  <listitem>
<para>Drop non-transformable edge blocks.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>Obviously, a transformation with
<option>-trim</option>
is not reversible, so strictly speaking
<command>jpegtran</command>
with this switch is not lossless.  Also, the expected mathematical
equivalences between the transformations no longer hold.  For example,
<option>-rot 270 -trim</option>
trims only the bottom edge, but
<option>-rot 90 -trim</option>
followed by
<option>-rot 180 -trim</option>
trims both edges.</para>

<para>Another not-strictly-lossless transformation switch is:</para>
<variablelist remap='TP'>
  <varlistentry>
  <term><option>-grayscale</option></term>
  <listitem>
<para>Force grayscale output.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>This option discards the chrominance channels if the input image is YCbCr
(ie, a standard color JPEG), resulting in a grayscale JPEG file.  The
luminance channel is preserved exactly, so this is a better method of reducing
to grayscale than decompression, conversion, and recompression.  This switch
is particularly handy for fixing a monochrome picture that was mistakenly
encoded as a color JPEG.  (In such a case, the space savings from getting rid
of the near-empty chroma channels won't be large; but the decoding time for
a grayscale JPEG is substantially less than that for a color JPEG.)</para>

<para><command>jpegtran</command>
also recognizes these switches that control what to do with "extra" markers,
such as comment blocks:</para>
<variablelist remap='TP'>
  <varlistentry>
  <term><option>-copy none</option></term>
  <listitem>
<para>Copy no extra markers from source file.  This setting suppresses all
comments and other excess baggage present in the source file.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-copy comments</option></term>
  <listitem>
<para>Copy only comment markers.  This setting copies comments from the source file,
but discards any other inessential data.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-copy all</option></term>
  <listitem>
<para>Copy all extra markers.  This setting preserves miscellaneous markers
found in the source file, such as JFIF thumbnails and Photoshop settings.
In some files these extra markers can be sizable.</para>
  </listitem>
  </varlistentry>
</variablelist>

<para>The default behavior is
<option>-copy comments</option>.
(Note: in IJG releases v6 and v6a,
<command>jpegtran</command>
always did the equivalent of
<option>-copy none</option>.)</para>

<para>Additional switches recognized by jpegtran are:</para>
<variablelist remap='TP'>
  <varlistentry>
  <term><option>-maxmemory</option><replaceable> N</replaceable></term>
  <listitem>
<para>Set limit for amount of memory to use in processing large images.  Value is
in thousands of bytes, or millions of bytes if "M" is attached to the
number.  For example,
<option>-max 4m</option>
selects 4000000 bytes.  If more space is needed, temporary files will be used.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-outfile</option><replaceable> name</replaceable></term>
  <listitem>
<para>Send output image to the named file, not to standard output.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-verbose</option></term>
  <listitem>
<para>Enable debug printout.  More
<option>-v</option>'s
give more output.  Also, version information is printed at startup.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><option>-debug</option></term>
  <listitem>
<para>Same as
<option>-verbose</option>.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='examples'><title>EXAMPLES</title>
<para>This example converts a baseline JPEG file to progressive form:</para>

<para><userinput>jpegtran -progressive</userinput>
<emphasis remap='I'>foo.jpg</emphasis>
<emphasis remap='B'>&gt;</emphasis>
<emphasis remap='I'>fooprog.jpg</emphasis></para>

<para>This example rotates an image 90 degrees clockwise, discarding any
unrotatable edge pixels:</para>

<para><userinput>jpegtran -rot 90 -trim</userinput>
<emphasis remap='I'>foo.jpg</emphasis>
<emphasis remap='B'>&gt;</emphasis>
<emphasis remap='I'>foo90.jpg</emphasis></para>
</refsect1>

<refsect1 id='environment'><title>ENVIRONMENT</title>
<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='B'>JPEGMEM</emphasis></term>
  <listitem>
<para>If this environment variable is set, its value is the default memory limit.
The value is specified as described for the
<option>-maxmemory</option>
switch.
<emphasis remap='B'>JPEGMEM</emphasis>
overrides the default value specified when the program was compiled, and
itself is overridden by an explicit
<option>-maxmemory</option>.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='see_also'><title>SEE ALSO</title>
<para><citerefentry><refentrytitle>cjpeg</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>djpeg</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>rdjpgcom</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>wrjpgcom</refentrytitle><manvolnum>1</manvolnum></citerefentry>
<!-- .br -->
Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.</para>
</refsect1>

<refsect1 id='author'><title>AUTHOR</title>
<para>Independent JPEG Group</para>
</refsect1>

<refsect1 id='bugs'><title>BUGS</title>
<para>Arithmetic coding is not supported for legal reasons.</para>

<para>The transform options can't transform odd-size images perfectly.  Use
<option>-trim</option>
if you don't like the results without it.</para>

<para>The entire image is read into memory and then written out again, even in
cases where this isn't really necessary.  Expect swapping on large images,
especially when using the more complex transform options.</para>
</refsect1>
</refentry>

