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
29 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
31 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
41 #include "asterisk/channel.h"
42 #include "asterisk/file.h"
43 #include "asterisk/logger.h"
44 #include "asterisk/sched.h"
45 #include "asterisk/module.h"
46 #include "asterisk/image.h"
47 #include "asterisk/lock.h"
48 #include "asterisk/endian.h"
50 static struct ast_frame
*jpeg_read_image(int fd
, int len
)
55 if (len
> sizeof(buf
) || len
< 0) {
56 ast_log(LOG_WARNING
, "JPEG image too large to read\n");
59 res
= read(fd
, buf
, len
);
61 ast_log(LOG_WARNING
, "Only read %d of %d bytes: %s\n", res
, len
, strerror(errno
));
63 memset(&fr
, 0, sizeof(fr
));
64 fr
.frametype
= AST_FRAME_IMAGE
;
65 fr
.subclass
= AST_FORMAT_JPEG
;
69 return ast_frisolate(&fr
);
72 static int jpeg_identify(int fd
)
76 res
= read(fd
, buf
, sizeof(buf
));
77 if (res
< sizeof(buf
))
79 if (memcmp(buf
+ 6, "JFIF", 4))
84 static int jpeg_write_image(int fd
, struct ast_frame
*fr
)
87 if (fr
->frametype
!= AST_FRAME_IMAGE
) {
88 ast_log(LOG_WARNING
, "Not an image\n");
91 if (fr
->subclass
!= AST_FORMAT_JPEG
) {
92 ast_log(LOG_WARNING
, "Not a jpeg image\n");
96 res
= write(fd
, fr
->data
, fr
->datalen
);
97 if (res
!= fr
->datalen
) {
98 ast_log(LOG_WARNING
, "Only wrote %d of %d bytes: %s\n", res
, fr
->datalen
, strerror(errno
));
105 static struct ast_imager jpeg_format
= {
107 "JPEG (Joint Picture Experts Group)",
115 static int load_module(void)
117 return ast_image_register(&jpeg_format
);
120 static int unload_module(void)
122 ast_image_unregister(&jpeg_format
);
127 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "JPEG (Joint Picture Experts Group) Image Format");