Exemplo n.º 1
0
void getRGBA()
{
    // get the pixels
  memset(rgba, 0, width*height*4);
#if defined(USE_POPPLER)
#if SAGE_POPPLER_VERSION == 5
  poppler_page_render_to_pixbuf (page, 0, 0, width, height, x_resolution/72.0, 0, pixbuf);
  memcpy(rgba, gdk_pixbuf_get_pixels(pixbuf), width *height * 3);
#endif

#if SAGE_POPPLER_VERSION == 12
  SplashBitmap *bitmap = splashOut->getBitmap();
  memcpy(rgba, bitmap->getDataPtr(), width *height * 3);
#endif
#else
    MagickGetImagePixels(wand, 0, 0, width, height, "RGBA", CharPixel, rgba);
#endif
    
    if (useDXT) {
	unsigned int numBytes;

	// compress into DXT
	memset(dxt, 0, width*height*4/8);
	numBytes = CompressDXT(rgba, dxt, width, height, FORMAT_DXT1, 1);
    }
}
Exemplo n.º 2
0
extern "C" JNIEXPORT jbyteArray JNICALL Java_com_iped_xpdf_gui_XpdfBitmapView_getPNMBuffer(JNIEnv *env, jobject obj, jint pg, jint w, jint h) {
	char ppmFile[512];

	SplashBitmap * bitMap;
    jbyteArray a1;
    displayWidth = w;
    displayHeight = h;
    double pageWidth;
    double pageHeight;
    double kx;
    double ky;
    // get PPM data
    pageWidth = doc->getPageCropWidth(pg);
    kx = ((double)displayWidth) / pageWidth;
	kx *= 72.0;
	pageHeight = doc->getPageCropHeight(pg);
	ky = ((double)displayHeight) / pageHeight;
	ky *= 72.0;
	resolution = (int)kx > (int)ky ? (int)ky : (int)kx;
	doc->displayPage(splashOut, pg, resolution, resolution, 0, gFalse, gTrue, gFalse);
	 sprintf(ppmFile, "%.*s-%06d.%s",(int)sizeof(ppmFile) - 32, "/sdcard/temp/", pg,  mono ? "pbm" : gray ? "pgm" : "ppm");
	
	splashOut->getBitmap()->writePNMFile(ppmFile);
	bitMap = splashOut->getBitmap();
	unsigned char * tempArr = bitMap->getPNMByteBuffer();
	realwidth = bitMap->getWidth();
	realheigt = bitMap->getHeight();
	jbyte * ji = (jbyte*)tempArr;
	int bufferLength = bitMap->getPNMBufferLength();
	a1 = env->NewByteArray(bufferLength);
	env->SetByteArrayRegion(a1,0,bufferLength, ji);
	delete []tempArr;
    return a1;
}
QPixmap NSRPopplerDocument::getCurrentPage()
{
	if (!_readyForLoad)
		return QPixmap();

	SplashBitmap *bitmap = _dev->getBitmap();
	int bw = bitmap->getWidth();
	int bh = bitmap->getHeight();

	char *dataPtr = (char *) _dev->getBitmap()->getDataPtr();

	int rowBytes = bw * 3;
	while (rowBytes % 4)
		rowBytes += 1;

#ifdef Q_OS_SYMBIAN
	TSize size (bw, bh);

	if (size != _iBitmap->SizeInPixels()) {
		_iBitmap->Reset();
		_iBitmap->Create(size, EColor16MU);
	}

	_iBitmap->BeginDataAccess();
	char *addr = (char *) _iBitmap->DataAddress();
	TInt stride = _iBitmap->DataStride();

	for (int i = 0; i < bh; ++i) {
		char *inAddr = dataPtr + i * rowBytes;

		for (int j = 0; j < bw; ++j) {
			if (isInvertedColors()) {
				addr[j * 4 + 0] = 255 - inAddr[j * 3 + 2];
				addr[j * 4 + 1] = 255 - inAddr[j * 3 + 1];
				addr[j * 4 + 2] = 255 - inAddr[j * 3 + 0];
			} else {
				addr[j * 4 + 0] = inAddr[j * 3 + 2];
				addr[j * 4 + 1] = inAddr[j * 3 + 1];
				addr[j * 4 + 2] = inAddr[j * 3 + 0];
			}

		}

		addr += stride;
	}

	_iBitmap->EndDataAccess();
#else
	QSize size (bw, bh);
	QImage img (size, QImage::Format_RGB888);

	char *addr = (char *) img.bits ();
	int stride = img.bytesPerLine ();

	for (int i = 0; i < bh; ++i) {
		char *inAddr = dataPtr + i * rowBytes;

		for (int j = 0; j < bw; ++j) {
			if (isInvertedColors()) {
				addr[j * 3 + 2] = 255 - inAddr[j * 3 + 2];
				addr[j * 3 + 1] = 255 - inAddr[j * 3 + 1];
				addr[j * 3 + 0] = 255 - inAddr[j * 3 + 0];
			} else {
				addr[j * 3 + 2] = inAddr[j * 3 + 2];
				addr[j * 3 + 1] = inAddr[j * 3 + 1];
				addr[j * 3 + 0] = inAddr[j * 3 + 0];
			}

		}

		addr += stride;
	}
#endif

	_dev->startPage (0, NULL);
	_readyForLoad = false;

#ifdef Q_OS_SYMBIAN
	return QPixmap::fromSymbianCFbsBitmap(_iBitmap);
#else
	return QPixmap::fromImage (img);
#endif
}
Exemplo n.º 4
0
PDFRectangle measure_margin(PDFDoc * doc, SplashOutputDev * dev, int page)
{
	doc->displayPageSlice(dev, page, 72.0, 72.0,
						  gFalse, gFalse, gFalse, gFalse, 0, 0, -1, -1);
	SplashBitmap *bitmap = dev->getBitmap();

	//bitmap->writePNMFile((char*)"out.ppm");
/*
	printf("width: %d\n", bitmap->getWidth());
	printf("height: %d\n", bitmap->getHeight());
	printf("rowsize: %d\n", bitmap->getRowSize());
*/
	SplashColorPtr data = bitmap->getDataPtr();
	int width = bitmap->getWidth();
	int height = bitmap->getHeight();

	int margin_left = 0;
	int margin_top = 0;
	int margin_right = 0;
	int margin_bottom = 0;

	int x, y, i;
	if(opt_oreilly){
		// fill top
		for (y = 0; y < 70; y++) {
			for (x = 0; x < width; x++) {
				i = y * width + x;
				data[i] = 0;
			}
		}
		// fill bottom
		for (y = height - 1; y >= height - 20; y--) {
			for (x = 0; x < width; x++) {
				i = y * width + x;
				data[i] = 0;
			}
		}
		//bitmap->writePNMFile((char*)"out.ppm");
	}

	for (y = 0; y < height; y++) {
		for (x = 0; x < width; x++) {
			i = y * width + x;
			if (data[i]) {
				margin_top = y;
				goto out_top;
			}
		}
	}
out_top:

	for (x = 0; x < width; x++) {
		for (y = 0; y < height; y++) {
			i = y * width + x;
			if (data[i]) {
				margin_left = x;
				goto out_left;
			}
		}
	}
out_left:

	for (y = height - 1; y >= 0; y--) {
		for (x = 0; x < width; x++) {
			i = y * width + x;
			if (data[i]) {
				margin_bottom = height - y - 1;
				goto out_bottom;
			}
		}
	}
out_bottom:

	for (x = width - 1; x >= 0; x--) {
		for (y = 0; y < height; y++) {
			i = y * width + x;
			if (data[i]) {
				margin_right = width - x - 1;
				goto out_right;
			}
		}
	}
out_right:

/*
    printf("margin_top: %d\n", margin_top);
    printf("margin_left: %d\n", margin_left);
    printf("margin_bottom: %d\n", margin_bottom);
    printf("margin_right: %d\n", margin_right);
*/
	PDFRectangle rect;
	rect.x1 = margin_left;
	rect.y1 = margin_bottom;
	rect.x2 = width - margin_right;
	rect.y2 = height - margin_top;
	return rect;
}