void setup() { bytesWritten = 0; G_MAGIC_NUMBER_MAX_RAW_CONTEXT_DISTANCE = std::sqrt(G_MAGIC_NUMBER_CONTEXT_SIZE_IN_BYTES * std::pow(G_MAGIC_NUMBER_MAX_SYMBOL_VALUE,2)); FILE* pFile; pFile = std::fopen("/mnt/local/gdrive/public/lippmann/ckolmogorov/ckolmogorov/data/primes.bin" ,"rb"); fseek(pFile,0,SEEK_END); fileIndexType fileSize = ftell(pFile); fseek(pFile,0,SEEK_SET); double* thePrimeArray = new double[fileSize/sizeof(double)]; fread(thePrimeArray,sizeof(double),fileSize/sizeof(double),pFile); thePrimes = vectorType(fileSize/sizeof(double)); for (fileIndexType i = 0; i<fileSize/sizeof(double); i++) { thePrimes(i) = thePrimeArray[i]; } assert(thePrimes(fileSize/sizeof(double)-1) == 4256227); delete[] thePrimeArray; }
void run() { if (_arguments.count() == 1) { printf("Usage: image_resample <config file path>\n"); return; } ConfigFile config; List<StructuredType::Member> vectorMembers; vectorMembers.add(StructuredType::Member(String("x"), Type::integer)); vectorMembers.add(StructuredType::Member(String("y"), Type::integer)); StructuredType vectorType(String("Vector"), vectorMembers); config.addType(vectorType); config.addOption("inputPicture", Type::string); config.addOption("outputSize", vectorType); config.addOption("subpixels", Type::boolean); config.addOption("tripleResolution", Type::boolean); config.addOption("outputPicture", Type::string); config.load(_arguments[1]); Bitmap<SRGB> input; input.load(File(config.get<String>("inputPicture"))); Bitmap<Vector3<float> > linearInput(input.size()); input.convert(linearInput, ConvertSRGBToLinear()); Array<Any> sizeArray = config.get<List<Any> >("outputSize"); Vector size(sizeArray[0].value<int>(), sizeArray[1].value<int>()); Bitmap<Vector3<float> > linearOutput(size); if (config.get<bool>("subpixels")) linearInput.subPixelResample(&linearOutput, config.get<bool>("tripleResolution")); else linearInput.resample(&linearOutput); Bitmap<SRGB> output(linearOutput.size()); linearOutput.convert(output, ConvertLinearToSRGB()); output.save(File(config.get<String>("outputPicture"))); }
MStatus dynExprField::compute(const MPlug& plug, MDataBlock& block) // // Descriptions: // compute output force. // { MStatus status; if( !(plug == mOutputForce) ) return( MS::kUnknownParameter ); // get the logical index of the element this plug refers to. // int multiIndex = plug.logicalIndex( &status ); McheckErr(status, "ERROR in plug.logicalIndex.\n"); // Get input data handle, use outputArrayValue since we do not // want to evaluate both inputs, only the one related to the // requested multiIndex. Evaluating both inputs at once would cause // a dependency graph loop. MArrayDataHandle hInputArray = block.outputArrayValue( mInputData, &status ); McheckErr(status,"ERROR in hInputArray = block.outputArrayValue().\n"); status = hInputArray.jumpToElement( multiIndex ); McheckErr(status, "ERROR: hInputArray.jumpToElement failed.\n"); // get children of aInputData. MDataHandle hCompond = hInputArray.inputValue( &status ); McheckErr(status, "ERROR in hCompond=hInputArray.inputValue\n"); MDataHandle hPosition = hCompond.child( mInputPositions ); MObject dPosition = hPosition.data(); MFnVectorArrayData fnPosition( dPosition ); MVectorArray points = fnPosition.array( &status ); McheckErr(status, "ERROR in fnPosition.array(), not find points.\n"); // Comment out the following since velocity, and mass are // not needed in this field. // // MDataHandle hVelocity = hCompond.child( mInputVelocities ); // MObject dVelocity = hVelocity.data(); // MFnVectorArrayData fnVelocity( dVelocity ); // MVectorArray velocities = fnVelocity.array( &status ); // McheckErr(status, "ERROR in fnVelocity.array(), not find velocities.\n"); // // MDataHandle hMass = hCompond.child( mInputMass ); // MObject dMass = hMass.data(); // MFnDoubleArrayData fnMass( dMass ); // MDoubleArray masses = fnMass.array( &status ); // McheckErr(status, "ERROR in fnMass.array(), not find masses.\n"); // The attribute mInputPPData contains the attribute in an array form // parpared by the particleShape if the particleShape has per particle // attribute fieldName_attrName. // // Suppose a field with the name dynExprField1 is connecting to // particleShape1, and the particleShape1 has per particle float attribute // dynExprField1_magnitude and vector attribute dynExprField1_direction, // then hInputPPArray will contains a MdoubleArray with the corresponding // name "magnitude" and a MvectorArray with the name "direction". This // is a mechanism to allow the field attributes being driven by dynamic // expression. MArrayDataHandle mhInputPPData = block.inputArrayValue( mInputPPData, &status ); McheckErr(status,"ERROR in mhInputPPData = block.inputArrayValue().\n"); status = mhInputPPData.jumpToElement( multiIndex ); McheckErr(status, "ERROR: mhInputPPArray.jumpToElement failed.\n"); MDataHandle hInputPPData = mhInputPPData.inputValue( &status ); McheckErr(status, "ERROR in hInputPPData = mhInputPPData.inputValue\n"); MObject dInputPPData = hInputPPData.data(); MFnArrayAttrsData inputPPArray( dInputPPData ); MDataHandle hOwnerPPData = block.inputValue( mOwnerPPData, &status ); McheckErr(status, "ERROR in hOwnerPPData = block.inputValue\n"); MObject dOwnerPPData = hOwnerPPData.data(); MFnArrayAttrsData ownerPPArray( dOwnerPPData ); const MString magString("magnitude"); MFnArrayAttrsData::Type doubleType(MFnArrayAttrsData::kDoubleArray); bool arrayExist; MDoubleArray magnitudeArray; arrayExist = inputPPArray.checkArrayExist(magString, doubleType, &status); // McheckErr(status, "ERROR in checkArrayExist(magnitude)\n"); if(arrayExist) { magnitudeArray = inputPPArray.getDoubleData(magString, &status); // McheckErr(status, "ERROR in inputPPArray.doubleArray(magnitude)\n"); } MDoubleArray magnitudeOwnerArray; arrayExist = ownerPPArray.checkArrayExist(magString, doubleType, &status); // McheckErr(status, "ERROR in checkArrayExist(magnitude)\n"); if(arrayExist) { magnitudeOwnerArray = ownerPPArray.getDoubleData(magString, &status); // McheckErr(status, "ERROR in ownerPPArray.doubleArray(magnitude)\n"); } const MString dirString("direction"); MFnArrayAttrsData::Type vectorType(MFnArrayAttrsData::kVectorArray); arrayExist = inputPPArray.checkArrayExist(dirString, vectorType, &status); MVectorArray directionArray; // McheckErr(status, "ERROR in checkArrayExist(direction)\n"); if(arrayExist) { directionArray = inputPPArray.getVectorData(dirString, &status); // McheckErr(status, "ERROR in inputPPArray.vectorArray(direction)\n"); } arrayExist = ownerPPArray.checkArrayExist(dirString, vectorType, &status); MVectorArray directionOwnerArray; // McheckErr(status, "ERROR in checkArrayExist(direction)\n"); if(arrayExist) { directionOwnerArray = ownerPPArray.getVectorData(dirString, &status); // McheckErr(status, "ERROR in ownerPPArray.vectorArray(direction)\n"); } // Compute the output force. // MVectorArray forceArray; apply( block, points.length(), magnitudeArray, magnitudeOwnerArray, directionArray, directionOwnerArray, forceArray ); // get output data handle // MArrayDataHandle hOutArray = block.outputArrayValue( mOutputForce, &status); McheckErr(status, "ERROR in hOutArray = block.outputArrayValue.\n"); MArrayDataBuilder bOutArray = hOutArray.builder( &status ); McheckErr(status, "ERROR in bOutArray = hOutArray.builder.\n"); // get output force array from block. // MDataHandle hOut = bOutArray.addElement(multiIndex, &status); McheckErr(status, "ERROR in hOut = bOutArray.addElement.\n"); MFnVectorArrayData fnOutputForce; MObject dOutputForce = fnOutputForce.create( forceArray, &status ); McheckErr(status, "ERROR in dOutputForce = fnOutputForce.create\n"); // update data block with new output force data. // hOut.set( dOutputForce ); block.setClean( plug ); return( MS::kSuccess ); }
KoFilter::ConversionStatus ExportHtml::extractImages(KoStore *odfStore, HtmlFile *htmlFile) { // Extract images and add them to htmlFile one by one QByteArray imgContent; int imgId = 1; foreach (const QString &imgSrc, m_imagesSrcList.keys()) { kDebug(30503) << imgSrc; if (!odfStore->extractFile(imgSrc, imgContent)) { kDebug(30503) << "Can not to extract file"; return KoFilter::FileNotFound; } #if 1 htmlFile->addContentFile(("image" + QString::number(imgId)), // id (htmlFile->filePrefix() + imgSrc.section('/', -1)), // filename m_manifest.value(imgSrc).toUtf8(), imgContent); #else VectorType type = vectorType(imgContent); QSizeF qSize = m_imagesSrcList.value(imgSrc); switch (type) { case ExportHtml::VectorTypeSvm: { kDebug(30503) << "Svm file"; QSize size(qSize.width(), qSize.height()); QByteArray output; if (!convertSvm(imgContent, output, size)) { kDebug(30503) << "Svm Parse error"; return KoFilter::ParsingError; } epubFile->addContentFile(("image" + QString::number(imgId)), (epubFile->pathPrefix() + imgSrc.section('/', -1)), "image/svg+xml", output); break; } case ExportHtml::VectorTypeEmf: { kDebug(30503) << "EMF file"; QSize size(qSize.width(), qSize.height()); QByteArray output; if (!convertEmf(imgContent, output, size)) { kDebug(30503) << "EMF Parse error"; return KoFilter::ParsingError; } epubFile->addContentFile(("image" + QString::number(imgId)), (epubFile->pathPrefix() + imgSrc.section('/', -1)), "image/svg+xml", output); break; } case ExportHtml::VectorTypeWmf: { kDebug(30503) << "WMF file"; QByteArray output; if (!convertWmf(imgContent, output, qSize)) { kDebug(30503) << "WMF Parse error"; return KoFilter::ParsingError; } epubFile->addContentFile(("image" + QString::number(imgId)), (epubFile->pathPrefix() + imgSrc.section('/', -1)), "image/svg+xml", output); break; } // If it's not one of the types we can convert, let's just // assume that the image can be used as it is. The user // will find out soon anyway when s/he tries to look at // the image. case ExportHtml::VectorTypeOther: { kDebug(30503) << "Other file"; epubFile->addContentFile(("image" + QString::number(imgId)), (epubFile->pathPrefix() + imgSrc.section('/', -1)), m_manifest.value(imgSrc).toUtf8(), imgContent); break; } default: kDebug(30503) << ""; } #endif } return KoFilter::OK; }