remove return type values.
#define _read_tvg_ui32(dst, src) memcpy(dst, (src), sizeof(uint32_t))
#define _read_tvg_float(dst, src) memcpy(dst, (src), sizeof(float))
#define _read_tvg_ui32(dst, src) memcpy(dst, (src), sizeof(uint32_t))
#define _read_tvg_float(dst, src) memcpy(dst, (src), sizeof(float))
-enum class LoaderResult { Success = 0, InvalidType, SizeCorruption, MemoryCorruption, LogicalCorruption };
-
static Paint* _parsePaint(TvgBinBlock block);
static Paint* _parsePaint(TvgBinBlock block);
static bool _paintProperty(TvgBinBlock block)
{
switch (block.type) {
static bool _paintProperty(TvgBinBlock block)
{
switch (block.type) {
-static LoaderResult _parseCmpTarget(const char *ptr, const char *end, Paint *paint)
+static bool _parseCmpTarget(const char *ptr, const char *end, Paint *paint)
{
auto block = _readBlock(ptr);
{
auto block = _readBlock(ptr);
- if (block.end > end) return LoaderResult::SizeCorruption;
+ if (block.end > end) return false;
- if (block.type != TVG_PAINT_CMP_METHOD_INDICATOR) return LoaderResult::LogicalCorruption;
- if (block.length != sizeof(TvgFlag)) return LoaderResult::SizeCorruption;
+ if (block.type != TVG_PAINT_CMP_METHOD_INDICATOR) return false;
+ if (block.length != sizeof(TvgFlag)) return false;
CompositeMethod cmpMethod;
CompositeMethod cmpMethod;
cmpMethod = CompositeMethod::InvAlphaMask;
break;
}
cmpMethod = CompositeMethod::InvAlphaMask;
break;
}
- default: return LoaderResult::LogicalCorruption;
}
ptr = block.end;
auto cmpBlock = _readBlock(ptr);
}
ptr = block.end;
auto cmpBlock = _readBlock(ptr);
- if (cmpBlock.end > end) return LoaderResult::SizeCorruption;
+ if (cmpBlock.end > end) return false;
paint->composite(unique_ptr<Paint>(_parsePaint(cmpBlock)), cmpMethod);
paint->composite(unique_ptr<Paint>(_parsePaint(cmpBlock)), cmpMethod);
- return LoaderResult::Success;
-static LoaderResult _parsePaintProperty(TvgBinBlock block, Paint *paint)
+static bool _parsePaintProperty(TvgBinBlock block, Paint *paint)
{
switch (block.type) {
case TVG_PAINT_OPACITY_INDICATOR: {
{
switch (block.type) {
case TVG_PAINT_OPACITY_INDICATOR: {
- if (block.length != sizeof(uint8_t)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(uint8_t)) return false;
paint->opacity(*block.data);
paint->opacity(*block.data);
- return LoaderResult::Success;
}
case TVG_PAINT_TRANSFORM_MATRIX_INDICATOR: {
}
case TVG_PAINT_TRANSFORM_MATRIX_INDICATOR: {
- if (block.length != sizeof(Matrix)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(Matrix)) return false;
Matrix matrix;
memcpy(&matrix, block.data, sizeof(Matrix));
Matrix matrix;
memcpy(&matrix, block.data, sizeof(Matrix));
- if (paint->transform(matrix) != Result::Success) return LoaderResult::MemoryCorruption;
- return LoaderResult::Success;
+ if (paint->transform(matrix) != Result::Success) return false;
+ return true;
}
case TVG_PAINT_CMP_TARGET_INDICATOR: {
}
case TVG_PAINT_CMP_TARGET_INDICATOR: {
- if (block.length < TVG_INDICATOR_SIZE + BYTE_COUNTER_SIZE) return LoaderResult::SizeCorruption;
+ if (block.length < TVG_INDICATOR_SIZE + BYTE_COUNTER_SIZE) return false;
return _parseCmpTarget(block.data, block.end, paint);
}
}
return _parseCmpTarget(block.data, block.end, paint);
}
}
- return LoaderResult::InvalidType;
-static LoaderResult _parseScene(TvgBinBlock block, Paint *paint)
+static bool _parseScene(TvgBinBlock block, Paint *paint)
{
auto scene = static_cast<Scene*>(paint);
switch (block.type) {
case TVG_SCENE_FLAG_RESERVEDCNT: {
{
auto scene = static_cast<Scene*>(paint);
switch (block.type) {
case TVG_SCENE_FLAG_RESERVEDCNT: {
- if (block.length != sizeof(uint32_t)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(uint32_t)) return false;
uint32_t reservedCnt;
_read_tvg_ui32(&reservedCnt, block.data);
scene->reserve(reservedCnt);
uint32_t reservedCnt;
_read_tvg_ui32(&reservedCnt, block.data);
scene->reserve(reservedCnt);
- return LoaderResult::Success;
if (auto paint = _parsePaint(block)) {
scene->push(unique_ptr<Paint>(paint));
if (auto paint = _parsePaint(block)) {
scene->push(unique_ptr<Paint>(paint));
- return LoaderResult::Success;
- return LoaderResult::InvalidType;
-static LoaderResult _parseShapePath(const char *ptr, const char *end, Shape *shape)
+static bool _parseShapePath(const char *ptr, const char *end, Shape *shape)
{
//Shape Path
uint32_t cmdCnt, ptsCnt;
{
//Shape Path
uint32_t cmdCnt, ptsCnt;
const Point* pts = (Point*) ptr;
ptr += sizeof(Point) * ptsCnt;
const Point* pts = (Point*) ptr;
ptr += sizeof(Point) * ptsCnt;
- if (ptr > end) return LoaderResult::SizeCorruption;
+ if (ptr > end) return false;
shape->appendPath(cmds, cmdCnt, pts, ptsCnt);
shape->appendPath(cmds, cmdCnt, pts, ptsCnt);
- return LoaderResult::Success;
-static LoaderResult _parseShapeFill(const char *ptr, const char *end, Fill **fillOutside)
+static bool _parseShapeFill(const char *ptr, const char *end, Fill **fillOutside)
{
unique_ptr<Fill> fillGrad;
while (ptr < end) {
auto block = _readBlock(ptr);
{
unique_ptr<Fill> fillGrad;
while (ptr < end) {
auto block = _readBlock(ptr);
- if (block.end > end) return LoaderResult::SizeCorruption;
+ if (block.end > end) return false;
switch (block.type) {
case TVG_FILL_RADIAL_GRADIENT_INDICATOR: {
switch (block.type) {
case TVG_FILL_RADIAL_GRADIENT_INDICATOR: {
- if (block.length != 3 * sizeof(float)) return LoaderResult::SizeCorruption;
+ if (block.length != 3 * sizeof(float)) return false;
auto ptr = block.data;
float x, y, radius;
auto ptr = block.data;
float x, y, radius;
break;
}
case TVG_FILL_LINEAR_GRADIENT_INDICATOR: {
break;
}
case TVG_FILL_LINEAR_GRADIENT_INDICATOR: {
- if (block.length != 4 * sizeof(float)) return LoaderResult::SizeCorruption;
+ if (block.length != 4 * sizeof(float)) return false;
auto ptr = block.data;
float x1, y1, x2, y2;
auto ptr = block.data;
float x1, y1, x2, y2;
break;
}
case TVG_FILL_FILLSPREAD_INDICATOR: {
break;
}
case TVG_FILL_FILLSPREAD_INDICATOR: {
- if (!fillGrad) return LoaderResult::LogicalCorruption;
- if (block.length != sizeof(TvgFlag)) return LoaderResult::SizeCorruption;
+ if (!fillGrad) return false;
+ if (block.length != sizeof(TvgFlag)) return false;
switch (*block.data) {
case TVG_FILL_FILLSPREAD_PAD_FLAG: {
fillGrad->spread(FillSpread::Pad);
switch (*block.data) {
case TVG_FILL_FILLSPREAD_PAD_FLAG: {
fillGrad->spread(FillSpread::Pad);
break;
}
case TVG_FILL_COLORSTOPS_INDICATOR: {
break;
}
case TVG_FILL_COLORSTOPS_INDICATOR: {
- if (!fillGrad) return LoaderResult::LogicalCorruption;
- if (block.length == 0 || block.length & 0x07) return LoaderResult::SizeCorruption;
+ if (!fillGrad) return false;
+ if (block.length == 0 || block.length & 0x07) return false;
uint32_t stopsCnt = block.length >> 3; // 8 bytes per ColorStop
uint32_t stopsCnt = block.length >> 3; // 8 bytes per ColorStop
- if (stopsCnt > 1023) return LoaderResult::SizeCorruption;
+ if (stopsCnt > 1023) return false;
Fill::ColorStop stops[stopsCnt];
auto p = block.data;
for (uint32_t i = 0; i < stopsCnt; i++, p += 8) {
Fill::ColorStop stops[stopsCnt];
auto p = block.data;
for (uint32_t i = 0; i < stopsCnt; i++, p += 8) {
ptr = block.end;
}
*fillOutside = fillGrad.release();
ptr = block.end;
}
*fillOutside = fillGrad.release();
- return LoaderResult::Success;
-static LoaderResult _parseShapeStrokeDashPattern(const char *ptr, const char *end, Shape *shape)
+static bool _parseShapeStrokeDashPattern(const char *ptr, const char *end, Shape *shape)
{
uint32_t dashPatternCnt;
_read_tvg_ui32(&dashPatternCnt, ptr);
{
uint32_t dashPatternCnt;
_read_tvg_ui32(&dashPatternCnt, ptr);
const float* dashPattern = (float*) ptr;
ptr += sizeof(float) * dashPatternCnt;
const float* dashPattern = (float*) ptr;
ptr += sizeof(float) * dashPatternCnt;
- if (ptr > end) return LoaderResult::SizeCorruption;
+ if (ptr > end) return false;
shape->stroke(dashPattern, dashPatternCnt);
shape->stroke(dashPattern, dashPatternCnt);
- return LoaderResult::Success;
-static LoaderResult _parseShapeStroke(const char *ptr, const char *end, Shape *shape)
+static bool _parseShapeStroke(const char *ptr, const char *end, Shape *shape)
{
while (ptr < end) {
auto block = _readBlock(ptr);
{
while (ptr < end) {
auto block = _readBlock(ptr);
- if (block.end > end) return LoaderResult::SizeCorruption;
+ if (block.end > end) return false;
switch (block.type) {
case TVG_SHAPE_STROKE_CAP_INDICATOR: {
switch (block.type) {
case TVG_SHAPE_STROKE_CAP_INDICATOR: {
- if (block.length != sizeof(TvgFlag)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(TvgFlag)) return false;
switch (*block.data) {
case TVG_SHAPE_STROKE_CAP_SQUARE_FLAG:
shape->stroke(StrokeCap::Square);
switch (*block.data) {
case TVG_SHAPE_STROKE_CAP_SQUARE_FLAG:
shape->stroke(StrokeCap::Square);
break;
}
case TVG_SHAPE_STROKE_JOIN_INDICATOR: {
break;
}
case TVG_SHAPE_STROKE_JOIN_INDICATOR: {
- if (block.length != sizeof(TvgFlag)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(TvgFlag)) return false;
switch (*block.data) {
case TVG_SHAPE_STROKE_JOIN_BEVEL_FLAG:
shape->stroke(StrokeJoin::Bevel);
switch (*block.data) {
case TVG_SHAPE_STROKE_JOIN_BEVEL_FLAG:
shape->stroke(StrokeJoin::Bevel);
break;
}
case TVG_SHAPE_STROKE_WIDTH_INDICATOR: {
break;
}
case TVG_SHAPE_STROKE_WIDTH_INDICATOR: {
- if (block.length != sizeof(float)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(float)) return false;
float width;
_read_tvg_float(&width, block.data);
shape->stroke(width);
break;
}
case TVG_SHAPE_STROKE_COLOR_INDICATOR: {
float width;
_read_tvg_float(&width, block.data);
shape->stroke(width);
break;
}
case TVG_SHAPE_STROKE_COLOR_INDICATOR: {
- if (block.length != 4) return LoaderResult::SizeCorruption;
+ if (block.length != 4) return false;
shape->stroke(block.data[0], block.data[1], block.data[2], block.data[3]);
break;
}
case TVG_SHAPE_STROKE_FILL_INDICATOR: {
Fill* fill;
shape->stroke(block.data[0], block.data[1], block.data[2], block.data[3]);
break;
}
case TVG_SHAPE_STROKE_FILL_INDICATOR: {
Fill* fill;
- auto result = _parseShapeFill(block.data, block.end, &fill);
- if (result != LoaderResult::Success) return result;
+ if (!_parseShapeFill(block.data, block.end, &fill)) return false;
shape->stroke(unique_ptr < Fill > (fill));
break;
}
case TVG_SHAPE_STROKE_DASHPTRN_INDICATOR: {
shape->stroke(unique_ptr < Fill > (fill));
break;
}
case TVG_SHAPE_STROKE_DASHPTRN_INDICATOR: {
- auto result = _parseShapeStrokeDashPattern(block.data, block.end, shape);
- if (result != LoaderResult::Success) return result;
+ if (!_parseShapeStrokeDashPattern(block.data, block.end, shape)) return false;
break;
}
}
ptr = block.end;
}
break;
}
}
ptr = block.end;
}
- return LoaderResult::Success;
-static LoaderResult _parseShape(TvgBinBlock block, Paint* paint)
+static bool _parseShape(TvgBinBlock block, Paint* paint)
{
auto shape = static_cast<Shape*>(paint);
switch (block.type) {
case TVG_SHAPE_PATH_INDICATOR: {
{
auto shape = static_cast<Shape*>(paint);
switch (block.type) {
case TVG_SHAPE_PATH_INDICATOR: {
- auto result = _parseShapePath(block.data, block.end, shape);
- if (result != LoaderResult::Success) return result;
+ if (!_parseShapePath(block.data, block.end, shape)) return false;
break;
}
case TVG_SHAPE_STROKE_INDICATOR: {
break;
}
case TVG_SHAPE_STROKE_INDICATOR: {
- auto result = _parseShapeStroke(block.data, block.end, shape);
- if (result != LoaderResult::Success) return result;
+ if (!_parseShapeStroke(block.data, block.end, shape)) return false;
break;
}
case TVG_SHAPE_FILL_INDICATOR: {
Fill* fill;
break;
}
case TVG_SHAPE_FILL_INDICATOR: {
Fill* fill;
- auto result = _parseShapeFill(block.data, block.end, &fill);
- if (result != LoaderResult::Success) return result;
+ if (!_parseShapeFill(block.data, block.end, &fill)) return false;
shape->fill(unique_ptr < Fill > (fill));
break;
}
case TVG_SHAPE_COLOR_INDICATOR: {
shape->fill(unique_ptr < Fill > (fill));
break;
}
case TVG_SHAPE_COLOR_INDICATOR: {
- if (block.length != 4) return LoaderResult::SizeCorruption;
+ if (block.length != 4) return false;
shape->fill(block.data[0], block.data[1], block.data[2], block.data[3]);
break;
}
case TVG_SHAPE_FILLRULE_INDICATOR: {
shape->fill(block.data[0], block.data[1], block.data[2], block.data[3]);
break;
}
case TVG_SHAPE_FILLRULE_INDICATOR: {
- if (block.length != sizeof(TvgFlag)) return LoaderResult::SizeCorruption;
+ if (block.length != sizeof(TvgFlag)) return false;
switch (*block.data) {
case TVG_SHAPE_FILLRULE_WINDING_FLAG:
shape->fill(FillRule::Winding);
switch (*block.data) {
case TVG_SHAPE_FILLRULE_WINDING_FLAG:
shape->fill(FillRule::Winding);
}
default: return _parsePaintProperty(block, shape);
}
}
default: return _parsePaintProperty(block, shape);
}
- return LoaderResult::Success;
-static LoaderResult _parsePicture(TvgBinBlock block, Paint* paint)
+static bool _parsePicture(TvgBinBlock block, Paint* paint)
{
auto picture = static_cast<Picture*>(paint);
switch (block.type) {
case TVG_RAW_IMAGE_BEGIN_INDICATOR: {
{
auto picture = static_cast<Picture*>(paint);
switch (block.type) {
case TVG_RAW_IMAGE_BEGIN_INDICATOR: {
- if (block.length < 2 * sizeof(uint32_t)) return LoaderResult::SizeCorruption;
+ if (block.length < 2 * sizeof(uint32_t)) return false;
auto ptr = block.data;
uint32_t w, h;
auto ptr = block.data;
uint32_t w, h;
ptr += sizeof(uint32_t);
auto size = w * h * sizeof(uint32_t);
ptr += sizeof(uint32_t);
auto size = w * h * sizeof(uint32_t);
- if (block.length != 2 * sizeof(uint32_t) + size) return LoaderResult::SizeCorruption;
+ if (block.length != 2 * sizeof(uint32_t) + size) return false;
- auto pixels = (uint32_t*) ptr;
- picture->load(pixels, w, h, true);
- return LoaderResult::Success;
+ picture->load((uint32_t*) ptr, w, h, true);
+ return true;
if (auto paint = _parsePaint(block)) {
picture->paint(unique_ptr<Paint>(paint));
if (auto paint = _parsePaint(block)) {
picture->paint(unique_ptr<Paint>(paint));
- return LoaderResult::Success;
- return LoaderResult::InvalidType;
}
static Paint* _parsePaint(TvgBinBlock baseBlock)
{
}
static Paint* _parsePaint(TvgBinBlock baseBlock)
{
- LoaderResult (*parser)(TvgBinBlock, Paint*);
+ bool (*parser)(TvgBinBlock, Paint*);
Paint *paint = nullptr;
switch (baseBlock.type) {
Paint *paint = nullptr;
switch (baseBlock.type) {
while (ptr < baseBlock.end) {
auto block = _readBlock(ptr);
if (block.end > baseBlock.end) return paint;
while (ptr < baseBlock.end) {
auto block = _readBlock(ptr);
if (block.end > baseBlock.end) return paint;
- auto result = parser(block, paint);
- if (result != LoaderResult::Success && result != LoaderResult::InvalidType) return paint;
+ //TODO: Do we need to clarify an invalid type case from the parsing failure?
+ if (!parser(block, paint)) return paint;
ptr = block.end;
}
return paint;
ptr = block.end;
}
return paint;