/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
staticint help( constchar *error = nullptr )
{ if (error)
fprintf (stderr, "Error: %s\n\n", error);
fprintf( stderr, "Usage: tilebench [path to document] [--preinit] [--save ] \n");
fprintf( stderr, "\trenders a selection of small tiles from the document, checksums them and times the process based on options:\n" );
fprintf( stderr, "\t--tile\t[max parts|-1] [max tiles|-1]\n" );
fprintf( stderr, "\t--dialog\t<.uno:Command>\n" );
fprintf( stderr, "\t--join\trun tile joining tests\n" ); return 1;
}
aTimes.emplace_back("get size of parts"); long nWidth = 0; long nHeight = 0; for (int n = 0; n < nParts; ++n)
{ constint nPart = (nOriginalPart + n) % nTotalParts; char* pName = pDocument->getPartName(nPart);
pDocument->setPart(nPart);
pDocument->getDocumentSize(&nWidth, &nHeight);
fprintf (stderr, " '%s' -> %ld, %ld\n", pName, nWidth, nHeight);
free (pName);
}
aTimes.emplace_back();
// Use realistic dimensions, similar to the Online client. longconst nTilePixelWidth = 512; longconst nTilePixelHeight = 512; longconst nTileTwipWidth = 3840; longconst nTileTwipHeight = 3840;
// Estimate the maximum tiles based on the number of parts requested, if Writer. if (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT)
max_tiles = static_cast<int>(ceil(max_parts * 16128. / nTilePixelHeight) * ceil(static_cast<double>(nWidth) / nTilePixelWidth));
fprintf(stderr, "Parts to render: %d, Total Parts: %d, Max parts: %d, Max tiles: %d\n", nParts, nTotalParts, max_parts, max_tiles);
if (dump || pDocument->getDocumentType() != LOK_DOCTYPE_TEXT)
{ // whole part; meaningful only for non-writer documents.
aTimes.emplace_back("render whole part");
pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
nWidth/2, 2000, 1000, 1000);
aTimes.emplace_back(); if (dump)
dumpTile("tile", nTilePixelWidth, nTilePixelHeight, mode, pPixels);
}
{ // 1:1
aTimes.emplace_back("render sub-region at 1:1"); // Estimate the maximum tiles based on the number of parts requested, if Writer. int nMaxTiles = max_tiles; int nTiles = 0; for (long nY = 0; nY < nHeight - 1; nY += nTilePixelHeight)
{ for (long nX = 0; nX < nWidth - 1; nX += nTilePixelWidth)
{ if (nMaxTiles >= 0 && nTiles >= nMaxTiles)
{
nY = nHeight; break;
}
pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
nX, nY, nTilePixelWidth, nTilePixelHeight);
nTiles++;
fprintf (stderr, " rendered 1:1 tile %d at %ld, %ld\n",
nTiles, nX, nY);
}
}
aTimes.emplace_back();
}
{ // scaled
aTimes.emplace_back("render sub-regions at scale"); int nMaxTiles = max_tiles; if (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT)
nMaxTiles = static_cast<int>(ceil(max_parts * 16128. / nTileTwipHeight) * ceil(static_cast<double>(nWidth) / nTileTwipWidth)); int nTiles = 0; for (long nY = 0; nY < nHeight - 1; nY += nTileTwipHeight)
{ for (long nX = 0; nX < nWidth - 1; nX += nTileTwipWidth)
{ if (nMaxTiles >= 0 && nTiles >= nMaxTiles)
{
nY = nHeight; break;
}
pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
nX, nY, nTileTwipWidth, nTileTwipHeight);
nTiles++;
fprintf (stderr, " rendered scaled tile %d at %ld, %ld\n",
nTiles, nX, nY);
}
}
aTimes.emplace_back();
}
}
}
long initPosX = nX * nTileTwipWidth, initPosY = nY * nTileTwipHeight;
// Calc has to do significant work on changing zoom ...
pDocument->setClientZoom( nTilePixelWidth, nTilePixelHeight,
nTileTwipWidth, nTileTwipHeight );
int nDifferences = 0; // Compare each of the 4x tiles with a sub-tile of the larger image for( auto &rPos : aCompare )
{
std::vector<unsignedchar> vCompare(
paintTile(pDocument,
initPosX + rPos.X * nTileTwipWidth,
initPosY + rPos.Y * nTileTwipHeight,
nTilePixelWidth, nTilePixelHeight,
nTileTwipWidth, nTileTwipHeight));
// Check that our tiles join nicely ... staticint testJoin( Document *pDocument)
{ // Ignore parts - just the first for now ... long nWidth = 0, nHeight = 0;
pDocument->getDocumentSize(&nWidth, &nHeight);
fprintf (stderr, "Width is %ld, %ld (twips)\n", nWidth, nHeight);
// Use realistic dimensions, similar to the Online client. longconst nTilePixelSize = 256; longconst nTileTwipSize = 3840; double fZooms[] = {
0.5,
0.6, 0.7, 0.85,
1.0,
1.2, 1.5, 1.75,
2.0
}; long nFails = 0;
std::stringstream results;
for( auto z : fZooms )
{ long nBad = 0; long nDifferences = 0; for( long y = 0; y < 8; ++y )
{ for( long x = 0; x < 8; ++x )
{ int nDiffs = testJoinsAt( pDocument, x, y, nTilePixelSize, nTileTwipSize * z ); if (nDiffs)
nBad++;
nDifferences += nDiffs;
}
} if (nBad > 0)
results << "\tZoom " << z << " bad tiles: " << nBad << " with " << nDifferences << " mismatching pixels\n";
nFails += nBad;
}
if (nFails > 0)
fprintf( stderr, "Failed %ld joins\n", nFails ); else
fprintf( stderr, "All joins compared correctly\n" );
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.