home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / include / rle.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  14.2 KB  |  486 lines

  1. /*
  2.  * This software is copyrighted as noted below.  It may be freely copied,
  3.  * modified, and redistributed, provided that the copyright notice is 
  4.  * preserved on all copies.
  5.  * 
  6.  * There is no warranty or other guarantee of fitness for this software,
  7.  * it is provided solely "as is".  Bug reports or fixes may be sent
  8.  * to the author, who may or may not act on them as he desires.
  9.  *
  10.  * You may not include this software in a program or other software product
  11.  * without supplying the source, or without informing the end-user that the 
  12.  * source is available for no extra charge.
  13.  *
  14.  * If you modify this software, you should include a notice giving the
  15.  * name of the person performing the modification, the date of modification,
  16.  * and the reason for such modification.
  17.  */
  18. /* 
  19.  * rle.h - Global declarations for Utah Raster Toolkit RLE programs.
  20.  * 
  21.  * Author:    Todd W. Fuqua
  22.  *         Computer Science Dept.
  23.  *         University of Utah
  24.  * Date:    Sun Jul 29 1984
  25.  * Copyright (c) 1984 Todd W. Fuqua
  26.  * 
  27.  * $Id: rle.h,v 3.0.1.1 90/11/19 16:52:57 spencer Exp $
  28.  */
  29.  
  30. #ifndef RLE_H
  31. #define RLE_H
  32.  
  33. #include "rle_config.h"        /* Configuration parameters. */
  34.  
  35. #include <stdio.h>        /* Declare FILE. */
  36.  
  37. #ifdef c_plusplus
  38. #define USE_PROTOTYPES
  39. #endif
  40. #ifndef CONST_DECL
  41. #define CONST_DECL
  42. #endif
  43.  
  44. enum rle_dispatch {
  45.     NO_DISPATCH = -1,
  46.     RUN_DISPATCH = 0
  47. };
  48.  
  49. /* ****************************************************************
  50.  * TAG( rle_pixel rle_map )
  51.  *
  52.  * Typedef for 8-bit (or less) pixel data.
  53.  *
  54.  * Typedef for 16-bit color map data.
  55.  */
  56. typedef unsigned char rle_pixel;
  57. typedef unsigned short rle_map;
  58.  
  59. /*
  60.  * Defines for traditional channel numbers.
  61.  */
  62. #define    RLE_RED        0    /* Red channel traditionally here. */
  63. #define RLE_GREEN    1    /* Green channel traditionally here. */
  64. #define    RLE_BLUE    2    /* Blue channel traditionally here. */
  65. #define RLE_ALPHA      -1    /* Alpha channel here. */
  66.  
  67. /*
  68.  * Return values from rle_get_setup.
  69.  */
  70. #define    RLE_SUCCESS     0
  71. #define    RLE_NOT_RLE    -1
  72. #define    RLE_NO_SPACE    -2
  73. #define    RLE_EMPTY    -3
  74. #define    RLE_EOF        -4
  75.  
  76. /*
  77.  * TAG( rle_hdr )
  78.  *
  79.  * Definition of header structure used by RLE routines.
  80.  */
  81.  
  82. #ifndef c_plusplus
  83. typedef struct rle_hdr rle_hdr;
  84. #endif
  85.  
  86. struct rle_hdr {
  87.     enum     rle_dispatch dispatch;    /* Type of file to create. */
  88.     int            ncolors,    /* Number of color channels. */
  89.            *bg_color,    /* Pointer to bg color vector. */
  90.             alpha,        /* If !0, save alpha channel. */
  91.             background,    /* 0->just save all pixels, */
  92.                 /* 1->overlay, 2->clear to bg first. */
  93.             xmin,        /* Lower X bound (left.) */
  94.             xmax,        /* Upper X bound (right.) */
  95.             ymin,        /* Lower Y bound (bottom.) */
  96.             ymax,        /* Upper Y bound (top.) */
  97.             ncmap,        /* Number of color channels in color map. */
  98.                 /* Map only saved if != 0. */
  99.             cmaplen;    /* Log2 of color map length. */
  100.     rle_map    *cmap;        /* Pointer to color map array. */
  101.     CONST_DECL char **comments;    /* Pointer to array of pointers to comments. */
  102.     FILE       *rle_file;    /* Input or output file. */
  103.     /* 
  104.      * Bit map of channels to read/save.  Indexed by (channel mod 256).
  105.      * Alpha channel sets bit 255.
  106.      * 
  107.      * Indexing (0 <= c <= 255):
  108.      *        bits[c/8] & (1 << (c%8))
  109.      */
  110. #define RLE_SET_BIT(glob,bit) \
  111.      ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))
  112. #define RLE_CLR_BIT(glob,bit) \
  113.     ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7)))
  114. #define RLE_BIT(glob,bit) \
  115.     ((glob).bits[((bit)&0xff)/8] & (1<<((bit)&0x7)))
  116.     char    bits[256/8];
  117.     /* 
  118.      * Local storage for rle_getrow & rle_putrow.
  119.      * rle_getrow has
  120.      *        scan_y    int        current Y scanline.
  121.      *        vert_skip    int        number of lines to skip.
  122.      * rle_putrow has
  123.      *        nblank    int        number of blank lines.
  124.      *        brun    short(*)[2] Array of background runs.
  125.      *        fileptr    long        Position in output file.
  126.      */
  127.      union {
  128.     struct {
  129.         int    scan_y,
  130.         vert_skip;
  131.         char is_eof,    /* Set when EOF or EofOp encountered. */
  132.         is_seek;    /* If true, can seek input file. */
  133.     } get;
  134.     struct {
  135.         int    nblank;
  136.         short (*brun)[2];
  137.         long fileptr;
  138.     } put;
  139.      } priv;
  140. };
  141.  
  142. /* 
  143.  * TAG( rle_dflt_hdr )
  144.  *
  145.  * Global variable with possibly useful default values.
  146.  */
  147. extern rle_hdr rle_dflt_hdr;
  148.  
  149.  
  150. /* Declare RLE library routines. */
  151.  
  152. #ifdef USE_PROTOTYPES
  153.     /* From rle_getrow.c */
  154.  
  155.     /*****************************************************************
  156.      * TAG( rle_debug )
  157.      * 
  158.      * Turn RLE debugging on or off.
  159.      */
  160.     extern void rle_debug( int on_off );
  161.  
  162.     /*****************************************************************
  163.      * TAG( rle_get_error )
  164.      *
  165.      * Print an error message based on the error code returned by
  166.      * rle_get_setup.
  167.      */
  168.     extern int rle_get_error( int code,
  169.                   CONST_DECL char *pgmname,
  170.                   CONST_DECL char *fname );
  171.               
  172.     /*****************************************************************
  173.      * TAG( rle_get_setup )
  174.      */
  175.     extern int rle_get_setup( rle_hdr *the_hdr );
  176.  
  177.     /*****************************************************************
  178.      * TAG( rle_get_setup_ok )
  179.      *
  180.      * Call rle_get_setup.  If it returns an error code, call
  181.      * rle_get_error to print the error message, then exit with the error
  182.      * code. 
  183.      */
  184.     extern void rle_get_setup_ok( rle_hdr *the_hdr,
  185.                   CONST_DECL char *prog_name,
  186.                   CONST_DECL char *file_name);
  187.  
  188.     /*****************************************************************
  189.      * TAG( rle_getrow )
  190.      *
  191.      * Read a scanline worth of data from an RLE file.
  192.      */
  193.     extern int rle_getrow( rle_hdr * the_hdr, 
  194.                rle_pixel * scanline[] );
  195.  
  196.     /* From rle_getskip.c */
  197.  
  198.     /*****************************************************************
  199.      * TAG( rle_getskip )
  200.      * Skip a scanline, return the number of the next one.
  201.      */
  202.     extern unsigned int rle_getskip( rle_hdr *the_hdr );
  203.  
  204.     /* From rle_putrow.c. */
  205.  
  206.     /*****************************************************************
  207.      * TAG( rgb_to_bw )
  208.      *
  209.      * Converts RGB data to gray data via the NTSC Y transform.
  210.      */
  211.     extern void rgb_to_bw( rle_pixel *red_row,
  212.                rle_pixel *green_row,
  213.                rle_pixel *blue_row,
  214.                rle_pixel *bw_row,
  215.                int rowlen );
  216.  
  217.     /*****************************************************************
  218.      * TAG( rle_puteof )
  219.      *
  220.      * Write an End-of-image opcode to the RLE file.
  221.      */
  222.     extern void rle_puteof( rle_hdr *the_hdr );
  223.  
  224.     /*****************************************************************
  225.      * TAG( rle_putrow )
  226.      *
  227.      * Write a scanline of data to the RLE file.
  228.      */
  229.     extern void rle_putrow( rle_pixel *rows[], int rowlen, rle_hdr *the_hdr );
  230.  
  231.     /*****************************************************************
  232.      * TAG( rle_put_init )
  233.      *
  234.      * Initialize header for output, but don't write it to the file.
  235.      */
  236.     extern void rle_put_init( rle_hdr * the_hdr );
  237.  
  238.     /*****************************************************************
  239.      * TAG( rle_put_setup )
  240.      *
  241.      * Write header information to a new RLE image file.
  242.      */
  243.     extern void rle_put_setup( rle_hdr * the_hdr );
  244.  
  245.     /*****************************************************************
  246.      * TAG( rle_skiprow )
  247.      *
  248.      * Skip nrow scanlines in the output file.
  249.      */
  250.     extern void rle_skiprow( rle_hdr *the_hdr, int nrow );
  251.  
  252.     /* From rle_cp.c */
  253.     /*****************************************************************
  254.      * TAG( rle_cp )
  255.      * Copy image data from input to output with minimal interpretation.
  256.      */
  257.     extern void rle_cp( rle_hdr *in_hdr, rle_hdr *out_hdr );
  258.  
  259.     /* From rle_row_alc.c. */
  260.     /*****************************************************************
  261.      * TAG( rle_row_alloc )
  262.      *
  263.      * Allocate scanline memory for use by rle_getrow.
  264.      */
  265.     extern int rle_row_alloc( rle_hdr * the_hdr,
  266.                   rle_pixel *** scanp );
  267.  
  268.     /*****************************************************************
  269.      * TAG( rle_row_free )
  270.      *
  271.      * Free the above.
  272.      */
  273.     extern void rle_row_free( rle_hdr *the_hdr, rle_pixel **scanp );
  274.  
  275.     /* From buildmap.c. */
  276.     /* 
  277.      * buildmap - build a more usable colormap from data in the_hdr struct.
  278.      */
  279.     extern rle_pixel **buildmap( rle_hdr *the_hdr,
  280.                  int minmap,
  281.                  double orig_gamma,
  282.                  double new_gamma );
  283.  
  284.     /* From rle_getcom.c. */
  285.     /*****************************************************************
  286.      * TAG( rle_getcom )
  287.      *
  288.      * Get a specific comment from the image comments.
  289.      */
  290.     extern char * rle_getcom( CONST_DECL char * name, rle_hdr * the_hdr );
  291.  
  292.     /* From rle_putcom.c. */
  293.     /*****************************************************************
  294.      * TAG( rle_delcom )
  295.      *
  296.      * Delete a specific comment from the image comments.
  297.      */
  298.     extern CONST_DECL char *
  299.     rle_delcom( CONST_DECL char * name, rle_hdr * the_hdr );
  300.  
  301.     /*****************************************************************
  302.      * TAG( rle_putcom )
  303.      * 
  304.      * Put (or replace) a comment into the image comments.
  305.      */
  306.     extern CONST_DECL char *
  307.     rle_putcom( CONST_DECL char * value, rle_hdr * the_hdr );
  308.  
  309.     /* From dither.c. */
  310.     /*****************************************************************
  311.      * TAG( bwdithermap )
  312.      * Create a color map for ordered dithering in grays.
  313.      */
  314.     extern void bwdithermap( int levels, double gamma, int bwmap[],
  315.                  int divN[256], int modN[256], int magic[16][16] );
  316.     /*****************************************************************
  317.      * TAG( ditherbw )
  318.      * Dither a gray-scale value.
  319.      */
  320.     extern int ditherbw( int x, int y, int val, 
  321.              int divN[256], int modN[256], int magic[16][16] );
  322.     /*****************************************************************
  323.      * TAG( dithergb )
  324.      * Dither a color value.
  325.      */
  326.     extern int dithergb( int x, int y, int r, int g, int b,
  327.              int divN[256], int modN[256], int magic[16][16] );
  328.     /*****************************************************************
  329.      * TAG( dithermap )
  330.      * Create a color map for ordered dithering in color.
  331.      */
  332.     extern void dithermap( int levels, double gamma, int rgbmap[][3],
  333.                int divN[256], int modN[256], int magic[16][16] );
  334.     /*****************************************************************
  335.      * TAG( make_square )
  336.      * Make a 16x16 magic square for ordered dithering.
  337.      */
  338.     extern void make_square( double N, int divN[256], int modN[256],
  339.                  int magic[16][16] );
  340.  
  341.     /* From float_to_exp.c. */
  342.     /*****************************************************************
  343.      * TAG( float_to_exp )
  344.      * Convert a list of floating point numbers to "exp" format.
  345.      */
  346.     extern void float_to_exp( int count, float * floats, rle_pixel * pixels );
  347.  
  348.     /* From rle_open_f.c. */
  349.     /*****************************************************************
  350.      * TAG( rle_open_f )
  351.      *
  352.      * Open an input/output file with default.
  353.      */
  354.     extern FILE *
  355.     rle_open_f( CONST_DECL char *prog_name,
  356.         CONST_DECL char *f_name,
  357.         CONST_DECL char *mode );
  358.  
  359.     /*****************************************************************
  360.      * TAG( rle_open_f_noexit )
  361.      *
  362.      * Open an input/output file with default.
  363.      */
  364.     extern FILE *
  365.     rle_open_f_noexit( CONST_DECL char *prog_name,
  366.                CONST_DECL char *f_name,
  367.                CONST_DECL char *mode );
  368.  
  369.     /* From colorquant.c. */
  370.     /*****************************************************************
  371.      * TAG( colorquant )
  372.      * Compute a colormap for quantizing an image to a limited set of colors.
  373.      */
  374.     extern int colorquant( rle_pixel *red, rle_pixel *green, rle_pixel *blue,
  375.                unsigned long pixels, rle_pixel *colormap[3],
  376.                int colors, int bits,
  377.                          rle_pixel *rgbmap, int fast, int otherimages );
  378.  
  379.     /* From rle_addhist.c. */
  380.     /*****************************************************************
  381.      * TAG( rle_addhist )
  382.      * Append history information to the HISTORY comment.
  383.      */
  384. extern void rle_addhist( char *argv[],
  385.              rle_hdr *in_hdr,
  386.              rle_hdr *out_hdr );
  387.  
  388.     /* From cmd_name.c. */
  389.     /*****************************************************************
  390.      * TAG( cmd_name )
  391.      * Extract command name from argv.
  392.      */
  393.     extern char *cmd_name( char **argv );
  394.  
  395.     /* From scanargs.c. */
  396.     /*****************************************************************
  397.      * TAG( scanargs )
  398.      * Scan command argument list and parse arguments.
  399.      */
  400.     extern int scanargs( int argc,
  401.              char **argv,
  402.              CONST_DECL char *format,
  403.              ... );
  404.  
  405. #ifdef NEED_BSTRING
  406.     /* From bstring.c. */
  407.     /*****************************************************************
  408.      * TAG( bstring bzero )
  409.      * 'Byte string' functions.
  410.      */
  411.     extern void bzero( char *str, int count );
  412.     extern void bcopy( char *from, char *to, int count );
  413. #endif
  414. #else /* USE_PROTOTYPES */
  415.     /* Return value decls for "K&R" C.  See above for full descriptions. */
  416.  
  417.     /* From rle_getrow.c. */
  418.     extern void rle_debug();
  419.     extern int rle_get_error();
  420.     extern int rle_get_setup();
  421.     extern void rle_get_setup_ok();
  422.     extern int rle_getrow();
  423.  
  424.     /* From rle_getskip.c */
  425.     extern unsigned int rle_getskip();
  426.  
  427.     /* From rle_putrow.c. */
  428.     extern void rgb_to_bw();
  429.     extern void rle_puteof();
  430.     extern void rle_putrow();
  431.     extern void rle_put_init();
  432.     extern void rle_put_setup();
  433.     extern void rle_skiprow();
  434.  
  435.     /* From rle_cp.c */
  436.     extern void rle_cp();
  437.  
  438.     /* From rle_row_alc.c. */
  439.     extern int rle_row_alloc();
  440.     extern void rle_row_free();
  441.  
  442.     /* From buildmap.c. */
  443.     extern rle_pixel **buildmap();
  444.     
  445.     /* From rle_getcom.c. */
  446.     extern char *rle_getcom();
  447.  
  448.     /* From rle_putcom.c. */
  449.     extern char *rle_delcom();
  450.     extern char *rle_putcom();
  451.  
  452.     /* From dither.c. */
  453.     extern void bwdithermap();
  454.     extern int ditherbw();
  455.     extern int dithergb();
  456.     extern void dithermap();
  457.     extern void magic4x4();
  458.     extern void make_square();
  459.  
  460.     /* From float_to_exp.c. */
  461.     extern void float_to_exp();
  462.  
  463.     /* From rle_open_f.c. */
  464.     extern FILE *rle_open_f();
  465.     extern FILE *rle_open_f_noexit();
  466.  
  467.     /* From colorquant.c. */
  468.     extern int colorquant();
  469.  
  470.     /* From rle_addhist.c. */
  471.     extern void rle_addhist();
  472.  
  473.     /* From cmd_name.c. */
  474.     extern char *cmd_name();
  475.  
  476.     /* From scanargs.c. */
  477.     extern int scanargs();
  478. #ifdef NEED_BSTRING
  479.     /* From bstring.c. */
  480.     extern void bzero();
  481.     extern void bcopy();
  482. #endif
  483. #endif /* USE_PROTOTYPES */
  484.  
  485. #endif /* RLE_H */
  486.