Skip to content

Commit

Permalink
remove json
Browse files Browse the repository at this point in the history
  • Loading branch information
SupinePandora43 committed Dec 30, 2020
1 parent ae80bca commit ea85528
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 428 deletions.
354 changes: 0 additions & 354 deletions GmodUltralight/View.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,6 @@ void finishcallback(IntPtr data, View caller, ulong frameId, bool isMainFrame, s
case "ToAscii":
lua.PushManagedFunction(View_ToAscii);
break;
case "ToJsonRGBXY":
lua.PushManagedFunction(View_ToJsonRGBXY);
break;
case "ToJsonRGBXYW":
lua.PushManagedFunction(View_ToJsonRGBXYW);
break;
case "ToJsonRGBXYW_net5_ColoredRect":
lua.PushManagedFunction(View_ToJsonRGBXYW_net5_ColoredRect);
break;
case "ToJsonRGBXYW_net5_Array":
lua.PushManagedFunction(View_ToJsonRGBXYW_net5_Array);
break;
// CLIENT
case "DrawDirty":
lua.PushManagedFunction(View_DrawDirty);
Expand Down Expand Up @@ -457,347 +445,5 @@ int View_ToAscii(ILua lua)
lua.PushString(stringBuilder.ToString());
return 1;
}
int View_ToJsonRGBXY(ILua lua)
{
string viewID = (string)GCHandle.FromIntPtr(lua.GetUserType(1, View_TypeId)).Target;
View view = views[viewID];
Surface surface = view.GetSurface();
Bitmap bitmap = surface.GetBitmap();

JArray pixelArray = new();

try
{
unsafe
{
byte* pixels = (byte*)bitmap.LockPixels();
long index = 0;
uint height = view.GetHeight();
uint width = view.GetWidth();
for (uint y = 0; y < height; y++)
{
for (uint x = 0; x < width; x++)
{
pixelArray.Add(new JArray(new[] { pixels[index + 2], pixels[index + 1], pixels[index], x, y }));

index += 4;
}
}
pixels = null;
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
bitmap.UnlockPixels();
}
lua.PushString(pixelArray.ToString());
return 1;
}
int View_ToJsonRGBXYW(ILua lua)
{
string viewID = (string)GCHandle.FromIntPtr(lua.GetUserType(1, View_TypeId)).Target;
View view = views[viewID];
Surface surface = view.GetSurface();
Bitmap bitmap = surface.GetBitmap();

JArray pixelArray = new();

try
{
unsafe
{
byte* pixels = (byte*)bitmap.LockPixels();
long index = 0;
uint height = view.GetHeight();
uint width = view.GetWidth();
uint row_bytes = bitmap.GetRowBytes();
for (uint y = 0; y < height; y++)
{
bool firstRect = true;
byte _a = 0;
byte _r = 0;
byte _g = 0;
byte _b = 0;
uint rect_x = 0;
uint rect_width = 0;
for (uint x = 0; x < width; x++)
{
byte a = pixels[index + 3];
byte r = pixels[index + 2];
byte g = pixels[index + 1];
byte b = pixels[index];

if (firstRect)
{
if (x + 1 >= width)
{
pixelArray.Add(new JArray(new uint[] { r, g, b, x, y, 1 }));
}
else
{
rect_x = x;
rect_width = 1;
_a = a;
_r = r;
_g = g;
_b = b;
}
firstRect = false;
}
else
{
if (_a == a && _r == r && _g == g && _b == b)
{
rect_width++;
if (x + 1 >= width)
{
pixelArray.Add(new JArray(new uint[] { _r, _g, _b, rect_x, y, rect_width }));
}
}
else
{
pixelArray.Add(new JArray(new uint[] { _r, _g, _b, rect_x, y, rect_width }));
if (x + 1 >= width)
{
pixelArray.Add(new JArray(new uint[] { r, g, b, x, y, 1 }));
}
else
{
_a = a;
_r = r;
_g = g;
_b = b;
rect_x = x;
rect_width = 1;
}
}
}

index += 4;
}
}
pixels = null; // TODO: free memory?
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
bitmap.UnlockPixels();
}

lua.PushString(pixelArray.ToString());

return 1;
}

public class ColoredRect_RGB_XY_W
{
public byte r, g, b;
public uint x, y, w;
}

int View_ToJsonRGBXYW_net5_ColoredRect(ILua lua)
{
string viewID = (string)GCHandle.FromIntPtr(lua.GetUserType(1, View_TypeId)).Target;
View view = views[viewID];
Surface surface = view.GetSurface();
Bitmap bitmap = surface.GetBitmap();

List<ColoredRect_RGB_XY_W> pixelArray = new();

try
{
unsafe
{
byte* pixels = (byte*)bitmap.LockPixels();
long index = 0;
uint height = view.GetHeight();
uint width = view.GetWidth();
uint row_bytes = bitmap.GetRowBytes();
for (uint y = 0; y < height; y++)
{
bool firstRect = true;
byte _a = 0;
byte _r = 0;
byte _g = 0;
byte _b = 0;
uint rect_x = 0;
uint rect_width = 0;
for (uint x = 0; x < width; x++)
{
byte a = pixels[index + 3];
byte r = pixels[index + 2];
byte g = pixels[index + 1];
byte b = pixels[index];

if (firstRect)
{
if (x + 1 >= width)
{
pixelArray.Add(new ColoredRect_RGB_XY_W() { r = r, g = g, b = b, x = x, y = y, w = 1 });
}
else
{
rect_x = x;
rect_width = 1;
_a = a;
_r = r;
_g = g;
_b = b;
}
firstRect = false;
}
else
{
if (_a == a && _r == r && _g == g && _b == b)
{
rect_width++;
if (x + 1 >= width)
{
pixelArray.Add(new ColoredRect_RGB_XY_W() { r = _r, g = _g, b = _b, x = rect_x, y = y, w = rect_width });
}
}
else
{
pixelArray.Add(new ColoredRect_RGB_XY_W() { r = _r, g = _g, b = _b, x = rect_x, y = y, w = rect_width });
if (x + 1 >= width)
{
pixelArray.Add(new ColoredRect_RGB_XY_W() { r = r, g = g, b = b, x = x, y = y, w = 1 });
}
else
{
_a = a;
_r = r;
_g = g;
_b = b;
rect_x = x;
rect_width = 1;
}
}
}

index += 4;
}
}
pixels = null; // TODO: free memory?
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
bitmap.UnlockPixels();
}

lua.PushString(System.Text.Json.JsonSerializer.Serialize(pixelArray.ToArray()));
return 1;
}
int View_ToJsonRGBXYW_net5_Array(ILua lua)
{
string viewID = (string)GCHandle.FromIntPtr(lua.GetUserType(1, View_TypeId)).Target;
View view = views[viewID];
Surface surface = view.GetSurface();
Bitmap bitmap = surface.GetBitmap();

List<uint[]> pixelArray = new();

try
{
unsafe
{
byte* pixels = (byte*)bitmap.LockPixels();
long index = 0;
uint height = view.GetHeight();
uint width = view.GetWidth();
uint row_bytes = bitmap.GetRowBytes();
for (uint y = 0; y < height; y++)
{
bool firstRect = true;
byte _a = 0;
byte _r = 0;
byte _g = 0;
byte _b = 0;
uint rect_x = 0;
uint rect_width = 0;
for (uint x = 0; x < width; x++)
{
byte a = pixels[index + 3];
byte r = pixels[index + 2];
byte g = pixels[index + 1];
byte b = pixels[index];

if (firstRect)
{
if (x + 1 >= width)
{
pixelArray.Add(new uint[] { r, g, b, x, y, 1 });
}
else
{
rect_x = x;
rect_width = 1;
_a = a;
_r = r;
_g = g;
_b = b;
}
firstRect = false;
}
else
{
if (_a == a && _r == r && _g == g && _b == b)
{
rect_width++;
if (x + 1 >= width)
{
pixelArray.Add(new uint[] { _r, _g, _b, rect_x, y, rect_width });
}
}
else
{
pixelArray.Add(new uint[] { _r, _g, _b, rect_x, y, rect_width });
if (x + 1 >= width)
{
pixelArray.Add(new uint[] { r, g, b, x, y, 1 });
}
else
{
_a = a;
_r = r;
_g = g;
_b = b;
rect_x = x;
rect_width = 1;
}
}
}

index += 4;
}
}
pixels = null; // TODO: free memory?
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
bitmap.UnlockPixels();
}

lua.PushString(System.Text.Json.JsonSerializer.Serialize(pixelArray));
return 1;
}
}
}
Loading

0 comments on commit ea85528

Please sign in to comment.