How to scale selections?
Michael Thaler
michael.thaler at ph.tum.de
Fri Jul 1 17:44:46 CEST 2005
Hello,
I just tried what happens when I scale an image with a selection with my
scaling code. What happens is, that the selection is just untouched (however
it is extended to the new image size). If the selection is really only a
layer, it should be straight-forward to scale it, too. How can I do this?
The relevant code that iterates over all layers is in kis_image.cc:
void KisImage::scale(double sx, double sy, KisProgressDisplayInterface
*m_progress, enumFilterType ftype)
{
kdDebug(DBG_AREA_CORE) << "KisImage::scale. SX: "
<< sx
<< ", SY:"
<< sy
<< "\n";
if (m_layers.empty()) return; // Nothing to scale
// New image size. XXX: Pass along to discourage rounding errors?
Q_INT32 w, h;
w = (Q_INT32)(( width() * sx) + 0.5);
h = (Q_INT32)(( height() * sy) + 0.5);
if (w != width() || h != height()) {
undoAdapter() -> beginMacro("Scale image");
vKisLayerSP_it it;
for ( it = m_layers.begin(); it != m_layers.end(); ++it ) {
KisLayerSP layer = (*it);
KisTransaction *cmd = 0;
if (undoAdapter() -> undo()) {
cmd = new KisTransaction("", layer.data());
Q_CHECK_PTR(cmd);
}
layer -> scale(sx, sy, m_progress, ftype);
if (undoAdapter() -> undo()) {
undoAdapter() -> addCommand(cmd);
}
}
undoAdapter() -> addCommand(new KisResizeImageCmd(m_adapter, this, w, h,
width(), height()));
m_width = w;
m_height = h;
m_projection = new KisLayer(this, "projection", OPACITY_OPAQUE);
Q_CHECK_PTR(m_projection);
m_bkg = new KisBackground(this, w, h);
Q_CHECK_PTR(m_bkg);
undoAdapter() -> endMacro();
emit sizeChanged(KisImageSP(this), w, h);
}
}
How can I add the selection layer here?
Greetings,
Michael
More information about the kimageshop
mailing list