Coverage Report

Created: 2025-04-22 06:20

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