gdevcd8-beta4.c

来自「printer driver for the HP670, HP690, HP8」· C语言 代码 · 共 1,806 行 · 第 1/5 页

C
1,806
字号
216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226,
226, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236,
236, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244,
245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251,
251, 252, 252, 253, 253, 253, 254, 254, 254, 254, 255, 255, 255, 255},

/* Lookup values for black */
/* gamma 3.3 */

{0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7,
8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14,
14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20,
21, 21, 21, 22, 22, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 26, 27, 27,
27, 28, 28, 29, 29, 29, 30, 30, 31, 31, 32, 32, 32, 33, 33, 34, 34, 34,
35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, 41, 42, 42,
43, 43, 44, 44, 45, 45, 46, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51,
52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 58, 58, 59, 60, 60, 61,
61, 62, 62, 63, 64, 64, 65, 65, 66, 67, 67, 68, 68, 69, 70, 70, 71, 72,
72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 80, 80, 81, 82, 83, 83, 84,
85, 86, 86, 87, 88, 89, 90, 91, 91, 92, 93, 94, 95, 96, 97, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, 114,
115, 117, 118, 119, 120, 122, 123, 124, 126, 127, 129, 130, 132, 134,
135, 137, 139, 141, 143, 145, 147, 149, 152, 154, 157, 159, 162, 166,
169, 173, 178, 183, 189, 196, 207, 255},
};

private const Gamma * const gammat[] =
{
    &gammat850,			/* CDJ670 */
    &gammat850,			/* CDJ850 */
    &gammat890,			/* CDJ890 */
    &gammat850			/* CDJ1600 */
};

private int
    rescale_byte_wise1x1(P4(int bytecount, const byte * inbytea,
			    const byte * inbyteb, byte * outbyte));
private int
    rescale_byte_wise2x1(P4(int bytecount, const byte * inbytea,
			    const byte * inbyteb, byte * outbyte));
private int
    rescale_byte_wise1x2(P4(int bytecount, const byte * inbytea,
			    const byte * inbyteb, byte * outbyte));
private int
    rescale_byte_wise2x2(P4(int bytecount, const byte * inbytea,
			    const byte * inbyteb, byte * outbyte));

private int (* const rescale_color_plane[2][2]) (P4(int, const byte *, const byte *, byte *)) = {
    {
	rescale_byte_wise1x1, rescale_byte_wise1x2
    },
    {
	rescale_byte_wise2x1, rescale_byte_wise2x2
    }
};

/*
 * Drivers stuff.
 *
 */
#define DESKJET_PRINT_LIMIT  0.04	/* 'real' top margin? */
/* Margins are left, bottom, right, top. */
#define DESKJET_MARGINS_LETTER   0.25, 0.50, 0.25, 0.167
#define DESKJET_MARGINS_A4       0.13, 0.46, 0.13, 0.04
/* Define bits-per-pixel - default is 32-bit cmyk-mode */
#ifndef BITSPERPIXEL
#  define BITSPERPIXEL 32
#endif
#define DOFFSET (dev_t_margin(pdev) - DESKJET_PRINT_LIMIT)	/* Print position */


#define W sizeof(word)
#define I sizeof(int)

/* paper types */
typedef enum {
    PLAIN_PAPER, BOND_PAPER, SPECIAL_PAPER, GLOSSY_FILM, TRANSPARENCY_FILM
} cdj_paper_type_t;

/* quality */
typedef enum {
    DRAFT = -1, NORMAL = 0, PRESENTATION = 1
} cdj_quality_t;

/* Printer types */
typedef enum {
    DJ670C, DJ850C, DJ890C, DJ1600C
} cdj_printer_type_t;

/* No. of ink jets (used to minimise head movements) */
#define HEAD_ROWS_MONO 50
#define HEAD_ROWS_COLOUR 16

/* Colour mapping procedures */
private dev_proc_map_cmyk_color(gdev_cmyk_map_cmyk_color);
private dev_proc_map_rgb_color(gdev_cmyk_map_rgb_color);
private dev_proc_map_color_rgb(gdev_cmyk_map_color_rgb);

private dev_proc_map_rgb_color(gdev_pcl_map_rgb_color);
private dev_proc_map_color_rgb(gdev_pcl_map_color_rgb);

/* Print-page, parameters and miscellaneous procedures */
private dev_proc_open_device(hp_colour_open);

private dev_proc_get_params(cdj850_get_params);
private dev_proc_put_params(cdj850_put_params);

private dev_proc_print_page(cdj850_print_page);

/* The device descriptors */

/* The basic structure for all printers. Note the presence of the cmyk, depth
   and correct fields even if some are not used by all printers. */

#define prn_colour_device_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page, cmyk, correct)\
    prn_device_body(dtype, procs, dname, w10, h10, xdpi, ydpi, lm, bm, rm, tm, ncomp, depth, mg, mc, dg, dc, print_page), cmyk, depth /* default */, correct



#define gx_prn_colour_device_common \
    gx_prn_device_common; \
    int cmyk;	  	/* 0: not CMYK-capable, > 0: printing CMYK, */ \
		  	/* < 0 : CMYK-capable, not printing CMYK */ \
    uint default_depth;	/* Used only for CMYK-capable printers now. */ \
    uint correction


/* some definitions needed later */
struct error_val_field {
    int c;		/* Current value of Cyan error during dithering */
    int m;		/* Current value of Magenta error during dithering */
    int y;		/* Current value of Yellow error during dithering */
    int k;		/* Current value of Black error during dithering */
};

/* this structure holds all the pointers to the different values
   in all those data fields */
 /*
    * The principal data pointers are stored as pairs of values, with
    * the selection being made by the 'scan' variable. The function of the
    * scan variable is overloaded, as it controls both the alternating
    * raster scan direction used in the Floyd-Steinberg dithering and also
    * the buffer alternation required for line-difference compression.
    *
    * Thus, the number of pointers required is as follows:
  */

struct ptr_arrays {
    byte *data[4];		/* 4 600dpi data, scan direction and alternating buffers */
    byte *data_c[4];		/* 4 300dpi data, as above, */
    byte *plane_data[4][4];	/*4 b/w-planes, scan direction and alternating buffers */
    byte *plane_data_c[4][8];	/* as above, but for 8 planes */
    byte *out_data;		/* output buffer for the b/w data, one 600dpi plane */
    byte *test_data[4];		/* holds a copy of the last plane */
    int *errors[2];		/* 2 b/w dithering erros (scan direction only) */
    int *errors_c[2];		/* 2 color dithering errors (scan direction only) */
    word *storage;		/* pointer to the beginning of the b/w-buffer */
    word *storage_start;	/* used for debugging */
    word *storage_end;		/* used for debugging */
    word *storage_size;		/* used for debugging */
};

/* Some miscellaneous variables */
struct misc_struct {
    int line_size;		/* size of scan_line */
    int line_size_c;		/* size of rescaled scan_line */
    int line_size_words;	/* size of scan_line in words */
    int paper_size;		/* size of paper */
    int num_comps;		/* number of color components (1 - 4) */
    int bits_per_pixel;		/* bits per pixel 1,4,8,16,24,32 */
    int storage_bpp;		/* = bits_per_pixel */
    int expanded_bpp;		/* = bits_per_pixel */
    int plane_size;		/* size of b/w bit plane */
    int plane_size_c;		/* size of color bit plane */
    int databuff_size;		/* size of databuffer for b/w data */
    int databuff_size_c;	/* size of databuffer for color data */
    int errbuff_size;		/* size of error buffer b/w -data */
    int errbuff_size_c;		/* size of error buffer color -data */
    int outbuff_size;		/* size of output buffer for b/w data */
    int scan;			/* scan-line variable [0,1] */
    int cscan;			/* dito for the color-planes */
    int is_two_pass;		/* checks if b/w data has already been printed */
    int zero_row_count;		/* How many empty lines */
    uint storage_size_words;	/* size of storage in words for b/w data */
    uint storage_size_words_c;	/* size of storage in words for c-data */
    int is_color_data;		/* indicates whether there is color data */
};

    /* function pointer typedefs for device driver struct */
typedef void (*StartRasterMode) (P3(gx_device_printer * pdev, int paper_size,
				    FILE * prn_stream));
typedef void (*PrintNonBlankLines) (P6(gx_device_printer * pdev,
				       struct ptr_arrays *data_ptrs,
				       struct misc_struct *misc_vars,
				       struct error_val_field *error_values,
				       const Gamma *gamma,
				       FILE * prn_stream));

typedef void (*TerminatePage) (P2(gx_device_printer * pdev, FILE * prn_stream));

typedef struct gx_device_cdj850_s {
    gx_device_common;
    gx_prn_colour_device_common;
    int /*cdj_quality_t*/ quality;  /* -1 draft, 0 normal, 1 best */
    int /*cdj_paper_type_t*/ papertype;  /* papertype [0,4] */
    int intensities;		/* intensity values per pixel [2,4] */
    int xscal;			/* boolean to indicate x scaling by 2 */
    int yscal;			/* boolean to indicate y scaling by 2 */
    int /*cdj_printer_type_t*/ ptype;  /* printer type, one of DJ670C, DJ850C, DJ890C, DJ1600C */
    int compression;		/* compression level */
    float mastergamma;		/* Gammavalue applied to all colors */
    float gammavalc;		/* range to which gamma-correction is
				   applied to bw values */
    float gammavalm;		/* amount of gamma correction for bw */
    float gammavaly;		/* range to which gamma-correction i
				   applied to color values */
    float gammavalk;		/* amount of gamma correction for color */
    float blackcorrect;		/* amount of gamma correction for color */
    StartRasterMode start_raster_mode;	/* output function to start raster mode */
    PrintNonBlankLines print_non_blank_lines;	/* output function to print a non blank line */
    TerminatePage terminate_page;	/* page termination output function */
} gx_device_cdj850;

typedef struct {
    gx_device_common;
    gx_prn_colour_device_common;
} gx_device_colour_prn;


/* Use the cprn_device macro to access generic fields (like cmyk,
   default_depth and correction), and specific macros for specific
   devices. */

#define cprn_device     ((gx_device_colour_prn*) pdev)
#define cdj850    ((gx_device_cdj850 *)pdev)

#define prn_cmyk_colour_device(dtype, procs, dev_name, x_dpi, y_dpi, bpp, print_page, correct)\
    prn_colour_device_body(dtype, procs, dev_name,\
    DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, x_dpi, y_dpi, 0, 0, 0, 0,\
    ((bpp == 1 || bpp == 4) ? 1 : 4), bpp,\
    (bpp > 8 ? 255 : 1), (1 << (bpp >> 2)) - 1, /* max_gray, max_color */\
    (bpp > 8 ? 5 : 2), (bpp > 8 ? 5 : bpp > 1 ? 2 : 0),\
    print_page, 1 /* cmyk */, correct)


#define prn_cmy_colour_device(dtype, procs, dev_name, x_dpi, y_dpi, bpp, print_page, correct)\
    prn_colour_device_body(dtype, procs, dev_name,\
    DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, x_dpi, y_dpi, 0, 0, 0, 0,\
    ((bpp == 1 || bpp == 4) ? 1 : 3), bpp,\
    (bpp > 8 ? 255 : 1), (bpp > 8 ? 255 : 1), /* max_gray, max_color */\
    (bpp > 8 ? 5 : 2), (bpp > 8 ? 5 : bpp > 1 ? 2 : 0),\
    print_page, -1 /* cmyk */, correct)


#define cdj_850_device(procs, dev_name, x_dpi, y_dpi, bpp, print_page, correction, quality, papertype, intensities,ptype,compression,mastergamma,gammavalc,gammavalm,gammavaly,gammavalk,blackcorrect,start_raster_mode,print_non_blank_line,terminate_page)\
{ prn_cmyk_colour_device(gx_device_cdj850, procs, dev_name, x_dpi, y_dpi, bpp, print_page, correction),\
    quality,\
    papertype,\
    intensities,\
    0, 0, /* xscal, yscal */\
    ptype,\
    compression,\
    mastergamma,\
    gammavalc,\
    gammavalm,\
    gammavaly,\
    gammavalk,\
    blackcorrect,\
    start_raster_mode,\
    print_non_blank_line,\
    terminate_page\
}

#define cdj_1600_device(procs, dev_name, x_dpi, y_dpi, bpp, print_page, correction, quality, papertype, intensities,ptype,compression,mastergamma,gammavalc,gammavalm,gammavaly,gammavalk,blackcorrect,start_raster_mode,print_non_blank_line,terminate_page)\
{ prn_cmy_colour_device(gx_device_cdj850, procs, dev_name, x_dpi, y_dpi, bpp, print_page, correction),\
    quality,\
    papertype,\
    intensities,\
    0, 0, /* xscal, yscal */\
    ptype,\
    compression,\
    mastergamma,\
    gammavalc,\
    gammavalm,\
    gammavaly,\
    gammavalk,\
    blackcorrect,\
    start_raster_mode,\
    print_non_blank_line,\
    terminate_page\
}

#define cmyk_colour_procs(proc_colour_open, proc_get_params, proc_put_params, \
			  map_rgb_color, map_color_rgb, map_cmyk_color) {\
	proc_colour_open,\
	gx_default_get_initial_matrix,\
	gx_default_sync_output,\
	gdev_prn_output_page,\
	gdev_prn_close,\
	map_rgb_color,\
	map_color_rgb,\
	NULL /* fill_rectangle */,\
	NULL /* tile_rectangle */,\
	NULL /* copy_mono */,\
	NULL /* copy_color */,\
	NULL /* draw_line */,\
	gx_default_get_bits,\
	proc_get_params,\
	proc_put_params,\
        map_cmyk_color\
}

private void
     cdj850_start_raster_mode(P3(gx_device_printer * pdev,
				 int papersize, FILE * prn_stream));

private void
     cdj850_print_non_blank_lines(P6(gx_device_printer * pdev,
				     struct ptr_arrays *data_ptrs,
				     struct misc_struct *misc_vars,
				     struct error_val_field *error_values,
				     const Gamma *gamma,
				     FILE * prn_stream));
private void
     cdj850_terminate_page(P2(gx_device_printer * pdev, FILE * prn_stream));

private void
     cdj1600_start_raster_mode(P3(gx_device_printer * pdev,
				  int papersize, FILE * prn_stream));
private void
     cdj1600_print_non_blank_lines(P6(gx_device_printer * pdev,
				      struct ptr_arrays *data_ptrs,
				      struct misc_struct *misc_vars,
				      struct error_val_field *error_values,
				      const Gamma *gamma,
				      FILE * prn_stream));
private void
     cdj1600_terminate_page(P2(gx_device_printer * pdev, FILE * prn_stream));



private const gx_device_procs cdj670_procs =
cmyk_colour_procs(hp_colour_open, cdj850_get_params, cdj850_put_params,
		  NULL, gdev_cmyk_map_color_rgb, gdev_cmyk_map_cmyk_color);

private const gx_device_procs cdj850_procs =
cmyk_colour_procs(hp_colour_open, cdj850_get_params, cdj850_put_params,
		  NULL, gdev_cmyk_map_color_rgb, gdev_cmyk_map_cmyk_color);

private const gx_device_procs cdj890_procs =
cmyk_colour_procs(hp_colour_open, cdj850_get_params, cdj850_put_params,
		  NULL, gdev_cmyk_map_color_rgb, gdev_cmyk_map_cmyk_color);

private const gx_device_procs cdj1600_procs =
cmyk_colour_procs(hp_colour_open, cdj850_get_params, cdj850_put_params,
		  gdev_pcl_map_rgb_color, gdev_pcl_map_color_rgb, NULL);

const gx_device_cdj850 gs_cdj670_device =
cdj_850_device(cdj670_procs, "cdj670", 600, 600, 32, cdj850_print_page, 0,
	       PRESENTATION, PLAIN_PAPER, 2, DJ670C, 9,
	       1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
	       cdj850_start_raster_mode, cdj850_print_non_blank_lines,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?