xref: /plan9/sys/src/cmd/gs/src/sjpegd.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1994, 1998, 1999 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: sjpegd.c,v 1.5 2002/02/21 22:24:54 giles Exp $ */
18 /* Interface routines for IJG decoding code. */
19 #include "stdio_.h"
20 #include "string_.h"
21 #include "jpeglib_.h"
22 #include "jerror_.h"
23 #include "gx.h"
24 #include "gserrors.h"
25 #include "strimpl.h"
26 #include "sdct.h"
27 #include "sjpeg.h"
28 
29 /*
30  * Interface routines.  This layer of routines exists solely to limit
31  * side-effects from using setjmp.
32  */
33 
34 int
gs_jpeg_create_decompress(stream_DCT_state * st)35 gs_jpeg_create_decompress(stream_DCT_state * st)
36 {				/* Initialize error handling */
37     gs_jpeg_error_setup(st);
38     /* Establish the setjmp return context for gs_jpeg_error_exit to use. */
39     if (setjmp(st->data.common->exit_jmpbuf))
40 	return_error(gs_jpeg_log_error(st));
41 
42     jpeg_stream_data_common_init(st->data.decompress);
43     jpeg_create_decompress(&st->data.decompress->dinfo);
44     return 0;
45 }
46 
47 int
gs_jpeg_read_header(stream_DCT_state * st,boolean require_image)48 gs_jpeg_read_header(stream_DCT_state * st,
49 		    boolean require_image)
50 {
51     if (setjmp(st->data.common->exit_jmpbuf))
52 	return_error(gs_jpeg_log_error(st));
53     return jpeg_read_header(&st->data.decompress->dinfo, require_image);
54 }
55 
56 int
gs_jpeg_start_decompress(stream_DCT_state * st)57 gs_jpeg_start_decompress(stream_DCT_state * st)
58 {
59     if (setjmp(st->data.common->exit_jmpbuf))
60 	return_error(gs_jpeg_log_error(st));
61 #if JPEG_LIB_VERSION > 55
62     return (int)jpeg_start_decompress(&st->data.decompress->dinfo);
63 #else
64     /* in IJG version 5, jpeg_start_decompress had no return value */
65     jpeg_start_decompress(&st->data.decompress->dinfo);
66     return 1;
67 #endif
68 }
69 
70 int
gs_jpeg_read_scanlines(stream_DCT_state * st,JSAMPARRAY scanlines,int max_lines)71 gs_jpeg_read_scanlines(stream_DCT_state * st,
72 		       JSAMPARRAY scanlines,
73 		       int max_lines)
74 {
75     if (setjmp(st->data.common->exit_jmpbuf))
76 	return_error(gs_jpeg_log_error(st));
77     return (int)jpeg_read_scanlines(&st->data.decompress->dinfo,
78 				    scanlines, (JDIMENSION) max_lines);
79 }
80 
81 int
gs_jpeg_finish_decompress(stream_DCT_state * st)82 gs_jpeg_finish_decompress(stream_DCT_state * st)
83 {
84     if (setjmp(st->data.common->exit_jmpbuf))
85 	return_error(gs_jpeg_log_error(st));
86     return (int)jpeg_finish_decompress(&st->data.decompress->dinfo);
87 }
88