1
1
Fork 0
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 toolchain-upgrade

This commit is contained in:
Samuel Gomes 2023-12-13 09:37:40 +05:30 committed by GitHub
commit 9572850494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 8327 additions and 6783 deletions

View file

@ -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

View file

@ -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;

View file

@ -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 {

File diff suppressed because it is too large Load diff

View file

@ -141,6 +141,7 @@ do
if [ "$CI_TESTING" == "y" ] && command -v pulseaudio > /dev/null
then
pulseaudio -k
sleep .5
pulseaudio -D
fi
else

View 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.

Binary file not shown.

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 94 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 94 KiB

View 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

View 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!