コード例 #1
0
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);
}
コード例 #2
0
void FormatSettingsPopup::buildPropertyComboBox(int index, TPropertyGroup *props)
{
	TEnumProperty *prop = (TEnumProperty *)(props->getProperty(index));
	assert(prop);

	PropertyComboBox *comboBox = new PropertyComboBox(this, prop);
	m_widgets[prop->getName()] = comboBox;
	connect(comboBox, SIGNAL(currentIndexChanged(const QString)), this, SLOT(onComboBoxIndexChanged(const QString)));
	TEnumProperty::Range range = prop->getRange();
	int currIndex = -1;
	wstring defaultVal = prop->getValue();

	for (int i = 0; i < (int)range.size(); i++) {
		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(QString::fromStdWString(nameProp));
	}
	if (currIndex >= 0)
		comboBox->setCurrentIndex(currIndex);

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

#ifdef WIN32
	if (m_format == "avi")
		m_codecComboBox = comboBox;
#endif;
}
コード例 #3
0
ファイル: timage_io.cpp プロジェクト: PsmithG/opentoonz
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);
}
コード例 #4
0
ファイル: tiio_tif.cpp プロジェクト: titer1/opentoonz
void TifWriter::open(FILE *file, const TImageInfo &info)
{
	m_info = info;
	std::string mode = "w";

	if (!m_properties)
		m_properties = new Tiio::TifWriterProperties();

	std::wstring byteOrdering = ((TEnumProperty *)(m_properties->getProperty("Byte Ordering")))->getValue();
	if (byteOrdering == L"IBM PC")
		mode += "l";
	else
		mode += "b";

	TEnumProperty *p = (TEnumProperty *)(m_properties->getProperty("Bits Per Pixel"));
	assert(p);
	std::string str = ::to_string(p->getValue());
	m_bpp = atoi(str.c_str());
	assert(m_bpp == 1 || m_bpp == 8 || m_bpp == 16 || m_bpp == 24 || m_bpp == 32 || m_bpp == 48 || m_bpp == 64);

	int fd = fileno(file);
#if 0
	m_tiff = TIFFFdOpenNoCloseProc(fd, "", mode.c_str());
#else
	m_tiff = TIFFFdOpen(dup(fd), "", mode.c_str());
#endif
	if (!m_tiff)
		return;

	std::wstring worientation = ((TEnumProperty *)(m_properties->getProperty("Orientation")))->getValue();

	int orientation;
	if (worientation == TNZ_INFO_ORIENT_TOPLEFT)
		orientation = ORIENTATION_TOPLEFT;
	else if (worientation == TNZ_INFO_ORIENT_TOPRIGHT)
		orientation = ORIENTATION_TOPRIGHT;
	else if (worientation == TNZ_INFO_ORIENT_BOTRIGHT)
		orientation = ORIENTATION_BOTRIGHT;
	else if (worientation == TNZ_INFO_ORIENT_BOTLEFT)
		orientation = ORIENTATION_BOTLEFT;
	else if (worientation == TNZ_INFO_ORIENT_LEFTTOP)
		orientation = ORIENTATION_LEFTTOP;
	else if (worientation == TNZ_INFO_ORIENT_RIGHTTOP)
		orientation = ORIENTATION_RIGHTTOP;
	else if (worientation == TNZ_INFO_ORIENT_RIGHTBOT)
		orientation = ORIENTATION_RIGHTBOT;
	else if (worientation == TNZ_INFO_ORIENT_LEFTBOT)
		orientation = ORIENTATION_LEFTBOT;
	else
		assert(0);

	switch (orientation) {
	case ORIENTATION_TOPLEFT: /* row 0 top, col 0 lhs */
		m_rowOrder = Tiio::TOP2BOTTOM;
		break;
	case ORIENTATION_TOPRIGHT: /* row 0 top, col 0 rhs */
		m_rowOrder = Tiio::TOP2BOTTOM;
		break;
	case ORIENTATION_LEFTTOP: /* row 0 lhs, col 0 top */
		m_rowOrder = Tiio::TOP2BOTTOM;
		break;
	case ORIENTATION_RIGHTTOP: /* row 0 rhs, col 0 top */
		m_rowOrder = Tiio::TOP2BOTTOM;
		break;

	case ORIENTATION_BOTRIGHT: /* row 0 bottom, col 0 rhs */
		m_rowOrder = Tiio::BOTTOM2TOP;
		break;
	case ORIENTATION_BOTLEFT: /* row 0 bottom, col 0 lhs */
		m_rowOrder = Tiio::BOTTOM2TOP;
		break;
	case ORIENTATION_RIGHTBOT: /* row 0 rhs, col 0 bottom */
		m_rowOrder = Tiio::BOTTOM2TOP;
		break;
	case ORIENTATION_LEFTBOT: /* row 0 lhs, col 0 bottom */
		m_rowOrder = Tiio::BOTTOM2TOP;
		break;
	default:
		m_rowOrder = Tiio::TOP2BOTTOM;
		break;
	}
	m_RightToLeft = false;
	if (orientation == ORIENTATION_TOPRIGHT || orientation == ORIENTATION_BOTRIGHT ||
		orientation == ORIENTATION_RIGHTTOP || orientation == ORIENTATION_RIGHTBOT)
		m_RightToLeft = true;

	int bitsPerSample = (m_bpp == 1) ? 1 : ((m_bpp == 8 || m_bpp == 24 || m_bpp == 32) ? 8 : 16);

	TIFFSetField(m_tiff, TIFFTAG_IMAGEWIDTH, m_info.m_lx);
	TIFFSetField(m_tiff, TIFFTAG_IMAGELENGTH, m_info.m_ly);
	TIFFSetField(m_tiff, TIFFTAG_BITSPERSAMPLE, bitsPerSample);
	TIFFSetField(m_tiff, TIFFTAG_SAMPLESPERPIXEL, m_bpp / bitsPerSample);
	TIFFSetField(m_tiff, TIFFTAG_ORIENTATION, orientation);

	if (m_bpp == 1)
		TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
	else {
		std::wstring compressionType = ((TEnumProperty *)(m_properties->getProperty("Compression Type")))->getValue();
		if (compressionType == TNZ_INFO_COMPRESS_LZW)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
		else if (compressionType == TNZ_INFO_COMPRESS_PACKBITS)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
		else if (compressionType == TNZ_INFO_COMPRESS_CCITTFAX3)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX3);
		else if (compressionType == TNZ_INFO_COMPRESS_CCITTFAX4)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
		else if (compressionType == TNZ_INFO_COMPRESS_CCITTRLE)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_CCITTRLE);
		else if (compressionType == TNZ_INFO_COMPRESS_JPEG)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
		else if (compressionType == TNZ_INFO_COMPRESS_OJPEG)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_OJPEG);
		else if (compressionType == TNZ_INFO_COMPRESS_NONE)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
		else if (compressionType == TNZ_INFO_COMPRESS_THUNDERSCAN)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_THUNDERSCAN);
		else if (compressionType == TNZ_INFO_COMPRESS_ADOBE_DEFLATE)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_ADOBE_DEFLATE);
		else if (compressionType == TNZ_INFO_COMPRESS_DEFLATE)
			TIFFSetField(m_tiff, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
		else
			assert(false);
	}
	TIFFSetField(m_tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
	TIFFSetField(m_tiff, TIFFTAG_PHOTOMETRIC, (m_bpp == 8 || m_bpp == 1) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB);
	TIFFSetField(m_tiff, TIFFTAG_XRESOLUTION, m_info.m_dpix);
	TIFFSetField(m_tiff, TIFFTAG_YRESOLUTION, m_info.m_dpiy);
	TIFFSetField(m_tiff, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
	TIFFSetField(m_tiff, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(m_tiff, 0));

	m_row = 0;
	if (m_bpp == 1)
		m_lineBuffer = new unsigned char[m_info.m_lx / 8 + 1];
	else
		m_lineBuffer = new unsigned char[(m_bpp == 1 ? 1 : m_bpp / 8) * m_info.m_lx];
}