Add a load image button to camera capture for reference image (#751)

Added button to load image in the selected cell into the reference (onion skin) image.
 This is useful in stop-motion work for lining up your camera with a previous image.
This commit is contained in:
Jeremy Bullock 2016-11-23 18:54:55 -07:00 committed by shun-iwasawa
parent 85c476cdde
commit 83d3e36d63
2 changed files with 78 additions and 2 deletions

View file

@ -5,7 +5,8 @@
#include "menubarcommandids.h"
#include "formatsettingspopups.h"
#include "filebrowsermodel.h"
#include "cellselection.h"
#include "toonzqt/tselectionhandle.h"
// TnzQt includes
#include "toonzqt/menubarcommand.h"
#include "toonzqt/filefield.h"
@ -625,6 +626,7 @@ PencilTestPopup::PencilTestPopup()
QGroupBox* displayFrame = new QGroupBox(tr("Display"), this);
m_onionSkinCB = new QCheckBox(tr("Show onion skin"), this);
m_loadImageButton = new QPushButton(tr("Load Selected Image"), this);
m_onionOpacityFld = new IntField(this);
QGroupBox* timerFrame = new QGroupBox(tr("Interval timer"), this);
@ -829,6 +831,7 @@ PencilTestPopup::PencilTestPopup()
displayLay->addWidget(new QLabel(tr("Opacity(%):"), this), 1, 0,
Qt::AlignRight);
displayLay->addWidget(m_onionOpacityFld, 1, 1);
displayLay->addWidget(m_loadImageButton, 2, 0, 1, 2);
}
displayLay->setColumnStretch(0, 0);
displayLay->setColumnStretch(1, 1);
@ -882,6 +885,8 @@ PencilTestPopup::PencilTestPopup()
SLOT(onCaptureWhiteBGButtonPressed()));
ret = ret && connect(m_onionSkinCB, SIGNAL(toggled(bool)), this,
SLOT(onOnionCBToggled(bool)));
ret = ret && connect(m_loadImageButton, SIGNAL(pressed()), this,
SLOT(onLoadImageButtonPressed()));
ret = ret && connect(m_onionOpacityFld, SIGNAL(valueEditedByHand()), this,
SLOT(onOnionOpacityFldEdited()));
ret = ret && connect(m_upsideDownCB, SIGNAL(toggled(bool)),
@ -1288,6 +1293,76 @@ void PencilTestPopup::onOnionCBToggled(bool on) {
//-----------------------------------------------------------------------------
void PencilTestPopup::onLoadImageButtonPressed() {
TCellSelection* cellSelection = dynamic_cast<TCellSelection*>(
TApp::instance()->getCurrentSelection()->getSelection());
if (cellSelection) {
int c0;
int r0;
TCellSelection::Range range = cellSelection->getSelectedCells();
if (range.isEmpty()) {
error(tr("No image selected. Please select an image in the Xsheet."));
return;
}
c0 = range.m_c0;
r0 = range.m_r0;
TXshCell cell =
TApp::instance()->getCurrentXsheet()->getXsheet()->getCell(r0, c0);
if (cell.getSimpleLevel() == nullptr) {
error(tr("No image selected. Please select an image in the Xsheet."));
return;
}
TXshSimpleLevel* level = cell.getSimpleLevel();
int type = level->getType();
if (type != TXshLevelType::OVL_XSHLEVEL) {
error(tr("The selected image is not in a raster level."));
return;
}
TImageP origImage = cell.getImage(false);
TRasterImageP tempImage(origImage);
TRasterImage* image = (TRasterImage*)tempImage->cloneImage();
int m_lx = image->getRaster()->getLx();
int m_ly = image->getRaster()->getLy();
QString res = m_resolutionCombo->currentText();
QStringList texts = res.split(' ');
if (m_lx != texts[0].toInt() || m_ly != texts[2].toInt()) {
error(
tr("The selected image size does not match the current camera "
"settings."));
return;
}
int m_bpp = image->getRaster()->getPixelSize();
int totalBytes = m_lx * m_ly * m_bpp;
image->getRaster()->yMirror();
// lock raster to get data
image->getRaster()->lock();
void* buffin = image->getRaster()->getRawData();
assert(buffin);
void* buffer = malloc(totalBytes);
memcpy(buffer, buffin, totalBytes);
image->getRaster()->unlock();
QImage qi = QImage((uint8_t*)buffer, m_lx, m_ly, QImage::Format_ARGB32);
QImage qi2(qi.size(), QImage::Format_ARGB32);
qi2.fill(QColor(Qt::white).rgb());
QPainter painter(&qi2);
if (m_upsideDownCB->isChecked()) {
painter.translate(m_lx / 2, m_ly / 2);
painter.rotate(180);
painter.translate(-m_lx / 2, -m_ly / 2);
}
painter.drawImage(0, 0, qi);
m_cameraViewfinder->setPreviousImage(qi2);
m_onionSkinCB->setChecked(true);
free(buffer);
}
}
//-----------------------------------------------------------------------------
void PencilTestPopup::onOnionOpacityFldEdited() {
int value = (int)(255.0f * (float)m_onionOpacityFld->getValue() / 100.0f);
m_cameraViewfinder->setOnionOpacity(value);

View file

@ -138,7 +138,7 @@ class PencilTestPopup : public DVGui::Dialog {
LevelNameLineEdit* m_levelNameEdit;
QCheckBox *m_upsideDownCB, *m_onionSkinCB, *m_saveOnCaptureCB, *m_timerCB;
QPushButton *m_fileFormatOptionButton, *m_captureWhiteBGButton,
*m_captureButton;
*m_captureButton, *m_loadImageButton;
DVGui::FileField* m_saveInFileFld;
FrameNumberLineEdit* m_frameNumberEdit;
DVGui::IntField *m_thresholdFld, *m_contrastFld, *m_brightnessFld,
@ -181,6 +181,7 @@ protected slots:
void onImageCaptured(int, const QImage&);
void onCaptureWhiteBGButtonPressed();
void onOnionCBToggled(bool);
void onLoadImageButtonPressed();
void onOnionOpacityFldEdited();
void onTimerCBToggled(bool);
void onCaptureTimerTimeout();