2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief JPEG File format support.
23 * \arg File name extension: jpeg, jpg
28 <support_level>extended</support_level>
33 #include "asterisk/mod_format.h"
34 #include "asterisk/module.h"
35 #include "asterisk/image.h"
36 #include "asterisk/endian.h"
37 #include "asterisk/format_cache.h"
39 static struct ast_frame *jpeg_read_image(int fd, int len)
44 if (len > sizeof(buf) || len < 0) {
45 ast_log(LOG_WARNING, "JPEG image too large to read\n");
48 res = read(fd, buf, len);
50 ast_log(LOG_WARNING, "Only read %d of %d bytes: %s\n", res, len, strerror(errno));
52 memset(&fr, 0, sizeof(fr));
53 fr.frametype = AST_FRAME_IMAGE;
54 fr.subclass.format = ast_format_jpeg;
58 return ast_frisolate(&fr);
61 static int jpeg_identify(int fd)
65 res = read(fd, buf, sizeof(buf));
66 if (res < sizeof(buf))
68 if (memcmp(buf + 6, "JFIF", 4))
73 static int jpeg_write_image(int fd, struct ast_frame *fr)
77 res = write(fd, fr->data.ptr, fr->datalen);
78 if (res != fr->datalen) {
79 ast_log(LOG_WARNING, "Only wrote %d of %d bytes: %s\n", res, fr->datalen, strerror(errno));
86 static struct ast_imager jpeg_format = {
88 .desc = "JPEG (Joint Picture Experts Group)",
90 .read_image = jpeg_read_image,
91 .identify = jpeg_identify,
92 .write_image = jpeg_write_image,
95 static int load_module(void)
97 jpeg_format.format = ast_format_jpeg;
98 if (ast_image_register(&jpeg_format))
99 return AST_MODULE_LOAD_DECLINE;
100 return AST_MODULE_LOAD_SUCCESS;
103 static int unload_module(void)
105 ast_image_unregister(&jpeg_format);
110 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "jpeg (joint picture experts group) image format",
111 .support_level = AST_MODULE_SUPPORT_EXTENDED,
113 .unload = unload_module,
114 .load_pri = AST_MODPRI_APP_DEPEND