void test(const char* proc_name,const TDrawMandelbrotProc fproc){
    const long max_iter=1000;
    TViewRect rect;
    rect.x0=-0.5;
    rect.y0=0;
    rect.r=2;

    TPixels32 dstPic;
    dstPic.resizeFast(640,480);

    std::cout<<proc_name<<": ";
    fproc(dstPic.getRef(),rect,max_iter);
    std::cout<<" ok"<<std::endl;

    { //save pic
        std::string dstFileName(proc_name);
        dstFileName+=".bmp";
#if defined(__APPLE__) && defined(__MACH__)
        TFileOutputStream bmpOutStream("/Users/hss/Desktop/GraphicDemo/ColorToGray/"+dstFileName);
#else
        TFileOutputStream bmpOutStream(dstFileName.c_str());
#endif
        TBmpFile::save(dstPic.getRef(),&bmpOutStream);//保存结果图片
    }
}
void KisAslLayerStyleSerializerTest::testReadMultipleStyles()
{
    KisPSDLayerStyleSP style(new KisPSDLayerStyle());

    QVector<KisPSDLayerStyleSP> styles;

    {
        KisAslLayerStyleSerializer s;

        QString srcFileName(TestUtil::fetchDataFileLazy("asl/multiple_styles.asl"));
        QFile aslFile(srcFileName);
        aslFile.open(QIODevice::ReadOnly);
        s.readFromDevice(&aslFile);

        styles = s.styles();
    }


    {
        KisAslLayerStyleSerializer s;

        QString dstFileName("multiple_styles_out.asl");
        QFile aslFile(dstFileName);
        aslFile.open(QIODevice::WriteOnly);

        s.setStyles(styles);
        s.saveToDevice(&aslFile);
    }

    {
        KisAslLayerStyleSerializer s;

        QString srcFileName("multiple_styles_out.asl");
        QFile aslFile(srcFileName);
        aslFile.open(QIODevice::ReadOnly);
        s.readFromDevice(&aslFile);

        styles = s.styles();

        dbgKrita << ppVar(styles.size());
    }
}
void test(const char* proc_name,const TDrawMandelbrotProc fproc){
    const long max_iter=1000;
    TViewRect rect;
    rect.x0=-0.5;
    rect.y0=0;
    rect.r=2;
    rect.seta=0;

    TPixels32 dstPic;
    dstPic.resizeFast(640,480);

    std::cout<<proc_name<<": ";
    fproc(dstPic.getRef(),rect,max_iter);
    std::cout<<" ok"<<std::endl;

    { //save pic
        std::string dstFileName(proc_name);
        dstFileName+=".bmp";
        TFileOutputStream bmpOutStream(dstFileName.c_str());
        TBmpFile::save(dstPic.getRef(),&bmpOutStream);//保存结果图片
    }
}
mxAPPLICATION_ENTRY_POINT

int mxAppMain()
{
	SetupBaseUtil	setupBase;
	//FileLogUtil		fileLog;
	SetupCoreUtil	setupCore;


	const String	srcFileName(
		"D:/dev/_assets/_diplomarbeit/iryoku-head/Head.sdkmesh"
		//"D:/research/_current/iryoku-separable-sss-f61b44c/Demo/Media/Head.sdkmesh"
		//"D:/dev/_assets/Head.sdkmesh"
		);


	FileReader	srcFile( srcFileName );
	CHK_VRET_X_IF_NOT( srcFile.IsOpen(), -1 );


	StaticTriangleMeshData	staticMeshData;

	{
		SDKMesh		sdkMesh;
		if( FAILED(sdkMesh.Create(mxTO_UNICODE( srcFileName ))) ) {
			return -1;
		}

		const SDKMESH_HEADER& header = *sdkMesh.GetHeader();
		(void)header;

		const UINT numMeshes = sdkMesh.GetNumMeshes();
		Assert(numMeshes == 1);
		const UINT iFirstMesh = 0;

		const UINT numSubsets = sdkMesh.GetNumSubsets( iFirstMesh );
		Assert( numSubsets == 1 );
		const UINT iFirstSubset = 0;

		const SDKMESH_SUBSET* pSubset = sdkMesh.GetSubset( iFirstMesh, iFirstSubset );
		const UINT numVertices = pSubset->VertexCount;
		const UINT numIndices = pSubset->IndexCount;

		const UINT numVBs = sdkMesh.GetNumVBs();
		Assert( numVBs == 1 );

		const UINT numIBs = sdkMesh.GetNumIBs();
		Assert( numIBs == 1 );

		const SDKMeshVertex* srcVertices = (const SDKMeshVertex*) sdkMesh.GetRawVerticesAt(0);

		const SDKMESH_INDEX_TYPE indexType = sdkMesh.GetIndexType( iFirstMesh );
		Assert( indexType == SDKMESH_INDEX_TYPE::IT_16BIT );

		const UINT16* srcIndices = (const UINT16*) sdkMesh.GetRawIndicesAt(0);

		{
			TList< Vec3D > &	positions	= staticMeshData.positions;
			TList< Vec2D > &	texCoords	= staticMeshData.texCoords;
			TList< Vec3D > &	normals		= staticMeshData.normals;
			//TList< Vec3D > &	binormals	= staticMeshData.binormals;
			TList< Vec3D > &	tangents	= staticMeshData.tangents;

			positions.SetNum( numVertices );
			texCoords.SetNum( numVertices );
			normals.SetNum( numVertices );
			tangents.SetNum( numVertices );

			staticMeshData.localBounds.Clear();

			for( UINT iVertex = 0; iVertex < numVertices; iVertex++ )
			{
				const SDKMeshVertex & srcVertex = srcVertices[ iVertex ];

				Assert( srcVertex.normal.IsNormalized() );
				Assert( srcVertex.tangent.IsNormalized() );

				positions[ iVertex ] = srcVertex.position;
				texCoords[ iVertex ] = srcVertex.texCoord;
				normals[ iVertex ] = srcVertex.normal;
				tangents[ iVertex ] = srcVertex.tangent;

				staticMeshData.localBounds.AddPoint( srcVertex.position );
			}

			staticMeshData.indices.AddBytes( srcIndices, numIndices * sizeof srcIndices[0] );
			staticMeshData.indexStride = sizeof srcIndices[0];

			MeshPart & firstBatch = staticMeshData.batches.Add();
			{
				firstBatch.baseVertex = pSubset->VertexStart;
				firstBatch.startIndex = pSubset->IndexStart;
				firstBatch.indexCount = pSubset->IndexCount;
				firstBatch.vertexCount = pSubset->VertexCount;
			}
		}
	}



	const String	dstPathName(
		//"D:/dev/_assets"
		"R:/"
		);

	String	dstFileName(
		"iryoku-Head"
		);
	//srcFileName.ExtractFileBase( dstFileName );
	dstFileName += ".static_mesh";


	FileWriter	dstFile( dstPathName + dstFileName );
	CHK_VRET_X_IF_NOT( dstFile.IsOpen(), -1 );

	ArchivePODWriter	archive( dstFile );

	staticMeshData.Serialize( archive );

	return 0;
}
Beispiel #5
0
void ArticleWriter::CompleteFileParts()
{
	debug("Completing file parts");
	debug("ArticleFilename: %s", m_fileInfo->GetFilename());

	bool directWrite = (g_Options->GetDirectWrite() || m_fileInfo->GetForceDirectWrite()) && m_fileInfo->GetOutputInitialized();

	BString<1024> nzbName;
	BString<1024> nzbDestDir;
	BString<1024> filename;

	{
		GuardedDownloadQueue guard = DownloadQueue::Guard();
		nzbName = m_fileInfo->GetNzbInfo()->GetName();
		nzbDestDir = m_fileInfo->GetNzbInfo()->GetDestDir();
		filename = m_fileInfo->GetFilename();
	}

	BString<1024> infoFilename("%s%c%s", *nzbName, PATH_SEPARATOR, *filename);

	bool cached = m_fileInfo->GetCachedArticles() > 0;

	if (g_Options->GetRawArticle())
	{
		detail("Moving articles for %s", *infoFilename);
	}
	else if (directWrite && cached)
	{
		detail("Writing articles for %s", *infoFilename);
	}
	else if (directWrite)
	{
		detail("Checking articles for %s", *infoFilename);
	}
	else
	{
		detail("Joining articles for %s", *infoFilename);
	}

	// Ensure the DstDir is created
	CString errmsg;
	if (!FileSystem::ForceDirectories(nzbDestDir, errmsg))
	{
		m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
			"Could not create directory %s: %s", *nzbDestDir, *errmsg);
		return;
	}

	CString ofn;
	if (m_fileInfo->GetForceDirectWrite())
	{
		ofn.Format("%s%c%s", *nzbDestDir, PATH_SEPARATOR, *filename);
	}
	else
	{
		ofn = FileSystem::MakeUniqueFilename(nzbDestDir, *filename);
	}

	DiskFile outfile;
	BString<1024> tmpdestfile("%s.tmp", *ofn);

	if (!g_Options->GetRawArticle() && !directWrite)
	{
		FileSystem::DeleteFile(tmpdestfile);
		if (!outfile.Open(tmpdestfile, DiskFile::omWrite))
		{
			m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
				"Could not create file %s: %s", *tmpdestfile, *FileSystem::GetLastErrorMessage());
			return;
		}
	}
	else if (directWrite && cached)
	{
		if (!outfile.Open(m_outputFilename, DiskFile::omReadWrite))
		{
			m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
				"Could not open file %s: %s", *m_outputFilename, *FileSystem::GetLastErrorMessage());
			return;
		}
		tmpdestfile = *m_outputFilename;
	}
	else if (g_Options->GetRawArticle())
	{
		FileSystem::DeleteFile(tmpdestfile);
		if (!FileSystem::CreateDirectory(ofn))
		{
			m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
				"Could not create directory %s: %s", *ofn, *FileSystem::GetLastErrorMessage());
			return;
		}
	}

	if (outfile.Active())
	{
		SetWriteBuffer(outfile, 0);
	}

	uint32 crc = 0;

	{
		std::unique_ptr<ArticleCache::FlushGuard> flushGuard;
		if (cached)
		{
			flushGuard = std::make_unique<ArticleCache::FlushGuard>(g_ArticleCache->GuardFlush());
		}

		CharBuffer buffer;
		bool firstArticle = true;

		if (!g_Options->GetRawArticle() && !directWrite)
		{
			buffer.Reserve(1024 * 64);
		}

		for (ArticleInfo* pa : m_fileInfo->GetArticles())
		{
			if (pa->GetStatus() != ArticleInfo::aiFinished)
			{
				continue;
			}

			if (!g_Options->GetRawArticle() && !directWrite && pa->GetSegmentOffset() > -1 &&
				pa->GetSegmentOffset() > outfile.Position() && outfile.Position() > -1)
			{
				memset(buffer, 0, buffer.Size());
				if (!g_Options->GetSkipWrite())
				{
					while (pa->GetSegmentOffset() > outfile.Position() && outfile.Position() > -1 &&
						outfile.Write(buffer, std::min((int)(pa->GetSegmentOffset() - outfile.Position()), buffer.Size())));
				}
			}

			if (pa->GetSegmentContent())
			{
				if (!g_Options->GetSkipWrite())
				{
					outfile.Seek(pa->GetSegmentOffset());
					outfile.Write(pa->GetSegmentContent(), pa->GetSegmentSize());
				}
				pa->DiscardSegment();
			}
			else if (!g_Options->GetRawArticle() && !directWrite && !g_Options->GetSkipWrite())
			{
				DiskFile infile;
				if (pa->GetResultFilename() && infile.Open(pa->GetResultFilename(), DiskFile::omRead))
				{
					int cnt = buffer.Size();
					while (cnt == buffer.Size())
					{
						cnt = (int)infile.Read(buffer, buffer.Size());
						outfile.Write(buffer, cnt);
					}
					infile.Close();
				}
				else
				{
					m_fileInfo->SetFailedArticles(m_fileInfo->GetFailedArticles() + 1);
					m_fileInfo->SetSuccessArticles(m_fileInfo->GetSuccessArticles() - 1);
					m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
						"Could not find file %s for %s [%i/%i]",
						pa->GetResultFilename(), *infoFilename, pa->GetPartNumber(),
						(int)m_fileInfo->GetArticles()->size());
				}
			}
			else if (g_Options->GetRawArticle())
			{
				BString<1024> dstFileName("%s%c%03i", *ofn, PATH_SEPARATOR, pa->GetPartNumber());
				if (!FileSystem::MoveFile(pa->GetResultFilename(), dstFileName))
				{
					m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
						"Could not move file %s to %s: %s", pa->GetResultFilename(),
						*dstFileName, *FileSystem::GetLastErrorMessage());
				}
			}

			if (m_format == Decoder::efYenc)
			{
				crc = firstArticle ? pa->GetCrc() : Crc32::Combine(crc, pa->GetCrc(), pa->GetSegmentSize());
				firstArticle = false;
			}
		}

		buffer.Clear();
	}

	if (outfile.Active())
	{
		outfile.Close();
		if (!directWrite && !FileSystem::MoveFile(tmpdestfile, ofn))
		{
			m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
				"Could not move file %s to %s: %s", *tmpdestfile, *ofn,
				*FileSystem::GetLastErrorMessage());
		}
	}

	if (directWrite)
	{
		if (!FileSystem::SameFilename(m_outputFilename, ofn) &&
			!FileSystem::MoveFile(m_outputFilename, ofn))
		{
			m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
				"Could not move file %s to %s: %s", *m_outputFilename, *ofn,
				*FileSystem::GetLastErrorMessage());
		}

		// if destination directory was changed delete the old directory (if empty)
		int len = strlen(nzbDestDir);
		if (!(!strncmp(nzbDestDir, m_outputFilename, len) &&
			(m_outputFilename[len] == PATH_SEPARATOR || m_outputFilename[len] == ALT_PATH_SEPARATOR)))
		{
			debug("Checking old dir for: %s", *m_outputFilename);
			BString<1024> oldDestDir;
			oldDestDir.Set(m_outputFilename, (int)(FileSystem::BaseFileName(m_outputFilename) - m_outputFilename));
			if (FileSystem::DirEmpty(oldDestDir))
			{
				debug("Deleting old dir: %s", *oldDestDir);
				FileSystem::RemoveDirectory(oldDestDir);
			}
		}
	}

	if (!directWrite)
	{
		for (ArticleInfo* pa : m_fileInfo->GetArticles())
		{
			if (pa->GetResultFilename())
			{
				FileSystem::DeleteFile(pa->GetResultFilename());
			}
		}
	}

	if (m_fileInfo->GetTotalArticles() == m_fileInfo->GetSuccessArticles())
	{
		m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkInfo, "Successfully downloaded %s", *infoFilename);
	}
	else if (m_fileInfo->GetMissedArticles() + m_fileInfo->GetFailedArticles() > 0)
	{
		m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkWarning,
			"%i of %i article downloads failed for \"%s\"",
			m_fileInfo->GetMissedArticles() + m_fileInfo->GetFailedArticles(),
			m_fileInfo->GetTotalArticles(), *infoFilename);
	}
	else
	{
		m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkInfo, "Partially downloaded %s", *infoFilename);
	}

	{
		GuardedDownloadQueue guard = DownloadQueue::Guard();

		m_fileInfo->SetCrc(crc);
		m_fileInfo->SetOutputFilename(ofn);

		if (strcmp(m_fileInfo->GetFilename(), filename))
		{
			// file was renamed during completion, need to move the file
			ofn = FileSystem::MakeUniqueFilename(nzbDestDir, m_fileInfo->GetFilename());
			if (!FileSystem::MoveFile(m_fileInfo->GetOutputFilename(), ofn))
			{
				m_fileInfo->GetNzbInfo()->PrintMessage(Message::mkError,
					"Could not rename file %s to %s: %s", m_fileInfo->GetOutputFilename(),
					*ofn, *FileSystem::GetLastErrorMessage());
			}
			m_fileInfo->SetOutputFilename(ofn);
		}

		if (strcmp(m_fileInfo->GetNzbInfo()->GetDestDir(), nzbDestDir))
		{
			// destination directory was changed during completion, need to move the file
			MoveCompletedFiles(m_fileInfo->GetNzbInfo(), nzbDestDir);
		}
	}
}