Skip to content

Commit

Permalink
Add dumpDraws and dumpDrawsToSVG to TestSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthaTi committed Jan 17, 2025
1 parent d784634 commit 668979c
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 44 deletions.
7 changes: 5 additions & 2 deletions dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
},
{
"dependencies": {
"silly": "~>1.1.1"
"silly": "~>1.1.1",
"elemi": "~>1.2.2",
"arsd-official:image_files": "~>11.3"
},
"importPaths": [
"tests",
Expand All @@ -43,7 +45,8 @@
"targetType": "library",
"versions": [
"Fluid_HeadlessOutput",
"Fluid_TestSpace"
"Fluid_TestSpace",
"Fluid_SVG"
]
},
{
Expand Down
39 changes: 8 additions & 31 deletions source/fluid/backend/headless.d
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// A headless backend. This backend does not actually render anything. This allows apps reliant on Fluid to run
/// A headless backend. This backend does not actually render anything. This allows apps reliant on Fluid to run
/// outside of graphical environments, provided an alternative method of access exist.
///
/// This backend is used internally in Fluid for performing tests. For this reason, this module may be configured to
/// capture the output in a way that can be analyzed or compared againt later. This functionality is disabled by
/// This backend is used internally in Fluid for performing tests. For this reason, this module may be configured to
/// capture the output in a way that can be analyzed or compared againt later. This functionality is disabled by
/// default due to significant overhead — use version `Fluid_HeadlessOutput` to turn it on.
///
/// If `elemi` is added as a dependency and `Fluid_HeadlessOutput` is set, the backend will also expose its
/// experimental SVG export functionality through `saveSVG`. It is only intended for testing; note it will export text
/// If `elemi` is added as a dependency and `Fluid_HeadlessOutput` is set, the backend will also expose its
/// experimental SVG export functionality through `saveSVG`. It is only intended for testing; note it will export text
/// as embedded raster images rather than proper vector text.
module fluid.backend.headless;

Expand Down Expand Up @@ -181,7 +181,7 @@ class HeadlessBackend : FluidBackend {
}

version (Fluid_HeadlessOutput) {

alias Drawing = SumType!(DrawnLine, DrawnTriangle, DrawnCircle, DrawnRectangle, DrawnTexture);

/// All items drawn during the last frame
Expand Down Expand Up @@ -484,7 +484,7 @@ class HeadlessBackend : FluidBackend {

Rectangle area() const {

if (_scissorsOn)
if (_scissorsOn)
return _area;
else
return Rectangle(0, 0, _windowSize.tupleof);
Expand Down Expand Up @@ -568,30 +568,7 @@ class HeadlessBackend : FluidBackend {
import arsd.png;
import arsd.image;

ubyte[] data;

// Load the image
final switch (image.format) {

case Image.Format.rgba:
data = cast(ubyte[]) image.rgbaPixels;
break;

// At the moment, this loads the palette available at the time of generation.
// Could it be possible to update the palette later?
case Image.Format.palettedAlpha:
data = cast(ubyte[]) image.palettedAlphaPixels
.map!(a => image.paletteColor(a))
.array;
break;

case Image.Format.alpha:
data = cast(ubyte[]) image.alphaPixels
.map!(a => Color(0xff, 0xff, 0xff, a))
.array;
break;

}
ubyte[] data = cast(ubyte[]) image.toRGBA.data;

// Load the image
auto arsdImage = new TrueColorImage(image.width, image.height, data);
Expand Down
Loading

0 comments on commit 668979c

Please sign in to comment.