static inline void sWriteCount(const ZStreamW& iStreamW, uint32 iCount) { if (iCount < 0xFF) { iStreamW.WriteUInt8(iCount); } else { iStreamW.WriteUInt8(0xFF); iStreamW.WriteUInt32(iCount); } }
static void sNodeToStream(const ZStreamW& iStreamW, const ZRef<ZTBQueryNode>& iNode) { if (iNode) iNode->ToStream(iStreamW); else iStreamW.WriteUInt8(0); }
void ZTBQueryNode_ID_Constant::ToStream(const ZStreamW& iStreamW) { iStreamW.WriteUInt8(5); sWriteCount(iStreamW, fIDs.size()); for (vector<uint64>::iterator i = fIDs.begin(), theEnd = fIDs.end(); i != theEnd; ++i) { iStreamW.WriteUInt64(*i); } }
void ZTBQueryNode_Combo::ToStream(const ZStreamW& iStreamW) { iStreamW.WriteUInt8(2); sWriteCount(iStreamW, fSort.size()); for (vector<ZTBQuery::SortSpec>::iterator i = fSort.begin(); i != fSort.end(); ++i) (*i).ToStream(iStreamW); sWriteCount(iStreamW, fIntersections.size()); for (vector<Intersection>::iterator i = fIntersections.begin(); i != fIntersections.end(); ++i) (*i).ToStream(iStreamW); }
void ZDCPixmapEncoder_GIF::Imp_Write(const ZStreamW& iStream, const void* iBaseAddress, const ZDCPixmapNS::RasterDesc& iRasterDesc, const ZDCPixmapNS::PixelDesc& iPixelDesc, const ZRect& iBounds) { ZRef<ZDCPixmapNS::PixelDescRep_Indexed> thePixelDescRep_Indexed = ZRefDynamicCast<ZDCPixmapNS::PixelDescRep_Indexed>(iPixelDesc.GetRep()); ZAssertStop(2, thePixelDescRep_Indexed); if (fTransparent) iStream.WriteString("GIF89a"); else iStream.WriteString("GIF87a"); iStream.WriteUInt16LE(iBounds.Width()); iStream.WriteUInt16LE(iBounds.Height()); uint8 globalStrmFlags = 0; globalStrmFlags |= 0x80; // hasGlobalColorTable globalStrmFlags |= 0x70; // colorResolution (8 bits per component) // globalStrmFlags |= 0x08; // set this if the color table is sorted in priority order ZAssertStop(2, iRasterDesc.fPixvalDesc.fDepth > 0 && iRasterDesc.fPixvalDesc.fDepth <= 8); globalStrmFlags |= iRasterDesc.fPixvalDesc.fDepth - 1; // globalColorTableSize & depth iStream.WriteUInt8(globalStrmFlags); iStream.WriteUInt8(0); // backgroundColorIndex iStream.WriteUInt8(0); // Pixel aspect ratio -- 0 == none specified. const ZRGBColorPOD* theColors; size_t theColorsCount; thePixelDescRep_Indexed->GetColors(theColors, theColorsCount); sWriteColorTable(iStream, theColors, theColorsCount, 1 << iRasterDesc.fPixvalDesc.fDepth); if (fTransparent) { iStream.WriteUInt8('!'); // Extension block iStream.WriteUInt8(0xF9); // Graphic Control Extension iStream.WriteUInt8(4); // Block size // The next byte encodes four fields: // 3 bits, Reserved == 0 // 3 bits, Disposal Method == none (0), // 1 bit, User Input Flag == none (0) // 1 bit, Transparent Color Flag = yes (1) iStream.WriteUInt8(1); iStream.WriteUInt16LE(0); // Delay time iStream.WriteUInt8(fTransparentPixval); iStream.WriteUInt8(0); // Block terminator } iStream.WriteUInt8(','); // Start of image iStream.WriteUInt16LE(0); // Origin h iStream.WriteUInt16LE(0); // Origin v iStream.WriteUInt16LE(iBounds.Width()); iStream.WriteUInt16LE(iBounds.Height()); uint8 localStrmFlags = 0; // localStrmFlags |= 0x80; // hasLocalColorTable if (fInterlace) localStrmFlags |= 0x40; // interlaced // localStrmFlags |= 0x20; // sorted // localStrmFlags |= 0x70; // localColorTableSize iStream.WriteUInt8(localStrmFlags); iStream.WriteUInt8(iRasterDesc.fPixvalDesc.fDepth); // Initial code size. { // Scope theSC. StreamW_Chunk theSC(iStream); ZStreamW_LZWEncode* theSLZW = nil; ZStreamW_LZWEncodeNoPatent* theSLZWNP = nil; ZStreamW* theStream; if (fNoPatent) { theSLZWNP = new ZStreamW_LZWEncodeNoPatent(iRasterDesc.fPixvalDesc.fDepth, theSC); theStream = theSLZWNP; } else { theSLZW = new ZStreamW_LZWEncode(iRasterDesc.fPixvalDesc.fDepth, theSC); theStream = theSLZW; } ZDCPixmapNS::PixvalDesc destPixvalDesc(8, true); vector<uint8> theRowBufferVector(iBounds.Width()); void* theRowBuffer = &theRowBufferVector[0]; try { if (fInterlace) { for (int pass = 0; pass < 4; ++pass) { for (ZCoord currentY = iBounds.top + sInterlaceStart[pass]; currentY < iBounds.bottom; currentY += sInterlaceIncrement[pass]) { const void* sourceRowAddress = iRasterDesc.CalcRowAddress(iBaseAddress, currentY); ZDCPixmapNS::sBlitRowPixvals( sourceRowAddress, iRasterDesc.fPixvalDesc, iBounds.left, theRowBuffer, destPixvalDesc, 0, iBounds.Width()); theStream->Write(theRowBuffer, iBounds.Width()); } } } else { for (ZCoord currentY = iBounds.top; currentY < iBounds.bottom; ++currentY) { const void* sourceRowAddress = iRasterDesc.CalcRowAddress(iBaseAddress, currentY); ZDCPixmapNS::sBlitRowPixvals( sourceRowAddress, iRasterDesc.fPixvalDesc, iBounds.left, theRowBuffer, destPixvalDesc, 0, iBounds.Width()); theStream->Write(theRowBuffer, iBounds.Width()); } } } catch (...) { delete theSLZW; delete theSLZWNP; throw; } delete theSLZW; delete theSLZWNP; } iStream.WriteUInt8(';'); // Trailer. }
void ZTBQueryNode_ID_FromSource::ToStream(const ZStreamW& iStreamW) { iStreamW.WriteUInt8(6); fSourcePropName.ToStream(iStreamW); sNodeToStream(iStreamW, fSourceNode); }
void ZTBQueryNode_First::ToStream(const ZStreamW& iStreamW) { iStreamW.WriteUInt8(4); fPropName.ToStream(iStreamW); sNodeToStream(iStreamW, fSourceNode); }
void ZTBQueryNode_Difference::ToStream(const ZStreamW& iStreamW) { iStreamW.WriteUInt8(3); sNodeToStream(iStreamW, fLeftNode); sNodeToStream(iStreamW, fRightNode); }
void ZTBQueryNode_All::ToStream(const ZStreamW& iStreamW) { iStreamW.WriteUInt8(1); }
void ZTBQuery::SortSpec::ToStream(const ZStreamW& iStreamW) const { fPropName.ToStream(iStreamW); iStreamW.WriteBool(fAscending); iStreamW.WriteUInt8(fStrength); }
void ZTBSpec::Comparator::ToStream(const ZStreamW& iStreamW) const { iStreamW.WriteUInt8(fRel); iStreamW.WriteUInt8(fStrength); }
bool ZTSWatcherServerAsync::Write(const ZStreamW& iStreamW) { bool wroteAnything = false; ZMutexLocker locker(fMutex); if (fSendClose) { iStreamW.WriteUInt8(eResp_Close); return false; } else if (fIDsNeeded) { if (ZLOG(s, eDebug, "ZTSWatcherServerAsync")) s << "Write, sending IDs"; const size_t countNeeded = fIDsNeeded; fIDsNeeded = 0; locker.Release(); uint64 theBaseID; size_t countIssued; bool success = fTSWatcher->AllocateIDs(countNeeded, theBaseID, countIssued); if (!success) { iStreamW.WriteUInt8(eResp_Close); return false; } iStreamW.WriteUInt8(eResp_IDs); iStreamW.WriteUInt64(theBaseID); iStreamW.WriteCount(countIssued); wroteAnything = true; if (ZLOG(s, eDebug, "ZTSWatcherServerAsync")) s << "Write, sent IDs"; } else if (fSyncNeeded) { if (ZLOG(s, eDebug, "ZTSWatcherServerAsync")) s << "Write, sync"; fSyncNeeded = false; vector<uint64> removedIDs; vector<uint64> addedIDs; vector<int64> removedQueries; vector<ZTSWatcher::AddedQueryCombo> addedQueries; vector<uint64> writtenTupleIDs; vector<ZTuple> writtenTuples; fRemovedIDs.swap(removedIDs); fAddedIDs.swap(addedIDs); fRemovedQueries.swap(removedQueries); fAddedQueries.swap(addedQueries); fWrittenTupleIDs.swap(writtenTupleIDs); fWrittenTuples.swap(writtenTuples); locker.Release(); vector<uint64> watcherAddedIDs; vector<uint64> changedTupleIDs; vector<ZTuple> changedTuples; map<int64, vector<uint64> > changedQueries; using ZUtil_STL::sFirstOrNil; bool success = fTSWatcher->Sync( sFirstOrNil(removedIDs), removedIDs.size(), sFirstOrNil(addedIDs), addedIDs.size(), sFirstOrNil(removedQueries), removedQueries.size(), sFirstOrNil(addedQueries), addedQueries.size(), watcherAddedIDs, changedTupleIDs, changedTuples, sFirstOrNil(writtenTupleIDs), sFirstOrNil(writtenTuples), writtenTupleIDs.size(), changedQueries); if (!success) { iStreamW.WriteUInt8(eResp_Close); return false; } iStreamW.WriteUInt8(eResp_SyncResults); iStreamW.WriteCount(watcherAddedIDs.size()); for (vector<uint64>::const_iterator i = watcherAddedIDs.begin(), theEnd = watcherAddedIDs.end(); i != theEnd; ++i) { iStreamW.WriteUInt64(*i); } iStreamW.WriteCount(changedTupleIDs.size()); vector<ZTuple>::const_iterator iterCT = changedTuples.begin(); for (vector<uint64>::const_iterator i = changedTupleIDs.begin(), theEnd = changedTupleIDs.end(); i != theEnd; ++i, ++iterCT) { iStreamW.WriteUInt64(*i); (*iterCT).ToStream(iStreamW); } iStreamW.WriteCount(changedQueries.size()); for (map<int64, vector<uint64> >::const_iterator i = changedQueries.begin(), theEnd = changedQueries.end(); i != theEnd; ++i) { iStreamW.WriteInt64((*i).first); const vector<uint64>& theVector = (*i).second; iStreamW.WriteCount(theVector.size()); for (vector<uint64>::const_iterator j = theVector.begin(); j != theVector.end(); ++j) iStreamW.WriteUInt64(*j); } wroteAnything = true; } else if (fCallbackNeeded) { if (ZLOG(s, eDebug, "ZTSWatcherServerAsync")) s << "Write, callback"; fCallbackNeeded = false; locker.Release(); iStreamW.WriteUInt8(eResp_SyncSuggested); wroteAnything = true; } if (wroteAnything) ZStreamerWriter::Wake(); else iStreamW.Flush(); return true; }