mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
common picture: code refactoring.
keep api parameter naming consistency. ptsCnt, cmdCnt, triangleCnt ...
This commit is contained in:
parent
240bf6259a
commit
ddb9bbdf0e
4 changed files with 27 additions and 27 deletions
|
@ -1200,13 +1200,13 @@ public:
|
|||
* If a mesh is provided, the transform property of the Picture will apply to the triangle mesh, and the
|
||||
* image data will be used as the texture.
|
||||
*
|
||||
* If triangles is null, or triangleCount is 0, the mesh will be removed.
|
||||
* If @p triangles is @c nullptr, or @p triangleCnt is 0, the mesh will be removed.
|
||||
*
|
||||
* Only raster image types are supported at this time (png, jpg). Vector types like svg and tvg do not support.
|
||||
* mesh deformation. However, if required you should be able to render a vector image to a raster image and then apply a mesh.
|
||||
*
|
||||
* @param[in] triangles An array of Polygon objects (triangles) that make up the mesh, or null to remove the mesh.
|
||||
* @param[in] triangleCount The number of Polygon objects (triangles) provided, or 0 to remove the mesh.
|
||||
* @param[in] triangles An array of Polygons(triangles) that make up the mesh, or null to remove the mesh.
|
||||
* @param[in] triangleCnt The number of Polygons(triangles) provided, or 0 to remove the mesh.
|
||||
*
|
||||
* @retval Result::Success When succeed.
|
||||
* @retval Result::Unknown If fails
|
||||
|
@ -1216,7 +1216,7 @@ public:
|
|||
*
|
||||
* @BETA_API
|
||||
*/
|
||||
Result mesh(const Polygon* triangles, const uint32_t triangleCount) noexcept;
|
||||
Result mesh(const Polygon* triangles, const uint32_t triangleCnt) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Return the number of triangles in the mesh, and optionally get a pointer to the array of triangles in the mesh.
|
||||
|
|
|
@ -182,7 +182,7 @@ struct SwImageTask : SwTask
|
|||
{
|
||||
SwImage image;
|
||||
Polygon* triangles;
|
||||
uint32_t triangleCount;
|
||||
uint32_t triangleCnt;
|
||||
|
||||
void run(unsigned tid) override
|
||||
{
|
||||
|
@ -193,10 +193,10 @@ struct SwImageTask : SwTask
|
|||
imageReset(&image);
|
||||
if (!image.data || image.w == 0 || image.h == 0) goto end;
|
||||
|
||||
if (!imagePrepare(&image, triangles, triangleCount, transform, clipRegion, bbox, mpool, tid)) goto end;
|
||||
if (!imagePrepare(&image, triangles, triangleCnt, transform, clipRegion, bbox, mpool, tid)) goto end;
|
||||
|
||||
// TODO: How do we clip the triangle mesh? Only clip non-meshed images for now
|
||||
if (triangleCount == 0 && clips.count > 0) {
|
||||
if (triangleCnt == 0 && clips.count > 0) {
|
||||
if (!imageGenRle(&image, bbox, false)) goto end;
|
||||
if (image.rle) {
|
||||
for (auto clip = clips.data; clip < (clips.data + clips.count); ++clip) {
|
||||
|
@ -366,7 +366,7 @@ bool SwRenderer::renderImageMesh(RenderData data)
|
|||
|
||||
if (task->opacity == 0) return true;
|
||||
|
||||
return rasterImageMesh(surface, &task->image, task->triangles, task->triangleCount, task->transform, task->bbox, task->opacity);
|
||||
return rasterImageMesh(surface, &task->image, task->triangles, task->triangleCnt, task->transform, task->bbox, task->opacity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -624,7 +624,7 @@ void* SwRenderer::prepareCommon(SwTask* task, const RenderTransform* transform,
|
|||
}
|
||||
|
||||
|
||||
RenderData SwRenderer::prepare(Surface* image, Polygon* triangles, uint32_t triangleCount, RenderData data, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flags)
|
||||
RenderData SwRenderer::prepare(Surface* image, Polygon* triangles, uint32_t triangleCnt, RenderData data, const RenderTransform* transform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag flags)
|
||||
{
|
||||
//prepare task
|
||||
auto task = static_cast<SwImageTask*>(data);
|
||||
|
@ -635,7 +635,7 @@ RenderData SwRenderer::prepare(Surface* image, Polygon* triangles, uint32_t tria
|
|||
task->image.h = image->h;
|
||||
task->image.stride = image->stride;
|
||||
task->triangles = triangles;
|
||||
task->triangleCount = triangleCount;
|
||||
task->triangleCnt = triangleCnt;
|
||||
}
|
||||
return prepareCommon(task, transform, opacity, clips, flags);
|
||||
}
|
||||
|
|
|
@ -121,9 +121,9 @@ const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const noexcept
|
|||
}
|
||||
|
||||
|
||||
Result Picture::mesh(const Polygon* triangles, const uint32_t triangleCount) noexcept
|
||||
Result Picture::mesh(const Polygon* triangles, const uint32_t triangleCnt) noexcept
|
||||
{
|
||||
if (pImpl->mesh(triangles, triangleCount)) return Result::Success;
|
||||
if (pImpl->mesh(triangles, triangleCnt)) return Result::Success;
|
||||
return Result::Unknown;
|
||||
}
|
||||
|
||||
|
@ -131,5 +131,5 @@ Result Picture::mesh(const Polygon* triangles, const uint32_t triangleCount) noe
|
|||
uint32_t Picture::mesh(const Polygon** triangles) const noexcept
|
||||
{
|
||||
if (triangles) *triangles = pImpl->triangles;
|
||||
return pImpl->triangleCount;
|
||||
return pImpl->triangleCnt;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ struct Picture::Impl
|
|||
Paint* paint = nullptr; //vector picture uses
|
||||
Surface* surface = nullptr; //bitmap picture uses
|
||||
Polygon* triangles = nullptr; //mesh data
|
||||
uint32_t triangleCount = 0; //mesh triangle count
|
||||
uint32_t triangleCnt = 0; //mesh triangle count
|
||||
void* rdata = nullptr; //engine data
|
||||
float w = 0, h = 0;
|
||||
bool resizing = false;
|
||||
|
@ -131,7 +131,7 @@ struct Picture::Impl
|
|||
|
||||
if (surface) {
|
||||
auto transform = resizeTransform(pTransform);
|
||||
rdata = renderer.prepare(surface, triangles, triangleCount, rdata, &transform, opacity, clips, static_cast<RenderUpdateFlag>(pFlag | flag));
|
||||
rdata = renderer.prepare(surface, triangles, triangleCnt, rdata, &transform, opacity, clips, static_cast<RenderUpdateFlag>(pFlag | flag));
|
||||
} else if (paint) {
|
||||
if (resizing) {
|
||||
loader->resize(paint, w, h);
|
||||
|
@ -172,12 +172,12 @@ struct Picture::Impl
|
|||
|
||||
bool bounds(float* x, float* y, float* w, float* h)
|
||||
{
|
||||
if (triangleCount > 0) {
|
||||
if (triangleCnt > 0) {
|
||||
|
||||
Point min = { triangles[0].vertex[0].pt.x, triangles[0].vertex[0].pt.y };
|
||||
Point max = { triangles[0].vertex[0].pt.x, triangles[0].vertex[0].pt.y };
|
||||
|
||||
for (uint32_t i = 0; i < triangleCount; ++i) {
|
||||
for (uint32_t i = 0; i < triangleCnt; ++i) {
|
||||
if (triangles[i].vertex[0].pt.x < min.x) min.x = triangles[i].vertex[0].pt.x;
|
||||
else if (triangles[i].vertex[0].pt.x > max.x) max.x = triangles[i].vertex[0].pt.x;
|
||||
if (triangles[i].vertex[0].pt.y < min.y) min.y = triangles[i].vertex[0].pt.y;
|
||||
|
@ -252,16 +252,16 @@ struct Picture::Impl
|
|||
return Result::Success;
|
||||
}
|
||||
|
||||
bool mesh(const Polygon* triangles, const uint32_t triangleCount)
|
||||
bool mesh(const Polygon* triangles, const uint32_t triangleCnt)
|
||||
{
|
||||
if (triangles && triangleCount > 0) {
|
||||
this->triangleCount = triangleCount;
|
||||
this->triangles = (Polygon*)malloc(sizeof(Polygon) * triangleCount);
|
||||
memcpy(this->triangles, triangles, sizeof(Polygon) * triangleCount);
|
||||
if (triangles && triangleCnt > 0) {
|
||||
this->triangleCnt = triangleCnt;
|
||||
this->triangles = (Polygon*)malloc(sizeof(Polygon) * triangleCnt);
|
||||
memcpy(this->triangles, triangles, sizeof(Polygon) * triangleCnt);
|
||||
} else {
|
||||
free(this->triangles);
|
||||
this->triangles = nullptr;
|
||||
this->triangleCount = 0;
|
||||
this->triangleCnt = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -284,10 +284,10 @@ struct Picture::Impl
|
|||
dup->h = h;
|
||||
dup->resizing = resizing;
|
||||
|
||||
if (triangleCount > 0) {
|
||||
dup->triangleCount = triangleCount;
|
||||
dup->triangles = (Polygon*)malloc(sizeof(Polygon) * triangleCount);
|
||||
memcpy(dup->triangles, triangles, sizeof(Polygon) * triangleCount);
|
||||
if (triangleCnt > 0) {
|
||||
dup->triangleCnt = triangleCnt;
|
||||
dup->triangles = (Polygon*)malloc(sizeof(Polygon) * triangleCnt);
|
||||
memcpy(dup->triangles, triangles, sizeof(Polygon) * triangleCnt);
|
||||
}
|
||||
|
||||
return ret.release();
|
||||
|
|
Loading…
Add table
Reference in a new issue