void ClientMessage::wrapForEncode(byte *buffer, int32_t size, bool owner) { wrapForWrite(buffer, size, HEADER_SIZE); isOwner = owner; setFrameLength(size); setVersion(VERSION); setFlags(BEGIN_AND_END_FLAGS); setCorrelationId(0); setPartitionId(-1); setDataOffset(HEADER_SIZE); }
void File::_initialize() { if (_initialized) return; Dat::Item::_initialize(); Dat::Item::setPosition(0); _version = uint32(); _framesPerSecond = uint16(); _actionFrame = uint16(); _framesPerDirection = uint16(); uint16_t shiftX[6]; uint16_t shiftY[6]; uint32_t dataOffset[6]; for (unsigned int i = 0; i != 6; ++i) shiftX[i] = uint16(); for (unsigned int i = 0; i != 6; ++i) shiftY[i] = uint16(); for (unsigned int i = 0; i != 6; ++i) { dataOffset[i] = uint32(); if (i > 0 && dataOffset[i-1] == dataOffset[i]) { continue; } auto direction = new Direction(); direction->setDataOffset(dataOffset[i]); direction->setShiftX(shiftX[i]); direction->setShiftY(shiftY[i]); _directions.push_back(direction); } // for each direction for (auto direction : _directions) { // jump to frames data at frames area Dat::Item::setPosition(direction->dataOffset() + 62); // read all frames for (unsigned i = 0; i != _framesPerDirection; ++i) { uint16_t width = uint16(); uint16_t height = uint16(); auto frame = new Frame(width, height); // Number of pixels for this frame // We don't need this, because we already have width*height uint32(); frame->setOffsetX(int16()); frame->setOffsetY(int16()); // Pixels data for (unsigned y = 0; y != frame->height(); ++y) { for (unsigned x = 0; x != frame->width(); ++x) { frame->setIndex(x, y, uint8()); } } direction->frames()->push_back(frame); } } }
void rWAVAudio::readHeaders() { unsigned int buff; int c=0; _D(Lvl_Info, "%s: Reading headers", (int)__PRETTY_FUNCTION__); DOS->Seek(getFile(), 0, OFFSET_BEGINNING); if (DOS->Read(getFile(), &buff, 4)!=4) { _D(Lvl_Info, "%s: File seems to be too small.. reading failed.", (int)__PRETTY_FUNCTION__); return; } buff = L2BE(buff); if (buff != ID_RIFF) { _D(Lvl_Info, "%s: RIFF Wave file header not present (got: %08lx)", (int)__PRETTY_FUNCTION__, buff); return; } DOS->Seek(getFile(), 4, OFFSET_CURRENT); if (DOS->Read(getFile(), &buff, 4)!=4) { _D(Lvl_Info, "%s: File truncated..?", (int)__PRETTY_FUNCTION__); return; } buff = L2BE(buff); if (buff != ID_WAVE) { _D(Lvl_Info, "%s: This RIFF is not Wave... (%08lx)", (int)__PRETTY_FUNCTION__, buff); return; } for (c=0; c<2;) { if (DOS->Read(getFile(), &buff, 4)!=4) { _D(Lvl_Info, "%s: File truncated...", (int)__PRETTY_FUNCTION__); return; } _D(Lvl_Info, "%s: Read tag: %08lx", (int)__PRETTY_FUNCTION__, buff); buff = L2BE(buff); if (buff == ID_fmt) { _D(Lvl_Info, "%s: format tag located.", (int)__PRETTY_FUNCTION__); c++; } else if (buff == ID_data) { _D(Lvl_Info, "%s: data tag located.", (int)__PRETTY_FUNCTION__); c++; if (DOS->Read(getFile(), &buff, 4)!=4) { _D(Lvl_Info, "%s: file truncated.", (int)__PRETTY_FUNCTION__); return; } setDataOffset(DOS->Seek(getFile(), 0, OFFSET_CURRENT)); buff = L2LE(buff); setDataSize(buff); DOS->Seek(getFile(), -4, OFFSET_CURRENT); } if (DOS->Read(getFile(), &buff, 4)!=4) { _D(Lvl_Info, "%s: Failed to read chunk size. File truncated.", (int)__PRETTY_FUNCTION__); return; } buff = L2LE(buff); _D(Lvl_Info,"%s: chunk size = %ld bytes.", (int)__PRETTY_FUNCTION__, buff); DOS->Seek(getFile(), buff, OFFSET_CURRENT); } return; }