home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / include / imagedef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-16  |  9.4 KB  |  388 lines

  1. /*
  2. %    IMAGESDEF . H
  3. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5.  
  6. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  7. Permission is granted to reproduce this software for non-commercial
  8. purposes provided that this notice is left intact.
  9.  
  10. It is acknowledged that the U.S. Government has rights to this software
  11. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  12. and the University of California.
  13.  
  14. This software is provided as a professional and academic contribution
  15. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  16. with no warranties of any kind whatsoever, no support, no promise of
  17. updates, or printed documentation. By using this software, you
  18. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  19. University of California shall have no liability with respect to the
  20. infringement of other copyrights by any part of this software.
  21.  
  22. For further information about this notice, contact William Johnston,
  23. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  24. (wejohnston@lbl.gov)
  25.  
  26. For further information about this software, contact:
  27.     Jin Guojun
  28.     Bld. 50B, Rm. 2275,
  29.     Lawrence Berkeley Laboratory, Berkeley, CA, 94720
  30.     g_jin@lbl.gov
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. %
  33. % AUTHOR:    Jin Guojun - LBL    4/1/91
  34. */
  35.  
  36.  
  37. #ifndef    IMAGES_DEF
  38. #define    IMAGES_DEF
  39.  
  40. #include "stdef.h"
  41.  
  42. #ifndef    io_test
  43. extern    char    *io_test_msg[];
  44. #define    io_test(io_fd, then_what)    {    \
  45.     register int    iset= !isatty(io_fd);    \
  46.     if (!iset) {    msg("device %s not ready\n", io_test_msg[io_fd]);\
  47.         then_what; }    }
  48. #endif    io_test
  49.  
  50. #ifdef    NonReliablePipe
  51. #define    upread(buf, ibyte, fsize, fp)    \
  52.     pread(fileno(fp), buf, ibyte*fsize) / ibyte
  53. #else
  54. #define    upread(buf, ibyte, fsize, fp)    \
  55.     fread(buf, ibyte, fsize, fp)
  56. #endif
  57.  
  58.  
  59. #ifndef    PANEL_H
  60.  
  61. #ifndef MAX
  62. # define MAX(A, B)    ((A > B) ? A : B)
  63. #endif
  64. #ifndef MIN
  65. # define MIN(A,B)    ((A < B) ? A : B)
  66. #endif
  67. #ifndef ABS
  68. # define ABS(A)        ((A < 0) ? -(A) : A)
  69. #endif
  70. #ifndef    Sign
  71. #define    Sign(v)        ((v < 0) ? -1 : v!=0)
  72. #endif
  73.  
  74. typedef    struct    {
  75.     int    min, max,
  76.         maxcnt;
  77.     } Mregister;
  78.  
  79. #endif    PANEL_H
  80.  
  81.  
  82. #ifndef    cmap_t
  83. #define    cmap_t    byte
  84. #endif
  85. #ifndef    sht_cmap_t
  86. #define    sht_cmap_t    short
  87. #endif
  88. #ifndef    LKT
  89. #define    LKT    float
  90. #endif
  91.  
  92. typedef    struct    {
  93.     cmap_t    r, g, b;
  94.     } color_cell;
  95.  
  96. typedef    struct    {
  97.     int    curve, lower, upper, bgrd, fgrd, intp;
  98.     } CENR;
  99.  
  100. typedef    struct    {
  101.     int    min, max, diff;    /* union with Mregister */
  102.     LKT    *lkt;
  103.     } InterpMap;
  104.  
  105. #ifndef    HIST_TITLE_STR
  106. #define    HIST_TITLE_STR    "HIST01"
  107. #endif
  108. #ifndef    HELP_INFO
  109. #define    HELP_INFO    "CTRL + button => panel"
  110. #endif
  111.  
  112. #define    HEADER_READ    1
  113. #define    HEADER_FREAD    2
  114. #define    HEADER_WRITE    3
  115. #define    HEADER_FWRITE    4
  116. #define    HEADER_FROM    5
  117. #define    HEADER_TO    6
  118. #define    HEADER_TRANSF    7
  119. #define    ADD_DESC    8
  120.  
  121. #define    HIPS    1
  122. #define    FITS    2
  123. #define    RLE    3
  124. #define    GIF    4
  125. #define    PGM    5
  126. #define    RAS    6
  127. #define    TiFF    7
  128. #define    PBM    8
  129. #define    PPM    9
  130. #define    PNM    10
  131. #define    ICC    11
  132. #define    COLOR_PS    12    /* end regular type */
  133. #define    PICT    13
  134. #define    JPEG    14
  135. #define    ENDITYPE    JPEG
  136. #define    IName_List    "UNKNOWN", "HIPS", "FITS", "RLE", "GIF", "PGM", "RAS",\
  137.     "TIFF", "PBM", "PPM", "PNM", "ICC", "COLOR_PS", "PICT", "JPEG",    "? END"
  138.  
  139. #ifndef    IMAGE_INIT_TYPE
  140. #define    IMAGE_INIT_TYPE    HIPS
  141. #endif
  142.  
  143. #define    FI_LOAD_FILE        1
  144. #define    FI_LOAD_ROW        2
  145. #define    FI_RLOAD_BUF        3
  146. #define    FI_RESERVED        4
  147. #define    FI_ACCESS_ABS_FRAME    5
  148. #define    FI_SAVE_FILE        6
  149. #define    FI_WHAT_FILE        7
  150. #define    FI_DESC_ETA        8
  151. #define    FI_GET_INFORMATION    9
  152. #define    FI_HIPS_HEADER_FORMAT    10
  153. #define    FI_INIT_NAME        11
  154. #define    FI_PNM_MAXVAL        12
  155.  
  156. #include <ctype.h>
  157. #ifndef    isfloat
  158. #define    isfloat(c)    (isdigit(c) || c=='.' || c=='-' || c=='+' || toupper(c)=='E')
  159. #endif
  160.  
  161. #ifndef    MType
  162. # ifdef    IBMPC    /* for different Machine Memory allocating    */
  163. #   define    MType    long
  164. # else
  165. #   define    MType    int
  166. # endif
  167. #endif
  168.  
  169. #define    bound_check(v, b, t)    \
  170.     if (b < 0)    b=0;    if (v+b > t)    v = t - b
  171.  
  172.  
  173. #define    MASKFUNC_MAXABS        1
  174. #define    MASKFUNC_MEANSQ        2
  175. #define    MASKFUNC_SUMABS        3
  176. #define    MASKFUNC_MAXX        4
  177. #define    MASKFUNC_MAXFLR        5
  178. #define    MASKFUNC_MAXSFLR    6
  179. #define    MASKFUNC_MUL        7
  180. #define    MASKFUNC_NORM        8
  181. #define    MASKFUNC_DIFF        9
  182. #define    MASKFUNC_ORIENT        10
  183. #define    MASKFUNC_IDENT        11
  184. #define    MAXMASKFUNCS    10
  185. #define    MAXMASKSet    9
  186.  
  187. #ifndef    MaxMaskSZ
  188. #define    MaxMaskSZ    9
  189. #endif
  190.  
  191. typedef    struct    {
  192.     char    *name, *history, *desc;
  193.     int    m_func,
  194.         m_sets,        /* # of mask sets (number of cubes) */
  195.         n_mask,        /* # of masks in each set */
  196.         m_size,        /* mask size    */
  197.         revs,        /* reverse all value in masks    */
  198.         bp_inc,
  199.         norm_d,        /* normalization divisor */
  200.         flag,        /* boundaries use    */
  201.         boundl, boundr,
  202.         boundt, boundb,
  203.         boundf, bound,
  204.         minusd, plusd,
  205.         *mval,        /* mask working place    */
  206.         **m_list,    /* can be any type. default is FP */
  207.         val;
  208.     } Mask_Win;
  209.  
  210. typedef    struct    {
  211.     char    *name, *history, *desc;
  212.     long    colormap;
  213.     void    *dpy, *gc, *igc;
  214.     long    frame, win, icon;
  215.     void    *event;
  216.     int    x0, y0, width, height,
  217.         icon_width, icon_height,
  218.         font_w, font_h, ascent;
  219.     VType    *image, *icon_image;
  220.     int    curve, linearlow, linearup, bgrd, fgrd,    /* elastic curve */
  221.         scale, tmp_offset,    /* used for anything    */
  222.         mark_x, mark_y, resize_w, resize_h,
  223.         sub_img_x, sub_img_y, sub_img_w, sub_img_h,
  224.         mag_fact, mag_mode,    /* display magnified image */
  225.         mag_x, mag_y, mag_w, mag_h,/* subimage currently being viewed */
  226.         save_mag_x, save_mag_y, save_mag_w, save_mag_h,
  227.         save_mag_fact, dpy_depth,
  228.         frames, fn, channels, dpy_channels,
  229.         *hist, *histp;    /* histogram buffer & pointer    */
  230.     VType    *src, *dest, *cnvt, *img_buf, *lkt;
  231.     bool    sub_img, sub_img_enh,    /* sub window and enhanced    */
  232.         active, rw_cmap,    /* writable colormap    */
  233.         color_dpy,        /* False if black/white    */
  234.         dither_img, update,
  235.         logscale, setscale,    /* use unique or own maxcnt    */
  236.         load_all, save_all;    /* if not true, do 1 frame at a time */
  237.     int    in_type, mid_type, o_type, in_color, color_form,
  238.         in_form, o_form, pxl_in, pxl_out;
  239.     FILE    *IN_FP, *OUT_FP;
  240.     Mregister    mmm, *marray;
  241.     StdInterface    *errors, *header_handle, *std_swif,
  242.             *close, *eof, *open, *read, *seek, *write;
  243.     TableInterface    (*table_if)(), **table, tables;
  244.     VType    **superimpose, *parts;
  245.     short    draws, texts, stack_num;/* parts in part stack    */
  246.     void    (*map_scanline)(), (*MAG_scanline)();
  247.     bool    binary_img, mono_img,    /* same info as color_form    */
  248.         mono_color, sep_colors,
  249.         update_header;
  250.     int    entries, ncmap, cmaplen;
  251.     cmap_t    **cmap;
  252. #if defined EXTENDED_U_IMAGE | defined X_WINDOW_DEP
  253.     int    lvls, lvls_squared,
  254.         visual_class;
  255.     VType    *dpy_visual;
  256. #endif
  257.     } U_IMAGE;    /* standard Union Image structure for filters */
  258.  
  259.  
  260. extern    U_IMAGE    uimg;
  261. #define    in_fp    uimg.IN_FP
  262. #define    out_fp    uimg.OUT_FP
  263.  
  264. #ifdef    SHOW_WARNINGS
  265. extern    VType    syserr();
  266. #else
  267. extern    bool    syserr();
  268. #endif
  269.  
  270. extern    char    *Progname, *Mversion, *ITypeName[];
  271. extern    cmap_t    *reg_cmap[3];    /* also *r_cmap are global cmaps */
  272. extern    sht_cmap_t    *r_cmap,
  273.         *regmap_to_rlemap(/* cmap, number, channels, rle_hd */);
  274.  
  275. extern    void    work_space_init(), DBwork_space_init(),
  276.         QuickSort();
  277. extern    VType    *DBvfft3d(), *DBvrft3d(), *vfft3d(), *vrft3d(),
  278.         *rgbmap_to_othermap(/* cmap, number, reg_or_rle */);
  279. extern    float    *vfft2d(), *vrft2d();
  280. extern    double    *DBvfft2d(), *DBvrft2d();
  281. extern    int    load_w(), load_DBw(),
  282.         Fourier(), DBFourier();
  283. extern    int    w_init(), w_load(),
  284.         vfft(), vfft_2d(), vrft_2d(), vfftn(),
  285.         dw_init(), dw_load(),
  286.         dvfft(), dvfft_2d(), dvfrt_2d(), dvfftn(),
  287.         RED_to_GRAY, GREEN_to_GRAY, BLUE_to_GRAY;
  288. extern    MType    fsize;    /* this one may not always exist */
  289.  
  290.  
  291. #ifndef    MaxColors
  292. #define    MaxColors    256
  293. #endif
  294.  
  295. #if    defined    COMMON_TOOL | defined    RLE_IMAGE
  296.  
  297. #include "rle.h"
  298.  
  299. #ifndef    SAVED_RLE_ROW
  300. #define SAVED_RLE_ROW(img, y)    \
  301.     ((byte*)((U_IMAGE*)img)->dest +    \
  302.     ((y) * ((U_IMAGE*)img)->width * (img)->dpy_channels))
  303. #define ORIG_RLE_ROW(img, y)    \
  304.     ((byte*)((U_IMAGE*)img)->src +    \
  305.     ((y) * ((U_IMAGE*)img)->width * (img)->dpy_channels))
  306. #endif    RLE_ROW
  307.  
  308. #endif    RLE_IMAGE
  309.  
  310.  
  311. #ifdef    COMMON_TOOL
  312.  
  313. typedef    struct    {
  314.     unsigned int    Width, Height,
  315.             CmapLen,
  316.             ColorResolution,
  317.             Background,
  318.             AspectRatio;
  319.     color_cell    ColorMap[MaxColors];
  320.     bool    interlace, jumpover;    /* pass uninteresting images */
  321.     } GS;
  322.  
  323. extern    GS    GifScreen;
  324.  
  325.  
  326. /*    The format for the "ICC" header is:    */
  327.  
  328. #ifndef    ICC_MAGIC
  329. #define    ICC_MAGIC    5965600
  330. #endif
  331.  
  332. typedef    struct    {
  333.     MType    magic_num,    /*    Magic Number    4 bytes    */
  334.         hd_len,        /*    Header Length    4 bytes    */
  335.         /*    Extraneous data    (Header Length - 4) bytes    */
  336.         H_W, S_W,
  337.         date, time,
  338.         new_date, new_time;
  339.     char    user_name[32];
  340.     struct    {
  341.     MType    len,        /*    Image header length    4 bytes    */
  342.         length;        /*    Header + data length    4 bytes    */
  343.     char    LFName[16];    /*    Logical File Name    16 bytes
  344.             This field will cause KPR command not working    */
  345.     MType    File_Type,    /*    ICC is (7)        4 bytes    */
  346.         orig_width,    /*    Extraneous data        8 bytes    */
  347.         orig_height,
  348.         x_size,        /*    Image X Size        4 bytes    */
  349.         y_size,        /*    Image Y Size        4 bytes    */
  350.         Ext_Data3[2],    /*    Extraneous data        8 bytes    */
  351.         gray_scale,    /*    color = 0, g/s = 1    4 bytes    */
  352.         planes;        /*    color = 3, g/s = 1    4 bytes    */
  353.     VType    *Ext_Data;    /*    Extraneous data        n bytes    */
  354.     } img_hd;
  355.     }    ICC_HEADER;
  356.  
  357. extern    ICC_HEADER    icchd;
  358.  
  359. # ifndef    X_WINDOW_DEP
  360. #    include    "pnm.h"
  361. #    include    "ppmcmap.h"
  362. # endif
  363.  
  364. # include    "tiffio.h"
  365. # include    "tiffioP.h"
  366. extern    TIFF    *TIFFin;
  367. extern    unsigned short    samplesperpixel, bitspersample;
  368.  
  369. # include    "rast.h"
  370. extern    struct rasterfile    srhd;
  371.  
  372. #ifndef    RAST_8PAD    /* must be power of 2 */
  373. #define    RAST_8PAD    2
  374. #endif
  375. #define    RAST_8COMP    RAST_8PAD - 1
  376.  
  377. #ifndef    RAST_ODD_PAD
  378. #  if    RAST_8PAD == 2
  379. #    define RAST_ODD_PAD(w)    ((w) & RAST_8COMP)
  380. #  else
  381. #    define RAST_ODD_PAD(w)    (RAST_8PAD - ((w) & RAST_8COMP) & RAST_8COMP)
  382. #  endif
  383. #endif
  384.  
  385. #endif    COMMON_TOOL
  386.  
  387. #endif    IMAGES_DEF
  388.