summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-02-29 14:19:42 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-02-29 15:56:45 +0100
commit63c0874392c5159e251514db48891500e9854c5d (patch)
tree4c86148cb9705da16876c13a0251b3530d376215
parentfc9dbdec311d643fe020557f5aa0bde045b27186 (diff)
downloadmupdf-63c0874392c5159e251514db48891500e9854c5d.tar.xz
Simplify res_image_get_md5.
We don't need to strip the alpha plane.
-rw-r--r--source/pdf/pdf-resources.c50
1 files changed, 6 insertions, 44 deletions
diff --git a/source/pdf/pdf-resources.c b/source/pdf/pdf-resources.c
index 577a6cc1..826b464b 100644
--- a/source/pdf/pdf-resources.c
+++ b/source/pdf/pdf-resources.c
@@ -25,52 +25,14 @@ res_table_free(fz_context *ctx, pdf_res_table *table)
static void
res_image_get_md5(fz_context *ctx, fz_image *image, unsigned char *digest)
{
- fz_pixmap *pixmap = NULL;
- int n, size;
- fz_buffer *buffer = NULL;
+ fz_pixmap *pixmap;
fz_md5 state;
- fz_var(pixmap);
- fz_var(buffer);
-
- fz_try(ctx)
- {
- pixmap = fz_get_pixmap_from_image(ctx, image, 0, 0);
- n = (pixmap->n == 1 ? 1 : pixmap->n - 1);
- size = image->w * image->h * n;
- buffer = fz_new_buffer(ctx, size);
- buffer->len = size;
- if (pixmap->n == 1)
- {
- memcpy(buffer->data, pixmap->samples, size);
- }
- else
- {
- /* Need to remove the alpha plane */
- unsigned char *d = buffer->data;
- unsigned char *s = pixmap->samples;
- int mod = n;
- while (size--)
- {
- *d++ = *s++;
- mod--;
- if (mod == 0)
- s++, mod = n;
- }
- }
- fz_md5_init(&state);
- fz_md5_update(&state, buffer->data, buffer->len);
- fz_md5_final(&state, digest);
- }
- fz_always(ctx)
- {
- fz_drop_pixmap(ctx, pixmap);
- fz_drop_buffer(ctx, buffer);
- }
- fz_catch(ctx)
- {
- fz_rethrow_message(ctx, "image md5 calculation failed");
- }
+ pixmap = fz_get_pixmap_from_image(ctx, image, 0, 0);
+ fz_md5_init(&state);
+ fz_md5_update(&state, pixmap->samples, pixmap->w * pixmap->h * pixmap->n);
+ fz_md5_final(&state, digest);
+ fz_drop_pixmap(ctx, pixmap);
}
/* Image specific methods */