Exemple #1
0
void PlaneViewer::draw(TRasterImageP ri) {
  double dpiX, dpiY;
  ri->getDpi(dpiX, dpiY);

  if (dpiX == 0.0 || dpiY == 0.0) dpiX = dpiY = Stage::inch;

  draw(ri->getRaster(), dpiX, dpiY);
}
static void get_virtual_buffer(const TRasterImageP &image,
							   int *p_lx, int *p_ly, int *p_wrap,
							   UCHAR **p_buffer)
{
	int x0, y0, x1, y1;
	int x_margin, y_margin;
	int lx, ly, wrap;
	UCHAR *buffer;

	TRasterGR8P ras8(image->getRaster());

	assert(ras8);
	double xdpi, ydpi;
	image->getDpi(xdpi, ydpi);

	/* BORDO DI MEZZO CENTIMETRO */
	x_margin = troundp(mmToPixel(5.0, xdpi));
	y_margin = troundp(mmToPixel(5.0, ydpi));
	x0 = Window_x0 + x_margin;
	y0 = Window_y0 + y_margin;
	x1 = Window_x1 - x_margin;
	y1 = Window_y1 - y_margin;
	notLessThan(x0 + 9, x1);
	notLessThan(y0 + 9, y1);
	notLessThan(0, x0);
	notMoreThan(ras8->getLx() - 1, x0);
	notLessThan(0, y0);
	notMoreThan(ras8->getLy() - 1, y0);
	notLessThan(0, x1);
	notMoreThan(ras8->getLx() - 1, x1);
	notLessThan(0, y1);
	notMoreThan(ras8->getLy() - 1, y1);

	lx = x1 - x0 + 1;
	ly = y1 - y0 + 1;
	wrap = ras8->getWrap();
	buffer = (UCHAR *)ras8->getRawData() + x0 + y0 * wrap;

	*p_lx = lx;
	*p_ly = ly;
	*p_wrap = wrap;
	*p_buffer = buffer;
}
void PreviewToggleCommand::postProcess() {
  TApp *app                   = TApp::instance();
  CleanupSettingsModel *model = CleanupSettingsModel::instance();

  TXshSimpleLevel *sl;
  TFrameId fid;
  model->getCleanupFrame(sl, fid);

  assert(sl);
  if (!sl) return;

  // Retrieve transformed image
  TRasterImageP transformed;
  {
    TRasterImageP original;
    TAffine transform;

    model->getPreviewData(original, transformed, transform);
    if (!transformed) return;
  }

  // Perform post-processing
  TRasterImageP preview(
      TCleanupper::instance()->processColors(transformed->getRaster()));

  TPointD dpi;
  transformed->getDpi(dpi.x, dpi.y);
  preview->setDpi(dpi.x, dpi.y);

  transformed = TRasterImageP();

  // Substitute current frame image with previewed one
  sl->setFrame(fid, preview);

  TApp::instance()->getCurrentLevel()->notifyLevelChange();
}
bool TCleanupper::getResampleValues(const TRasterImageP &image, TAffine &aff, double &blur,
									TDimension &outDim, TPointD &outDpi, bool isCameraTest, bool &isSameDpi)
{
	double outlp, outlq;
	double scalex, scaley;
	double cxin, cyin, cpout, cqout;
	double max_blur;
	TPointD dpi;

	// Locking the input image to be cleanupped
	image->getRaster()->lock();

	// Retrieve image infos
	int rasterLx = image->getRaster()->getLx();
	int rasterLy = image->getRaster()->getLy();

	/*---入力画像サイズとSaveBoxのサイズが一致しているか?の判定---*/
	TRect saveBox = image->getSavebox();
	bool raster_is_savebox = true;
	if (saveBox == TRect() && (saveBox.getLx() > 0 && saveBox.getLx() < rasterLx ||
							   saveBox.getLy() > 0 && saveBox.getLy() < rasterLy))
		raster_is_savebox = false;

	image->getDpi(dpi.x, dpi.y);
	if (dpi == TPointD()) {
		dpi = getCustomDpi();
		if (dpi == TPointD())
			dpi.x = dpi.y = 65.0; //using 65.0 as default DPI
	} else if (!dpi.x)
		dpi.x = dpi.y;
	else if (!dpi.y)
		dpi.y = dpi.x;

	// Retrieve some cleanup parameters
	int rotate = m_parameters->m_rotate;

	//Build scaling/dpi data
	{
		m_parameters->getOutputImageInfo(outDim, outDpi.x, outDpi.y);

		// input -> output scale factor
		scalex = outDpi.x / dpi.x;
		scaley = outDpi.y / dpi.y;

		outlp = outDim.lx;
		outlq = outDim.ly;
	}

	/*--- 拡大/縮小をしていない場合(DPIが変わらない場合)、NearestNeighborでリサンプリングする。---*/
	isSameDpi = areAlmostEqual(outDpi.x, dpi.x, 0.1) && areAlmostEqual(outDpi.y, dpi.y, 0.1);

	// Retrieve input center
	if (raster_is_savebox) {
		cxin = -saveBox.getP00().x + (saveBox.getLx() - 1) / 2.0;
		cyin = -saveBox.getP00().y + (saveBox.getLy() - 1) / 2.0;
	} else {
		cxin = (rasterLx - 1) / 2.0;
		cyin = (rasterLy - 1) / 2.0;
	}

	// Retrieve output center
	cpout = (outlp - 1) / 2.0;
	cqout = (outlq - 1) / 2.0;
	// Perform autocenter if any is found
	double angle = 0.0;
	double skew = 0.0;
	TAffine pre_aff;
	image->getRaster()->lock();

	bool autocentered =
		doAutocenter(
			angle, skew,
			cxin, cyin, cqout, cpout,
			dpi.x, dpi.y,
			raster_is_savebox, saveBox,
			image, scalex);
	image->getRaster()->unlock();

	// Build the image transform as deduced by the autocenter
	if (m_parameters->m_autocenterType == AUTOCENTER_CTR && skew) {
		pre_aff.a11 = cos(skew * TConsts::pi_180);
		pre_aff.a21 = sin(skew * TConsts::pi_180);
	}

	aff = (TScale(scalex, scaley) * pre_aff) * TRotation(angle);
	aff = aff.place(cxin, cyin, cpout, cqout);

	// Apply eventual additional user-defined transforms
	TPointD pout = TPointD((outlp - 1) / 2.0, (outlq - 1) / 2.0);

	if (m_parameters->m_rotate != 0)
		aff = TRotation(-(double)m_parameters->m_rotate).place(pout, pout) * aff;

	if (m_parameters->m_flipx || m_parameters->m_flipy)
		aff = TScale(m_parameters->m_flipx ? -1 : 1, m_parameters->m_flipy ? -1 : 1).place(pout, pout) * aff;

	if (!isCameraTest)
		aff = TTranslation(m_parameters->m_offx * outDpi.x / 2, m_parameters->m_offy * outDpi.y / 2) * aff;

	max_blur = 20.0 * sqrt(fabs(scalex /*** * oversample_factor ***/));
	blur = pow(max_blur, (100 - m_parameters->m_sharpness) / (100 - 1));
	return autocentered;
}