summaryrefslogtreecommitdiff
path: root/prnt/hpcups
diff options
context:
space:
mode:
Diffstat (limited to 'prnt/hpcups')
-rw-r--r--prnt/hpcups/CommonDefinitions.h930
-rw-r--r--prnt/hpcups/Encapsulator.cpp7
-rw-r--r--prnt/hpcups/Encapsulator.h1
-rw-r--r--prnt/hpcups/HPCupsFilter.cpp1691
-rw-r--r--prnt/hpcups/HPCupsFilter.h247
-rw-r--r--prnt/hpcups/Job.cpp7
-rw-r--r--prnt/hpcups/Job.h1
-rw-r--r--prnt/hpcups/LJZjStream.cpp178
-rw-r--r--prnt/hpcups/LJZjStream.h1
-rw-r--r--prnt/hpcups/dbuscomm.cpp143
-rw-r--r--prnt/hpcups/dbuscomm.h81
11 files changed, 1876 insertions, 1411 deletions
diff --git a/prnt/hpcups/CommonDefinitions.h b/prnt/hpcups/CommonDefinitions.h
index 4f9e68414..cca7990d8 100644
--- a/prnt/hpcups/CommonDefinitions.h
+++ b/prnt/hpcups/CommonDefinitions.h
@@ -1,464 +1,466 @@
-/*****************************************************************************\
- CommonDefinitions.h : common header
-
- Copyright (c) 1996 - 2009, Hewlett-Packard Co.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Hewlett-Packard nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Author: Naga Samrat Chowdary Narla,
-\*****************************************************************************/
-
-#ifndef COMMON_DEFINITIONS_H
-#define COMMON_DEFINITIONS_H
-
-#include <stdio.h>
-#include <inttypes.h>
-#include <stdint.h>
-//#include <machine/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <cups/cups.h>
-#include <cups/raster.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <assert.h>
-#include <time.h>
-#include <sys/timeb.h>
-#include <string.h>
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#define BASIC_LOG 1
-#define SAVE_PCL_FILE 2
-#define SAVE_INPUT_RASTERS 4
-#define SEND_TO_PRINTER_ALSO 8
-
-#define MAX_COLORTYPE 2
-#define NUMBER_PLANES 3
-
-#define ASSERT assert
-
-#define _STRINGIZE(x) #x
-#define STRINGIZE(x) _STRINGIZE(x)
-
-#define dbglog(args...) {syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args); \
-fprintf(stderr, __FILE__ " " STRINGIZE(__LINE__) ": " args);}
-
-
-typedef unsigned char BYTE;
-
-#ifndef ABS
- #define ABS(x) ( ((x)<0) ? -(x) : (x) )
-#endif
-
-#ifndef MIN
- #define MIN(a,b) (((a)>=(b))?(b):(a))
-#endif
-
-#ifndef MAX
- #define MAX(a,b) (((a)<=(b))?(b):(a))
-#endif
-
-#ifdef APDK_LITTLE_ENDIAN
- #define GetRed(x) (((x >> 16) & 0x0FF))
- #define GetGreen(x) (((x >> 8) & 0x0FF))
- #define GetBlue(x) ((x & 0x0FF))
- #else
- #define GetRed(x) (((x >> 24) & 0x0FF))
- #define GetGreen(x) (((x >> 16) & 0x0FF))
- #define GetBlue(x) (((x >> 8) & 0x0FF))
- #endif
-
-#ifdef BLACK_PEN
- #undef BLACK_PEN
-#endif
-
-#ifdef NO_ERROR
- #undef NO_ERROR
-#endif
-
-#define HIBYTE(sVar) (BYTE) ((sVar & 0xFF00) >> 8)
-#define LOBYTE(sVar) (BYTE) ((sVar & 0x00FF))
-#ifndef LOWORD
- #define LOWORD(l) ((unsigned short) (l))
-#endif
-
-#ifndef HIWORD
- #define HIWORD(l) ((unsigned short) (((uint32_t) (l) >> 16) & 0xFFFF))
-#endif
-
-#define PCL_BUFFER_SIZE 10000
-
-typedef unsigned short UInt16;
-typedef unsigned long UInt32;
-typedef unsigned char UChar;
-typedef unsigned int Int16;
-typedef long Int32;
-
-typedef struct RASTERDATA
-{
- int rastersize[MAX_COLORTYPE];
- BYTE *rasterdata[MAX_COLORTYPE];
-} RASTERDATA;
-
-const int MAXCOLORDEPTH = 3;
-
-const int MAXCOLORPLANES = 6; // current max anticipated, 6 for 690 photopen
-
-const int MAXCOLORROWS = 2; // multiple of high-to-low for mixed-resolution cases
-
-enum HALFTONING_ALGORITHM
-{
- FED,
- MATRIX
-};
-
-/*
- * values of DRIVER_ERROR
- * Values < 0 are warnings
- */
-
-typedef enum
-{
-
-// general or system errors
- NO_ERROR = 0x00, //!< everything okay
- JOB_CANCELED = 0x01, //!< CANCEL chosen by user
- SYSTEM_ERROR = 0x02, //!< something bad that should not have happened
- ALLOCMEM_ERROR = 0x03, //!< failed to allocate memory
- NO_PRINTER_SELECTED = 0x04, //!< indicates improper calling sequence or unidi
- INDEX_OUT_OF_RANGE = 0x05, //!< what it says
- ILLEGAL_RESOLUTION = 0x06, //!< tried to set resolution at unacceptable value
- NULL_POINTER = 0x07, //!< supplied ptr was null
- MISSING_PENS = 0x08, //!< one or more printhead/pen missing
-
-// build-related
-// (items either absent from current build, or just bad index from client code)
- UNSUPPORTED_PRINTER = 0x10, //!< selected printer-type unsupported in build
- UNSUPPORTED_PEN = 0x11, //!< selected pen-type unsupported
- GRAPHICS_UNSUPPORTED = 0x13, //!< no graphics allowed in current build
- ILLEGAL_COORDS = 0x15, //!< bad (x,y) passed to TextOut
- BAD_INPUT_WIDTH = 0x18, //!< inputwidth is 0 and
- OUTPUTWIDTH_EXCEEDS_PAGEWIDTH = 0x19, //!< inputwidth exceeds printable width
- UNSUPPORTED_PRINTMODE = 0x19, //!< requested printmode not available
-
-// I/O related
- IO_ERROR = 0x20, //!< I/O error communicating with printer
- BAD_DEVICE_ID = 0x21, //!< bad or garbled device id from printer
- CONTINUE_FROM_BLOCK = 0x22, //!< continue from blocked state for printers with no buttons
-
-// Runtime related
- PLUGIN_LIBRARY_MISSING = 0x30, //!< a required plugin (dynamic) library is missing
-
-// WARNINGS
-// convention is that values < 0 can be ignored (at user's peril)
- WARN_MODE_MISMATCH = -1, //!< printmode selection incompatible with pen, tray, etc.
- WARN_DUPLEX = -2, //!< duplexer installed; our driver can't use it
- WARN_LOW_INK_BOTH_PENS= -3, //!< sensor says pens below threshold
- WARN_LOW_INK_BLACK = -4, //!< sensor says black pen below threshold
- WARN_LOW_INK_COLOR = -5, //!< sensor says color pen below threshold
-
- WARN_LOW_INK_PHOTO = -10, //!< sensor says photo pen below threshold
- WARN_LOW_INK_GREY = -11, //!< sensor says grey pen below threshold
- WARN_LOW_INK_BLACK_PHOTO = -12, //!< sensor says black and photo pens below threshold
- WARN_LOW_INK_COLOR_PHOTO = -13, //!< sensor says color and photo pens below threshold
- WARN_LOW_INK_GREY_PHOTO = -14, //!< sensor says grey and photo pens below threshold
- WARN_LOW_INK_COLOR_GREY = -15, //!< sensor says color and grey pens below threshold
- WARN_LOW_INK_COLOR_GREY_PHOTO = -16, //!< sensor says color, photo, and grey pens below threshold
- WARN_LOW_INK_COLOR_BLACK_PHOTO = -17, //!< sensor says color, photo, and black pens below threshold
- WARN_LOW_INK_CYAN = -18, //!< sensor says cyan ink below threshold
- WARN_LOW_INK_MAGENTA = -19, //!< sensor says magenta ink below threshold
- WARN_LOW_INK_YELLOW = -20, //!< sensor says yellow ink below threshold
- WARN_LOW_INK_MULTIPLE_PENS = - 21, //!< sensor says more than one pen below threshold
- WARN_ILLEGAL_PAPERSIZE = -8, //!< papersize illegal for given hardware
- ILLEGAL_PAPERSIZE = -8,
- WARN_INVALID_MEDIA_SOURCE = -9, //!< media source tray is invalid
-
- eCreate_Thread_Error = 128 //! Thread error creating the error....
-} DRIVER_ERROR; //DRIVER_ERROR
-
-enum DUPLEXMODE
-{
- DUPLEXMODE_NONE,
- DUPLEXMODE_BOOK,
- DUPLEXMODE_TABLET
-};
-
-enum ENDIAN_TYPE
-{
- LITTLEENDIAN,
- BIGENDIAN
-};
-
-// used to encourage consistent ordering of color planes
-#define PLANE_K 0
-#define PLANE_C 1
-#define PLANE_M 2
-#define PLANE_Y 3
-#define Clight 4
-#define Mlight 5
-#define kWhite 0x00FFFFFE
-
-#define K 0
-#define C 1
-#define M 2
-#define Y 3
-#define Clight 4
-#define Mlight 5
-#define RANDSEED 77
-
-/*
- * ZJStream related definitions
- */
-
-typedef uint32_t DWORD;
-typedef unsigned short WORD;
-typedef enum
-{
- ZJT_START_DOC,
- ZJT_END_DOC,
- ZJT_START_PAGE,
- ZJT_END_PAGE,
- ZJT_JBIG_BIH,
- ZJT_JBIG_HID,
- ZJT_END_JBIG,
- ZJT_SIGNATURE,
- ZJT_RAW_IMAGE,
- ZJT_START_PLANE,
- ZJT_END_PLANE,
- ZJT_PAUSE,
- ZJT_BITMAP
-} CHUNK_TYPE;
-
-typedef enum
-{
-/* 0x00*/ ZJI_PAGECOUNT,
-/* 0x01*/ ZJI_DMCOLLATE,
-/* 0x02*/ ZJI_DMDUPLEX,
-
-/* 0x03*/ ZJI_DMPAPER,
-/* 0x04*/ ZJI_DMCOPIES,
-/* 0x05*/ ZJI_DMDEFAULTSOURCE,
-/* 0x06*/ ZJI_DMMEDIATYPE,
-/* 0x07*/ ZJI_NBIE,
-/* 0x08*/ ZJI_RESOLUTION_X,
-/* 0x09*/ ZJI_RESOLUTION_Y,
-/* 0x0A */ ZJI_OFFSET_X,
-/* 0x0B */ ZJI_OFFSET_Y,
-/* 0x0C */ ZJI_RASTER_X,
-/* 0x0D */ ZJI_RASTER_Y,
-
-/* 0x0E */ ZJI_COLLATE,
-/* 0x0F */ ZJI_QUANTITY,
-
-/* 0x10 */ ZJI_VIDEO_BPP,
-/* 0x11 */ ZJI_VIDEO_X,
-/* 0x12 */ ZJI_VIDEO_Y,
-/* 0x13 */ ZJI_INTERLACE,
-/* 0x14 */ ZJI_PLANE,
-/* 0x15 */ ZJI_PALETTE,
-
-/* 0x16 */ ZJI_RET,
-/* 0x17 */ ZJI_TONER_SAVE,
-
-/* 0x18 */ ZJI_MEDIA_SIZE_X,
-/* 0x19 */ ZJI_MEDIA_SIZE_Y,
-/* 0x1A */ ZJI_MEDIA_SIZE_UNITS,
-
-/* 0x1B */ ZJI_CHROMATIC,
-
-/* 0x63 */ ZJI_PAD = 99,
-
-/* 0x64 */ ZJI_PROMPT,
-
-/* 0x65 */ ZJI_BITMAP_TYPE,
-/* 0x66 */ ZJI_ENCODING_DATA,
-/* 0x67 */ ZJI_END_PLANE,
-
-/* 0x68 */ ZJI_BITMAP_PIXELS,
-/* 0x69 */ ZJI_BITMAP_LINES,
-/* 0x6A */ ZJI_BITMAP_BPP,
-/* 0x6B */ ZJI_BITMAP_STRIDE,
-
-} ZJ_ITEM;
-
-typedef enum
-{
- RET_OFF = 0,
- RET_ON,
- RET_AUTO,
- RET_LIGHT,
- RET_MEDIUM,
- RET_DARK
-} RET_VALUE;
-
-typedef enum
-{
- ZJIT_UINT32 = 1,
- ZJIT_INT32,
- ZJIT_STRING,
- ZJIT_BYTELUT
-} CHUNK_ITEM_TYPE;
-
-// very frequently used fragments made into macros for readability
-#define CERRCHECK if (constructor_error != NO_ERROR) {dbglog("CERRCHECK fired\n"); return;}
-#define ERRCHECK if (err != NO_ERROR) {dbglog("ERRCHECK fired\n"); return err;}
-#define NEWCHECK(x) if (x==NULL) return ALLOCMEM_ERROR;
-#define CNEWCHECK(x) if (x==NULL) { constructor_error=ALLOCMEM_ERROR; return; }
-
-#define CUSTOM_MEDIA_SIZE 101
-
-enum COLORTYPE
-{
- COLORTYPE_COLOR, // 0
- COLORTYPE_BLACK, // 1
- COLORTYPE_BOTH
-};
-
-typedef struct ColorMap_s
-{
- uint32_t *ulMap1;
- uint32_t *ulMap2;
- unsigned char *ulMap3;
-} ColorMap;
-
-enum COMPRESS_MODE
-{
- COMPRESS_MODE0 = 0,
- COMPRESS_MODE2 = 2,
- COMPRESS_MODE9 = 9,
- COMPRESS_MODE_AUTO = 10,
- COMPRESS_MODE_JPEG = 11,
- COMPRESS_MODE_LJ = 12,
- COMPRESS_MODE_GRAFIT = 16
-};
-
-enum COMPRESSOR_TYPE
-{
- COMPRESSOR_JPEG_QUICKCONNECT,
- COMPRESSOR_JPEG_JETREADY,
- COMPRESSOR_TAOS
-};
-
-const int QTABLE_SIZE = 64;
-// jpeglib.h declares these as UINT16, which is defined as unsigned short in jmorecfg.h
-typedef struct QTableInfo_s
-{
- DWORD qtable0[QTABLE_SIZE];
- DWORD qtable1[QTABLE_SIZE];
- DWORD qtable2[QTABLE_SIZE];
- unsigned int qFactor;
-} QTableInfo;
-
-typedef struct PrintMode_s
-{
- const char *name;
-// The resolutions can be different for different planes
- unsigned int ResolutionX[MAXCOLORPLANES];
- unsigned int ResolutionY[MAXCOLORPLANES];
-
- unsigned int ColorDepth[MAXCOLORPLANES];
- unsigned int dyeCount; // number of inks in the pen(s)
-
- HALFTONING_ALGORITHM eHT;
-
- ColorMap cmap;
-
- unsigned int BaseResX,BaseResY;
- bool MixedRes;
-
- const unsigned char* BlackFEDTable;
- const unsigned char* ColorFEDTable;
-} PrintMode;
-
-typedef struct
-{
- const char *printer_platform_name;
- PrintMode *print_modes;
- int count;
-} PrintModeTable;
-
-typedef struct QualityAttributes_s
-{
- int media_type;
- int media_subtype;
- int print_quality;
- unsigned int horizontal_resolution;
- unsigned int vertical_resolution;
- unsigned int actual_vertical_resolution;
- char print_mode_name[32];
-} QualityAttributes;
-
-typedef struct MediaAttributes_s
-{
- int pcl_id;
- int physical_width;
- int physical_height;
- int printable_width;
- int printable_height;
- int printable_start_x;
- int printable_start_y;
- int horizontal_overspray;
- int vertical_overspray;
- int left_overspray;
- int top_overspray;
-} MediaAttributes;
-
-typedef struct JobAttributes_s
-{
- int media_source;
- int color_mode;
- DUPLEXMODE e_duplex_mode;
- int print_borderless;
- int krgb_mode;
- int mech_offset;
- QualityAttributes quality_attributes;
- MediaAttributes media_attributes;
- int job_id;
- int page_order;
- int total_pages;
- char job_title[128];
- char user_name[32];
- char host_name[32];
- char domain_name[32];
- char os_name[160];
- char driver_version[32];
- char driver_name[128];
- char printer_name[160];
- char job_start_time[32];
- char uuid[64];
- char printer_platform[32];
- char printer_language[32];
- int integer_values[16];
- int printer_platform_version;
-} JobAttributes;
-
-#endif // COMMON_DEFINITIONS_H
-
+/*****************************************************************************\
+ CommonDefinitions.h : common header
+
+ Copyright (c) 1996 - 2009, Hewlett-Packard Co.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of Hewlett-Packard nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ Author: Naga Samrat Chowdary Narla,
+\*****************************************************************************/
+
+#ifndef COMMON_DEFINITIONS_H
+#define COMMON_DEFINITIONS_H
+
+#include <stdio.h>
+#include <inttypes.h>
+#include <stdint.h>
+//#include <machine/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <cups/cups.h>
+#include <cups/raster.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <assert.h>
+#include <time.h>
+#include <sys/timeb.h>
+#include <string.h>
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#define BASIC_LOG 1
+#define SAVE_PCL_FILE 2
+#define SAVE_INPUT_RASTERS 4
+#define SEND_TO_PRINTER_ALSO 8
+
+#define MAX_COLORTYPE 2
+#define NUMBER_PLANES 3
+
+#define ASSERT assert
+
+#define _STRINGIZE(x) #x
+#define STRINGIZE(x) _STRINGIZE(x)
+
+#define dbglog(args...) {syslog(LOG_ERR, __FILE__ " " STRINGIZE(__LINE__) ": " args); \
+fprintf(stderr, __FILE__ " " STRINGIZE(__LINE__) ": " args);}
+
+
+typedef unsigned char BYTE;
+
+#ifndef ABS
+ #define ABS(x) ( ((x)<0) ? -(x) : (x) )
+#endif
+
+#ifndef MIN
+ #define MIN(a,b) (((a)>=(b))?(b):(a))
+#endif
+
+#ifndef MAX
+ #define MAX(a,b) (((a)<=(b))?(b):(a))
+#endif
+
+#ifdef APDK_LITTLE_ENDIAN
+ #define GetRed(x) (((x >> 16) & 0x0FF))
+ #define GetGreen(x) (((x >> 8) & 0x0FF))
+ #define GetBlue(x) ((x & 0x0FF))
+ #else
+ #define GetRed(x) (((x >> 24) & 0x0FF))
+ #define GetGreen(x) (((x >> 16) & 0x0FF))
+ #define GetBlue(x) (((x >> 8) & 0x0FF))
+ #endif
+
+#ifdef BLACK_PEN
+ #undef BLACK_PEN
+#endif
+
+#ifdef NO_ERROR
+ #undef NO_ERROR
+#endif
+
+#define HIBYTE(sVar) (BYTE) ((sVar & 0xFF00) >> 8)
+#define LOBYTE(sVar) (BYTE) ((sVar & 0x00FF))
+#ifndef LOWORD
+ #define LOWORD(l) ((unsigned short) (l))
+#endif
+
+#ifndef HIWORD
+ #define HIWORD(l) ((unsigned short) (((uint32_t) (l) >> 16) & 0xFFFF))
+#endif
+
+#define PCL_BUFFER_SIZE 10000
+
+typedef unsigned short UInt16;
+typedef unsigned long UInt32;
+typedef unsigned char UChar;
+typedef unsigned int Int16;
+typedef long Int32;
+
+typedef struct RASTERDATA
+{
+ int rastersize[MAX_COLORTYPE];
+ BYTE *rasterdata[MAX_COLORTYPE];
+} RASTERDATA;
+
+const int MAXCOLORDEPTH = 3;
+
+const int MAXCOLORPLANES = 6; // current max anticipated, 6 for 690 photopen
+
+const int MAXCOLORROWS = 2; // multiple of high-to-low for mixed-resolution cases
+
+enum HALFTONING_ALGORITHM
+{
+ FED,
+ MATRIX
+};
+
+/*
+ * values of DRIVER_ERROR
+ * Values < 0 are warnings
+ */
+
+typedef enum
+{
+
+// general or system errors
+ NO_ERROR = 0x00, //!< everything okay
+ JOB_CANCELED = 0x01, //!< CANCEL chosen by user
+ SYSTEM_ERROR = 0x02, //!< something bad that should not have happened
+ ALLOCMEM_ERROR = 0x03, //!< failed to allocate memory
+ NO_PRINTER_SELECTED = 0x04, //!< indicates improper calling sequence or unidi
+ INDEX_OUT_OF_RANGE = 0x05, //!< what it says
+ ILLEGAL_RESOLUTION = 0x06, //!< tried to set resolution at unacceptable value
+ NULL_POINTER = 0x07, //!< supplied ptr was null
+ MISSING_PENS = 0x08, //!< one or more printhead/pen missing
+
+// build-related
+// (items either absent from current build, or just bad index from client code)
+ UNSUPPORTED_PRINTER = 0x10, //!< selected printer-type unsupported in build
+ UNSUPPORTED_PEN = 0x11, //!< selected pen-type unsupported
+ GRAPHICS_UNSUPPORTED = 0x13, //!< no graphics allowed in current build
+ ILLEGAL_COORDS = 0x15, //!< bad (x,y) passed to TextOut
+ BAD_INPUT_WIDTH = 0x18, //!< inputwidth is 0 and
+ OUTPUTWIDTH_EXCEEDS_PAGEWIDTH = 0x19, //!< inputwidth exceeds printable width
+ UNSUPPORTED_PRINTMODE = 0x19, //!< requested printmode not available
+
+// I/O related
+ IO_ERROR = 0x20, //!< I/O error communicating with printer
+ BAD_DEVICE_ID = 0x21, //!< bad or garbled device id from printer
+ CONTINUE_FROM_BLOCK = 0x22, //!< continue from blocked state for printers with no buttons
+
+// Runtime related
+ PLUGIN_LIBRARY_MISSING = 0x30, //!< a required plugin (dynamic) library is missing
+
+// WARNINGS
+// convention is that values < 0 can be ignored (at user's peril)
+ WARN_MODE_MISMATCH = -1, //!< printmode selection incompatible with pen, tray, etc.
+ WARN_DUPLEX = -2, //!< duplexer installed; our driver can't use it
+ WARN_LOW_INK_BOTH_PENS= -3, //!< sensor says pens below threshold
+ WARN_LOW_INK_BLACK = -4, //!< sensor says black pen below threshold
+ WARN_LOW_INK_COLOR = -5, //!< sensor says color pen below threshold
+
+ WARN_LOW_INK_PHOTO = -10, //!< sensor says photo pen below threshold
+ WARN_LOW_INK_GREY = -11, //!< sensor says grey pen below threshold
+ WARN_LOW_INK_BLACK_PHOTO = -12, //!< sensor says black and photo pens below threshold
+ WARN_LOW_INK_COLOR_PHOTO = -13, //!< sensor says color and photo pens below threshold
+ WARN_LOW_INK_GREY_PHOTO = -14, //!< sensor says grey and photo pens below threshold
+ WARN_LOW_INK_COLOR_GREY = -15, //!< sensor says color and grey pens below threshold
+ WARN_LOW_INK_COLOR_GREY_PHOTO = -16, //!< sensor says color, photo, and grey pens below threshold
+ WARN_LOW_INK_COLOR_BLACK_PHOTO = -17, //!< sensor says color, photo, and black pens below threshold
+ WARN_LOW_INK_CYAN = -18, //!< sensor says cyan ink below threshold
+ WARN_LOW_INK_MAGENTA = -19, //!< sensor says magenta ink below threshold
+ WARN_LOW_INK_YELLOW = -20, //!< sensor says yellow ink below threshold
+ WARN_LOW_INK_MULTIPLE_PENS = - 21, //!< sensor says more than one pen below threshold
+ WARN_ILLEGAL_PAPERSIZE = -8, //!< papersize illegal for given hardware
+ ILLEGAL_PAPERSIZE = -8,
+ WARN_INVALID_MEDIA_SOURCE = -9, //!< media source tray is invalid
+
+ eCreate_Thread_Error = 128 //! Thread error creating the error....
+} DRIVER_ERROR; //DRIVER_ERROR
+
+enum DUPLEXMODE
+{
+ DUPLEXMODE_NONE,
+ DUPLEXMODE_BOOK,
+ DUPLEXMODE_TABLET
+};
+
+enum ENDIAN_TYPE
+{
+ LITTLEENDIAN,
+ BIGENDIAN
+};
+
+// used to encourage consistent ordering of color planes
+#define PLANE_K 0
+#define PLANE_C 1
+#define PLANE_M 2
+#define PLANE_Y 3
+#define Clight 4
+#define Mlight 5
+#define kWhite 0x00FFFFFE
+
+#define K 0
+#define C 1
+#define M 2
+#define Y 3
+#define Clight 4
+#define Mlight 5
+#define RANDSEED 77
+
+/*
+ * ZJStream related definitions
+ */
+
+typedef uint32_t DWORD;
+typedef unsigned short WORD;
+typedef enum
+{
+ ZJT_START_DOC,
+ ZJT_END_DOC,
+ ZJT_START_PAGE,
+ ZJT_END_PAGE,
+ ZJT_JBIG_BIH,
+ ZJT_JBIG_HID,
+ ZJT_END_JBIG,
+ ZJT_SIGNATURE,
+ ZJT_RAW_IMAGE,
+ ZJT_START_PLANE,
+ ZJT_END_PLANE,
+ ZJT_PAUSE,
+ ZJT_BITMAP
+} CHUNK_TYPE;
+
+typedef enum
+{
+/* 0x00*/ ZJI_PAGECOUNT,
+/* 0x01*/ ZJI_DMCOLLATE,
+/* 0x02*/ ZJI_DMDUPLEX,
+
+/* 0x03*/ ZJI_DMPAPER,
+/* 0x04*/ ZJI_DMCOPIES,
+/* 0x05*/ ZJI_DMDEFAULTSOURCE,
+/* 0x06*/ ZJI_DMMEDIATYPE,
+/* 0x07*/ ZJI_NBIE,
+/* 0x08*/ ZJI_RESOLUTION_X,
+/* 0x09*/ ZJI_RESOLUTION_Y,
+/* 0x0A */ ZJI_OFFSET_X,
+/* 0x0B */ ZJI_OFFSET_Y,
+/* 0x0C */ ZJI_RASTER_X,
+/* 0x0D */ ZJI_RASTER_Y,
+
+/* 0x0E */ ZJI_COLLATE,
+/* 0x0F */ ZJI_QUANTITY,
+
+/* 0x10 */ ZJI_VIDEO_BPP,
+/* 0x11 */ ZJI_VIDEO_X,
+/* 0x12 */ ZJI_VIDEO_Y,
+/* 0x13 */ ZJI_INTERLACE,
+/* 0x14 */ ZJI_PLANE,
+/* 0x15 */ ZJI_PALETTE,
+
+/* 0x16 */ ZJI_RET,
+/* 0x17 */ ZJI_TONER_SAVE,
+
+/* 0x18 */ ZJI_MEDIA_SIZE_X,
+/* 0x19 */ ZJI_MEDIA_SIZE_Y,
+/* 0x1A */ ZJI_MEDIA_SIZE_UNITS,
+
+/* 0x1B */ ZJI_CHROMATIC,
+
+/* 0x63 */ ZJI_PAD = 99,
+
+/* 0x64 */ ZJI_PROMPT,
+
+/* 0x65 */ ZJI_BITMAP_TYPE,
+/* 0x66 */ ZJI_ENCODING_DATA,
+/* 0x67 */ ZJI_END_PLANE,
+
+/* 0x68 */ ZJI_BITMAP_PIXELS,
+/* 0x69 */ ZJI_BITMAP_LINES,
+/* 0x6A */ ZJI_BITMAP_BPP,
+/* 0x6B */ ZJI_BITMAP_STRIDE,
+
+} ZJ_ITEM;
+
+typedef enum
+{
+ RET_OFF = 0,
+ RET_ON,
+ RET_AUTO,
+ RET_LIGHT,
+ RET_MEDIUM,
+ RET_DARK
+} RET_VALUE;
+
+typedef enum
+{
+ ZJIT_UINT32 = 1,
+ ZJIT_INT32,
+ ZJIT_STRING,
+ ZJIT_BYTELUT
+} CHUNK_ITEM_TYPE;
+
+// very frequently used fragments made into macros for readability
+#define CERRCHECK if (constructor_error != NO_ERROR) {dbglog("CERRCHECK fired\n"); return;}
+#define ERRCHECK if (err != NO_ERROR) {dbglog("ERRCHECK fired\n"); return err;}
+#define NEWCHECK(x) if (x==NULL) return ALLOCMEM_ERROR;
+#define CNEWCHECK(x) if (x==NULL) { constructor_error=ALLOCMEM_ERROR; return; }
+
+#define CUSTOM_MEDIA_SIZE 101
+
+#define EVENT_PRINT_FAILED_MISSING_PLUGIN 502
+enum COLORTYPE
+{
+ COLORTYPE_COLOR, // 0
+ COLORTYPE_BLACK, // 1
+ COLORTYPE_BOTH
+};
+
+typedef struct ColorMap_s
+{
+ uint32_t *ulMap1;
+ uint32_t *ulMap2;
+ unsigned char *ulMap3;
+} ColorMap;
+
+enum COMPRESS_MODE
+{
+ COMPRESS_MODE0 = 0,
+ COMPRESS_MODE2 = 2,
+ COMPRESS_MODE9 = 9,
+ COMPRESS_MODE_AUTO = 10,
+ COMPRESS_MODE_JPEG = 11,
+ COMPRESS_MODE_LJ = 12,
+ COMPRESS_MODE_GRAFIT = 16
+};
+
+enum COMPRESSOR_TYPE
+{
+ COMPRESSOR_JPEG_QUICKCONNECT,
+ COMPRESSOR_JPEG_JETREADY,
+ COMPRESSOR_TAOS
+};
+
+const int QTABLE_SIZE = 64;
+// jpeglib.h declares these as UINT16, which is defined as unsigned short in jmorecfg.h
+typedef struct QTableInfo_s
+{
+ DWORD qtable0[QTABLE_SIZE];
+ DWORD qtable1[QTABLE_SIZE];
+ DWORD qtable2[QTABLE_SIZE];
+ unsigned int qFactor;
+} QTableInfo;
+
+typedef struct PrintMode_s
+{
+ const char *name;
+// The resolutions can be different for different planes
+ unsigned int ResolutionX[MAXCOLORPLANES];
+ unsigned int ResolutionY[MAXCOLORPLANES];
+
+ unsigned int ColorDepth[MAXCOLORPLANES];
+ unsigned int dyeCount; // number of inks in the pen(s)
+
+ HALFTONING_ALGORITHM eHT;
+
+ ColorMap cmap;
+
+ unsigned int BaseResX,BaseResY;
+ bool MixedRes;
+
+ const unsigned char* BlackFEDTable;
+ const unsigned char* ColorFEDTable;
+} PrintMode;
+
+typedef struct
+{
+ const char *printer_platform_name;
+ PrintMode *print_modes;
+ int count;
+} PrintModeTable;
+
+typedef struct QualityAttributes_s
+{
+ int media_type;
+ int media_subtype;
+ int print_quality;
+ unsigned int horizontal_resolution;
+ unsigned int vertical_resolution;
+ unsigned int actual_vertical_resolution;
+ char print_mode_name[32];
+} QualityAttributes;
+
+typedef struct MediaAttributes_s
+{
+ int pcl_id;
+ int physical_width;
+ int physical_height;
+ int printable_width;
+ int printable_height;
+ int printable_start_x;
+ int printable_start_y;
+ int horizontal_overspray;
+ int vertical_overspray;
+ int left_overspray;
+ int top_overspray;
+} MediaAttributes;
+
+typedef struct JobAttributes_s
+{
+ int media_source;
+ int color_mode;
+ DUPLEXMODE e_duplex_mode;
+ int print_borderless;
+ int krgb_mode;
+ int mech_offset;
+ QualityAttributes quality_attributes;
+ MediaAttributes media_attributes;
+ int job_id;
+ int page_order;
+ int total_pages;
+ char job_title[128];
+ char user_name[32];
+ char host_name[32];
+ char domain_name[32];
+ char os_name[160];
+ char driver_version[32];
+ char driver_name[128];
+ char printer_name[160];
+ char job_start_time[32];
+ char uuid[64];
+ char printer_platform[32];
+ char printer_language[32];
+ int integer_values[16];
+ int printer_platform_version;
+ int pre_process_raster;
+} JobAttributes;
+
+#endif // COMMON_DEFINITIONS_H
+
diff --git a/prnt/hpcups/Encapsulator.cpp b/prnt/hpcups/Encapsulator.cpp
index 894e5fcc7..530fb9634 100644
--- a/prnt/hpcups/Encapsulator.cpp
+++ b/prnt/hpcups/Encapsulator.cpp
@@ -274,3 +274,10 @@ void Encapsulator::sendJobHeader()
return;
}
+
+DRIVER_ERROR Encapsulator::preProcessRasterData(cups_raster_t **cups_raster, cups_page_header2_t* firstpage_cups_header, char* pSwapedPagesFileName)
+{
+ dbglog ("DEBUG: Encapsulator::preProcessRasterData.............. \n");
+ return NO_ERROR;
+}
+
diff --git a/prnt/hpcups/Encapsulator.h b/prnt/hpcups/Encapsulator.h
index ac14a33f4..50587bce1 100644
--- a/prnt/hpcups/Encapsulator.h
+++ b/prnt/hpcups/Encapsulator.h
@@ -53,6 +53,7 @@ public:
virtual void SetLastBand() {}
virtual bool UnpackBits() {return true;}
virtual void CancelJob();
+ virtual DRIVER_ERROR preProcessRasterData(cups_raster_t **cups_raster, cups_page_header2_t* firstpage_cups_header, char* pSwapedPagesFileName);
protected:
void addToHeader(const BYTE *command_string, int length);
diff --git a/prnt/hpcups/HPCupsFilter.cpp b/prnt/hpcups/HPCupsFilter.cpp
index 0967fcc9e..514e285d9 100644
--- a/prnt/hpcups/HPCupsFilter.cpp
+++ b/prnt/hpcups/HPCupsFilter.cpp
@@ -1,825 +1,866 @@
-/*****************************************************************************\
- HPCupsFilter.cpp : Interface for HPCupsFilter class
-
- Copyright (c) 1996 - 2009, Hewlett-Packard Co.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Hewlett-Packard nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- Author: Naga Samrat Chowdary Narla,
-\*****************************************************************************/
-
-#include "HPCupsFilter.h"
-#include <signal.h>
-#include <sys/wait.h>
-#include <sys/utsname.h>
-#include <time.h>
-#include <sys/timeb.h>
-
-#define HP_FILE_VERSION_STR "03.09.08.0"
-
-static HPCupsFilter filter;
-int main (int argc, char *argv[])
-{
- openlog("hpcups", LOG_PID, LOG_DAEMON);
-
- if (argc < 6 || argc > 7) {
- dbglog("ERROR: %s job-id user title copies options [file]\n", *argv);
- return JOB_CANCELED;
- }
-
- return filter.StartPrintJob(argc, argv);
-}
-
-void HPCancelJob(int sig)
-{
- filter.CancelJob();
- exit(0);
-}
-
-void HPCupsFilter::CreateBMPHeader (int width, int height, int planes, int bpp)
-{
- memset (&this->bmfh, 0, 14);
- memset (&this->bmih, 0, 40);
- bmfh.bfOffBits = 54;
- bmfh.bfType = 0x4d42;
- bmfh.bfReserved1 = 0;
- bmfh.bfReserved2 = 0;
- bmih.biSize = DBITMAPINFOHEADER;
- bmih.biWidth = width;
- bmih.biHeight = -height;
- bmih.biPlanes = 1;
- bmih.biBitCount = planes * bpp;
- bmih.biCompression = 0;
- bmih.biSizeImage = width * height * planes * bpp / 8;
- bmih.biClrImportant = 0;
- bmih.biClrUsed = (planes == 3) ? 0 : 2;
- bmih.biXPelsPerMeter = 0;
- bmih.biYPelsPerMeter = 0;
-
- bmfh.bfOffBits += bmih.biClrUsed * 4;
- bmfh.bfSize = bmih.biSizeImage + bmfh.bfOffBits;
-}
-
-void HPCupsFilter::WriteBMPHeader (FILE *fp, int width, int height, eRasterType raster_type)
-{
- if (fp == NULL)
- {
- return;
- }
- if (raster_type == BLACK_RASTER)
- {
- WriteKBMPHeader (fp, width, height);
- }
- else
- {
- WriteCBMPHeader (fp, width, height);
- }
-}
-
-void HPCupsFilter::WriteCBMPHeader (FILE *fp, int width, int height)
-{
- if (fp == NULL)
- return;
- adj_c_width = width;
- if (width % 4)
- {
- adj_c_width = (width / 4 + 1) * 4;
- }
- color_raster = new BYTE[adj_c_width * 3];
- memset (color_raster, 0xFF, adj_c_width * 3);
- CreateBMPHeader(adj_c_width, height, 3, 8);
- fwrite (&this->bmfh.bfType, 1, sizeof (short), fp);
- fwrite (&this->bmfh.bfSize, 1, sizeof (int), fp);
- fwrite (&this->bmfh.bfReserved1, 1, sizeof (short), fp);
- fwrite (&this->bmfh.bfReserved2, 1, sizeof (short), fp);
- fwrite (&this->bmfh.bfOffBits, 1, sizeof (int), fp);
- fwrite (&this->bmih, 1, DBITMAPINFOHEADER, fp);
-}
-
-void HPCupsFilter::WriteKBMPHeader(FILE *fp, int width, int height)
-{
- BYTE cmap[8];
- if (fp == NULL)
- return;
- adj_k_width = width;
- if (width % 32)
- {
- adj_k_width = (width / 32 + 1) * 32;
- }
- CreateBMPHeader(adj_k_width, height, 1, 1);
- adj_k_width /= 8;
- black_raster = new BYTE[adj_k_width];
- memset (black_raster, 0, adj_k_width);
-
- fwrite (&this->bmfh.bfType, 1, sizeof (short), fp);
- fwrite (&this->bmfh.bfSize, 1, sizeof (int), fp);
- fwrite (&this->bmfh.bfReserved1, 1, sizeof (short), fp);
- fwrite (&this->bmfh.bfReserved2, 1, sizeof (short), fp);
- fwrite (&this->bmfh.bfOffBits, 1, sizeof (int), fp);
- fwrite (&this->bmih, 1, DBITMAPINFOHEADER, fp);
- memset(cmap, 0, sizeof(cmap));
- cmap[0] = cmap[1] = cmap[2] = cmap[3] = 255;
- fwrite(cmap, 1, sizeof(cmap), fp);
-}
-
-void HPCupsFilter::WriteBMPRaster (FILE *fp, BYTE *raster, int width, eRasterType raster_type)
-{
- if (raster_type == BLACK_RASTER)
- return WriteKBMPRaster (fp, raster, width);
- else
- return WriteCBMPRaster (fp, raster, width);
-}
-
-void HPCupsFilter::WriteCBMPRaster (FILE *fp, BYTE *pbyrgb, int width)
-{
- if (fp == NULL)
- return;
- //BYTE c[3];
- int i;
- BYTE *p = pbyrgb;
- BYTE *q = color_raster;
- if (pbyrgb == NULL)
- {
- memset (color_raster, 0xFF, adj_c_width * 3);
- }
- else
- {
- for (i = 0; i < width; i++) {
- q[0] = p[2];
- q[1] = p[1];
- q[2] = p[0];
- p += 3;
- q += 3;
- }
- }
- fwrite (color_raster, 1, adj_c_width * 3, fp);
-}
-
-void HPCupsFilter::WriteKBMPRaster (FILE *fp, BYTE *pbyk, int width)
-{
- if (fp == NULL)
- return;
- if (pbyk == NULL)
- {
- memset (black_raster, 0, adj_k_width);
- }
- else
- {
- memcpy (black_raster, pbyk, width);
- }
- fwrite (black_raster, 1, adj_k_width, fp);
-}
-
-HPCupsFilter::HPCupsFilter() : m_pPrinterBuffer(NULL)
-{
- setbuf (stderr, NULL);
-
- adj_c_width = 0;
- adj_k_width = 0;
- black_raster = NULL;
- color_raster = NULL;
-}
-
-HPCupsFilter::~HPCupsFilter()
-{
-
-}
-
-void HPCupsFilter::closeFilter ()
-{
- //! If we printed any pages, end the current job instance.
- m_Job.Cleanup();
- cleanup();
-}
-
-void HPCupsFilter::cleanup()
-{
- if (m_pPrinterBuffer) {
- delete [] m_pPrinterBuffer;
- }
-
- if(m_ppd){
- ppdClose(m_ppd);
- m_ppd = NULL;
- }
-}
-
-void HPCupsFilter::CancelJob()
-{
- m_Job.CancelJob();
- cleanup();
-}
-
-DRIVER_ERROR HPCupsFilter::startPage (cups_page_header2_t *cups_header)
-{
- DRIVER_ERROR err = NO_ERROR;
- ppd_attr_t *attr;
- int xoverspray = 120;
- int yoverspray = 60;
-
-/*
- * Check for invalid data
- */
- if (cups_header->HWResolution[0] == 100 && cups_header->HWResolution[1] == 100)
- {
-
-/*
- * Something went wrong, cups is defaulting to 100 dpi.
- * Some inkjet printers do not support 100 dpi. Return error.
- */
-
- dbglog("ERROR: Unsupported resolution\n");
- return JOB_CANCELED;
- }
-
-// XOverSpray and YOverSpray are entered as fractional value * 1000
-
- if (((attr = ppdFindAttr(m_ppd, "HPXOverSpray", NULL)) != NULL) &&
- (attr && attr->value != NULL)) {
- xoverspray = atoi(attr->value);
- }
- if (((attr = ppdFindAttr(m_ppd, "HPYOverSpray", NULL)) != NULL) &&
- (attr && attr->value != NULL)) {
- yoverspray = atoi(attr->value);
- }
-
- if (m_iLogLevel & BASIC_LOG) {
- printCupsHeaderInfo(cups_header);
- }
-
- m_JA.quality_attributes.media_type = cups_header->cupsMediaType;
- m_JA.quality_attributes.print_quality = atoi(cups_header->OutputType);
- m_JA.quality_attributes.horizontal_resolution = cups_header->HWResolution[0];
- m_JA.quality_attributes.vertical_resolution = cups_header->HWResolution[1];
- m_JA.quality_attributes.actual_vertical_resolution = cups_header->HWResolution[1];
-
-// Get the printer's actual resolution, may be different than what is reported
- char *p;
- if ((p = strstr (cups_header->OutputType, "_"))) {
- int x = 0, y = 0;
- p++;
- x = atoi(p);
- while (*p && *p != 'x')
- p++;
- if (*p && *p == 'x') {
- p++;
- y = atoi(p);
- }
-// Currently, there is one printer with one printmode that supports lower y-resolution
- if (y != 0) {
- m_JA.quality_attributes.actual_vertical_resolution = y;
- }
- }
- m_JA.color_mode = cups_header->cupsRowStep;
- m_JA.media_source = cups_header->MediaPosition;
-
- m_JA.print_borderless = (cups_header->ImagingBoundingBox[0] == 0) ? true : false;
- if (cups_header->Duplex) {
- m_JA.e_duplex_mode = (cups_header->Tumble == 0) ? DUPLEXMODE_BOOK : DUPLEXMODE_TABLET;
- }
- else {
- m_JA.e_duplex_mode = DUPLEXMODE_NONE;
- }
- m_JA.krgb_mode = (cups_header->cupsColorSpace == CUPS_CSPACE_RGBW) ? true : false;
-
- /*
- * Cups PageSize dimensions are in PostScript units, which are 72 units to an inch
- * and is stored as <width, height>
- * The ImagingBoundingBox is in PostScript units and are stored as <lower_left> <upper_right>
- * and <0, 0> is at the bottom left
- * lower_left_x = ImagingBoundingBox[0]
- * lower_left_y = ImagingBoundingBox[1]
- * upper_right_x = ImagingBoundingBox[2]
- * upper_right_y = ImagingBoundingBox[3]
- * We require <top_left> <bottom_right> values and <0, 0> is top left
- * So,
- * PrintableStartX = lower_left_x
- * PrintableStartY = PhysicalPageHeight - upper_right_y
- */
-
- int horz_res = cups_header->HWResolution[0];
- int vert_res = cups_header->HWResolution[1];
- m_JA.media_attributes.pcl_id = cups_header->cupsInteger[0];
- m_JA.media_attributes.physical_width = (cups_header->PageSize[0] * horz_res) / 72;
- m_JA.media_attributes.physical_height = (cups_header->PageSize[1] * vert_res) / 72;
- m_JA.media_attributes.printable_width = cups_header->cupsWidth;
- m_JA.media_attributes.printable_height = cups_header->cupsHeight;
-
- m_JA.media_attributes.printable_start_x = (cups_header->Margins[0] * horz_res) / 72;
- m_JA.media_attributes.printable_start_y = ((cups_header->PageSize[1] - cups_header->ImagingBoundingBox[3]) * vert_res) / 72;
-
- m_JA.media_attributes.horizontal_overspray = (xoverspray * horz_res) / 1000;
- m_JA.media_attributes.vertical_overspray = (yoverspray * vert_res) / 1000;
-
- /*
- * Left and top overspray in dots. We haven't defined ovespray for all classes in the drv.
- * Hence using default values in the case of older classes.
- */
- m_JA.media_attributes.left_overspray = cups_header->cupsReal[0] ? (cups_header->cupsReal[0] * horz_res) : m_JA.media_attributes.horizontal_overspray / 2;
- m_JA.media_attributes.top_overspray = cups_header->cupsReal[1] ? (cups_header->cupsReal[1] * vert_res) : m_JA.media_attributes.vertical_overspray / 2;
-
- if (((attr = ppdFindAttr(m_ppd, "HPMechOffset", NULL)) != NULL) &&
- (attr && attr->value != NULL)) {
- m_JA.mech_offset = atoi(attr->value);
- }
-
-// Get printer platform name
- if (((attr = ppdFindAttr(m_ppd, "hpPrinterPlatform", NULL)) != NULL) &&
- (attr->value != NULL)) {
- strncpy(m_JA.printer_platform, attr->value, sizeof(m_JA.printer_platform)-1);
- if (m_iLogLevel & BASIC_LOG) {
- dbglog("HPCUPS: found Printer Platform, it is - %s", attr->value);
- }
- if(strcmp(m_JA.printer_platform, "ljzjscolor") == 0)
- {
- if(((attr = ppdFindAttr(m_ppd, "hpLJZjsColorVersion", NULL)) != NULL) && (attr->value != NULL))
- m_JA.printer_platform_version = atoi(attr->value);
- }
- }
-
-// Get the encapsulation technology from ppd
-
- if (((attr = ppdFindAttr(m_ppd, "hpPrinterLanguage", NULL)) == NULL) ||
- (attr && attr->value == NULL)) {
- dbglog("DEBUG: Bad PPD - hpPrinterLanguage not found\n");
- ppdClose(m_ppd);
- m_ppd = NULL;
- return SYSTEM_ERROR;
- }
- strncpy(m_JA.printer_language, attr->value, sizeof(m_JA.printer_language)-1);
- if (m_iLogLevel & BASIC_LOG) {
- dbglog("HPCUPS: found Printer Language, it is - %s", attr->value);
- }
-
-// Fill in the other PCL header info
-
- struct utsname uts_name;
- uname(&uts_name);
- strncpy(m_JA.job_title, m_argv[3], sizeof(m_JA.job_title)-1);
- strncpy(m_JA.user_name, m_argv[2], sizeof(m_JA.user_name)-1);
- strncpy(m_JA.host_name, uts_name.nodename, sizeof(m_JA.host_name)-1);
- strncpy(m_JA.os_name, uts_name.sysname, sizeof(m_JA.os_name)-1);
- getdomainname(m_JA.domain_name, sizeof(m_JA.domain_name) - 1);
- int i = strlen(m_argv[0]) - 1;
- while (i >= 0 && m_argv[0][i] != '/') {
- i--;
- }
- snprintf(m_JA.driver_name, sizeof(m_JA.driver_name), "%s; %s", &m_argv[0][i+1], HP_FILE_VERSION_STR);
- char *ptr = getenv("DEVICE_URI");
- i = 0;
- if (ptr) {
- while (*ptr) {
- if (*ptr == '%') {
- ptr += 3;
- m_JA.printer_name[i++] = ' ';
- }
- m_JA.printer_name[i++] = *ptr++;
- }
- }
- ptr = strstr(m_argv[5], "job-uuid");
- if (ptr) {
- strncpy(m_JA.uuid, ptr + strlen("job-uuid=urn:uuid:"), sizeof(m_JA.uuid)-1);
- }
-
- for (i = 0; i < 16; i++)
- m_JA.integer_values[i] = cups_header->cupsInteger[i];
-
- if (cups_header->cupsString[0]) {
- strncpy(m_JA.quality_attributes.print_mode_name, &cups_header->cupsString[0][0],
- sizeof(m_JA.quality_attributes.print_mode_name)-1);
- }
- Encapsulator *encap_interface = EncapsulatorFactory::GetEncapsulator(attr->value);
- if ((err = m_Job.Init(m_pSys, &m_JA, encap_interface)) != NO_ERROR)
- {
- if (err == PLUGIN_LIBRARY_MISSING)
- fputs ("STATE: +hplip.plugin-error\n", stderr);
- dbglog ("m_Job initialization failed with error = %d", err);
- ppdClose(m_ppd);
- m_ppd = NULL;
- return err;
- }
-
- if (m_iLogLevel & BASIC_LOG) {
- dbglog("HPCUPS: returning NO_ERROR from startPage");
- }
-
- m_pPrinterBuffer = new BYTE[cups_header->cupsWidth * 4 + 32];
-
-
- return NO_ERROR;
-}
-
-int HPCupsFilter::StartPrintJob(int argc, char *argv[])
-{
- int fd = 0;
- cups_raster_t *cups_raster;
- int err = 0;
-
- memset(&m_JA, 0, sizeof(JobAttributes));
- struct tm *t;
- struct timeb tb;
- time_t long_time;
- time(&long_time);
- t = localtime(&long_time);
- ftime(&tb);
- strncpy(m_JA.job_start_time, asctime(t), sizeof(m_JA.job_start_time)-1); // returns Fri Jun 5 08:12:16 2009
- snprintf(m_JA.job_start_time+19, sizeof(m_JA.job_start_time) - 20, ":%d %d", tb.millitm, t->tm_year + 1900); // add milliseconds
-
- getLogLevel();
- m_JA.job_id = atoi(argv[1]);
- FILE *fp;
- char dFileName[32];
- memset(dFileName, 0, sizeof(dFileName));
- m_JA.job_id = atoi(argv[1]);
- snprintf (dFileName, sizeof(dFileName), "/var/spool/cups/d%05d-001", m_JA.job_id);
- if ((fp = fopen (dFileName, "r")))
- {
- char line[258];
- for (int i = 0; i < 10; i++)
- {
- fgets (line, 256, fp);
- if (!strncmp (line, "%%Pages:", 8))
- {
- sscanf (line+9, "%d", &m_JA.total_pages);
- break;
- }
- }
- fclose (fp);
- }
-
- m_ppd = ppdOpenFile(getenv("PPD"));
- if (m_ppd == NULL) {
- dbglog("DEBUG: ppdOpenFile failed for %s\n", getenv("PPD"));
- return SYSTEM_ERROR;
- }
-
- m_argv = argv;
- if (m_iLogLevel & BASIC_LOG) {
- for (int i = 0; i < argc; i++) {
- dbglog("argv[%d] = %s\n", i, argv[i]);
- }
- }
-
- if (argc == 7)
- {
- if (m_iLogLevel & BASIC_LOG)
- {
- dbglog("Page Stream Data Name: %s\n", argv[6] );
- }
- if ((fd = open (argv[6], O_RDONLY)) == -1)
- {
- perror("ERROR: Unable to open raster file - ");
- return 1;
- }
- }
-
- m_pSys = new SystemServices(m_iLogLevel, m_JA.job_id);
-
-/*
- * When user cancels a print job, the spooler sends SIGTERM signal
- * to the filter. Must catch this signal to send end job sequence
- * to the printer.
- */
-
- signal(SIGTERM, HPCancelJob);
-
- cups_raster = cupsRasterOpen(fd, CUPS_RASTER_READ);
-
- if (cups_raster == NULL) {
- dbglog("cupsRasterOpen failed, fd = %d\n", fd);
- if (fd != 0) {
- close(fd);
- }
- closeFilter();
- return 1;
- }
-
- if ((err = processRasterData(cups_raster))) {
- if (fd != 0) {
- close(fd);
- }
- if (m_iLogLevel & BASIC_LOG)
- dbglog("HPCUPS: processRasterData returned %d, calling closeFilter()", err);
- closeFilter();
- cupsRasterClose(cups_raster);
- return 1;
- }
-
- if (fd != 0) {
- close(fd);
- }
- if (m_iLogLevel & BASIC_LOG)
- dbglog("HPCUPS: StartPrintJob end of job, calling closeFilter()");
- closeFilter();
- cupsRasterClose(cups_raster);
- return 0;
-}
-
-bool HPCupsFilter::isBlankRaster(BYTE *input_raster, cups_page_header2_t *header)
-{
- int length_in_bytes = (int)header->cupsBytesPerLine;
- if (input_raster == NULL) {
- return true;
- }
-
- if(header->cupsColorSpace == CUPS_CSPACE_K){
- if (*input_raster == 0x00 &&
- !(memcmp(input_raster + 1, input_raster, length_in_bytes - 1))) {
- return true;
- }
- }
- else{
- if (*input_raster == 0xFF &&
- !(memcmp(input_raster + 1, input_raster, length_in_bytes - 1))) {
- return true;
- }
- }
- return false;
-}
-
-int HPCupsFilter::processRasterData(cups_raster_t *cups_raster)
-{
- FILE *kfp = NULL;
- FILE *cfp = NULL;
- BYTE *kRaster = NULL;
- BYTE *rgbRaster = NULL;
- int current_page_number = 0;
- cups_page_header2_t cups_header;
- DRIVER_ERROR err;
- int ret_status = 0;
-
-
- while (cupsRasterReadHeader2(cups_raster, &cups_header))
- {
- current_page_number++;
-
- if (current_page_number == 1) {
- if (startPage(&cups_header) != NO_ERROR) {
- return JOB_CANCELED;
- }
- if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW) {
- rgbRaster = new BYTE[cups_header.cupsWidth * 3];
- if (rgbRaster == NULL) {
- return ALLOCMEM_ERROR;
- }
- kRaster = new BYTE[cups_header.cupsWidth];
- if (kRaster == NULL) {
- delete [] rgbRaster;
- return ALLOCMEM_ERROR;
- }
- memset (kRaster, 0, cups_header.cupsWidth);
- memset (rgbRaster, 0xFF, cups_header.cupsWidth * 3);
- }
- } // current_page_number == 1
-
- if (cups_header.cupsColorSpace == CUPS_CSPACE_K) {
- kRaster = m_pPrinterBuffer;
- rgbRaster = NULL;
- }
- else if (cups_header.cupsColorSpace != CUPS_CSPACE_RGBW) {
- dbglog("5......\n");
- rgbRaster = m_pPrinterBuffer;
- kRaster = NULL;
- }
-
- BYTE *color_raster = NULL;
- BYTE *black_raster = NULL;
-
- err = m_Job.StartPage(&m_JA);
- if (err != NO_ERROR) {
- if (m_iLogLevel & BASIC_LOG) {
- dbglog ("DEBUG: Job::StartPage failed with err = %d\n", err);
- }
- ret_status = JOB_CANCELED;
- break;
- }
-
- if (m_iLogLevel & SAVE_INPUT_RASTERS)
- {
- char szFileName[32];
- memset(szFileName, 0, sizeof(szFileName));
- snprintf (szFileName, sizeof(szFileName), "/tmp/hpcupsfilterc_%d.bmp", current_page_number);
- if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW ||
- cups_header.cupsColorSpace == CUPS_CSPACE_RGB)
- {
- cfp = fopen (szFileName, "w");
- chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- }
- if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW ||
- cups_header.cupsColorSpace == CUPS_CSPACE_K)
- {
- szFileName[17] = 'k';
- kfp = fopen (szFileName, "w");
- chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- }
- dbglog("9......\n");
- WriteBMPHeader (cfp, cups_header.cupsWidth, cups_header.cupsHeight, COLOR_RASTER);
- WriteBMPHeader (kfp, cups_header.cupsWidth, cups_header.cupsHeight, BLACK_RASTER);
- dbglog("10......\n");
- }
-
- fprintf(stderr, "PAGE: %d %s", current_page_number, m_argv[4]);
- // Iterating through the raster per page
- for (int y = 0; y < (int) cups_header.cupsHeight; y++) {
- cupsRasterReadPixels (cups_raster, m_pPrinterBuffer, cups_header.cupsBytesPerLine);
- color_raster = rgbRaster;
- black_raster = kRaster;
-
- if (this->isBlankRaster((BYTE *) m_pPrinterBuffer, &cups_header)) {
-
- color_raster = NULL;
- black_raster = NULL;
- }
- extractBlackPixels(&cups_header, black_raster, color_raster);
- //! Sending Raster bits off to encapsulation
- err = m_Job.SendRasters (black_raster, color_raster);
- if (err != NO_ERROR) {
- break;
- }
- WriteBMPRaster (cfp, color_raster, cups_header.cupsWidth, COLOR_RASTER);
- WriteBMPRaster (kfp, black_raster, cups_header.cupsWidth/8, BLACK_RASTER);
- }
- m_Job.NewPage();
- if (err != NO_ERROR) {
- break;
- }
- }
-
- //! Remove the old processing band data...
- if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW) {
- delete [] kRaster;
- delete [] rgbRaster;
- }
- return ret_status;
-}
-
-void HPCupsFilter::extractBlackPixels(cups_page_header2_t *cups_header, BYTE *kRaster, BYTE *rgbRaster)
-{
-/*
- * DON'T DO BITPACKING HERE, DO IT IN HALFTONER FOR CMYK PRINTES
- * AND IN MODE9 FOR RGB PRINTERS
- */
-
-static BYTE pixel_value[8] = {
- 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
- };
-
- if (rgbRaster == NULL) {
- return;
- }
-
- if (cups_header->cupsColorSpace == CUPS_CSPACE_RGBW) {
- int k = 0;
- BYTE *pIn = m_pPrinterBuffer;
- BYTE kVal = 0;
- BYTE b;
- BYTE *rgb = rgbRaster;
- BYTE *black = kRaster;
- memset (kRaster, 0, cups_header->cupsWidth);
-
-
- for (unsigned int i = 0; i < cups_header->cupsWidth; i++) {
- rgb[0] = *pIn++;
- rgb[1] = *pIn++;
- rgb[2] = *pIn++;
- b = *pIn++;
-
- if (b != 0 && b != 0xFF) {
-
-#ifdef __linux
- // rgb[0] -= (255 - b);
- // rgb[1] -= (255 - b);
- // rgb[2] -= (255 - b);
- int cr,cg,cb;
- cr = rgb[0] - (int)(255 - b);
- rgb[0] = cr >= 0 ? cr : 0;
-
- cg = rgb[1] - (int)(255 - b);
- rgb[1] = cg >= 0 ? cg : 0;
-
- cb = rgb[2] - (int)(255 - b);
- rgb[2] = cb >= 0 ? cb : 0;
-#else // This alternate path is for Mac....
-
- rgb[0] &= b;
- rgb[1] &= b;
- rgb[2] &= b;
-#endif
- }
- else
- kVal |= (b == 0) ? pixel_value[k] : 0;
- // else if (rgb[0] == rgb[1] && rgb[1] ==rgb[2])
- // kVal |= (rgb[0] == 0) ? pixel_value[k] : 0;
- rgb += 3;
- if (k == 7) {
- *black++ = kVal;
- kVal = 0;
- k = 0;
- }
- else {
- k++;
- }
- } // end of for loop
- *black = kVal;
-
- } // end of if condition
-}
-
-void HPCupsFilter::printCupsHeaderInfo(cups_page_header2_t *header)
-{
-
- dbglog ("DEBUG: startPage...\n");
- dbglog ("DEBUG: MediaClass = \"%s\"\n", header->MediaClass);
- dbglog ("DEBUG: MediaColor = \"%s\"\n", header->MediaColor);
- dbglog ("DEBUG: MediaType = \"%s\"\n", header->MediaType);
- dbglog ("DEBUG: OutputType = \"%s\"\n", header->OutputType);
- dbglog ("DEBUG: AdvanceDistance = %d\n", header->AdvanceDistance);
- dbglog ("DEBUG: AdvanceMedia = %d\n", header->AdvanceMedia);
- dbglog ("DEBUG: Collate = %d\n", header->Collate);
- dbglog ("DEBUG: CutMedia = %d\n", header->CutMedia);
- dbglog ("DEBUG: Duplex = %d\n", header->Duplex);
- dbglog ("DEBUG: HWResolution = [ %d %d ]\n", header->HWResolution[0], header->HWResolution[1]);
- dbglog ("DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
- header->ImagingBoundingBox[0], header->ImagingBoundingBox[1],
- header->ImagingBoundingBox[2], header->ImagingBoundingBox[3]);
- dbglog ("DEBUG: InsertSheet = %d\n", header->InsertSheet);
- dbglog ("DEBUG: Jog = %d\n", header->Jog);
- dbglog ("DEBUG: LeadingEdge = %d\n", header->LeadingEdge);
- dbglog ("DEBUG: Margins = [ %d %d ]\n", header->Margins[0], header->Margins[1]);
- dbglog ("DEBUG: ManualFeed = %d\n", header->ManualFeed);
- dbglog ("DEBUG: MediaPosition = %d\n", header->MediaPosition);
- dbglog ("DEBUG: MediaWeight = %d\n", header->MediaWeight);
- dbglog ("DEBUG: MirrorPrint = %d\n", header->MirrorPrint);
- dbglog ("DEBUG: NegativePrint = %d\n", header->NegativePrint);
- dbglog ("DEBUG: NumCopies = %d\n", header->NumCopies);
- dbglog ("DEBUG: Orientation = %d\n", header->Orientation);
- dbglog ("DEBUG: OutputFaceUp = %d\n", header->OutputFaceUp);
- dbglog ("DEBUG: PageSize = [ %d %d ]\n", header->PageSize[0], header->PageSize[1]);
- dbglog ("DEBUG: Separations = %d\n", header->Separations);
- dbglog ("DEBUG: TraySwitch = %d\n", header->TraySwitch);
- dbglog ("DEBUG: Tumble = %d\n", header->Tumble);
- dbglog ("DEBUG: cupsWidth = %d\n", header->cupsWidth);
- dbglog ("DEBUG: cupsHeight = %d\n", header->cupsHeight);
- dbglog ("DEBUG: cupsMediaType = %d\n", header->cupsMediaType);
- dbglog ("DEBUG: cupsRowStep = %d\n", header->cupsRowStep);
- dbglog ("DEBUG: cupsBitsPerColor = %d\n", header->cupsBitsPerColor);
- dbglog ("DEBUG: cupsBitsPerPixel = %d\n", header->cupsBitsPerPixel);
- dbglog ("DEBUG: cupsBytesPerLine = %d\n", header->cupsBytesPerLine);
- dbglog ("DEBUG: cupsColorOrder = %d\n", header->cupsColorOrder);
- dbglog ("DEBUG: cupsColorSpace = %d\n", header->cupsColorSpace);
- dbglog ("DEBUG: cupsCompression = %d\n", header->cupsCompression);
- dbglog ("DEBUG: cupsPageSizeName = %s\n", header->cupsPageSizeName);
- dbglog ("DEBUG: cupsInteger0 = %d\n", header->cupsInteger[0]); // max jpeg filesize
- dbglog ("DEBUG: cupsInteger1 = %d\n", header->cupsInteger[1]); // Red eye removal
- dbglog ("DEBUG: cupsInteger2 = %d\n", header->cupsInteger[2]); // Photo fix (RLT)
- dbglog ("DEBUG: cupsString0 = %s\n", header->cupsString[0]); // print_mode_name
- dbglog ("DEBUG: cupsReal0 = %f\n", header->cupsReal[0]); // Left overspray
- dbglog ("DEBUG: cupsReal1 = %f\n", header->cupsReal[1]); // Top overspray
-}
-
-void HPCupsFilter::getLogLevel ()
-{
- FILE *fp;
- char str[258];
- char *p;
- fp = fopen ("/etc/cups/cupsd.conf", "r");
- if (fp == NULL)
- return;
- while (!feof (fp))
- {
- if (!fgets (str, 256, fp))
- {
- break;
- }
- if ((p = strstr (str, "hpLogLevel")))
- {
- p += strlen ("hpLogLevel") + 1;
- m_iLogLevel = atoi (p);
- break;
- }
- }
- fclose (fp);
-}
-
+/*****************************************************************************\
+ HPCupsFilter.cpp : Interface for HPCupsFilter class
+
+ Copyright (c) 1996 - 2009, Hewlett-Packard Co.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of Hewlett-Packard nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ Author: Naga Samrat Chowdary Narla, Sanjay Kumar, Amarnath Chitumalla
+\*****************************************************************************/
+
+#include "HPCupsFilter.h"
+#include <signal.h>
+#include <sys/wait.h>
+#include <sys/utsname.h>
+#include <time.h>
+#include <sys/timeb.h>
+
+#define HP_FILE_VERSION_STR "03.09.08.0"
+
+static HPCupsFilter filter;
+int main (int argc, char *argv[])
+{
+ openlog("hpcups", LOG_PID, LOG_DAEMON);
+
+ if (argc < 6 || argc > 7) {
+ dbglog("ERROR: %s job-id user title copies options [file]\n", *argv);
+ return JOB_CANCELED;
+ }
+
+ return filter.StartPrintJob(argc, argv);
+}
+
+void HPCancelJob(int sig)
+{
+ filter.CancelJob();
+ exit(0);
+}
+
+void HPCupsFilter::CreateBMPHeader (int width, int height, int planes, int bpp)
+{
+ memset (&this->bmfh, 0, 14);
+ memset (&this->bmih, 0, 40);
+ bmfh.bfOffBits = 54;
+ bmfh.bfType = 0x4d42;
+ bmfh.bfReserved1 = 0;
+ bmfh.bfReserved2 = 0;
+ bmih.biSize = DBITMAPINFOHEADER;
+ bmih.biWidth = width;
+ bmih.biHeight = -height;
+ bmih.biPlanes = 1;
+ bmih.biBitCount = planes * bpp;
+ bmih.biCompression = 0;
+ bmih.biSizeImage = width * height * planes * bpp / 8;
+ bmih.biClrImportant = 0;
+ bmih.biClrUsed = (planes == 3) ? 0 : 2;
+ bmih.biXPelsPerMeter = 0;
+ bmih.biYPelsPerMeter = 0;
+
+ bmfh.bfOffBits += bmih.biClrUsed * 4;
+ bmfh.bfSize = bmih.biSizeImage + bmfh.bfOffBits;
+}
+
+void HPCupsFilter::WriteBMPHeader (FILE *fp, int width, int height, eRasterType raster_type)
+{
+ if (fp == NULL)
+ {
+ return;
+ }
+ if (raster_type == BLACK_RASTER)
+ {
+ WriteKBMPHeader (fp, width, height);
+ }
+ else
+ {
+ WriteCBMPHeader (fp, width, height);
+ }
+}
+
+void HPCupsFilter::WriteCBMPHeader (FILE *fp, int width, int height)
+{
+ if (fp == NULL)
+ return;
+ adj_c_width = width;
+ if (width % 4)
+ {
+ adj_c_width = (width / 4 + 1) * 4;
+ }
+ color_raster = new BYTE[adj_c_width * 3];
+ memset (color_raster, 0xFF, adj_c_width * 3);
+ CreateBMPHeader(adj_c_width, height, 3, 8);
+ fwrite (&this->bmfh.bfType, 1, sizeof (short), fp);
+ fwrite (&this->bmfh.bfSize, 1, sizeof (int), fp);
+ fwrite (&this->bmfh.bfReserved1, 1, sizeof (short), fp);
+ fwrite (&this->bmfh.bfReserved2, 1, sizeof (short), fp);
+ fwrite (&this->bmfh.bfOffBits, 1, sizeof (int), fp);
+ fwrite (&this->bmih, 1, DBITMAPINFOHEADER, fp);
+}
+
+void HPCupsFilter::WriteKBMPHeader(FILE *fp, int width, int height)
+{
+ BYTE cmap[8];
+ if (fp == NULL)
+ return;
+ adj_k_width = width;
+ if (width % 32)
+ {
+ adj_k_width = (width / 32 + 1) * 32;
+ }
+ CreateBMPHeader(adj_k_width, height, 1, 1);
+ adj_k_width /= 8;
+ black_raster = new BYTE[adj_k_width];
+ memset (black_raster, 0, adj_k_width);
+
+ fwrite (&this->bmfh.bfType, 1, sizeof (short), fp);
+ fwrite (&this->bmfh.bfSize, 1, sizeof (int), fp);
+ fwrite (&this->bmfh.bfReserved1, 1, sizeof (short), fp);
+ fwrite (&this->bmfh.bfReserved2, 1, sizeof (short), fp);
+ fwrite (&this->bmfh.bfOffBits, 1, sizeof (int), fp);
+ fwrite (&this->bmih, 1, DBITMAPINFOHEADER, fp);
+ memset(cmap, 0, sizeof(cmap));
+ cmap[0] = cmap[1] = cmap[2] = cmap[3] = 255;
+ fwrite(cmap, 1, sizeof(cmap), fp);
+}
+
+void HPCupsFilter::WriteBMPRaster (FILE *fp, BYTE *raster, int width, eRasterType raster_type)
+{
+ if (raster_type == BLACK_RASTER)
+ return WriteKBMPRaster (fp, raster, width);
+ else
+ return WriteCBMPRaster (fp, raster, width);
+}
+
+void HPCupsFilter::WriteCBMPRaster (FILE *fp, BYTE *pbyrgb, int width)
+{
+ if (fp == NULL)
+ return;
+ //BYTE c[3];
+ int i;
+ BYTE *p = pbyrgb;
+ BYTE *q = color_raster;
+ if (pbyrgb == NULL)
+ {
+ memset (color_raster, 0xFF, adj_c_width * 3);
+ }
+ else
+ {
+ for (i = 0; i < width; i++) {
+ q[0] = p[2];
+ q[1] = p[1];
+ q[2] = p[0];
+ p += 3;
+ q += 3;
+ }
+ }
+ fwrite (color_raster, 1, adj_c_width * 3, fp);
+}
+
+void HPCupsFilter::WriteKBMPRaster (FILE *fp, BYTE *pbyk, int width)
+{
+ if (fp == NULL)
+ return;
+ if (pbyk == NULL)
+ {
+ memset (black_raster, 0, adj_k_width);
+ }
+ else
+ {
+ memcpy (black_raster, pbyk, width);
+ }
+ fwrite (black_raster, 1, adj_k_width, fp);
+}
+
+HPCupsFilter::HPCupsFilter() : m_pPrinterBuffer(NULL)
+{
+ setbuf (stderr, NULL);
+
+ adj_c_width = 0;
+ adj_k_width = 0;
+ black_raster = NULL;
+ color_raster = NULL;
+}
+
+HPCupsFilter::~HPCupsFilter()
+{
+
+}
+
+void HPCupsFilter::closeFilter ()
+{
+ //! If we printed any pages, end the current job instance.
+ m_Job.Cleanup();
+ cleanup();
+}
+
+void HPCupsFilter::cleanup()
+{
+ if (m_pPrinterBuffer) {
+ delete [] m_pPrinterBuffer;
+ }
+
+ if(m_ppd){
+ ppdClose(m_ppd);
+ m_ppd = NULL;
+ }
+}
+
+void HPCupsFilter::CancelJob()
+{
+ m_Job.CancelJob();
+ cleanup();
+}
+
+DRIVER_ERROR HPCupsFilter::startPage (cups_page_header2_t *cups_header)
+{
+ DRIVER_ERROR err = NO_ERROR;
+ ppd_attr_t *attr;
+ int xoverspray = 120;
+ int yoverspray = 60;
+
+/*
+ * Check for invalid data
+ */
+ if (cups_header->HWResolution[0] == 100 && cups_header->HWResolution[1] == 100)
+ {
+
+/*
+ * Something went wrong, cups is defaulting to 100 dpi.
+ * Some inkjet printers do not support 100 dpi. Return error.
+ */
+
+ dbglog("ERROR: Unsupported resolution\n");
+ return JOB_CANCELED;
+ }
+
+// XOverSpray and YOverSpray are entered as fractional value * 1000
+
+ if (((attr = ppdFindAttr(m_ppd, "HPXOverSpray", NULL)) != NULL) &&
+ (attr && attr->value != NULL)) {
+ xoverspray = atoi(attr->value);
+ }
+ if (((attr = ppdFindAttr(m_ppd, "HPYOverSpray", NULL)) != NULL) &&
+ (attr && attr->value != NULL)) {
+ yoverspray = atoi(attr->value);
+ }
+
+ if (m_iLogLevel & BASIC_LOG) {
+ printCupsHeaderInfo(cups_header);
+ }
+
+ m_JA.quality_attributes.media_type = cups_header->cupsMediaType;
+ m_JA.quality_attributes.print_quality = atoi(cups_header->OutputType);
+ m_JA.quality_attributes.horizontal_resolution = cups_header->HWResolution[0];
+ m_JA.quality_attributes.vertical_resolution = cups_header->HWResolution[1];
+ m_JA.quality_attributes.actual_vertical_resolution = cups_header->HWResolution[1];
+
+// Get the printer's actual resolution, may be different than what is reported
+ char *p;
+ if ((p = strstr (cups_header->OutputType, "_"))) {
+ int x = 0, y = 0;
+ p++;
+ x = atoi(p);
+ while (*p && *p != 'x')
+ p++;
+ if (*p && *p == 'x') {
+ p++;
+ y = atoi(p);
+ }
+// Currently, there is one printer with one printmode that supports lower y-resolution
+ if (y != 0) {
+ m_JA.quality_attributes.actual_vertical_resolution = y;
+ }
+ }
+ m_JA.color_mode = cups_header->cupsRowStep;
+ m_JA.media_source = cups_header->MediaPosition;
+
+ m_JA.print_borderless = (cups_header->ImagingBoundingBox[0] == 0) ? true : false;
+ if (cups_header->Duplex) {
+ m_JA.e_duplex_mode = (cups_header->Tumble == 0) ? DUPLEXMODE_BOOK : DUPLEXMODE_TABLET;
+ }
+ else {
+ m_JA.e_duplex_mode = DUPLEXMODE_NONE;
+ }
+ m_JA.krgb_mode = (cups_header->cupsColorSpace == CUPS_CSPACE_RGBW) ? true : false;
+
+ /*
+ * Cups PageSize dimensions are in PostScript units, which are 72 units to an inch
+ * and is stored as <width, height>
+ * The ImagingBoundingBox is in PostScript units and are stored as <lower_left> <upper_right>
+ * and <0, 0> is at the bottom left
+ * lower_left_x = ImagingBoundingBox[0]
+ * lower_left_y = ImagingBoundingBox[1]
+ * upper_right_x = ImagingBoundingBox[2]
+ * upper_right_y = ImagingBoundingBox[3]
+ * We require <top_left> <bottom_right> values and <0, 0> is top left
+ * So,
+ * PrintableStartX = lower_left_x
+ * PrintableStartY = PhysicalPageHeight - upper_right_y
+ */
+
+ int horz_res = cups_header->HWResolution[0];
+ int vert_res = cups_header->HWResolution[1];
+ m_JA.media_attributes.pcl_id = cups_header->cupsInteger[0];
+ m_JA.media_attributes.physical_width = (cups_header->PageSize[0] * horz_res) / 72;
+ m_JA.media_attributes.physical_height = (cups_header->PageSize[1] * vert_res) / 72;
+ m_JA.media_attributes.printable_width = cups_header->cupsWidth;
+ m_JA.media_attributes.printable_height = cups_header->cupsHeight;
+
+ m_JA.media_attributes.printable_start_x = (cups_header->Margins[0] * horz_res) / 72;
+ m_JA.media_attributes.printable_start_y = ((cups_header->PageSize[1] - cups_header->ImagingBoundingBox[3]) * vert_res) / 72;
+
+ m_JA.media_attributes.horizontal_overspray = (xoverspray * horz_res) / 1000;
+ m_JA.media_attributes.vertical_overspray = (yoverspray * vert_res) / 1000;
+
+ /*
+ * Left and top overspray in dots. We haven't defined ovespray for all classes in the drv.
+ * Hence using default values in the case of older classes.
+ */
+ m_JA.media_attributes.left_overspray = cups_header->cupsReal[0] ? (cups_header->cupsReal[0] * horz_res) : m_JA.media_attributes.horizontal_overspray / 2;
+ m_JA.media_attributes.top_overspray = cups_header->cupsReal[1] ? (cups_header->cupsReal[1] * vert_res) : m_JA.media_attributes.vertical_overspray / 2;
+
+ if (((attr = ppdFindAttr(m_ppd, "HPMechOffset", NULL)) != NULL) &&
+ (attr && attr->value != NULL)) {
+ m_JA.mech_offset = atoi(attr->value);
+ }
+
+// Get printer platform name
+ if (((attr = ppdFindAttr(m_ppd, "hpPrinterPlatform", NULL)) != NULL) && (attr->value != NULL)) {
+
+ strncpy(m_JA.printer_platform, attr->value, sizeof(m_JA.printer_platform)-1);
+
+ if (m_iLogLevel & BASIC_LOG) {
+ dbglog("HPCUPS: found Printer Platform, it is - %s\n", attr->value);
+ }
+
+ if(strcmp(m_JA.printer_platform, "ljzjscolor") == 0){
+ if(((attr = ppdFindAttr(m_ppd, "hpLJZjsColorVersion", NULL)) != NULL) && (attr->value != NULL)){
+ m_JA.printer_platform_version = atoi(attr->value);
+ }
+ }
+ }
+
+//Get Raster Preprocessing status
+ if(((attr = ppdFindAttr(m_ppd, "hpReverseRasterPages", NULL)) != NULL) && (attr->value != NULL)){
+ m_JA.pre_process_raster = atoi(attr->value);
+ }
+
+
+// Get the encapsulation technology from ppd
+
+ if (((attr = ppdFindAttr(m_ppd, "hpPrinterLanguage", NULL)) == NULL) ||
+ (attr && attr->value == NULL)) {
+ dbglog("DEBUG: Bad PPD - hpPrinterLanguage not found\n");
+ ppdClose(m_ppd);
+ m_ppd = NULL;
+ return SYSTEM_ERROR;
+ }
+ strncpy(m_JA.printer_language, attr->value, sizeof(m_JA.printer_language)-1);
+ if (m_iLogLevel & BASIC_LOG) {
+ dbglog("HPCUPS: found Printer Language, it is - %s\n", attr->value);
+ }
+
+// Fill in the other PCL header info
+
+ struct utsname uts_name;
+ uname(&uts_name);
+ strncpy(m_JA.job_title, m_argv[3], sizeof(m_JA.job_title)-1);
+ strncpy(m_JA.user_name, m_argv[2], sizeof(m_JA.user_name)-1);
+ strncpy(m_JA.host_name, uts_name.nodename, sizeof(m_JA.host_name)-1);
+ strncpy(m_JA.os_name, uts_name.sysname, sizeof(m_JA.os_name)-1);
+ getdomainname(m_JA.domain_name, sizeof(m_JA.domain_name) - 1);
+ int i = strlen(m_argv[0]) - 1;
+ while (i >= 0 && m_argv[0][i] != '/') {
+ i--;
+ }
+ snprintf(m_JA.driver_name, sizeof(m_JA.driver_name), "%s; %s", &m_argv[0][i+1], HP_FILE_VERSION_STR);
+ char *ptr = getenv("DEVICE_URI");
+ i = 0;
+ if (ptr) {
+ while (*ptr) {
+ if (*ptr == '%') {
+ ptr += 3;
+ m_JA.printer_name[i++] = ' ';
+ }
+ m_JA.printer_name[i++] = *ptr++;
+ }
+ }
+
+ string strPrinterURI="" ,strPrinterName= "";
+ m_DBusComm.initDBusComm(DBUS_PATH,DBUS_INTERFACE, getenv("DEVICE_URI"), m_JA.printer_name);
+
+ ptr = strstr(m_argv[5], "job-uuid");
+ if (ptr) {
+ strncpy(m_JA.uuid, ptr + strlen("job-uuid=urn:uuid:"), sizeof(m_JA.uuid)-1);
+ }
+
+ for (i = 0; i < 16; i++)
+ m_JA.integer_values[i] = cups_header->cupsInteger[i];
+
+ if (cups_header->cupsString[0]) {
+ strncpy(m_JA.quality_attributes.print_mode_name, &cups_header->cupsString[0][0],
+ sizeof(m_JA.quality_attributes.print_mode_name)-1);
+ }
+ Encapsulator *encap_interface = EncapsulatorFactory::GetEncapsulator(attr->value);
+ if ((err = m_Job.Init(m_pSys, &m_JA, encap_interface)) != NO_ERROR)
+ {
+ if (err == PLUGIN_LIBRARY_MISSING)
+ {
+ fputs ("STATE: +hplip.plugin-error\n", stderr);
+
+ m_DBusComm.sendEvent(EVENT_PRINT_FAILED_MISSING_PLUGIN, "Plugin missing", m_JA.job_id, m_JA.user_name);
+
+ }
+ dbglog ("m_Job initialization failed with error = %d", err);
+ ppdClose(m_ppd);
+ m_ppd = NULL;
+ return err;
+ }
+
+ if (m_iLogLevel & BASIC_LOG) {
+ dbglog("HPCUPS: returning NO_ERROR from startPage\n");
+ }
+
+ m_pPrinterBuffer = new BYTE[cups_header->cupsWidth * 4 + 32];
+
+
+ return NO_ERROR;
+}
+
+int HPCupsFilter::StartPrintJob(int argc, char *argv[])
+{
+ int fd = 0;
+ cups_raster_t *cups_raster;
+ int err = 0;
+
+ memset(&m_JA, 0, sizeof(JobAttributes));
+ struct tm *t;
+ struct timeb tb;
+ time_t long_time;
+ time(&long_time);
+ t = localtime(&long_time);
+ ftime(&tb);
+ strncpy(m_JA.job_start_time, asctime(t), sizeof(m_JA.job_start_time)-1); // returns Fri Jun 5 08:12:16 2009
+ snprintf(m_JA.job_start_time+19, sizeof(m_JA.job_start_time) - 20, ":%d %d", tb.millitm, t->tm_year + 1900); // add milliseconds
+
+ getLogLevel();
+ m_JA.job_id = atoi(argv[1]);
+ FILE *fp;
+ char dFileName[32];
+ memset(dFileName, 0, sizeof(dFileName));
+ m_JA.job_id = atoi(argv[1]);
+ snprintf (dFileName, sizeof(dFileName), "/var/spool/cups/d%05d-001", m_JA.job_id);
+ if ((fp = fopen (dFileName, "r")))
+ {
+ char line[258];
+ for (int i = 0; i < 10; i++)
+ {
+ fgets (line, 256, fp);
+ if (!strncmp (line, "%%Pages:", 8))
+ {
+ sscanf (line+9, "%d", &m_JA.total_pages);
+ break;
+ }
+ }
+ fclose (fp);
+ }
+
+ m_ppd = ppdOpenFile(getenv("PPD"));
+ if (m_ppd == NULL) {
+ dbglog("DEBUG: ppdOpenFile failed for %s\n", getenv("PPD"));
+ return SYSTEM_ERROR;
+ }
+
+ m_argv = argv;
+ if (m_iLogLevel & BASIC_LOG) {
+ for (int i = 0; i < argc; i++) {
+ dbglog("argv[%d] = %s\n", i, argv[i]);
+ }
+ }
+
+ if (argc == 7)
+ {
+ if (m_iLogLevel & BASIC_LOG)
+ {
+ dbglog("Page Stream Data Name: %s\n", argv[6] );
+ }
+ if ((fd = open (argv[6], O_RDONLY)) == -1)
+ {
+ perror("ERROR: Unable to open raster file - ");
+ return 1;
+ }
+ }
+
+ m_pSys = new SystemServices(m_iLogLevel, m_JA.job_id);
+
+/*
+ * When user cancels a print job, the spooler sends SIGTERM signal
+ * to the filter. Must catch this signal to send end job sequence
+ * to the printer.
+ */
+
+ signal(SIGTERM, HPCancelJob);
+
+ cups_raster = cupsRasterOpen(fd, CUPS_RASTER_READ);
+
+ if (cups_raster == NULL) {
+ dbglog("cupsRasterOpen failed, fd = %d\n", fd);
+ if (fd != 0) {
+ close(fd);
+ }
+ closeFilter();
+ return 1;
+ }
+
+ if ((err = processRasterData(cups_raster))) {
+ if (fd != 0) {
+ close(fd);
+ }
+ if (m_iLogLevel & BASIC_LOG)
+ dbglog("HPCUPS: processRasterData returned %d, calling closeFilter()", err);
+ closeFilter();
+ cupsRasterClose(cups_raster);
+ return 1;
+ }
+
+ if (fd != 0) {
+ close(fd);
+ }
+ if (m_iLogLevel & BASIC_LOG)
+ dbglog("HPCUPS: StartPrintJob end of job, calling closeFilter()");
+ closeFilter();
+ cupsRasterClose(cups_raster);
+ return 0;
+}
+
+bool HPCupsFilter::isBlankRaster(BYTE *input_raster, cups_page_header2_t *header)
+{
+ int length_in_bytes = (int)header->cupsBytesPerLine;
+ if (input_raster == NULL) {
+ return true;
+ }
+
+ if(header->cupsColorSpace == CUPS_CSPACE_K){
+ if (*input_raster == 0x00 &&
+ !(memcmp(input_raster + 1, input_raster, length_in_bytes - 1))) {
+ return true;
+ }
+ }
+ else{
+ if (*input_raster == 0xFF &&
+ !(memcmp(input_raster + 1, input_raster, length_in_bytes - 1))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+int HPCupsFilter::processRasterData(cups_raster_t *cups_raster)
+{
+ FILE *kfp = NULL;
+ FILE *cfp = NULL;
+ BYTE *kRaster = NULL;
+ BYTE *rgbRaster = NULL;
+ int current_page_number = 0;
+ cups_page_header2_t cups_header;
+ DRIVER_ERROR err;
+ int ret_status = 0;
+ char hpPreProcessedRasterFile[] = "/tmp/hplipSwapedPagesXXXXXX"; //temp file needed to store raster data with swaped pages.
+
+ while (cupsRasterReadHeader2(cups_raster, &cups_header))
+ {
+ current_page_number++;
+
+ if (current_page_number == 1) {
+
+ if (startPage(&cups_header) != NO_ERROR) {
+ return JOB_CANCELED;
+ }
+
+ if(m_JA.pre_process_raster) {
+ err = m_Job.preProcessRasterData(&cups_raster, &cups_header, hpPreProcessedRasterFile);
+ if (err != NO_ERROR) {
+ if (m_iLogLevel & BASIC_LOG) {
+ dbglog ("DEBUG: Job::StartPage failed with err = %d\n", err);
+ }
+ ret_status = JOB_CANCELED;
+ break;
+ }
+ }
+
+ if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW) {
+ rgbRaster = new BYTE[cups_header.cupsWidth * 3];
+ if (rgbRaster == NULL) {
+ return ALLOCMEM_ERROR;
+ }
+ kRaster = new BYTE[cups_header.cupsWidth];
+ if (kRaster == NULL) {
+ delete [] rgbRaster;
+ return ALLOCMEM_ERROR;
+ }
+ memset (kRaster, 0, cups_header.cupsWidth);
+ memset (rgbRaster, 0xFF, cups_header.cupsWidth * 3);
+ }
+ } // current_page_number == 1
+
+ if (cups_header.cupsColorSpace == CUPS_CSPACE_K) {
+ kRaster = m_pPrinterBuffer;
+ rgbRaster = NULL;
+ }
+ else if (cups_header.cupsColorSpace != CUPS_CSPACE_RGBW) {
+ rgbRaster = m_pPrinterBuffer;
+ kRaster = NULL;
+ }
+
+ BYTE *color_raster = NULL;
+ BYTE *black_raster = NULL;
+
+ err = m_Job.StartPage(&m_JA);
+ if (err != NO_ERROR) {
+ if (m_iLogLevel & BASIC_LOG) {
+ dbglog ("DEBUG: Job::StartPage failed with err = %d\n", err);
+ }
+ ret_status = JOB_CANCELED;
+ break;
+ }
+
+ if (m_iLogLevel & SAVE_INPUT_RASTERS)
+ {
+ char szFileName[32];
+ memset(szFileName, 0, sizeof(szFileName));
+ snprintf (szFileName, sizeof(szFileName), "/tmp/hpcupsfilterc_%d.bmp", current_page_number);
+ if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW ||
+ cups_header.cupsColorSpace == CUPS_CSPACE_RGB)
+ {
+ cfp = fopen (szFileName, "w");
+ chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ }
+ if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW ||
+ cups_header.cupsColorSpace == CUPS_CSPACE_K)
+ {
+ szFileName[17] = 'k';
+ kfp = fopen (szFileName, "w");
+ chmod (szFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ }
+
+ WriteBMPHeader (cfp, cups_header.cupsWidth, cups_header.cupsHeight, COLOR_RASTER);
+ WriteBMPHeader (kfp, cups_header.cupsWidth, cups_header.cupsHeight, BLACK_RASTER);
+ }
+
+ fprintf(stderr, "PAGE: %d %s\r\n", current_page_number, m_argv[4]);
+ // Iterating through the raster per page
+ for (int y = 0; y < (int) cups_header.cupsHeight; y++) {
+ cupsRasterReadPixels (cups_raster, m_pPrinterBuffer, cups_header.cupsBytesPerLine);
+ color_raster = rgbRaster;
+ black_raster = kRaster;
+
+ if(y == 0 && (0 == strcmp(m_JA.printer_language, "ljmono")) )
+ {
+ //For ljmono, make sure that first line is not a blankRaster line.Otherwise printer
+ //may not skip blank lines before actual data
+ //Need to revisit to crosscheck if it is a firmware issue.
+
+ *m_pPrinterBuffer = 0x01;
+ dbglog("First raster data plane.." );
+ }
+
+ if (this->isBlankRaster((BYTE *) m_pPrinterBuffer, &cups_header)) {
+
+ color_raster = NULL;
+ black_raster = NULL;
+ }
+ extractBlackPixels(&cups_header, black_raster, color_raster);
+ //! Sending Raster bits off to encapsulation
+ err = m_Job.SendRasters (black_raster, color_raster);
+ if (err != NO_ERROR) {
+ break;
+ }
+ WriteBMPRaster (cfp, color_raster, cups_header.cupsWidth, COLOR_RASTER);
+ WriteBMPRaster (kfp, black_raster, cups_header.cupsWidth/8, BLACK_RASTER);
+ }
+ m_Job.NewPage();
+ if (err != NO_ERROR) {
+ break;
+ }
+ }
+
+ //! Remove the old processing band data...
+ if (cups_header.cupsColorSpace == CUPS_CSPACE_RGBW) {
+ delete [] kRaster;
+ delete [] rgbRaster;
+ }
+
+ unlink(hpPreProcessedRasterFile);
+ return ret_status;
+}
+
+void HPCupsFilter::extractBlackPixels(cups_page_header2_t *cups_header, BYTE *kRaster, BYTE *rgbRaster)
+{
+/*
+ * DON'T DO BITPACKING HERE, DO IT IN HALFTONER FOR CMYK PRINTES
+ * AND IN MODE9 FOR RGB PRINTERS
+ */
+
+static BYTE pixel_value[8] = {
+ 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
+ };
+
+ if (rgbRaster == NULL) {
+ return;
+ }
+
+ if (cups_header->cupsColorSpace == CUPS_CSPACE_RGBW) {
+ int k = 0;
+ BYTE *pIn = m_pPrinterBuffer;
+ BYTE kVal = 0;
+ BYTE b;
+ BYTE *rgb = rgbRaster;
+ BYTE *black = kRaster;
+ memset (kRaster, 0, cups_header->cupsWidth);
+
+
+ for (unsigned int i = 0; i < cups_header->cupsWidth; i++) {
+ rgb[0] = *pIn++;
+ rgb[1] = *pIn++;
+ rgb[2] = *pIn++;
+ b = *pIn++;
+
+ if (b != 0 && b != 0xFF) {
+
+#ifdef __linux
+ // rgb[0] -= (255 - b);
+ // rgb[1] -= (255 - b);
+ // rgb[2] -= (255 - b);
+ int cr,cg,cb;
+ cr = rgb[0] - (int)(255 - b);
+ rgb[0] = cr >= 0 ? cr : 0;
+
+ cg = rgb[1] - (int)(255 - b);
+ rgb[1] = cg >= 0 ? cg : 0;
+
+ cb = rgb[2] - (int)(255 - b);
+ rgb[2] = cb >= 0 ? cb : 0;
+#else // This alternate path is for Mac....
+
+ rgb[0] &= b;
+ rgb[1] &= b;
+ rgb[2] &= b;
+#endif
+ }
+ else
+ kVal |= (b == 0) ? pixel_value[k] : 0;
+ // else if (rgb[0] == rgb[1] && rgb[1] ==rgb[2])
+ // kVal |= (rgb[0] == 0) ? pixel_value[k] : 0;
+ rgb += 3;
+ if (k == 7) {
+ *black++ = kVal;
+ kVal = 0;
+ k = 0;
+ }
+ else {
+ k++;
+ }
+ } // end of for loop
+ *black = kVal;
+
+ } // end of if condition
+}
+
+void HPCupsFilter::printCupsHeaderInfo(cups_page_header2_t *header)
+{
+
+ dbglog ("DEBUG: startPage...\n");
+ dbglog ("DEBUG: MediaClass = \"%s\"\n", header->MediaClass);
+ dbglog ("DEBUG: MediaColor = \"%s\"\n", header->MediaColor);
+ dbglog ("DEBUG: MediaType = \"%s\"\n", header->MediaType);
+ dbglog ("DEBUG: OutputType = \"%s\"\n", header->OutputType);
+ dbglog ("DEBUG: AdvanceDistance = %d\n", header->AdvanceDistance);
+ dbglog ("DEBUG: AdvanceMedia = %d\n", header->AdvanceMedia);
+ dbglog ("DEBUG: Collate = %d\n", header->Collate);
+ dbglog ("DEBUG: CutMedia = %d\n", header->CutMedia);
+ dbglog ("DEBUG: Duplex = %d\n", header->Duplex);
+ dbglog ("DEBUG: HWResolution = [ %d %d ]\n", header->HWResolution[0], header->HWResolution[1]);
+ dbglog ("DEBUG: ImagingBoundingBox = [ %d %d %d %d ]\n",
+ header->ImagingBoundingBox[0], header->ImagingBoundingBox[1],
+ header->ImagingBoundingBox[2], header->ImagingBoundingBox[3]);
+ dbglog ("DEBUG: InsertSheet = %d\n", header->InsertSheet);
+ dbglog ("DEBUG: Jog = %d\n", header->Jog);
+ dbglog ("DEBUG: LeadingEdge = %d\n", header->LeadingEdge);
+ dbglog ("DEBUG: Margins = [ %d %d ]\n", header->Margins[0], header->Margins[1]);
+ dbglog ("DEBUG: ManualFeed = %d\n", header->ManualFeed);
+ dbglog ("DEBUG: MediaPosition = %d\n", header->MediaPosition);
+ dbglog ("DEBUG: MediaWeight = %d\n", header->MediaWeight);
+ dbglog ("DEBUG: MirrorPrint = %d\n", header->MirrorPrint);
+ dbglog ("DEBUG: NegativePrint = %d\n", header->NegativePrint);
+ dbglog ("DEBUG: NumCopies = %d\n", header->NumCopies);
+ dbglog ("DEBUG: Orientation = %d\n", header->Orientation);
+ dbglog ("DEBUG: OutputFaceUp = %d\n", header->OutputFaceUp);
+ dbglog ("DEBUG: PageSize = [ %d %d ]\n", header->PageSize[0], header->PageSize[1]);
+ dbglog ("DEBUG: Separations = %d\n", header->Separations);
+ dbglog ("DEBUG: TraySwitch = %d\n", header->TraySwitch);
+ dbglog ("DEBUG: Tumble = %d\n", header->Tumble);
+ dbglog ("DEBUG: cupsWidth = %d\n", header->cupsWidth);
+ dbglog ("DEBUG: cupsHeight = %d\n", header->cupsHeight);
+ dbglog ("DEBUG: cupsMediaType = %d\n", header->cupsMediaType);
+ dbglog ("DEBUG: cupsRowStep = %d\n", header->cupsRowStep);
+ dbglog ("DEBUG: cupsBitsPerColor = %d\n", header->cupsBitsPerColor);
+ dbglog ("DEBUG: cupsBitsPerPixel = %d\n", header->cupsBitsPerPixel);
+ dbglog ("DEBUG: cupsBytesPerLine = %d\n", header->cupsBytesPerLine);
+ dbglog ("DEBUG: cupsColorOrder = %d\n", header->cupsColorOrder);
+ dbglog ("DEBUG: cupsColorSpace = %d\n", header->cupsColorSpace);
+ dbglog ("DEBUG: cupsCompression = %d\n", header->cupsCompression);
+ dbglog ("DEBUG: cupsPageSizeName = %s\n", header->cupsPageSizeName);
+ dbglog ("DEBUG: cupsInteger0 = %d\n", header->cupsInteger[0]); // max jpeg filesize
+ dbglog ("DEBUG: cupsInteger1 = %d\n", header->cupsInteger[1]); // Red eye removal
+ dbglog ("DEBUG: cupsInteger2 = %d\n", header->cupsInteger[2]); // Photo fix (RLT)
+ dbglog ("DEBUG: cupsString0 = %s\n", header->cupsString[0]); // print_mode_name
+ dbglog ("DEBUG: cupsReal0 = %f\n", header->cupsReal[0]); // Left overspray
+ dbglog ("DEBUG: cupsReal1 = %f\n", header->cupsReal[1]); // Top overspray
+}
+
+void HPCupsFilter::getLogLevel ()
+{
+ FILE *fp;
+ char str[258];
+ char *p;
+ fp = fopen ("/etc/cups/cupsd.conf", "r");
+ if (fp == NULL)
+ return;
+ while (!feof (fp))
+ {
+ if (!fgets (str, 256, fp))
+ {
+ break;
+ }
+ if ((p = strstr (str, "hpLogLevel")))
+ {
+ p += strlen ("hpLogLevel") + 1;
+ m_iLogLevel = atoi (p);
+ break;
+ }
+ }
+ fclose (fp);
+}
+
diff --git a/prnt/hpcups/HPCupsFilter.h b/prnt/hpcups/HPCupsFilter.h
index 4320ae52e..0431a7a6c 100644
--- a/prnt/hpcups/HPCupsFilter.h
+++ b/prnt/hpcups/HPCupsFilter.h
@@ -1,122 +1,125 @@
-/*****************************************************************************\
- HPCupsFilter.h : Interface for HPCupsFilter class
-
- Copyright (c) 1996 - 2009, Hewlett-Packard Co.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Hewlett-Packard nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-\*****************************************************************************/
-
-#ifndef HP_CUPSFILTER_H
-#define HP_CUPSFILTER_H
-
-#include "CommonDefinitions.h"
-#include "SystemServices.h"
-#include "Compressor.h"
-#include "Job.h"
-
-#define DBITMAPFILEHEADER 14
-#define DBITMAPINFOHEADER 40
-
-enum eRasterType
-{
- BLACK_RASTER,
- COLOR_RASTER
-};
-
-typedef struct
-{
- short bfType;
- int bfSize;
- short bfReserved1;
- short bfReserved2;
- int bfOffBits;
-} BITMAPFILEHEADER;
-
-typedef struct
-{
- int biSize;
- int biWidth;
- int biHeight;
- short biPlanes;
- short biBitCount;
- int biCompression;
- int biSizeImage;
- int biXPelsPerMeter;
- int biYPelsPerMeter;
- int biClrUsed;
- int biClrImportant;
-} BITMAPINFOHEADER;
-
-class HPCupsFilter
-{
-public:
-
- HPCupsFilter();
- ~HPCupsFilter();
- int StartPrintJob(int argc, char *argv[]);
- void CancelJob();
- void RemoveStatus();
-
- void WriteBMPHeader (FILE *fp, int width, int height, eRasterType raster_type);
- void WriteBMPRaster (FILE *fp, BYTE *raster, int width, eRasterType raster_type);
-
-private:
-
- BYTE *m_pPrinterBuffer;
- Job m_Job;
- SystemServices *m_pSys;
- int child_pid;
- char **m_argv;
- JobAttributes m_JA;
- ppd_file_t *m_ppd;
-
-private:
-
- void closeFilter();
- void cleanup();
- void getLogLevel();
- DRIVER_ERROR startPage (cups_page_header2_t *header);
- int processRasterData(cups_raster_t *cups_raster);
- void extractBlackPixels(cups_page_header2_t *cups_header,
- BYTE *kRaster, BYTE *rgbRaster);
- void printCupsHeaderInfo(cups_page_header2_t *header);
- bool isBlankRaster(BYTE *input_raster, cups_page_header2_t *header);
- int m_iLogLevel;
-
- void CreateBMPHeader(int width, int height, int planes, int bpp);
- void WriteCBMPHeader (FILE *fp, int width, int height);
- void WriteKBMPHeader (FILE *fp, int width, int height);
- void WriteCBMPRaster (FILE *fp, BYTE *rgb_raster, int width);
- void WriteKBMPRaster (FILE *fp, BYTE *k_raster, int width);
- int adj_c_width;
- int adj_k_width;
- BYTE *black_raster;
- BYTE *color_raster;
- BITMAPFILEHEADER bmfh;
- BITMAPINFOHEADER bmih;
-};
-
-#endif // HP_CUPSFILTER_H
-
+/*****************************************************************************\
+ HPCupsFilter.h : Interface for HPCupsFilter class
+
+ Copyright (c) 1996 - 2009, Hewlett-Packard Co.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of Hewlett-Packard nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+\*****************************************************************************/
+
+#ifndef HP_CUPSFILTER_H
+#define HP_CUPSFILTER_H
+
+#include "CommonDefinitions.h"
+#include "SystemServices.h"
+#include "Compressor.h"
+#include "Job.h"
+
+#include "dbuscomm.h"
+
+#define DBITMAPFILEHEADER 14
+#define DBITMAPINFOHEADER 40
+
+enum eRasterType
+{
+ BLACK_RASTER,
+ COLOR_RASTER
+};
+
+typedef struct
+{
+ short bfType;
+ int bfSize;
+ short bfReserved1;
+ short bfReserved2;
+ int bfOffBits;
+} BITMAPFILEHEADER;
+
+typedef struct
+{
+ int biSize;
+ int biWidth;
+ int biHeight;
+ short biPlanes;
+ short biBitCount;
+ int biCompression;
+ int biSizeImage;
+ int biXPelsPerMeter;
+ int biYPelsPerMeter;
+ int biClrUsed;
+ int biClrImportant;
+} BITMAPINFOHEADER;
+
+class HPCupsFilter
+{
+public:
+
+ HPCupsFilter();
+ ~HPCupsFilter();
+ int StartPrintJob(int argc, char *argv[]);
+ void CancelJob();
+ void RemoveStatus();
+
+ void WriteBMPHeader (FILE *fp, int width, int height, eRasterType raster_type);
+ void WriteBMPRaster (FILE *fp, BYTE *raster, int width, eRasterType raster_type);
+
+private:
+
+ BYTE *m_pPrinterBuffer;
+ Job m_Job;
+ SystemServices *m_pSys;
+ int child_pid;
+ char **m_argv;
+ JobAttributes m_JA;
+ ppd_file_t *m_ppd;
+ DBusCommunicator m_DBusComm;
+
+private:
+
+ void closeFilter();
+ void cleanup();
+ void getLogLevel();
+ DRIVER_ERROR startPage (cups_page_header2_t *header);
+ int processRasterData(cups_raster_t *cups_raster);
+ void extractBlackPixels(cups_page_header2_t *cups_header,
+ BYTE *kRaster, BYTE *rgbRaster);
+ void printCupsHeaderInfo(cups_page_header2_t *header);
+ bool isBlankRaster(BYTE *input_raster, cups_page_header2_t *header);
+ int m_iLogLevel;
+
+ void CreateBMPHeader(int width, int height, int planes, int bpp);
+ void WriteCBMPHeader (FILE *fp, int width, int height);
+ void WriteKBMPHeader (FILE *fp, int width, int height);
+ void WriteCBMPRaster (FILE *fp, BYTE *rgb_raster, int width);
+ void WriteKBMPRaster (FILE *fp, BYTE *k_raster, int width);
+ int adj_c_width;
+ int adj_k_width;
+ BYTE *black_raster;
+ BYTE *color_raster;
+ BITMAPFILEHEADER bmfh;
+ BITMAPINFOHEADER bmih;
+};
+
+#endif // HP_CUPSFILTER_H
+
diff --git a/prnt/hpcups/Job.cpp b/prnt/hpcups/Job.cpp
index 41a599f7b..90355688b 100644
--- a/prnt/hpcups/Job.cpp
+++ b/prnt/hpcups/Job.cpp
@@ -290,3 +290,10 @@ DRIVER_ERROR Job::setBlankRaster()
return NO_ERROR;
}
+DRIVER_ERROR Job::preProcessRasterData(cups_raster_t **ppcups_raster, cups_page_header2_t* firstpage_cups_header, char* pPreProcessedRasterFile)
+{
+ dbglog ("DEBUG: Job::preProcessRasterData.............. \n");
+ return m_pEncap->preProcessRasterData(ppcups_raster, firstpage_cups_header, pPreProcessedRasterFile);
+}
+
+
diff --git a/prnt/hpcups/Job.h b/prnt/hpcups/Job.h
index 1aa7862bb..4b30bac5e 100644
--- a/prnt/hpcups/Job.h
+++ b/prnt/hpcups/Job.h
@@ -49,6 +49,7 @@ public:
DRIVER_ERROR SendRasters(BYTE* BlackImageData=(BYTE*)NULL, BYTE* ColorImageData=(BYTE*)NULL);
DRIVER_ERROR NewPage();
DRIVER_ERROR StartPage(JobAttributes *job_attrs);
+ DRIVER_ERROR preProcessRasterData(cups_raster_t **cups_raster, cups_page_header2_t* firstpage_cups_header, char* pPreProcessedRasterFile);
void CancelJob();
private:
diff --git a/prnt/hpcups/LJZjStream.cpp b/prnt/hpcups/LJZjStream.cpp
index b7b58517e..35f0cd707 100644
--- a/prnt/hpcups/LJZjStream.cpp
+++ b/prnt/hpcups/LJZjStream.cpp
@@ -661,3 +661,181 @@ DRIVER_ERROR LJZjStream::encapsulateColor (RASTERDATA *raster)
return err;
}
+
+DRIVER_ERROR LJZjStream::preProcessRasterData(cups_raster_t **ppcups_raster, cups_page_header2_t* firstpage_cups_header, char* pSwapedPagesFileName)
+{
+ int current_page_number = 0;
+ int fdEven = -1;
+ int fdOdd = -1;
+ int fdSwaped = -1;
+ int loopcntr = 0;
+ DRIVER_ERROR driver_error = NO_ERROR;
+ cups_page_header2_t cups_header;
+ cups_raster_t *swaped_pages_raster=NULL;
+ cups_raster_t *even_pages_raster=NULL;
+ cups_raster_t *odd_pages_raster = NULL;
+ BYTE* pPageDataBuffer = NULL;
+ char hpEvenPagesFile[] = "/tmp/hplipEvenPagesXXXXXX";
+ char hpOddPagesFile[] = "/tmp/hplipOddPagesXXXXXX";
+
+ if (1 != m_pJA->pre_process_raster || !cups_header.Duplex){
+ return NO_ERROR;
+ }
+
+ dbglog ("DEBUG: Getting Swaped Pages Raster.....\n");
+
+ memcpy(&cups_header, firstpage_cups_header, sizeof(cups_page_header2_t));
+
+ //Create temp files to store odd, even and swaped pages.
+ fdEven = mkstemp (hpEvenPagesFile);
+ fdOdd = mkstemp (hpOddPagesFile);
+ fdSwaped = mkstemp (pSwapedPagesFileName);
+ if (fdEven < 0 || fdOdd < 0 || fdSwaped < 0){
+ dbglog ("ERROR: Unable to open temp output files for writing\n");
+ driver_error = SYSTEM_ERROR;
+ goto bugout;
+ }
+
+ even_pages_raster = cupsRasterOpen(fdEven, CUPS_RASTER_WRITE);
+ odd_pages_raster = cupsRasterOpen(fdOdd, CUPS_RASTER_WRITE);
+ if (even_pages_raster == NULL || odd_pages_raster == NULL) {
+ dbglog("cupsRasterOpen failed for even_pages_raster or odd_pages_raster\n");
+ driver_error = NULL_POINTER;
+ goto bugout;
+ }
+
+ pPageDataBuffer = new BYTE[cups_header.cupsBytesPerLine+1];
+ if (pPageDataBuffer == NULL) {
+ driver_error = ALLOCMEM_ERROR;
+ goto bugout;
+ }
+
+
+ do
+ {
+ current_page_number++;
+ if(current_page_number % 2) {
+ cupsRasterWriteHeader2(odd_pages_raster, &cups_header);
+ }
+ else {
+ cupsRasterWriteHeader2(even_pages_raster, &cups_header);
+ }
+
+ // Iterating through the raster per page
+ for (int y = 0; y < (int) cups_header.cupsHeight; y++) {
+ cupsRasterReadPixels (*ppcups_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ if(current_page_number % 2) {
+ cupsRasterWritePixels (odd_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ }
+ else {
+ cupsRasterWritePixels (even_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ }
+ }
+
+ } while (cupsRasterReadHeader2(*ppcups_raster, &cups_header));
+
+ cupsRasterClose(even_pages_raster);
+ cupsRasterClose(odd_pages_raster);
+
+ //Now read even and odd pages rasters and then put into swaped raster
+ if ((fdEven = open (hpEvenPagesFile, O_RDONLY)) == -1) {
+ perror("ERROR: Unable to open evenpage raster file for reading.");
+ driver_error = SYSTEM_ERROR;
+ goto bugout;
+ }
+
+ if ((fdOdd = open (hpOddPagesFile, O_RDONLY)) == -1){
+ perror("ERROR: Unable to open odd page raster file for writing. ");
+ driver_error = SYSTEM_ERROR;
+ goto bugout;
+ }
+ even_pages_raster = cupsRasterOpen(fdEven, CUPS_RASTER_READ);
+ odd_pages_raster = cupsRasterOpen(fdOdd, CUPS_RASTER_READ);
+ swaped_pages_raster = cupsRasterOpen(fdSwaped, CUPS_RASTER_WRITE);
+
+ if (swaped_pages_raster == NULL || even_pages_raster == NULL || odd_pages_raster == NULL) {
+ dbglog("cupsRasterOpen failed for even_pages_raster or odd_pages_raster or swaped_pages_raster\n");
+ driver_error = NULL_POINTER;
+ goto bugout;
+
+ }
+
+ loopcntr = current_page_number / 2;
+ while (loopcntr--) {
+ if(cupsRasterReadHeader2(even_pages_raster, &cups_header)){
+ cupsRasterWriteHeader2(swaped_pages_raster, &cups_header);
+
+ // Iterating through the raster per line
+ for (int y = 0; y < (int) cups_header.cupsHeight; y++){
+ cupsRasterReadPixels (even_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ cupsRasterWritePixels (swaped_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ }
+ }
+
+ if(cupsRasterReadHeader2(odd_pages_raster, &cups_header)){
+ cupsRasterWriteHeader2(swaped_pages_raster, &cups_header);
+
+ // Iterating through the raster per line
+ for (int y = 0; y < (int) cups_header.cupsHeight; y++) {
+ cupsRasterReadPixels (odd_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ cupsRasterWritePixels (swaped_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ }
+ }
+
+ }
+
+ //Last Page is in odd page file
+ if(current_page_number%2 == 1){
+ cupsRasterReadHeader2(odd_pages_raster, &cups_header);
+ cupsRasterWriteHeader2(swaped_pages_raster, &cups_header);
+
+ // Iterating through the raster per line
+ for (int y = 0; y < (int) cups_header.cupsHeight; y++){
+ cupsRasterReadPixels (odd_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ cupsRasterWritePixels (swaped_pages_raster, pPageDataBuffer, cups_header.cupsBytesPerLine);
+ }
+ }
+
+ cupsRasterClose(even_pages_raster);
+ cupsRasterClose(odd_pages_raster);
+ cupsRasterClose(swaped_pages_raster);
+
+ if(pPageDataBuffer){
+ delete [] pPageDataBuffer;
+ pPageDataBuffer = NULL;
+ }
+
+ //Now send swaped raster file further processing.
+ if ((fdSwaped = open (pSwapedPagesFileName, O_RDONLY)) == -1){
+ perror("ERROR: Unable to open swaped pages raster file - ");
+ driver_error = SYSTEM_ERROR;
+ goto bugout;
+ }
+
+ *ppcups_raster = cupsRasterOpen(fdSwaped, CUPS_RASTER_READ);
+ cupsRasterReadHeader2(*ppcups_raster, &cups_header);
+ memcpy(firstpage_cups_header, &cups_header, sizeof(cups_page_header2_t));
+ unlink(hpEvenPagesFile);
+ unlink(hpOddPagesFile);
+
+ return NO_ERROR; //cups_raster;
+
+bugout:
+ dbglog ("DEBUG:Something went wrong while creating swaped pages raster..\n");
+ if (fdEven > 2)
+ close(fdEven);
+ if (fdOdd > 2)
+ close(fdOdd);
+ if (fdSwaped > 2)
+ close(fdSwaped);
+ //closeFilter();
+
+ if(pPageDataBuffer){
+ delete [] pPageDataBuffer;
+ }
+
+ unlink(hpEvenPagesFile);
+ unlink(hpOddPagesFile);
+ return driver_error;
+}
+
diff --git a/prnt/hpcups/LJZjStream.h b/prnt/hpcups/LJZjStream.h
index 4926a2c5f..cbdcf29be 100644
--- a/prnt/hpcups/LJZjStream.h
+++ b/prnt/hpcups/LJZjStream.h
@@ -48,6 +48,7 @@ public:
DRIVER_ERROR FormFeed();
DRIVER_ERROR EndJob();
DRIVER_ERROR SendCAPy(int iOffset) {return NO_ERROR;}
+ DRIVER_ERROR preProcessRasterData(cups_raster_t **cups_raster, cups_page_header2_t* firstpage_cups_header, char* pSwapedPagesFileName);
bool CanSkipRasters() {return false;}
protected:
diff --git a/prnt/hpcups/dbuscomm.cpp b/prnt/hpcups/dbuscomm.cpp
new file mode 100644
index 000000000..dc41960c8
--- /dev/null
+++ b/prnt/hpcups/dbuscomm.cpp
@@ -0,0 +1,143 @@
+/*****************************************************************************\
+ dbuscomm.cpp : Interface for DBusCommunicator class
+
+ Copyright (c) 1996 - 2011, Hewlett-Packard Co.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of Hewlett-Packard nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Author: Amarnath Chitumalla
+\*****************************************************************************/
+
+#include "dbuscomm.h"
+
+DBusCommunicator::DBusCommunicator()
+{
+ m_strPrinterURI = "";
+ m_strPrinterName = "";
+#ifdef HAVE_DBUS
+ m_DbusConnPtr = NULL;
+#endif
+}
+/*
+*
+*
+*/
+
+
+bool DBusCommunicator::initDBusComm(string strDbusPath/*=""*/,string strInterfaceName/*=""*/,
+ string strPrinterURI/*=""*/, string strPrinterName/*= ""*/, int iJobId/*=0*/, string strUser/*=""*/)
+{
+#ifdef HAVE_DBUS
+ DBusError objError;
+ DBusError * pDBusError=&objError;
+
+ m_strPrinterURI = strPrinterURI;
+ m_strPrinterName = strPrinterName;
+ m_strDbusInterface = strInterfaceName;
+ m_strDbusPath = strDbusPath;
+ m_strUser = strUser;
+ m_iJobId = iJobId;
+
+ dbus_error_init(pDBusError);
+ m_DbusConnPtr = dbus_bus_get(DBUS_BUS_SYSTEM, pDBusError);
+ if(dbus_error_is_set(pDBusError))
+ {
+ dbglog("Error: dBus Connection Error (%s)!\n", pDBusError->message);
+ dbus_error_free(pDBusError);
+ }
+
+ if(m_DbusConnPtr == NULL)
+ {
+ dbglog("Error: dBus Connection Error (%s)!\n", pDBusError->message);
+ return false;
+ }
+#endif
+ return true;
+}
+
+bool DBusCommunicator::sendEvent(string strDbusPath,string strInterfaceName, string strDeviceURI, string strPrinterName, int iEvent,
+ string strTitle/*=""*/, int iJobId/*=0*/, string strUser/*=""*/)
+{
+#ifdef HAVE_DBUS
+
+ if(NULL == m_DbusConnPtr )
+ {
+ dbglog("Error: dBus connection ptr is NULL.\n");
+ return false;
+ }
+ if(true == strDbusPath.empty() || true == strInterfaceName.empty() || 0 == iEvent)
+ {
+ dbglog("Error: dBus service Name can't be empty. DBus Path(%s) DBus Interface (%s) Event(%d)!\n",
+ strDbusPath.c_str(), strInterfaceName.c_str(), iEvent);
+ return false;
+ }
+ DBusMessage * msg = dbus_message_new_signal(strDbusPath.c_str(), strInterfaceName.c_str(), "Event");
+ if (NULL == msg)
+ {
+ dbglog("Error: dBus dbus_message_new_signal returned error. DBus Interface (%s) Event(%d)!\n", strInterfaceName.c_str(), iEvent);
+ return false;
+ }
+
+ if (NULL == msg)
+ {
+ dbglog("dbus message is NULL!\n");
+ return false;
+ }
+ const char * stURI=strDeviceURI.c_str();
+ const char * stPRNTNM=strPrinterName.c_str();
+ const char * stUSR=strUser.c_str();
+ const char * stTtl=strTitle.c_str();
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &stURI,
+ DBUS_TYPE_STRING, &stPRNTNM,
+ DBUS_TYPE_UINT32, &iEvent,
+ DBUS_TYPE_STRING, &stUSR,
+ DBUS_TYPE_UINT32, &iJobId,
+ DBUS_TYPE_STRING, &stTtl,
+ DBUS_TYPE_INVALID);
+
+ if (!dbus_connection_send(m_DbusConnPtr , msg, NULL))
+ {
+ dbglog("dbus message send failed!\n");
+ return false;
+ }
+
+ dbus_connection_flush(m_DbusConnPtr );
+ dbus_message_unref(msg);
+
+#endif
+ return true;
+
+}
+
+bool DBusCommunicator::sendEvent(int iEvent, string strTitle/*=""*/, int iJobId/*=0*/,string strUser/*=""*/)
+{
+ return sendEvent(m_strDbusPath, m_strDbusInterface, m_strPrinterURI, m_strPrinterName, iEvent, strTitle, iJobId,strUser);
+}
+
+DBusCommunicator::~DBusCommunicator()
+{
+
+}
diff --git a/prnt/hpcups/dbuscomm.h b/prnt/hpcups/dbuscomm.h
new file mode 100644
index 000000000..9932473b9
--- /dev/null
+++ b/prnt/hpcups/dbuscomm.h
@@ -0,0 +1,81 @@
+/*****************************************************************************\
+ dbuscomm.h : Interface for DBusCommunicator class
+
+ Copyright (c) 1996 - 2011, Hewlett-Packard Co.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of Hewlett-Packard nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+\*****************************************************************************/
+
+#ifndef __DBUSCOMM_H__
+#define __DBUSCOMM_H__
+
+# include <string>
+#include "CommonDefinitions.h"
+#include "hpmud.h"
+#include <pwd.h>
+
+#ifdef HAVE_DBUS
+ #include <dbus/dbus.h>
+ #define DBUS_INTERFACE "com.hplip.StatusService"
+ #define DBUS_PATH "/"
+#else
+#define DBUS_INTERFACE ""
+#define DBUS_PATH ""
+#endif
+
+
+using namespace std;
+
+/* //DBusBusType
+ DBUS_BUS_SESSION //The login session bus.
+ DBUS_BUS_SYSTEM //The systemwide bus.
+ DBUS_BUS_STARTER //The bus that started us, if any.
+*/
+
+class DBusCommunicator
+{
+ private:
+ string m_strPrinterURI;
+ string m_strPrinterName;
+#ifdef HAVE_DBUS
+ DBusConnection *m_DbusConnPtr;
+#endif
+ string m_strDbusInterface;
+ string m_strDbusPath;
+ string m_strUser;
+ int m_iJobId;
+
+
+ public:
+ DBusCommunicator();
+ bool initDBusComm(string strDbusPath="",string strInterfaceName="", string strPrinterURI="", string strPrinterName = "",int iJobId=0, string strUser="");
+ bool sendEvent(int iEvent, string strTitle="", int iJobId=0, string strUser="");
+ bool sendEvent(string strDbusPath,string strInterfaceName, string strPrinterURI, string strPrinterName, int event, string strTitle="",int iJobId=0, string strUser="");
+ ~DBusCommunicator();
+};
+
+
+#endif // __DBUSCOMM_H__
+