diff options
author | Tor Andersson <tor@ghostscript.com> | 2010-06-30 17:32:10 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2010-06-30 17:32:10 +0200 |
commit | 8b91056a31825914bcfb8ae5d902622976bca284 (patch) | |
tree | 47c9f38f98502cac43e7061b46ebcd0813699efa | |
parent | 27e32c2ae2b462b6a8b0798f6f477b6a104ac972 (diff) | |
download | mupdf-8b91056a31825914bcfb8ae5d902622976bca284.tar.xz |
Use 32-bit blitting and DeviceBGR colorspace in windows viewer to avoid converting the pixmap.
-rw-r--r-- | apps/pdfapp.c | 12 | ||||
-rw-r--r-- | apps/win_main.c | 96 | ||||
-rw-r--r-- | mupdf/pdf_shade.c | 2 |
3 files changed, 44 insertions, 66 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index e798dfb9..6eec1b8f 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -279,6 +279,8 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage) if (drawpage) { + fz_colorspace *colorspace; + wincursor(app, WAIT); ctm = pdfapp_viewctm(app); @@ -293,7 +295,15 @@ static void pdfapp_showpage(pdfapp_t *app, int loadpage, int drawpage) /* Draw */ if (app->image) fz_droppixmap(app->image); - app->image = fz_newpixmapwithrect((app->grayscale ? pdf_devicegray : pdf_devicergb), bbox); + if (app->grayscale) + colorspace = pdf_devicegray; + else +#ifdef _WIN32 + colorspace = pdf_devicebgr; +#else + colorspace = pdf_devicergb; +#endif + app->image = fz_newpixmapwithrect(colorspace, bbox); fz_clearpixmap(app->image, 0xFF); idev = fz_newdrawdevice(app->cache, app->image); fz_executedisplaylist(app->page->list, idev, ctm); diff --git a/apps/win_main.c b/apps/win_main.c index ae12c673..7de84d2d 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -2,8 +2,12 @@ #include <mupdf.h> #include "pdfapp.h" +#ifndef UNICODE #define UNICODE +#endif +#ifndef _UNICODE #define _UNICODE +#endif #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <commdlg.h> @@ -26,8 +30,6 @@ static HCURSOR arrowcurs, handcurs, waitcurs; static LRESULT CALLBACK frameproc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK viewproc(HWND, UINT, WPARAM, LPARAM); -static int bmpstride = 0; -static unsigned char *bmpdata = NULL; static int justcopied = 0; static pdfapp_t gapp; @@ -301,7 +303,7 @@ void winopen() assert(dibinf != NULL); dibinf->bmiHeader.biSize = sizeof(dibinf->bmiHeader); dibinf->bmiHeader.biPlanes = 1; - dibinf->bmiHeader.biBitCount = 24; + dibinf->bmiHeader.biBitCount = 32; dibinf->bmiHeader.biCompression = BI_RGB; dibinf->bmiHeader.biXPelsPerMeter = 2834; dibinf->bmiHeader.biYPelsPerMeter = 2834; @@ -378,51 +380,6 @@ void wintitle(pdfapp_t *app, char *title) SetWindowTextW(hwndframe, wide); } -void winconvert(fz_pixmap *image) -{ - int y, x; - - if (bmpdata) - fz_free(bmpdata); - - bmpstride = ((image->w * 3 + 3) / 4) * 4; - bmpdata = fz_malloc(image->h * bmpstride); - - if (image->n == 4) - { - for (y = 0; y < image->h; y++) - { - unsigned char *p = bmpdata + y * bmpstride; - unsigned char *s = image->samples + y * image->w * 4; - for (x = 0; x < image->w; x++) - { - p[x * 3 + 0] = s[x * 4 + 2]; - p[x * 3 + 1] = s[x * 4 + 1]; - p[x * 3 + 2] = s[x * 4 + 0]; - } - } - } - else if (image->n == 2) - { - for (y = 0; y < image->h; y++) - { - unsigned char *p = bmpdata + y * bmpstride; - unsigned char *s = image->samples + y * image->w * 2; - for (x = 0; x < image->w; x++) - { - p[x * 3 + 0] = s[x * 2]; - p[x * 3 + 1] = s[x * 2]; - p[x * 3 + 2] = s[x * 2]; - } - } - } - else - { - assert("Unexpected image depth in winconvert" != NULL); - } - -} - void windrawrect(pdfapp_t *app, int x0, int y0, int x1, int y1) { RECT r; @@ -458,24 +415,35 @@ void winblit() pdfapp_inverthit(&gapp); - winconvert(gapp.image); - dibinf->bmiHeader.biWidth = gapp.image->w; dibinf->bmiHeader.biHeight = -gapp.image->h; - dibinf->bmiHeader.biSizeImage = gapp.image->h * bmpstride; - SetDIBitsToDevice(hdc, - gapp.panx, /* destx */ - gapp.pany, /* desty */ - gapp.image->w, /* destw */ - gapp.image->h, /* desth */ - 0, /* srcx */ - 0, /* srcy */ - 0, /* startscan */ - gapp.image->h, /* numscans */ - bmpdata, /* pBits */ - dibinf, /* pInfo */ - DIB_RGB_COLORS /* color use flag */ - ); + dibinf->bmiHeader.biSizeImage = gapp.image->h * 4; + + if (gapp.image->n == 2) + { + int i = gapp.image->w * gapp.image->h; + unsigned char *color = malloc(i*4); + unsigned char *s = gapp.image->samples; + unsigned char *d = color; + for (; i > 0 ; i--) + { + d[2] = d[1] = d[0] = *s++; + d[3] = *s++; + d += 4; + } + SetDIBitsToDevice(hdc, + gapp.panx, gapp.pany, gapp.image->w, gapp.image->h, + 0, 0, 0, gapp.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, + dibinf, DIB_RGB_COLORS); + } pdfapp_inverthit(&gapp); diff --git a/mupdf/pdf_shade.c b/mupdf/pdf_shade.c index 10aef51b..77ac9c56 100644 --- a/mupdf/pdf_shade.c +++ b/mupdf/pdf_shade.c @@ -26,7 +26,7 @@ pdf_addvertex(fz_shade *shade, float x, float y, float *color) { int ncomp = shade->usefunction ? 1 : shade->cs->n; int i; - pdf_growmesh(shade, 2 + ncomp); + pdf_growmesh(shade, 2 + ncomp); shade->mesh[shade->meshlen++] = x; shade->mesh[shade->meshlen++] = y; for (i = 0; i < ncomp; i++) |