void Render(HDC hdc, RectI target, int pageNo, float zoom) { ScopedCritSec scope(&currAccess); if (currBmp && currPage == pageNo && currSize == target.Size()) currBmp->StretchDIBits(hdc, target); else if (!thread) { reqPage = pageNo; reqZoom = zoom; reqSize = target.Size(); thread = CreateThread(NULL, 0, RenderThread, this, 0, 0); } }
void Render(HDC hdc, RectI target, int pageNo, float zoom) { ScopedCritSec scope(&currAccess); if (currBmp && currPage == pageNo && currSize == target.Size()) currBmp->StretchDIBits(hdc, target); else if (!thread) { reqPage = pageNo; reqZoom = zoom; reqSize = target.Size(); reqAbort = false; thread = CreateThread(NULL, 0, RenderThread, this, 0, 0); } else if (reqPage != pageNo || reqSize != target.Size()) { if (abortCookie) abortCookie->Abort(); reqAbort = true; } }
RenderedBitmap *DjVuEngineImpl::RenderBitmap(int pageNo, float zoom, int rotation, RectD *pageRect, RenderTarget target, AbortCookie **cookie_out) { ScopedCritSec scope(&gDjVuContext.lock); RectD pageRc = pageRect ? *pageRect : PageMediabox(pageNo); RectI screen = Transform(pageRc, pageNo, zoom, rotation).Round(); RectI full = Transform(PageMediabox(pageNo), pageNo, zoom, rotation).Round(); screen = full.Intersect(screen); ddjvu_page_t *page = ddjvu_page_create_by_pageno(doc, pageNo-1); if (!page) return NULL; int rotation4 = (((-rotation / 90) % 4) + 4) % 4; ddjvu_page_set_rotation(page, (ddjvu_page_rotation_t)rotation4); while (!ddjvu_page_decoding_done(page)) gDjVuContext.SpinMessageLoop(); if (ddjvu_page_decoding_error(page)) return NULL; bool isBitonal = DDJVU_PAGETYPE_BITONAL == ddjvu_page_get_type(page); ddjvu_format_t *fmt = ddjvu_format_create(isBitonal ? DDJVU_FORMAT_GREY8 : DDJVU_FORMAT_BGR24, 0, NULL); ddjvu_format_set_row_order(fmt, /* top_to_bottom */ TRUE); ddjvu_rect_t prect = { full.x, full.y, full.dx, full.dy }; ddjvu_rect_t rrect = { screen.x, 2 * full.y - screen.y + full.dy - screen.dy, screen.dx, screen.dy }; RenderedBitmap *bmp = NULL; int stride = ((screen.dx * (isBitonal ? 1 : 3) + 3) / 4) * 4; ScopedMem<char> bmpData(AllocArray<char>(stride * (screen.dy + 5))); if (bmpData) { #ifndef DEBUG ddjvu_render_mode_t mode = isBitonal ? DDJVU_RENDER_MASKONLY : DDJVU_RENDER_COLOR; #else // TODO: there seems to be a heap corruption in IW44Image.cpp // in debug builds when passing in DDJVU_RENDER_COLOR ddjvu_render_mode_t mode = DDJVU_RENDER_MASKONLY; #endif if (ddjvu_page_render(page, mode, &prect, &rrect, fmt, stride, bmpData.Get())) { bmp = new RenderedDjVuPixmap(bmpData, screen.Size(), isBitonal); AddUserAnnots(bmp, pageNo, zoom, rotation, screen); } } ddjvu_format_release(fmt); ddjvu_page_release(page); return bmp; }
void EnsureAreaVisibility(RectI& r) { // adjust to the work-area of the current monitor (not necessarily the primary one) RectI work = GetWorkAreaRect(r); // make sure that the window is neither too small nor bigger than the monitor if (r.dx < MIN_WIN_DX || r.dx > work.dx) r.dx = (int)min(work.dy * DEF_PAGE_RATIO, work.dx); if (r.dy < MIN_WIN_DY || r.dy > work.dy) r.dy = work.dy; // check whether the lower half of the window's title bar is // inside a visible working area int captionDy = GetSystemMetrics(SM_CYCAPTION); RectI halfCaption(r.x, r.y + captionDy / 2, r.dx, captionDy / 2); if (halfCaption.Intersect(work).IsEmpty()) r = RectI(work.TL(), r.Size()); }
RenderedBitmap *ImagesEngine::RenderBitmap(int pageNo, float zoom, int rotation, RectD *pageRect, RenderTarget target, AbortCookie **cookie_out) { RectD pageRc = pageRect ? *pageRect : PageMediabox(pageNo); RectI screen = Transform(pageRc, pageNo, zoom, rotation).Round(); screen.Offset(-screen.x, -screen.y); HDC hDC = GetDC(NULL); HDC hDCMem = CreateCompatibleDC(hDC); HBITMAP hbmp = CreateCompatibleBitmap(hDC, screen.dx, screen.dy); DeleteObject(SelectObject(hDCMem, hbmp)); bool ok = RenderPage(hDCMem, screen, pageNo, zoom, rotation, pageRect, target, cookie_out); DeleteDC(hDCMem); ReleaseDC(NULL, hDC); if (!ok) { DeleteObject(hbmp); return NULL; } return new RenderedBitmap(hbmp, screen.Size()); }