Coverage Report

Created: 2025-06-10 07:06

/src/ghostpdl/psi/zfdcte.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
/* DCTEncode filter creation */
18
#include "memory_.h"
19
#include "stdio_.h"   /* for jpeglib.h */
20
#include "jpeglib_.h"
21
#include "ghost.h"
22
#include "oper.h"
23
#include "gsmemory.h"
24
#include "ialloc.h"
25
#include "idict.h"
26
#include "idparam.h"
27
#include "strimpl.h"
28
#include "sdct.h"
29
#include "sjpeg.h"
30
#include "ifilter.h"
31
#include "iparam.h"
32
33
/* Import the parameter processing procedure from sdeparam.c */
34
stream_state_proc_put_params(s_DCTE_put_params, stream_DCT_state);
35
36
/* <target> <dict> DCTEncode/filter <file> */
37
static int
38
zDCTE(i_ctx_t *i_ctx_p)
39
0
{
40
0
    os_ptr op = osp;
41
0
    gs_memory_t *mem = gs_memory_stable(imemory);
42
0
    stream_DCT_state state;
43
0
    dict_param_list list;
44
0
    jpeg_compress_data *jcdp;
45
0
    int code;
46
0
    const ref *dop;
47
0
    uint dspace;
48
49
0
    check_op(2);
50
    /* First allocate space for IJG parameters. */
51
0
    jcdp = gs_alloc_struct_immovable(mem, jpeg_compress_data,
52
0
      &st_jpeg_compress_data, "zDCTE");
53
0
    if (jcdp == 0)
54
0
        return_error(gs_error_VMerror);
55
0
    state.memory = mem;
56
0
    if (s_DCTE_template.set_defaults)
57
0
        (*s_DCTE_template.set_defaults) ((stream_state *) & state);
58
0
    state.data.compress = jcdp;
59
0
    jcdp->memory = state.jpeg_memory = mem; /* set now for allocation */
60
0
    state.report_error = filter_report_error; /* in case create fails */
61
0
    if ((code = gs_jpeg_create_compress(&state)) < 0)
62
0
        goto fail;   /* correct to do jpeg_destroy here */
63
    /* Read parameters from dictionary */
64
0
    if (r_has_type(op, t_dictionary))
65
0
        dop = op, dspace = r_space(op);
66
0
    else
67
0
        dop = 0, dspace = 0;
68
0
    if ((code = dict_param_list_read(&list, dop, NULL, false, iimemory)) < 0)
69
0
        goto fail;
70
0
    if ((code = s_DCTE_put_params((gs_param_list *) & list, &state)) < 0)
71
0
        goto rel;
72
    /* Create the filter. */
73
0
    jcdp->templat = s_DCTE_template;
74
    /* Make sure we get at least a full scan line of input. */
75
0
    state.scan_line_size = jcdp->cinfo.input_components *
76
0
        jcdp->cinfo.image_width;
77
0
    state.icc_profile = NULL;
78
0
    jcdp->templat.min_in_size =
79
0
        max(s_DCTE_template.min_in_size, state.scan_line_size);
80
    /* Make sure we can write the user markers in a single go. */
81
0
    jcdp->templat.min_out_size =
82
0
        max(s_DCTE_template.min_out_size, state.Markers.size);
83
0
    code = filter_write(i_ctx_p, 0, &jcdp->templat,
84
0
                        (stream_state *) & state, dspace);
85
0
    if (code >= 0)   /* Success! */
86
0
        return code;
87
    /* We assume that if filter_write fails, the stream has not been
88
     * registered for closing, so s_DCTE_release will never be called.
89
     * Therefore we free the allocated memory before failing.
90
     */
91
0
rel:
92
0
    iparam_list_release(&list);
93
0
fail:
94
0
    gs_jpeg_destroy(&state);
95
0
    gs_free_object(mem, jcdp, "zDCTE fail");
96
0
    return code;
97
0
}
98
99
/* ------ Initialization procedure ------ */
100
101
const op_def zfdcte_op_defs[] =
102
{
103
    op_def_begin_filter(),
104
    {"2DCTEncode", zDCTE},
105
    op_def_end(0)
106
};