Coverage Report

Created: 2025-06-10 06:59

/src/ghostpdl/base/sjpege.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2025 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
/* Interface routines for IJG encoding code. */
18
#include "stdio_.h"
19
#include "string_.h"
20
#include "jpeglib_.h"
21
#include "jerror_.h"
22
#include "gx.h"
23
#include "strimpl.h"
24
#include "sdct.h"
25
#include "sjpeg.h"
26
#include "setjmp_.h"
27
28
/*
29
 * Interface routines.  This layer of routines exists solely to limit
30
 * side-effects from using setjmp.
31
 */
32
33
OPTIMIZE_SETJMP
34
int
35
gs_jpeg_create_compress(stream_DCT_state * st)
36
0
{       /* Initialize error handling */
37
0
    gs_jpeg_error_setup(st);
38
    /* Establish the setjmp return context for gs_jpeg_error_exit to use. */
39
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
40
0
        return_error(gs_jpeg_log_error(st));
41
42
0
    jpeg_stream_data_common_init(st->data.compress);
43
44
0
    if (gs_jpeg_mem_init (st->memory, (j_common_ptr)&st->data.compress->cinfo) < 0)
45
0
        return_error(gs_error_VMerror);
46
47
0
    jpeg_create_compress(&st->data.compress->cinfo);
48
0
    return 0;
49
0
}
50
51
OPTIMIZE_SETJMP
52
int
53
gs_jpeg_set_defaults(stream_DCT_state * st)
54
0
{
55
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
56
0
        return_error(gs_jpeg_log_error(st));
57
0
    jpeg_set_defaults(&st->data.compress->cinfo);
58
0
    return 0;
59
0
}
60
61
OPTIMIZE_SETJMP
62
int
63
gs_jpeg_set_colorspace(stream_DCT_state * st,
64
                       J_COLOR_SPACE colorspace)
65
0
{
66
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
67
0
        return_error(gs_jpeg_log_error(st));
68
0
    jpeg_set_colorspace(&st->data.compress->cinfo, colorspace);
69
0
    return 0;
70
0
}
71
72
OPTIMIZE_SETJMP
73
int
74
gs_jpeg_set_linear_quality(stream_DCT_state * st,
75
                           int scale_factor, boolean force_baseline)
76
0
{
77
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
78
0
        return_error(gs_jpeg_log_error(st));
79
0
    jpeg_set_linear_quality(&st->data.compress->cinfo,
80
0
                            scale_factor, force_baseline);
81
0
    return 0;
82
0
}
83
84
OPTIMIZE_SETJMP
85
int
86
gs_jpeg_set_quality(stream_DCT_state * st,
87
                    int quality, boolean force_baseline)
88
0
{
89
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
90
0
        return_error(gs_jpeg_log_error(st));
91
0
    jpeg_set_quality(&st->data.compress->cinfo,
92
0
                     quality, force_baseline);
93
0
    return 0;
94
0
}
95
96
OPTIMIZE_SETJMP
97
int
98
gs_jpeg_start_compress(stream_DCT_state * st,
99
                       boolean write_all_tables)
100
0
{
101
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
102
0
        return_error(gs_jpeg_log_error(st));
103
0
    jpeg_start_compress(&st->data.compress->cinfo, write_all_tables);
104
0
    return 0;
105
0
}
106
107
OPTIMIZE_SETJMP
108
int
109
gs_jpeg_write_scanlines(stream_DCT_state * st,
110
                        JSAMPARRAY scanlines,
111
                        int num_lines)
112
0
{
113
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
114
0
        return_error(gs_jpeg_log_error(st));
115
0
    return (int)jpeg_write_scanlines(&st->data.compress->cinfo,
116
0
                                     scanlines, (JDIMENSION) num_lines);
117
0
}
118
119
OPTIMIZE_SETJMP
120
int
121
gs_jpeg_finish_compress(stream_DCT_state * st)
122
0
{
123
0
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
124
0
        return_error(gs_jpeg_log_error(st));
125
0
    jpeg_finish_compress(&st->data.compress->cinfo);
126
0
    return 0;
127
0
}