Coverage Report

Created: 2025-06-10 07:27

/src/ghostpdl/base/scfe.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* CCITTFax encoding filter */
18
#include "stdio_.h"   /* includes std.h */
19
#include "memory_.h"
20
#include "gdebug.h"
21
#include "strimpl.h"
22
#include "scf.h"
23
#include "scfx.h"
24
25
/* ------ Macros and support routines ------ */
26
27
/* Statistics */
28
/* #define COLLECT_STATS_SCFE */
29
30
#ifdef COLLECT_STATS_SCFE
31
typedef struct stats_runs_s {
32
    ulong termination[64];
33
    ulong make_up[41];
34
} stats_runs_t;
35
static stats_runs_t stats_white_runs, stats_black_runs;
36
37
#define COUNT_RUN(tab, i) (tab)[i]++;
38
39
static void
40
print_run_stats(const gs_memory_t *mem, const stats_runs_t * stats)
41
{
42
    int i;
43
    ulong total;
44
45
    for (i = 0, total = 0; i < 41; i++)
46
        dmprintf1(mem, " %lu", stats->make_up[i]),
47
            total += stats->make_up[i];
48
    dmprintf1(mem, " total=%lu\n\t", total);
49
    for (i = 0, total = 0; i < 64; i++)
50
        dmprintf1(mem, " %lu", stats->termination[i]),
51
            total += stats->termination[i];
52
    dmprintf1(mem, " total=%lu\n", total);
53
}
54
55
#else /* !defined(COLLECT_STATS_SCFE) */
56
57
498M
#define COUNT_RUN(cnt, i) DO_NOTHING
58
59
#endif /* DEBUG */
60
61
/* Put a run onto the output stream. */
62
/* Free variables: q, bits, bits_left. */
63
64
470M
#define CF_PUT_RUN(ss, lenv, rt, stats)\
65
470M
BEGIN\
66
470M
    cfe_run rr;\
67
470M
\
68
470M
    if ( lenv >= 64 ) {\
69
24.2M
        hce_store_state();\
70
24.2M
        q = cf_put_long_run(ss, q, lenv, &rt);\
71
24.2M
        hce_load_state();\
72
24.2M
        lenv &= 63;\
73
24.2M
    }\
74
470M
    rr = rt.termination[lenv];\
75
470M
    COUNT_RUN(stats.termination, lenv);\
76
470M
    hc_put_value(ss, q, rr.code, rr.code_length);\
77
470M
END
78
79
static byte *
80
cf_put_long_run(stream_CFE_state * ss, byte * q, int lenv, const cf_runs * prt)
81
24.2M
{
82
24.2M
    hce_declare_state;
83
24.2M
    cfe_run rr;
84
85
#ifdef COLLECT_STATS_SCFE
86
    stats_runs_t *pstats =
87
    (prt == &cf_white_runs ? &stats_white_runs : &stats_black_runs);
88
#endif
89
90
24.2M
    hce_load_state();
91
28.3M
    while (lenv >= 2560 + 64) {
92
4.11M
        rr = prt->make_up[40];
93
4.11M
        COUNT_RUN(pstats->make_up, 40);
94
4.11M
        hc_put_value(ss, q, rr.code, rr.code_length);
95
4.11M
        lenv -= 2560;
96
4.11M
    }
97
24.2M
    rr = prt->make_up[lenv >> 6];
98
24.2M
    COUNT_RUN(pstats->make_up, lenv >> 6);
99
24.2M
    hc_put_value(ss, q, rr.code, rr.code_length);
100
24.2M
    hce_store_state();
101
24.2M
    return q;
102
24.2M
}
103
104
#define CF_PUT_WHITE_RUN(ss, lenv)\
105
242M
  CF_PUT_RUN(ss, lenv, cf_white_runs, stats_white_runs)
106
107
#define CF_PUT_BLACK_RUN(ss, lenv)\
108
227M
  CF_PUT_RUN(ss, lenv, cf_black_runs, stats_black_runs)
109
110
/* ------ CCITTFaxEncode ------ */
111
112
private_st_CFE_state();
113
114
static void s_CFE_release(stream_state *);
115
116
/* Set default parameter values. */
117
static void
118
s_CFE_set_defaults(register stream_state * st)
119
126k
{
120
126k
    stream_CFE_state *const ss = (stream_CFE_state *) st;
121
122
126k
    s_CFE_set_defaults_inline(ss);
123
126k
}
124
125
/* Initialize CCITTFaxEncode filter */
126
static int
127
s_CFE_init(register stream_state * st)
128
2.25M
{
129
2.25M
    stream_CFE_state *const ss = (stream_CFE_state *) st;
130
2.25M
    int columns = ss->Columns;
131
132
    /*
133
     * The worst case for encoding is alternating white and black pixels.
134
     * For 1-D encoding, the worst case is 9 bits per 2 pixels; for 2-D
135
     * (horizontal), 12 bits per 2 pixels. However, for 2D vertical encoding
136
     * an offset 3 vertically encoded requires 7 bits of encoding. So we need
137
     * to allow 14 bits for this, not 12 (see bug 696413). To fill out a scan line,
138
     * we may add up to 6 12-bit EOL codes.
139
     */
140
2.25M
    int code_bytes =
141
2.25M
    (((columns * (ss->K == 0 ? 9 : 14)) + 15) >> 4) + 20;  /* add slop */
142
2.25M
    int raster = ss->raster =
143
2.25M
        ROUND_UP((columns + 7) >> 3, ss->DecodedByteAlign);
144
145
2.25M
    s_hce_init_inline(ss);
146
2.25M
    ss->lbuf = ss->lprev = ss->lcode = 0; /* in case we have to release */
147
2.25M
    if (columns > cfe_max_width)
148
0
        return ERRC;
149
/****** WRONG ******/
150
    /* Because skip_white_pixels can look as many as 4 bytes ahead, */
151
    /* we need to allow 4 extra bytes at the end of the row buffers. */
152
2.25M
    ss->lbufstart = gs_alloc_bytes(st->memory, raster + 8, "CFE lbuf");
153
2.25M
    ss->lcode = gs_alloc_bytes(st->memory, code_bytes, "CFE lcode");
154
2.25M
    if (ss->lbufstart == 0 || ss->lcode == 0) {
155
0
        s_CFE_release(st);
156
0
        return ERRC;
157
/****** WRONG ******/
158
0
    }
159
2.25M
    ss->lbuf = ss->lbufstart + 4;
160
2.25M
    memset(ss->lbuf + raster, 0, 4); /* to pacify Valgrind */
161
2.25M
    if (ss->K != 0) {
162
2.25M
        ss->lprevstart = gs_alloc_bytes(st->memory, raster + 8, "CFE lprev");
163
2.25M
        if (ss->lprevstart == 0) {
164
0
            s_CFE_release(st);
165
0
            return ERRC;
166
/****** WRONG ******/
167
0
        }
168
2.25M
        ss->lprev = ss->lprevstart + 4;
169
        /* Clear the initial reference line for 2-D encoding. */
170
        /* Make sure it is terminated properly. */
171
2.25M
        memset(ss->lprev, (ss->BlackIs1 ? 0 : 0xff), raster + 4); /* +4 to pacify Valgrind */
172
2.25M
        if (columns & 7)
173
101k
            ss->lprev[raster - 1] ^= 0x80 >> (columns & 7);
174
2.15M
        else
175
2.15M
            ss->lprev[raster] = ~ss->lprev[0];
176
2.25M
    }
177
2.25M
    ss->read_count = raster;
178
2.25M
    ss->write_count = 0;
179
2.25M
    ss->k_left = (ss->K > 0 ? 1 : ss->K);
180
2.25M
    ss->max_code_bytes = code_bytes;
181
2.25M
    return 0;
182
2.25M
}
183
184
/* Release the filter. */
185
static void
186
s_CFE_release(stream_state * st)
187
2.25M
{
188
2.25M
    stream_CFE_state *const ss = (stream_CFE_state *) st;
189
190
2.25M
    gs_free_object(st->memory, ss->lprevstart, "CFE lprev(close)");
191
2.25M
    gs_free_object(st->memory, ss->lcode, "CFE lcode(close)");
192
2.25M
    gs_free_object(st->memory, ss->lbufstart, "CFE lbuf(close)");
193
2.25M
}
194
195
/* Flush the buffer */
196
static void cf_encode_1d(stream_CFE_state *, const byte *,
197
                          stream_cursor_write *);
198
static void cf_encode_2d(stream_CFE_state *, const byte *,
199
                          stream_cursor_write *, const byte *);
200
static int
201
s_CFE_process(stream_state * st, stream_cursor_read * pr,
202
              stream_cursor_write * pw, bool last)
203
181M
{
204
181M
    stream_CFE_state *const ss = (stream_CFE_state *) st;
205
181M
    const byte *rlimit = pr->limit;
206
181M
    byte *wlimit = pw->limit;
207
181M
    int raster = ss->raster;
208
181M
    byte end_mask = 1 << (-ss->Columns & 7);
209
181M
    int status = 0;
210
211
    /* Update the pointers we actually use, in case GC moved the buffer */
212
181M
    ss->lbuf = ss->lbufstart + 4;
213
181M
    ss->lprev = ss->lprevstart + 4;
214
215
257M
    for (;;) {
216
257M
        stream_cursor_write w;
217
218
257M
        if_debug2m('w', ss->memory, "[w]CFE: read_count = %d, write_count=%d,\n",
219
257M
                   ss->read_count, ss->write_count);
220
257M
        if_debug6m('w', ss->memory, "    pr = "PRI_INTPTR"(%d)"PRI_INTPTR", pw = "PRI_INTPTR"(%d)"PRI_INTPTR"\n",
221
257M
                   (intptr_t) pr->ptr, (int)(rlimit - pr->ptr), (intptr_t) rlimit,
222
257M
                   (intptr_t) pw->ptr, (int)(wlimit - pw->ptr), (intptr_t) wlimit);
223
257M
        if (ss->write_count) {
224
            /* Copy more of an encoded line to the caller. */
225
24.7M
            int wcount = wlimit - pw->ptr;
226
24.7M
            int ccount = min(wcount, ss->write_count);
227
228
24.7M
            memcpy(pw->ptr + 1, ss->lcode + ss->code_bytes - ss->write_count,
229
24.7M
                   ccount);
230
24.7M
            pw->ptr += ccount;
231
24.7M
            if ((ss->write_count -= ccount) > 0) {
232
338k
                status = 1;
233
338k
                break;
234
338k
            }
235
24.7M
        }
236
257M
        if (ss->read_count) {
237
            /* Copy more of an unencoded line from the caller. */
238
257M
            int rcount = rlimit - pr->ptr;
239
257M
            int ccount = min(rcount, ss->read_count);
240
241
257M
            if (rcount == 0 && last)
242
2.19M
                break;
243
254M
            memcpy(ss->lbuf + raster - ss->read_count,
244
254M
                   pr->ptr + 1, ccount);
245
254M
            pr->ptr += ccount;
246
254M
            if ((ss->read_count -= ccount) != 0)
247
179M
                break;
248
254M
        }
249
        /*
250
         * We have a full scan line in lbuf.  Ensure that it ends with
251
         * two polarity changes.
252
         */
253
75.6M
        {
254
75.6M
            byte *end = ss->lbuf + raster - 1;
255
75.6M
            byte end_bit = *end & end_mask;
256
75.6M
            byte not_bit = end_bit ^ end_mask;
257
258
75.6M
            *end &= -end_mask;
259
75.6M
            if (end_mask == 1)
260
65.8M
                end[1] = (end_bit ? 0x40 : 0x80);
261
9.77M
            else if (end_mask == 2)
262
912k
                *end |= not_bit >> 1, end[1] = end_bit << 7;
263
8.86M
            else
264
8.86M
                *end |= (not_bit >> 1) | (end_bit >> 2);
265
75.6M
        }
266
        /*
267
         * Write the output directly to the caller's buffer if it's large
268
         * enough, otherwise to our own buffer.
269
         */
270
75.6M
        if (wlimit - pw->ptr >= ss->max_code_bytes) {
271
16.7M
            w = *pw;
272
58.9M
        } else {
273
58.9M
            w.ptr = ss->lcode - 1;
274
58.9M
            w.limit = w.ptr + ss->max_code_bytes;
275
58.9M
        }
276
#ifdef DEBUG
277
        if (ss->K > 0) {
278
            if_debug2m('w', ss->memory, "[w2]new %d-D row, k_left=%d\n",
279
                       (ss->k_left == 1 ? 1 : 2), ss->k_left);
280
        } else {
281
            if_debug1m('w', ss->memory, "[w%d]new row\n", (ss->K < 0 ? 2 : 1));
282
        }
283
#endif
284
        /*
285
         * Write an EOL (actually a "beginning of line") if requested.
286
         */
287
75.6M
        if (ss->EndOfLine) {
288
15.1M
            const cfe_run *rp =
289
15.1M
            (ss->K <= 0 ? &cf_run_eol :
290
15.1M
             ss->k_left > 1 ? &cf2_run_eol_2d :
291
0
             &cf2_run_eol_1d);
292
15.1M
            cfe_run run;
293
294
15.1M
            hce_declare_state;
295
296
15.1M
            hce_load_state();
297
15.1M
            if (ss->EncodedByteAlign) {
298
0
                run = *rp;
299
                /* Pad the run on the left */
300
                /* so it winds up byte-aligned. */
301
0
                run.code_length +=
302
0
                    (bits_left - run_eol_code_length) & 7;
303
0
                if (run.code_length > 16) /* <= 23 */
304
0
                    bits_left -= run.code_length & 7,
305
0
                        run.code_length = 16;
306
0
                rp = &run;
307
0
            }
308
15.1M
            hc_put_code(ss, w.ptr, rp);
309
15.1M
            hce_store_state();
310
60.5M
        } else if (ss->EncodedByteAlign)
311
0
            ss->bits_left &= ~7;
312
        /* Encode the line. */
313
75.6M
        if (ss->K == 0)
314
15.1M
            cf_encode_1d(ss, ss->lbuf, &w);  /* pure 1-D */
315
60.5M
        else if (ss->K < 0)
316
60.5M
            cf_encode_2d(ss, ss->lbuf, &w, ss->lprev);  /* pure 2-D */
317
0
        else if (--(ss->k_left)) /* mixed, use 2-D */
318
0
            cf_encode_2d(ss, ss->lbuf, &w, ss->lprev);
319
0
        else {     /* mixed, use 1-D */
320
0
            cf_encode_1d(ss, ss->lbuf, &w);
321
0
            ss->k_left = ss->K;
322
0
        }
323
        /*
324
         * If we didn't write directly to the client's buffer, schedule
325
         * the output data to be written.
326
         */
327
75.6M
        if (w.limit == wlimit)
328
16.7M
            pw->ptr = w.ptr;
329
58.9M
        else
330
58.9M
            ss->write_count = ss->code_bytes = w.ptr - (ss->lcode - 1);
331
75.6M
        if (ss->K != 0) {
332
            /* In 2-D modes, swap the current and previous scan lines. */
333
60.5M
            byte *temp = ss->lbuf;
334
60.5M
            byte *temp1 = ss->lbufstart;
335
336
60.5M
            ss->lbuf = ss->lprev;
337
60.5M
            ss->lbufstart = ss->lprevstart;
338
60.5M
            ss->lprev = temp;
339
60.5M
            ss->lprevstart = temp1;
340
60.5M
        }
341
        /* Note that the input buffer needs refilling. */
342
75.6M
        ss->read_count = raster;
343
75.6M
    }
344
    /*
345
     * When we exit from the loop, we know that write_count = 0, and
346
     * there is no line waiting to be processed in the input buffer.
347
     */
348
181M
    if (last && status == 0) {
349
2.19M
        const cfe_run *rp =
350
2.19M
        (ss->K > 0 ? &cf2_run_eol_1d : &cf_run_eol);
351
2.19M
        int i = (!ss->EndOfBlock ? 0 : ss->K < 0 ? 2 : 6);
352
2.19M
        uint bits_to_write =
353
2.19M
        hc_bits_size - ss->bits_left + i * rp->code_length;
354
2.19M
        byte *q = pw->ptr;
355
356
2.19M
        hce_declare_state;
357
358
2.19M
        if (wlimit - q < (bits_to_write + 7) >> 3) {
359
204k
            status = 1;
360
204k
            goto out;
361
204k
        }
362
1.98M
        hce_load_state();
363
1.98M
        if (ss->EncodedByteAlign)
364
0
            bits_left &= ~7;
365
5.71M
        while (--i >= 0)
366
3.72M
            hc_put_code(ss, q, rp);
367
        /* Force out the last byte or bytes. */
368
1.98M
        pw->ptr = hc_put_last_bits((stream_hc_state *) ss, q);
369
1.98M
    }
370
181M
  out:
371
181M
    if_debug9m('w', ss->memory, "[w]CFE exit %d: read_count = %d, write_count = %d,\n"
372
181M
               "     pr = "PRI_INTPTR"(%d)"PRI_INTPTR"; pw = "PRI_INTPTR"(%d)"PRI_INTPTR"\n",
373
181M
               status, ss->read_count, ss->write_count,
374
181M
               (intptr_t) pr->ptr, (int)(rlimit - pr->ptr), (intptr_t) rlimit,
375
181M
               (intptr_t) pw->ptr, (int)(wlimit - pw->ptr), (intptr_t) wlimit);
376
#ifdef DEBUG
377
    if (pr->ptr > rlimit || pw->ptr > wlimit) {
378
        lprintf("Pointer overrun!\n");
379
        status = ERRC;
380
    }
381
#ifdef COLLECT_STATS_SCFE
382
    if (gs_debug_c('w') && status == 1) {
383
        dmlputs(ss->memory, "[w]white runs:");
384
        print_run_stats(ss->memory, &stats_white_runs);
385
        dmlputs(ss->memory, "[w]black runs:");
386
        print_run_stats(ss->memory, &stats_black_runs);
387
    }
388
#endif
389
#endif
390
181M
    return status;
391
181M
}
392
393
/* Encode a 1-D scan line. */
394
/* Attempt to stop coverity thinking skip_white_pixels() taints lbuf:*/
395
/* coverity[ -tainted_data_return ] */
396
/* coverity[ -tainted_data_argument arg-2 ] */
397
static void
398
cf_encode_1d(stream_CFE_state * ss, const byte * lbuf, stream_cursor_write * pw)
399
15.1M
{
400
15.1M
    uint count = ss->raster << 3;
401
15.1M
    byte *q = pw->ptr;
402
15.1M
    int end_count = -ss->Columns & 7;
403
15.1M
    int rlen;
404
405
15.1M
    hce_declare_state;
406
15.1M
    const byte *p = lbuf;
407
15.1M
    byte invert = (ss->BlackIs1 ? 0 : 0xff);
408
409
    /* Invariant: data = p[-1] ^ invert. */
410
15.1M
    uint data = *p++ ^ invert;
411
412
15.1M
    hce_load_state();
413
232M
    while (count != end_count) {
414
        /* Parse a white run. */
415
232M
        skip_white_pixels(data, p, count, invert, rlen);
416
232M
        CF_PUT_WHITE_RUN(ss, rlen);
417
232M
        if (count == end_count)
418
15.0M
            break;
419
        /* Parse a black run. */
420
232M
        skip_black_pixels(data, p, count, invert, rlen);
421
217M
        CF_PUT_BLACK_RUN(ss, rlen);
422
217M
    }
423
15.1M
    hce_store_state();
424
15.1M
    pw->ptr = q;
425
15.1M
}
426
427
/* Encode a 2-D scan line. */
428
/* coverity[ -tainted_data_argument : arg-1 ] */
429
static void
430
cf_encode_2d(stream_CFE_state * ss, const byte * lbuf, stream_cursor_write * pw,
431
             const byte * lprev)
432
60.5M
{
433
60.5M
    byte invert_white = (ss->BlackIs1 ? 0 : 0xff);
434
60.5M
    byte invert = invert_white;
435
60.5M
    uint count = ss->raster << 3;
436
60.5M
    int end_count = -ss->Columns & 7;
437
60.5M
    const byte *p = lbuf;
438
60.5M
    byte *q = pw->ptr;
439
60.5M
    uint data = *p++ ^ invert;
440
441
60.5M
    hce_declare_state;
442
    /*
443
     * In order to handle the nominal 'changing white' at the beginning of
444
     * each scan line, we need to suppress the test for an initial black bit
445
     * in the reference line when we are at the very beginning of the scan
446
     * line.  To avoid an extra test, we use two different mask tables.
447
     */
448
60.5M
    static const byte initial_count_bit[8] =
449
60.5M
    {
450
60.5M
        0, 1, 2, 4, 8, 0x10, 0x20, 0x40
451
60.5M
    };
452
60.5M
    static const byte further_count_bit[8] =
453
60.5M
    {
454
60.5M
        0x80, 1, 2, 4, 8, 0x10, 0x20, 0x40
455
60.5M
    };
456
60.5M
    const byte *count_bit = initial_count_bit;
457
458
60.5M
    hce_load_state();
459
328M
    while (count != end_count) {
460
        /*
461
         * If invert == invert_white, white and black have their
462
         * correct meanings; if invert == ~invert_white,
463
         * black and white are interchanged.
464
         */
465
267M
        uint a0 = count;
466
267M
        uint a1;
467
468
267M
#define b1 (a1 - diff)    /* only for printing */
469
267M
        int diff;
470
267M
        uint prev_count = count;
471
267M
        const byte *prev_p = p - lbuf + lprev;
472
267M
        byte prev_data = prev_p[-1] ^ invert;
473
267M
        int rlen;
474
475
        /* Find the a1 and b1 transitions. */
476
267M
        skip_white_pixels(data, p, count, invert, rlen);
477
267M
        a1 = count;
478
267M
        if ((prev_data & count_bit[prev_count & 7])) {
479
            /* Look for changing white first. */
480
32.9M
            skip_black_pixels(prev_data, prev_p, prev_count, invert, rlen);
481
32.9M
        }
482
267M
        count_bit = further_count_bit;  /* no longer at beginning */
483
271M
      pass:
484
271M
        if (prev_count != end_count)
485
271M
            skip_white_pixels(prev_data, prev_p, prev_count, invert, rlen);
486
271M
        diff = a1 - prev_count; /* i.e., logical b1 - a1 */
487
        /* In all the comparisons below, remember that count */
488
        /* runs downward, not upward, so the comparisons are */
489
        /* reversed. */
490
271M
        if (diff <= -2) {
491
            /* Could be a pass mode.  Find b2. */
492
10.2M
            if (prev_count != end_count)
493
10.2M
                skip_black_pixels(prev_data, prev_p,
494
10.2M
                                  prev_count, invert, rlen);
495
10.2M
            if (prev_count > a1) {
496
                /* Use pass mode. */
497
4.22M
                if_debug4m('W', ss->memory, "[W]pass: count = %d, a1 = %d, b1 = %d, new count = %d\n",
498
4.22M
                           a0, a1, b1, prev_count);
499
4.22M
                hc_put_value(ss, q, cf2_run_pass_value, cf2_run_pass_length);
500
4.22M
                a0 = prev_count;
501
4.22M
                goto pass;
502
4.22M
            }
503
10.2M
        }
504
        /* Check for vertical coding. */
505
267M
        if (diff <= 3 && diff >= -3) {
506
            /* Use vertical coding. */
507
257M
            const cfe_run *cp = &cf2_run_vertical[diff + 3];
508
509
257M
            if_debug5m('W', ss->memory, "[W]vertical %d: count = %d, a1 = %d, b1 = %d, new count = %d\n",
510
257M
                       diff, a0, a1, b1, count);
511
257M
            hc_put_code(ss, q, cp);
512
257M
            invert = ~invert; /* a1 polarity changes */
513
257M
            data ^= 0xff;
514
257M
            continue;
515
257M
        }
516
        /* No luck, use horizontal coding. */
517
9.92M
        if (count != end_count)
518
9.92M
            skip_black_pixels(data, p, count, invert, rlen); /* find a2 */
519
9.92M
        hc_put_value(ss, q, cf2_run_horizontal_value,
520
9.92M
                     cf2_run_horizontal_length);
521
9.92M
        a0 -= a1;
522
9.92M
        a1 -= count;
523
9.92M
        if (invert == invert_white) {
524
6.11M
            if_debug3m('W', ss->memory, "[W]horizontal: white = %d, black = %d, new count = %d\n",
525
6.11M
                      a0, a1, count);
526
6.11M
            CF_PUT_WHITE_RUN(ss, a0);
527
6.11M
            CF_PUT_BLACK_RUN(ss, a1);
528
6.11M
        } else {
529
3.81M
            if_debug3m('W', ss->memory, "[W]horizontal: black = %d, white = %d, new count = %d\n",
530
3.81M
                       a0, a1, count);
531
3.81M
            CF_PUT_BLACK_RUN(ss, a0);
532
3.81M
            CF_PUT_WHITE_RUN(ss, a1);
533
3.81M
#undef b1
534
3.81M
        }
535
9.92M
    }
536
60.5M
    hce_store_state();
537
60.5M
    pw->ptr = q;
538
60.5M
}
539
540
/* Stream template */
541
const stream_template s_CFE_template =
542
{
543
    &st_CFE_state, s_CFE_init, s_CFE_process, 1, 1,
544
    s_CFE_release, s_CFE_set_defaults
545
};