NAME

      jpg_compress, jpg_decompress - Joint  Photographic  Experts
     Group(JPEG) image compression scheme

SYNOPSIS

      #include "CVIPimage.h"
      #include "jinclude.h"
      #include "jversion.h"

     int jpg_compress(Image *cvipImage, char *filename, int qual-
     ity,  CVIP_BOOLEAN  grayscale,  CVIP_BOOLEAN  optimize,  int
     smooth, CVIP_BOOLEAN verbose, char *qtablesFile)

     <quality> -    Scale quantization  tables  to  adjust  image
     quality.  Quality is 0 (worst) to 100 (best); default is 75.
     (See below for more info.)

     <grayscale> -  Create monochrome JPEG file from color input.
     Be  sure to use this switch when compressing a grayscale GIF
     file, because cjpeg isn't bright enough to notice whether  a
     GIF  file  uses  only shades of gray.  By saying -grayscale,
     you'll get a smaller JPEG file that takes less time to  pro-
     cess.

     <optimize>  -   Perform  optimization  of  entropy  encoding
     parameters.  Without  this,  default encoding parameters are
     used.  -optimize  usually  makes  the  JPEG  file  a  little
     smaller,  but cjpeg runs somewhat slower and needs much more
     memory.  Image quality and speed of decompression are  unaf-
     fected by -optimize.

     <smooth> -     Smooth the input image to eliminate dithering
     noise.  N,  ranging from 1 to 100, indicates the strength of
     smoothing.  0 (the default) means no smoothing.

     <verbose> -    Enable debug printout.  More -v's  give  more
     printout. Also, version information is printed at startup.

     <qtables file> -     Use the quantization  tables  given  in
     the  specified  file.  The  file  should contain one to four
     tables (64 values each) as plain text.  Comments preceded by
     '#'  may be included in the file.  The tables are implicitly
     numbered 0,1,etc.  If -quality  N  is  also  specified,  the
     values  in  the  file are scaled accordingto cjpeg's quality
     scaling curve.

     Image   *jpg_decompress(char    *filename,    int    colors,
     CVIP_BOOLEAN     blocksmooth,     CVIP_BOOLEAN    grayscale,
     CVIP_BOOLEAN nodither, CVIP_BOOLEAN verbose);

     <colors> -     Reduce image  to  at  most  N  colors.   This
     reduces  the  number  of colors used in the output image, so
     that it can be displayed on a colormapped display or  stored
     in   a colormapped file format.  For example, if you have an
     8-bit display, you'd need to reduce to 256  or  fewercolors.
     (-colors is the recommended name, -quantize is provided only
     for backwards compatibility.)

     <blocksmooth> -Perform cross-block smoothing.  This is slow,
     quite  memory-intensive, and only seems to improve the image
     at very low quality settings (-quality 10 to 20 or  so).  At
     normal quality settings it may make things worse.

     <grayscale> -  Force gray-scale output even if JPEG file  is
     color. Useful for viewing on monochrome displays.

     <nodither> -   Do not use dithering in  color  quantization.
     By  default, Floyd-Steinberg dithering is applied when quan-
     tizing colors, but on some images dithering  may  result  in
     objectionable  "graininess".   If that happens, you can turn
     off dithering with -nodither. -nodither  is  ignored  unless
     you also say -colors N.

     <verbose> -    Enable debug printout.  More -v's  give  more
     printout. Also, version information is printed at startup.

PATH

     $CVIPHOME/COMPRESSION/jpeg.c

DESCRIPTION

     JPEG (pronounced "jay-peg") is a standardized image compres-
     sion  mechanism.  JPEG stands for Joint Photographic Experts
     Group, the original name of the  committee  that  wrote  the
     standard. JPEG is designed for compressing either full-color
     or gray-scale images of natural, real-world scenes. JPEG  is
     "lossy," meaning that the decompressed image isn't quite the
     same as the one  you  started  with.  JPEG  is  designed  to
     exploit known limitations of the human eye, notably the fact
     that small color changes are perceived less accurately  than
     small  changes  in  brightness. A useful property of JPEG is
     that the degree of lossiness  can  be  varied  by  adjusting
     compression parameters.  This means that the image maker can
     trade off file size against output image quality.

     The function code is based on BETA TEST  release  6a  of  7-
     Feb-96, the Independent JPEG Groups free JPEG software.

TYPES AND CONSTANTS

     None

RETURN VALUES

     jpg_compress: 0 on success, -1 on failure
     jpg_decompression:  an   uncompressed   image   pointer   on
     success,a NULL pointer on failure

HISTORY

     History information recorded: None

EXAMPLE

      #include "CVIPdef.h"
      #include "CVIPimage.h"
      #include "CVIPconvert.h"
      #include "CVIPcompress.h"

      void main() {
        Image *cvipImage, *outImage;
        IMAGE_FORMAT format;
        char *inputfile, *outputfile;
        int  returnVal;

        setDisplay_Image("RamViewer", "Default");

        print_CVIP("\n\t\tEnter the Input File Name:  ");
        inputfile = getString_CVIP();

        cvipImage = read_Image(inputfile, 1);
        view_Image(cvipImage, inputfile);

        print_CVIP("\n\t\tEnter the Compressed File Name:");
        outputfile = getString_CVIP();

        returnVal  =  jpg_compress(cvipImage,   outputfile,   75,
     CVIP_NO, CVIP_NO, 0, CVIP_NO, NULL);
        if (returnVal<0) {
            error_CVIP("jpg_compress", "compression failed");
            exit(1);
        }

        outImage  =  jpg_decompress(outputfile,   256,   CVIP_NO,
     CVIP_NO, CVIP_YES, CVIP_YES);

        if ((cvipImage)==NULL){
            error_CVIP("jpg_decompress", "decompression failed");
            exit(1);
        }
        else
            view_Image(outImage, outputfile);

        free(inputfile);
        free(outputfile);
      }

BUGS

     jpg_compress: to create  monochrome  JPEG  file  from  color
     input  by  set  input  argument  grayscale=CVIP_YES does not
     work; jpg_decompress: to force  gray-scale  output  even  if
     JPEG  file is color by set input argument grayscale=CVIP_YES
     does not work;

SEE ALSO

     libcompress,

AUTHOR

     Copyright (C) 1996 SIUE - by Scott Umbaugh, Kui Cai.