diff --git a/examples/lang_cs/lang_cs.csproj b/examples/lang_cs/lang_cs.csproj
index 33bbf25..1bf0ac8 100644
--- a/examples/lang_cs/lang_cs.csproj
+++ b/examples/lang_cs/lang_cs.csproj
@@ -12,16 +12,4 @@
-
-
- libservicepoint2.so
-
-
-
-
-
- libservicepoint2.so
-
-
-
diff --git a/servicepoint2-binding-cs/ServicePoint2/BindGen/ServicePoint2.g.cs b/servicepoint2-binding-cs/ServicePoint2/BindGen/ServicePoint2.g.cs
index 894b667..c5a0642 100644
--- a/servicepoint2-binding-cs/ServicePoint2/BindGen/ServicePoint2.g.cs
+++ b/servicepoint2-binding-cs/ServicePoint2/BindGen/ServicePoint2.g.cs
@@ -192,6 +192,10 @@ namespace ServicePoint2.BindGen
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint sp2_pixel_grid_height(PixelGrid* @this);
+ /// Gets a reference to the data of the `PixelGrid` instance.
+ [DllImport(__DllName, EntryPoint = "sp2_pixel_grid_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ public static extern byte* sp2_pixel_grid_data_ref(PixelGrid* @this);
+
}
diff --git a/servicepoint2-binding-cs/ServicePoint2/ByteGrid.cs b/servicepoint2-binding-cs/ServicePoint2/ByteGrid.cs
index 4c023a8..112c36e 100644
--- a/servicepoint2-binding-cs/ServicePoint2/ByteGrid.cs
+++ b/servicepoint2-binding-cs/ServicePoint2/ByteGrid.cs
@@ -1,3 +1,4 @@
+using System.Text;
using ServicePoint2.BindGen;
namespace ServicePoint2;
@@ -50,6 +51,36 @@ public sealed class ByteGrid : Sp2NativeInstance
}
}
+ public string this[int y]
+ {
+ set
+ {
+ var width = Width;
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(value.Length, width);
+
+ var x = 0;
+ for (; x < value.Length; x++)
+ this[x, y] = (byte)value[x];
+
+ for (; x < width; x++)
+ this[x, y] = 0;
+ }
+
+ get
+ {
+ var sb = new StringBuilder();
+ for (int x = 0; x < Width; x++)
+ {
+ var val = this[x, y];
+ if (val == 0)
+ break;
+ sb.Append((char)val);
+ }
+
+ return sb.ToString();
+ }
+ }
+
public void Fill(byte value)
{
unsafe
diff --git a/servicepoint2-binding-cs/ServicePoint2/PixelGrid.cs b/servicepoint2-binding-cs/ServicePoint2/PixelGrid.cs
index 9c202c7..855a128 100644
--- a/servicepoint2-binding-cs/ServicePoint2/PixelGrid.cs
+++ b/servicepoint2-binding-cs/ServicePoint2/PixelGrid.cs
@@ -80,6 +80,18 @@ public sealed class PixelGrid : Sp2NativeInstance
}
}
+ public Span Data
+ {
+ get
+ {
+ unsafe
+ {
+ var ptr = NativeMethods.sp2_pixel_grid_data_ref(Instance);
+ return new Span(ptr, Width * Height / 8);
+ }
+ }
+ }
+
private unsafe PixelGrid(BindGen.PixelGrid* instance) : base(instance)
{
}
diff --git a/servicepoint2-binding-cs/ServicePoint2/ServicePoint2.csproj b/servicepoint2-binding-cs/ServicePoint2/ServicePoint2.csproj
index 4a24632..b62a9ad 100644
--- a/servicepoint2-binding-cs/ServicePoint2/ServicePoint2.csproj
+++ b/servicepoint2-binding-cs/ServicePoint2/ServicePoint2.csproj
@@ -7,4 +7,16 @@
true
+
+
+ libservicepoint2.so
+
+
+
+
+
+ libservicepoint2.so
+
+
+
diff --git a/servicepoint2/src/bit_vec.rs b/servicepoint2/src/bit_vec.rs
index 2f28c19..6e41c1f 100644
--- a/servicepoint2/src/bit_vec.rs
+++ b/servicepoint2/src/bit_vec.rs
@@ -75,6 +75,10 @@ impl BitVec {
self.data.len() * 8
}
+ pub fn data_ref(&self) -> &[u8] {
+ &*self.data
+ }
+
fn get_indexes(&self, index: usize) -> (usize, u8) {
let byte_index = index / 8;
let bit_in_byte_index = 7 - index % 8;
@@ -160,7 +164,7 @@ pub mod c_api {
/// Gets the length of the `BitVec` in bits.
#[no_mangle]
- pub unsafe extern "C" fn sp2_bit_vec_len(this: *const BitVec) -> usize{
+ pub unsafe extern "C" fn sp2_bit_vec_len(this: *const BitVec) -> usize {
(*this).len()
}
}
diff --git a/servicepoint2/src/pixel_grid.rs b/servicepoint2/src/pixel_grid.rs
index eb736da..d6b8507 100644
--- a/servicepoint2/src/pixel_grid.rs
+++ b/servicepoint2/src/pixel_grid.rs
@@ -76,6 +76,10 @@ impl PixelGrid {
pub fn fill(&mut self, value: bool) {
self.bit_vec.fill(value);
}
+
+ pub fn data_ref(&self) -> &[u8] {
+ self.bit_vec.data_ref()
+ }
}
impl Into> for PixelGrid {
@@ -148,4 +152,11 @@ pub mod c_api
pub unsafe extern "C" fn sp2_pixel_grid_height(this: *const PixelGrid) -> usize {
(*this).height
}
+
+ /// Gets a reference to the data of the `PixelGrid` instance.
+ #[no_mangle]
+ pub unsafe extern "C" fn sp2_pixel_grid_data_ref(this: *const PixelGrid) -> *const u8 {
+ // TODO: also return length
+ (*this).data_ref().as_ptr_range().start
+ }
}