mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
common: code refactoring.
renamed loader classes same to Saver classes tvgLoaderMgr -> tvgLoader (tvgSaver) tvgLoader -> tvgLoadModule (tvgSaveModule)
This commit is contained in:
parent
3ae9e33c65
commit
e56476b7bd
19 changed files with 70 additions and 71 deletions
|
@ -15,10 +15,10 @@ source_file = [
|
||||||
'tvgBinaryDesc.h',
|
'tvgBinaryDesc.h',
|
||||||
'tvgFill.h',
|
'tvgFill.h',
|
||||||
'tvgLoader.h',
|
'tvgLoader.h',
|
||||||
'tvgLoaderMgr.h',
|
'tvgLoadModule.h',
|
||||||
'tvgPictureImpl.h',
|
'tvgPictureImpl.h',
|
||||||
'tvgRender.h',
|
'tvgRender.h',
|
||||||
'tvgSaver.h',
|
'tvgSaveModule.h',
|
||||||
'tvgSceneImpl.h',
|
'tvgSceneImpl.h',
|
||||||
'tvgShapeImpl.h',
|
'tvgShapeImpl.h',
|
||||||
'tvgTaskScheduler.h',
|
'tvgTaskScheduler.h',
|
||||||
|
@ -28,7 +28,7 @@ source_file = [
|
||||||
'tvgGlCanvas.cpp',
|
'tvgGlCanvas.cpp',
|
||||||
'tvgInitializer.cpp',
|
'tvgInitializer.cpp',
|
||||||
'tvgLinearGradient.cpp',
|
'tvgLinearGradient.cpp',
|
||||||
'tvgLoaderMgr.cpp',
|
'tvgLoader.cpp',
|
||||||
'tvgPaint.cpp',
|
'tvgPaint.cpp',
|
||||||
'tvgPicture.cpp',
|
'tvgPicture.cpp',
|
||||||
'tvgRadialGradient.cpp',
|
'tvgRadialGradient.cpp',
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
*/
|
*/
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgTaskScheduler.h"
|
#include "tvgTaskScheduler.h"
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
|
|
||||||
#ifdef THORVG_SW_RASTER_SUPPORT
|
#ifdef THORVG_SW_RASTER_SUPPORT
|
||||||
#include "tvgSwRenderer.h"
|
#include "tvgSwRenderer.h"
|
||||||
|
|
|
@ -19,18 +19,36 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef _TVG_LOADER_MGR_H_
|
#ifndef _TVG_LOAD_MODULE_H_
|
||||||
#define _TVG_LOADER_MGR_H_
|
#define _TVG_LOAD_MODULE_H_
|
||||||
|
|
||||||
#include "tvgLoader.h"
|
#include "tvgCommon.h"
|
||||||
|
|
||||||
struct LoaderMgr
|
namespace tvg
|
||||||
{
|
{
|
||||||
static bool init();
|
|
||||||
static bool term();
|
class LoadModule
|
||||||
static shared_ptr<Loader> loader(const string& path, bool* invalid);
|
{
|
||||||
static shared_ptr<Loader> loader(const char* data, uint32_t size, bool copy);
|
public:
|
||||||
static shared_ptr<Loader> loader(const uint32_t* data, uint32_t w, uint32_t h, bool copy);
|
//default view box, if any.
|
||||||
|
float vx = 0;
|
||||||
|
float vy = 0;
|
||||||
|
float vw = 0;
|
||||||
|
float vh = 0;
|
||||||
|
float w = 0, h = 0; //default image size
|
||||||
|
bool preserveAspect = true; //keep aspect ratio by default.
|
||||||
|
|
||||||
|
virtual ~LoadModule() {}
|
||||||
|
|
||||||
|
virtual bool open(const string& path) { /* Not supported */ return false; };
|
||||||
|
virtual bool open(const char* data, uint32_t size, bool copy) { /* Not supported */ return false; };
|
||||||
|
virtual bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) { /* Not supported */ return false; };
|
||||||
|
virtual bool read() = 0;
|
||||||
|
virtual bool close() = 0;
|
||||||
|
virtual const uint32_t* pixels() { return nullptr; };
|
||||||
|
virtual unique_ptr<Scene> scene() { return nullptr; };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_TVG_LOADER_MGR_H_
|
}
|
||||||
|
|
||||||
|
#endif //_TVG_LOAD_MODULE_H_
|
|
@ -19,7 +19,7 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
|
|
||||||
#ifdef THORVG_SVG_LOADER_SUPPORT
|
#ifdef THORVG_SVG_LOADER_SUPPORT
|
||||||
#include "tvgSvgLoader.h"
|
#include "tvgSvgLoader.h"
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static Loader* _find(FileType type)
|
static LoadModule* _find(FileType type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case FileType::Svg: {
|
case FileType::Svg: {
|
||||||
|
@ -114,7 +114,7 @@ static Loader* _find(FileType type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Loader* _find(const string& path)
|
static LoadModule* _find(const string& path)
|
||||||
{
|
{
|
||||||
auto ext = path.substr(path.find_last_of(".") + 1);
|
auto ext = path.substr(path.find_last_of(".") + 1);
|
||||||
if (!ext.compare("svg")) return _find(FileType::Svg);
|
if (!ext.compare("svg")) return _find(FileType::Svg);
|
||||||
|
@ -146,12 +146,12 @@ bool LoaderMgr::term()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shared_ptr<Loader> LoaderMgr::loader(const string& path, bool* invalid)
|
shared_ptr<LoadModule> LoaderMgr::loader(const string& path, bool* invalid)
|
||||||
{
|
{
|
||||||
*invalid = false;
|
*invalid = false;
|
||||||
|
|
||||||
if (auto loader = _find(path)) {
|
if (auto loader = _find(path)) {
|
||||||
if (loader->open(path)) return shared_ptr<Loader>(loader);
|
if (loader->open(path)) return shared_ptr<LoadModule>(loader);
|
||||||
else delete(loader);
|
else delete(loader);
|
||||||
*invalid = true;
|
*invalid = true;
|
||||||
}
|
}
|
||||||
|
@ -159,12 +159,12 @@ shared_ptr<Loader> LoaderMgr::loader(const string& path, bool* invalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shared_ptr<Loader> LoaderMgr::loader(const char* data, uint32_t size, bool copy)
|
shared_ptr<LoadModule> LoaderMgr::loader(const char* data, uint32_t size, bool copy)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < static_cast<int>(FileType::Unknown); i++) {
|
for (int i = 0; i < static_cast<int>(FileType::Unknown); i++) {
|
||||||
auto loader = _find(static_cast<FileType>(i));
|
auto loader = _find(static_cast<FileType>(i));
|
||||||
if (loader) {
|
if (loader) {
|
||||||
if (loader->open(data, size, copy)) return shared_ptr<Loader>(loader);
|
if (loader->open(data, size, copy)) return shared_ptr<LoadModule>(loader);
|
||||||
else delete(loader);
|
else delete(loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,12 +172,12 @@ shared_ptr<Loader> LoaderMgr::loader(const char* data, uint32_t size, bool copy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
shared_ptr<Loader> LoaderMgr::loader(const uint32_t *data, uint32_t w, uint32_t h, bool copy)
|
shared_ptr<LoadModule> LoaderMgr::loader(const uint32_t *data, uint32_t w, uint32_t h, bool copy)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < static_cast<int>(FileType::Unknown); i++) {
|
for (int i = 0; i < static_cast<int>(FileType::Unknown); i++) {
|
||||||
auto loader = _find(static_cast<FileType>(i));
|
auto loader = _find(static_cast<FileType>(i));
|
||||||
if (loader) {
|
if (loader) {
|
||||||
if (loader->open(data, w, h, copy)) return shared_ptr<Loader>(loader);
|
if (loader->open(data, w, h, copy)) return shared_ptr<LoadModule>(loader);
|
||||||
else delete(loader);
|
else delete(loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,33 +22,15 @@
|
||||||
#ifndef _TVG_LOADER_H_
|
#ifndef _TVG_LOADER_H_
|
||||||
#define _TVG_LOADER_H_
|
#define _TVG_LOADER_H_
|
||||||
|
|
||||||
#include "tvgCommon.h"
|
#include "tvgLoadModule.h"
|
||||||
|
|
||||||
namespace tvg
|
struct LoaderMgr
|
||||||
{
|
{
|
||||||
|
static bool init();
|
||||||
class Loader
|
static bool term();
|
||||||
{
|
static shared_ptr<LoadModule> loader(const string& path, bool* invalid);
|
||||||
public:
|
static shared_ptr<LoadModule> loader(const char* data, uint32_t size, bool copy);
|
||||||
//default view box, if any.
|
static shared_ptr<LoadModule> loader(const uint32_t* data, uint32_t w, uint32_t h, bool copy);
|
||||||
float vx = 0;
|
|
||||||
float vy = 0;
|
|
||||||
float vw = 0;
|
|
||||||
float vh = 0;
|
|
||||||
float w = 0, h = 0; //default image size
|
|
||||||
bool preserveAspect = true; //keep aspect ratio by default.
|
|
||||||
|
|
||||||
virtual ~Loader() {}
|
|
||||||
|
|
||||||
virtual bool open(const string& path) { /* Not supported */ return false; };
|
|
||||||
virtual bool open(const char* data, uint32_t size, bool copy) { /* Not supported */ return false; };
|
|
||||||
virtual bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) { /* Not supported */ return false; };
|
|
||||||
virtual bool read() = 0;
|
|
||||||
virtual bool close() = 0;
|
|
||||||
virtual const uint32_t* pixels() { return nullptr; };
|
|
||||||
virtual unique_ptr<Scene> scene() { return nullptr; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //_TVG_LOADER_H_
|
#endif //_TVG_LOADER_H_
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "tvgPaint.h"
|
#include "tvgPaint.h"
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
|
@ -47,7 +47,7 @@ struct PictureIterator : Iterator
|
||||||
|
|
||||||
struct Picture::Impl
|
struct Picture::Impl
|
||||||
{
|
{
|
||||||
shared_ptr<Loader> loader = nullptr;
|
shared_ptr<LoadModule> loader = nullptr;
|
||||||
Paint* paint = nullptr;
|
Paint* paint = nullptr;
|
||||||
uint32_t *pixels = nullptr;
|
uint32_t *pixels = nullptr;
|
||||||
Picture *picture = nullptr;
|
Picture *picture = nullptr;
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#ifndef _TVG_SAVER_H_
|
#ifndef _TVG_SAVE_MODULE_H_
|
||||||
#define _TVG_SAVER_H_
|
#define _TVG_SAVE_MODULE_H_
|
||||||
|
|
||||||
#include "tvgPaint.h"
|
#include "tvgPaint.h"
|
||||||
|
|
||||||
|
@ -44,4 +44,4 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //_TVG_SAVER_H_
|
#endif //_TVG_SAVE_MODULE_H_
|
|
@ -20,7 +20,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "tvgCommon.h"
|
#include "tvgCommon.h"
|
||||||
#include "tvgSaver.h"
|
#include "tvgSaveModule.h"
|
||||||
|
|
||||||
#ifdef THORVG_TVG_SAVER_SUPPORT
|
#ifdef THORVG_TVG_SAVER_SUPPORT
|
||||||
#include "tvgTvgSaver.h"
|
#include "tvgTvgSaver.h"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <turbojpeg.h>
|
#include <turbojpeg.h>
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
#include "tvgJpgLoader.h"
|
#include "tvgJpgLoader.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
|
@ -25,13 +25,13 @@
|
||||||
using tjhandle = void*;
|
using tjhandle = void*;
|
||||||
|
|
||||||
//TODO: Use Task?
|
//TODO: Use Task?
|
||||||
class JpgLoader : public Loader
|
class JpgLoader : public LoadModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
JpgLoader();
|
JpgLoader();
|
||||||
~JpgLoader();
|
~JpgLoader();
|
||||||
|
|
||||||
using Loader::open;
|
using LoadModule::open;
|
||||||
bool open(const string& path) override;
|
bool open(const string& path) override;
|
||||||
bool open(const char* data, uint32_t size, bool copy) override;
|
bool open(const char* data, uint32_t size, bool copy) override;
|
||||||
bool read() override;
|
bool read() override;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
#include "tvgPngLoader.h"
|
#include "tvgPngLoader.h"
|
||||||
|
|
||||||
PngLoader::PngLoader()
|
PngLoader::PngLoader()
|
||||||
|
|
|
@ -24,14 +24,13 @@
|
||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
//OPTIMIZE ME: Use Task?
|
class PngLoader : public LoadModule
|
||||||
class PngLoader : public Loader
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PngLoader();
|
PngLoader();
|
||||||
~PngLoader();
|
~PngLoader();
|
||||||
|
|
||||||
using Loader::open;
|
using LoadModule::open;
|
||||||
bool open(const string& path) override;
|
bool open(const string& path) override;
|
||||||
bool open(const char* data, uint32_t size, bool copy) override;
|
bool open(const char* data, uint32_t size, bool copy) override;
|
||||||
bool read() override;
|
bool read() override;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
*/
|
*/
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
#include "tvgRawLoader.h"
|
#include "tvgRawLoader.h"
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#ifndef _TVG_RAW_LOADER_H_
|
#ifndef _TVG_RAW_LOADER_H_
|
||||||
#define _TVG_RAW_LOADER_H_
|
#define _TVG_RAW_LOADER_H_
|
||||||
|
|
||||||
class RawLoader : public Loader
|
class RawLoader : public LoadModule
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const uint32_t* content = nullptr;
|
const uint32_t* content = nullptr;
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
~RawLoader();
|
~RawLoader();
|
||||||
|
|
||||||
using Loader::open;
|
using LoadModule::open;
|
||||||
bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) override;
|
bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) override;
|
||||||
bool read() override;
|
bool read() override;
|
||||||
bool close() override;
|
bool close() override;
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
#include "tvgXmlParser.h"
|
#include "tvgXmlParser.h"
|
||||||
#include "tvgSvgLoader.h"
|
#include "tvgSvgLoader.h"
|
||||||
#include "tvgSvgSceneBuilder.h"
|
#include "tvgSvgSceneBuilder.h"
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "tvgTaskScheduler.h"
|
#include "tvgTaskScheduler.h"
|
||||||
#include "tvgSvgLoaderCommon.h"
|
#include "tvgSvgLoaderCommon.h"
|
||||||
|
|
||||||
class SvgLoader : public Loader, public Task
|
class SvgLoader : public LoadModule, public Task
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
string filePath;
|
string filePath;
|
||||||
|
@ -40,7 +40,7 @@ public:
|
||||||
SvgLoader();
|
SvgLoader();
|
||||||
~SvgLoader();
|
~SvgLoader();
|
||||||
|
|
||||||
using Loader::open;
|
using LoadModule::open;
|
||||||
bool open(const string& path) override;
|
bool open(const string& path) override;
|
||||||
bool open(const char* data, uint32_t size, bool copy) override;
|
bool open(const char* data, uint32_t size, bool copy) override;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include "tvgLoaderMgr.h"
|
#include "tvgLoader.h"
|
||||||
#include "tvgTvgLoader.h"
|
#include "tvgTvgLoader.h"
|
||||||
#include "tvgTvgLoadParser.h"
|
#include "tvgTvgLoadParser.h"
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "tvgTaskScheduler.h"
|
#include "tvgTaskScheduler.h"
|
||||||
|
|
||||||
class TvgLoader : public Loader, public Task
|
class TvgLoader : public LoadModule, public Task
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const char* data = nullptr;
|
const char* data = nullptr;
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
|
|
||||||
~TvgLoader();
|
~TvgLoader();
|
||||||
|
|
||||||
using Loader::open;
|
using LoadModule::open;
|
||||||
bool open(const string &path) override;
|
bool open(const string &path) override;
|
||||||
bool open(const char *data, uint32_t size, bool copy) override;
|
bool open(const char *data, uint32_t size, bool copy) override;
|
||||||
bool read() override;
|
bool read() override;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "tvgSaver.h"
|
#include "tvgSaveModule.h"
|
||||||
#include "tvgTvgSaver.h"
|
#include "tvgTvgSaver.h"
|
||||||
|
|
||||||
#define SIZE(A) sizeof(A)
|
#define SIZE(A) sizeof(A)
|
||||||
|
|
Loading…
Add table
Reference in a new issue