Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
justburner 521a74
#include "toonzqt/seethroughwindow.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/menubarcommand.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/viewcommandids.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/imageutils.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
f6ea6c
// Qt Includes:
f6ea6c
#include <qscreen></qscreen>
f6ea6c
#include <qwindow></qwindow>
f6ea6c
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/preferences.h"
Toshihiro Shimizu 890ddd
#include "toonz/namebuilder.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/tproject.h"
Toshihiro Shimizu 890ddd
#include "toonz/Naa2TlvConverter.h"
shun-iwasawa acfe75
#include "toonz/toonzimageutils.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#include "avicodecrestrictions.h"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tsystem.h"
Toshihiro Shimizu 890ddd
#include "tfilepath_io.h"
Toshihiro Shimizu 890ddd
#include "timage_io.h"
Toshihiro Shimizu 890ddd
#include "tlevel.h"
Toshihiro Shimizu 890ddd
#include "tlevel_io.h"
Toshihiro Shimizu 890ddd
#include "tpalette.h"
Toshihiro Shimizu 890ddd
#include "tropcm.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "tvectorrenderdata.h"
Toshihiro Shimizu 890ddd
#include "tofflinegl.h"
Toshihiro Shimizu 890ddd
#include "tconvert.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "timageinfo.h"
Toshihiro Shimizu 890ddd
#include "tfiletype.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "ttoonzimage.h"
Toshihiro Shimizu 890ddd
#include "tvectorimage.h"
Toshihiro Shimizu 890ddd
#include "tstroke.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
shun_iwasawa b2badd
#ifdef _WIN32
shun_iwasawa b2badd
#include <qtplatformheaders qwindowswindowfunctions=""></qtplatformheaders>
shun_iwasawa b2badd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// boost includes
Toshihiro Shimizu 890ddd
#include <boost iterator="" transform_iterator.hpp=""></boost>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace  stuff
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void addOverlappedRegions(TRegion *reg, std::vector<tfilledregioninf> ®Inf) {</tfilledregioninf>
Shinya Kitaoka 120a6e
  regInf.push_back(TFilledRegionInf(reg->getId(), reg->getStyle()));
Shinya Kitaoka 120a6e
  UINT regNum = reg->getSubregionCount();
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < regNum; i++)
Shinya Kitaoka 120a6e
    addOverlappedRegions(reg->getSubregion(i), regInf);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void addRegionsInArea(TRegion *reg, std::vector<tfilledregioninf> ®s,</tfilledregioninf>
Shinya Kitaoka 120a6e
                      const TRectD &area) {
Shinya Kitaoka 120a6e
  if (area.contains(reg->getBBox()))
Shinya Kitaoka 120a6e
    regs.push_back(TFilledRegionInf(reg->getId(), reg->getStyle()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (reg->getBBox().overlaps(area)) {
Shinya Kitaoka 120a6e
    UINT regNum = reg->getSubregionCount();
Shinya Kitaoka 120a6e
    for (UINT i = 0; i < regNum; i++)
Shinya Kitaoka 120a6e
      addRegionsInArea(reg->getSubregion(i), regs, area);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void getFrameIds(TFrameId from, TFrameId to, const TLevelP &level,
Shinya Kitaoka 120a6e
                 std::vector<tframeid> &frames) {</tframeid>
Shinya Kitaoka 120a6e
  struct locals {
Shinya Kitaoka 120a6e
    static inline TFrameId getFrame(const TLevel::Table::value_type &pair) {
Shinya Kitaoka 120a6e
      return pair.first;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };  // locals
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (from.isEmptyFrame()) from = TFrameId(-(std::numeric_limits<int>::max)());</int>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (to.isEmptyFrame()) to = TFrameId((std::numeric_limits<int>::max)());</int>
Toshihiro Shimizu 890ddd
otakuto ed7dcd
  if (from > to) std::swap(from, to);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TLevel::Table &table = *level->getTable();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLevel::Table::const_iterator lBegin = table.lower_bound(from),
Shinya Kitaoka 120a6e
                                lEnd   = table.upper_bound(to);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(frames.empty());
Shinya Kitaoka 120a6e
  frames.insert(frames.end(),
Shinya Kitaoka 120a6e
                boost::make_transform_iterator(lBegin, locals::getFrame),
Shinya Kitaoka 120a6e
                boost::make_transform_iterator(lEnd, locals::getFrame));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
//    ImageUtils namespace  stuff
Toshihiro Shimizu 890ddd
//**********************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace ImageUtils {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// todo: spostare da qualche altra parte. rendere accessibile a tutti.
Shinya Kitaoka 120a6e
// utilizzare
Toshihiro Shimizu 890ddd
// anche nella libreria dovunque si usi direttamente "_files"
Campbell Barton ccd505
static TFilePath getResourceFolder(const TFilePath &scenePath) {
Shinya Kitaoka 120a6e
  return scenePath.getParentDir() + (scenePath.getName() + "_files");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton ccd505
static void copyScene(const TFilePath &dst, const TFilePath &src) {
Shinya Kitaoka 120a6e
  TSystem::copyFile(dst, src);
Shinya Kitaoka 120a6e
  if (TProjectManager::instance()->isTabModeEnabled())
Shinya Kitaoka 120a6e
    TSystem::copyDir(getResourceFolder(dst), getResourceFolder(src));
Shinya Kitaoka 120a6e
  TFilePath srcIcon = ToonzScene::getIconPath(src);
Shinya Kitaoka 120a6e
  if (TFileStatus(srcIcon).doesExist()) {
Shinya Kitaoka 120a6e
    TFilePath dstIcon = ToonzScene::getIconPath(dst);
Shinya Kitaoka 120a6e
    TSystem::copyFile(dstIcon, srcIcon);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFilePath duplicate(const TFilePath &levelPath) {
Shinya Kitaoka 120a6e
  if (levelPath == TFilePath()) return TFilePath();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!TSystem::doesExistFileOrLevel(levelPath)) {
Shinya Kitaoka 120a6e
    DVGui::warning(
Shinya Kitaoka 120a6e
        QObject::tr("It is not possible to find the %1 level.")
Shinya Kitaoka 120a6e
            .arg(QString::fromStdWString(levelPath.getWideString())));
Shinya Kitaoka 120a6e
    return TFilePath();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  NameBuilder *nameBuilder =
Shinya Kitaoka 120a6e
      NameBuilder::getBuilder(::to_wstring(levelPath.getName()));
Shinya Kitaoka 120a6e
  std::wstring levelNameOut;
Shinya Kitaoka 120a6e
  do
Shinya Kitaoka 120a6e
    levelNameOut = nameBuilder->getNext();
Shinya Kitaoka 120a6e
  while (TSystem::doesExistFileOrLevel(levelPath.withName(levelNameOut)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFilePath levelPathOut = levelPath.withName(levelNameOut);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    if (levelPath.getType() == "tnz")
Shinya Kitaoka 120a6e
      copyScene(levelPathOut, levelPath);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      TSystem::copyFileOrLevel_throw(levelPathOut, levelPath);
Shinya Kitaoka 120a6e
      if (levelPath.getType() == "tlv") {
Shinya Kitaoka 120a6e
        TFilePath pltPath = levelPath.withType("tpl");
Shinya Kitaoka 120a6e
        if (TSystem::doesExistFileOrLevel(pltPath))
Shinya Kitaoka 120a6e
          TSystem::copyFileOrLevel_throw(levelPathOut.withType("tpl"), pltPath);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    QString msg =
Shinya Kitaoka 120a6e
        QObject::tr("There was an error copying %1").arg(toQString(levelPath));
Shinya Kitaoka 120a6e
    DVGui::error(msg);
Shinya Kitaoka 120a6e
    return TFilePath();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //  QString msg = QString("Copied ") +
Shinya Kitaoka 120a6e
  //                QString::fromStdWString(levelPath.withoutParentDir().getWideString())
Shinya Kitaoka 120a6e
  //                +
Shinya Kitaoka 120a6e
  //                QString(" to " +
Shinya Kitaoka 120a6e
  //                QString::fromStdWString(levelPathOut.withoutParentDir().getWideString()));
Shinya Kitaoka 120a6e
  //  DVGui::info(msg);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return levelPathOut;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void premultiply(const TFilePath &levelPath) {
Shinya Kitaoka 120a6e
  if (levelPath == TFilePath()) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!TSystem::doesExistFileOrLevel(levelPath)) {
Shinya Kitaoka 120a6e
    DVGui::warning(
Shinya Kitaoka 120a6e
        QObject::tr("It is not possible to find the level %1")
Shinya Kitaoka 120a6e
            .arg(QString::fromStdWString(levelPath.getWideString())));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TFileType::Type type = TFileType::getInfo(levelPath);
Shinya Kitaoka 120a6e
  if (type == TFileType::CMAPPED_LEVEL) {
Shinya Kitaoka 120a6e
    DVGui::warning(QObject::tr("Cannot premultiply the selected file."));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (type == TFileType::VECTOR_LEVEL || type == TFileType::VECTOR_IMAGE) {
Shinya Kitaoka 120a6e
    DVGui::warning(QObject::tr("Cannot premultiply a vector-based level."));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  if (type != TFileType::RASTER_LEVEL && type != TFileType::RASTER_IMAGE) {
Shinya Kitaoka 120a6e
    DVGui::info(QObject::tr("Cannot premultiply the selected file."));
Toshihiro Shimizu 890ddd
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    TLevelReaderP lr = TLevelReaderP(levelPath);
Shinya Kitaoka 120a6e
    if (!lr) return;
Shinya Kitaoka 120a6e
    TLevelP level = lr->loadInfo();
Shinya Kitaoka 120a6e
    if (!level || level->getFrameCount() == 0) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bool isMovie = type == TFileType::RASTER_LEVEL;
Shinya Kitaoka 120a6e
    /*
Shinya Kitaoka 120a6e
if (!isMovie && lr->getImageInfo()->m_samplePerPixel!=4)
Shinya Kitaoka 120a6e
{
artisteacher 7db72b
QMessageBox::information(0, QString("ERROR"), QString("Only rgba images can be
Shinya Kitaoka 120a6e
premultiplied!"));
Shinya Kitaoka 120a6e
return;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TLevelWriterP lw;
Shinya Kitaoka 120a6e
    if (!isMovie) {
Shinya Kitaoka 120a6e
      lw = TLevelWriterP(levelPath);
Shinya Kitaoka 120a6e
      if (!lw) return;
Toshihiro Shimizu 890ddd
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
Shinya Kitaoka 120a6e
    qApp->processEvents();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int count           = 0;
Shinya Kitaoka 120a6e
    TLevel::Iterator it = level->begin();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (; it != level->end(); ++it) {
Shinya Kitaoka 120a6e
      TImageReaderP ir = lr->getFrameReader(it->first);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TRasterImageP rimg = (TRasterImageP)ir->load();
Shinya Kitaoka 120a6e
      if (!rimg) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TRop::premultiply(rimg->getRaster());
Shinya Kitaoka 120a6e
      ir = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (isMovie)
Shinya Kitaoka 120a6e
        level->setFrame(it->first, rimg);
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        TImageWriterP iw = lw->getFrameWriter(it->first);
Shinya Kitaoka 120a6e
        iw->save(levelPath.withFrame(it->first), rimg);
Shinya Kitaoka 120a6e
        iw = 0;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    lr = TLevelReaderP();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (isMovie) {
Shinya Kitaoka 120a6e
      TSystem::deleteFile(levelPath);
Shinya Kitaoka 120a6e
      lw = TLevelWriterP(levelPath);
Shinya Kitaoka 120a6e
      if (!lw) {
Shinya Kitaoka 120a6e
        QApplication::restoreOverrideCursor();
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      lw->save(level);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (...) {
Shinya Kitaoka 120a6e
    DVGui::warning(QObject::tr("Cannot premultiply the selected file."));
Shinya Kitaoka 120a6e
    QApplication::restoreOverrideCursor();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QApplication::restoreOverrideCursor();
Shinya Kitaoka 120a6e
  QString msg = QObject::tr("Level %1 premultiplied.")
Shinya Kitaoka 120a6e
                    .arg(QString::fromStdString(levelPath.getLevelName()));
Shinya Kitaoka 120a6e
  DVGui::info(msg);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void getFillingInformationOverlappingArea(const TVectorImageP &vi,
Shinya Kitaoka 120a6e
                                          std::vector<tfilledregioninf> ®Inf,</tfilledregioninf>
Shinya Kitaoka 120a6e
                                          const TRectD &area1,
Shinya Kitaoka 120a6e
                                          const TRectD &area2) {
Shinya Kitaoka 120a6e
  if (!vi->isComputedRegionAlmostOnce()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  assert(area1 != TRectD() || area2 != TRectD());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  vi->findRegions();
Shinya Kitaoka 120a6e
  UINT regNum = vi->getRegionCount();
Shinya Kitaoka 120a6e
  TRegion *reg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < regNum; i++) {
Shinya Kitaoka 120a6e
    reg = vi->getRegion(i);
Shinya Kitaoka 120a6e
    if (reg->getBBox().overlaps(area1) || reg->getBBox().overlaps(area2))
Shinya Kitaoka 120a6e
      addOverlappedRegions(reg, regInf);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void getFillingInformationInArea(const TVectorImageP &vi,
Shinya Kitaoka 120a6e
                                 std::vector<tfilledregioninf> ®s,</tfilledregioninf>
Shinya Kitaoka 120a6e
                                 const TRectD &area) {
Shinya Kitaoka 120a6e
  if (!vi->isComputedRegionAlmostOnce()) return;
Shinya Kitaoka 120a6e
  vi->findRegions();
Shinya Kitaoka 120a6e
  UINT regNum = vi->getRegionCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < regNum; i++)
Shinya Kitaoka 120a6e
    addRegionsInArea(vi->getRegion(i), regs, area);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void assignFillingInformation(TVectorImage &vi,
Shinya Kitaoka 120a6e
                              const std::vector<tfilledregioninf> ®s) {</tfilledregioninf>
Shinya Kitaoka 120a6e
  vi.findRegions();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  UINT r, rCount = UINT(regs.size());
Shinya Kitaoka 120a6e
  for (r = 0; r != rCount; ++r) {
Shinya Kitaoka 120a6e
    const TFilledRegionInf &rInfo = regs[r];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (TRegion *region = vi.getRegion(rInfo.m_regionId))
Shinya Kitaoka 120a6e
      region->setStyle(rInfo.m_styleId);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void getStrokeStyleInformationInArea(
Shinya Kitaoka 120a6e
    const TVectorImageP &vi, std::vector<std::pair<int, int="">> &strokesInfo,</std::pair<int,>
Shinya Kitaoka 120a6e
    const TRectD &area) {
Shinya Kitaoka 120a6e
  if (!vi->isComputedRegionAlmostOnce()) return;
Shinya Kitaoka 120a6e
  vi->findRegions();
Shinya Kitaoka 120a6e
  UINT regNum = vi->getStrokeCount();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (UINT i = 0; i < vi->getStrokeCount(); i++) {
Shinya Kitaoka 120a6e
    if (!vi->inCurrentGroup(i)) continue;
Shinya Kitaoka 120a6e
    if (area.contains(vi->getStroke(i)->getBBox()))
Shinya Kitaoka 120a6e
      strokesInfo.push_back(
Shinya Kitaoka 120a6e
          std::pair<int, int="">(i, vi->getStroke(i)->getStyle()));</int,>
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
shun-iwasawa 27b0cf
static void convertFromCM(
shun-iwasawa 27b0cf
    const TLevelReaderP &lr, const TPaletteP &plt, const TLevelWriterP &lw,
shun-iwasawa 27b0cf
    const std::vector<tframeid> &frames, const TAffine &aff,</tframeid>
shun-iwasawa 27b0cf
    const TRop::ResampleFilterType &resType, FrameTaskNotifier *frameNotifier,
shun-iwasawa 27b0cf
    const TPixel &bgColor, bool removeDotBeforeFrameNumber = false) {
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)frames.size(); i++) {
Shinya Kitaoka 120a6e
    if (frameNotifier->abortTask()) break;
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TImageReaderP ir = lr->getFrameReader(frames[i]);
Shinya Kitaoka 120a6e
      TImageP img      = ir->load();
Shinya Kitaoka 120a6e
      TToonzImageP toonzImage(img);
Shinya Kitaoka 120a6e
      double xdpi, ydpi;
Shinya Kitaoka 120a6e
      toonzImage->getDpi(xdpi, ydpi);
Shinya Kitaoka 120a6e
      assert(toonzImage);
Shinya Kitaoka 120a6e
      if (toonzImage) {
Shinya Kitaoka 120a6e
        TRasterCM32P rasCMImage = toonzImage->getRaster();
Shinya Kitaoka 120a6e
        TRaster32P ras(
Shinya Kitaoka 120a6e
            convert(aff * convert(rasCMImage->getBounds())).getSize());
Shinya Kitaoka 120a6e
        if (!aff.isIdentity())
Shinya Kitaoka 120a6e
          TRop::resample(ras, rasCMImage, plt, aff, resType);
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          TRop::convert(ras, rasCMImage, plt);
Shinya Kitaoka 120a6e
        if (bgColor != TPixel::Transparent) TRop::addBackground(ras, bgColor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        TRasterImageP rasImage(ras);
Shinya Kitaoka 120a6e
        rasImage->setDpi(xdpi, ydpi);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        /*---
Shinya Kitaoka 120a6e
                ConvertPopup
Shinya Kitaoka 120a6e
        での指定に合わせて、[レベル名].[フレーム番号].[拡張子]
Shinya Kitaoka 120a6e
                のうち、[レベル名]と[フレーム番号]の間のドットを消す。
Shinya Kitaoka 120a6e
                例:A.0001.tga → A0001.tga になる。
Shinya Kitaoka 120a6e
        ---*/
Shinya Kitaoka 120a6e
        if (removeDotBeforeFrameNumber) {
Shinya Kitaoka 120a6e
          TFilePath outPath = lw->getFilePath().withFrame(frames[i]);
Shinya Kitaoka 120a6e
          /*--- フレーム番号と拡張子の文字数の合計。大抵8 ---*/
Shinya Kitaoka 120a6e
          int index               = 4 + 1 + outPath.getType().length();
Shinya Kitaoka 120a6e
          std::wstring renamedStr = outPath.getWideString();
Shinya Kitaoka 120a6e
          if (renamedStr[renamedStr.length() - index - 1] == L'.')
Shinya Kitaoka 120a6e
            renamedStr = renamedStr.substr(0, renamedStr.length() - index - 1) +
Shinya Kitaoka 120a6e
                         renamedStr.substr(renamedStr.length() - index, index);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          const TFilePath fp(renamedStr);
Shinya Kitaoka 120a6e
          TImageWriterP writer(fp);
Shinya Kitaoka 120a6e
          writer->setProperties(lw->getProperties());
Shinya Kitaoka 120a6e
          writer->save(rasImage);
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          TImageWriterP iw = lw->getFrameWriter(frames[i]);
Shinya Kitaoka 120a6e
          iw->save(rasImage);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } catch (...) {
Shinya Kitaoka 120a6e
      // QString msg=QObject::tr("Frame %1 : conversion
Shinya Kitaoka 120a6e
      // failed!").arg(QString::number(i+1));
Shinya Kitaoka 120a6e
      //      DVGui::info(msg);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    /*--
Shinya Kitaoka 120a6e
     * これはプログレスバーを進めるものなので、動画番号ではなく、完了したフレームの枚数を投げる
Shinya Kitaoka 120a6e
     * --*/
Shinya Kitaoka 120a6e
    frameNotifier->notifyFrameCompleted(100 * (i + 1) / frames.size());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton ccd505
static void convertFromVI(const TLevelReaderP &lr, const TPaletteP &plt,
shun-iwasawa 27b0cf
                          const TLevelWriterP &lw,
shun-iwasawa 27b0cf
                          const std::vector<tframeid> &frames,</tframeid>
Campbell Barton ccd505
                          const TRop::ResampleFilterType &resType, int width,
Campbell Barton ccd505
                          FrameTaskNotifier *frameNotifier) {
Shinya Kitaoka 120a6e
  QString msg;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  std::vector<tvectorimagep> images;</tvectorimagep>
Shinya Kitaoka 120a6e
  TRectD maxBbox;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)frames.size();
Shinya Kitaoka 120a6e
       i++) {  // trovo la bbox che possa contenere tutte le immagini
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TImageReaderP ir  = lr->getFrameReader(frames[i]);
Shinya Kitaoka 120a6e
      TVectorImageP img = ir->load();
Shinya Kitaoka 120a6e
      images.push_back(img);
Shinya Kitaoka 120a6e
      maxBbox += img->getBBox();
Shinya Kitaoka 120a6e
    } catch (...) {
Shinya Kitaoka 120a6e
      msg = QObject::tr("Frame %1 : conversion failed!")
Shinya Kitaoka 120a6e
                .arg(QString::fromStdString(frames[i].expand()));
Shinya Kitaoka 120a6e
      DVGui::info(msg);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  maxBbox = maxBbox.enlarge(2);
Shinya Kitaoka 120a6e
  TAffine aff;
Shinya Kitaoka 120a6e
  if (width)  // calcolo l'affine
shun-iwasawa c88070
    aff = TScale((double)width / maxBbox.getLx());
Shinya Kitaoka 120a6e
  maxBbox = aff * maxBbox;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)images.size(); i++) {
Shinya Kitaoka 120a6e
    if (frameNotifier->abortTask()) break;
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TVectorImageP vectorImage = images[i];
Shinya Kitaoka 120a6e
      assert(vectorImage);
Shinya Kitaoka 120a6e
      if (vectorImage) {
Shinya Kitaoka 120a6e
        // faccio il render dell'immagine
Shinya Kitaoka 120a6e
        vectorImage->transform(aff, true);
Shinya Kitaoka 120a6e
        const TVectorRenderData rd(TTranslation(-maxBbox.getP00()), TRect(),
Shinya Kitaoka 120a6e
                                   plt.getPointer(), 0, true, true);
Shinya Kitaoka 120a6e
        TOfflineGL *glContext = new TOfflineGL(convert(maxBbox).getSize());
Shinya Kitaoka 120a6e
        glContext->clear(TPixel32::Transparent);
Shinya Kitaoka 120a6e
        glContext->draw(vectorImage, rd);
Shinya Kitaoka 120a6e
        TRaster32P rasImage = (glContext->getRaster());
Shinya Kitaoka 120a6e
        TImageWriterP iw    = lw->getFrameWriter(TFrameId(i + 1));
Shinya Kitaoka 120a6e
        iw->save(TRasterImageP(rasImage));
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } catch (...) {
Shinya Kitaoka 120a6e
      msg = QObject::tr("Frame %1 : conversion failed!")
Shinya Kitaoka 120a6e
                .arg(QString::fromStdString(frames[i].expand()));
Shinya Kitaoka 120a6e
      DVGui::info(msg);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    frameNotifier->notifyFrameCompleted(100 * (i + 1) / frames.size());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------
Toshihiro Shimizu 890ddd
shun-iwasawa 27b0cf
static void convertFromFullRaster(
shun-iwasawa 27b0cf
    const TLevelReaderP &lr, const TLevelWriterP &lw,
shun-iwasawa 27b0cf
    const std::vector<tframeid> &_frames, const TAffine &aff,</tframeid>
shun-iwasawa 27b0cf
    const TRop::ResampleFilterType &resType, FrameTaskNotifier *frameNotifier,
shun-iwasawa 27b0cf
    const TPixel &bgColor, bool removeDotBeforeFrameNumber = false) {
Shinya Kitaoka 120a6e
  std::vector<tframeid> frames = _frames;</tframeid>
shun-iwasawa c88070
  if (frames.empty() && lr->loadInfo()->getFrameCount() ==
shun-iwasawa c88070
                            1)  // e' una immagine singola, non un livello
Shinya Kitaoka 120a6e
    frames.push_back(TFrameId());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)frames.size(); i++) {
Shinya Kitaoka 120a6e
    if (frameNotifier->abortTask()) break;
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TRasterImageP img;
Shinya Kitaoka 120a6e
      if (frames[i] == TFrameId())  // immagine singola, non livello
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        assert(frames.size() == 1);
Shinya Kitaoka 120a6e
        TImageP _img;
Shinya Kitaoka 120a6e
        if (!TImageReader::load(lr->getFilePath(), _img)) continue;
Shinya Kitaoka 120a6e
        img = _img;
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        TImageReaderP ir = lr->getFrameReader(frames[i]);
Shinya Kitaoka 120a6e
        img              = ir->load();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      TRaster32P raster(convert(aff * img->getBBox()).getSize());
Shinya Kitaoka 120a6e
      if (!aff.isIdentity())
Shinya Kitaoka 120a6e
        TRop::resample(raster, img->getRaster(), aff, resType);
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        if ((TRaster32P)img->getRaster())
Shinya Kitaoka 120a6e
          raster = img->getRaster();
Shinya Kitaoka 120a6e
        else
Shinya Kitaoka 120a6e
          TRop::convert(raster, img->getRaster());
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      if (bgColor != TPixel::Transparent) TRop::addBackground(raster, bgColor);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TRasterImageP newImg(raster);
Shinya Kitaoka 120a6e
      double xDpi, yDpi;
Shinya Kitaoka 120a6e
      img->getDpi(xDpi, yDpi);
Shinya Kitaoka 120a6e
      if (xDpi == 0 && yDpi == 0)
Shinya Kitaoka 120a6e
        xDpi = yDpi = Preferences::instance()->getDefLevelDpi();
Shinya Kitaoka 120a6e
      newImg->setDpi(xDpi, yDpi);
Shinya Kitaoka 120a6e
      if (frames[i] == TFrameId())
Shinya Kitaoka 120a6e
        TImageWriter::save(lw->getFilePath(), newImg);
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        /*---
Shinya Kitaoka 120a6e
ConvertPopup での指定に合わせて、[レベル名].[フレーム番号].[拡張子]
Shinya Kitaoka 120a6e
のうち、[レベル名]と[フレーム番号]の間のドットを消す。
Shinya Kitaoka 120a6e
例:A.0001.tga → A0001.tga になる。
Shinya Kitaoka 120a6e
---*/
Shinya Kitaoka 120a6e
        if (removeDotBeforeFrameNumber) {
Shinya Kitaoka 120a6e
          TFilePath outPath = lw->getFilePath().withFrame(frames[i]);
Shinya Kitaoka 120a6e
          /*--- フレーム番号と拡張子の文字数の合計。大抵8 ---*/
Shinya Kitaoka 120a6e
          int index               = 4 + 1 + outPath.getType().length();
Shinya Kitaoka 120a6e
          std::wstring renamedStr = outPath.getWideString();
Shinya Kitaoka 120a6e
          if (renamedStr[renamedStr.length() - index - 1] == L'.')
Shinya Kitaoka 120a6e
            renamedStr = renamedStr.substr(0, renamedStr.length() - index - 1) +
Shinya Kitaoka 120a6e
                         renamedStr.substr(renamedStr.length() - index, index);
Shinya Kitaoka 120a6e
          const TFilePath fp(renamedStr);
Shinya Kitaoka 120a6e
          TImageWriterP writer(fp);
Shinya Kitaoka 120a6e
          writer->setProperties(lw->getProperties());
Shinya Kitaoka 120a6e
          writer->save(newImg);
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          TImageWriterP iw = lw->getFrameWriter(frames[i]);
Shinya Kitaoka 120a6e
          iw->save(newImg);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } catch (...) {
Shinya Kitaoka 120a6e
      // QString msg=QObject::tr("Frame %1 : conversion
Shinya Kitaoka 120a6e
      // failed!").arg(QString::number(i+1));
Shinya Kitaoka 120a6e
      // DVGui::info(msg);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    /*--
Shinya Kitaoka 120a6e
     * これはプログレスバーを進めるものなので、動画番号ではなく、完了したフレームの枚数を投げる
Shinya Kitaoka 120a6e
     * --*/
Shinya Kitaoka 120a6e
    frameNotifier->notifyFrameCompleted(100 * (i + 1) / frames.size());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Campbell Barton ccd505
static void convertFromVector(const TLevelReaderP &lr, const TLevelWriterP &lw,
Campbell Barton ccd505
                              const std::vector<tframeid> &_frames,</tframeid>
Campbell Barton ccd505
                              FrameTaskNotifier *frameNotifier) {
Shinya Kitaoka 120a6e
  std::vector<tframeid> frames = _frames;</tframeid>
Shinya Kitaoka 120a6e
  TLevelP lv                   = lr->loadInfo();
Shinya Kitaoka 120a6e
  if (frames.empty() &&
Shinya Kitaoka 120a6e
      lv->getFrameCount() == 1)  // e' una immagine singola, non un livello
Shinya Kitaoka 120a6e
    frames.push_back(TFrameId());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)frames.size(); i++) {
Shinya Kitaoka 120a6e
    if (frameNotifier->abortTask()) break;
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TVectorImageP img;
Shinya Kitaoka 120a6e
      if (frames[i] == TFrameId())  // immagine singola, non livello
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        assert(frames.size() == 1);
Shinya Kitaoka 120a6e
        TImageP _img;
Shinya Kitaoka 120a6e
        if (!TImageReader::load(lr->getFilePath(), _img)) continue;
Shinya Kitaoka 120a6e
        img = _img;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        TImageReaderP ir = lr->getFrameReader(frames[i]);
Shinya Kitaoka 120a6e
        img              = ir->load();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      img->setPalette(lv->getPalette());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (frames[i] == TFrameId())
Shinya Kitaoka 120a6e
        TImageWriter::save(lw->getFilePath(), img);
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        TImageWriterP iw = lw->getFrameWriter(frames[i]);
Shinya Kitaoka 120a6e
        iw->save(img);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } catch (...) {
Shinya Kitaoka 120a6e
      // QString msg=QObject::tr("Frame %1 : conversion
Shinya Kitaoka 120a6e
      // failed!").arg(QString::number(i+1));
Shinya Kitaoka 120a6e
      // DVGui::info(msg);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    frameNotifier->notifyFrameCompleted(100 * (i + 1) / frames.size());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void convert(const TFilePath &source, const TFilePath &dest,
Shinya Kitaoka 120a6e
             const TFrameId &from, const TFrameId &to, double framerate,
Shinya Kitaoka 120a6e
             TPropertyGroup *prop, FrameTaskNotifier *frameNotifier,
shun-iwasawa fc0d80
             const TPixel &bgColor, bool removeDotBeforeFrameNumber,
shun-iwasawa fc0d80
             const TFrameId &tmplFId) {
Shinya Kitaoka 120a6e
  std::string dstExt = dest.getType(), srcExt = source.getType();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Load source level structure
Shinya Kitaoka 120a6e
  TLevelReaderP lr(source);
Shinya Kitaoka 120a6e
  TLevelP level = lr->loadInfo();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  if (dstExt == "avi") {
Shinya Kitaoka 120a6e
    TDimension res(0, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    const TImageInfo *info = lr->getImageInfo(level->begin()->first);
Shinya Kitaoka 120a6e
    res.lx                 = info->m_lx;
Shinya Kitaoka 120a6e
    res.ly                 = info->m_ly;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    std::string codecName = prop->getProperty(0)->getValueAsString();
Shinya Kitaoka 120a6e
    if (!AviCodecRestrictions::canWriteMovie(::to_wstring(codecName), res)) {
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 3bfa54
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Get the frames available in level inside the [from, to] range
Shinya Kitaoka 120a6e
  std::vector<tframeid> frames;</tframeid>
Shinya Kitaoka 120a6e
  getFrameIds(from, to, level, frames);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Write the destination level
Shinya Kitaoka 120a6e
  TLevelWriterP lw(dest, prop);
Shinya Kitaoka 120a6e
  lw->setFrameRate(framerate);
shun-iwasawa fc0d80
  lw->setFrameFormatTemplateFId(tmplFId);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (srcExt == "tlv")
Shinya Kitaoka 120a6e
    convertFromCM(lr, level->getPalette(), lw, frames, TAffine(),
Shinya Kitaoka 120a6e
                  TRop::Triangle, frameNotifier, bgColor,
Shinya Kitaoka 120a6e
                  removeDotBeforeFrameNumber);
Shinya Kitaoka 120a6e
  else if (srcExt == "pli")
luz paz 6454c4
    // assert(!"Conversion from pli files is currently disabled");
Shinya Kitaoka 120a6e
    convertFromVector(lr, lw, frames, frameNotifier);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    convertFromFullRaster(lr, lw, frames, TAffine(), TRop::Triangle,
Shinya Kitaoka 120a6e
                          frameNotifier, bgColor, removeDotBeforeFrameNumber);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void convertNaa2Tlv(const TFilePath &source, const TFilePath &dest,
Shinya Kitaoka 120a6e
                    const TFrameId &from, const TFrameId &to,
shun_iwasawa 1fa45a
                    FrameTaskNotifier *frameNotifier, TPalette *palette,
shun-iwasawa 1584bb
                    bool removeUnusedStyles, double dpi) {
Shinya Kitaoka 120a6e
  std::string dstExt = dest.getType(), srcExt = source.getType();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Load source level structure
Shinya Kitaoka 120a6e
  TLevelReaderP lr(source);
Shinya Kitaoka 120a6e
  TLevelP level = lr->loadInfo();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Get the frames available in level inside the [from, to] range
Shinya Kitaoka 120a6e
  std::vector<tframeid> frames;</tframeid>
Shinya Kitaoka 120a6e
  getFrameIds(from, to, level, frames);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (frames.empty()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Write the destination level
Shinya Kitaoka 120a6e
  TLevelWriterP lw;  // Initialized just before a sure write
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Naa2TlvConverter converter;
Shinya Kitaoka 120a6e
  converter.setPalette(palette);
Toshihiro Shimizu 890ddd
shun_iwasawa 22ad9e
  QList<int> usedStyleIds({0});</int>
shun_iwasawa 22ad9e
Shinya Kitaoka 120a6e
  int f, fCount = int(frames.size());
Shinya Kitaoka 120a6e
  for (f = 0; f != fCount; ++f) {
Shinya Kitaoka 120a6e
    if (frameNotifier->abortTask()) break;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    try {
Shinya Kitaoka 120a6e
      TImageReaderP ir = lr->getFrameReader(frames[f]);
Shinya Kitaoka 120a6e
      TImageP img      = ir->load();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (!img) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TRasterImageP ri = img;
Shinya Kitaoka 120a6e
      if (!ri) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TRaster32P raster =
Shinya Kitaoka 120a6e
          ri->getRaster();  // Converts only 32-bit images, it seems...
Shinya Kitaoka 120a6e
      if (!raster)          //
Shinya Kitaoka 120a6e
        continue;           //
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      converter.process(raster);
Toshihiro Shimizu 890ddd
shun-iwasawa 1584bb
      if (TToonzImageP dstImg = converter.makeTlv(
shun-iwasawa 1584bb
              false, usedStyleIds, dpi))  // Opaque synthetic inks
Shinya Kitaoka 120a6e
      {
Shinya Kitaoka 120a6e
        if (converter.getPalette() == 0)
Shinya Kitaoka 120a6e
          converter.setPalette(dstImg->getPalette());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        if (!lw)  // Initialize output file only on a sure write
Shinya Kitaoka 120a6e
          lw = TLevelWriterP(dest);  //
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        TImageWriterP iw = lw->getFrameWriter(frames[f]);
Shinya Kitaoka 120a6e
        iw->save(dstImg);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        DVGui::warning(QObject::tr(
Shinya Kitaoka 120a6e
            "The source image seems not suitable for this kind of conversion"));
Shinya Kitaoka 120a6e
        frameNotifier->notifyError();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } catch (...) {
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    frameNotifier->notifyFrameCompleted(100 * (f + 1) / frames.size());
Shinya Kitaoka 120a6e
  }
shun_iwasawa 22ad9e
shun_iwasawa 22ad9e
  if (removeUnusedStyles) converter.removeUnusedStyles(usedStyleIds);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
shun-iwasawa acfe75
void convertOldLevel2Tlv(const TFilePath &source, const TFilePath &dest,
shun-iwasawa acfe75
                         const TFrameId &from, const TFrameId &to,
shun-iwasawa acfe75
                         FrameTaskNotifier *frameNotifier) {
shun-iwasawa acfe75
  TFilePath destPltPath = TFilePath(dest.getParentDir().getWideString() +
shun-iwasawa acfe75
                                    L"\\" + dest.getWideName() + L".tpl");
shun-iwasawa acfe75
  if (TSystem::doesExistFileOrLevel(destPltPath))
shun-iwasawa acfe75
    TSystem::removeFileOrLevel(destPltPath);
shun-iwasawa acfe75
shun-iwasawa acfe75
  TLevelWriterP lw(dest);
shun-iwasawa acfe75
  lw->setIconSize(Preferences::instance()->getIconSize());
shun-iwasawa acfe75
  TPaletteP palette =
shun-iwasawa acfe75
      ToonzImageUtils::loadTzPalette(source.withType("plt").withNoFrame());
shun-iwasawa acfe75
  TLevelReaderP lr(source);
shun-iwasawa acfe75
  if (!lr) {
shun-iwasawa acfe75
    DVGui::warning(QObject::tr(
shun-iwasawa acfe75
        "The source image seems not suitable for this kind of conversion"));
shun-iwasawa acfe75
    frameNotifier->notifyError();
shun-iwasawa acfe75
    return;
shun-iwasawa acfe75
  }
shun-iwasawa acfe75
  TLevelP inLevel = lr->loadInfo();
shun-iwasawa acfe75
  if (!inLevel || inLevel->getFrameCount() == 0) {
shun-iwasawa acfe75
    DVGui::warning(QObject::tr(
shun-iwasawa acfe75
        "The source image seems not suitable for this kind of conversion"));
shun-iwasawa acfe75
    frameNotifier->notifyError();
shun-iwasawa acfe75
    return;
shun-iwasawa acfe75
  }
shun-iwasawa acfe75
  // Get the frames available in level inside the [from, to] range
shun-iwasawa acfe75
  std::vector<tframeid> frames;</tframeid>
shun-iwasawa acfe75
  getFrameIds(from, to, inLevel, frames);
shun-iwasawa acfe75
  if (frames.empty()) return;
shun-iwasawa acfe75
shun-iwasawa acfe75
  TLevelP outLevel;
shun-iwasawa acfe75
  outLevel->setPalette(palette.getPointer());
shun-iwasawa acfe75
  try {
shun-iwasawa acfe75
    int f, fCount = int(frames.size());
shun-iwasawa acfe75
    for (f = 0; f != fCount; ++f) {
shun-iwasawa acfe75
      if (frameNotifier->abortTask()) break;
shun-iwasawa acfe75
      TToonzImageP img = lr->getFrameReader(frames[f])->load();
shun-iwasawa acfe75
      if (!img) continue;
shun-iwasawa acfe75
      img->setPalette(palette.getPointer());
shun-iwasawa acfe75
      lw->getFrameWriter(frames[f])->save(img);
shun-iwasawa acfe75
shun-iwasawa acfe75
      frameNotifier->notifyFrameCompleted(100 * (f + 1) / frames.size());
shun-iwasawa acfe75
    }
shun-iwasawa acfe75
  } catch (TException &e) {
shun-iwasawa acfe75
    QString msg = QString::fromStdWString(e.getMessage());
shun-iwasawa acfe75
    DVGui::warning(msg);
shun-iwasawa acfe75
    lw = TLevelWriterP();
shun-iwasawa acfe75
    if (TSystem::doesExistFileOrLevel(dest)) TSystem::removeFileOrLevel(dest);
shun-iwasawa acfe75
    frameNotifier->notifyError();
shun-iwasawa acfe75
    return;
shun-iwasawa acfe75
  }
shun-iwasawa acfe75
  lw = TLevelWriterP();
shun-iwasawa acfe75
}
shun-iwasawa acfe75
shun-iwasawa acfe75
//=============================================================================
shun-iwasawa acfe75
Toshihiro Shimizu 890ddd
#define ZOOMLEVELS 13
Toshihiro Shimizu 890ddd
#define NOZOOMINDEX 6
Shinya Kitaoka 120a6e
double ZoomFactors[ZOOMLEVELS] = {
Shinya Kitaoka 120a6e
    0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
double getQuantizedZoomFactor(double zf, bool forward) {
Shinya Kitaoka 120a6e
  if (forward && (zf > ZoomFactors[ZOOMLEVELS - 1] ||
Shinya Kitaoka 120a6e
                  areAlmostEqual(zf, ZoomFactors[ZOOMLEVELS - 1], 1e-5)))
Shinya Kitaoka 120a6e
    return zf;
Shinya Kitaoka 120a6e
  else if (!forward &&
Shinya Kitaoka 120a6e
           (zf < ZoomFactors[0] || areAlmostEqual(zf, ZoomFactors[0], 1e-5)))
Shinya Kitaoka 120a6e
    return zf;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  assert((!forward && zf > ZoomFactors[0]) ||
Shinya Kitaoka 120a6e
         (forward && zf < ZoomFactors[ZOOMLEVELS - 1]));
Shinya Kitaoka 120a6e
  int i = 0;
Shinya Kitaoka 120a6e
  for (i = 0; i <= ZOOMLEVELS - 1; i++)
Shinya Kitaoka 120a6e
    if (areAlmostEqual(zf, ZoomFactors[i], 1e-5)) zf = ZoomFactors[i];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (forward && zf < ZoomFactors[0])
Shinya Kitaoka 120a6e
    return ZoomFactors[0];
Shinya Kitaoka 120a6e
  else if (!forward && zf > ZoomFactors[ZOOMLEVELS - 1])
Shinya Kitaoka 120a6e
    return ZoomFactors[ZOOMLEVELS - 1];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < ZOOMLEVELS - 1; i++)
Shinya Kitaoka 120a6e
    if (ZoomFactors[i + 1] - zf >= 0 && zf - ZoomFactors[i] >= 0) {
Shinya Kitaoka 120a6e
      if (forward && ZoomFactors[i + 1] == zf)
Shinya Kitaoka 120a6e
        return ZoomFactors[i + 2];
Shinya Kitaoka 120a6e
      else if (!forward && ZoomFactors[i] == zf)
Shinya Kitaoka 120a6e
        return ZoomFactors[i - 1];
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        return forward ? ZoomFactors[i + 1] : ZoomFactors[i];
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  return ZoomFactors[NOZOOMINDEX];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace ImageUtils
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
manongjohn 4f0f61
void getViewerShortcuts(int &zoomIn, int &zoomOut, int &viewReset, int &zoomFit,
Jeremy Bullock 628337
                        int &showHideFullScreen, int &actualPixelSize,
manongjohn 4f0f61
                        int &flipX, int &flipY, int &zoomReset,
manongjohn 4f0f61
                        int &rotateReset, int &positionReset) {
Shinya Kitaoka 120a6e
  CommandManager *cManager = CommandManager::instance();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  zoomIn = cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomIn));
Shinya Kitaoka 120a6e
  zoomOut =
Shinya Kitaoka 120a6e
      cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomOut));
manongjohn 4f0f61
  viewReset =
manongjohn 4f0f61
      cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ViewReset));
Shinya Kitaoka 120a6e
  zoomFit =
Shinya Kitaoka 120a6e
      cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomFit));
Shinya Kitaoka 120a6e
  showHideFullScreen = cManager->getKeyFromShortcut(
Shinya Kitaoka 120a6e
      cManager->getShortcutFromId(V_ShowHideFullScreen));
Shinya Kitaoka 120a6e
  actualPixelSize = cManager->getKeyFromShortcut(
Shinya Kitaoka 120a6e
      cManager->getShortcutFromId(V_ActualPixelSize));
Jeremy Bullock 628337
  flipX = cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_FlipX));
Jeremy Bullock 628337
  flipY = cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_FlipY));
manongjohn 4f0f61
  zoomReset =
manongjohn 4f0f61
      cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_ZoomReset));
manongjohn 4f0f61
  rotateReset =
manongjohn 4f0f61
      cManager->getKeyFromShortcut(cManager->getShortcutFromId(V_RotateReset));
manongjohn 4f0f61
  positionReset = cManager->getKeyFromShortcut(
manongjohn 4f0f61
      cManager->getShortcutFromId(V_PositionReset));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace ImageUtils {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
ShortcutZoomer::ShortcutZoomer(QWidget *zoomingWidget)
Shinya Kitaoka 120a6e
    : m_widget(zoomingWidget) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ShortcutZoomer::exec(QKeyEvent *event) {
manongjohn 4f0f61
  int zoomInKey, zoomOutKey, viewResetKey, zoomFitKey, showHideFullScreenKey,
manongjohn 4f0f61
      actualPixelSize, flipX, flipY, zoomReset, rotateReset, positionReset;
manongjohn 4f0f61
  getViewerShortcuts(zoomInKey, zoomOutKey, viewResetKey, zoomFitKey,
manongjohn 4f0f61
                     showHideFullScreenKey, actualPixelSize, flipX, flipY,
manongjohn 4f0f61
                     zoomReset, rotateReset, positionReset);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int key = event->key();
Shinya Kitaoka 120a6e
  if (key == Qt::Key_Control || key == Qt::Key_Shift || key == Qt::Key_Alt)
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
shun-iwasawa c88070
  key = key | event->modifiers() &
shun-iwasawa c88070
                  (~0xf0000000);  // Ignore if the key is a numpad key
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return (key == showHideFullScreenKey)
Shinya Kitaoka 120a6e
             ? toggleFullScreen()
Shinya Kitaoka 120a6e
             : (key == Qt::Key_Escape)
Shinya Kitaoka 120a6e
                   ? toggleFullScreen(true)
Shinya Kitaoka 120a6e
                   : (key == actualPixelSize)
Shinya Kitaoka 120a6e
                         ? setActualPixelSize()
Shinya Kitaoka 120a6e
                         : (key == zoomFitKey)
Shinya Kitaoka 120a6e
                               ? fit()
Shinya Kitaoka 120a6e
                               : (key == zoomInKey || key == zoomOutKey ||
manongjohn 4f0f61
                                  key == viewResetKey)
Shinya Kitaoka 120a6e
                                     ? zoom(key == zoomInKey,
manongjohn 4f0f61
                                            key == viewResetKey)
Jeremy Bullock 628337
                                     : (key == flipX)
Jeremy Bullock 628337
                                           ? setFlipX()
manongjohn 4f0f61
                                           : (key == flipY)
manongjohn 4f0f61
                                                 ? setFlipY()
manongjohn 4f0f61
                                                 : (key == zoomReset)
manongjohn 4f0f61
                                                       ? resetZoom()
manongjohn 4f0f61
                                                       : (key == rotateReset)
manongjohn 4f0f61
                                                             ? resetRotation()
manongjohn 4f0f61
                                                             : (key ==
manongjohn 4f0f61
                                                                positionReset)
manongjohn 4f0f61
                                                                   ? resetPosition()
manongjohn 4f0f61
                                                                   : false;
manongjohn 4f0f61
  ;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*********************************************************************************************
Toshihiro Shimizu 890ddd
//    FullScreenWidget  implementation
Toshihiro Shimizu 890ddd
//*********************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FullScreenWidget::FullScreenWidget(QWidget *parent) : QWidget(parent) {
Shinya Kitaoka 120a6e
  QHBoxLayout *layout = new QHBoxLayout(this);
Shinya Kitaoka 120a6e
  layout->setMargin(0);
Shinya Kitaoka 120a6e
  layout->setSpacing(0);
Toshihiro Shimizu 890ddd
justburner 521a74
  // Attach see-through window signal so this can detect opacity changes
justburner 521a74
  connect(SeeThroughWindowMode::instance(), SIGNAL(opacityChanged(int, bool &)),
justburner 521a74
          this, SLOT(opacityChanged(int, bool &)));
justburner 521a74
Shinya Kitaoka 120a6e
  setLayout(layout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FullScreenWidget::setWidget(QWidget *widget) {
Shinya Kitaoka 120a6e
  QLayout *layout = this->layout();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  delete layout->takeAt(0);
Shinya Kitaoka 120a6e
  if ((m_widget = widget)) layout->addWidget(m_widget);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
7d50d1
//=============================================================
shun-iwasawa d76dfe
bool FullScreenWidget::toggleFullScreen(
shun-iwasawa d76dfe
    //=============================================================
Toshihiro Shimizu 890ddd
shun-iwasawa d76dfe
    const bool kfApplicationQuitInProgress)  // Indicates whether the
luz paz 6454c4
                                             // application is quitting.
f6ea6c
f6ea6c
/*
shun-iwasawa d76dfe
 *  DESCRIPTION:
shun-iwasawa d76dfe
 *
shun-iwasawa d76dfe
 * Sets the size and location of the widget to either full screen or normal.
f6ea6c
 *
shun-iwasawa d76dfe
 * Entering full screen has to be done manually in order to avoid having the
shun-iwasawa d76dfe
 * window placed on the wrong monitor on systems running X11 with multiple
shun-iwasawa d76dfe
 * monitors.
f6ea6c
 */
f6ea6c
{
shun-iwasawa d76dfe
  // Initialize the return value.
shun-iwasawa d76dfe
  bool fFullScreenStateToggled = false;
shun-iwasawa d76dfe
shun-iwasawa d76dfe
  // Define some constants for setting and clearing window flags.
shun-iwasawa d76dfe
  const Qt::WindowFlags kwfFullScreenWidgetFlags =
shun-iwasawa 25b046
      Qt::Window |              // <-- Make the widget become a window.
shun-iwasawa 25b046
      Qt::FramelessWindowHint;  // <-- Full screen windows have no border.
shun-iwasawa d76dfe
shun-iwasawa d76dfe
  const Qt::WindowFlags kwfFullScreenWidgetExcludedFlagsMask =
shun-iwasawa d76dfe
      (Qt::WindowFlags)~Qt::WindowTitleHint;  // <-- Full screen windows have no
shun-iwasawa d76dfe
                                              // titlebar.
shun-iwasawa d76dfe
shun-iwasawa d76dfe
  // Determine whether to enter or leave full screen mode
shun-iwasawa d76dfe
  if (this->windowState() & Qt::WindowFullScreen) {
shun-iwasawa d76dfe
    this->hide();
shun-iwasawa d76dfe
shun-iwasawa d76dfe
    this->setWindowFlags(this->windowFlags() & ~kwfFullScreenWidgetFlags);
shun-iwasawa d76dfe
shun-iwasawa d76dfe
    this->showNormal();
shun-iwasawa d76dfe
shun-iwasawa d76dfe
    this->m_widget->setFocus();
shun-iwasawa d76dfe
shun-iwasawa d76dfe
    // Set the return value to indicate that the full screen mode has been
shun-iwasawa d76dfe
    // changed.
shun-iwasawa d76dfe
    fFullScreenStateToggled = true;
justburner 521a74
justburner 521a74
    // Refresh see-through window opacity
justburner 521a74
    SeeThroughWindowMode::instance()->refreshOpacity();
shun-iwasawa d76dfe
  } else {
shun-iwasawa d76dfe
    // There's no point to switching into full screen if the
luz paz 6454c4
    // application is in the process of quitting.
shun-iwasawa d76dfe
    if (!kfApplicationQuitInProgress) {
shun-iwasawa d76dfe
      //==============================================================
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //  NOTE:
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //    This new way of going into full screen mode does things manually in
shun-iwasawa d76dfe
      //    order to bypass Qt's incorrect policy of always relocating a widget
shun-iwasawa d76dfe
      //    to desktop coordinates (0,0) when the widget becomes a window via
shun-iwasawa d76dfe
      //    setting the Qt::Window flag.
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //    This makes full screen mode work MUCH better on X11 systems with
shun-iwasawa d76dfe
      //    multiple displays.
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //==============================================================
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //  STRATEGY:
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //    1.    Obtain the rectangle of the screen that the widgets host
shun-iwasawa d76dfe
      //    window is on. This has to be done first, otherwise the CORRECT
shun-iwasawa d76dfe
      //    screen info can potentially become unavailable in the following
shun-iwasawa d76dfe
      //    steps.
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //    2.    Manually set all the necessary flags for the full screen
shun-iwasawa d76dfe
      //    window attributes and state. Qt WILL hide the widget/window when
shun-iwasawa d76dfe
      //    this is done.
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //    3.    Set the window geometry/rect to be the same as the screen from
shun-iwasawa d76dfe
      //    Step 1.
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //    4.    Make the window visible again.
shun-iwasawa d76dfe
      //
shun-iwasawa d76dfe
      //---------------------------------------------------
shun-iwasawa d76dfe
      // STEP 1:
shun-iwasawa d76dfe
shun-iwasawa d76dfe
      // Get the window widget that contains this widget.
shun-iwasawa d76dfe
      QWidget *ptrWindowWidget = this->window();
shun-iwasawa d76dfe
      if (ptrWindowWidget) {
shun-iwasawa d76dfe
        // Get the access to the QWindow object of the containing window.
shun-iwasawa d76dfe
        QWindow *ptrContainingQWindow = ptrWindowWidget->windowHandle();
shun-iwasawa d76dfe
        if (ptrContainingQWindow) {
shun-iwasawa d76dfe
          // Get access to the screen the window is on.
shun-iwasawa d76dfe
          QScreen *ptrScreenThisWindowIsOn = ptrContainingQWindow->screen();
shun-iwasawa d76dfe
          if (ptrScreenThisWindowIsOn) {
shun-iwasawa d76dfe
#if !defined(_WIN32)
shun-iwasawa d76dfe
            // Get the geometry rect for the correct screen.
shun-iwasawa d76dfe
            QRect qrcScreen = ptrScreenThisWindowIsOn->geometry();
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            //---------------------------------------------------
shun-iwasawa d76dfe
            // STEP 2:
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            // Set the window flags to be frameless and with no titlebar.
shun-iwasawa d76dfe
            //
shun-iwasawa d76dfe
            // This call will turn the widget into a "window", and HIDE it. This
shun-iwasawa d76dfe
            // is because Qt always hides a widget when it transforms a widget
shun-iwasawa d76dfe
            //  into a window, or turns a window into a widget.
shun-iwasawa d76dfe
            //
shun-iwasawa d76dfe
            this->setWindowFlags(
shun-iwasawa d76dfe
                (this->windowFlags() & kwfFullScreenWidgetExcludedFlagsMask) |
shun-iwasawa d76dfe
                kwfFullScreenWidgetFlags);
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            // Set the window state flag to indicate that it's now in fullscreen
shun-iwasawa d76dfe
            // mode.
shun-iwasawa d76dfe
            // If this state flag isn't set, the test for whether to enter or
shun-iwasawa d76dfe
            // leave full screen mode won't work correctly.
shun-iwasawa d76dfe
            this->setWindowState(Qt::WindowFullScreen);
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            //---------------------------------------------------
shun-iwasawa d76dfe
            // STEP 3:
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            // Set the window to the geometry rect of the correct screen.
shun-iwasawa d76dfe
            this->setGeometry(qrcScreen);
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            //---------------------------------------------------
shun-iwasawa d76dfe
            // STEP 4:
shun-iwasawa d76dfe
shun-iwasawa d76dfe
            // Make the window visible. This also causes all the changes to the
shun-iwasawa d76dfe
            // widget's flags, state and geometry that was just set to take
shun-iwasawa d76dfe
            // effect.
shun-iwasawa d76dfe
            this->show();
94e290
#else
shun-iwasawa 25b046
            this->setWindowFlags(this->windowFlags() | Qt::Window);
shun-iwasawa d76dfe
            this->window()->windowHandle()->setScreen(ptrScreenThisWindowIsOn);
94e290
shun-iwasawa d76dfe
            // http://doc.qt.io/qt-5/windows-issues.html#fullscreen-opengl-based-windows
Rodney 8ec0c6
            this->winId();
shun-iwasawa d76dfe
            QWindowsWindowFunctions::setHasBorderInFullScreen(
shun-iwasawa d76dfe
                this->windowHandle(), true);
94e290
shun-iwasawa d76dfe
            this->showFullScreen();
94e290
#endif
shun-iwasawa d76dfe
          }
shun-iwasawa d76dfe
        }
shun-iwasawa d76dfe
      }
shun-iwasawa d76dfe
shun-iwasawa d76dfe
      // Set the return value to indicate that the full screen mode has been
shun-iwasawa d76dfe
      // changed.
shun-iwasawa d76dfe
      fFullScreenStateToggled = true;
justburner 521a74
justburner 521a74
      // Refresh see-through window opacity
justburner 521a74
      SeeThroughWindowMode::instance()->refreshOpacity();
shun-iwasawa d76dfe
    }
shun-iwasawa d76dfe
  }
shun-iwasawa d76dfe
shun-iwasawa d76dfe
  return (fFullScreenStateToggled);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
justburner 521a74
void FullScreenWidget::opacityChanged(int value, bool &hideMain) {
justburner 521a74
  this->setWindowOpacity((double)value / 100);
justburner 521a74
  if (this->windowState() & Qt::WindowFullScreen) hideMain = true;
justburner 521a74
}
justburner 521a74
shun-iwasawa c88070
}  // namespace ImageUtils