Coverage Report

Created: 2022-10-31 07:00

/src/ghostpdl/base/sjpegd.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
/* Interface routines for IJG decoding code. */
18
#include "stdio_.h"
19
#include "string_.h"
20
#include "jpeglib_.h"
21
#include "jerror_.h"
22
#include "gserrors.h"
23
#include "gx.h"
24
#include "strimpl.h"
25
#include "sdct.h"
26
#include "sjpeg.h"
27
28
/*
29
 * Interface routines.  This layer of routines exists solely to limit
30
 * side-effects from using setjmp.
31
 */
32
33
int
34
gs_jpeg_create_decompress(stream_DCT_state * st)
35
6.44k
{       /* Initialize error handling */
36
6.44k
    gs_jpeg_error_setup(st);
37
    /* Establish the setjmp return context for gs_jpeg_error_exit to use. */
38
6.44k
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
39
1
        return_error(gs_jpeg_log_error(st));
40
41
6.44k
    jpeg_stream_data_common_init(st->data.decompress);
42
43
6.44k
    if (gs_jpeg_mem_init (st->memory, (j_common_ptr)&st->data.decompress->dinfo) < 0)
44
0
        return_error(gs_error_VMerror);
45
46
6.44k
    jpeg_create_decompress(&st->data.decompress->dinfo);
47
6.44k
    return 0;
48
6.44k
}
49
50
int
51
gs_jpeg_read_header(stream_DCT_state * st,
52
                    boolean require_image)
53
9.27k
{
54
9.27k
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
55
742
        return_error(gs_jpeg_log_error(st));
56
8.52k
    return jpeg_read_header(&st->data.decompress->dinfo, require_image);
57
9.27k
}
58
59
int
60
gs_jpeg_start_decompress(stream_DCT_state * st)
61
7.72k
{
62
7.72k
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
63
67
        return_error(gs_jpeg_log_error(st));
64
7.65k
#if JPEG_LIB_VERSION > 55
65
7.65k
    return (int)jpeg_start_decompress(&st->data.decompress->dinfo);
66
#else
67
    /* in IJG version 5, jpeg_start_decompress had no return value */
68
    jpeg_start_decompress(&st->data.decompress->dinfo);
69
    return 1;
70
#endif
71
7.72k
}
72
73
int
74
gs_jpeg_read_scanlines(stream_DCT_state * st,
75
                       JSAMPARRAY scanlines,
76
                       int max_lines)
77
1.18M
{
78
1.18M
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
79
0
        return_error(gs_jpeg_log_error(st));
80
1.18M
    return (int)jpeg_read_scanlines(&st->data.decompress->dinfo,
81
1.18M
                                    scanlines, (JDIMENSION) max_lines);
82
1.18M
}
83
84
int
85
gs_jpeg_finish_decompress(stream_DCT_state * st)
86
9.50k
{
87
9.50k
    int code = 0;
88
9.50k
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
89
590
        code = gs_note_error(gs_jpeg_log_error(st));
90
9.50k
    if (code >= 0)
91
9.50k
        code = (int)jpeg_finish_decompress(&st->data.decompress->dinfo);
92
9.50k
    stream_dct_end_passthrough(st->data.decompress);
93
9.50k
    return code;
94
9.50k
}