home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / print / print.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  16.0 KB  |  444 lines

  1. /*
  2.  * "$Id: print.h,v 1.15 2000/10/04 01:47:59 mitch Exp $"
  3.  *
  4.  *   Print plug-in header file for the GIMP.
  5.  *
  6.  *   Copyright 1997-2000 Michael Sweet (mike@easysw.com) and
  7.  *    Robert Krawitz (rlk@alum.mit.edu)
  8.  *
  9.  *   This program is free software; you can redistribute it and/or modify it
  10.  *   under the terms of the GNU General Public License as published by the Free
  11.  *   Software Foundation; either version 2 of the License, or (at your option)
  12.  *   any later version.
  13.  *
  14.  *   This program is distributed in the hope that it will be useful, but
  15.  *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16.  *   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17.  *   for more details.
  18.  *
  19.  *   You should have received a copy of the GNU General Public License
  20.  *   along with this program; if not, write to the Free Software
  21.  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22.  *
  23.  * Revision History:
  24.  *
  25.  *   See ChangeLog
  26.  */
  27.  
  28. /*
  29.  * This file must include only standard C header files.  The core code must
  30.  * compile on generic platforms that don't support glib, gimp, gtk, etc.
  31.  */
  32.  
  33. #ifndef PRINT_HEADER
  34. #define PRINT_HEADER
  35.  
  36. /*
  37.  * Include necessary header files...
  38.  */
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <errno.h>
  44.  
  45. /*
  46.  * Constants...
  47.  */
  48.  
  49. #define OUTPUT_GRAY        0    /* Grayscale output */
  50. #define OUTPUT_COLOR        1    /* Color output */
  51. #define OUTPUT_GRAY_COLOR    2     /* Grayscale output using color */
  52.  
  53. #define ORIENT_AUTO        -1    /* Best orientation */
  54. #define ORIENT_PORTRAIT        0    /* Portrait orientation */
  55. #define ORIENT_LANDSCAPE    1    /* Landscape orientation */
  56. #define ORIENT_UPSIDEDOWN    2    /* Reverse portrait orientation */
  57. #define ORIENT_SEASCAPE        3    /* Reverse landscape orientation */
  58.  
  59. #define MAX_CARRIAGE_WIDTH    80 /* This really needs to go away */
  60.                 /* For now, this is wide enough for 4B ISO */
  61.  
  62. #define IMAGE_LINE_ART        0
  63. #define IMAGE_SOLID_TONE    1
  64. #define IMAGE_CONTINUOUS    2
  65. #define IMAGE_MONOCHROME    3
  66. #define NIMAGE_TYPES        4
  67.  
  68. /* Uncomment the next line to get performance statistics:
  69.  * look for QUANT(#) in the code. At the end of escp2-print
  70.  * run, it will print out how long and how many time did 
  71.  * certain pieces of code take. Of course, don't forget about
  72.  * overhead of call to gettimeofday - it's not zero.
  73.  * If you need more detailed performance stats, just put
  74.  * QUANT() calls in the interesting spots in the code */
  75. /*#define QUANTIFY*/
  76. #ifdef QUANTIFY
  77. #include <assert.h>
  78. #include <sys/time.h>
  79. #include <unistd.h>
  80. #else
  81. #define QUANT(n)
  82. #endif
  83.  
  84. /*
  85.  * Printer driver control structure.  See "print.c" for the actual list...
  86.  */
  87.  
  88. typedef struct                    /* Plug-in variables */
  89. {
  90.   char    output_to[256],        /* Name of file or command to print to */
  91.     driver[64],        /* Name of printer "driver" */
  92.     ppd_file[256];        /* PPD file */
  93.   int    output_type;        /* Color or grayscale output */
  94.   char    resolution[64],        /* Resolution */
  95.     media_size[64],        /* Media size */
  96.     media_type[64],        /* Media type */
  97.     media_source[64],    /* Media source */
  98.     ink_type[64],        /* Ink or cartridge */
  99.     dither_algorithm[64];    /* Dithering algorithm */
  100.   float    brightness;        /* Output brightness */
  101.   float    scaling;        /* Scaling, percent of printable area */
  102.   int    orientation,        /* Orientation - 0 = port., 1 = land.,
  103.                    -1 = auto */
  104.     left,            /* Offset from lower-lefthand corner, points */
  105.     top;            /* ... */
  106.   float gamma;                  /* Gamma */
  107.   float contrast,        /* Output Contrast */
  108.     cyan,            /* Output red level */
  109.     magenta,        /* Output green level */
  110.     yellow;            /* Output blue level */
  111.   int    linear;            /* Linear density (mostly for testing!) */
  112.   float    saturation;        /* Output saturation */
  113.   float    density;        /* Maximum output density */
  114.   int    image_type;        /* Image type (line art etc.) */
  115.   int    unit;            /* Units for preview area 0=Inch 1=Metric */
  116.   float app_gamma;        /* Application gamma */
  117.   int    page_width;        /* Width of page in points */
  118.   int    page_height;        /* Height of page in points */
  119.   void  *lut;            /* Look-up table */
  120.   unsigned char *cmap;        /* Color map */
  121. } vars_t;
  122.  
  123. typedef struct        /**** Printer List ****/
  124. {
  125.   int    active;            /* Do we know about this printer? */
  126.   char    name[128];        /* Name of printer */
  127.   vars_t v;
  128. } plist_t;
  129.  
  130. typedef enum papersize_unit
  131. {
  132.   PAPERSIZE_ENGLISH,
  133.   PAPERSIZE_METRIC
  134. } papersize_unit_t;
  135.  
  136. typedef struct
  137. {
  138.   char name[32];
  139.   unsigned width;
  140.   unsigned length;
  141.   papersize_unit_t paper_unit;
  142. } papersize_t;
  143.  
  144. /*
  145.  * Abstract data type for interfacing with the image creation program
  146.  * (in this case, the Gimp).
  147.  */
  148. typedef void *Image;
  149.  
  150. /* For how to create an Image wrapping a Gimp drawable, see print_gimp.h */
  151.  
  152. extern void Image_init(Image image);
  153. extern void Image_reset(Image image);
  154. extern void Image_transpose(Image image);
  155. extern void Image_hflip(Image image);
  156. extern void Image_vflip(Image image);
  157. extern void Image_crop(Image image, int left, int top, int right, int bottom);
  158. extern void Image_rotate_ccw(Image image);
  159. extern void Image_rotate_cw(Image image);
  160. extern void Image_rotate_180(Image image);
  161. extern int  Image_bpp(Image image);
  162. extern int  Image_width(Image image);
  163. extern int  Image_height(Image image);
  164. extern void Image_get_row(Image image, unsigned char *data, int row);
  165.  
  166. extern const char *Image_get_appname(Image image);
  167. extern void Image_progress_init(Image image);
  168. extern void Image_note_progress(Image image, double current, double total);
  169. extern void Image_progress_conclude(Image image);
  170.  
  171.  
  172. typedef struct printer
  173. {
  174.   char    *long_name,            /* Long name for UI */
  175.     *driver;            /* Short name for printrc file */
  176.   int    model;                /* Model number */
  177.   char    **(*parameters)(const struct printer *printer, char *ppd_file,
  178.                         char *name, int *count);
  179.                     /* Parameter names */
  180.   void    (*media_size)(const struct printer *printer, const vars_t *v,
  181.               int *width, int *length);
  182.   void    (*imageable_area)(const struct printer *printer, const vars_t *v,
  183.                           int *left, int *right, int *bottom, int *top);
  184.   void    (*limit)(const struct printer *printer, const vars_t *v,
  185.          int *width, int *length);
  186.   /* Print function */
  187.   void    (*print)(const struct printer *printer, int copies, FILE *prn,
  188.          Image image, const vars_t *v);
  189.   const char *(*default_resolution)(const struct printer *printer);
  190.   vars_t printvars;
  191. } printer_t;
  192.  
  193. typedef void (*convert_t)(unsigned char *in, unsigned short *out, int width,
  194.               int bpp, unsigned char *cmap, const vars_t *vars);
  195.  
  196. typedef struct
  197. {
  198.   double value;
  199.   unsigned bit_pattern;
  200.   int is_dark;
  201.   unsigned dot_size;
  202. } simple_dither_range_t;
  203.  
  204. typedef struct
  205. {
  206.   double value;
  207.   double lower;
  208.   double upper;
  209.   unsigned bit_pattern;
  210.   int is_dark;
  211.   unsigned dot_size;
  212. } dither_range_t;
  213.  
  214. typedef struct
  215. {
  216.    double value_l;
  217.    double value_h;
  218.    unsigned bits_l;
  219.    unsigned bits_h;
  220.    int isdark_l;
  221.    int isdark_h;
  222. } full_dither_range_t;
  223.  
  224. /*
  225.  * Prototypes...
  226.  */
  227.  
  228. extern void *    init_dither(int in_width, int out_width, int horizontal_aspect,
  229.                 int vertical_aspect, vars_t *vars);
  230. extern void    dither_set_transition(void *vd, double);
  231. extern void    dither_set_density(void *vd, double);
  232. extern void     dither_set_black_lower(void *vd, double);
  233. extern void     dither_set_black_upper(void *vd, double);
  234. extern void    dither_set_black_levels(void *vd, double, double, double);
  235. extern void     dither_set_randomizers(void *vd, double, double, double, double);
  236. extern void     dither_set_ink_darkness(void *vd, double, double, double);
  237. extern void     dither_set_light_inks(void *vd, double, double, double, double);
  238. extern void    dither_set_c_ranges(void *vd, int nlevels,
  239.                     const simple_dither_range_t *ranges,
  240.                     double density);
  241. extern void    dither_set_m_ranges(void *vd, int nlevels,
  242.                     const simple_dither_range_t *ranges,
  243.                     double density);
  244. extern void    dither_set_y_ranges(void *vd, int nlevels,
  245.                     const simple_dither_range_t *ranges,
  246.                     double density);
  247. extern void    dither_set_k_ranges(void *vd, int nlevels,
  248.                     const simple_dither_range_t *ranges,
  249.                     double density);
  250. extern void    dither_set_k_ranges_full(void *vd, int nlevels,
  251.                      const full_dither_range_t *ranges,
  252.                      double density);
  253. extern void    dither_set_c_ranges_full(void *vd, int nlevels,
  254.                      const full_dither_range_t *ranges,
  255.                      double density);
  256. extern void    dither_set_m_ranges_full(void *vd, int nlevels,
  257.                      const full_dither_range_t *ranges,
  258.                      double density);
  259. extern void    dither_set_y_ranges_full(void *vd, int nlevels,
  260.                      const full_dither_range_t *ranges,
  261.                      double density);
  262. extern void    dither_set_c_ranges_simple(void *vd, int nlevels,
  263.                        const double *levels, double density);
  264. extern void    dither_set_m_ranges_simple(void *vd, int nlevels,
  265.                        const double *levels, double density);
  266. extern void    dither_set_y_ranges_simple(void *vd, int nlevels,
  267.                        const double *levels, double density);
  268. extern void    dither_set_k_ranges_simple(void *vd, int nlevels,
  269.                        const double *levels, double density);
  270. extern void    dither_set_c_ranges_complete(void *vd, int nlevels,
  271.                          const dither_range_t *ranges);
  272. extern void    dither_set_m_ranges_complete(void *vd, int nlevels,
  273.                          const dither_range_t *ranges);
  274. extern void    dither_set_y_ranges_complete(void *vd, int nlevels,
  275.                          const dither_range_t *ranges);
  276. extern void    dither_set_k_ranges_complete(void *vd, int nlevels,
  277.                          const dither_range_t *ranges);
  278. extern void    dither_set_ink_spread(void *vd, int spread);
  279. extern void    dither_set_max_ink(void *vd, int, double);
  280. extern void    dither_set_x_oversample(void *vd, int os);
  281. extern void    dither_set_y_oversample(void *vd, int os);
  282. extern void    dither_set_adaptive_divisor(void *vd, unsigned divisor);
  283.  
  284.  
  285. extern void    free_dither(void *);
  286.  
  287.  
  288. extern void *    initialize_weave_params(int S, int J, int O,
  289.                                 int firstrow, int lastrow,
  290.                                 int pagelength, int strategy);
  291. extern void    calculate_row_parameters(void *w, int row, int subpass,
  292.                                  int *pass, int *jet, int *startrow,
  293.                      int *phantomrows, int *jetsused);
  294. extern void    destroy_weave_params(void *vw);
  295.  
  296.  
  297. extern void    dither_monochrome(const unsigned short *, int, void *,
  298.                  unsigned char *, int duplicate_line);
  299.  
  300. extern void    dither_black(const unsigned short *, int, void *,
  301.                  unsigned char *, int duplicate_line);
  302.  
  303. extern void    dither_cmyk(const unsigned short *, int, void *,
  304.                 unsigned char *,
  305.                 unsigned char *, unsigned char *,
  306.                 unsigned char *, unsigned char *,
  307.                 unsigned char *, unsigned char *,
  308.                 int duplicate_line);
  309.  
  310. extern void    merge_printvars(vars_t *user, const vars_t *print);
  311. extern void    free_lut(vars_t *v);
  312. extern void    compute_lut(size_t steps, vars_t *v);
  313.  
  314.  
  315. extern void    default_media_size(const printer_t *printer, const vars_t *v,
  316.                    int *width, int *length);
  317.  
  318.  
  319. extern char    **escp2_parameters(const printer_t *printer, char *ppd_file,
  320.                    char *name, int *count);
  321. extern void    escp2_imageable_area(const printer_t *printer, const vars_t *v,
  322.                      int *left, int *right,
  323.                      int *bottom, int *top);
  324. extern void    escp2_limit(const printer_t *printer, const vars_t *v,
  325.                 int *width, int *length);
  326. extern void    escp2_print(const printer_t *printer, int copies, FILE *prn,
  327.                 Image image, const vars_t *v);
  328. extern const char *escp2_default_resolution(const printer_t *printer);
  329.  
  330.  
  331. extern char    **canon_parameters(const printer_t *printer, char *ppd_file,
  332.                            char *name, int *count);
  333. extern void    canon_imageable_area(const printer_t *printer, const vars_t *v,
  334.                      int *left, int *right,
  335.                      int *bottom, int *top);
  336. extern void    canon_limit(const printer_t *printer, const vars_t *v,
  337.                 int *width, int *length);
  338. extern void    canon_print(const printer_t *printer, int copies, FILE *prn,
  339.                 Image image, const vars_t *v);
  340. extern const char *canon_default_resolution(const printer_t *printer);
  341.  
  342.  
  343. extern char    **pcl_parameters(const printer_t *printer, char *ppd_file,
  344.                          char *name, int *count);
  345. extern void    pcl_imageable_area(const printer_t *printer, const vars_t *v,
  346.                            int *left, int *right,
  347.                    int *bottom, int *top);
  348. extern void    pcl_limit(const printer_t *printer, const vars_t *v,
  349.               int *width, int *length);
  350. extern void    pcl_print(const printer_t *printer, int copies, FILE *prn,
  351.               Image image, const vars_t *v);
  352. extern const char *pcl_default_resolution(const printer_t *printer);
  353.  
  354.  
  355. extern char    **ps_parameters(const printer_t *printer, char *ppd_file,
  356.                         char *name, int *count);
  357. extern void    ps_media_size(const printer_t *printer, const vars_t *v,
  358.                   int *width, int *length);
  359. extern void    ps_imageable_area(const printer_t *printer, const vars_t *v,
  360.                   int *left, int *right,
  361.                           int *bottom, int *top);
  362. extern void    ps_limit(const printer_t *printer, const vars_t *v,
  363.              int *width, int *length);
  364. extern void    ps_print(const printer_t *printer, int copies, FILE *prn,
  365.              Image image, const vars_t *v);
  366. extern const char *ps_default_resolution(const printer_t *printer);
  367.  
  368. extern const char *default_dither_algorithm(void);
  369.  
  370. extern int                  known_papersizes(void);
  371. extern const papersize_t    *get_papersizes(void);
  372. extern const papersize_t    *get_papersize_by_name(const char *);
  373. extern const papersize_t     *get_papersize_by_size(int l, int w);
  374.  
  375. extern int            known_printers(void);
  376. extern const printer_t        *get_printers(void);
  377. extern const printer_t        *get_printer_by_index(int);
  378. extern const printer_t        *get_printer_by_long_name(const char *);
  379. extern const printer_t        *get_printer_by_driver(const char *);
  380. extern int            get_printer_index_by_driver(const char *);
  381.  
  382. extern int            num_dither_algos;
  383. extern char            *dither_algo_names[];
  384. extern convert_t choose_colorfunc(int, int, const unsigned char *, int *,
  385.                   const vars_t *);
  386. extern void
  387. compute_page_parameters(int page_right, int page_left, int page_top,
  388.             int page_bottom, double scaling, int image_width,
  389.             int image_height, Image image, int *orientation,
  390.             int *page_width, int *page_height, int *out_width,
  391.             int *out_height, int *left, int *top);
  392.  
  393. extern int
  394. verify_printer_params(const printer_t *, const vars_t *);
  395. extern const vars_t *print_default_settings(void);
  396. extern const vars_t *print_maximum_settings(void);
  397. extern const vars_t *print_minimum_settings(void);
  398.  
  399. #ifdef QUANTIFY
  400. /* Used for performance analysis - to be called before and after
  401.  * the interval to be quantified */
  402. #define NUM_QUANTIFY_BUCKETS 1024
  403. extern unsigned quantify_counts[NUM_QUANTIFY_BUCKETS];
  404. extern struct timeval quantify_buckets[NUM_QUANTIFY_BUCKETS];
  405. extern int quantify_high_index;
  406. extern int quantify_first_time;
  407. extern struct timeval quantify_cur_time;
  408. extern struct timeval quantify_prev_time;
  409.  
  410. #define QUANT(number) \
  411. {\
  412.     gettimeofday(&quantify_cur_time, NULL);\
  413.     assert(number < NUM_QUANTIFY_BUCKETS);\
  414.     quantify_counts[number]++;\
  415. \
  416.     if (quantify_first_time) {\
  417.         quantify_first_time = 0;\
  418.     } else {\
  419.         if (number > quantify_high_index) quantify_high_index = number;\
  420.         if (quantify_prev_time.tv_usec > quantify_cur_time.tv_usec) {\
  421.            quantify_buckets[number].tv_usec += ((quantify_cur_time.tv_usec + 1000000) - quantify_prev_time.tv_usec);\
  422.            quantify_buckets[number].tv_sec += (quantify_cur_time.tv_sec - quantify_prev_time.tv_sec - 1);\
  423.         } else {\
  424.            quantify_buckets[number].tv_sec += quantify_cur_time.tv_sec - quantify_prev_time.tv_sec;\
  425.            quantify_buckets[number].tv_usec += quantify_cur_time.tv_usec - quantify_prev_time.tv_usec;\
  426.         }\
  427.         if (quantify_buckets[number].tv_usec >= 1000000)\
  428.         {\
  429.            quantify_buckets[number].tv_usec -= 1000000;\
  430.            quantify_buckets[number].tv_sec++;\
  431.         }\
  432.     }\
  433. \
  434.     gettimeofday(&quantify_prev_time, NULL);\
  435. }
  436.  
  437. extern void  print_timers(void );
  438. #endif
  439.  
  440. #endif /* PRINT_HEADER */
  441. /*
  442.  * End of "$Id: print.h,v 1.15 2000/10/04 01:47:59 mitch Exp $".
  443.  */
  444.