void FormatSettingsPopup::showEvent(QShowEvent *se)
{
#ifdef WIN32
	if (m_format == "avi") {
		assert(m_codecComboBox);
		m_codecComboBox->blockSignals(true);
		m_codecComboBox->clear();
		ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
		TEnumProperty *eProps = dynamic_cast<TEnumProperty *>(m_props->getProperty(0));
		assert(eProps);

		TDimension res(0, 0);
		if (m_levelPath.isEmpty())
			res = scene->getCurrentCamera()->getRes();
		else {
			TLevelReaderP lr(m_levelPath);
			TLevelP level = lr->loadInfo();
			const TImageInfo *info = lr->getImageInfo(level->begin()->first);
			res.lx = info->m_lx;
			res.ly = info->m_ly;
		}

		TEnumProperty::Range range = eProps->getRange();
		int currIndex = -1;
		wstring defaultVal = eProps->getValue();

		QMap<wstring, bool> usableCodecs = AviCodecRestrictions::getUsableCodecs(res);
		for (int i = 0; i < (int)range.size(); i++) {
			wstring nameProp = range[i];
			if (nameProp == L"Uncompressed" || (usableCodecs.contains(nameProp) && usableCodecs[nameProp])) {
				if (nameProp == defaultVal)
					currIndex = m_codecComboBox->count();
				m_codecComboBox->addItem(QString::fromStdWString(nameProp));
			}
		}
		m_codecComboBox->blockSignals(false);
		if (currIndex >= 0)
			m_codecComboBox->setCurrentIndex(currIndex);
	}

#endif

	Dialog::showEvent(se);
}
void FormatSettingsPopup::buildPropertyComboBox(int index,
                                                TPropertyGroup *props) {
  TEnumProperty *prop = (TEnumProperty *)(props->getProperty(index));

  assert(prop);

  DVGui::PropertyComboBox *comboBox = new DVGui::PropertyComboBox(this, prop);
  m_widgets[prop->getName()]        = comboBox;

#ifdef _WIN32
  connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this,
          SLOT(onComboBoxIndexChanged(const QString &)));
#endif
  TEnumProperty::Range range = prop->getRange();
  TEnumProperty::Items items = prop->getItems();
  int currIndex              = -1;
  std::wstring defaultVal    = prop->getValue();

  for (int i = 0; i < (int)range.size(); i++) {
    std::wstring nameProp = range[i];

    if (nameProp.find(L"16(GREYTONES)") !=
        -1)  // pezza per il tif: il 16 lo scrive male, e il 48 lo legge male...
      continue;
    /* if (nameProp.find(L"ThunderScan")!=-1) //pezza epr il tif, molte
compressioni non vanno..scive male il file
break;*/

    if (nameProp == defaultVal) currIndex = comboBox->count();
    comboBox->addItem(items[i].UIName, QString::fromStdWString(nameProp));
  }
  if (currIndex >= 0) comboBox->setCurrentIndex(currIndex);

  int row = m_mainLayout->rowCount();
  m_mainLayout->addWidget(new QLabel(prop->getQStringName() + ":", this), row,
                          0, Qt::AlignRight | Qt::AlignVCenter);
  m_mainLayout->addWidget(comboBox, row, 1);

#ifdef _WIN32
  if (m_format == "avi") m_codecComboBox = comboBox;
#endif
}
Beispiel #3
0
void TImageWriter::save(const TImageP &img)
{
	const std::string &type = toLower(m_path.getType());

	Tiio::Writer *writer = Tiio::makeWriter(type);
	if (!writer)
		throw TImageException(m_path, "unsupported format for raster images");

	writer->setProperties(m_properties);

	FILE *file = fopen(m_path, "wb");
	if (file == NULL)
		throw TImageException(m_path, "Can't write file");

	if (TRasterImageP ri = img) {
		TImageInfo info;
		TRasterP ras;

		TRasterGR8P rasGr = ri->getRaster();
		TRaster32P ras32 = ri->getRaster();
		TRaster64P ras64 = ri->getRaster();

		TEnumProperty *p = m_properties ? (TEnumProperty *)m_properties->getProperty("Bits Per Pixel")
										: 0;

		if (p && ri->isScanBW()) {
			const std::vector<std::wstring> &range = p->getRange();
			p->setValue(range[2]); // Horrible. See tiio_tif.cpp (732 or near)     -.-'
		}

		int bpp = p ? atoi((toString(p->getValue()).c_str())) : 32;

		//  bpp       1  8  16 24 32 40  48 56  64
		int spp[] = {1, 1, 1, 4, 4, 0, 4, 0, 4};	// 0s are for pixel sizes which are normally unsupported
		int bps[] = {1, 8, 16, 8, 8, 0, 16, 0, 16}; // by image formats, let alone by Toonz raster ones.
													// The 24 and 48 cases get automatically promoted to 32 and 64.
		int bypp = bpp / 8;
		assert(bypp < boost::size(spp) && spp[bypp] && bps[bypp]);

		info.m_samplePerPixel = spp[bypp];
		info.m_bitsPerSample = bps[bypp];

		if (rasGr) {
			if (bypp < 2)	// Seems 16 bit greymaps are not handled... why?
				ras = rasGr; // we do have a Toonz raster for those...    >:|
			else
				convertForWriting(ras, rasGr, bpp);
		} else if (ras32) {
			if (bpp == 32 || bpp == 24)
				ras = ras32;
			else
				convertForWriting(ras, ras32, bpp);
		} else if (ras64) {
			if (bpp == 64 || bpp == 48)
				ras = ras64;
			else
				convertForWriting(ras, ras64, bpp);
		} else {
			fclose(file);
			throw TImageException(m_path, "unsupported raster type");
		}

		info.m_lx = ras->getLx();
		info.m_ly = ras->getLy();

		ri->getDpi(info.m_dpix, info.m_dpiy);

		if (writer->getProperties() && m_properties)
			writer->getProperties()->setProperties(m_properties);

		writer->open(file, info);

		ras->lock();
		if (writer->getRowOrder() == Tiio::BOTTOM2TOP) {
			if (bpp == 1 || bpp == 8 || bpp == 24 || bpp == 32 || bpp == 16)
				for (int i = 0; i < ras->getLy(); i++)
					writer->writeLine((char *)ras->getRawData(0, i));
			else
				for (int i = 0; i < ras->getLy(); i++)
					writer->writeLine((short *)ras->getRawData(0, i));
		} else {
			if (bpp == 1 || bpp == 8 || bpp == 24 || bpp == 32 || bpp == 16)
				for (int i = ras->getLy() - 1; i >= 0; i--)
					writer->writeLine((char *)ras->getRawData(0, i));
			else
				for (int i = ras->getLy() - 1; i >= 0; i--)
					writer->writeLine((short *)ras->getRawData(0, i));
		}

		ras->unlock();

		writer->flush();
		delete writer;
	} else if (TVectorImageP vi = img) {
		Tiio::VectorWriter *writer = Tiio::makeVectorWriter(type);
		if (!writer) {
			fclose(file);
			throw TImageException(m_path, "unsupported format for vector images");
		}

		writer->open(file);
		writer->write(vi.getPointer());

		delete writer;
	} else {
		fclose(file);
		throw TImageException(m_path, "Can't write file");
	}

	fclose(file);
}