Commit 0dc16af0 authored by Albert Astals Cid's avatar Albert Astals Cid

Introduce variants of renderTo that return a QImage and do not use a QPixmap...

Introduce variants of renderTo that return a QImage and do not use a QPixmap so threading is possible.
parent 5c2cbf5d
2006-01-02 Albert Astals Cid <aacid@kde.org>
* qt/poppler-page.cc:
* qt/poppler-qt.h:
* qt4/src/poppler-page.cc:
* qt4/src/poppler-qt4.h: Introduce variants of renderTo that return a
QImage and do not use a QPixmap so threading is possible.
2006-01-02 Albert Astals Cid <aacid@kde.org>
* poppler/PageTransition.cc: Use error() insted of std::cerr
......
......@@ -58,6 +58,12 @@ void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h) const
}
void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const
{
QImage img = renderToImage(xres, yres);
*q = new QPixmap( img );
}
QImage Page::renderToImage(double xres, double yres) const
{
SplashOutputDev *output_dev;
SplashBitmap *bitmap;
......@@ -70,20 +76,20 @@ void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres,
color_ptr = bitmap->getDataPtr ();
int bw = output_dev->getBitmap()->getWidth();
int bh = output_dev->getBitmap()->getHeight();
QImage * img = new QImage( bw, bh, 32 );
QImage img( bw, bh, 32 );
SplashColorPtr pixel = new Guchar[4];
for (int i = 0; i < bw; i++)
{
for (int j = 0; j < bh; j++)
{
output_dev->getBitmap()->getPixel(i, j, pixel);
img->setPixel( i, j, qRgb( pixel[0], pixel[1], pixel[2] ) );
img.setPixel( i, j, qRgb( pixel[0], pixel[1], pixel[2] ) );
}
}
delete[] pixel;
*q = new QPixmap( *img );
delete img;
return img;
}
QString Page::getText(const Rectangle &r) const
......
......@@ -128,12 +128,32 @@ class Page {
void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const;
/**
* This is a convenience function that is equivalent to
* renderToPixmap() with xres and yres set to 72.0. We keep it
* only for binary compatibility
**/
This is a convenience function that is equivalent to
renderToPixmap() with xres and yres set to 72.0. We keep it
only for binary compatibility
\sa renderToImage()
*/
void renderToPixmap(QPixmap **q, int x, int y, int w, int h) const;
/**
\brief Render the page to a QImage using the Splash renderer
This method can be used to render the page to a QImage. It
uses the "Splash" rendering engine.
\param xres horizontal resolution of the graphics device,
in dots per inch (defaults to 72 dpi)
\param yres vertical resolution of the graphics device, in
dots per inch (defaults to 72 dpi)
\returns a QImage of the page.
\sa renderToPixmap()
*/
QImage renderToImage(double xres = 72.0, double yres = 72.0) const;
/**
* Returns the size of the page in points
**/
......
......@@ -55,7 +55,7 @@ Page::~Page()
delete m_page;
}
QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int w, int h) const
QImage Page::splashRenderToImage(double xres, double yres, int x, int y, int w, int h) const
{
SplashOutputDev *output_dev = m_page->parentDoc->m_doc->getSplashOutputDev();
......@@ -86,6 +86,13 @@ QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int
}
delete[] pixel;
return img;
}
QPixmap *Page::splashRenderToPixmap(double xres, double yres, int x, int y, int w, int h) const
{
QImage img = splashRenderToImage(xres, yres, x, y, w, h);
// Turn the QImage into a QPixmap
QPixmap* out = new QPixmap(QPixmap::fromImage(img));
......
......@@ -154,28 +154,11 @@ namespace Poppler {
~Page();
/**
Render the page to a QPixmap using the Splash renderer
Render the page to a QImage using the Splash renderer
This method can be used to render the page to a QPixmap. It
uses the "Splash" rendering engine that is included in the
Poppler distribution. This method is reasonably well-tested
and has produced good output so far. This method is used as
follows.
@code
Poppler::Page* pdfPage;
// Generate a QPixmap of the rendered page
QPixmap* pixmap = pdfPage->splashRenderToPixmap(0, 0, 0, 0, xres, yres );
if (pixmap == 0) {
... error message ...
return;
}
... use pixmap ...
delete pixmap;
@endcode
uses the "Splash" rendering engine. This method is reasonably
well-tested and has produced good output so far.
If x=y=w=h=-1, the method will automatically compute the
size of the pixmap from the horizontal and vertical
......@@ -205,8 +188,30 @@ delete pixmap;
well-tested. Unusual or meaningless parameters may lead to
rather unexpected results.
\returns pointer to a QPixmap, or NULL on failure. The
pixmap returned must be deleted.
\returns a QImage of the page, or a null image on failure.
*/
QImage splashRenderToImage(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1) const;
/**
Render the page to a QPixmap using the Splash renderer
This member function is provided for convenience. It behaves essentially like the above function.
It is used as follows.
@code
Poppler::Page* pdfPage;
// Generate a QPixmap of the rendered page
QPixmap* pixmap = pdfPage->splashRenderToPixmap(0, 0, 0, 0, xres, yres );
if (pixmap == 0) {
... error message ...
return;
}
... use pixmap ...
delete pixmap;
@endcode
*/
QPixmap *splashRenderToPixmap(double xres=72.0, double yres=72.0, int x=-1, int y=-1, int w=-1, int h=-1) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment