void tiff::Header::deserialize(io::InputStream& input) { input.read((sys::byte *)&mByteOrder, sizeof(mByteOrder)); input.read((sys::byte *)&mId, sizeof(mId)); input.read((sys::byte *)&mIFDOffset, sizeof(mIFDOffset)); mDifferentByteOrdering = sys::isBigEndianSystem() ? \ getByteOrder() != tiff::Header::MM : getByteOrder() != tiff::Header::II; if (mDifferentByteOrdering) { mId = sys::byteSwap(mId); mIFDOffset = sys::byteSwap(mIFDOffset); } }
//----------------------------------------------------------------------------- void PDCFileWriter::writePDCHeader(ofstream &outfile) { //create temporary versions of the variables to byte-swap int temp_formatVersion = getFormatVersion(); int temp_byteOrder = getByteOrder(); int temp_extra1 = getExtra1(); int temp_extra2 = getExtra2(); int temp_numParticles = getParticleCount(); int temp_numAttributes = getAttributeCount(); //do swap of byte order swapInt((char*) &temp_formatVersion); swapInt((char*) &temp_byteOrder); swapInt((char*) &temp_extra1); swapInt((char*) &temp_extra2); swapInt((char*) &temp_numParticles); swapInt((char*) &temp_numAttributes); //write out to file for(int i=0;i<4;i++) { outfile.put( m_format[i]); } outfile.write((char*) &temp_formatVersion, sizeof(int)); outfile.write((char*) &temp_byteOrder, sizeof(int)); outfile.write((char*) &temp_extra1, sizeof(int)); outfile.write((char*) &temp_extra2, sizeof(int)); outfile.write((char*) &temp_numParticles, sizeof(int)); outfile.write((char*) &temp_numAttributes, sizeof(int)); }
unsigned SoundSourceOggVorbis::read(volatile unsigned long size, const SAMPLE * destination) { if (size % 2 != 0) { qDebug() << "SoundSourceOggVorbis got non-even size in read."; size--; } char *pRead = (char*) destination; SAMPLE *dest = (SAMPLE*) destination; // 'needed' is size of buffer in bytes. 'size' is size in SAMPLEs, // which is 2 bytes. If the stream is mono, we read 'size' bytes, // so that half the buffer is full, then below we double each // sample on the left and right channel. If the stream is stereo, // then ov_read interleaves the samples into the full length of // the buffer. // ov_read speaks bytes, we speak words. needed is the bytes to // read, not words to read. // size is the maximum space in words that we have in // destination. For stereo files, read the full buffer (size*2 // bytes). For mono files, only read half the buffer (size bytes), // and we will double the buffer to be in stereo later. unsigned int needed = size * channels; unsigned int index=0,ret=0; // loop until requested number of samples has been retrieved while (needed > 0) { // read samples into buffer ret = ov_read(&vf, pRead+index, needed, getByteOrder(), 2, 1, ¤t_section); if (ret <= 0) { // An error or EOF occured, break out and return what we have sofar. break; } index += ret; needed -= ret; } // As of here, index is the total bytes read. (index/2/channels) is the // total frames read. // convert into stereo if file is mono if (channels == 1) { SampleUtil::doubleMonoToDualMono(dest, index / 2); // Pretend we read twice as many bytes as we did, since we just repeated // each pair of bytes. index *= 2; } // index is the total bytes read, so the words read is index/2 return index / 2; }
// Update digest with data of size len, do in blocks void HASHwithTransform::Update(const byte* data, word32 len) { // do block size increments word32 blockSz = getBlockSize(); byte* local = reinterpret_cast<byte*>(buffer_); while (len) { word32 add = min(len, blockSz - buffLen_); memcpy(&local[buffLen_], data, add); buffLen_ += add; data += add; len -= add; if (buffLen_ == blockSz) { ByteReverseIf(local, local, blockSz, getByteOrder()); Transform(); AddLength(blockSz); buffLen_ = 0; } } }
// Final process, place digest in hash void HASHwithTransform::Final(byte* hash) { word32 blockSz = getBlockSize(); word32 digestSz = getDigestSize(); word32 padSz = getPadSize(); ByteOrder order = getByteOrder(); AddLength(buffLen_); // before adding pads HashLengthType preLoLen = GetBitCountLo(); HashLengthType preHiLen = GetBitCountHi(); byte* local = reinterpret_cast<byte*>(buffer_); local[buffLen_++] = 0x80; // add 1 // pad with zeros if (buffLen_ > padSz) { memset(&local[buffLen_], 0, blockSz - buffLen_); buffLen_ += blockSz - buffLen_; ByteReverseIf(local, local, blockSz, order); Transform(); buffLen_ = 0; } memset(&local[buffLen_], 0, padSz - buffLen_); ByteReverseIf(local, local, blockSz, order); memcpy(&local[padSz], order ? &preHiLen : &preLoLen, sizeof(preLoLen)); memcpy(&local[padSz+4], order ? &preLoLen : &preHiLen, sizeof(preLoLen)); Transform(); ByteReverseIf(digest_, digest_, digestSz, order); memcpy(hash, digest_, digestSz); Init(); // reset state }
unsigned SoundSourceOggVorbis::read(volatile unsigned long size, const SAMPLE * destination) { if (size % 2 != 0) { qDebug() << "SoundSourceOggVorbis got non-even size in read."; size--; } char *pRead = (char*) destination; SAMPLE *dest = (SAMPLE*) destination; // 'needed' is size of buffer in bytes. 'size' is size in SAMPLEs, // which is 2 bytes. If the stream is mono, we read 'size' bytes, // so that half the buffer is full, then below we double each // sample on the left and right channel. If the stream is stereo, // then ov_read interleaves the samples into the full length of // the buffer. // ov_read speaks bytes, we speak words. needed is the bytes to // read, not words to read. // size is the maximum space in words that we have in // destination. For stereo files, read the full buffer (size*2 // bytes). For mono files, only read half the buffer (size bytes), // and we will double the buffer to be in stereo later. unsigned int needed = size * channels; unsigned int index=0,ret=0; // loop until requested number of samples has been retrieved while (needed > 0) { // read samples into buffer ret = ov_read(&vf, pRead+index, needed, getByteOrder(), 2, 1, ¤t_section); if (ret <= 0) { // An error or EOF occured, break out and return what we have sofar. break; } index += ret; needed -= ret; } // As of here, index is the total bytes read. (index/2/channels) is the // total frames read. // convert into stereo if file is mono if (channels == 1) { // rryan 2/2009 // Mini-proof of the below: // size = 20, destination is a 20 element array 0-19 // readNo = 10 (or less, but 10 in this case) // i = 10-1 = 9, so dest[9*2] and dest[9*2+1], // so the first iteration touches the very ends of destination // on the last iteration, dest[0] and dest[1] are assigned to dest[0] for(int i=(index/2-1); i>=0; i--) { dest[i*2] = dest[i]; dest[(i*2)+1] = dest[i]; } // Pretend we read twice as many bytes as we did, since we just repeated // each pair of bytes. index *= 2; } // index is the total bytes read, so the words read is index/2 return index / 2; }
inline bool Endianness::isPDP() { return (getByteOrder() == Endianness::PDP); }
inline bool Endianness::isBig() { return (getByteOrder() == Endianness::BIG); }
inline bool Endianness::isLittle() { return (getByteOrder() == Endianness::LITTLE); }