diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-05-03 13:02:10 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-05-03 16:39:02 +0100 |
commit | 09bb1dc2a0cbea13b9ad27f626d2c9e16984ebf9 (patch) | |
tree | 25e7a25b122b1c67805b6982e7f583bd4a34e009 /fitz | |
parent | f499ef89525fd596753f1a4e93e8a8c56953e21a (diff) | |
download | mupdf-09bb1dc2a0cbea13b9ad27f626d2c9e16984ebf9.tar.xz |
Simple Image file format recogniser
Now can open jpeg/png/tiff files within mupdf.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/doc_document.c | 19 | ||||
-rw-r--r-- | fitz/fitz-internal.h | 3 | ||||
-rw-r--r-- | fitz/res_image.c | 20 |
3 files changed, 36 insertions, 6 deletions
diff --git a/fitz/doc_document.c b/fitz/doc_document.c index 564329c4..a23aef27 100644 --- a/fitz/doc_document.c +++ b/fitz/doc_document.c @@ -4,10 +4,12 @@ extern struct pdf_document *pdf_open_document(fz_context *ctx, const char *filename); extern struct xps_document *xps_open_document(fz_context *ctx, const char *filename); extern struct cbz_document *cbz_open_document(fz_context *ctx, const char *filename); +extern struct image_document *image_open_document(fz_context *ctx, const char *filename); extern struct pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file); extern struct xps_document *xps_open_document_with_stream(fz_context *ctx, fz_stream *file); extern struct cbz_document *cbz_open_document_with_stream(fz_context *ctx, fz_stream *file); +extern struct image_document *image_open_document_with_stream(fz_context *ctx, fz_stream *file); extern int pdf_js_supported(void); @@ -42,6 +44,11 @@ fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stre return (fz_document*) cbz_open_document_with_stream(ctx, stream); if (!fz_strcasecmp(ext, ".pdf")) return (fz_document*) pdf_open_document_with_stream(ctx, stream); + if (!fz_strcasecmp(ext, ".png") || !fz_strcasecmp(ext, ".jpg") || + !fz_strcasecmp(ext, ".jpeg") || !fz_strcasecmp(ext, ".jfif") || + !fz_strcasecmp(ext, ".jfif-tbnl") || !fz_strcasecmp(ext, ".jpe") || + !fz_strcasecmp(ext, ".tif") || !fz_strcasecmp(ext, ".tiff")) + return (fz_document*) image_open_document_with_stream(ctx, stream); } if (!strcmp(magic, "cbz") || !strcmp(magic, "application/x-cbz")) @@ -50,6 +57,13 @@ fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stre return (fz_document*) xps_open_document_with_stream(ctx, stream); if (!strcmp(magic, "pdf") || !strcmp(magic, "application/pdf")) return (fz_document*) pdf_open_document_with_stream(ctx, stream); + if (!strcmp(magic, "png") || !strcmp(magic, "image/png") || + !strcmp(magic, "jpg") || !strcmp(magic, "image/jpeg") || + !strcmp(magic, "jpeg") || !strcmp(magic, "image/pjpeg") || + !strcmp(magic, "jpe") || !strcmp(magic, "jfif") || + !strcmp(magic, "tif") || !strcmp(magic, "image/tiff") || + !strcmp(magic, "tiff") || !strcmp(magic, "image/x-tiff")) + return (fz_document*) image_open_document_with_stream(ctx, stream); /* last guess: pdf */ return (fz_document*) pdf_open_document_with_stream(ctx, stream); @@ -68,6 +82,11 @@ fz_open_document(fz_context *ctx, const char *filename) return (fz_document*) cbz_open_document(ctx, filename); if (!fz_strcasecmp(ext, ".pdf")) return (fz_document*) pdf_open_document(ctx, filename); + if (!fz_strcasecmp(ext, ".png") || !fz_strcasecmp(ext, ".jpg") || + !fz_strcasecmp(ext, ".jpeg") || !fz_strcasecmp(ext, ".jpe") || + !fz_strcasecmp(ext, ".jfif") || !fz_strcasecmp(ext, ".jfif-tbnl") || + !fz_strcasecmp(ext, ".tif") || !fz_strcasecmp(ext, ".tiff")) + return (fz_document*) image_open_document(ctx, filename); } /* last guess: pdf */ diff --git a/fitz/fitz-internal.h b/fitz/fitz-internal.h index bf7d2873..17a919d3 100644 --- a/fitz/fitz-internal.h +++ b/fitz/fitz-internal.h @@ -977,7 +977,8 @@ void fz_free_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf); fz_image *fz_new_image(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, int xres, int yres, int interpolate, int imagemask, float *decode, int *colorkey, fz_compressed_buffer *buffer, fz_image *mask); fz_image *fz_new_image_from_pixmap(fz_context *ctx, fz_pixmap *pixmap, fz_image *mask); -fz_image *fz_new_image_from_buffer(fz_context *ctx, unsigned char *buf, int len); +fz_image *fz_new_image_from_data(fz_context *ctx, unsigned char *data, int len); +fz_image *fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer); fz_pixmap *fz_image_get_pixmap(fz_context *ctx, fz_image *image, int w, int h); void fz_free_image(fz_context *ctx, fz_storable *image); fz_pixmap *fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, int in_line, int indexed, int l2factor, int native_l2factor); diff --git a/fitz/res_image.c b/fitz/res_image.c index c8ba8257..82703b50 100644 --- a/fitz/res_image.c +++ b/fitz/res_image.c @@ -416,15 +416,25 @@ fz_new_image(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, } fz_image * -fz_new_image_from_buffer(fz_context *ctx, unsigned char *buf, int len) +fz_new_image_from_data(fz_context *ctx, unsigned char *data, int len) +{ + fz_buffer *buffer = fz_new_buffer_from_data(ctx, data, len); + + return fz_new_image_from_buffer(ctx, buffer); +} + +fz_image * +fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer) { fz_compressed_buffer *bc = NULL; int w, h, xres, yres; fz_colorspace *cspace; - unsigned char *free_buf = buf; + fz_buffer *drop_buffer = buffer; + int len = buffer->len; + unsigned char *buf = buffer->data; fz_var(bc); - fz_var(free_buf); + fz_var(drop_buffer); fz_try(ctx) { @@ -433,7 +443,7 @@ fz_new_image_from_buffer(fz_context *ctx, unsigned char *buf, int len) bc = fz_malloc_struct(ctx, fz_compressed_buffer); bc->buffer = fz_new_buffer_from_data(ctx, buf, len); - free_buf = NULL; + drop_buffer = NULL; if (buf[0] == 0xff && buf[1] == 0xd8) { @@ -458,7 +468,7 @@ fz_new_image_from_buffer(fz_context *ctx, unsigned char *buf, int len) } fz_catch(ctx) { - fz_free(ctx, free_buf); + fz_drop_buffer(ctx, drop_buffer); fz_free_compressed_buffer(ctx, bc); fz_rethrow(ctx); } |