#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "../lib/libprintut.h"
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
static const char *id="@(#) $Id: pcl-unprint.c,v 1.1.1.1 2003/01/27 19:05:32 jlovell Exp $";
#define READ_SIZE 1024
#define MAX_DATA 1024
FILE *read_fd,*write_fd;
char read_buffer[READ_SIZE];
char data_buffer[MAX_DATA];
char initial_command[3];
int initial_command_index;
char final_command;
int numeric_arg;
int read_pointer;
int read_size;
int eof;
int combined_command = 0;
typedef struct {
int colour_type;
int black_depth;
int cyan_depth;
int magenta_depth;
int yellow_depth;
int lcyan_depth;
int lmagenta_depth;
int image_width;
int image_height;
int compression_type;
} image_t;
typedef struct {
char **black_bufs;
int black_data_rows_per_row;
char **cyan_bufs;
int cyan_data_rows_per_row;
char **magenta_bufs;
int magenta_data_rows_per_row;
char **yellow_bufs;
int yellow_data_rows_per_row;
char **lcyan_bufs;
int lcyan_data_rows_per_row;
char **lmagenta_bufs;
int lmagenta_data_rows_per_row;
int buffer_length;
int active_height;
int output_depth;
} output_t;
#define PCL_MONO 1
#define PCL_CMY 3
#define PCL_CMYK 4
#define PCL_CMYKcm 6
#define PCL_COMPRESSION_NONE 0
#define PCL_COMPRESSION_RUNHEIGHT 1
#define PCL_COMPRESSION_TIFF 2
#define PCL_COMPRESSION_DELTA 3
#define PCL_COMPRESSION_CRDR 9
#define PCL_RESET 1
#define PCL_MEDIA_SIZE 2
#define PCL_PERF_SKIP 3
#define PCL_TOP_MARGIN 4
#define PCL_MEDIA_TYPE 5
#define PCL_MEDIA_SOURCE 6
#define PCL_SHINGLING 7
#define PCL_RASTERGRAPHICS_QUALITY 8
#define PCL_DEPLETION 9
#define PCL_CONFIGURE 10
#define PCL_RESOLUTION 11
#define PCL_COLOURTYPE 12
#define PCL_COMPRESSIONTYPE 13
#define PCL_LEFTRASTER_POS 14
#define PCL_TOPRASTER_POS 15
#define PCL_RASTER_WIDTH 16
#define PCL_RASTER_HEIGHT 17
#define PCL_START_RASTER 18
#define PCL_END_RASTER 19
#define PCL_END_COLOUR_RASTER 20
#define PCL_DATA 21
#define PCL_DATA_LAST 22
#define PCL_PRINT_QUALITY 23
#define PCL_ENTER_PJL 24
#define PCL_GRAY_BALANCE 25
#define PCL_DRIVER_CONFIG 26
#define PCL_PAGE_ORIENTATION 27
#define PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS 28
#define PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS 29
#define PCL_UNIT_OF_MEASURE 30
#define PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT 31
#define PCL_PALETTE_CONFIGURATION 32
#define PCL_LPI 33
#define PCL_CPI 34
#define PCL_PAGE_LENGTH 35
#define PCL_NUM_COPIES 36
#define PCL_DUPLEX 37
#define PCL_MEDIA_SIDE 38
#define RTL_CONFIGURE 39
#define PCL_ENTER_PCL 40
#define PCL_ENTER_HPGL2 41
#define PCL_NEGATIVE_MOTION 42
typedef struct {
const char initial_command[3];
const char final_command;
int has_data;
int command;
const char *description;
} commands_t;
const commands_t pcl_commands[] =
{
{ "E", '\0', 0, PCL_RESET, "PCL RESET" },
{ "%", 'A', 0, PCL_ENTER_PCL, "PCL mode" },
{ "%", 'B', 0, PCL_ENTER_HPGL2, "HPGL/2 mode" },
{ "%", 'X', 0, PCL_ENTER_PJL, "PJL mode" },
{ "&a", 'G', 0, PCL_MEDIA_SIDE, "Set Media Side" },
{ "&a", 'H', 0, PCL_LEFTRASTER_POS, "Left Raster Position" },
{ "&a", 'N', 0, PCL_NEGATIVE_MOTION, "Negative Motion" },
{ "&a", 'V', 0, PCL_TOPRASTER_POS, "Top Raster Position" },
{ "&k", 'H', 0, PCL_CPI, "Characters per Inch" },
{ "&l", 'A', 0, PCL_MEDIA_SIZE , "Media Size" },
{ "&l", 'D', 0, PCL_LPI , "Lines per Inch" },
{ "&l", 'E', 0, PCL_TOP_MARGIN , "Top Margin" },
{ "&l", 'H', 0, PCL_MEDIA_SOURCE, "Media Source" },
{ "&l", 'L', 0, PCL_PERF_SKIP , "Perf. Skip" },
{ "&l", 'M', 0, PCL_MEDIA_TYPE , "Media Type" },
{ "&l", 'O', 0, PCL_PAGE_ORIENTATION, "Page Orientation" },
{ "&l", 'P', 0, PCL_PAGE_LENGTH, "Page Length in Lines" },
{ "&l", 'S', 0, PCL_DUPLEX, "Duplex mode" },
{ "&l", 'X', 0, PCL_NUM_COPIES, "Number of copies" },
{ "&u", 'D', 0, PCL_UNIT_OF_MEASURE, "Unit of Measure" },
{ "*b", 'B', 0, PCL_GRAY_BALANCE, "Gray Balance" },
{ "*b", 'M', 0, PCL_COMPRESSIONTYPE, "Compression Type" },
{ "*b", 'V', 1, PCL_DATA, "Data, intermediate" },
{ "*b", 'W', 1, PCL_DATA_LAST, "Data, last" },
{ "*b", 'Y', 0, PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT, "Relative Vertical Pixel Movement" },
{ "*d", 'W', 1, PCL_PALETTE_CONFIGURATION, "Palette Configuration" },
{ "*g", 'W', 1, PCL_CONFIGURE, "Configure Raster Data" },
{ "*o", 'D', 0, PCL_DEPLETION, "Depletion" },
{ "*o", 'M', 0, PCL_PRINT_QUALITY, "Print Quality" },
{ "*o", 'Q', 0, PCL_SHINGLING, "Raster Graphics Shingling" },
{ "*o", 'W', 1, PCL_DRIVER_CONFIG, "Driver Configuration Command" },
{ "*p", 'X', 0, PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS, "Horizontal Cursor Positioning by Dots" },
{ "*p", 'Y', 0, PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS, "Vertical Cursor Positioning by Dots" },
{ "*r", 'A', 0, PCL_START_RASTER, "Start Raster Graphics" },
{ "*r", 'B', 0, PCL_END_RASTER, "End Raster Graphics"},
{ "*r", 'C', 0, PCL_END_COLOUR_RASTER, "End Colour Raster Graphics" },
{ "*r", 'Q', 0, PCL_RASTERGRAPHICS_QUALITY, "Raster Graphics Quality" },
{ "*r", 'S', 0, PCL_RASTER_WIDTH, "Raster Width" },
{ "*r", 'T', 0, PCL_RASTER_HEIGHT, "Raster Height" },
{ "*r", 'U', 0, PCL_COLOURTYPE, "Colour Type" },
{ "*t", 'R', 0, PCL_RESOLUTION, "Resolution" },
{ "*v", 'W', 1, RTL_CONFIGURE, "RTL Configure Image Data" },
};
int pcl_find_command (void);
void fill_buffer (void);
void pcl_read_command (void);
void write_grey (output_t *output, image_t *image);
void write_colour (output_t *output, image_t *image);
int decode_tiff (char *in_buffer, int data_height, char *decode_buf,
int maxlen);
void pcl_reset (image_t *i);
int depth_to_rows (int depth);
int pcl_find_command(void)
{
int num_commands = sizeof(pcl_commands) / sizeof(commands_t);
int i;
for (i=0; i < num_commands; i++) {
if ((strcmp(initial_command, pcl_commands[i].initial_command) == 0) &&
(final_command == pcl_commands[i].final_command))
return(i);
}
return (-1);
}
void fill_buffer(void)
{
if ((read_pointer == -1) || (read_pointer >= read_size)) {
read_size = (int) fread(&read_buffer, sizeof(char), READ_SIZE, read_fd);
#ifdef DEBUG
fprintf(stderr, "Read %d characters\n", read_size);
#endif
if (read_size == 0) {
#ifdef DEBUG
fprintf(stderr, "No More to read!\n");
#endif
eof = 1;
return;
}
read_pointer = 0;
}
}
void pcl_read_command(void)
{
char c;
int minus;
int skipped_chars;
#define PCL_DIGIT(c) (((unsigned int) c >= 48) && ((unsigned int) c <= 57))
#define PCL_TWOCHAR(c) (((unsigned int) c >= 48) && ((unsigned int) c <= 126))
#define PCL_PARAM(c) (((unsigned int) c >= 33) && ((unsigned int) c <= 47))
#define PCL_PARAM2(c) (((unsigned int) c >= 96) && ((unsigned int) c <= 126))
#define PCL_COMBINED_TERM(c) (((unsigned int) c >= 96) && ((unsigned int) c <= 126))
#define PCL_TERM(c) (((unsigned int) c >= 64) && ((unsigned int) c <= 94))
#define PCL_CONVERT_TERM(c) (c - (char) 32)
numeric_arg=0;
minus = 0;
final_command = '\0';
fill_buffer();
if (eof == 1)
return;
c = read_buffer[read_pointer++];
#ifdef DEBUG
fprintf(stderr, "Got %c\n", c);
#endif
if (combined_command == 0) {
if(c != (char) 0x1b) {
fprintf(stderr, "ERROR: No ESC found (out of sync?) searching... ");
skipped_chars = 0;
while (c != (char) 0x1b) {
skipped_chars++;
fill_buffer();
if (eof == 1) {
fprintf(stderr, "ERROR: EOF looking for ESC!\n");
return;
}
c = read_buffer[read_pointer++];
}
fprintf(stderr, "%d characters skipped.\n", skipped_chars);
}
initial_command_index=0;
initial_command[initial_command_index] = '\0';
fill_buffer();
if (eof == 1) {
fprintf(stderr, "ERROR: EOF after ESC!\n");
return;
}
c = read_buffer[read_pointer++];
initial_command[initial_command_index++] = c;
#ifdef DEBUG
fprintf(stderr, "Got %c\n", c);
#endif
if (PCL_TWOCHAR(c)) {
#ifdef DEBUG
fprintf(stderr, "Two character command\n");
#endif
initial_command[initial_command_index] = '\0';
return;
}
else if (PCL_PARAM(c)) {
#ifdef DEBUG
fprintf(stderr, "Parameterised command\n");
#endif
fill_buffer();
if (eof == 1) {
#ifdef DEBUG
fprintf(stderr, "EOF in middle of command!\n");
#endif
eof = 0;
initial_command[initial_command_index] = '\0';
return;
}
c = read_buffer[read_pointer++];
#ifdef DEBUG
fprintf(stderr, "Got %c\n", c);
#endif
if (PCL_PARAM2(c)) {
initial_command[initial_command_index++] = c;
initial_command[initial_command_index] = '\0';
fill_buffer();
if (eof == 1) {
#ifdef DEBUG
fprintf(stderr, "EOF in middle of command!\n");
#endif
eof = 0;
return;
}
c = read_buffer[read_pointer++];
#ifdef DEBUG
fprintf(stderr, "Got %c\n", c);
#endif
}
else {
if (initial_command[0] == '%') {
#ifdef DEBUG
fprintf(stderr, "ESC%% commmand\n");
#endif
initial_command[initial_command_index] = '\0';
}
else {
fprintf(stderr, "ERROR: Illegal second character %c in parameterised command.\n",
c);
initial_command[initial_command_index] = '\0';
return;
}
}
}
else {
fprintf(stderr, "ERROR: Illegal first character %c in command.\n",
c);
initial_command[initial_command_index] = '\0';
return;
}
}
if ((c == '-') || (c == '+') || (PCL_DIGIT(c))) {
if (c == '-')
minus = 1;
else if (c == '+')
minus = 0;
else
numeric_arg = (int) (c - '0');
while (1) {
fill_buffer();
if (eof == 1) {
fprintf(stderr, "ERROR: EOF in middle of command!\n");
return;
}
c = read_buffer[read_pointer++];
#ifdef DEBUG
fprintf(stderr, "Got %c\n", c);
#endif
if (! PCL_DIGIT(c)) {
break;
}
numeric_arg = (10 * numeric_arg) + (int) (c - '0');
}
}
combined_command = (PCL_COMBINED_TERM(c) != 0);
if (combined_command == 1) {
#ifdef DEBUG
fprintf(stderr, "Combined command\n");
#endif
final_command = PCL_CONVERT_TERM(c);
}
else
final_command = c;
if (minus == 1)
numeric_arg = -numeric_arg;
return;
}
void write_grey(output_t *output,
image_t *image)
{
int wholebytes = image->image_width / 8;
int crumbs = image->image_width - (wholebytes * 8);
char *buf = output->black_bufs[0];
int i, j;
char tb[8];
#ifdef DEBUG
fprintf(stderr, "Data Height: %d, wholebytes: %d, crumbs: %d\n",
output->active_height, wholebytes, crumbs);
#endif
for (i=0; i < wholebytes; i++) {
for (j=0; j < 8; j++) {
tb[j] = (((buf[i] >> (7-j)) & 1));
tb[j] = output->output_depth - tb[j];
}
(void) fwrite(&tb[0], sizeof(char), 8, write_fd);
}
for (j=0; j < crumbs; j++) {
tb[j] = (((buf[wholebytes] >> (7-j)) & 1));
tb[j] = output->output_depth - tb[j];
}
(void) fwrite(&tb[0], sizeof(char), (size_t) crumbs, write_fd);
}
void write_colour(output_t *output,
image_t *image)
{
int wholebytes = image->image_width / 8;
int crumbs = image->image_width - (wholebytes * 8);
int i, j, jj;
char tb[8*3];
char *cyan_buf;
char *magenta_buf;
char *yellow_buf;
char *black_buf;
cyan_buf = output->cyan_bufs[0];
magenta_buf = output->magenta_bufs[0];
yellow_buf = output->yellow_bufs[0];
if (image->colour_type != PCL_CMY)
black_buf = output->black_bufs[0];
else
black_buf = NULL;
#ifdef DEBUG
fprintf(stderr, "Data Height: %d, wholebytes: %d, crumbs: %d, planes: %d\n",
output->active_height, wholebytes, crumbs, image->colour_type);
fprintf(stderr, "Cyan: ");
for (i=0; i < output->active_height; i++) {
fprintf(stderr, "%02x ", (unsigned char) cyan_buf[i]);
}
fprintf(stderr, "\n");
fprintf(stderr, "Magenta: ");
for (i=0; i < output->active_height; i++) {
fprintf(stderr, "%02x ", (unsigned char) magenta_buf[i]);
}
fprintf(stderr, "\n");
fprintf(stderr, "Yellow: ");
for (i=0; i < output->active_height; i++) {
fprintf(stderr, "%02x ", (unsigned char) yellow_buf[i]);
}
fprintf(stderr, "\n");
if (image->colour_type == PCL_CMYK) {
fprintf(stderr, "Black: ");
for (i=0; i < output->active_height; i++) {
fprintf(stderr, "%02x ", (unsigned char) black_buf[i]);
}
fprintf(stderr, "\n");
}
#endif
if (image->colour_type == PCL_CMY) {
for (i=0; i < wholebytes; i++) {
for (j=0,jj=0; j < 8; j++,jj+=3) {
tb[jj] = (((cyan_buf[i] >> (7-j)) & 1));
tb[jj] = output->output_depth - tb[jj];
tb[jj+1] = (((magenta_buf[i] >> (7-j)) & 1));
tb[jj+1] = output->output_depth - tb[jj+1];
tb[jj+2] = (((yellow_buf[i] >> (7-j)) & 1));
tb[jj+2] = output->output_depth - tb[jj+2];
}
(void) fwrite(&tb[0], sizeof(char), (size_t) (8*3), write_fd);
}
for (j=0,jj=0; j < crumbs; j++,jj+=3) {
tb[jj] = (((cyan_buf[wholebytes] >> (7-j)) & 1));
tb[jj] = output->output_depth - tb[jj];
tb[jj+1] = (((magenta_buf[wholebytes] >> (7-j)) & 1));
tb[jj+1] = output->output_depth - tb[jj+1];
tb[jj+2] = (((yellow_buf[wholebytes] >> (7-j)) & 1));
tb[jj+2] = output->output_depth - tb[jj+2];
}
(void) fwrite(&tb[0], sizeof(char), (size_t) crumbs*3, write_fd);
}
else {
for (i=0; i < wholebytes; i++) {
for (j=0,jj=0; j < 8; j++,jj+=3) {
#if !defined OUTPUT_CMYK_ONLY_K && !defined OUTPUT_CMYK_ONLY_CMY
tb[jj] = ((((cyan_buf[i]|black_buf[i]) >> (7-j)) & 1));
tb[jj+1] = ((((magenta_buf[i]|black_buf[i]) >> (7-j)) & 1));
tb[jj+2] = ((((yellow_buf[i]|black_buf[i]) >> (7-j)) & 1));
#endif
#ifdef OUTPUT_CMYK_ONLY_K
tb[jj] = (((black_buf[i] >> (7-j)) & 1));
tb[jj+1] = (((black_buf[i] >> (7-j)) & 1));
tb[jj+2] = (((black_buf[i] >> (7-j)) & 1));
#endif
#ifdef OUTPUT_CMYK_ONLY_CMY
tb[jj] = (((cyan_buf[i] >> (7-j)) & 1));
tb[jj+1] = (((magenta_buf[i] >> (7-j)) & 1));
tb[jj+2] = (((yellow_buf[i] >> (7-j)) & 1));
#endif
tb[jj] = output->output_depth - tb[jj];
tb[jj+1] = output->output_depth - tb[jj+1];
tb[jj+2] = output->output_depth - tb[jj+2];
}
(void) fwrite(&tb[0], sizeof(char), (size_t) (8*3), write_fd);
}
for (j=0,jj=0; j < crumbs; j++,jj+=3) {
#if !defined OUTPUT_CMYK_ONLY_K && !defined OUTPUT_CMYK_ONLY_CMY
tb[jj] = ((((cyan_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1));
tb[jj+1] = ((((magenta_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1));
tb[jj+2] = ((((yellow_buf[wholebytes]|black_buf[wholebytes]) >> (7-j)) & 1));
#endif
#ifdef OUTPUT_CMYK_ONLY_K
tb[jj] = (((black_buf[wholebytes] >> (7-j)) & 1));
tb[jj+1] = (((black_buf[wholebytes] >> (7-j)) & 1));
tb[jj+2] = (((black_buf[wholebytes] >> (7-j)) & 1));
#endif
#ifdef OUTPUT_CMYK_ONLY_CMY
tb[jj] = (((cyan_buf[wholebytes] >> (7-j)) & 1));
tb[jj+1] = (((magenta_buf[wholebytes] >> (7-j)) & 1));
tb[jj+2] = (((yellow_buf[wholebytes] >> (7-j)) & 1));
#endif
tb[jj] = output->output_depth - tb[jj];
tb[jj+1] = output->output_depth - tb[jj+1];
tb[jj+2] = output->output_depth - tb[jj+2];
}
(void) fwrite(&tb[0], sizeof(char), (size_t) crumbs*3, write_fd);
}
}
int decode_tiff(char *in_buffer,
int data_height,
char *decode_buf,
int maxlen)
{
int count;
int pos = 0;
int dpos = 0;
#ifdef DEBUG
int i;
#endif
while(pos < data_height ) {
count = in_buffer[pos];
if ((count >= 0) && (count <= 127)) {
#ifdef DEBUG
fprintf(stderr, "%d bytes of nonrepeated data\n", count+1);
fprintf(stderr, "DATA: ");
for (i=0; i< (count+1); i++) {
fprintf(stderr, "%02x ", (unsigned char) in_buffer[pos + 1 + i]);
}
fprintf(stderr, "\n");
#endif
if ((dpos + count + 1) > maxlen) {
fprintf(stderr, "ERROR: Too much expanded data (%d)!\n", dpos + count + 1);
exit(EXIT_FAILURE);
}
memcpy(&decode_buf[dpos], &in_buffer[pos+1], (size_t) (count + 1));
dpos += count + 1;
pos += count + 2;
}
else if ((count >= -127) && (count < 0)) {
#ifdef DEBUG
fprintf(stderr, "%02x repeated %d times\n", (unsigned char) in_buffer[pos + 1], 1 - count);
#endif
if ((dpos + 1 - count) > maxlen) {
fprintf(stderr, "ERROR: Too much expanded data (%d)!\n", dpos + 1 - count);
exit(EXIT_FAILURE);
}
memset(&decode_buf[dpos], in_buffer[pos + 1], (size_t) (1 - count));
dpos += 1 - count;
pos += 2;
}
else {
fprintf(stderr, "ERROR: Illegal TIFF count: %d, skipped\n", count);
pos += 2;
}
}
#ifdef DEBUG
fprintf(stderr, "TIFFOUT: ");
for (i=0; i< dpos; i++) {
fprintf(stderr, "%02x ", (unsigned char) decode_buf[i]);
}
fprintf(stderr, "\n");
#endif
return(dpos);
}
void pcl_reset(image_t *i)
{
i->colour_type = PCL_MONO;
i->black_depth = 2;
i->cyan_depth = 0;
i->magenta_depth = 0;
i->yellow_depth = 0;
i->lcyan_depth = 0;
i->lmagenta_depth = 0;
i->image_width = -1;
i->image_height = -1;
i->compression_type = 0;
}
int depth_to_rows(int depth)
{
int rows;
if (depth == 0)
return(0);
for (rows = 1; rows < 8; rows++) {
if ((depth >> rows) == 1)
return(rows);
}
fprintf(stderr, "ERROR: depth %d too big to handle in depth_to_rows()!\n",
depth);
return(0);
}
int main(int argc, char *argv[])
{
int command_index;
int command;
int i, j;
int image_row_counter = -1;
int current_data_row = -1;
int expected_data_rows_per_row = -1;
image_t image_data;
long filepos = -1;
output_t output_data;
char **received_rows;
output_data.black_bufs = NULL;
output_data.black_data_rows_per_row = 0;
output_data.cyan_bufs = NULL;
output_data.cyan_data_rows_per_row = 0;
output_data.magenta_bufs = NULL;
output_data.magenta_data_rows_per_row = 0;
output_data.yellow_bufs = NULL;
output_data.yellow_data_rows_per_row = 0;
output_data.lcyan_bufs = NULL;
output_data.lcyan_data_rows_per_row = 0;
output_data.lmagenta_bufs = NULL;
output_data.lmagenta_data_rows_per_row = 0;
output_data.buffer_length = 0;
output_data.active_height = 0;
output_data.output_depth = 0;
id = id;
received_rows = NULL;
if(argc == 1){
read_fd = stdin;
write_fd = stdout;
}
else if(argc == 2){
read_fd = fopen(argv[1],"r");
write_fd = stdout;
}
else {
if(*argv[1] == '-'){
read_fd = stdin;
write_fd = fopen(argv[2],"w");
}
else {
read_fd = fopen(argv[1],"r");
write_fd = fopen(argv[2],"w");
}
}
if (read_fd == (FILE *)NULL) {
fprintf(stderr, "ERROR: Error Opening input file.\n");
exit (EXIT_FAILURE);
}
if (write_fd == (FILE *)NULL) {
fprintf(stderr, "ERROR: Error Opening output file.\n");
exit (EXIT_FAILURE);
}
read_pointer=-1;
eof=0;
initial_command_index=0;
initial_command[initial_command_index] = '\0';
numeric_arg=0;
final_command = '\0';
pcl_reset(&image_data);
while (1) {
pcl_read_command();
if (eof == 1) {
#ifdef DEBUG
fprintf(stderr, "EOF while reading command.\n");
#endif
(void) fclose(read_fd);
(void) fclose(write_fd);
exit(EXIT_SUCCESS);
}
#ifdef DEBUG
fprintf(stderr, "initial_command: %s, numeric_arg: %d, final_command: %c\n",
initial_command, numeric_arg, final_command);
#endif
command_index = pcl_find_command();
if (command_index == -1) {
fprintf(stderr, "ERROR: Unknown (and unhandled) command: %s%d%c\n", initial_command,
numeric_arg, final_command);
}
else {
command = pcl_commands[command_index].command;
if (pcl_commands[command_index].has_data == 1) {
#ifdef DEBUG
fprintf(stderr, "Data: ");
#endif
if (numeric_arg > MAX_DATA) {
fprintf(stderr, "ERROR: Too much data (%d), increase MAX_DATA!\n", numeric_arg);
exit(EXIT_FAILURE);
}
for (i=0; i < numeric_arg; i++) {
fill_buffer();
if (eof == 1) {
fprintf(stderr, "ERROR: Unexpected EOF whilst reading data\n");
exit(EXIT_FAILURE);
}
data_buffer[i] = read_buffer[read_pointer++];
#ifdef DEBUG
fprintf(stderr, "%02x ", (unsigned char) data_buffer[i]);
#endif
}
#ifdef DEBUG
fprintf(stderr, "\n");
#endif
}
switch(command) {
case PCL_RESET :
fprintf(stderr, "%s\n", pcl_commands[command_index].description);
pcl_reset(&image_data);
break;
case PCL_START_RASTER :
fprintf(stderr, "%s\n", pcl_commands[command_index].description);
i = 0;
if (image_data.image_width == -1) {
fprintf(stderr, "ERROR: Image width not set!\n");
i++;
}
if (image_data.image_height == -1) {
fprintf(stderr, "WARNING: Image height not set!\n");
}
if ((image_data.black_depth != 0) &&
(image_data.black_depth != 2)) {
fprintf(stderr, "WARNING: Only 2 level black dithers handled.\n");
}
if ((image_data.cyan_depth != 0) &&
(image_data.cyan_depth != 2)) {
fprintf(stderr, "WARNING: Only 2 level cyan dithers handled.\n");
}
if ((image_data.magenta_depth != 0) &&
(image_data.magenta_depth != 2)) {
fprintf(stderr, "WARNING: Only 2 level magenta dithers handled.\n");
}
if ((image_data.yellow_depth != 0) &&
(image_data.yellow_depth != 2)) {
fprintf(stderr, "WARNING: only 2 level yellow dithers handled.\n");
}
if (image_data.lcyan_depth != 0) {
fprintf(stderr, "WARNING: Light cyan dithers not yet handled.\n");
}
if (image_data.lmagenta_depth != 0) {
fprintf(stderr, "WARNING: Light magenta dithers not yet handled.\n");
}
if ((image_data.compression_type != PCL_COMPRESSION_NONE) &&
(image_data.compression_type != PCL_COMPRESSION_TIFF)) {
fprintf(stderr,
"Sorry, only 'no compression' or 'tiff compression' handled.\n");
i++;
}
if (i != 0) {
fprintf(stderr, "Cannot continue.\n");
exit (EXIT_FAILURE);
}
if (image_data.colour_type == PCL_MONO)
(void) fputs("P5\n", write_fd);
else
(void) fputs("P6\n", write_fd);
(void) fputs("# Written by pclunprint.\n", write_fd);
filepos = ftell(write_fd);
fprintf(write_fd, "%10d %10d\n", image_data.image_width,
image_data.image_height);
if (image_data.black_depth != 0)
output_data.output_depth = image_data.black_depth - 1;
else
output_data.output_depth = image_data.cyan_depth - 1;
fprintf(write_fd, "%d\n", output_data.output_depth);
image_row_counter = 0;
current_data_row = 0;
output_data.black_data_rows_per_row = depth_to_rows(image_data.black_depth);
output_data.cyan_data_rows_per_row = depth_to_rows(image_data.cyan_depth);
output_data.magenta_data_rows_per_row = depth_to_rows(image_data.magenta_depth);
output_data.yellow_data_rows_per_row = depth_to_rows(image_data.yellow_depth);
output_data.lcyan_data_rows_per_row = depth_to_rows(image_data.lcyan_depth);
output_data.lmagenta_data_rows_per_row = depth_to_rows(image_data.lmagenta_depth);
output_data.buffer_length = (image_data.image_width + 7) / 8;
if (output_data.black_data_rows_per_row != 0) {
output_data.black_bufs = xmalloc(output_data.black_data_rows_per_row * sizeof (char *));
for (i=0; i < output_data.black_data_rows_per_row; i++) {
output_data.black_bufs[i] = xmalloc(output_data.buffer_length * sizeof (char));
}
}
if (output_data.cyan_data_rows_per_row != 0) {
output_data.cyan_bufs = xmalloc(output_data.cyan_data_rows_per_row * sizeof (char *));
for (i=0; i < output_data.cyan_data_rows_per_row; i++) {
output_data.cyan_bufs[i] = xmalloc(output_data.buffer_length * sizeof (char));
}
}
if (output_data.magenta_data_rows_per_row != 0) {
output_data.magenta_bufs = xmalloc(output_data.magenta_data_rows_per_row * sizeof (char *));
for (i=0; i < output_data.magenta_data_rows_per_row; i++) {
output_data.magenta_bufs[i] = xmalloc(output_data.buffer_length * sizeof (char));
}
}
if (output_data.yellow_data_rows_per_row != 0) {
output_data.yellow_bufs = xmalloc(output_data.yellow_data_rows_per_row * sizeof (char *));
for (i=0; i < output_data.yellow_data_rows_per_row; i++) {
output_data.yellow_bufs[i] = xmalloc(output_data.buffer_length * sizeof (char));
}
}
if (output_data.lcyan_data_rows_per_row != 0) {
output_data.lcyan_bufs = xmalloc(output_data.lcyan_data_rows_per_row * sizeof (char *));
for (i=0; i < output_data.lcyan_data_rows_per_row; i++) {
output_data.lcyan_bufs[i] = xmalloc(output_data.buffer_length * sizeof (char));
}
}
if (output_data.lmagenta_data_rows_per_row != 0) {
output_data.lmagenta_bufs = xmalloc(output_data.lmagenta_data_rows_per_row * sizeof (char *));
for (i=0; i < output_data.lmagenta_data_rows_per_row; i++) {
output_data.lmagenta_bufs[i] = xmalloc(output_data.buffer_length * sizeof (char));
}
}
expected_data_rows_per_row = output_data.black_data_rows_per_row +
output_data.cyan_data_rows_per_row + output_data.magenta_data_rows_per_row +
output_data.yellow_data_rows_per_row + output_data.lcyan_data_rows_per_row +
output_data.lmagenta_data_rows_per_row;
received_rows = xmalloc(expected_data_rows_per_row * sizeof(char *));
j = 0;
for (i = 0; i < output_data.black_data_rows_per_row; i++)
received_rows[j++] = output_data.black_bufs[i];
for (i = 0; i < output_data.cyan_data_rows_per_row; i++)
received_rows[j++] = output_data.cyan_bufs[i];
for (i = 0; i < output_data.magenta_data_rows_per_row; i++)
received_rows[j++] = output_data.magenta_bufs[i];
for (i = 0; i < output_data.yellow_data_rows_per_row; i++)
received_rows[j++] = output_data.yellow_bufs[i];
for (i = 0; i < output_data.lcyan_data_rows_per_row; i++)
received_rows[j++] = output_data.lcyan_bufs[i];
for (i = 0; i < output_data.lmagenta_data_rows_per_row; i++)
received_rows[j++] = output_data.lmagenta_bufs[i];
break;
case PCL_END_RASTER :
case PCL_END_COLOUR_RASTER :
fprintf(stderr, "%s\n", pcl_commands[command_index].description);
if (image_data.image_height == -1) {
image_data.image_height = image_row_counter;
if (fseek(write_fd, filepos, SEEK_SET) != -1) {
fprintf(write_fd, "%10d %10d\n", image_data.image_width,
image_data.image_height);
fseek(write_fd, 0L, SEEK_END);
}
}
if (image_row_counter != image_data.image_height)
fprintf(stderr, "ERROR: Row count mismatch. Expected %d rows, got %d rows.\n",
image_data.image_height, image_row_counter);
else
fprintf(stderr, "\t%d rows processed.\n", image_row_counter);
image_data.image_height = -1;
if (output_data.black_data_rows_per_row != 0) {
for (i=0; i < output_data.black_data_rows_per_row; i++) {
free(output_data.black_bufs[i]);
}
free(output_data.black_bufs);
output_data.black_bufs = NULL;
}
if (output_data.cyan_data_rows_per_row != 0) {
for (i=0; i < output_data.cyan_data_rows_per_row; i++) {
free(output_data.cyan_bufs[i]);
}
free(output_data.cyan_bufs);
output_data.cyan_bufs = NULL;
}
if (output_data.magenta_data_rows_per_row != 0) {
for (i=0; i < output_data.magenta_data_rows_per_row; i++) {
free(output_data.magenta_bufs[i]);
}
free(output_data.magenta_bufs);
output_data.magenta_bufs = NULL;
}
if (output_data.yellow_data_rows_per_row != 0) {
for (i=0; i < output_data.yellow_data_rows_per_row; i++) {
free(output_data.yellow_bufs[i]);
}
free(output_data.yellow_bufs);
output_data.yellow_bufs = NULL;
}
if (output_data.lcyan_data_rows_per_row != 0) {
for (i=0; i < output_data.lcyan_data_rows_per_row; i++) {
free(output_data.lcyan_bufs[i]);
}
free(output_data.lcyan_bufs);
output_data.lcyan_bufs = NULL;
}
if (output_data.lmagenta_data_rows_per_row != 0) {
for (i=0; i < output_data.lmagenta_data_rows_per_row; i++) {
free(output_data.lmagenta_bufs[i]);
}
free(output_data.lmagenta_bufs);
output_data.lmagenta_bufs = NULL;
}
free(received_rows);
received_rows = NULL;
break;
case PCL_MEDIA_SIZE :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 2 :
fprintf(stderr, "Letter\n");
break;
case 3 :
fprintf(stderr, "Legal\n");
break;
case 6 :
fprintf(stderr, "Tabloid\n");
break;
case 26 :
fprintf(stderr, "A4\n");
break;
case 27 :
fprintf(stderr, "A3\n");
break;
case 101 :
fprintf(stderr, "Custom\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_MEDIA_TYPE :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 0 :
fprintf(stderr, "Plain\n");
break;
case 1 :
fprintf(stderr, "Bond\n");
break;
case 2 :
fprintf(stderr, "Premium\n");
break;
case 3 :
fprintf(stderr, "Glossy/Photo\n");
break;
case 4 :
fprintf(stderr, "Transparency\n");
break;
case 5 :
fprintf(stderr, "Quick-dry Photo\n");
break;
case 6 :
fprintf(stderr, "Quick-dry Transparency\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_MEDIA_SOURCE :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 0 :
fprintf(stderr, "EJECT\n");
break;
case 1 :
fprintf(stderr, "LJ Tray 2 or Portable CSF or DJ Tray\n");
break;
case 2 :
fprintf(stderr, "Manual\n");
break;
case 3 :
fprintf(stderr, "Envelope\n");
break;
case 4 :
fprintf(stderr, "LJ Tray 3 or Desktop CSF or DJ Tray 2\n");
break;
case 5 :
fprintf(stderr, "LJ Tray 4 or DJ optional\n");
break;
case 7 :
fprintf(stderr, "DJ Autosource\n");
break;
case 8 :
fprintf(stderr, "LJ Tray 1\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_SHINGLING :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 0 :
fprintf(stderr, "None\n");
break;
case 1 :
fprintf(stderr, "2 passes\n");
break;
case 2 :
fprintf(stderr, "4 passes\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_RASTERGRAPHICS_QUALITY :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 0 :
fprintf(stderr, "(set by printer controls)\n");
case 1 :
fprintf(stderr, "Draft\n");
break;
case 2 :
fprintf(stderr, "High\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_DEPLETION :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 1 :
fprintf(stderr, "None\n");
break;
case 2 :
fprintf(stderr, "25%%\n");
break;
case 3 :
fprintf(stderr, "50%%\n");
break;
case 5 :
fprintf(stderr, "50%% with gamma correction\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_PRINT_QUALITY :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case -1 :
fprintf(stderr, "Draft\n");
break;
case 0 :
fprintf(stderr, "Normal\n");
break;
case 1 :
fprintf(stderr, "Presentation\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", numeric_arg);
break;
}
break;
case PCL_RELATIVE_VERTICAL_PIXEL_MOVEMENT :
fprintf(stderr, "%s: %d\n", pcl_commands[command_index].description, numeric_arg);
if (expected_data_rows_per_row == -1)
fprintf(stderr, "ERROR: raster data without start raster!\n");
for (i=0; i<expected_data_rows_per_row; i++)
{
memset(received_rows[i], 0, (size_t) output_data.buffer_length * sizeof(char));
}
for (i=0; i<numeric_arg; i++)
{
if (image_data.colour_type == PCL_MONO)
write_grey(&output_data, &image_data);
else
write_colour(&output_data, &image_data);
image_row_counter++;
}
break;
case PCL_PERF_SKIP :
case PCL_TOP_MARGIN :
case PCL_RESOLUTION :
case PCL_LEFTRASTER_POS :
case PCL_TOPRASTER_POS :
case PCL_VERTICAL_CURSOR_POSITIONING_BY_DOTS :
case PCL_HORIZONTAL_CURSOR_POSITIONING_BY_DOTS :
case PCL_PALETTE_CONFIGURATION :
case PCL_UNIT_OF_MEASURE :
case PCL_GRAY_BALANCE :
case PCL_DRIVER_CONFIG :
case PCL_LPI :
case PCL_CPI :
case PCL_PAGE_LENGTH :
case PCL_NUM_COPIES :
case PCL_DUPLEX :
case PCL_MEDIA_SIDE :
case RTL_CONFIGURE :
case PCL_ENTER_PCL :
case PCL_NEGATIVE_MOTION :
fprintf(stderr, "%s: %d (ignored)", pcl_commands[command_index].description, numeric_arg);
if (pcl_commands[command_index].has_data == 1) {
fprintf(stderr, " Data: ");
for (i=0; i < numeric_arg; i++) {
fprintf(stderr, "%02x ", (unsigned char) data_buffer[i]);
}
}
fprintf(stderr, "\n");
break;
case PCL_COLOURTYPE :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
image_data.colour_type = -numeric_arg;
switch (image_data.colour_type) {
case PCL_MONO :
fprintf(stderr, "MONO\n");
break;
case PCL_CMY :
fprintf(stderr, "CMY (one cart)\n");
image_data.black_depth = 0;
image_data.cyan_depth = 2;
image_data.magenta_depth = 2;
image_data.yellow_depth = 2;
break;
case PCL_CMYK :
fprintf(stderr, "CMYK (two cart)\n");
image_data.black_depth = 2;
image_data.cyan_depth = 2;
image_data.magenta_depth = 2;
image_data.yellow_depth = 2;
break;
default :
fprintf(stderr, "Unknown (%d)\n", -numeric_arg);
break;
}
break;
case PCL_COMPRESSIONTYPE :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
image_data.compression_type = numeric_arg;
switch (image_data.compression_type) {
case PCL_COMPRESSION_NONE :
fprintf(stderr, "NONE\n");
break;
case PCL_COMPRESSION_RUNHEIGHT :
fprintf(stderr, "Runheight\n");
break;
case PCL_COMPRESSION_TIFF :
fprintf(stderr, "TIFF\n");
break;
case PCL_COMPRESSION_CRDR :
fprintf(stderr, "Compressed Row Delta Replacement\n");
break;
default :
fprintf(stderr, "Unknown (%d)\n", image_data.compression_type);
break;
}
break;
case PCL_RASTER_WIDTH :
fprintf(stderr, "%s: %d\n", pcl_commands[command_index].description, numeric_arg);
image_data.image_width = numeric_arg;
break;
case PCL_RASTER_HEIGHT :
fprintf(stderr, "%s: %d\n", pcl_commands[command_index].description, numeric_arg);
image_data.image_height = numeric_arg;
break;
case PCL_CONFIGURE :
fprintf(stderr, "%s (size=%d)\n", pcl_commands[command_index].description,
numeric_arg);
fprintf(stderr, "\tFormat: %d\n", data_buffer[0]);
if (data_buffer[0] == 2) {
fprintf(stderr, "\tOutput Planes: ");
image_data.colour_type = data_buffer[1];
switch (image_data.colour_type) {
case PCL_MONO :
fprintf(stderr, "MONO\n");
if (numeric_arg != 8)
fprintf(stderr, "ERROR: Expected 8 bytes of data, got %d\n", numeric_arg);
fprintf(stderr, "\tBlack: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[2]<<8)+(unsigned char)data_buffer[3],
((unsigned char) data_buffer[4]<<8)+(unsigned char) data_buffer[5], data_buffer[7]);
image_data.black_depth = data_buffer[7];
break;
case PCL_CMY :
fprintf(stderr, "CMY (one cart)\n");
if (numeric_arg != 20)
fprintf(stderr, "ERROR: Expected 20 bytes of data, got %d\n", numeric_arg);
fprintf(stderr, "\tCyan: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[2]<<8)+(unsigned char) data_buffer[3],
((unsigned char) data_buffer[4]<<8)+(unsigned char) data_buffer[5], data_buffer[7]);
fprintf(stderr, "\tMagenta: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[8]<<8)+(unsigned char) data_buffer[9],
((unsigned char) data_buffer[10]<<8)+(unsigned char) data_buffer[11], data_buffer[13]);
fprintf(stderr, "\tYellow: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[14]<<8)+(unsigned char) data_buffer[15],
((unsigned char) data_buffer[16]<<8)+(unsigned char) data_buffer[17], data_buffer[19]);
image_data.black_depth = 0;
image_data.cyan_depth = data_buffer[7];
image_data.magenta_depth = data_buffer[13];
image_data.yellow_depth = data_buffer[19];
break;
case PCL_CMYK :
fprintf(stderr, "CMYK (two cart)\n");
if (numeric_arg != 26)
fprintf(stderr, "ERROR: Expected 26 bytes of data, got %d\n", numeric_arg);
fprintf(stderr, "\tBlack: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[2]<<8)+(unsigned char) data_buffer[3],
((unsigned char) data_buffer[4]<<8)+(unsigned char) data_buffer[5], data_buffer[7]);
fprintf(stderr, "\tCyan: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[8]<<8)+(unsigned char) data_buffer[9],
((unsigned char) data_buffer[10]<<8)+(unsigned char) data_buffer[11], data_buffer[13]);
fprintf(stderr, "\tMagenta: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[14]<<8)+(unsigned char) data_buffer[15],
((unsigned char) data_buffer[16]<<8)+(unsigned char) data_buffer[17], data_buffer[19]);
fprintf(stderr, "\tYellow: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[20]<<8)+(unsigned char) data_buffer[21],
((unsigned char) data_buffer[22]<<8)+(unsigned char) data_buffer[23], data_buffer[25]);
image_data.black_depth = data_buffer[7];
image_data.cyan_depth = data_buffer[13];
image_data.magenta_depth = data_buffer[19];
image_data.yellow_depth = data_buffer[25];
break;
case PCL_CMYKcm :
fprintf(stderr, "CMYKcm (two cart photo)\n");
if (numeric_arg != 38)
fprintf(stderr, "ERROR: Expected 38 bytes of data, got %d\n", numeric_arg);
fprintf(stderr, "\tBlack: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[2]<<8)+(unsigned char) data_buffer[3],
((unsigned char) data_buffer[4]<<8)+(unsigned char) data_buffer[5], data_buffer[7]);
fprintf(stderr, "\tCyan: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[8]<<8)+(unsigned char) data_buffer[9],
((unsigned char) data_buffer[10]<<8)+(unsigned char) data_buffer[11], data_buffer[13]);
fprintf(stderr, "\tMagenta: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[14]<<8)+(unsigned char) data_buffer[15],
((unsigned char) data_buffer[16]<<8)+(unsigned char) data_buffer[17], data_buffer[19]);
fprintf(stderr, "\tYellow: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[20]<<8)+(unsigned char) data_buffer[21],
((unsigned char) data_buffer[22]<<8)+(unsigned char) data_buffer[23], data_buffer[25]);
fprintf(stderr, "\tLight Cyan: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[26]<<8)+(unsigned char) data_buffer[27],
((unsigned char) data_buffer[28]<<8)+(unsigned char) data_buffer[29], data_buffer[31]);
fprintf(stderr, "\tLight Magenta: X dpi: %d, Y dpi: %d, Levels: %d\n", ((unsigned char) data_buffer[32]<<8)+(unsigned char) data_buffer[33],
((unsigned char) data_buffer[34]<<8)+(unsigned char) data_buffer[35], data_buffer[37]);
image_data.black_depth = data_buffer[7];
image_data.cyan_depth = data_buffer[13];
image_data.magenta_depth = data_buffer[19];
image_data.yellow_depth = data_buffer[25];
image_data.lcyan_depth = data_buffer[31];
image_data.lmagenta_depth = data_buffer[37];
break;
default :
fprintf(stderr, "Unknown (%d)\n", data_buffer[1]);
break;
}
}
else {
fprintf(stderr, "Unknown format %d\n", data_buffer[0]);
fprintf(stderr, "Data: ");
for (i=0; i < numeric_arg; i++) {
fprintf(stderr, "%02x ", (unsigned char) data_buffer[i]);
}
fprintf(stderr, "\n");
}
break;
case PCL_DATA :
case PCL_DATA_LAST :
#ifdef DEBUG
fprintf(stderr, "%s\n", pcl_commands[command_index].description);
fprintf(stderr, "Data Height: %d\n", numeric_arg);
#endif
if (expected_data_rows_per_row == -1)
fprintf(stderr, "ERROR: raster data without start raster!\n");
if (command == PCL_DATA_LAST) {
if (current_data_row != (expected_data_rows_per_row - 1))
fprintf(stderr, "ERROR: 'Last Plane' set on plane %d of %d!\n",
current_data_row, expected_data_rows_per_row);
}
else {
if (current_data_row == (expected_data_rows_per_row - 1))
fprintf(stderr, "ERROR: Expected 'last plane', but not set!\n");
}
if (image_data.compression_type == PCL_COMPRESSION_NONE) {
memcpy(received_rows[current_data_row], &data_buffer, (size_t) numeric_arg);
output_data.active_height = numeric_arg;
}
else
output_data.active_height = decode_tiff(data_buffer, numeric_arg, received_rows[current_data_row], output_data.buffer_length);
if (command == PCL_DATA_LAST) {
if (image_data.colour_type == PCL_MONO)
write_grey(&output_data, &image_data);
else
write_colour(&output_data, &image_data);
current_data_row = 0;
image_row_counter++;
}
else
current_data_row++;
break;
case PCL_ENTER_HPGL2 :
case PCL_ENTER_PJL : {
int c;
fprintf(stderr, "%s %d\n", pcl_commands[command_index].description, numeric_arg);
c = 0;
while (1) {
fill_buffer();
if (eof == 1) {
fprintf(stderr, "\n");
break;
}
c = read_buffer[read_pointer++];
if (c == '\033')
break;
fprintf(stderr, "%c", c);
}
read_pointer--;
fprintf(stderr, "\n");
fprintf(stderr, "End of %s\n", pcl_commands[command_index].description);
}
break;
case PCL_PAGE_ORIENTATION :
fprintf(stderr, "%s: ", pcl_commands[command_index].description);
switch (numeric_arg) {
case 0 :
fprintf(stderr, "Portrait");
break;
case 1 :
fprintf(stderr, "Landscape");
break;
case 2 :
fprintf(stderr, "Reverse Portrait");
break;
case 3 :
fprintf(stderr, "Reverse Landscape");
break;
default :
fprintf(stderr, "Unknown (%d)", numeric_arg);
break;
}
fprintf(stderr, " (ignored)\n");
break;
default :
fprintf(stderr, "ERROR: No handler for %s!\n", pcl_commands[command_index].description);
break;
}
}
}
}