debugging SVG

Signed-off-by: Slice <sergey.slice@gmail.com>
This commit is contained in:
Slice 2024-07-03 22:58:47 +03:00
parent 5333dff2c1
commit 1404ba662b
9 changed files with 183 additions and 151 deletions

View File

@ -652,14 +652,14 @@
<key>Tool</key>
<true/>
</dict>
<key>ScreenResolution?</key>
<string>1280x1024</string>
<key>ScreenResolution</key>
<string>1600x900</string>
<key>ShowOptimus?</key>
<false/>
<key>TextOnly</key>
<false/>
<key>Theme</key>
<string>Clovy</string>
<string>cesium</string>
<key>Timezone</key>
<integer>3</integer>
</dict>

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 409 KiB

After

Width:  |  Height:  |  Size: 402 KiB

View File

@ -29,11 +29,11 @@ then
echo "You must restore the folder \'"$(dirname "$qemu_path")"\'"
exit 1
fi
if ! [ -f "$SCRIPT_DIR"/disk_image_gpt.img ]
then
unzip -o "$SCRIPT_DIR"/disk_image_gpt.img.zip -d "$SCRIPT_DIR"
rm -rf "$SCRIPT_DIR"/__MACOSX
fi
# if ! [ -f "$SCRIPT_DIR"/disk_image_gpt.img ]
# then
# unzip -o "$SCRIPT_DIR"/disk_image_gpt.img.zip -d "$SCRIPT_DIR"
# rm -rf "$SCRIPT_DIR"/__MACOSX
# fi
if pgrep qemu
then
@ -44,7 +44,7 @@ then
if ! [ -z "$clover_efi_file" ]
then
hdiutil attach "$SCRIPT_DIR"/disk_image_gpt.img || exit 1
hdiutil attach "$SCRIPT_DIR"/QEMU-test2.img || exit 1
shopt -s nocasematch
@ -81,7 +81,7 @@ diskutil eject disk5
-bios "$bios_file" \
-machine q35 \
-device ahci,id=ahi \
-drive format=raw,id=hda,file=./disk_image_gpt.img \
-drive format=raw,id=hda,file=./QEMU-test2.img \
-usb \
-device usb-mouse,bus=usb-bus.0,port=2 \
-device usb-kbd,bus=usb-bus.0,port=1 \
@ -93,8 +93,8 @@ diskutil eject disk5
# -hdb "/JiefLand/Mac OS X 11.0.Beta10.vmwarevm/Virtual Disk.vmdk" \
# -hdc /JiefLand/5.Devel/Clover/CloverEfi.vmw/ElCapitan.vmdk \
hdiutil attach ./disk_image_gpt.img
diskutil mount disk5s1
hdiutil attach ./QEMU-test2.img
diskutil mount QEMU_EFI
fi

View File

@ -2,9 +2,9 @@
#cp -v /Users/sergey/src/edk2/Clover/CloverPackage/CloverV2/EFI/CLOVER/drivers64UEFI/VBoxHfs-64.efi /Volumes/TEFI/EFI/CLOVER/drivers64UEFI
#sudo umount /Volumes/QEFI
diskutil umount /dev/disk2s1
diskutil umount /dev/disk2s2
diskutil eject disk2
diskutil umount /dev/disk6s1
diskutil umount /dev/disk6s2
diskutil eject disk6
#qemu -L ~/Desktop/QEMU-Clover/QEMU -m 2048 -cpu core2duo -bios OVMF.fd -machine q35 -usb -device usb-mouse,bus=usb-bus.0,port=2 -device usb-kbd,bus=usb-bus.0,port=1 -device ahci,id=ahc -device ide-drive,bus=ahc.0,drive=hdc -drive id=hdc,file=/Users/sergey/Desktop/QEMU-Clover/QEMU-test2.img -device ide-drive,bus=ahc.1,drive=hdb -drive id=hdb,if=none,file=/Users/sergey/Desktop/QEMU-Clover/freedos.img -net nic,macaddr=00:12:32:43:55:16 -net user,name=lan -serial stdio
#qemu -L ~/Desktop/QEMU-Clover/QEMU -m 2048 -vga std -cpu core2duo -bios OVMF.fd -machine q35 -usb -device usb-mouse,bus=usb-bus.0,port=2 -device usb-kbd,bus=usb-bus.0,port=1 -hda /Users/sergey/Desktop/QEMU-Clover/QEMU-test2.img -hdc /Users/sergey/Desktop/QEMU-Clover/freedos.img -net nic,macaddr=00:12:32:43:55:16 -net user,name=lan

View File

@ -1020,8 +1020,8 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN OUT INTN *DefaultEntryIndex, OUT REFI
break;
case SCAN_F8:
// testSVG();
testBMP();
testSVG();
// testBMP();
testEfires();
break;

View File

@ -100,8 +100,8 @@ EFI_STATUS XTheme::ParseSVGXIcon(NSVGparser* SVGParser, INTN Id, const XString8&
return Status;
}
float bounds[4];
nsvg__imageBounds(SVGimage, bounds, IconNameX.c_str());
float bounds[4] = {0,0,0,0};
nsvg__imageBounds(SVGimage, bounds, IconNameX);
if ((Id == BUILTIN_ICON_BANNER) && IconNameX.contains("Banner")) {
BannerPosX = (int)(bounds[0] * Scale - CentreShift);
@ -132,9 +132,16 @@ EFI_STATUS XTheme::ParseSVGXIcon(NSVGparser* SVGParser, INTN Id, const XString8&
tx = (Width - realWidth) * 0.5f;
ty = (Height - realHeight) * 0.5f;
}
float ScaleY = Scale;
if (IconNameX.contains("sequoia") || IconNameX.contains("vent")) {
DBG("[0]=%f [1]=%f [2]=%f [3]=%f\n", bounds[0], bounds[1], bounds[2], bounds[3]);
//[0]=1330.129883 [1]=740.651855 [2]=1458.281494 [3]=886.530396
// ScaleY = -Scale;
}
NSVGrasterizer* rast = nsvg__createRasterizer();
nsvgRasterize(rast, SVGimage, bounds, IconNameX.c_str(), tx, ty, Scale, Scale, (UINT8*)NewImage.GetPixelPtr(0,0), iWidth, iHeight, iWidth*4);
nsvgRasterize(rast, SVGimage, bounds, IconNameX.c_str(), tx, ty, Scale, ScaleY, (UINT8*)NewImage.GetPixelPtr(0,0), iWidth, iHeight, iWidth*4);
nsvg__deleteRasterizer(rast);
*Image = NewImage; //copy array
@ -518,7 +525,7 @@ void testSVG()
float tx = 0; //-SVGimage->realBounds[0] * Scale;
float ty = 0; //-SVGimage->realBounds[1] * Scale;
DBG("timing rasterize start tx=%f ty=%f\n", tx, ty); //the aim is measure duration
nsvgRasterize(rast, SVGimage, tx,ty,Scale,Scale, (UINT8*)NewImage.GetPixelPtr(0,0), (int)Width, (int)Height, (int)Width*4);
nsvgRasterize(rast, SVGimage, tx,ty,Scale, -Scale, (UINT8*)NewImage.GetPixelPtr(0,0), (int)Width, (int)Height, (int)Width*4);
DBG("timing rasterize end\n");
NewImage.Draw((UGAWidth - Width) / 2,
(UGAHeight - Height) / 2);

View File

@ -47,7 +47,7 @@
#include "../include/OneLinerMacros.h"
#ifndef DEBUG_ALL
#define DEBUG_SVG 1
#define DEBUG_SVG 0
#else
#define DEBUG_SVG DEBUG_ALL
#endif
@ -952,7 +952,7 @@ static NSVGgradientLink* nsvg__createGradientLink(const char* id)
return grad;
}
static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape); //, float* xform);
static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape, bool dump); //, float* xform);
static NSVGgradient* nsvg__createGradient(NSVGparser* p, NSVGshape* shape, NSVGgradientLink* link, char* paintType)
{
@ -996,7 +996,7 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, NSVGshape* shape, NSVGg
// The shape width and height.
if (data->units == NSVG_OBJECT_SPACE) {
float localBounds[4];
nsvg__getLocalBounds(localBounds, shape); //, inv); //before any transform
nsvg__getLocalBounds(localBounds, shape, false); //, inv); //before any transform
ox = localBounds[0];
oy = localBounds[1];
@ -1063,7 +1063,7 @@ static float nsvg__getAverageScale(float* t)
return (nsvg__vmag(t[0], t[2]) + nsvg__vmag(t[1], t[3])) * 0.5f;
}
static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape) //, float* atXform)
static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape, bool dump) //, float* atXform)
{
NSVGpath* path;
float curve[8];
@ -1093,6 +1093,9 @@ static void nsvg__getLocalBounds(float* bounds, NSVGshape *shape) //, float* atX
curve[0] = curve[6];
curve[1] = curve[7];
}
// if (dump) {
// nsvg__dumpFloat(" local bounds ", bounds, 4);
// }
}
}
@ -1133,8 +1136,8 @@ static void nsvg__addShape(NSVGparser* p)
for (int i=0; i<shape->clip.count; i++) {
shape->clip.index[i] = p->clipPathStack[i];
}
nsvg__getLocalBounds(shape->bounds, shape); //(dest, src)
bool dump = (strstr(shape->id, "path8seq") != NULL);
nsvg__getLocalBounds(shape->bounds, shape, dump); //(dest, src)
// Set fill
shape->fill.type = NSVG_PAINT_NONE;
@ -4396,15 +4399,19 @@ int nsvg__shapesBound(/*NSVGimage* image,*/ NSVGshape *shapes, float* bounds, co
nsvg__takeXformBounds(shape, &xform2[0], bounds);
shape = shape->next;
}
/*
if (shapeLink->isText) { //strstr(shapeLink->id, "shar")) {
DBG("take Bounds: shapeID=%s\n", shapeLink->id);
nsvg__dumpFloat(" transform", xform, 6);
nsvg__dumpFloat(" shape initial bounds", shapeLink->bounds, 4);
}
*/
// if ((strstr(shapeLink->id, "seq") != NULL) || (strstr(shapeLink->id, "son") != NULL) ) {
// DBG("take Bounds: shapeID=%s\n", shapeLink->id);
// nsvg__dumpFloat(" transform", xform, 6);
// nsvg__dumpFloat(" shape initial bounds", &shapeLink->bounds[0], 4);
// }
count++; //count visible
}
// if ((strstr(groupName, "seq") != NULL) || (strstr(groupName, "ven") != NULL)) {
// DBG("group Bounds: ID=%s\n", groupName);
// nsvg__dumpFloat(" group bounds", &bounds[0], 4);
// }
return count;
}
@ -4446,11 +4453,16 @@ NSVGclipPath* nsvg__getClipPathWithIndex(NSVGimage* image, NSVGclipPathIndex idx
}
void nsvg__imageBounds(NSVGimage* image, float* bounds, const char* groupName)
void nsvg__imageBounds(NSVGimage* image, float* bounds, const XString8& IconNameX)
{
if (!bounds || !image) {
return;
}
// bool dump = (IconNameX.contains("sequoia") || IconNameX.contains("sonoma"));
// if (dump) {
// DBG("dump %s\n", IconNameX.c_str());
// }
const char* groupName = IconNameX.c_str();
bounds[0] = FLT_MAX;
bounds[1] = FLT_MAX;
bounds[2] = -FLT_MAX;
@ -4463,16 +4475,33 @@ void nsvg__imageBounds(NSVGimage* image, float* bounds, const char* groupName)
if ( groupName && !nsvg__isShapeInGroup(shape, groupName) ) {
continue;
}
// if (dump) {
// DBG("nsvg__imageBounds2 found shapes=%s shape->clip.count=%d\n", shape->id, shape->clip.count);
// }
for (int i = 0; i < shape->clip.count; i++) {
NSVGclipPath* clipPath = nsvg__getClipPathWithIndex(image, shape->clip.index[i]);
// if (dump) {
// //DBG("clip-id=%s clip index=%d\n", image->clipPaths->id, shape->clip.index[i]);
// nsvg__dumpFloat("clip shape bounds", &shape->bounds[0], 4);
// }
if ( clipPath ) {
count += nsvg__shapesBound(clipPath->shapes, bounds, NULL); // why NULL);?
// if (dump) {
// DBG("nsvg__imageBounds found clipPath %s\n", clipPath->id);
count += nsvg__shapesBound(clipPath->shapes, bounds, NULL);
}
}
//
// }
}
} //for clips
// if (dump) {
// nsvg__dumpFloat("clip image bounds", &shape->bounds[0], 4);
// }
} // for shapes
count += nsvg__shapesBound(image->shapes, bounds, groupName);
// if (dump) {
// nsvg__dumpFloat("final image real bounds", bounds, 4);
// }
if (count == 0) {
bounds[0] = bounds[1] = 0.0f;
bounds[2] = bounds[3] = 1.0f;

View File

@ -499,7 +499,7 @@ void nsvg__xformMultiply(float* t, float* s);
void nsvg__deleteFont(NSVGfont* font);
void nsvg__deleteFontChain(NSVGfontChain *fontChain);
void nsvg__imageBounds(NSVGimage* image, float* bounds);
void nsvg__imageBounds(NSVGimage* image, float* bounds, const char* groupName);
void nsvg__imageBounds(NSVGimage* image, float* bounds,const XString8& name);
float nsvg__addLetter(NSVGparser* p, CHAR16 letter, float x, float y, float scale, UINT32 color);
void RenderSVGfont(NSVGfont *fontSVG, UINT32 color);

View File

@ -41,7 +41,7 @@
#include "../Platform/Utils.h"
#ifndef DEBUG_ALL
#define DEBUG_SVG 1
#define DEBUG_SVG 0
#else
#define DEBUG_SVG DEBUG_ALL
#endif
@ -1634,9 +1634,11 @@ static void nsvg__rasterizeShapes(NSVGrasterizer* r,
UINT8* dst, int w, int h, int stride,
NSVGscanlineFunction fscanline)
{
#ifdef DEBUG_TRACE
DBG("nsvg__rasterizeShapes %s %f %f %f %f\n", groupName ? groupName : "", tx, ty, scalex, scaley);
#endif
// bool dump = (strstr(groupName, "seq") != NULL) || (strstr(groupName, "ven") != NULL) ; //XXX
// if (dump) {
// DBG("nsvg__rasterizeShapes %s %f %f %f %f\n", groupName ? groupName : shapes->id, tx, ty, scalex, scaley);
// }
NSVGshape *shape = NULL, *shapeLink = NULL;
float xform[6], xform2[6];
float min_scale = fabsf(scalex) < fabsf(scaley) ? fabsf(scalex) : fabsf(scaley);
@ -1676,7 +1678,11 @@ static void nsvg__rasterizeShapes(NSVGrasterizer* r,
xform[3] *= scaley;
xform[4] = xform[4] * scalex + tx;
xform[5] = xform[5] * scaley + ty;
// if (dump) {
// DBG("shape->id=%s\n", shape->id );
// nsvg__dumpFloat(" shape->xform ", xform, 6);
// nsvg__dumpFloat(" shape->bounds ", &shape->bounds[0], 4);
// }
if (!shape->link) {
renderShape(r, shape, &xform[0], min_scale);
}
@ -1702,19 +1708,23 @@ static void nsvg__rasterizeShapes(NSVGrasterizer* r,
static void renderShape(NSVGrasterizer* r,
NSVGshape* shape, float *xform, float min_scale)
{
#ifdef DEBUG_TRACE
DBG("render shape %s %f %f %f %f %f %f\n", shape->id, xform[0], xform[1], xform[2], xform[3], xform[4], xform[5]);
#endif
// bool dump = (strstr(shape->id, "seq") != NULL) || (strstr(shape->id, "ven") != NULL);
// if (dump) {
// DBG("render shape %s %f %f %f %f %f %f\n", shape->id,
// xform[0], xform[1], xform[2], xform[3], xform[4], xform[5]);
// }
NSVGedge *e = NULL;
NSVGcachedPaint cache;
SetMem(&cache, sizeof(NSVGcachedPaint), 0);
// if (dump) {
// NSVGclip& clip = shape->clip;
// DBG("renderShape %s with clips", shape->id);
// for (int i=0; i < clip.count; i++) {
// DBG(" %d", clip.index[i]);
// }
// DBG("\n");
// }
if (shape->fill.type != NSVG_PAINT_NONE) {
nsvg__resetPool(r);
@ -1800,7 +1810,7 @@ void nsvgRasterize(NSVGrasterizer* r,
NSVGimage* image, float tx, float ty, float scalex, float scaley,
UINT8* dst, int w, int h, int stride)
{
nsvgRasterize(r, image, &image->realBounds[0], NULL, tx, ty, scalex, scaley, dst, w, h, stride);
nsvgRasterize(r, image, &image->realBounds[0], NULL, tx, ty, scalex, fabsf(scaley), dst, w, h, stride);
}
void nsvgRasterize(NSVGrasterizer* r,
@ -1810,8 +1820,14 @@ void nsvgRasterize(NSVGrasterizer* r,
{
tx -= bounds[0] * scalex;
ty -= bounds[1] * scaley;
// if (scaley < 0) {
// DBG(" image %s will be scaled by [%f]\n", image->id, scalex);
// nsvg__dumpFloat(" image real bounds ", image->realBounds, 4);
// }
// if (strstr(groupName, "seq") != NULL || strstr(groupName, "ven") != NULL) {
// DBG(" image %s will be scaled by [%f]\n", groupName, scalex);
// nsvg__dumpFloat(" image real bounds ", image->realBounds, 4);
// }
nsvg__rasterizeClipPaths(r, image, w, h, tx, ty, scalex, scaley);