Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/psi/zfzlib.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2021 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.,  1305 Grant Avenue - Suite 200, Novato,
13
   CA 94945, U.S.A., +1(415)492-9861, for further information.
14
*/
15
16
17
/* zlib and Flate filter creation */
18
#include "ghost.h"
19
#include "oper.h"
20
#include "idict.h"
21
#include "strimpl.h"
22
#include "spdiffx.h"
23
#include "spngpx.h"
24
#include "szlibx.h"
25
#include "idparam.h"
26
#include "ifilter.h"
27
#include "ifrpred.h"
28
#include "ifwpred.h"
29
30
/* Common setup for zlib (Flate) filter */
31
static int
32
filter_zlib(i_ctx_t *i_ctx_p, stream_zlib_state *pzls)
33
0
{
34
0
    os_ptr op = osp;
35
0
    int code = 0;
36
37
0
    (*s_zlibE_template.set_defaults)((stream_state *)pzls);
38
0
    if (r_has_type(op, t_dictionary))
39
0
        code = dict_int_param(op, "Effort", -1, 9, -1, &pzls->level);
40
0
    return code;
41
0
}
42
43
/* <source> zlibEncode/filter <file> */
44
/* <source> <dict> zlibEncode/filter <file> */
45
static int
46
zzlibE(i_ctx_t *i_ctx_p)
47
0
{
48
0
    stream_zlib_state zls;
49
0
    int code = filter_zlib(i_ctx_p, &zls);
50
51
0
    if (code < 0)
52
0
        return code;
53
0
    return filter_write(i_ctx_p, 0, &s_zlibE_template, (stream_state *)&zls, 0);
54
0
}
55
56
/* <target> zlibDecode/filter <file> */
57
/* <target> <dict> zlibDecode/filter <file> */
58
static int
59
zzlibD(i_ctx_t *i_ctx_p)
60
0
{
61
0
    stream_zlib_state zls;
62
63
0
    (*s_zlibD_template.set_defaults)((stream_state *)&zls);
64
0
    return filter_read(i_ctx_p, 0, &s_zlibD_template, (stream_state *)&zls, 0);
65
0
}
66
67
/* <source> FlateEncode/filter <file> */
68
/* <source> <dict> FlateEncode/filter <file> */
69
static int
70
zFlateE(i_ctx_t *i_ctx_p)
71
0
{
72
0
    stream_zlib_state zls;
73
0
    int code = filter_zlib(i_ctx_p, &zls);
74
75
0
    if (code < 0)
76
0
        return code;
77
0
    return filter_write_predictor(i_ctx_p, 0, &s_zlibE_template,
78
0
                                  (stream_state *)&zls);
79
0
}
80
81
/* <target> FlateDecode/filter <file> */
82
/* <target> <dict> FlateDecode/filter <file> */
83
static int
84
zFlateD(i_ctx_t *i_ctx_p)
85
0
{
86
0
    stream_zlib_state zls;
87
88
0
    (*s_zlibD_template.set_defaults)((stream_state *)&zls);
89
0
    return filter_read_predictor(i_ctx_p, 0, &s_zlibD_template,
90
0
                                 (stream_state *)&zls);
91
0
}
92
93
/* ------ Initialization procedure ------ */
94
95
const op_def zfzlib_op_defs[] =
96
{
97
    op_def_begin_filter(),
98
    {"1zlibEncode", zzlibE},
99
    {"1zlibDecode", zzlibD},
100
    {"1FlateEncode", zFlateE},
101
    {"1FlateDecode", zFlateD},
102
    op_def_end(0)
103
};