mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-04 04:50:22 +00:00
Merge branch 'QB64-Phoenix-Edition:main' into miniaudio-upgrade
This commit is contained in:
commit
57eaa8d119
1
Makefile
1
Makefile
|
@ -176,6 +176,7 @@ endif
|
|||
DEP_ICON_RC := y
|
||||
DEP_SOCKETS := y
|
||||
DEP_HTTP := y
|
||||
DEP_CONSOLE := y
|
||||
endif
|
||||
|
||||
include $(PATH_INTERNAL_C)/libqb/build.mk
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
// We need 'qbs' and 'image' structs stuff from here
|
||||
// This should eventually change when things are moved to smaller, logical and self-contained files
|
||||
#include "../../../libqb.h"
|
||||
#include "filepath.h"
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -178,11 +180,48 @@ static uint32_t *image_svg_load(NSVGimage *image, int32_t *xOut, int32_t *yOut,
|
|||
/// @param isVG Out: vector graphics? Always set to true
|
||||
/// @return A pointer to the raw pixel data in RGBA format or NULL on failure
|
||||
static uint32_t *image_svg_load_from_file(const char *fileName, int32_t *xOut, int32_t *yOut, ImageScaler scaler, int *components, bool *isVG) {
|
||||
auto image = nsvgParseFromFile(fileName, "px", 96.0f);
|
||||
if (!image)
|
||||
if (!filepath_has_extension(fileName, "svg"))
|
||||
return nullptr;
|
||||
|
||||
return image_svg_load(image, xOut, yOut, scaler, components, isVG);
|
||||
auto fp = fopen(fileName, "rb");
|
||||
if (!fp)
|
||||
return nullptr;
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
auto size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
auto svgString = (char *)malloc(size + 1);
|
||||
if (!svgString) {
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (fread(svgString, 1, size, fp) != size) {
|
||||
free(svgString);
|
||||
fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
svgString[size] = '\0'; // must be null terminated
|
||||
|
||||
fclose(fp);
|
||||
|
||||
// Check if it has a valid SVG start tag
|
||||
if (!strstr(svgString, "<svg")) {
|
||||
free(svgString);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto image = nsvgParse(svgString, "px", 96.0f); // important note: changes the string
|
||||
if (!image) {
|
||||
free(svgString);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto pixels = image_svg_load(image, xOut, yOut, scaler, components, isVG); // this is where everything else is freed
|
||||
free(svgString);
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
/// @brief Loads an SVG image file from memory
|
||||
|
@ -200,7 +239,13 @@ static uint32_t *image_svg_load_from_memory(const uint8_t *buffer, size_t size,
|
|||
return nullptr;
|
||||
|
||||
memcpy(svgString, buffer, size);
|
||||
svgString[size] = '\0';
|
||||
svgString[size] = '\0'; // must be null terminated
|
||||
|
||||
// Check if it has a valid SVG start tag
|
||||
if (!strstr(svgString, "<svg")) {
|
||||
free(svgString);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto image = nsvgParse(svgString, "px", 96.0f); // important note: changes the string
|
||||
if (!image) {
|
||||
|
@ -208,7 +253,7 @@ static uint32_t *image_svg_load_from_memory(const uint8_t *buffer, size_t size,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto pixels = image_svg_load(image, xOut, yOut, scaler, components, isVG);
|
||||
auto pixels = image_svg_load(image, xOut, yOut, scaler, components, isVG); // this is where everything else is freed
|
||||
free(svgString);
|
||||
|
||||
return pixels;
|
||||
|
|
|
@ -331,6 +331,7 @@ static float nsvg__normalize(float *x, float* y)
|
|||
}
|
||||
|
||||
static float nsvg__absf(float x) { return x < 0 ? -x : x; }
|
||||
static float nsvg__roundf(float x) { return (x >= 0) ? floorf(x + 0.5) : ceilf(x - 0.5); }
|
||||
|
||||
static void nsvg__flattenCubicBez(NSVGrasterizer* r,
|
||||
float x1, float y1, float x2, float y2,
|
||||
|
@ -872,10 +873,10 @@ static NSVGactiveEdge* nsvg__addActive(NSVGrasterizer* r, NSVGedge* e, float sta
|
|||
// STBTT_assert(e->y0 <= start_point);
|
||||
// round dx down to avoid going too far
|
||||
if (dxdy < 0)
|
||||
z->dx = (int)(-floorf(NSVG__FIX * -dxdy));
|
||||
z->dx = (int)(-nsvg__roundf(NSVG__FIX * -dxdy));
|
||||
else
|
||||
z->dx = (int)floorf(NSVG__FIX * dxdy);
|
||||
z->x = (int)floorf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
|
||||
z->dx = (int)nsvg__roundf(NSVG__FIX * dxdy);
|
||||
z->x = (int)nsvg__roundf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
|
||||
// z->x -= off_x * FIX;
|
||||
z->ey = e->y1;
|
||||
z->next = 0;
|
||||
|
@ -1282,7 +1283,7 @@ static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, float opac
|
|||
if (grad->nstops == 0) {
|
||||
for (i = 0; i < 256; i++)
|
||||
cache->colors[i] = 0;
|
||||
} if (grad->nstops == 1) {
|
||||
} else if (grad->nstops == 1) {
|
||||
for (i = 0; i < 256; i++)
|
||||
cache->colors[i] = nsvg__applyOpacity(grad->stops[i].color, opacity);
|
||||
} else {
|
||||
|
|
13552
internal/source/main.txt
13552
internal/source/main.txt
File diff suppressed because it is too large
Load diff
|
@ -141,6 +141,7 @@ do
|
|||
if [ "$CI_TESTING" == "y" ] && command -v pulseaudio > /dev/null
|
||||
then
|
||||
pulseaudio -k
|
||||
sleep .5
|
||||
pulseaudio -D
|
||||
fi
|
||||
else
|
||||
|
|
1
tests/compile_tests/image/bogus1.svg
Normal file
1
tests/compile_tests/image/bogus1.svg
Normal file
|
@ -0,0 +1 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
BIN
tests/compile_tests/image/bogus2.svg
Normal file
BIN
tests/compile_tests/image/bogus2.svg
Normal file
Binary file not shown.
730
tests/compile_tests/image/good1.svg
Normal file
730
tests/compile_tests/image/good1.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 94 KiB |
729
tests/compile_tests/image/good2.svg
Normal file
729
tests/compile_tests/image/good2.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 94 KiB |
28
tests/compile_tests/image/svg_test.bas
Normal file
28
tests/compile_tests/image/svg_test.bas
Normal file
|
@ -0,0 +1,28 @@
|
|||
$CONSOLE:ONLY
|
||||
OPTION _EXPLICIT
|
||||
|
||||
CHDIR _STARTDIR$
|
||||
|
||||
DIM fileName AS STRING
|
||||
|
||||
READ fileName
|
||||
WHILE LEN(fileName) > 0
|
||||
DIM img AS LONG: img = _LOADIMAGE("./" + fileName)
|
||||
|
||||
IF img < -1 THEN
|
||||
PRINT fileName; ": ("; _WIDTH(img); "x"; _HEIGHT(img); ") pixels"
|
||||
_FREEIMAGE img
|
||||
ELSE
|
||||
PRINT fileName; " is not a valid image file!"
|
||||
END IF
|
||||
|
||||
READ fileName
|
||||
WEND
|
||||
|
||||
SYSTEM
|
||||
|
||||
DATA good1.svg
|
||||
DATA good2.svg
|
||||
DATA bogus1.svg
|
||||
DATA bogus2.svg
|
||||
DATA
|
4
tests/compile_tests/image/svg_test.output
Normal file
4
tests/compile_tests/image/svg_test.output
Normal file
|
@ -0,0 +1,4 @@
|
|||
good1.svg: ( 493 x 800 ) pixels
|
||||
good2.svg: ( 493 x 800 ) pixels
|
||||
bogus1.svg is not a valid image file!
|
||||
bogus2.svg is not a valid image file!
|
Loading…
Reference in a new issue