From d55162d649a12d62a1d1c738d99ca9dee7de575d Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 2 Mar 2012 14:13:05 +0000 Subject: Split fitz.h/mupdf.h into internal/external headers. Attempt to separate public API from internal functions. --- apps/mudraw.c | 6 +----- apps/mupdfclean.c | 2 +- apps/mupdfextract.c | 27 ++++----------------------- apps/mupdfinfo.c | 2 +- apps/mupdfshow.c | 2 +- apps/pdfapp.c | 18 +----------------- apps/win_main.c | 27 ++++++++++++++++----------- 7 files changed, 25 insertions(+), 59 deletions(-) (limited to 'apps') diff --git a/apps/mudraw.c b/apps/mudraw.c index ce59a4e3..46da1949 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -251,14 +251,10 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) 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(digest, pix); printf(" "); for (i = 0; i < 16; i++) printf("%02x", digest[i]); 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..069f7233 100644 --- a/apps/mupdfextract.c +++ b/apps/mupdfextract.c @@ -3,7 +3,7 @@ */ #include "fitz.h" -#include "mupdf.h" +#include "mupdf-internal.h" static pdf_document *doc = NULL; static fz_context *ctx = NULL; @@ -34,7 +34,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 +44,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); 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..475dc5a9 100644 --- a/apps/mupdfshow.c +++ b/apps/mupdfshow.c @@ -3,7 +3,7 @@ */ #include "fitz.h" -#include "mupdf.h" +#include "mupdf-internal.h" static pdf_document *doc = NULL; static fz_context *ctx = NULL; diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 6f2d766d..68b4b945 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -80,23 +80,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/win_main.c b/apps/win_main.c index c87faa97..1052ccdd 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -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); } -- cgit v1.2.3 From 16c6f406911b9c93491a244cfe1ec37603284489 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 7 Mar 2012 15:31:36 +0100 Subject: Splitting tweaks. --- apps/mudraw.c | 1 - apps/mupdfextract.c | 5 ++--- apps/mupdfshow.c | 3 +-- apps/pdfapp.c | 3 +-- apps/pdfapp.h | 7 +++++++ apps/win_main.c | 2 +- apps/x11_image.c | 8 +++++++- apps/x11_main.c | 44 ++++++++++++++++++++++++-------------------- 8 files changed, 43 insertions(+), 30 deletions(-) (limited to 'apps') diff --git a/apps/mudraw.c b/apps/mudraw.c index 46da1949..8b3aebf5 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -3,7 +3,6 @@ */ #include "fitz.h" -#include "mupdf.h" #ifdef _MSC_VER #include diff --git a/apps/mupdfextract.c b/apps/mupdfextract.c index 069f7233..1f53541b 100644 --- a/apps/mupdfextract.c +++ b/apps/mupdfextract.c @@ -2,8 +2,7 @@ * pdfextract -- the ultimate way to extract images and fonts from pdfs */ -#include "fitz.h" -#include "mupdf-internal.h" +#include "mupdf.h" static pdf_document *doc = NULL; static fz_context *ctx = NULL; @@ -180,7 +179,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/mupdfshow.c b/apps/mupdfshow.c index 475dc5a9..94aa90d6 100644 --- a/apps/mupdfshow.c +++ b/apps/mupdfshow.c @@ -2,7 +2,6 @@ * pdfshow -- the ultimate pdf debugging tool */ -#include "fitz.h" #include "mupdf-internal.h" static pdf_document *doc = 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 68b4b945..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 /* for tolower() */ 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 1052ccdd..6cb1f7e1 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -1,5 +1,5 @@ #include "fitz.h" -#include "mupdf.h" +#include "mupdf-internal.h" #include "muxps.h" #include "mucbz.h" #include "pdfapp.h" 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 @@ -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); } } -- cgit v1.2.3 From c4e870b5422207e6ca31eb2cd6694ba44faec21e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 7 Mar 2012 17:08:41 +0000 Subject: Tweak Halftone functions A NULL halftone pointer passed to fz_halftone_pixmap is now taken to mean "use the default halftone". This means we can remove most of the halftone functions from the public API until (post 1.0) we decide to flesh out the functionality. --- apps/mudraw.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'apps') diff --git a/apps/mudraw.c b/apps/mudraw.c index 8b3aebf5..7c79b2fa 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -240,11 +240,9 @@ 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); } } -- cgit v1.2.3 From 7a2973ba2c4865f42d02a4f878ce51ab7d72c394 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 7 Mar 2012 20:53:31 +0000 Subject: More release tidyups. Add some function documentation to fitz.h. Add fz_ prefix to runetochar, chartorune, runelen etc. Change fz_runetochar to avoid passing unnecessary pointer. --- apps/win_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/win_main.c b/apps/win_main.c index 6cb1f7e1..3417a11e 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -1,5 +1,5 @@ #include "fitz.h" -#include "mupdf-internal.h" +#include "mupdf.h" #include "muxps.h" #include "mucbz.h" #include "pdfapp.h" @@ -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; -- cgit v1.2.3 From 3db3054ec8223b6bd01d8d8144b4863c9ca8fd2d Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 12 Mar 2012 12:56:16 +0000 Subject: More API tidying. Make fz_clone_context copy existing AA settings. Add accessor function for fz_bitmap. Add more documentation for various functions/types. --- apps/mudraw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/mudraw.c b/apps/mudraw.c index 7c79b2fa..51a48539 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -251,7 +251,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum) unsigned char digest[16]; int i; - fz_md5_pixmap(digest, pix); + fz_md5_pixmap(pix, digest); printf(" "); for (i = 0; i < 16; i++) printf("%02x", digest[i]); -- cgit v1.2.3 From 2bd952f3fa8241aad0626f39343cffa9855c2d8c Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 12 Mar 2012 15:57:28 +0000 Subject: More API work. Details of buffers hidden in fitz-internal.h. Public API now just lets us keep/drop and get storage details for a buffer. fz_debug_outline{,_xml} lose the 'level' param in their public API. fz_matrix_max_expansion hidden, as it's only used internally. Document fz_setjmp/fz_longjmp and Apple specific hackery. --- apps/mudraw.c | 4 ++-- apps/mupdfextract.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'apps') diff --git a/apps/mudraw.c b/apps/mudraw.c index cf60bbcf..2ca925c6 100644 --- a/apps/mudraw.c +++ b/apps/mudraw.c @@ -349,9 +349,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/mupdfextract.c b/apps/mupdfextract.c index 1f53541b..398ff6d9 100644 --- a/apps/mupdfextract.c +++ b/apps/mupdfextract.c @@ -60,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) @@ -113,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) -- cgit v1.2.3