mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 15:02:56 +02:00
add support for svg images
This commit is contained in:
@@ -21,4 +21,4 @@ libneutrino_pictureviewer_a_SOURCES = \
|
||||
gif.cpp \
|
||||
jpeg.cpp \
|
||||
pictureviewer.cpp \
|
||||
png.cpp bmp.cpp
|
||||
png.cpp bmp.cpp svg.cpp
|
||||
|
3411
src/driver/pictureviewer/nanosvg.h
Normal file
3411
src/driver/pictureviewer/nanosvg.h
Normal file
File diff suppressed because it is too large
Load Diff
1615
src/driver/pictureviewer/nanosvgrast.h
Normal file
1615
src/driver/pictureviewer/nanosvgrast.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,11 @@ extern int fh_crw_getsize (const char *, int *, int *, int, int);
|
||||
extern int fh_crw_load (const char *, unsigned char **, int *, int *);
|
||||
extern int fh_crw_id (const char *);
|
||||
#endif
|
||||
|
||||
#ifdef FBV_SUPPORT_SVG
|
||||
extern int fh_svg_getsize (const char *, int *, int *, int, int);
|
||||
extern int fh_svg_load (const char *, unsigned char **, int *, int *);
|
||||
extern int fh_svg_id (const char *);
|
||||
#endif
|
||||
double CPictureViewer::m_aspect_ratio_correction;
|
||||
|
||||
void CPictureViewer::add_format (int (*picsize) (const char *, int *, int *, int, int), int (*picread) (const char *, unsigned char **, int *, int *), int (*id) (const char *))
|
||||
@@ -77,6 +81,9 @@ void CPictureViewer::getSupportedImageFormats(std::vector<std::string>& exts)
|
||||
#ifdef FBV_SUPPORT_CRW
|
||||
exts.push_back(".crw");
|
||||
#endif
|
||||
#ifdef FBV_SUPPORT_SVG
|
||||
exts.push_back(".svg");
|
||||
#endif
|
||||
}
|
||||
|
||||
void CPictureViewer::init_handlers (void)
|
||||
@@ -96,6 +103,9 @@ void CPictureViewer::init_handlers (void)
|
||||
#ifdef FBV_SUPPORT_CRW
|
||||
add_format (fh_crw_getsize, fh_crw_load, fh_crw_id);
|
||||
#endif
|
||||
#ifdef FBV_SUPPORT_SVG
|
||||
add_format (fh_svg_getsize, fh_svg_load, fh_svg_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
CPictureViewer::CFormathandler * CPictureViewer::fh_getsize (const char *name, int *x, int *y, int width_wanted, int height_wanted)
|
||||
@@ -831,6 +841,9 @@ fb_pixel_t * CPictureViewer::int_getImage(const std::string & name, int *width,
|
||||
else
|
||||
#endif
|
||||
load_ret = fh->get_pic(name.c_str (), &buffer, &x, &y);
|
||||
#ifdef FBV_SUPPORT_SVG
|
||||
if (name.find(".svg") == (name.length() - 4)) bpp = 4;
|
||||
#endif
|
||||
dprintf(DEBUG_INFO, "[CPictureViewer] [%s - %d] load_result: %d \n", __func__, __LINE__, load_ret);
|
||||
|
||||
if (load_ret == FH_ERROR_OK)
|
||||
|
@@ -3,3 +3,4 @@
|
||||
#define FBV_SUPPORT_JPEG
|
||||
#define FBV_SUPPORT_GIF
|
||||
#define FBV_SUPPORT_CRW
|
||||
#define FBV_SUPPORT_SVG
|
||||
|
132
src/driver/pictureviewer/svg.cpp
Normal file
132
src/driver/pictureviewer/svg.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
Copyright (C) 2021 TangoCash
|
||||
|
||||
License: GPLv2
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation;
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Included Headers:
|
||||
|
||||
Copyright (c) 2013-14 Mikko Mononen memon@inside.org
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <float.h>
|
||||
#define NANOSVG_ALL_COLOR_KEYWORDS // Include full list of color keywords.
|
||||
#define NANOSVG_IMPLEMENTATION // Expands implementation
|
||||
#include "nanosvg.h"
|
||||
#define NANOSVGRAST_IMPLEMENTATION
|
||||
#include "nanosvgrast.h"
|
||||
|
||||
#include <config.h>
|
||||
#include "pv_config.h"
|
||||
|
||||
int fh_svg_id(const char *name)
|
||||
{
|
||||
std::string fn = name;
|
||||
if(fn.substr(fn.find_last_of(".") + 1) == "svg")
|
||||
return(1);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
int fh_svg_load(const char *name, unsigned char **buffer, int* xp, int* yp);
|
||||
|
||||
int fh_svg_load(const char *name, unsigned char **buffer, int* xp, int* yp)
|
||||
{
|
||||
NSVGimage *image = NULL;
|
||||
NSVGrasterizer *rast = NULL;
|
||||
int w, h;
|
||||
|
||||
//printf("[SVG] parsing load %s\n", name);
|
||||
image = nsvgParseFromFile(name, "px", 96.0f);
|
||||
if (image == NULL)
|
||||
{
|
||||
printf("[SVG] Could not open SVG image.\n");
|
||||
goto error;
|
||||
}
|
||||
w = (int)image->width;
|
||||
h = (int)image->height;
|
||||
|
||||
rast = nsvgCreateRasterizer();
|
||||
if (rast == NULL)
|
||||
{
|
||||
printf("[SVG] Could not init rasterizer.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(w > *xp || h > *yp)
|
||||
{
|
||||
free(*buffer);
|
||||
*buffer = (unsigned char*) malloc(w*h*4);
|
||||
}
|
||||
*xp = w;
|
||||
*yp = h;
|
||||
|
||||
if (buffer == NULL)
|
||||
{
|
||||
printf("[SVG] Could not alloc image buffer.\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
//printf("[SVG] rasterizing image %d x %d\n", w, h);
|
||||
nsvgRasterize(rast, image, 0,0,1, *buffer, w, h, w*4);
|
||||
|
||||
error:
|
||||
nsvgDeleteRasterizer(rast);
|
||||
nsvgDelete(image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fh_svg_getsize(const char *name,int *x,int *y, int /*wanted_width*/, int /*wanted_height*/)
|
||||
{
|
||||
NSVGimage *image = NULL;
|
||||
int w, h;
|
||||
|
||||
//printf("[SVG] parsing getsize %s\n", name);
|
||||
image = nsvgParseFromFile(name, "px", 96.0f);
|
||||
if (image == NULL)
|
||||
{
|
||||
printf("[SVG] Could not open SVG image.\n");
|
||||
goto error;
|
||||
}
|
||||
w = (int)image->width;
|
||||
h = (int)image->height;
|
||||
|
||||
*x = w;
|
||||
*y = h;
|
||||
|
||||
error:
|
||||
nsvgDelete(image);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user