mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44: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',
|
||||
'tvgFill.h',
|
||||
'tvgLoader.h',
|
||||
'tvgLoaderMgr.h',
|
||||
'tvgLoadModule.h',
|
||||
'tvgPictureImpl.h',
|
||||
'tvgRender.h',
|
||||
'tvgSaver.h',
|
||||
'tvgSaveModule.h',
|
||||
'tvgSceneImpl.h',
|
||||
'tvgShapeImpl.h',
|
||||
'tvgTaskScheduler.h',
|
||||
|
@ -28,7 +28,7 @@ source_file = [
|
|||
'tvgGlCanvas.cpp',
|
||||
'tvgInitializer.cpp',
|
||||
'tvgLinearGradient.cpp',
|
||||
'tvgLoaderMgr.cpp',
|
||||
'tvgLoader.cpp',
|
||||
'tvgPaint.cpp',
|
||||
'tvgPicture.cpp',
|
||||
'tvgRadialGradient.cpp',
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgTaskScheduler.h"
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
|
||||
#ifdef THORVG_SW_RASTER_SUPPORT
|
||||
#include "tvgSwRenderer.h"
|
||||
|
|
|
@ -19,18 +19,36 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef _TVG_LOADER_MGR_H_
|
||||
#define _TVG_LOADER_MGR_H_
|
||||
#ifndef _TVG_LOAD_MODULE_H_
|
||||
#define _TVG_LOAD_MODULE_H_
|
||||
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgCommon.h"
|
||||
|
||||
struct LoaderMgr
|
||||
namespace tvg
|
||||
{
|
||||
static bool init();
|
||||
static bool term();
|
||||
static shared_ptr<Loader> loader(const string& path, bool* invalid);
|
||||
static shared_ptr<Loader> loader(const char* data, uint32_t size, bool copy);
|
||||
static shared_ptr<Loader> loader(const uint32_t* data, uint32_t w, uint32_t h, bool copy);
|
||||
|
||||
class LoadModule
|
||||
{
|
||||
public:
|
||||
//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
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
|
||||
#ifdef THORVG_SVG_LOADER_SUPPORT
|
||||
#include "tvgSvgLoader.h"
|
||||
|
@ -43,7 +43,7 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static Loader* _find(FileType type)
|
||||
static LoadModule* _find(FileType type)
|
||||
{
|
||||
switch(type) {
|
||||
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);
|
||||
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;
|
||||
|
||||
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);
|
||||
*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++) {
|
||||
auto loader = _find(static_cast<FileType>(i));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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++) {
|
||||
auto loader = _find(static_cast<FileType>(i));
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -22,33 +22,15 @@
|
|||
#ifndef _TVG_LOADER_H_
|
||||
#define _TVG_LOADER_H_
|
||||
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgLoadModule.h"
|
||||
|
||||
namespace tvg
|
||||
struct LoaderMgr
|
||||
{
|
||||
|
||||
class Loader
|
||||
{
|
||||
public:
|
||||
//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 ~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; };
|
||||
static bool init();
|
||||
static bool term();
|
||||
static shared_ptr<LoadModule> loader(const string& path, bool* invalid);
|
||||
static shared_ptr<LoadModule> loader(const char* data, uint32_t size, bool copy);
|
||||
static shared_ptr<LoadModule> loader(const uint32_t* data, uint32_t w, uint32_t h, bool copy);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //_TVG_LOADER_H_
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <string>
|
||||
#include "tvgPaint.h"
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
/* Internal Class Implementation */
|
||||
|
@ -47,7 +47,7 @@ struct PictureIterator : Iterator
|
|||
|
||||
struct Picture::Impl
|
||||
{
|
||||
shared_ptr<Loader> loader = nullptr;
|
||||
shared_ptr<LoadModule> loader = nullptr;
|
||||
Paint* paint = nullptr;
|
||||
uint32_t *pixels = nullptr;
|
||||
Picture *picture = nullptr;
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#ifndef _TVG_SAVER_H_
|
||||
#define _TVG_SAVER_H_
|
||||
#ifndef _TVG_SAVE_MODULE_H_
|
||||
#define _TVG_SAVE_MODULE_H_
|
||||
|
||||
#include "tvgPaint.h"
|
||||
|
||||
|
@ -44,4 +44,4 @@ public:
|
|||
|
||||
}
|
||||
|
||||
#endif //_TVG_SAVER_H_
|
||||
#endif //_TVG_SAVE_MODULE_H_
|
|
@ -20,7 +20,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
#include "tvgCommon.h"
|
||||
#include "tvgSaver.h"
|
||||
#include "tvgSaveModule.h"
|
||||
|
||||
#ifdef THORVG_TVG_SAVER_SUPPORT
|
||||
#include "tvgTvgSaver.h"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <memory.h>
|
||||
#include <turbojpeg.h>
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgJpgLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
|
|
|
@ -25,13 +25,13 @@
|
|||
using tjhandle = void*;
|
||||
|
||||
//TODO: Use Task?
|
||||
class JpgLoader : public Loader
|
||||
class JpgLoader : public LoadModule
|
||||
{
|
||||
public:
|
||||
JpgLoader();
|
||||
~JpgLoader();
|
||||
|
||||
using Loader::open;
|
||||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read() override;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgPngLoader.h"
|
||||
|
||||
PngLoader::PngLoader()
|
||||
|
|
|
@ -24,14 +24,13 @@
|
|||
|
||||
#include <png.h>
|
||||
|
||||
//OPTIMIZE ME: Use Task?
|
||||
class PngLoader : public Loader
|
||||
class PngLoader : public LoadModule
|
||||
{
|
||||
public:
|
||||
PngLoader();
|
||||
~PngLoader();
|
||||
|
||||
using Loader::open;
|
||||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
bool read() override;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgRawLoader.h"
|
||||
|
||||
/************************************************************************/
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#ifndef _TVG_RAW_LOADER_H_
|
||||
#define _TVG_RAW_LOADER_H_
|
||||
|
||||
class RawLoader : public Loader
|
||||
class RawLoader : public LoadModule
|
||||
{
|
||||
public:
|
||||
const uint32_t* content = nullptr;
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
~RawLoader();
|
||||
|
||||
using Loader::open;
|
||||
using LoadModule::open;
|
||||
bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) override;
|
||||
bool read() override;
|
||||
bool close() override;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <fstream>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgXmlParser.h"
|
||||
#include "tvgSvgLoader.h"
|
||||
#include "tvgSvgSceneBuilder.h"
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "tvgTaskScheduler.h"
|
||||
#include "tvgSvgLoaderCommon.h"
|
||||
|
||||
class SvgLoader : public Loader, public Task
|
||||
class SvgLoader : public LoadModule, public Task
|
||||
{
|
||||
public:
|
||||
string filePath;
|
||||
|
@ -40,7 +40,7 @@ public:
|
|||
SvgLoader();
|
||||
~SvgLoader();
|
||||
|
||||
using Loader::open;
|
||||
using LoadModule::open;
|
||||
bool open(const string& path) override;
|
||||
bool open(const char* data, uint32_t size, bool copy) override;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <memory.h>
|
||||
#include "tvgLoaderMgr.h"
|
||||
#include "tvgLoader.h"
|
||||
#include "tvgTvgLoader.h"
|
||||
#include "tvgTvgLoadParser.h"
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "tvgTaskScheduler.h"
|
||||
|
||||
class TvgLoader : public Loader, public Task
|
||||
class TvgLoader : public LoadModule, public Task
|
||||
{
|
||||
public:
|
||||
const char* data = nullptr;
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
|
||||
~TvgLoader();
|
||||
|
||||
using Loader::open;
|
||||
using LoadModule::open;
|
||||
bool open(const string &path) override;
|
||||
bool open(const char *data, uint32_t size, bool copy) override;
|
||||
bool read() override;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "tvgSaver.h"
|
||||
#include "tvgSaveModule.h"
|
||||
#include "tvgTvgSaver.h"
|
||||
|
||||
#define SIZE(A) sizeof(A)
|
||||
|
|
Loading…
Add table
Reference in a new issue