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
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;
}