From 34ed3770863899755ff688cc86c29aacaf924a5d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 17 Jun 2013 22:38:48 +0200 Subject: Move fz_write_pixmap wrapper into pdfextract (its only user). --- apps/pdfextract.c | 40 ++++++++++++++++++++++++++++++++---- fitz/image_save.c | 33 ----------------------------- include/mupdf/fitz/output-pnm.h | 11 ---------- win32/libmupdf.vcproj | 4 ---- winrt/libmupdf_winRT.vcxproj | 3 +-- winrt/libmupdf_winRT.vcxproj.filters | 5 +---- 6 files changed, 38 insertions(+), 58 deletions(-) delete mode 100644 fitz/image_save.c diff --git a/apps/pdfextract.c b/apps/pdfextract.c index e30b8268..78a61f14 100644 --- a/apps/pdfextract.c +++ b/apps/pdfextract.c @@ -28,10 +28,42 @@ static int isfontdesc(pdf_obj *obj) return pdf_is_name(type) && !strcmp(pdf_to_name(type), "FontDescriptor"); } +static void writepixmap(fz_context *ctx, fz_pixmap *pix, char *file, int rgb) +{ + char name[1024]; + fz_pixmap *converted = NULL; + + if (!pix) + return; + + if (rgb && pix->colorspace && pix->colorspace != fz_device_rgb(ctx)) + { + fz_irect bbox; + converted = fz_new_pixmap_with_bbox(ctx, fz_device_rgb(ctx), fz_pixmap_bbox(ctx, pix, &bbox)); + fz_convert_pixmap(ctx, converted, pix); + pix = converted; + } + + if (pix->n <= 4) + { + sprintf(name, "%s.png", file); + printf("extracting image %s\n", name); + fz_write_png(ctx, pix, name, 0); + } + else + { + sprintf(name, "%s.pam", file); + printf("extracting image %s\n", name); + fz_write_pam(ctx, pix, name, 0); + } + + fz_drop_pixmap(ctx, converted); +} + static void saveimage(int num) { fz_image *image; - fz_pixmap *img; + fz_pixmap *pix; pdf_obj *ref; char name[32]; @@ -40,13 +72,13 @@ static void saveimage(int num) /* TODO: detect DCTD and save as jpeg */ image = pdf_load_image(doc, ref); - img = fz_image_to_pixmap(ctx, image, 0, 0); + pix = fz_image_to_pixmap(ctx, image, 0, 0); fz_drop_image(ctx, image); sprintf(name, "img-%04d", num); - fz_write_pixmap(ctx, img, name, dorgb); + writepixmap(ctx, pix, name, dorgb); - fz_drop_pixmap(ctx, img); + fz_drop_pixmap(ctx, pix); pdf_drop_obj(ref); } diff --git a/fitz/image_save.c b/fitz/image_save.c deleted file mode 100644 index 0a564ed1..00000000 --- a/fitz/image_save.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "mupdf/fitz.h" - -void fz_write_pixmap(fz_context *ctx, fz_pixmap *img, char *file, int rgb) -{ - char name[1024]; - fz_pixmap *converted = NULL; - - if (!img) - return; - - if (rgb && img->colorspace && img->colorspace != fz_device_rgb(ctx)) - { - fz_irect bbox; - converted = fz_new_pixmap_with_bbox(ctx, fz_device_rgb(ctx), fz_pixmap_bbox(ctx, img, &bbox)); - fz_convert_pixmap(ctx, converted, img); - img = converted; - } - - if (img->n <= 4) - { - sprintf(name, "%s.png", file); - printf("extracting image %s\n", name); - fz_write_png(ctx, img, name, 0); - } - else - { - sprintf(name, "%s.pam", file); - printf("extracting image %s\n", name); - fz_write_pam(ctx, img, name, 0); - } - - fz_drop_pixmap(ctx, converted); -} diff --git a/include/mupdf/fitz/output-pnm.h b/include/mupdf/fitz/output-pnm.h index f4cc6735..8094aedb 100644 --- a/include/mupdf/fitz/output-pnm.h +++ b/include/mupdf/fitz/output-pnm.h @@ -7,17 +7,6 @@ #include "mupdf/fitz/pixmap.h" #include "mupdf/fitz/bitmap.h" -/* - fz_write_pixmap: Save a pixmap out. - - name: The prefix for the name of the pixmap. The pixmap will be saved - as "name.png" if the pixmap is RGB or Greyscale, "name.pam" otherwise. - - rgb: If non zero, the pixmap is converted to rgb (if possible) before - saving. -*/ -void fz_write_pixmap(fz_context *ctx, fz_pixmap *img, char *name, int rgb); - /* fz_write_pnm: Save a pixmap as a pnm diff --git a/win32/libmupdf.vcproj b/win32/libmupdf.vcproj index ba55e7c4..61fea92a 100644 --- a/win32/libmupdf.vcproj +++ b/win32/libmupdf.vcproj @@ -508,10 +508,6 @@ RelativePath="..\fitz\image_png.c" > - - diff --git a/winrt/libmupdf_winRT.vcxproj b/winrt/libmupdf_winRT.vcxproj index 02147b9f..ec98e347 100644 --- a/winrt/libmupdf_winRT.vcxproj +++ b/winrt/libmupdf_winRT.vcxproj @@ -82,7 +82,6 @@ - @@ -429,4 +428,4 @@ - \ No newline at end of file + diff --git a/winrt/libmupdf_winRT.vcxproj.filters b/winrt/libmupdf_winRT.vcxproj.filters index 109c2c0c..74df3789 100644 --- a/winrt/libmupdf_winRT.vcxproj.filters +++ b/winrt/libmupdf_winRT.vcxproj.filters @@ -153,9 +153,6 @@ fitz - - fitz - fitz @@ -402,4 +399,4 @@ image - \ No newline at end of file + -- cgit v1.2.3