/** Write a node at the specified coordinates. If a node is currently there then overwrite. */ void GridNode::writeNode(int x,int y, Color color, int numberOfNodes, File grid) { int pos = findPositionOfGridNode(x,y,grid); if(grid) { if(pos == -1) { if(numberOfNodes > 0) { grid.write(','); grid.write('\n'); } grid.write('\"'); writeNumber(grid,x); grid.write(','); writeNumber(grid,y); grid.write('\"'); grid.write('{'); grid.write('\n'); writeColor(grid,color, false); grid.write('\n'); grid.write('}'); } else { grid.seek(pos); grid.write('\n'); writeColor(grid,color, false); } } else { //Serial.println("Map file was not avaliable for writing"); } grid.flush(); grid.close(); }
void setup() { // Initialize pin modes: set pin 0, 1 and 2 to outputs. DDRB = 0b00000111; PRR = _BV(PRADC); // Turn off the ADC checkAndInitialize(); if(PINB & SWITCH){ // Enter the rather complex color observation mode, write the new ones out to the EPROM. observe_color(); writeColor(red, (uint8_t*) RED_BASE); writeColor(green, (uint8_t*) GREEN_BASE); writeColor(blue, (uint8_t*) BLUE_BASE); }else{// Read the old values from the eeprom, initializing it if needed. red = readColor((uint8_t*) RED_BASE); green = readColor((uint8_t*) GREEN_BASE); blue = readColor((uint8_t*) BLUE_BASE); } /* Setup timer0 to fire an interrupt every 75 cycles, the enter an infinite loop. All the work is done on the interrupts - once we've figured out what colors to use, the device simply has to PWM them until it's shutoff. Based on Atmel's "AVR136: Low-jitter Multi-channel Software PWM" */ cli(); // This is probably not needed. Disable interrupts. /* Interesting design: before altering any other bits in CLKPR, CLKPCE must be set. The processor then resets CLKPCE within four cycles. After we've enabled updating CLKPR, set the clock speed to its maximum. */ CLKPR = _BV(CLKPCE); CLKPR = 0; TCCR0B = _BV(CS00); // No prescaler TCCR0A = _BV(WGM01);// Clear the timer on compare OCR0A = 75; TIMSK |= _BV(OCIE0A);// interrupt on compare with register A, which just happens to be 75. sei(); // Turn everything on, and loop! while(1); }
void ClawsMailSettings::readSettingsColor(const KConfigGroup& group) { const bool enableColor = group.readEntry("enable_color", false); if(enableColor) { const QString colorLevel1 = group.readEntry("quote_level1_color"); if(!colorLevel1.isEmpty()) { const QColor col = QColor(colorLevel1); if(col.isValid()) { addKmailConfig(QLatin1String("Reader"), QLatin1String("QuotedText1"), writeColor(col)); } //[Reader] QuotedText1 } const QString colorLevel2 = group.readEntry("quote_level2_color"); if(!colorLevel2.isEmpty()) { const QColor col = QColor(colorLevel2); if(col.isValid()) { addKmailConfig(QLatin1String("Reader"), QLatin1String("QuotedText2"), writeColor(col)); } //[Reader] QuotedText2 } const QString colorLevel3 = group.readEntry("quote_level3_color"); if(!colorLevel3.isEmpty()) { const QColor col = QColor(colorLevel3); if(col.isValid()) { addKmailConfig(QLatin1String("Reader"), QLatin1String("QuotedText3"), writeColor(col)); } //[Reader] QuotedText3 } const QString misspellColor = group.readEntry(QLatin1String("misspelled_color")); if(!misspellColor.isEmpty()) { const QColor col = QColor(misspellColor); if(col.isValid()) { addKmailConfig(QLatin1String("Reader"), QLatin1String("MisspelledColor"), writeColor(col)); } } const QString uriColor = group.readEntry(QLatin1String("uri_color")); if(!uriColor.isEmpty()) { const QColor col(uriColor); if(col.isValid()) { addKmailConfig(QLatin1String("Reader"), QLatin1String("LinkColor"), writeColor(col)); } } const QString newColor = group.readEntry(QLatin1String("color_new")); if(!newColor.isEmpty()) { const QColor col(newColor); if(col.isValid()) { addKmailConfig(QLatin1String("MessageListView::Colors"), QLatin1String("UnreadMessageColor"), writeColor(col)); } } } }
void KAbstractHdrParserPrivate::writeScanline(float *dest, unsigned char *src, int scanline) { switch (m_yOrder) { case KAbstractHdrParser::Positive: for (int i = 0; i < m_xSize; ++i) { writeColor(&dest[scanline*m_xSize*3 + i*3], src[i], src[i + m_xSize], src[i + 2 * m_xSize], src[i + 3 * m_xSize]); } break; case KAbstractHdrParser::Negative: for (int i = 0; i < m_xSize; ++i) { writeColor(&dest[(m_ySize - scanline - 1)*m_xSize*3 + i*3], src[i], src[i + m_xSize], src[i + 2 * m_xSize], src[i + 3 * m_xSize]); } break; } }
void ConsoleWindow::write(QString data, MessageLevel::Enum mode) { QScrollBar *bar = ui->text->verticalScrollBar(); int max_bar = bar->maximum(); int val_bar = bar->value(); if(isVisible()) { if (m_scroll_active) { m_scroll_active = (max_bar - val_bar) <= 1; } else { m_scroll_active = val_bar == max_bar; } } if (data.endsWith('\n')) data = data.left(data.length() - 1); QStringList paragraphs = data.split('\n'); for (QString ¶graph : paragraphs) { paragraph = paragraph.trimmed(); } QListIterator<QString> iter(paragraphs); if (mode == MessageLevel::MultiMC) while (iter.hasNext()) writeColor(iter.next(), "blue", 0); else if (mode == MessageLevel::Error) while (iter.hasNext()) writeColor(iter.next(), "red", 0); else if (mode == MessageLevel::Warning) while (iter.hasNext()) writeColor(iter.next(), "orange", 0); else if (mode == MessageLevel::Fatal) while (iter.hasNext()) writeColor(iter.next(), "red", "black"); else if (mode == MessageLevel::Debug) while (iter.hasNext()) writeColor(iter.next(), "green", 0); else if (mode == MessageLevel::PrePost) while (iter.hasNext()) writeColor(iter.next(), "grey", 0); // TODO: implement other MessageLevels else while (iter.hasNext()) writeColor(iter.next(), 0, 0); if(isVisible()) { if (m_scroll_active) { bar->setValue(bar->maximum()); } m_last_scroll_value = bar->value(); } }
void XmlWriter::writeVariant( QXmlStreamWriter &stream, const QVariant &value ) { ASSERT_LIMITED_VARIANT( value ); if( value.isNull() || value.type() == QVariant::Invalid ) { stream.writeEmptyElement( "nil" ); } else if( value.type() == QVariant::Bool ) { stream.writeTextElement( "boolean", value.toBool() ? "true" : "false" ); } else if( value.type() == QVariant::ByteArray ) { stream.writeTextElement( "base64", value.toByteArray().toBase64() ); } else if( value.type() == QVariant::Color ) { writeColor( stream, value.value<QColor>() ); } else if( value.type() == QVariant::Date ) { stream.writeTextElement( "date", value.toDate().toString( Qt::ISODate ) ); } else if( value.type() == QVariant::DateTime ) { stream.writeTextElement( "datetime", value.toDateTime().toString( Qt::ISODate ) ); } else if( value.type() == QVariant::Double ) { stream.writeTextElement( "double", QString::number( value.toDouble() ) ); } else if( value.type() == QVariant::Hash ) { QHash<QString, QVariant> hash = value.toHash(); QHashIterator<QString, QVariant> it( hash ); stream.writeStartElement( "map" ); stream.writeAttribute( "type", "hash" ); while( it.hasNext() ) { it.next(); stream.writeStartElement( "item" ); stream.writeTextElement( "key", it.key() ); stream.writeStartElement( "value" ); writeVariant( stream, it.value() ); stream.writeEndElement(); // value stream.writeEndElement(); // item } stream.writeEndElement(); } else if( value.type() == QVariant::Image ) { QByteArray ba; QBuffer buffer( &ba ); buffer.open( QIODevice::WriteOnly ); value.value<QImage>().save( &buffer, "PNG" ); buffer.close(); stream.writeTextElement( "image", ba.toBase64() ); } else if( value.type() == QVariant::Int ) { stream.writeTextElement( "int", QString::number( value.toInt() ) ); } else if( value.type() == QVariant::List ) { stream.writeStartElement( "list" ); const QVariantList list = value.toList(); foreach( const QVariant & var, list ) { writeVariant( stream, var ); }
void MayaMeshWriter::writePoly( const Alembic::AbcGeom::OV2fGeomParam::Sample & iUVs) { MStatus status = MS::kSuccess; MFnMesh lMesh( mDagPath, &status ); if ( !status ) { MGlobal::displayError( "MFnMesh() failed for MayaMeshWriter" ); } std::vector<float> points; std::vector<Alembic::Util::int32_t> facePoints; std::vector<Alembic::Util::int32_t> pointCounts; fillTopology(points, facePoints, pointCounts); Alembic::AbcGeom::ON3fGeomParam::Sample normalsSamp; std::vector<float> normals; getPolyNormals(normals); if (!normals.empty()) { normalsSamp.setScope( Alembic::AbcGeom::kFacevaryingScope ); normalsSamp.setVals(Alembic::AbcGeom::N3fArraySample( (const Imath::V3f *) &normals.front(), normals.size() / 3)); } Alembic::AbcGeom::OPolyMeshSchema::Sample samp( Alembic::Abc::V3fArraySample((const Imath::V3f *)&points.front(), points.size() / 3), Alembic::Abc::Int32ArraySample(facePoints), Alembic::Abc::Int32ArraySample(pointCounts), iUVs, normalsSamp); // if this mesh is animated, write out the animated geometry if (mIsGeometryAnimated) { mPolySchema.set(samp); } else { mPolySchema.set(samp); } writeColor(); }
void XmlWriter::writeCategory( QXmlStreamWriter &stream, const Category *category ) { Q_ASSERT( category ); stream.writeStartElement( "category" ); stream.writeAttribute( "id", QString::number( categoryIdentifier( category ) ) ); stream.writeTextElement( "name", category->name() ); writeColor( stream, category->color() ); writeLimit( stream, category->minimumLimitEnabled(), category->minimumLimit(), category->maximumLimitEnabled(), category->maximumLimit() ); writeObjectData( stream, category ); for( int i = 0; i < category->countCategories(); ++i ) { writeCategory( stream, category->category( i ) ); } stream.writeEndElement(); // category }
void KdbxXmlWriter::writeMetadata() { m_xml.writeStartElement("Meta"); writeString("Generator", m_meta->generator()); if (m_kdbxVersion < KeePass2::FILE_VERSION_4 && !m_headerHash.isEmpty()) { writeBinary("HeaderHash", m_headerHash); } writeString("DatabaseName", m_meta->name()); writeDateTime("DatabaseNameChanged", m_meta->nameChanged()); writeString("DatabaseDescription", m_meta->description()); writeDateTime("DatabaseDescriptionChanged", m_meta->descriptionChanged()); writeString("DefaultUserName", m_meta->defaultUserName()); writeDateTime("DefaultUserNameChanged", m_meta->defaultUserNameChanged()); writeNumber("MaintenanceHistoryDays", m_meta->maintenanceHistoryDays()); writeColor("Color", m_meta->color()); writeDateTime("MasterKeyChanged", m_meta->masterKeyChanged()); writeNumber("MasterKeyChangeRec", m_meta->masterKeyChangeRec()); writeNumber("MasterKeyChangeForce", m_meta->masterKeyChangeForce()); writeMemoryProtection(); writeCustomIcons(); writeBool("RecycleBinEnabled", m_meta->recycleBinEnabled()); writeUuid("RecycleBinUUID", m_meta->recycleBin()); writeDateTime("RecycleBinChanged", m_meta->recycleBinChanged()); writeUuid("EntryTemplatesGroup", m_meta->entryTemplatesGroup()); writeDateTime("EntryTemplatesGroupChanged", m_meta->entryTemplatesGroupChanged()); writeUuid("LastSelectedGroup", m_meta->lastSelectedGroup()); writeUuid("LastTopVisibleGroup", m_meta->lastTopVisibleGroup()); writeNumber("HistoryMaxItems", m_meta->historyMaxItems()); writeNumber("HistoryMaxSize", m_meta->historyMaxSize()); if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) { writeDateTime("SettingsChanged", m_meta->settingsChanged()); } if (m_kdbxVersion < KeePass2::FILE_VERSION_4) { writeBinaries(); } writeCustomData(m_meta->customData()); m_xml.writeEndElement(); }
/******************************************************************************* * Parser Definitions ******************************************************************************/ bool KAbstractHdrParserPrivate::parse() { // Initialize lexer nextChar(); if(!readExpect("#?RADIANCE\n")) { qFatal("No #?RADIANCE header, the file may be corrupt or invalid."); return false; } forceValidate(); nextToken(); // Read the Key/Value pairs for (;;) { if (peekToken() == PT_ENDOFHEADER) break; switch (nextToken()) { case PT_ERROR: qFatal("Encountered an error! Aborting"); return false; case PT_EOF: return true; case PT_KEYVALUE: m_parser->onKeyValue(m_key.c_str(), m_value.c_str()); case PT_ENDOFHEADER: break; } } // Read the data parseDimension(); parseDimension(); m_parser->onResolution(m_xOrder, m_yOrder, m_xSize, m_ySize); // Start parsing the data Rgbe color; RleCode rle; float *dest = m_parser->beginData(); int count; size_t repeat = 0; unsigned invalidCount = 0; unsigned char *scanline = new unsigned char[4 * m_xSize]; unsigned char *ptr, *end; int scanlines = 0; color = nextColor(); while (scanlines != m_ySize) { // Check for invalid color which marks RLE pixel repeat // Consecutive repeat invalid pixels increments repeat count. if (color.r == 1 && color.g == 1 && color.b == 1) { qFatal("Untested! Possibly incorrect!"); while (color.r == 1 && color.g == 1 && color.b == 1) { repeat += (color.e << (invalidCount * 8)); color = nextColor(); ++invalidCount; } while (repeat) { writeColor(dest, color); --repeat; } } // Check for invalid color which marks per-element RLE if (color.r == 2 && color.g == 2) { // Check scanline width if (((color.b << 8) | color.e) != m_xSize) { qFatal("Incorrect encoded scanline width! Expected `%d`, got `%d`", m_xSize, int((color.r << 8) | color.e)); } // Read all channels ptr = &scanline[0]; int written = 0; for (int channel = 0; channel < 4; ++channel) { end = &scanline[(channel+1)*m_xSize]; while (ptr < end) { rle = nextRle(); if (rle.run > 128) { count = int(rle.run) - 128; Q_ASSERT(count != 0); Q_ASSERT(count <= end - ptr); while (count > 0) { ++written; *ptr++ = rle.color; --count; } } else { count = int(rle.run) - 1; Q_ASSERT(count != -1); Q_ASSERT(count <= end - ptr); *ptr++ = rle.color; ++written; while (count > 0) { ++written; *ptr++ = nextChar(); --count; } } } } // Output the scanline data writeScanline(dest, scanline, scanlines); ++scanlines; } color = nextColor(); } m_parser->endData(); delete [] scanline; return false; }
void KAbstractHdrParserPrivate::writeColor(float *dest, Rgbe color) { writeColor(dest, color.r, color.g, color.b, color.e); }
void nonRSB_drawPix(uint8_t rowNum) { //uint8_t *setting = &(settingBuffer[rowNum][0]); #if(defined(ROW_BUFFER) && ROW_BUFFER) uint8_t *color = &(rowBuffer[0]); #else uint8_t *color = &(frameBuffer[rowNum][0]); #endif /* DEonly_fromNada(); //Enable complementary-output for Green (on /OC1B, where CLK is OC1B) TCCR1A = ( (0<<COM1A1) | (1<<COM1A0) | (0<<COM1B1) | (1<<COM1B0) | (1<<PWM1A) | (1<<PWM1B) ); */ //The Greenish-bar on the left is due to the time it takes to execute // the first writeColor (since its value is only written at the END) // Thus the greenish-bar is about one write-color wide... //Judging by some weird experiences re v21/22, // it's not entirely likely this will be predictable // it may try to recalculate the Z register between writeBlues... // hopefully not, for now. I should probably assemblify this writeColor(*(color+0)); //Moving this here not only removes (most of) the green bar // but also seems to make the pixel edges significantly sharper // (v29 has ~1/8in of noise, v30 has ~1pixel noise at the right edge) TCCR1A = ( (0<<COM1A1) | (1<<COM1A0) | (0<<COM1B1) | (1<<COM1B0) | (1<<PWM1A) | (1<<PWM1B) ); writeColor(*(color+1)); writeColor(*(color+2)); writeColor(*(color+3)); writeColor(*(color+4)); writeColor(*(color+5)); writeColor(*(color+6)); writeColor(*(color+7)); writeColor(*(color+8)); writeColor(*(color+9)); writeColor(*(color+10)); writeColor(*(color+11)); writeColor(*(color+12)); writeColor(*(color+13)); writeColor(*(color+14)); writeColor(*(color+15)); #define COLORS_WRITTEN 16 #if ( (defined(COLOR_BAR_SCROLL) && COLOR_BAR_SCROLL) \ || (defined(ROW_BUFFER) && (ROW_BUFFER)) ) writeColor(*(color+16)); writeColor(*(color+17)); writeColor(*(color+18)); writeColor(*(color+19)); writeColor(*(color+20)); writeColor(*(color+21)); writeColor(*(color+22)); writeColor(*(color+23)); writeColor(*(color+24)); writeColor(*(color+25)); writeColor(*(color+26)); writeColor(*(color+27)); #define COLORS_WRITTEN 28 #if (defined(ROW_BUFFER) && (ROW_BUFFER)) writeColor(*(color+28)); writeColor(*(color+29)); writeColor(*(color+30)); writeColor(*(color+31)); //Some sort of syncing problem after 32... (?) writeColor(*(color+32)); writeColor(*(color+33)); writeColor(*(color+34)); writeColor(*(color+35)); writeColor(*(color+36)); writeColor(*(color+37)); writeColor(*(color+38)); writeColor(*(color+39)); writeColor(*(color+40)); writeColor(*(color+41)); writeColor(*(color+42)); writeColor(*(color+43)); writeColor(*(color+44)); writeColor(*(color+45)); writeColor(*(color+46)); writeColor(*(color+47)); writeColor(*(color+48)); writeColor(*(color+49)); writeColor(*(color+50)); writeColor(*(color+51)); writeColor(*(color+52)); writeColor(*(color+53)); writeColor(*(color+54)); writeColor(*(color+55)); writeColor(*(color+56)); writeColor(*(color+57)); writeColor(*(color+58)); writeColor(*(color+59)); writeColor(*(color+60)); writeColor(*(color+61)); writeColor(*(color+62)); writeColor(*(color+63)); // WriteColor writes the pixel *after* the calculations... // thus the pixel appears basically after writeColor completes // These nops assure the 64th pixel is fully-displayed before exitting // (Not sure how the other following instructions apply to this) // The number of nops was found experimentally... asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); asm("nop"); //count "0" below, as well.. #define COLORS_WRITTEN 65 #endif //ROW_BUFFER #else // writeColor(0); #endif //COLOR_BARS || ROW_BUFFER /* reg[17] = colorBuffer[rowNum][17]; writeColor(reg[17]); ... reg[20] = colorBuffer[rowNum][20]; writeColor(reg[20]); //REPEATING to fill screen... (delayDots = 342 worked prior to this) reg[0] = colorBuffer[rowNum][0]; writeColor(reg[0]); ... reg[10] = colorBuffer[rowNum][10]; writeColor(reg[10]); */ //Display the rest as black... writeColor(0); //writeColor(0xff); //delay_Dots(500);//142); //Don't want to disable DE too early... //900 leaves a buffer for various calculations while also showing // a blue bar at the right-side... //LTN Last Used 900 // -68 is from 900's intent, IIRC // seems arbitrary, but its value (especially if too small) // causes blank lines... (?!) // -60 makes more sense for a delay (was the original post-900) // (outside DOTS_TO_CYC because it's for cycles used for calcs... // -68 worked for LVDS_PRE=2 // -60 for 1 // 4 doesn't work... blue-lines //a/o v60 //From Here Down, everything has only been tested recently with rowSegBuf // I did a nice #if-#else scheme which makes this redundant // with what's in rsb_drawPix()... // a/o v59-12ish... ROW_COMPLETION_DELAY uses were already commented-out // BUT WHY WAS IT REMOVED?! Seems to help, now. // // Some Experimenting has led to the conclusion: // DE's active-duration needn't be exact. In fact, it can be *way* off // White is shown between the end of drawSegs, and cyan is shown after // ROW_COMPLETION_DELAY (which, for now, is constant, regardless of how // many pixels were drawn) // Almost immediately after the ROW_COMPLETION_DELAY (when it turns cyan) // DE is disabled // Yet the remainder of the screen still fills with cyan. // THUS: Disabling DE before the end of the screen appears to have the // effect of either not being acknowledged, or of repeating the last // color (untested) // Also, DE durations that are *longer* than the screen, seem to be // absorbed by nonexistent pixels to the left... // (setting ROW_COMPLETION_DELAY==65535 unreasonably high, // just shows white at the right side, and still syncs) // Now, the original problem was that there seemed to be some carry-over // which maybe due to DEs that are EXTRAORDINARILY long? // NO! // Actually, it appears to be due to DEs that are TOO SHORT (?) // (setting ROW_COMPLETION_DELAY to 0 causes the problem again) // Doesn't appear to be *entirely* scientific, as using SEG_SINE // would suggest that these (now cyan) bars would appear at the troughs // in the diagonal-color-stripes at the top... // they seem, instead to be somewhat random, though maybe more common // at those locations. // But Wait! Setting ROW_COMPLETION_DELAY to 1 fixes it again. // realistically, that should be nothing more than a single nop; no? // (Maybe not, with a few cycles to entry, and minimum execution times) // a handful of nops does the trick, as well. // So is it a problem with too short a DE, or is it a matter of // e.g. the last segment drawn is setting new values that might only // be *completely transmitted* after a full PWM cycle... // So maybe somehow that last transaction is being interrupted // by the TCCR1A settings, or new values... // Plausible. // // FURTHER. Lest it be revisited. It was noted elsewhere that I thought // this display was NOT DE-Only. In fact, the datasheet specifically says // "DE-Only Mode" /*#define ROW_COMPLETION_DELAY \ (DOTS_TO_CYC(DE_ACTIVE_DOTS) -60 \ - WRITE_COLOR_CYCS * COLORS_WRITTEN) */ #define ROW_COMPLETION_DELAY 512 //1 //65535//512 //#error "should add SEG_STRETCH here..." #if (ROW_COMPLETION_DELAY > 0) // delay_cyc(DOTS_TO_CYC(DE_ACTIVE_DOTS) -60 // - 68)// - 60 // - WRITE_COLOR_CYCS*COLORS_WRITTEN); delay_cyc(ROW_COMPLETION_DELAY); // asm("nop;"); // asm("nop;"); // asm("nop;"); // asm("nop;"); // asm("nop;"); // asm("nop;"); // asm("nop;"); // asm("nop;"); #else #warning "ROW_COMPLETION_DELAY <= 0" #endif //Just for testing... // Actually, it's quite handy, because it shows where drawSegs has // completed... (I thought it stretched to the end of DE, but nope) // The "bug" with PLL_SYSCLK's white bars now appears to be quite // apparently due to carry-over from a previous line // rather than an Hsync problem, as now it appears cyan. OCR1D = 0; //DE->Nada transition expects fullBlue... //Also helps to show the edge of the DE timing... //!!! Not sure what the state is at this point... // could be any DE+Blue level, or could be NADA... // Nada: DT1=3, still leaves one bit for clocking, might be OK //Among the things that don't make sense... // This appears to go into affect BEFORE delay_cyc (?) // as, without a pull-up resistor on the /OC1B output, // green seems to be floating between the last pixel and the // delay_cyc (!) //Disable complementary-output for Green // (on /OC1B, where CLK is OC1B) // Since Nada, V, and H DT's might be bad for clocking. TCCR1A = ( (0<<COM1A1) | (1<<COM1A0) | (1<<COM1B1) | (0<<COM1B0) | (1<<PWM1A) | (1<<PWM1B) ); fullBlue(); Nada_fromDEonly(); }
// reading, writing of .creatortheme ini file //////////////////////////////// void Theme::writeSettings(const QString &filename) const { QSettings settings(filename, QSettings::IniFormat); const QMetaObject &m = *metaObject(); { settings.setValue(QLatin1String("ThemeName"), d->name); settings.setValue(QLatin1String("PreferredStyles"), d->preferredStyles); } { settings.beginGroup(QLatin1String("Palette")); for (int i = 0, total = d->colors.size(); i < total; ++i) { const QPair<QColor, QString> var = d->colors[i]; if (var.second.isEmpty()) continue; settings.setValue(var.second, writeColor(var.first)); } settings.endGroup(); } { settings.beginGroup(QLatin1String("Colors")); const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color")); for (int i = 0, total = e.keyCount(); i < total; ++i) { const QString key = QLatin1String(e.key(i)); const QPair<QColor, QString> var = d->colors[i]; if (!var.second.isEmpty()) settings.setValue(key, var.second); // named color else settings.setValue(key, writeColor(var.first)); } settings.endGroup(); } { settings.beginGroup(QLatin1String("ImageFiles")); const QMetaEnum e = m.enumerator(m.indexOfEnumerator("ImageFile")); for (int i = 0, total = e.keyCount(); i < total; ++i) { const QString key = QLatin1String(e.key(i)); const QString &var = d->imageFiles.at(i); if (!var.isEmpty()) settings.setValue(key, var); } settings.endGroup(); } { settings.beginGroup(QLatin1String("Gradients")); const QMetaEnum e = m.enumerator(m.indexOfEnumerator("Gradient")); for (int i = 0, total = e.keyCount(); i < total; ++i) { const QString key = QLatin1String(e.key(i)); QGradientStops stops = gradient(static_cast<Theme::Gradient>(i)); settings.beginWriteArray(key); int k = 0; foreach (const QGradientStop stop, stops) { settings.setArrayIndex(k); settings.setValue(QLatin1String("pos"), stop.first); settings.setValue(QLatin1String("color"), writeColor(stop.second)); ++k; } settings.endArray(); } settings.endGroup(); }
void KdbxXmlWriter::writeEntry(const Entry* entry) { Q_ASSERT(!entry->uuid().isNull()); m_xml.writeStartElement("Entry"); writeUuid("UUID", entry->uuid()); writeNumber("IconID", entry->iconNumber()); if (!entry->iconUuid().isNull()) { writeUuid("CustomIconUUID", entry->iconUuid()); } writeColor("ForegroundColor", entry->foregroundColor()); writeColor("BackgroundColor", entry->backgroundColor()); writeString("OverrideURL", entry->overrideUrl()); writeString("Tags", entry->tags()); writeTimes(entry->timeInfo()); const QList<QString> attributesKeyList = entry->attributes()->keys(); for (const QString& key : attributesKeyList) { m_xml.writeStartElement("String"); // clang-format off bool protect = (((key == "Title") && m_meta->protectTitle()) || ((key == "UserName") && m_meta->protectUsername()) || ((key == "Password") && m_meta->protectPassword()) || ((key == "URL") && m_meta->protectUrl()) || ((key == "Notes") && m_meta->protectNotes()) || entry->attributes()->isProtected(key)); // clang-format on writeString("Key", key); m_xml.writeStartElement("Value"); QString value; if (protect) { if (!m_innerStreamProtectionDisabled && m_randomStream) { m_xml.writeAttribute("Protected", "True"); bool ok; QByteArray rawData = m_randomStream->process(entry->attributes()->value(key).toUtf8(), &ok); if (!ok) { raiseError(m_randomStream->errorString()); } value = QString::fromLatin1(rawData.toBase64()); } else { m_xml.writeAttribute("ProtectInMemory", "True"); value = entry->attributes()->value(key); } } else { value = entry->attributes()->value(key); } if (!value.isEmpty()) { m_xml.writeCharacters(stripInvalidXml10Chars(value)); } m_xml.writeEndElement(); m_xml.writeEndElement(); } const QList<QString> attachmentsKeyList = entry->attachments()->keys(); for (const QString& key : attachmentsKeyList) { m_xml.writeStartElement("Binary"); writeString("Key", key); m_xml.writeStartElement("Value"); m_xml.writeAttribute("Ref", QString::number(m_idMap[entry->attachments()->value(key)])); m_xml.writeEndElement(); m_xml.writeEndElement(); } writeAutoType(entry); if (m_kdbxVersion >= KeePass2::FILE_VERSION_4) { writeCustomData(entry->customData()); } // write history only for entries that are not history items if (entry->parent()) { writeEntryHistory(entry); } m_xml.writeEndElement(); }
void MayaMeshWriter::writeSubD( const Alembic::AbcGeom::OV2fGeomParam::Sample & iUVs) { MStatus status = MS::kSuccess; MFnMesh lMesh( mDagPath, &status ); if ( !status ) { MGlobal::displayError( "MFnMesh() failed for MayaMeshWriter" ); } std::vector<float> points; std::vector<Alembic::Util::int32_t> facePoints; std::vector<Alembic::Util::int32_t> pointCounts; fillTopology(points, facePoints, pointCounts); Alembic::AbcGeom::OSubDSchema::Sample samp( Alembic::AbcGeom::V3fArraySample((const Imath::V3f *)&points.front(), points.size() / 3), Alembic::Abc::Int32ArraySample(facePoints), Alembic::Abc::Int32ArraySample(pointCounts)); samp.setUVs( iUVs ); MPlug plug = lMesh.findPlug("faceVaryingInterpolateBoundary"); if (!plug.isNull()) samp.setFaceVaryingInterpolateBoundary(plug.asInt()); plug = lMesh.findPlug("interpolateBoundary"); if (!plug.isNull()) samp.setInterpolateBoundary(plug.asInt()); plug = lMesh.findPlug("faceVaryingPropagateCorners"); if (!plug.isNull()) samp.setFaceVaryingPropagateCorners(plug.asInt()); std::vector <Alembic::Util::int32_t> creaseIndices; std::vector <Alembic::Util::int32_t> creaseLengths; std::vector <float> creaseSharpness; std::vector <Alembic::Util::int32_t> cornerIndices; std::vector <float> cornerSharpness; MUintArray edgeIds; MDoubleArray creaseData; if (lMesh.getCreaseEdges(edgeIds, creaseData) == MS::kSuccess) { unsigned int numCreases = creaseData.length(); creaseIndices.resize(numCreases * 2); creaseLengths.resize(numCreases, 2); creaseSharpness.resize(numCreases); for (unsigned int i = 0; i < numCreases; ++i) { int verts[2]; lMesh.getEdgeVertices(edgeIds[i], verts); creaseIndices[2 * i] = verts[0]; creaseIndices[2 * i + 1] = verts[1]; creaseSharpness[i] = static_cast<float>(creaseData[i]); } samp.setCreaseIndices(Alembic::Abc::Int32ArraySample(creaseIndices)); samp.setCreaseLengths(Alembic::Abc::Int32ArraySample(creaseLengths)); samp.setCreaseSharpnesses( Alembic::Abc::FloatArraySample(creaseSharpness)); } MUintArray cornerIds; MDoubleArray cornerData; if (lMesh.getCreaseVertices(cornerIds, cornerData) == MS::kSuccess) { unsigned int numCorners = cornerIds.length(); cornerIndices.resize(numCorners); cornerSharpness.resize(numCorners); for (unsigned int i = 0; i < numCorners; ++i) { cornerIndices[i] = cornerIds[i]; cornerSharpness[i] = static_cast<float>(cornerData[i]); } samp.setCornerSharpnesses( Alembic::Abc::FloatArraySample(cornerSharpness)); samp.setCornerIndices( Alembic::Abc::Int32ArraySample(cornerIndices)); } #if MAYA_API_VERSION >= 201100 MUintArray holes = lMesh.getInvisibleFaces(); unsigned int numHoles = holes.length(); std::vector <Alembic::Util::int32_t> holeIndices(numHoles); for (unsigned int i = 0; i < numHoles; ++i) { holeIndices[i] = holes[i]; } if (!holeIndices.empty()) { samp.setHoles(holeIndices); } #endif mSubDSchema.set(samp); writeColor(); writeUVSets(); }
MayaMeshWriter::MayaMeshWriter(MDagPath & iDag, Alembic::Abc::OObject & iParent, Alembic::Util::uint32_t iTimeIndex, const JobArgs & iArgs, GetMembersMap& gmMap) : mNoNormals(iArgs.noNormals), mWriteUVs(iArgs.writeUVs), mWriteColorSets(iArgs.writeColorSets), mWriteUVSets(iArgs.writeUVSets), mIsGeometryAnimated(false), mDagPath(iDag) { MStatus status = MS::kSuccess; MFnMesh lMesh( mDagPath, &status ); if ( !status ) { MGlobal::displayError( "MFnMesh() failed for MayaMeshWriter" ); } // intermediate objects aren't translated MObject surface = iDag.node(); if (iTimeIndex != 0 && util::isAnimated(surface)) { mIsGeometryAnimated = true; } else { iTimeIndex = 0; } std::vector<float> uvs; std::vector<Alembic::Util::uint32_t> indices; std::string uvSetName; MString name = lMesh.name(); name = util::stripNamespaces(name, iArgs.stripNamespace); // check to see if this poly has been tagged as a SubD MPlug plug = lMesh.findPlug("SubDivisionMesh"); if ( !plug.isNull() && plug.asBool() ) { Alembic::AbcGeom::OSubD obj(iParent, name.asChar(), iTimeIndex); mSubDSchema = obj.getSchema(); Alembic::AbcGeom::OV2fGeomParam::Sample uvSamp; if (mWriteUVs || mWriteUVSets) { getUVs(uvs, indices, uvSetName); if (!uvs.empty()) { if (!uvSetName.empty()) { mSubDSchema.setUVSourceName(uvSetName); } uvSamp.setScope( Alembic::AbcGeom::kFacevaryingScope ); uvSamp.setVals(Alembic::AbcGeom::V2fArraySample( (const Imath::V2f *) &uvs.front(), uvs.size() / 2)); if (!indices.empty()) { uvSamp.setIndices(Alembic::Abc::UInt32ArraySample( &indices.front(), indices.size())); } } } Alembic::Abc::OCompoundProperty cp; Alembic::Abc::OCompoundProperty up; if (AttributesWriter::hasAnyAttr(lMesh, iArgs)) { cp = mSubDSchema.getArbGeomParams(); up = mSubDSchema.getUserProperties(); } mAttrs = AttributesWriterPtr(new AttributesWriter(cp, up, obj, lMesh, iTimeIndex, iArgs)); writeSubD(uvSamp); } else { Alembic::AbcGeom::OPolyMesh obj(iParent, name.asChar(), iTimeIndex); mPolySchema = obj.getSchema(); Alembic::AbcGeom::OV2fGeomParam::Sample uvSamp; if (mWriteUVs || mWriteUVSets) { getUVs(uvs, indices, uvSetName); if (!uvs.empty()) { if (!uvSetName.empty()) { mPolySchema.setUVSourceName(uvSetName); } uvSamp.setScope( Alembic::AbcGeom::kFacevaryingScope ); uvSamp.setVals(Alembic::AbcGeom::V2fArraySample( (const Imath::V2f *) &uvs.front(), uvs.size() / 2)); if (!indices.empty()) { uvSamp.setIndices(Alembic::Abc::UInt32ArraySample( &indices.front(), indices.size())); } } } Alembic::Abc::OCompoundProperty cp; Alembic::Abc::OCompoundProperty up; if (AttributesWriter::hasAnyAttr(lMesh, iArgs)) { cp = mPolySchema.getArbGeomParams(); up = mPolySchema.getUserProperties(); } // set the rest of the props and write to the writer node mAttrs = AttributesWriterPtr(new AttributesWriter(cp, up, obj, lMesh, iTimeIndex, iArgs)); writePoly(uvSamp); } if (mWriteColorSets) { MStringArray colorSetNames; lMesh.getColorSetNames(colorSetNames); if (colorSetNames.length() > 0) { // Create the color sets compound prop Alembic::Abc::OCompoundProperty arbParams; if (mPolySchema.valid()) { arbParams = mPolySchema.getArbGeomParams(); } else { arbParams = mSubDSchema.getArbGeomParams(); } std::string currentColorSet = lMesh.currentColorSetName().asChar(); for (unsigned int i=0; i < colorSetNames.length(); ++i) { // Create an array property for each color set std::string colorSetPropName = colorSetNames[i].asChar(); Alembic::AbcCoreAbstract::MetaData md; if (currentColorSet == colorSetPropName) { md.set("mayaColorSet", "1"); } else { md.set("mayaColorSet", "0"); } if (lMesh.getColorRepresentation(colorSetNames[i]) == MFnMesh::kRGB) { Alembic::AbcGeom::OC3fGeomParam colorProp(arbParams, colorSetPropName, true, Alembic::AbcGeom::kFacevaryingScope, 1, iTimeIndex, md); mRGBParams.push_back(colorProp); } else { Alembic::AbcGeom::OC4fGeomParam colorProp(arbParams, colorSetPropName, true, Alembic::AbcGeom::kFacevaryingScope, 1, iTimeIndex, md); mRGBAParams.push_back(colorProp); } } writeColor(); } } if (mWriteUVSets) { MStringArray uvSetNames; lMesh.getUVSetNames(uvSetNames); unsigned int uvSetNamesLen = uvSetNames.length(); if (uvSetNamesLen > 1) { // Create the uv sets compound prop Alembic::Abc::OCompoundProperty arbParams; if (mPolySchema.valid()) { arbParams = mPolySchema.getArbGeomParams(); } else { arbParams = mSubDSchema.getArbGeomParams(); } MString currentUV = lMesh.currentUVSetName(); for (unsigned int i = 0; i < uvSetNamesLen; ++i) { // Create an array property for each uv set MString uvSetPropName = uvSetNames[i]; // the current UV set gets mapped to the primary UVs if (currentUV == uvSetPropName) { continue; } if (uvSetPropName.length() > 0 && lMesh.numUVs(uvSetPropName) > 0) { mUVparams.push_back(Alembic::AbcGeom::OV2fGeomParam( arbParams, uvSetPropName.asChar(), true, Alembic::AbcGeom::kFacevaryingScope, 1, iTimeIndex)); } } writeUVSets(); } } // write out facesets if(!iArgs.writeFaceSets) return; // get the connected shading engines MObjectArray connSGObjs (getOutConnectedSG(mDagPath)); const unsigned int sgCount = connSGObjs.length(); for (unsigned int i = 0; i < sgCount; ++i) { MObject connSGObj, compObj; connSGObj = connSGObjs[i]; MFnDependencyNode fnDepNode(connSGObj); MString connSgObjName = fnDepNode.name(); // retrive the component MObject status = getSetComponents(mDagPath, connSGObj, gmMap, compObj); if (status != MS::kSuccess) { // for some reason the shading group doesn't represent a face set continue; } // retrieve the face indices MIntArray indices; MFnSingleIndexedComponent compFn; compFn.setObject(compObj); compFn.getElements(indices); const unsigned int numData = indices.length(); // encountered the whole object mapping. skip it. if (numData == 0) continue; std::vector<Alembic::Util::int32_t> faceIndices(numData); for (unsigned int j = 0; j < numData; ++j) { faceIndices[j] = indices[j]; } connSgObjName = util::stripNamespaces(connSgObjName, iArgs.stripNamespace); Alembic::AbcGeom::OFaceSet faceSet; std::string faceSetName(connSgObjName.asChar()); MPlug abcFacesetNamePlug = fnDepNode.findPlug("AbcFacesetName", true); if (!abcFacesetNamePlug.isNull()) { faceSetName = abcFacesetNamePlug.asString().asChar(); } if (mPolySchema.valid()) { if (mPolySchema.hasFaceSet(faceSetName)) { faceSet = mPolySchema.getFaceSet(faceSetName); } else { faceSet = mPolySchema.createFaceSet(faceSetName); } } else { if (mSubDSchema.hasFaceSet(faceSetName)) { faceSet = mSubDSchema.getFaceSet(faceSetName); } else { faceSet = mSubDSchema.createFaceSet(faceSetName); } } Alembic::AbcGeom::OFaceSetSchema::Sample samp; samp.setFaces(Alembic::Abc::Int32ArraySample(faceIndices)); Alembic::AbcGeom::OFaceSetSchema faceSetSchema = faceSet.getSchema(); faceSetSchema.set(samp); faceSetSchema.setFaceExclusivity(Alembic::AbcGeom::kFaceSetExclusive); MFnDependencyNode iNode(connSGObj); Alembic::Abc::OCompoundProperty cp; Alembic::Abc::OCompoundProperty up; if (AttributesWriter::hasAnyAttr(iNode, iArgs)) { cp = faceSetSchema.getArbGeomParams(); up = faceSetSchema.getUserProperties(); } AttributesWriter attrWriter(cp, up, faceSet, iNode, iTimeIndex, iArgs); attrWriter.write(); } }