File: sjpegd.c

package info (click to toggle)
ghostscript 10.06.0~dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 96,296 kB
  • sloc: ansic: 944,438; python: 7,917; cpp: 6,534; cs: 6,457; sh: 6,168; java: 4,028; perl: 2,373; tcl: 1,639; makefile: 538; awk: 66; yacc: 18
file content (115 lines) | stat: -rw-r--r-- 3,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Copyright (C) 2001-2025 Artifex Software, Inc.
   All Rights Reserved.

   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied,
   modified or distributed except as expressly authorized under the terms
   of the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
   CA 94129, USA, for further information.
*/


/* Interface routines for IJG decoding code. */
#include "stdio_.h"
#include "string_.h"
#include "jpeglib_.h"
#include "jerror_.h"
#include "gserrors.h"
#include "gx.h"
#include "strimpl.h"
#include "sdct.h"
#include "sjpeg.h"
#include "setjmp_.h"

/*
 * Interface routines.  This layer of routines exists solely to limit
 * side-effects from using setjmp.
 */

OPTIMIZE_SETJMP
int
gs_jpeg_create_decompress(stream_DCT_state * st)
{				/* Initialize error handling */
    gs_jpeg_error_setup(st);
#if INIT_GS_JMPBUF==1
    memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf));
#endif
    /* Establish the setjmp return context for gs_jpeg_error_exit to use. */
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
        return_error(gs_jpeg_log_error(st));

    jpeg_stream_data_common_init(st->data.decompress);

    if (gs_jpeg_mem_init (st->memory, (j_common_ptr)&st->data.decompress->dinfo) < 0)
        return_error(gs_error_VMerror);

    jpeg_create_decompress(&st->data.decompress->dinfo);
    return 0;
}

OPTIMIZE_SETJMP
int
gs_jpeg_read_header(stream_DCT_state * st,
                    boolean require_image)
{
#if INIT_GS_JMPBUF==1
    memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf));
#endif
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
        return_error(gs_jpeg_log_error(st));
    return jpeg_read_header(&st->data.decompress->dinfo, require_image);
}

OPTIMIZE_SETJMP
int
gs_jpeg_start_decompress(stream_DCT_state * st)
{
#if INIT_GS_JMPBUF==1
    memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf));
#endif
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
        return_error(gs_jpeg_log_error(st));
#if JPEG_LIB_VERSION > 55
    return (int)jpeg_start_decompress(&st->data.decompress->dinfo);
#else
    /* in IJG version 5, jpeg_start_decompress had no return value */
    jpeg_start_decompress(&st->data.decompress->dinfo);
    return 1;
#endif
}

OPTIMIZE_SETJMP
int
gs_jpeg_read_scanlines(stream_DCT_state * st,
                       JSAMPARRAY scanlines,
                       int max_lines)
{
#if INIT_GS_JMPBUF==1
    memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf));
#endif
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
        return_error(gs_jpeg_log_error(st));
    return (int)jpeg_read_scanlines(&st->data.decompress->dinfo,
                                    scanlines, (JDIMENSION) max_lines);
}

OPTIMIZE_SETJMP
int
gs_jpeg_finish_decompress(stream_DCT_state * st)
{
    int code = 0;
#if INIT_GS_JMPBUF==1
    memset(&(st->data.common->exit_jmpbuf), 0x00, sizeof(st->data.common->exit_jmpbuf));
#endif
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
        code = gs_note_error(gs_jpeg_log_error(st));
    if (code >= 0)
        code = (int)jpeg_finish_decompress(&st->data.decompress->dinfo);
    stream_dct_end_passthrough(st->data.decompress);
    return code;
}