void ValueTreeSynchroniser::valueTreeChildRemoved (ValueTree& parentTree, ValueTree&, int oldIndex) { MemoryOutputStream m; ValueTreeSynchroniserHelpers::writeHeader (*this, m, ValueTreeSynchroniserHelpers::childRemoved, parentTree); m.writeCompressedInt (oldIndex); stateChanged (m.getData(), m.getDataSize()); }
void Robot::timerCallback() { MemoryOutputStream * out = messageBuffer.getReader(); if (out != nullptr) { send(out->getData(), out->getDataSize()); messageBuffer.readDone(); } }
void ValueTreeSynchroniser::sendFullSyncCallback() { MemoryOutputStream m; writeHeader (m, ValueTreeSynchroniserHelpers::fullSync); valueTree.writeToStream (m); stateChanged (m.getData(), m.getDataSize()); }
void HelmPlugin::getStateInformation(MemoryBlock& dest_data) { var state = LoadSave::stateToVar(&synth_, gui_state_, getCallbackLock()); String data_string = JSON::toString(state); MemoryOutputStream stream; stream.writeString(data_string); dest_data.append(stream.getData(), stream.getDataSize()); }
Drawable* Drawable::createFromImageDataStream (InputStream& dataSource) { MemoryOutputStream mo; mo.writeFromInputStream (dataSource, -1); return createFromImageData (mo.getData(), mo.getDataSize()); }
void runTest() override { beginTest ("Basics"); Random r = getRandom(); int randomInt = r.nextInt(); int64 randomInt64 = r.nextInt64(); double randomDouble = r.nextDouble(); String randomString (createRandomWideCharString (r)); MemoryOutputStream mo; mo.writeInt (randomInt); mo.writeIntBigEndian (randomInt); mo.writeCompressedInt (randomInt); mo.writeString (randomString); mo.writeInt64 (randomInt64); mo.writeInt64BigEndian (randomInt64); mo.writeDouble (randomDouble); mo.writeDoubleBigEndian (randomDouble); MemoryInputStream mi (mo.getData(), mo.getDataSize(), false); expect (mi.readInt() == randomInt); expect (mi.readIntBigEndian() == randomInt); expect (mi.readCompressedInt() == randomInt); expectEquals (mi.readString(), randomString); expect (mi.readInt64() == randomInt64); expect (mi.readInt64BigEndian() == randomInt64); expect (mi.readDouble() == randomDouble); expect (mi.readDoubleBigEndian() == randomDouble); }
OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead) { const size_t dataSize = streamToRead.getDataSize(); if (dataSize > 0) stream.write (streamToRead.getData(), dataSize); return stream; }
void ValueTreeSynchroniser::valueTreeChildAdded (ValueTree& parentTree, ValueTree& childTree) { const int index = parentTree.indexOf (childTree); jassert (index >= 0); MemoryOutputStream m; ValueTreeSynchroniserHelpers::writeHeader (*this, m, ValueTreeSynchroniserHelpers::childAdded, parentTree); m.writeCompressedInt (index); childTree.writeToStream (m); stateChanged (m.getData(), m.getDataSize()); }
void jojo_write (t_jojo *x, const File& aFile) { MemoryOutputStream myText; GZIPCompressorOutputStream zipper (&myText); zipper << "Stately, plump Buck Mulligan came from the stairhead, " << newLine << "bearing a bowl of lather on which a mirror and a razor lay crossed." << newLine; zipper.flush(); aFile.replaceWithData (myText.getData(), myText.getDataSize()); }
PxConvexMesh* createConvexMesh( const std::vector<PxVec3>& verts, PxConvexFlags flags ) { PxConvexMeshDesc convexDesc; convexDesc.points.count = verts.size(); convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = &(verts[0]); convexDesc.flags = flags; MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookConvexMesh(convexDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createConvexMesh( readBuffer ); }
PxConvexMesh* PxToolkit::createConvexMesh(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags) { PxConvexMeshDesc convexDesc; convexDesc.points.count = vertCount; convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = verts; convexDesc.flags = flags; MemoryOutputStream buf; if(!cooking.cookConvexMesh(convexDesc, buf)) return NULL; PxToolkit::MemoryInputData input(buf.getData(), buf.getSize()); return physics.createConvexMesh(input); }
PxTriangleMesh* createTriangleMesh( const std::vector<PxVec3>& verts, const std::vector<PxU32>& indices ) { PxTriangleMeshDesc meshDesc; meshDesc.points.count = verts.size(); meshDesc.points.stride = sizeof(PxVec3); meshDesc.points.data = &(verts[0]); meshDesc.triangles.count = indices.size() / 3; meshDesc.triangles.stride = 3 * sizeof(PxU32); meshDesc.triangles.data = &(indices[0]); MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookTriangleMesh(meshDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createTriangleMesh( readBuffer ); }
void ValueTreeSynchroniser::valueTreePropertyChanged (ValueTree& vt, const Identifier& property) { MemoryOutputStream m; if (auto* value = vt.getPropertyPointer (property)) { ValueTreeSynchroniserHelpers::writeHeader (*this, m, ValueTreeSynchroniserHelpers::propertyChanged, vt); m.writeString (property.toString()); value->writeToStream (m); } else { ValueTreeSynchroniserHelpers::writeHeader (*this, m, ValueTreeSynchroniserHelpers::propertyRemoved, vt); m.writeString (property.toString()); } stateChanged (m.getData(), m.getDataSize()); }
XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement) { if (originalText.isEmpty() && inputSource != nullptr) { ScopedPointer<InputStream> in (inputSource->createInputStream()); if (in != nullptr) { MemoryOutputStream data; data.writeFromInputStream (*in, onlyReadOuterDocumentElement ? 8192 : -1); #if JUCE_STRING_UTF_TYPE == 8 if (data.getDataSize() > 2) { data.writeByte (0); const char* text = static_cast<const char*> (data.getData()); if (CharPointer_UTF16::isByteOrderMarkBigEndian (text) || CharPointer_UTF16::isByteOrderMarkLittleEndian (text)) { originalText = data.toString(); } else { if (CharPointer_UTF8::isByteOrderMark (text)) text += 3; // parse the input buffer directly to avoid copying it all to a string.. return parseDocumentElement (String::CharPointerType (text), onlyReadOuterDocumentElement); } } #else originalText = data.toString(); #endif } } return parseDocumentElement (originalText.getCharPointer(), onlyReadOuterDocumentElement); }
PxClothFabric* createClothFabric( const std::vector<PxVec3>& verts, const std::vector<PxU32>& indices, const osg::Vec3& gravity ) { PxClothMeshDesc meshDesc; meshDesc.points.count = verts.size(); meshDesc.points.stride = sizeof(PxVec3); meshDesc.points.data = &(verts[0]); meshDesc.triangles.count = indices.size() / 3; meshDesc.triangles.stride = 3 * sizeof(PxU32); meshDesc.triangles.data = &(indices[0]); PxVec3 g( gravity[0], gravity[1], gravity[2] ); #if USE_PHYSX_33 return PxClothFabricCreate( *SDK_OBJ, meshDesc, g ); #else MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookClothFabric(meshDesc, g, writeBuffer) ) return NULL; MemoryInputData readData( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createClothFabric(readData); #endif }
PxConvexMesh* createConvexMesh( osg::Node& node, PxConvexFlags flags ) { GeometryDataCollector collector; node.accept( collector ); std::vector<PxVec3> verts; for ( unsigned int i=0; i<collector.vertices.size(); ++i ) { const osg::Vec3& v = collector.vertices[i]; verts.push_back( PxVec3(v[0], v[1], v[2]) ); } std::vector<PxU32> indices; for ( unsigned int i=0; i<collector.faces.size(); ++i ) { const GeometryDataCollector::GeometryFace& f = collector.faces[i]; indices.push_back( f.indices[0] ); indices.push_back( f.indices[1] ); indices.push_back( f.indices[2] ); } if ( !verts.size() || !indices.size() ) return NULL; PxConvexMeshDesc convexDesc; convexDesc.points.count = verts.size(); convexDesc.points.stride = sizeof(PxVec3); convexDesc.points.data = &(verts[0]); convexDesc.triangles.count = indices.size() / 3; convexDesc.triangles.stride = 3 * sizeof(PxU32); convexDesc.triangles.data = &(indices[0]); convexDesc.flags = flags; MemoryOutputStream writeBuffer; if ( !SDK_COOK->cookConvexMesh(convexDesc, writeBuffer) ) return NULL; MemoryInputData readBuffer( writeBuffer.getData(), writeBuffer.getSize() ); return SDK_OBJ->createConvexMesh( readBuffer ); }
bool overwriteFileWithNewDataIfDifferent (const File& file, const MemoryOutputStream& newData) { return overwriteFileWithNewDataIfDifferent (file, newData.getData(), newData.getDataSize()); }
void BinaryResources::loadFromCpp (const File& cppFileLocation, const String& cppFile) { StringArray cpp; cpp.addLines (cppFile); clear(); for (int i = 0; i < cpp.size(); ++i) { if (cpp[i].contains ("JUCER_RESOURCE:")) { StringArray tokens; tokens.addTokens (cpp[i].fromFirstOccurrenceOf (":", false, false), ",", "\"'"); tokens.trim(); tokens.removeEmptyStrings(); const String resourceName (tokens[0]); const int resourceSize = tokens[1].getIntValue(); const String originalFileName (cppFileLocation.getSiblingFile (tokens[2].unquoted()).getFullPathName()); jassert (resourceName.isNotEmpty() && resourceSize > 0); if (resourceName.isNotEmpty() && resourceSize > 0) { const int firstLine = i; while (i < cpp.size()) if (cpp [i++].contains ("}")) break; const String dataString (cpp.joinIntoString (" ", firstLine, i - firstLine) .fromFirstOccurrenceOf ("{", false, false)); MemoryOutputStream out; String::CharPointerType t (dataString.getCharPointer()); int n = 0; while (! t.isEmpty()) { const juce_wchar c = t.getAndAdvance(); if (c >= '0' && c <= '9') n = n * 10 + (c - '0'); else if (c == ',') { out.writeByte ((char) n); n = 0; } else if (c == '}') break; } jassert (resourceSize < (int) out.getDataSize() && resourceSize > (int) out.getDataSize() - 2); MemoryBlock mb (out.getData(), out.getDataSize()); mb.setSize ((size_t) resourceSize); add (resourceName, originalFileName, mb); } } } }
Image JPEGImageFormat::decodeImage (InputStream& in) { #if (JUCE_MAC || JUCE_IOS) && USE_COREGRAPHICS_RENDERING && JUCE_USE_COREIMAGE_LOADER return juce_loadWithCoreImage (in); #else using namespace jpeglibNamespace; using namespace JPEGHelpers; MemoryOutputStream mb; mb << in; Image image; if (mb.getDataSize() > 16) { struct jpeg_decompress_struct jpegDecompStruct; struct jpeg_error_mgr jerr; setupSilentErrorHandler (jerr); jpegDecompStruct.err = &jerr; jpeg_create_decompress (&jpegDecompStruct); jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small) ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr)); jpegDecompStruct.src->init_source = dummyCallback1; jpegDecompStruct.src->fill_input_buffer = jpegFill; jpegDecompStruct.src->skip_input_data = jpegSkip; jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart; jpegDecompStruct.src->term_source = dummyCallback1; jpegDecompStruct.src->next_input_byte = static_cast <const unsigned char*> (mb.getData()); jpegDecompStruct.src->bytes_in_buffer = mb.getDataSize(); try { jpeg_read_header (&jpegDecompStruct, TRUE); jpeg_calc_output_dimensions (&jpegDecompStruct); const int width = (int) jpegDecompStruct.output_width; const int height = (int) jpegDecompStruct.output_height; jpegDecompStruct.out_color_space = JCS_RGB; JSAMPARRAY buffer = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct, JPOOL_IMAGE, (JDIMENSION) width * 3, 1); if (jpeg_start_decompress (&jpegDecompStruct)) { image = Image (Image::RGB, width, height, false); image.getProperties()->set ("originalImageHadAlpha", false); const bool hasAlphaChan = image.hasAlphaChannel(); // (the native image creator may not give back what we expect) const Image::BitmapData destData (image, Image::BitmapData::writeOnly); for (int y = 0; y < height; ++y) { jpeg_read_scanlines (&jpegDecompStruct, buffer, 1); const uint8* src = *buffer; uint8* dest = destData.getLinePointer (y); if (hasAlphaChan) { for (int i = width; --i >= 0;) { ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]); ((PixelARGB*) dest)->premultiply(); dest += destData.pixelStride; src += 3; } } else { for (int i = width; --i >= 0;) { ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]); dest += destData.pixelStride; src += 3; } } } jpeg_finish_decompress (&jpegDecompStruct); in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData()); } jpeg_destroy_decompress (&jpegDecompStruct); } catch (...) {} } return image; #endif }
OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead) { stream.write (streamToRead.getData(), streamToRead.getDataSize()); return stream; }