1.1 --- a/bitblt.c Wed Feb 19 10:34:35 2003 +0000 1.2 +++ b/bitblt.c Thu Feb 20 12:11:06 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 * bitblt routines 1.7 - * $Id: bitblt.c,v 1.11 2003/02/19 02:14:44 eric Exp $ 1.8 + * $Id: bitblt.c,v 1.12 2003/02/20 04:11:06 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 @@ -726,6 +726,79 @@ 1.13 } 1.14 1.15 1.16 -void bitblt_init (void) 1.17 +int32_t get_row_run_lengths (Bitmap *src, 1.18 + int32_t y, 1.19 + int32_t min_x, int32_t max_x, 1.20 + int32_t max_runs, 1.21 + uint32_t *run_length) 1.22 { 1.23 + uint8_t *byte_ptr; 1.24 + uint8_t byte; 1.25 + int bit_pos; 1.26 + 1.27 + uint32_t byte_cnt; 1.28 + int last_bits; 1.29 + bool last_flag = 0; 1.30 + 1.31 + uint8_t pol = 0x00; /* 0x00 = counting zeros (white), 1.32 + 0xff = counting ones (black) */ 1.33 + 1.34 + uint32_t rl; 1.35 + int32_t i = 0; 1.36 + 1.37 + /* adjust coordinate system */ 1.38 + y -= src->rect.min.y; 1.39 + min_x -= src->rect.min.x; 1.40 + max_x -= src->rect.min.x; 1.41 + 1.42 + byte_ptr = (uint8_t *) (src->bits + y * src->row_words); 1.43 + byte_cnt = (max_x / 8) + 1 - (min_x / 8); 1.44 + last_bits = max_x % 8; 1.45 + 1.46 + rl = 0; 1.47 + pol = 0x00; /* initially count white pixels */ 1.48 + 1.49 + byte_ptr += min_x / 8; 1.50 + bit_pos = min_x % 8; 1.51 + byte = *(byte_ptr++); 1.52 + 1.53 + /* is the first byte also the last? */ 1.54 + if (--byte_cnt == 0) 1.55 + { 1.56 + byte <<= (7 - last_bits); /* last byte may be partial */ 1.57 + bit_pos += (7 - last_bits); 1.58 + last_flag = 1; 1.59 + } 1.60 + 1.61 + for (;;) 1.62 + { 1.63 + int b2 = rle_tab [bit_pos] [pol ^ byte]; 1.64 + rl += b2; 1.65 + bit_pos += b2; 1.66 + if (bit_pos == 8) 1.67 + { 1.68 + if (last_flag) 1.69 + { 1.70 + if (rl) 1.71 + run_length [i++] = rl; 1.72 + return (i); 1.73 + } 1.74 + bit_pos = 0; 1.75 + byte = *(byte_ptr++); 1.76 + if (--byte_cnt == 0) 1.77 + { 1.78 + byte <<= (7 - last_bits); /* last byte may be partial */ 1.79 + bit_pos += (7 - last_bits); 1.80 + last_flag = 1; 1.81 + } 1.82 + } 1.83 + else 1.84 + { 1.85 + run_length [i++] = rl; 1.86 + if (i == max_runs) 1.87 + return (-i); 1.88 + rl = 0; 1.89 + pol ^= 0xff; 1.90 + } 1.91 + } 1.92 }