2 * Copyright (C)2011 D. R. Commander. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of the libjpeg-turbo Project nor the names of its
13 * contributors may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 /* This program demonstrates how to check for the colorspace extension
30 capabilities of libjpeg-turbo at both compile time and run time. */
37 #ifndef JCS_EXTENSIONS
40 #if !defined(JCS_EXTENSIONS) || !defined(JCS_ALPHA_EXTENSIONS)
41 #define JCS_EXT_RGBA 12
44 static char lasterror[JMSG_LENGTH_MAX] = "No error";
46 typedef struct _error_mgr {
47 struct jpeg_error_mgr pub;
51 static void my_error_exit(j_common_ptr cinfo)
53 error_mgr *myerr = (error_mgr *)cinfo->err;
54 (*cinfo->err->output_message) (cinfo);
55 longjmp(myerr->jb, 1);
58 static void my_output_message(j_common_ptr cinfo)
60 (*cinfo->err->format_message) (cinfo, lasterror);
65 int jcs_valid = -1, jcs_alpha_valid = -1;
66 struct jpeg_compress_struct cinfo;
69 printf("libjpeg-turbo colorspace extensions:\n");
71 printf(" Present at compile time\n");
73 printf(" Not present at compile time\n");
76 cinfo.err = jpeg_std_error(&jerr.pub);
77 jerr.pub.error_exit = my_error_exit;
78 jerr.pub.output_message = my_output_message;
80 if (setjmp(jerr.jb)) {
81 /* this will execute if libjpeg has an error */
86 jpeg_create_compress(&cinfo);
87 cinfo.input_components = 3;
88 jpeg_set_defaults(&cinfo);
89 cinfo.in_color_space = JCS_EXT_RGB;
90 jpeg_default_colorspace(&cinfo);
95 printf(" Working properly\n");
97 printf(" Not working properly. Error returned was:\n %s\n",
100 printf("libjpeg-turbo alpha colorspace extensions:\n");
101 #if JCS_ALPHA_EXTENSIONS
102 printf(" Present at compile time\n");
104 printf(" Not present at compile time\n");
107 if (setjmp(jerr.jb)) {
108 /* this will execute if libjpeg has an error */
113 cinfo.in_color_space = JCS_EXT_RGBA;
114 jpeg_default_colorspace(&cinfo);
119 printf(" Working properly\n");
121 printf(" Not working properly. Error returned was:\n %s\n",
124 jpeg_destroy_compress(&cinfo);