Exemplo n.º 1
0
status CAFFile::writeDescription()
{
	Track *track = getTrack();

	Tag desc("desc");
	int64_t chunkLength = 32;
	double sampleRate = track->f.sampleRate;
	Tag formatID("lpcm");
	uint32_t formatFlags = 0;
	if (track->f.byteOrder == AF_BYTEORDER_LITTLEENDIAN)
		formatFlags |= kCAFLinearPCMFormatFlagIsLittleEndian;
	if (track->f.isFloat())
		formatFlags |= kCAFLinearPCMFormatFlagIsFloat;
	uint32_t bytesPerPacket = track->f.bytesPerFrame(false);
	uint32_t framesPerPacket = 1;
	uint32_t channelsPerFrame = track->f.channelCount;
	uint32_t bitsPerChannel = track->f.sampleWidth;

	if (track->f.compressionType == AF_COMPRESSION_G711_ULAW)
	{
		formatID = "ulaw";
		formatFlags = 0;
		bytesPerPacket = channelsPerFrame;
		bitsPerChannel = 8;
	}
	else if (track->f.compressionType == AF_COMPRESSION_G711_ALAW)
	{
		formatID = "alaw";
		formatFlags = 0;
		bytesPerPacket = channelsPerFrame;
		bitsPerChannel = 8;
	}
	else if (track->f.compressionType == AF_COMPRESSION_IMA)
	{
		formatID = "ima4";
		formatFlags = 0;
		bytesPerPacket = track->f.bytesPerPacket;
		framesPerPacket = track->f.framesPerPacket;
		bitsPerChannel = 16;
	}

	if (!writeTag(&desc) ||
		!writeS64(&chunkLength) ||
		!writeDouble(&sampleRate) ||
		!writeTag(&formatID) ||
		!writeU32(&formatFlags) ||
		!writeU32(&bytesPerPacket) ||
		!writeU32(&framesPerPacket) ||
		!writeU32(&channelsPerFrame) ||
		!writeU32(&bitsPerChannel))
		return AF_FAIL;
	return AF_SUCCEED;
}
Exemplo n.º 2
0
void
TagDialog::saveTags()
{
    if( !m_perTrack )
    {
        applyToAllTracks();
    }
    else
    {
        storeTags();
    }

    QMap<QString, MetaBundle>::ConstIterator endStore( storedTags.end() );
    for(QMap<QString, MetaBundle>::ConstIterator it = storedTags.begin(); it != endStore; ++it ) {
        if( writeTag( it.data(), it == --storedTags.end() ) )    //update the collection browser if it's the last track
            Playlist::instance()->updateMetaData( it.data() );
        else
            amaroK::StatusBar::instance()->longMessage( i18n(
                        "Sorry, the tag for %1 could not be changed." ).arg( it.data().prettyURL() ), KDE::StatusBar::Error );
    }
    QMap<QString, int>::ConstIterator endScore( storedScores.end() );
    for(QMap<QString, int>::ConstIterator it = storedScores.begin(); it != endScore; ++it ) {
        CollectionDB::instance()->setSongPercentage( it.key(), it.data() );
    }
    QMap<QString, int>::ConstIterator endRating( storedRatings.end() );
    for(QMap<QString, int>::ConstIterator it = storedRatings.begin(); it != endRating; ++it ) {
        CollectionDB::instance()->setSongRating( it.key(), it.data() );
    }
    QMap<QString, QString>::ConstIterator endLyrics( storedLyrics.end() );
    for(QMap<QString, QString>::ConstIterator it = storedLyrics.begin(); it != endLyrics; ++it ) {
        CollectionDB::instance()->setLyrics( it.key(), it.data() );
        emit lyricsChanged( it.key() );
    }
}
Exemplo n.º 3
0
 FatalLogger::FatalLogger(SeverityType theSeverity,
     const char* theSourceFile, int theSourceLine, int theExitCode) :
   StringLogger(false, theExitCode)
 {
   // Create a tag for this fatal log message in our string stream
   writeTag(getStream(), theSeverity, theSourceFile, theSourceLine);
 }
Exemplo n.º 4
0
void FileLogger::logMessage(SeverityType severity, const char* sourceFile, int sourceLine, const char* message)
{
    if(mFileStream.is_open())
    {
        writeTag(mFileStream, severity, sourceFile, sourceLine);
        mFileStream << message << std::endl << std::endl;
    }
}
Exemplo n.º 5
0
void FileLogger::logMessage(SeverityType severity, const char* message)
{
    if(mFileStream.is_open())
    {
        writeTag(mFileStream, severity, __FILE__ , __LINE__);
        mFileStream << message << std::endl << std::endl;
    }
}
Exemplo n.º 6
0
/**
 * @brief Write the user data to the tag
 *
 * @param data Array of 16 bytes of user data
 * @returns True if commands could be sent to device
 */
bool RWDH2::writeTagUserData(uint8_t* data) {
  for (uint8_t i = 0; i < 4; i++) {
    if (!writeTag(4+i, &data[i*4])) {
      return false;
    }
  }
  return true;
}
Exemplo n.º 7
0
	void FileLogger::logMessage( SeverityType severity, const std::string& sourceFile, int theSourceLine, const std::string& message )
	{
		if(mFileStream.is_open() && isActive())
		{
			writeTag(mFileStream, severity, sourceFile, theSourceLine);
			mFileStream << message << std::endl;
		}
	}
Exemplo n.º 8
0
	void StringLogger::logMessage( SeverityType theSeverity, const std::string& sourceFile, int sourceLine, const std::string& message )
	{
		if(isActive())
		{
			writeTag(mStringStream, theSeverity, sourceFile, sourceLine);
			mStringStream << message << std::endl;
		}
	}
Exemplo n.º 9
0
	void appendTags( QXmlStreamWriter &stream, const Billon &billon )
	{
		stream.writeStartElement("tags");
		writeTag(stream,"width",QString::number(billon.n_cols));
		writeTag(stream,"height",QString::number(billon.n_rows));
		writeTag(stream,"depth",QString::number(billon.n_slices));
		writeTag(stream,"xspacing",QString::number(billon.voxelWidth()));
		writeTag(stream,"yspacing",QString::number(billon.voxelHeight()));
		writeTag(stream,"zspacing",QString::number(billon.voxelDepth()));
		writeTag(stream,"voxelwidth",QString::number(billon.voxelWidth()));
		writeTag(stream,"voxelheight",QString::number(billon.voxelHeight()));
		writeTag(stream,"voxeldepth",QString::number(billon.voxelDepth()));
		stream.writeEndElement();
	}
Exemplo n.º 10
0
void MyMoneyStorageXML::writeTags(QDomElement& tags)
{
  const QList<MyMoneyTag> list = m_storage->tagList();
  QList<MyMoneyTag>::ConstIterator it;
  tags.setAttribute("count", list.count());

  for (it = list.begin(); it != list.end(); ++it)
    writeTag(tags, *it);
}
Exemplo n.º 11
0
void XMLWriter::breakLine() {
	if (!_openTags.empty()) {
		_openTags.back().empty = false;
		writeTag();
	}

	_stream->writeString("\n");
	_needIndent = true;
}
Exemplo n.º 12
0
	std::ostream& FileLogger::getStream( SeverityType severity, const std::string& sourceFile, int sourceLine, int exitCode /*= StatusError*/ )
	{
		std::ostream * result = &gNullStream;
		if(mFileStream.is_open() && isActive())
		{
			result = &mFileStream;
			writeTag(mFileStream,severity,sourceFile,sourceLine);
		}
		return *result;
	}
Exemplo n.º 13
0
std::ostream& FileLogger::getStream(SeverityType severity, const char* sourceFile, int sourceLine)
{
    std::ostream* result = &nullStream;
    if(mFileStream.is_open())
    {
        writeTag(mFileStream, severity, sourceFile, sourceLine);
        result = &mFileStream;
    }
    return *result;
}
Exemplo n.º 14
0
	std::ostream& StringLogger::getStream( SeverityType severity, 
		const std::string& sourceFile, 
		int sourceLine, 
		int exitCode /*= StatusError*/ )
	{
		std::ostream* anResult = &gNullStream;
		if(isActive())
		{
			anResult = &mStringStream;
			writeTag(mStringStream, severity, sourceFile, sourceLine);
		}
		return *anResult;
	}
Exemplo n.º 15
0
void XMLWriter::openTag(const Common::UString &name) {
	if (!_openTags.empty()) {
		_openTags.back().empty = false;

		indent(_openTags.size());
		writeTag();
	}

	_openTags.push_back(Tag());

	Tag &tag = _openTags.back();

	tag.name  = name;
	tag.empty = true;
}
Exemplo n.º 16
0
void XMLWriter::closeTag() {
	if (_openTags.empty())
		return;

	writeTag();

	const Tag &tag = _openTags.back();

	if (!tag.empty) {
		indent(_openTags.size() - 1);
		_stream->writeString("</" + tag.name + ">");
	}

	_openTags.pop_back();
}
Exemplo n.º 17
0
/*
	WriteMiscellaneous writes all the miscellaneous data chunks in a
	file handle structure to an IFF/8SVX file.
*/
status IFFFile::writeMiscellaneous()
{
	if (m_miscellaneousPosition == 0)
		m_miscellaneousPosition = m_fh->tell();
	else
		m_fh->seek(m_miscellaneousPosition, File::SeekFromBeginning);

	for (int i=0; i<m_miscellaneousCount; i++)
	{
		Miscellaneous *misc = &m_miscellaneous[i];
		Tag chunkType;
		uint32_t chunkSize;
		uint8_t padByte = 0;

		switch (misc->type)
		{
			case AF_MISC_NAME:
				chunkType = "NAME"; break;
			case AF_MISC_AUTH:
				chunkType = "AUTH"; break;
			case AF_MISC_COPY:
				chunkType = "(c) "; break;
			case AF_MISC_ANNO:
				chunkType = "ANNO"; break;
		}

		writeTag(&chunkType);

		chunkSize = misc->size;
		writeU32(&chunkSize);

		/*
			Write the miscellaneous buffer and then a pad byte
			if necessary.  If the buffer is null, skip the space
			for now.
		*/
		if (misc->buffer != NULL)
			m_fh->write(misc->buffer, misc->size);
		else
			m_fh->seek(misc->size, File::SeekFromCurrent);

		if (misc->size % 2 != 0)
			writeU8(&padByte);
	}

	return AF_SUCCEED;
}
Exemplo n.º 18
0
status CAFFile::writeInit(AFfilesetup setup)
{
	if (initFromSetup(setup) == AF_FAIL)
		return AF_FAIL;

	initCompressionParams();

	Tag caff("caff");
	if (!writeTag(&caff)) return AF_FAIL;
	const uint8_t versionAndFlags[4] = { 0, 1, 0, 0 };
	if (m_fh->write(versionAndFlags, 4) != 4) return AF_FAIL;

	if (writeDescription() == AF_FAIL)
		return AF_FAIL;
	if (writeData(false) == AF_FAIL)
		return AF_FAIL;

	return AF_SUCCEED;
}
Exemplo n.º 19
0
status CAFFile::writeData(bool update)
{
	Track *track = getTrack();

	if (m_dataOffset == -1)
		m_dataOffset = m_fh->tell();
	else
		m_fh->seek(m_dataOffset, File::SeekFromBeginning);

	Tag data("data");
	int64_t dataLength = -1;
	uint32_t editCount = 0;
	if (update)
		dataLength = track->data_size + 4;

	if (!writeTag(&data) ||
		!writeS64(&dataLength) ||
		!writeU32(&editCount))
		return AF_FAIL;
	if (track->fpos_first_frame == 0)
		track->fpos_first_frame = m_fh->tell();
	return AF_SUCCEED;
}
//---------------------------------------------------------
int ofXMLSettings::setValue(string  tag, double value, int which){
	char valueStr[255];
	sprintf(valueStr, "%f", value);
	int tagID = writeTag(tag, valueStr, which) -1;
	return tagID;
}
Exemplo n.º 21
0
//---------------------------------------------------------
int ofxXmlSettings::addValue(const string&  tag, double value){
	int tagID = writeTag(tag, ofToString(value, floatPrecision).c_str(), -1) -1;
	return tagID;
}
Exemplo n.º 22
0
//---------------------------------------------------------
int ofxXmlSettings::addValue(const string& tag, int value){
	int tagID = writeTag(tag, ofToString(value).c_str(), -1) -1;
	return tagID;
}
Exemplo n.º 23
0
bool  TiffEncoder::write( const Mat& img, const vector<int>& /*params*/)
#endif
{
    int channels = img.channels();
    int width = img.cols, height = img.rows;
    int depth = img.depth();

    if (depth != CV_8U && depth != CV_16U)
        return false;

    int bytesPerChannel = depth == CV_8U ? 1 : 2;
    int fileStep = width * channels * bytesPerChannel;

    WLByteStream strm;

    if( m_buf )
    {
        if( !strm.open(*m_buf) )
            return false;
    }
    else
    {
#ifdef HAVE_TIFF
      return writeLibTiff(img, params);
#else
      if( !strm.open(m_filename) )
          return false;
#endif
    }

    int rowsPerStrip = (1 << 13)/fileStep;

    if( rowsPerStrip < 1 )
        rowsPerStrip = 1;

    if( rowsPerStrip > height )
        rowsPerStrip = height;

    int i, stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;

    if( m_buf )
        m_buf->reserve( alignSize(stripCount*8 + fileStep*height + 256, 256) );

/*#if defined _DEBUG || !defined WIN32
    int uncompressedRowSize = rowsPerStrip * fileStep;
#endif*/
    int directoryOffset = 0;

    AutoBuffer<int> stripOffsets(stripCount);
    AutoBuffer<short> stripCounts(stripCount);
    AutoBuffer<uchar> _buffer(fileStep+32);
    uchar* buffer = _buffer;
    int  stripOffsetsOffset = 0;
    int  stripCountsOffset = 0;
    int  bitsPerSample = 8 * bytesPerChannel;
    int  y = 0;

    strm.putBytes( fmtSignTiffII, 4 );
    strm.putDWord( directoryOffset );

    // write an image data first (the most reasonable way
    // for compressed images)
    for( i = 0; i < stripCount; i++ )
    {
        int limit = y + rowsPerStrip;

        if( limit > height )
            limit = height;

        stripOffsets[i] = strm.getPos();

        for( ; y < limit; y++ )
        {
            if( channels == 3 )
            {
                if (depth == CV_8U)
                    icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
                else
                    icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
            }
            else
            {
              if( channels == 4 )
              {
                if (depth == CV_8U)
                    icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
                else
                    icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
              }
            }

            strm.putBytes( channels > 1 ? buffer : img.data + img.step*y, fileStep );
        }

        stripCounts[i] = (short)(strm.getPos() - stripOffsets[i]);
        /*assert( stripCounts[i] == uncompressedRowSize ||
                stripCounts[i] < uncompressedRowSize &&
                i == stripCount - 1);*/
    }

    if( stripCount > 2 )
    {
        stripOffsetsOffset = strm.getPos();
        for( i = 0; i < stripCount; i++ )
            strm.putDWord( stripOffsets[i] );

        stripCountsOffset = strm.getPos();
        for( i = 0; i < stripCount; i++ )
            strm.putWord( stripCounts[i] );
    }
    else if(stripCount == 2)
    {
        stripOffsetsOffset = strm.getPos();
        for (i = 0; i < stripCount; i++)
        {
            strm.putDWord (stripOffsets [i]);
        }
        stripCountsOffset = stripCounts [0] + (stripCounts [1] << 16);
    }
    else
    {
        stripOffsetsOffset = stripOffsets[0];
        stripCountsOffset = stripCounts[0];
    }

    if( channels > 1 )
    {
        int bitsPerSamplePos = strm.getPos();
        strm.putWord(bitsPerSample);
        strm.putWord(bitsPerSample);
        strm.putWord(bitsPerSample);
        if( channels == 4 )
            strm.putWord(bitsPerSample);
        bitsPerSample = bitsPerSamplePos;
    }

    directoryOffset = strm.getPos();

    // write header
    strm.putWord( 9 );

    /* warning: specification 5.0 of Tiff want to have tags in
       ascending order. This is a non-fatal error, but this cause
       warning with some tools. So, keep this in ascending order */

    writeTag( strm, TIFF_TAG_WIDTH, TIFF_TYPE_LONG, 1, width );
    writeTag( strm, TIFF_TAG_HEIGHT, TIFF_TYPE_LONG, 1, height );
    writeTag( strm, TIFF_TAG_BITS_PER_SAMPLE,
              TIFF_TYPE_SHORT, channels, bitsPerSample );
    writeTag( strm, TIFF_TAG_COMPRESSION, TIFF_TYPE_LONG, 1, TIFF_UNCOMP );
    writeTag( strm, TIFF_TAG_PHOTOMETRIC, TIFF_TYPE_SHORT, 1, channels > 1 ? 2 : 1 );

    writeTag( strm, TIFF_TAG_STRIP_OFFSETS, TIFF_TYPE_LONG,
              stripCount, stripOffsetsOffset );

    writeTag( strm, TIFF_TAG_SAMPLES_PER_PIXEL, TIFF_TYPE_SHORT, 1, channels );
    writeTag( strm, TIFF_TAG_ROWS_PER_STRIP, TIFF_TYPE_LONG, 1, rowsPerStrip );

    writeTag( strm, TIFF_TAG_STRIP_COUNTS,
              stripCount > 1 ? TIFF_TYPE_SHORT : TIFF_TYPE_LONG,
              stripCount, stripCountsOffset );

    strm.putDWord(0);
    strm.close();

    if( m_buf )
    {
        (*m_buf)[4] = (uchar)directoryOffset;
        (*m_buf)[5] = (uchar)(directoryOffset >> 8);
        (*m_buf)[6] = (uchar)(directoryOffset >> 16);
        (*m_buf)[7] = (uchar)(directoryOffset >> 24);
    }
    else
    {
//---------------------------------------------------------
int ofXMLSettings::addTag(string tag){
	int tagID = writeTag(tag, "", -1) -1;
	return tagID;	
}
//---------------------------------------------------------
int ofXMLSettings::addValue(string tag, string value){
	int tagID = writeTag(tag, (char *)value.c_str(), -1) -1;
	return tagID;	
}
//---------------------------------------------------------
int ofXMLSettings::addValue(string  tag, double value){
	char valueStr[255];
	sprintf(valueStr, "%f", value);
	int tagID = writeTag(tag, valueStr, -1) -1;
	return tagID;
}
Exemplo n.º 27
0
//---------------------------------------------------------
int ofxXmlSettings::addTag(const string& tag){
	int tagID = writeTag(tag, "", -1) -1;
	return tagID;
}
Exemplo n.º 28
0
status WAVEFile::writeMiscellaneous()
{
	if (miscellaneousCount != 0)
	{
		uint32_t	miscellaneousBytes;
		uint32_t 	chunkSize;

		/* Start at 12 to account for 'LIST', size, and 'INFO'. */
		miscellaneousBytes = 12;

		/* Then calculate the size of the whole INFO chunk. */
		for (int i=0; i<miscellaneousCount; i++)
		{
			Tag miscid;

			// Skip miscellaneous data of an unsupported type.
			if (!misc_type_to_wave(miscellaneous[i].type, &miscid))
				continue;

			// Account for miscellaneous type and size.
			miscellaneousBytes += 8;
			miscellaneousBytes += miscellaneous[i].size;

			// Add a pad byte if necessary.
			if (miscellaneous[i].size % 2 != 0)
				miscellaneousBytes++;

			assert(miscellaneousBytes % 2 == 0);
		}

		if (miscellaneousStartOffset == 0)
			miscellaneousStartOffset = fh->tell();
		else
			fh->seek(miscellaneousStartOffset, File::SeekFromBeginning);

		totalMiscellaneousSize = miscellaneousBytes;

		/*
			Write the data.  On the first call to this
			function (from _af_wave_write_init), the
			data won't be available, fh->seek is used to
			reserve space until the data has been provided.
			On subseuent calls to this function (from
			_af_wave_update), the data will really be written.
		*/

		/* Write 'LIST'. */
		fh->write("LIST", 4);

		/* Write the size of the following chunk. */
		chunkSize = miscellaneousBytes-8;
		writeU32(&chunkSize);

		/* Write 'INFO'. */
		fh->write("INFO", 4);

		/* Write each miscellaneous chunk. */
		for (int i=0; i<miscellaneousCount; i++)
		{
			uint32_t miscsize = miscellaneous[i].size;
			Tag miscid;

			// Skip miscellaneous data of an unsupported type.
			if (!misc_type_to_wave(miscellaneous[i].type, &miscid))
				continue;

			writeTag(&miscid);
			writeU32(&miscsize);
			if (miscellaneous[i].buffer != NULL)
			{
				uint8_t	zero = 0;

				fh->write(miscellaneous[i].buffer, miscellaneous[i].size);

				// Pad if necessary.
				if ((miscellaneous[i].size%2) != 0)
					writeU8(&zero);
			}
			else
			{
				int	size;
				size = miscellaneous[i].size;

				// Pad if necessary.
				if ((size % 2) != 0)
					size++;
				fh->seek(size, File::SeekFromCurrent);
			}
		}
	}

	return AF_SUCCEED;
}
//---------------------------------------------------------
int ofXMLSettings::setValue(string tag, string value, int which){
	int tagID = writeTag(tag, (char *)value.c_str(), which) -1;
	return tagID;
}
Exemplo n.º 30
0
//---------------------------------------------------------
int ofxXmlSettings::addValue(const string& tag, const string& value){
	int tagID = writeTag(tag, value, -1) -1;
	return tagID;
}