136
136
# define out_shift_initial (8 - out_bits)
137
137
# define out_shift_update(out_shift, nbits) ((out_shift -= (nbits)) < 0)
139
int out_shift = out_shift_initial;
141
int in_shift = in_shift_initial;
142
int dw = 8 - (srcx & 7);
145
/* Loop over source bytes. */
146
for (w = width; w > 0; w -= dw, dw = 8) {
148
int in_shift_final = (w >= dw ? 0 : dw - w);
151
* Check quickly for all-0s or all-1s, but only if each
152
* input byte generates no more than one output byte,
153
* we're at an input byte boundary, and we're processing
154
* an entire input byte (i.e., this isn't a final
157
if (in_shift == in_shift_check && in_shift_final == 0)
160
for (index = sraster; index != sskip; index += sraster)
163
if (out_shift_update(out_shift, input_byte_out_bits))
164
*d++ = out, out_shift &= 7, out = 0;
139
int out_shift = out_shift_initial;
141
int in_shift = in_shift_initial;
142
int dw = 8 - (srcx & 7);
145
/* Loop over source bytes. */
146
for (w = width; w > 0; w -= dw, dw = 8) {
148
int in_shift_final = (w >= dw ? 0 : dw - w);
151
* Check quickly for all-0s or all-1s, but only if each
152
* input byte generates no more than one output byte,
153
* we're at an input byte boundary, and we're processing
154
* an entire input byte (i.e., this isn't a final
157
if (in_shift == in_shift_check && in_shift_final == 0)
160
for (index = sraster; index != sskip; index += sraster)
163
if (out_shift_update(out_shift, input_byte_out_bits))
164
*d++ = out, out_shift &= 7, out = 0;
167
167
#if !ALPHA_LSB_FIRST /* too messy to make it work */
169
for (index = sraster; index != sskip; index += sraster)
170
if (s[index] != 0xff)
174
(out_shift -= input_byte_out_bits) + out_bits;
169
for (index = sraster; index != sskip; index += sraster)
170
if (s[index] != 0xff)
174
(out_shift -= input_byte_out_bits) + out_bits;
177
out |= input_byte_out_mask << shift;
179
out |= input_byte_out_mask >> -shift;
182
out = input_byte_out_mask << (8 + shift);
177
out |= input_byte_out_mask << shift;
179
out |= input_byte_out_mask >> -shift;
182
out = input_byte_out_mask << (8 + shift);
191
p: /* Loop over source pixels within a byte. */
195
for (index = 0, count = 0; index != sskip;
198
count += half_byte_1s[(s[index] >> in_shift) & mask];
199
if (count != 0 && table[count] == 0) { /* Look at adjacent cells to help prevent */
201
uint orig_count = count;
202
uint shifted_mask = mask << in_shift;
205
if_debug3('B', "[B]count(%d,%d)=%d\n",
206
(width - w) / xscale,
207
(height - h) / yscale, count);
208
if (yscale > 1) { /* Look at the next "lower" cell. */
209
if (h < height && (in = s[0] & shifted_mask) != 0) {
212
for (index = 0, lower = 0;
213
-(index -= sraster) <= sskip &&
214
(in &= s[index]) != 0;
216
lower += half_byte_1s[in >> in_shift];
217
if_debug1('B', "[B] lower adds %d\n",
219
if (lower <= orig_count)
222
/* Look at the next "higher" cell. */
223
if (h > yscale && (in = s[sskip - sraster] & shifted_mask) != 0) {
226
for (index = sskip, upper = 0;
227
index < sskip << 1 &&
228
(in &= s[index]) != 0;
231
upper += half_byte_1s[in >> in_shift];
232
if_debug1('B', "[B] upper adds %d\n",
234
if (upper < orig_count)
239
uint mask1 = (mask << 1) + 1;
241
/* Look at the next cell to the left. */
243
int lshift = in_shift + xscale - 1;
246
for (index = 0, left = 0;
247
index < sskip; index += sraster
250
((s[index - 1] << 8) +
253
left += bits5_trailing_1s[bits & mask1];
255
if_debug1('B', "[B] left adds %d\n",
257
if (left < orig_count)
260
/* Look at the next cell to the right. */
262
int rshift = in_shift - xscale + 8;
265
for (index = 0, right = 0;
266
index < sskip; index += sraster
270
s[index + 1]) >> rshift;
272
right += bits5_leading_1s[(bits & mask1) << (4 - xscale)];
274
if_debug1('B', "[B] right adds %d\n",
276
if (right <= orig_count)
280
if (count > count_max)
283
out += table[count] << out_shift;
284
if (out_shift_update(out_shift, out_bits))
285
*d++ = out, out_shift &= 7, out = 0;
287
while ((in_shift -= xscale) >= in_shift_final);
290
if (out_shift != out_shift_initial)
292
for (w = dskip; w != 0; w--)
191
p: /* Loop over source pixels within a byte. */
195
for (index = 0, count = 0; index != sskip;
198
count += half_byte_1s[(s[index] >> in_shift) & mask];
199
if (count != 0 && table[count] == 0) { /* Look at adjacent cells to help prevent */
201
uint orig_count = count;
202
uint shifted_mask = mask << in_shift;
205
if_debug3('B', "[B]count(%d,%d)=%d\n",
206
(width - w) / xscale,
207
(height - h) / yscale, count);
208
if (yscale > 1) { /* Look at the next "lower" cell. */
209
if (h < height && (in = s[0] & shifted_mask) != 0) {
212
for (index = 0, lower = 0;
213
-(index -= sraster) <= sskip &&
214
(in &= s[index]) != 0;
216
lower += half_byte_1s[in >> in_shift];
217
if_debug1('B', "[B] lower adds %d\n",
219
if (lower <= orig_count)
222
/* Look at the next "higher" cell. */
223
if (h > yscale && (in = s[sskip - sraster] & shifted_mask) != 0) {
226
for (index = sskip, upper = 0;
227
index < sskip << 1 &&
228
(in &= s[index]) != 0;
231
upper += half_byte_1s[in >> in_shift];
232
if_debug1('B', "[B] upper adds %d\n",
234
if (upper < orig_count)
239
uint mask1 = (mask << 1) + 1;
241
/* Look at the next cell to the left. */
243
int lshift = in_shift + xscale - 1;
246
for (index = 0, left = 0;
247
index < sskip; index += sraster
250
((s[index - 1] << 8) +
253
left += bits5_trailing_1s[bits & mask1];
255
if_debug1('B', "[B] left adds %d\n",
257
if (left < orig_count)
260
/* Look at the next cell to the right. */
262
int rshift = in_shift - xscale + 8;
265
for (index = 0, right = 0;
266
index < sskip; index += sraster
270
s[index + 1]) >> rshift;
272
right += bits5_leading_1s[(bits & mask1) << (4 - xscale)];
274
if_debug1('B', "[B] right adds %d\n",
276
if (right <= orig_count)
280
if (count > count_max)
283
out += table[count] << out_shift;
284
if (out_shift_update(out_shift, out_bits))
285
*d++ = out, out_shift &= 7, out = 0;
287
while ((in_shift -= xscale) >= in_shift_final);
290
if (out_shift != out_shift_initial)
292
for (w = dskip; w != 0; w--)
294
294
#undef out_shift_initial
295
295
#undef out_shift_update