• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  * Copyright (C) 2016 Mopria Alliance, Inc.
4  * Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __LIB_PCL_H__
20 #define __LIB_PCL_H__
21 
22 #include "ifc_print_job.h"
23 #include "ifc_wprint.h"
24 #include "lib_wprint.h"
25 #include "lib_pclm.h"
26 #include "common_defines.h"
27 
28 #define _WJOBH_NONE  0
29 #define STANDARD_SCALE_FOR_PDF    72.0
30 
31 #define SP_GRAY(Yr, Cbg, Crb) (((Yr<<6) + (Cbg*160) + (Crb<<5)) >> 8)
32 
33 #define _START_JOB(JOB_INFO, EXT) \
34 { \
35     const ifc_wprint_debug_stream_t* debug_ifc = \
36         JOB_INFO->wprint_ifc->get_debug_stream_ifc(JOB_INFO->job_handle); \
37     if (debug_ifc) { \
38         debug_ifc->debug_start_job(JOB_INFO->job_handle, EXT); \
39     } \
40 }
41 
42 #define _START_PAGE(JOB_INFO, WIDTH, HEIGHT) \
43 { \
44     const ifc_wprint_debug_stream_t* debug_ifc = \
45         JOB_INFO->wprint_ifc->get_debug_stream_ifc(JOB_INFO->job_handle); \
46     if (debug_ifc) { \
47         debug_ifc->debug_start_page(JOB_INFO->job_handle, JOB_INFO->page_number + 1, WIDTH, \
48             HEIGHT); \
49     } \
50 }
51 
52 #define _PAGE_DATA(JOB_INFO, BUFF, LEN) \
53 { \
54     const ifc_wprint_debug_stream_t* debug_ifc = \
55         JOB_INFO->wprint_ifc->get_debug_stream_ifc(JOB_INFO->job_handle); \
56     if (debug_ifc) { \
57         debug_ifc->debug_page_data(JOB_INFO->job_handle, BUFF, LEN); \
58     } \
59 }
60 
61 #define _END_PAGE(JOB_INFO) \
62 { \
63     const ifc_wprint_debug_stream_t* debug_ifc = \
64         JOB_INFO->wprint_ifc->get_debug_stream_ifc(JOB_INFO->job_handle); \
65     if (debug_ifc) { \
66         debug_ifc->debug_end_page(JOB_INFO->job_handle); \
67     } \
68 }
69 
70 #define _END_JOB(JOB_INFO) \
71 { \
72     const ifc_wprint_debug_stream_t* debug_ifc = \
73         JOB_INFO->wprint_ifc->get_debug_stream_ifc(JOB_INFO->job_handle); \
74     if (debug_ifc) { \
75         debug_ifc->debug_end_job(JOB_INFO->job_handle); \
76     } \
77 }
78 
79 #define _WRITE(JOB_INFO, BUFF, LEN)   \
80 { \
81     const ifc_wprint_debug_stream_t* debug_ifc = \
82         JOB_INFO->wprint_ifc->get_debug_stream_ifc(JOB_INFO->job_handle); \
83     if (debug_ifc) { \
84         debug_ifc->debug_job_data(JOB_INFO->job_handle, (const unsigned char *)BUFF, LEN); \
85     } \
86     JOB_INFO->print_ifc->send_data(JOB_INFO->print_ifc, BUFF, LEN); \
87 }
88 
89 /*
90  * PCL/PWG job definition
91  */
92 typedef struct {
93     const ifc_wprint_t *wprint_ifc;
94     const ifc_print_job_t *print_ifc;
95 
96     wJob_t job_handle;
97     uint8 *seed_row, *pcl_buff;
98     uint8 *halftone_row;
99     sint16 *error_buf;
100     int pixel_width, pixel_height;
101     media_size_t media_size;
102     int resolution;
103     int page_number, num_rows;
104     int send_full_row;
105     int rows_to_skip;
106     uint8 monochrome;
107 
108     int num_components;
109     int scan_line_width;
110     float standard_scale;
111     int strip_height;
112     int pclm_scan_line_width;
113 
114     void *pclmgen_obj;
115     PCLmPageSetup pclm_page_info;
116     uint8 *pclm_output_buffer;
117     const char *useragent;
118 } pcl_job_info_t;
119 
120 /*
121  * Interface for PCL and PWG job handling
122  */
123 typedef struct ifc_pcl_st {
124     /*
125      * Called once per job at the start of the job. Returns a print job handle that is used
126      * in other functions of this library. Returns WPRINT_BAD_JOB_HANDLE for errors.
127      */
128     wJob_t (*start_job)(wJob_t job_handle, pcl_job_info_t *job_info, media_size_t media_size,
129             media_type_t media_type, int resolution, duplex_t duplex,
130             duplex_dry_time_t dry_time, color_space_t color_space, media_tray_t media_tray,
131             float top_margin, float left_margin);
132 
133     /*
134      * Called once per job at the end of the job. A current print job
135      * must end for the next one to start. Returns OK or ERROR as the case maybe.
136      */
137     status_t (*end_job)(pcl_job_info_t *job_info);
138 
139     /*
140      * Called once per page of the job to indicate start of the page and page metrics.
141      * Returns running page number starting with 1 or ERROR.
142      */
143     status_t (*start_page)(pcl_job_info_t *job_info,
144             int pixel_width,
145             int pixel_height);
146 
147     /*
148      * Called once per page of the job to indicate end of the page. Returns OK or ERROR.
149      */
150     status_t (*end_page)(pcl_job_info_t *job_info,
151             int page_number);
152 
153     /*
154      * Called several times a page to send a rectangular swath of RGB data. The array
155      * rgb_pixels[] must have (num_rows * pixel_width) pixels. bytes_per_row can be used for
156      * 32-bit aligned rows. Returns OK or ERROR.
157      */
158     status_t (*print_swath)(pcl_job_info_t *job_info, char *rgb_pixels, int start_row, int num_rows,
159             int bytes_per_row);
160 
161     /*
162      * Return true if this interface can cancel a job partway through a page
163      */
164     bool (*canCancelMidPage)(void);
165 } ifc_pcl_t;
166 
167 /*
168  * Connect to the PCLm plugin, returning its interface
169  */
170 ifc_pcl_t *pclm_connect(void);
171 
172 /*
173  * Connect to the pwg plugin, returning its interface
174  */
175 ifc_pcl_t *pwg_connect(void);
176 
177 #endif // __LIB_PCL_H__