Avoid passing both factors and product

Simplify a logic too, to not check the tokens number
multiple times and generate nice error.

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I613bbc63ef5d1f19acc484ba36eac887cb21e535
This commit is contained in:
Szymon Kłos 2024-07-17 15:23:13 +02:00 committed by Szymon Kłos
parent 2faa12c355
commit 514f929785
2 changed files with 29 additions and 26 deletions

View file

@ -2193,9 +2193,9 @@ uint64_t hashSubBuffer(unsigned char* pixmap, size_t startX, size_t startY,
} }
} }
bool ChildSession::renderNextSlideLayer(int width, int height, size_t pixmapDataSize, bool& done) bool ChildSession::renderNextSlideLayer(const unsigned width, const unsigned height, bool& done)
{ {
std::vector<unsigned char> pixmap(pixmapDataSize); std::vector<unsigned char> pixmap(static_cast<size_t>(4) * width * height);
bool bIsBitmapLayer = false; bool bIsBitmapLayer = false;
char* msg = nullptr; char* msg = nullptr;
done = getLOKitDocument()->renderNextSlideLayer(pixmap.data(), &bIsBitmapLayer, &msg); done = getLOKitDocument()->renderNextSlideLayer(pixmap.data(), &bIsBitmapLayer, &msg);
@ -2223,7 +2223,7 @@ bool ChildSession::renderNextSlideLayer(int width, int height, size_t pixmapData
response += "\n"; response += "\n";
std::vector<char> output; std::vector<char> output;
output.reserve(response.size() + pixmapDataSize); output.reserve(response.size() + pixmap.size());
output.resize(response.size()); output.resize(response.size());
std::memcpy(output.data(), response.data(), response.size()); std::memcpy(output.data(), response.data(), response.size());
@ -2243,55 +2243,58 @@ bool ChildSession::renderNextSlideLayer(int width, int height, size_t pixmapData
bool ChildSession::renderSlide(const StringVector& tokens) bool ChildSession::renderSlide(const StringVector& tokens)
{ {
if (tokens.size() <= 3)
{
sendTextFrameAndLogError("error: cmd=getslide kind=syntax");
return false;
}
int part = -1; int part = -1;
std::string partString; std::string partString;
if (tokens.size() > 1 && getTokenString(tokens[1], "part", partString)) if (getTokenString(tokens[1], "part", partString))
{
part = std::stoi(partString); part = std::stoi(partString);
}
int suggestedWidth = -1; unsigned suggestedWidth = 0;
std::string widthString; std::string widthString;
if (tokens.size() > 2 && getTokenString(tokens[2], "width", widthString)) if (getTokenString(tokens[2], "width", widthString))
{
suggestedWidth = std::stoi(widthString); suggestedWidth = std::stoi(widthString);
}
int suggestedHeight = -1; unsigned suggestedHeight = 0;
std::string heightString; std::string heightString;
if (tokens.size() > 3 && getTokenString(tokens[3], "height", heightString)) if (getTokenString(tokens[3], "height", heightString))
{
suggestedHeight = std::stoi(heightString); suggestedHeight = std::stoi(heightString);
}
if (part < 0 || suggestedWidth < 0 || suggestedHeight < 0) if (part < 0 || suggestedWidth == 0 || suggestedHeight == 0)
{
sendTextFrameAndLogError("error: cmd=getslide kind=syntax");
return false; return false;
}
bool renderBackground = true; bool renderBackground = true;
std::string renderBackgroundString; std::string renderBackgroundString;
if (tokens.size() > 4 && getTokenString(tokens[4], "renderBackground", renderBackgroundString)) if (tokens.size() > 4 && getTokenString(tokens[4], "renderBackground", renderBackgroundString))
{
renderBackground = std::stoi(renderBackgroundString) > 0; renderBackground = std::stoi(renderBackgroundString) > 0;
}
bool renderMasterPage = true; bool renderMasterPage = true;
std::string renderMasterPageString; std::string renderMasterPageString;
if (tokens.size() > 5 && getTokenString(tokens[5], "renderMasterPage", renderMasterPageString)) if (tokens.size() > 5 && getTokenString(tokens[5], "renderMasterPage", renderMasterPageString))
{
renderMasterPage = std::stoi(renderMasterPageString) > 0; renderMasterPage = std::stoi(renderMasterPageString) > 0;
}
unsigned int bufferWidth = suggestedWidth; unsigned bufferWidth = suggestedWidth;
unsigned int bufferHeight = suggestedHeight; unsigned bufferHeight = suggestedHeight;
bool success = getLOKitDocument()->createSlideRenderer(part, bool success = getLOKitDocument()->createSlideRenderer(part,
&bufferWidth, &bufferHeight, &bufferWidth, &bufferHeight,
renderBackground, renderMasterPage); renderBackground, renderMasterPage);
if (!success) if (!success)
return false; return false;
const int width = bufferWidth; assert(bufferWidth <= suggestedWidth);
const int height = bufferHeight; assert(bufferHeight <= suggestedHeight);
const size_t pixmapDataSize = 4 * bufferWidth * bufferHeight;
bool done = false; bool done = false;
while (!done) while (!done)
{ {
success = renderNextSlideLayer(width, height, pixmapDataSize, done); success = renderNextSlideLayer(bufferWidth, bufferHeight, done);
if (!success) if (!success)
break; break;
} }

View file

@ -154,7 +154,7 @@ private:
bool unoCommand(const StringVector& tokens); bool unoCommand(const StringVector& tokens);
bool selectText(const StringVector& tokens, const LokEventTargetEnum target); bool selectText(const StringVector& tokens, const LokEventTargetEnum target);
bool selectGraphic(const StringVector& tokens); bool selectGraphic(const StringVector& tokens);
bool renderNextSlideLayer(int width, int height, size_t pixmapDataSize, bool& done); bool renderNextSlideLayer(const unsigned width, const unsigned height, bool& done);
bool renderSlide(const StringVector& tokens); bool renderSlide(const StringVector& tokens);
bool renderWindow(const StringVector& tokens); bool renderWindow(const StringVector& tokens);
bool resizeWindow(const StringVector& tokens); bool resizeWindow(const StringVector& tokens);