1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-09-19 21:50:08 +00:00
pdf2htmlEX/src/HTMLRenderer/image.cc
2012-08-14 17:50:16 +08:00

65 lines
1.6 KiB
C++

/*
* image.cc
*
* Handling images
*
* by WangLu
* 2012.08.14
*/
#include <boost/format.hpp>
// for gil bug
const int *int_p_NULL = nullptr;
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
#include "HTMLRenderer.h"
#include "namespace.h"
using namespace boost::gil;
void HTMLRenderer::drawImage(GfxState * state, Object * ref, Stream * str, int width, int height, GfxImageColorMap * colorMap, GBool interpolate, int *maskColors, GBool inlineImg)
{
if(maskColors)
return;
rgb8_image_t img(width, height);
auto imgview = view(img);
auto loc = imgview.xy_at(0,0);
ImageStream * img_stream = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
img_stream->reset();
for(int i = 0; i < height; ++i)
{
auto p = img_stream->getLine();
for(int j = 0; j < width; ++j)
{
GfxRGB rgb;
colorMap->getRGB(p, &rgb);
*loc = rgb8_pixel_t(colToByte(rgb.r), colToByte(rgb.g), colToByte(rgb.b));
p += colorMap->getNumPixelComps();
++ loc.x();
}
loc = imgview.xy_at(0, i+1);
}
png_write_view((format("i%|1$x|.png")%image_count).str(), imgview);
img_stream->close();
delete img_stream;
close_cur_line();
double * ctm = state->getCTM();
ctm[4] = ctm[5] = 0.0;
html_fout << format("<img class=\"i t%2%\" style=\"left:%3%px;bottom:%4%px;width:%5%px;height:%6%px;\" src=\"i%|1$x|.png\" />") % image_count % install_transform_matrix(ctm) % state->getCurX() % state->getCurY() % width % height << endl;
++ image_count;
}