diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-03-12 17:15:47 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-03-12 17:38:14 +0000 |
commit | 1013512f2851242c446443ff0eeb297701710e2b (patch) | |
tree | ba326c5bff9de775df8ca4fb4f58ff0f1b2ad6ce /apps | |
parent | cb2441e8ed1136dc85a9cd02f733035277be43b2 (diff) | |
parent | 2bd952f3fa8241aad0626f39343cffa9855c2d8c (diff) | |
download | mupdf-1013512f2851242c446443ff0eeb297701710e2b.tar.xz |
Merge branch 'header-split'
Diffstat (limited to 'apps')
-rw-r--r-- | apps/mudraw.c | 15 | ||||
-rw-r--r-- | apps/mupdfclean.c | 2 | ||||
-rw-r--r-- | apps/mupdfextract.c | 36 | ||||
-rw-r--r-- | apps/mupdfinfo.c | 2 | ||||
-rw-r--r-- | apps/mupdfshow.c | 5 | ||||
-rw-r--r-- | apps/pdfapp.c | 21 | ||||
-rw-r--r-- | apps/pdfapp.h | 7 | ||||
-rw-r--r-- | apps/win_main.c | 29 | ||||
-rw-r--r-- | apps/x11_image.c | 8 | ||||
-rw-r--r-- | apps/x11_main.c | 44 |
10 files changed, 74 insertions, 95 deletions
diff --git a/apps/mudraw.c b/apps/mudraw.c index e74f3081..19f359a1 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -3,7 +3,6 @@ */ #include "fitz.h" -#include "mupdf.h" #ifdef _MSC_VER #include <winsock2.h> @@ -273,24 +272,18 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) else if (strstr(output, ".png")) fz_write_png(ctx, pix, buf, savealpha); else if (strstr(output, ".pbm")) { - fz_halftone *ht = fz_get_default_halftone(ctx, 1); - fz_bitmap *bit = fz_halftone_pixmap(ctx, pix, ht); + fz_bitmap *bit = fz_halftone_pixmap(ctx, pix, NULL); fz_write_pbm(ctx, bit, buf); fz_drop_bitmap(ctx, bit); - fz_drop_halftone(ctx, ht); } } if (showmd5) { - fz_md5 md5; unsigned char digest[16]; int i; - fz_md5_init(&md5); - fz_md5_update(&md5, pix->samples, pix->w * pix->h * pix->n); - fz_md5_final(&md5, digest); - + fz_md5_pixmap(pix, digest); printf(" "); for (i = 0; i < 16; i++) printf("%02x", digest[i]); @@ -382,9 +375,9 @@ static void drawoutline(fz_context *ctx, fz_document *doc) { fz_outline *outline = fz_load_outline(doc); if (showoutline > 1) - fz_debug_outline_xml(ctx, outline, 0); + fz_debug_outline_xml(ctx, outline); else - fz_debug_outline(ctx, outline, 0); + fz_debug_outline(ctx, outline); fz_free_outline(ctx, outline); } diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c index c8a81274..caee8d5b 100644 --- a/apps/mupdfclean.c +++ b/apps/mupdfclean.c @@ -10,7 +10,7 @@ */ #include "fitz.h" -#include "mupdf.h" +#include "mupdf-internal.h" static FILE *out = NULL; diff --git a/apps/mupdfextract.c b/apps/mupdfextract.c index 88a3630d..398ff6d9 100644 --- a/apps/mupdfextract.c +++ b/apps/mupdfextract.c @@ -2,7 +2,6 @@ * pdfextract -- the ultimate way to extract images and fonts from pdfs */ -#include "fitz.h" #include "mupdf.h" static pdf_document *doc = NULL; @@ -34,7 +33,7 @@ static void saveimage(int num) fz_image *image; fz_pixmap *img; pdf_obj *ref; - char name[1024]; + char name[32]; ref = pdf_new_indirect(ctx, num, 0, doc); @@ -44,27 +43,8 @@ static void saveimage(int num) img = fz_image_to_pixmap(ctx, image, 0, 0); fz_drop_image(ctx, image); - if (dorgb && img->colorspace && img->colorspace != fz_device_rgb) - { - fz_pixmap *temp; - temp = fz_new_pixmap_with_rect(ctx, fz_device_rgb, fz_bound_pixmap(img)); - fz_convert_pixmap(ctx, img, temp); - fz_drop_pixmap(ctx, img); - img = temp; - } - - if (img->n <= 4) - { - sprintf(name, "img-%04d.png", num); - printf("extracting image %s\n", name); - fz_write_png(ctx, img, name, 0); - } - else - { - sprintf(name, "img-%04d.pam", num); - printf("extracting image %s\n", name); - fz_write_pam(ctx, img, name, 0); - } + sprintf(name, "img-%04d", num); + fz_save_pixmap(ctx, img, name, dorgb); fz_drop_pixmap(ctx, img); pdf_drop_obj(ref); @@ -80,7 +60,8 @@ static void savefont(pdf_obj *dict, int num) char *ext = ""; FILE *f; char *fontname = "font"; - int n; + int n, len; + char *data; obj = pdf_dict_gets(dict, "FontName"); if (obj) @@ -133,8 +114,9 @@ static void savefont(pdf_obj *dict, int num) if (!f) fz_throw(ctx, "Error creating font file"); - n = fwrite(buf->data, 1, buf->len, f); - if (n < buf->len) + len = fz_buffer_storage(ctx, buf, &data); + n = fwrite(data, 1, len, f); + if (n < len) fz_throw(ctx, "Error writing font file"); if (fclose(f) < 0) @@ -199,7 +181,7 @@ int main(int argc, char **argv) if (fz_optind == argc) { - for (o = 0; o < doc->len; o++) + for (o = 0; o < pdf_count_objects(doc); o++) showobject(o); } else diff --git a/apps/mupdfinfo.c b/apps/mupdfinfo.c index 161a80f1..d567bf8e 100644 --- a/apps/mupdfinfo.c +++ b/apps/mupdfinfo.c @@ -4,7 +4,7 @@ */ #include "fitz.h" -#include "mupdf.h" +#include "mupdf-internal.h" pdf_document *xref; fz_context *ctx; diff --git a/apps/mupdfshow.c b/apps/mupdfshow.c index 92fcac2d..94aa90d6 100644 --- a/apps/mupdfshow.c +++ b/apps/mupdfshow.c @@ -2,8 +2,7 @@ * pdfshow -- the ultimate pdf debugging tool */ -#include "fitz.h" -#include "mupdf.h" +#include "mupdf-internal.h" static pdf_document *doc = NULL; static fz_context *ctx = NULL; @@ -145,7 +144,7 @@ static void showgrep(char *filename) pdf_obj *obj; int i; - for (i = 0; i < doc->len; i++) + for (i = 0; i < pdf_count_objects(doc); i++) { if (doc->table[i].type == 'n' || doc->table[i].type == 'o') { diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 6f2d766d..4f093508 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -1,8 +1,7 @@ -#include "fitz.h" +#include "pdfapp.h" #include "mupdf.h" #include "muxps.h" #include "mucbz.h" -#include "pdfapp.h" #include <ctype.h> /* for tolower() */ @@ -80,23 +79,7 @@ void pdfapp_init(fz_context *ctx, pdfapp_t *app) void pdfapp_invert(pdfapp_t *app, fz_bbox rect) { - unsigned char *p; - int x, y, n; - - int x0 = CLAMP(rect.x0 - app->image->x, 0, app->image->w - 1); - int x1 = CLAMP(rect.x1 - app->image->x, 0, app->image->w - 1); - int y0 = CLAMP(rect.y0 - app->image->y, 0, app->image->h - 1); - int y1 = CLAMP(rect.y1 - app->image->y, 0, app->image->h - 1); - - for (y = y0; y < y1; y++) - { - p = app->image->samples + (y * app->image->w + x0) * app->image->n; - for (x = x0; x < x1; x++) - { - for (n = app->image->n; n > 0; n--, p++) - *p = 255 - *p; - } - } + fz_invert_pixmap_rect(app->image, rect); } void pdfapp_open(pdfapp_t *app, char *filename, int fd, int reload) diff --git a/apps/pdfapp.h b/apps/pdfapp.h index bb067bb4..0c1b6ac4 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -1,3 +1,8 @@ +#ifndef PDFAPP_H +#define PDFAPP_H + +#include "fitz.h" + /* * Utility object for handling a pdf application / view * Takes care of PDF loading and displaying and navigation, @@ -106,3 +111,5 @@ void pdfapp_onresize(pdfapp_t *app, int w, int h); void pdfapp_invert(pdfapp_t *app, fz_bbox rect); void pdfapp_inverthit(pdfapp_t *app); + +#endif diff --git a/apps/win_main.c b/apps/win_main.c index c87faa97..3417a11e 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -317,7 +317,7 @@ void wintitle(pdfapp_t *app, char *title) sp = title; while (*sp && dp < wide + 255) { - sp += chartorune(&rune, sp); + sp += fz_chartorune(&rune, sp); *dp++ = rune; } *dp = 0; @@ -355,10 +355,15 @@ void winblitsearch() void winblit() { + fz_bbox bb = fz_bound_pixmap(gapp.image); + int image_w = bb.x1-bb.x0; + int image_h = bb.y1-bb.y0; + int image_n = fz_pixmap_components(context, gapp.image); + unsigned char *samples = fz_pixmap_pixels(context, gapp.image); int x0 = gapp.panx; int y0 = gapp.pany; - int x1 = gapp.panx + gapp.image->w; - int y1 = gapp.pany + gapp.image->h; + int x1 = gapp.panx + image_w; + int y1 = gapp.pany + image_h; RECT r; if (gapp.image) @@ -371,15 +376,15 @@ void winblit() pdfapp_inverthit(&gapp); - dibinf->bmiHeader.biWidth = gapp.image->w; - dibinf->bmiHeader.biHeight = -gapp.image->h; - dibinf->bmiHeader.biSizeImage = gapp.image->h * 4; + dibinf->bmiHeader.biWidth = image_w; + dibinf->bmiHeader.biHeight = -image_h; + dibinf->bmiHeader.biSizeImage = image_h * 4; if (gapp.image->n == 2) { - int i = gapp.image->w * gapp.image->h; + int i = image_w * image_h; unsigned char *color = malloc(i*4); - unsigned char *s = gapp.image->samples; + unsigned char *s = samples; unsigned char *d = color; for (; i > 0 ; i--) { @@ -388,16 +393,16 @@ void winblit() d += 4; } SetDIBitsToDevice(hdc, - gapp.panx, gapp.pany, gapp.image->w, gapp.image->h, - 0, 0, 0, gapp.image->h, color, + gapp.panx, gapp.pany, image_w, image_h, + 0, 0, 0, image_h, color, dibinf, DIB_RGB_COLORS); free(color); } if (gapp.image->n == 4) { SetDIBitsToDevice(hdc, - gapp.panx, gapp.pany, gapp.image->w, gapp.image->h, - 0, 0, 0, gapp.image->h, gapp.image->samples, + gapp.panx, gapp.pany, image_w, image_h, + 0, 0, 0, image_h, samples, dibinf, DIB_RGB_COLORS); } diff --git a/apps/x11_image.c b/apps/x11_image.c index 35b32c7e..06764313 100644 --- a/apps/x11_image.c +++ b/apps/x11_image.c @@ -22,6 +22,12 @@ extern int ffs(int); +static int is_big_endian(void) +{ + static const int one = 1; + return *(char*)&one == 0; +} + typedef void (*ximage_convert_func_t) ( const unsigned char *src, @@ -212,7 +218,7 @@ select_mode(void) unsigned long rs, gs, bs; byteorder = ImageByteOrder(info.display); - if (fz_is_big_endian()) + if (is_big_endian()) byterev = byteorder != MSBFirst; else byterev = byteorder != LSBFirst; diff --git a/apps/x11_main.c b/apps/x11_main.c index 281618ef..091f0ec6 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -1,7 +1,3 @@ -#include "fitz.h" -#include "mupdf.h" -#include "muxps.h" -#include "mucbz.h" #include "pdfapp.h" #include <X11/Xlib.h> @@ -253,6 +249,9 @@ void winhelp(pdfapp_t *app) void winresize(pdfapp_t *app, int w, int h) { + fz_bbox bb = fz_bound_pixmap(gapp.image); + int image_w = bb.x1 - bb.x0; + int image_h = bb.y1 - bb.y0; XWindowChanges values; int mask, width, height; @@ -287,7 +286,7 @@ void winresize(pdfapp_t *app, int w, int h) } XSetForeground(xdpy, xgc, WhitePixel(xdpy, xscr)); - XFillRectangle(xdpy, xwin, xgc, 0, 0, gapp.image->w, gapp.image->h); + XFillRectangle(xdpy, xwin, xgc, 0, 0, image_w, image_h); XFlush(xdpy); if (width != reqw || height != reqh) @@ -338,10 +337,15 @@ static void winblitsearch(pdfapp_t *app) static void winblit(pdfapp_t *app) { + fz_bbox bb = fz_bound_pixmap(gapp.image); + int image_w = bb.x1 - bb.x0; + int image_h = bb.y1 - bb.y0; + int image_n = fz_pixmap_components(gapp.ctx, gapp.image); + unsigned char *image_samples = fz_pixmap_pixels(gapp.ctx, gapp.image); int x0 = gapp.panx; int y0 = gapp.pany; - int x1 = gapp.panx + gapp.image->w; - int y1 = gapp.pany + gapp.image->h; + int x1 = gapp.panx + image_w; + int y1 = gapp.pany + image_h; XSetForeground(xdpy, xgc, xbgcolor.pixel); fillrect(0, 0, x0, gapp.winh); @@ -350,8 +354,8 @@ static void winblit(pdfapp_t *app) fillrect(0, y1, gapp.winw, gapp.winh - y1); XSetForeground(xdpy, xgc, xshcolor.pixel); - fillrect(x0+2, y1, gapp.image->w, 2); - fillrect(x1, y0+2, 2, gapp.image->h); + fillrect(x0+2, y1, image_w, 2); + fillrect(x1, y0+2, 2, image_h); if (gapp.iscopying || justcopied) { @@ -361,21 +365,21 @@ static void winblit(pdfapp_t *app) pdfapp_inverthit(&gapp); - if (gapp.image->n == 4) + if (image_n == 4) ximage_blit(xwin, xgc, x0, y0, - gapp.image->samples, + image_samples, 0, 0, - gapp.image->w, - gapp.image->h, - gapp.image->w * gapp.image->n); - else if (gapp.image->n == 2) + image_w, + image_h, + image_w * image_n); + else if (image_n == 2) { - int i = gapp.image->w*gapp.image->h; + int i = image_w*image_h; unsigned char *color = malloc(i*4); if (color) { - unsigned char *s = gapp.image->samples; + unsigned char *s = image_samples; unsigned char *d = color; for (; i > 0 ; i--) { @@ -387,9 +391,9 @@ static void winblit(pdfapp_t *app) x0, y0, color, 0, 0, - gapp.image->w, - gapp.image->h, - gapp.image->w * 4); + image_w, + image_h, + image_w * 4); free(color); } } |