diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2017-09-08 01:57:24 +0800 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2017-09-08 01:57:24 +0800 |
commit | 171c079a80b00971bff1aca9de7ee08083bb7ebf (patch) | |
tree | b9c88a64abbe68d788f66ed158ebc9f22818c007 /source/fitz | |
parent | fe82c2d5c3d6128de511093fc4b8eaf47096653c (diff) | |
download | mupdf-171c079a80b00971bff1aca9de7ee08083bb7ebf.tar.xz |
Remove unnecessary fz_try()/fz_catch().
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/archive.c | 17 | ||||
-rw-r--r-- | source/fitz/draw-glyph.c | 25 | ||||
-rw-r--r-- | source/fitz/image.c | 119 | ||||
-rw-r--r-- | source/fitz/load-pnm.c | 35 | ||||
-rw-r--r-- | source/fitz/output-png.c | 8 | ||||
-rw-r--r-- | source/fitz/output.c | 8 |
6 files changed, 89 insertions, 123 deletions
diff --git a/source/fitz/archive.c b/source/fitz/archive.c index 5bd3434b..96e70073 100644 --- a/source/fitz/archive.c +++ b/source/fitz/archive.c @@ -59,17 +59,12 @@ fz_open_archive_with_stream(fz_context *ctx, fz_stream *file) { fz_archive *arch = NULL; - fz_try(ctx) - { - if (fz_is_zip_archive(ctx, file)) - arch = fz_open_zip_archive_with_stream(ctx, file); - else if (fz_is_tar_archive(ctx, file)) - arch = fz_open_tar_archive_with_stream(ctx, file); - else - fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize archive"); - } - fz_catch(ctx) - fz_rethrow(ctx); + if (fz_is_zip_archive(ctx, file)) + arch = fz_open_zip_archive_with_stream(ctx, file); + else if (fz_is_tar_archive(ctx, file)) + arch = fz_open_tar_archive_with_stream(ctx, file); + else + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize archive"); return arch; } diff --git a/source/fitz/draw-glyph.c b/source/fitz/draw-glyph.c index dacee540..9c0a1b70 100644 --- a/source/fitz/draw-glyph.c +++ b/source/fitz/draw-glyph.c @@ -429,25 +429,18 @@ fz_render_glyph_pixmap(fz_context *ctx, fz_font *font, int gid, fz_matrix *ctm, return NULL; } - fz_try(ctx) + if (is_ft_font) { - if (is_ft_font) - { - val = fz_render_ft_glyph_pixmap(ctx, font, gid, &subpix_ctm, aa); - } - else if (fz_font_t3_procs(ctx, font)) - { - val = fz_render_t3_glyph_pixmap(ctx, font, gid, &subpix_ctm, NULL, scissor, aa); - } - else - { - fz_warn(ctx, "assert: uninitialized font structure"); - val = NULL; - } + val = fz_render_ft_glyph_pixmap(ctx, font, gid, &subpix_ctm, aa); } - fz_catch(ctx) + else if (fz_font_t3_procs(ctx, font)) + { + val = fz_render_t3_glyph_pixmap(ctx, font, gid, &subpix_ctm, NULL, scissor, aa); + } + else { - fz_rethrow(ctx); + fz_warn(ctx, "assert: uninitialized font structure"); + val = NULL; } return val; diff --git a/source/fitz/image.c b/source/fitz/image.c index 9eedea8a..3ac2afeb 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -909,70 +909,65 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer) /* Note: cspace is only ever a borrowed reference here */ - fz_try(ctx) + if (buf[0] == 'P' && buf[1] >= '1' && buf[1] <= '7') { - if (buf[0] == 'P' && buf[1] >= '1' && buf[1] <= '7') - { - type = FZ_IMAGE_PNM; - fz_load_pnm_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (buf[0] == 0xff && buf[1] == 0x4f) - { - type = FZ_IMAGE_JPX; - fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x00 && buf[3] == 0x0c && buf[4] == 0x6a && buf[5] == 0x50 && buf[6] == 0x20 && buf[7] == 0x20) - { - type = FZ_IMAGE_JPX; - fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (buf[0] == 0xff && buf[1] == 0xd8) - { - type = FZ_IMAGE_JPEG; - fz_load_jpeg_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0) - { - type = FZ_IMAGE_PNG; - fz_load_png_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 0xBC) - { - type = FZ_IMAGE_JXR; - fz_load_jxr_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 42 && buf[3] == 0) - { - type = FZ_IMAGE_TIFF; - fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (buf[0] == 'M' && buf[1] == 'M' && buf[2] == 0 && buf[3] == 42) - { - type = FZ_IMAGE_TIFF; - fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (memcmp(buf, "GIF", 3) == 0) - { - type = FZ_IMAGE_GIF; - fz_load_gif_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else if (memcmp(buf, "BM", 2) == 0) - { - type = FZ_IMAGE_BMP; - fz_load_bmp_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); - } - else - fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format"); - - bc = fz_malloc_struct(ctx, fz_compressed_buffer); - bc->buffer = fz_keep_buffer(ctx, buffer); - bc->params.type = type; - if (type == FZ_IMAGE_JPEG) - bc->params.u.jpeg.color_transform = -1; - image = fz_new_image_from_compressed_buffer(ctx, w, h, 8, cspace, xres, yres, 0, 0, NULL, NULL, bc, NULL); + type = FZ_IMAGE_PNM; + fz_load_pnm_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); } - fz_catch(ctx) - fz_rethrow(ctx); + else if (buf[0] == 0xff && buf[1] == 0x4f) + { + type = FZ_IMAGE_JPX; + fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0x00 && buf[3] == 0x0c && buf[4] == 0x6a && buf[5] == 0x50 && buf[6] == 0x20 && buf[7] == 0x20) + { + type = FZ_IMAGE_JPX; + fz_load_jpx_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (buf[0] == 0xff && buf[1] == 0xd8) + { + type = FZ_IMAGE_JPEG; + fz_load_jpeg_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (memcmp(buf, "\211PNG\r\n\032\n", 8) == 0) + { + type = FZ_IMAGE_PNG; + fz_load_png_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 0xBC) + { + type = FZ_IMAGE_JXR; + fz_load_jxr_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (buf[0] == 'I' && buf[1] == 'I' && buf[2] == 42 && buf[3] == 0) + { + type = FZ_IMAGE_TIFF; + fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (buf[0] == 'M' && buf[1] == 'M' && buf[2] == 0 && buf[3] == 42) + { + type = FZ_IMAGE_TIFF; + fz_load_tiff_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (memcmp(buf, "GIF", 3) == 0) + { + type = FZ_IMAGE_GIF; + fz_load_gif_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else if (memcmp(buf, "BM", 2) == 0) + { + type = FZ_IMAGE_BMP; + fz_load_bmp_info(ctx, buf, len, &w, &h, &xres, &yres, &cspace); + } + else + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown image file format"); + + bc = fz_malloc_struct(ctx, fz_compressed_buffer); + bc->buffer = fz_keep_buffer(ctx, buffer); + bc->params.type = type; + if (type == FZ_IMAGE_JPEG) + bc->params.u.jpeg.color_transform = -1; + image = fz_new_image_from_compressed_buffer(ctx, w, h, 8, cspace, xres, yres, 0, 0, NULL, NULL, bc, NULL); return image; } diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c index 36493823..c30d0688 100644 --- a/source/fitz/load-pnm.c +++ b/source/fitz/load-pnm.c @@ -392,30 +392,25 @@ pam_binary_read_header(fz_context *ctx, struct info *pnm, unsigned char *p, unsi { int token = TOKEN_UNKNOWN; - fz_try(ctx) + while (p < e && token != TOKEN_ENDHDR) { - while (p < e && token != TOKEN_ENDHDR) + p = pnm_read_token(ctx, p, e, &token); + p = pnm_read_white(ctx, p, e, 0); + switch (token) { - p = pnm_read_token(ctx, p, e, &token); - p = pnm_read_white(ctx, p, e, 0); - switch (token) - { - case TOKEN_WIDTH: p = pnm_read_number(ctx, p, e, &pnm->width); break; - case TOKEN_HEIGHT: p = pnm_read_number(ctx, p, e, &pnm->height); break; - case TOKEN_DEPTH: p = pnm_read_number(ctx, p, e, &pnm->depth); break; - case TOKEN_MAXVAL: p = pnm_read_number(ctx, p, e, &pnm->maxval); break; - case TOKEN_TUPLTYPE: p = pnm_read_tupletype(ctx, p, e, &pnm->tupletype); break; - case TOKEN_ENDHDR: break; - default: - fz_throw(ctx, FZ_ERROR_GENERIC, "unknown header token in pnm image"); - } - - if (token != TOKEN_ENDHDR) - p = pnm_read_white(ctx, p, e, 0); + case TOKEN_WIDTH: p = pnm_read_number(ctx, p, e, &pnm->width); break; + case TOKEN_HEIGHT: p = pnm_read_number(ctx, p, e, &pnm->height); break; + case TOKEN_DEPTH: p = pnm_read_number(ctx, p, e, &pnm->depth); break; + case TOKEN_MAXVAL: p = pnm_read_number(ctx, p, e, &pnm->maxval); break; + case TOKEN_TUPLTYPE: p = pnm_read_tupletype(ctx, p, e, &pnm->tupletype); break; + case TOKEN_ENDHDR: break; + default: + fz_throw(ctx, FZ_ERROR_GENERIC, "unknown header token in pnm image"); } + + if (token != TOKEN_ENDHDR) + p = pnm_read_white(ctx, p, e, 0); } - fz_catch(ctx) - fz_rethrow(ctx); return p; } diff --git a/source/fitz/output-png.c b/source/fitz/output-png.c index afda42f3..f67b1de0 100644 --- a/source/fitz/output-png.c +++ b/source/fitz/output-png.c @@ -356,13 +356,7 @@ fz_buffer * fz_new_buffer_from_image_as_png(fz_context *ctx, fz_image *image, const fz_color_params *color_params) { fz_pixmap *pix = fz_get_pixmap_from_image(ctx, image, NULL, NULL, NULL, NULL); - fz_buffer *buf = NULL; - - fz_try(ctx) - buf = png_from_pixmap(ctx, pix, color_params, 1); - fz_catch(ctx) - fz_rethrow(ctx); - return buf; + return png_from_pixmap(ctx, pix, color_params, 1); } fz_buffer * diff --git a/source/fitz/output.c b/source/fitz/output.c index a0f7fdee..44efc414 100644 --- a/source/fitz/output.c +++ b/source/fitz/output.c @@ -178,7 +178,6 @@ fz_new_output_with_file_ptr(fz_context *ctx, FILE *file, int close) fz_output * fz_new_output_with_path(fz_context *ctx, const char *filename, int append) { - fz_output *out = NULL; FILE *file; if (!strcmp(filename, "/dev/null") || !fz_strcasecmp(filename, "nul:")) @@ -196,12 +195,7 @@ fz_new_output_with_path(fz_context *ctx, const char *filename, int append) if (!file) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); - fz_try(ctx) - out = fz_new_output_with_file_ptr(ctx, file, 1); - fz_catch(ctx) - fz_rethrow(ctx); - - return out; + return fz_new_output_with_file_ptr(ctx, file, 1); } static void |