1.1 --- a/bitblt_g4.c Fri Feb 21 09:25:47 2003 +0000 1.2 +++ b/bitblt_g4.c Fri Feb 21 10:49:11 2003 +0000 1.3 @@ -4,7 +4,7 @@ 1.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 1.5 * 1.6 * PDF routines 1.7 - * $Id: bitblt_g4.c,v 1.5 2003/02/21 01:25:47 eric Exp $ 1.8 + * $Id: bitblt_g4.c,v 1.6 2003/02/21 02:49:11 eric Exp $ 1.9 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.10 * 1.11 * This program is free software; you can redistribute it and/or modify 1.12 @@ -27,6 +27,7 @@ 1.13 #include <stdbool.h> 1.14 #include <stdint.h> 1.15 #include <stdio.h> 1.16 +#include <stdlib.h> 1.17 #include <string.h> 1.18 1.19 1.20 @@ -37,6 +38,9 @@ 1.21 #include "pdf_private.h" 1.22 1.23 1.24 +#define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0) 1.25 + 1.26 + 1.27 struct pdf_g4_image 1.28 { 1.29 double width, height; 1.30 @@ -94,28 +98,48 @@ 1.31 { 1.32 struct pdf_g4_image *image = app_data; 1.33 1.34 -#if 0 1.35 - pdf_stream_write_data (pdf_file, stream, image->data, image->len); 1.36 -#else 1.37 - unsigned long row = 0; 1.38 - word_type *ref; 1.39 - word_type *raw; 1.40 + uint32_t row; 1.41 + 1.42 + /* reference (previous) row */ 1.43 + uint32_t *ref_runs = pdf_calloc (image->Columns, sizeof (uint32_t)); 1.44 + uint32_t ref_run_count; 1.45 1.46 - ref = NULL; 1.47 - raw = image->bitmap->bits; 1.48 + /* row being converted */ 1.49 + uint32_t *row_runs = pdf_calloc (image->Columns, sizeof (uint32_t)); 1.50 + uint32_t row_run_count; 1.51 + 1.52 + /* initialize reference row - all white */ 1.53 + ref_runs [0] = image->Columns; 1.54 + ref_run_count = 0; 1.55 1.56 - while (row < image->Rows) 1.57 + for (row = image->bitmap->rect.min.y; 1.58 + row < image->bitmap->rect.max.y; 1.59 + row++) 1.60 { 1.61 - pdf_stream_write_data (pdf_file, stream, (uint8_t *) raw, 1.62 - image->bitmap->row_words * sizeof (word_type)); 1.63 + row_run_count = get_row_run_lengths (image->bitmap, 1.64 + row, 1.65 + image->bitmap->rect.min.x, 1.66 + image->bitmap->rect.max.x - 1, 1.67 + image->Columns, /* max_runs */ 1.68 + row_runs); 1.69 + pdf_assert (row_run_count > 0); 1.70 + 1.71 + /* $$$ G4 encode the runs here */ 1.72 1.73 - row++; 1.74 - ref = raw; 1.75 - raw += image->bitmap->row_words; 1.76 + /* pdf_stream_write_data (pdf_file, stream, image->data, image->len); */ 1.77 + 1.78 + SWAP (uint32_t *, row_runs, ref_runs); 1.79 + ref_run_count = row_run_count; 1.80 } 1.81 + 1.82 + 1.83 /* $$$ generate and write EOFB code */ 1.84 - /* $$$ flush any remaining buffered bits */ 1.85 -#endif 1.86 + pdf_stream_write_bits (pdf_file, stream, 24, 0x001001); 1.87 + 1.88 + pdf_stream_flush_bits (pdf_file, stream); 1.89 + 1.90 + free (ref_runs); 1.91 + free (row_runs); 1.92 } 1.93 1.94 1.95 @@ -139,7 +163,7 @@ 1.96 1.97 struct pdf_obj *content_stream; 1.98 1.99 - image = pdf_calloc (sizeof (struct pdf_g4_image)); 1.100 + image = pdf_calloc (1, sizeof (struct pdf_g4_image)); 1.101 1.102 image->width = width; 1.103 image->height = height;