Initial commit

This commit is contained in:
2025-11-01 23:54:33 -05:00
commit f397068f8d
44 changed files with 13027 additions and 0 deletions

View File

@@ -0,0 +1,177 @@
#pragma once
#include <TessesFramework/TessesFramework.hpp>
namespace Tesses::Framework::Graphics {
struct Color {
uint8_t Red=0;
uint8_t Green=0;
uint8_t Blue=0;
uint8_t Alpha=255;
Color();
Color(uint8_t r, uint8_t g, uint8_t b);
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
Color(Color c, uint8_t a);
Color(uint8_t* color_data);
std::string ToString(bool alphaIf255=false);
void ToArray(uint8_t* color_data);
static bool TryParse(std::string color, Color& col);
static Color Parse(std::string color);
bool operator!=(Color other);
bool operator==(Color other);
};
namespace Colors {
extern const Color AliceBlue;
extern const Color AntiqueWhite;
extern const Color Aqua;
extern const Color Aquamarine;
extern const Color Azure;
extern const Color Beige;
extern const Color Bisque;
extern const Color Black;
extern const Color BlanchedAlmond;
extern const Color Blue;
extern const Color BlueViolet;
extern const Color Brown;
extern const Color BurlyWood;
extern const Color CadetBlue;
extern const Color Chartreuse;
extern const Color Chocolate;
extern const Color Coral;
extern const Color CornflowerBlue;
extern const Color Cornsilk;
extern const Color Crimson;
extern const Color Cyan;
extern const Color DarkBlue;
extern const Color DarkCyan;
extern const Color DarkGoldenRod;
extern const Color DarkGray;
extern const Color DarkGrey;
extern const Color DarkGreen;
extern const Color DarkKhaki;
extern const Color DarkMagenta;
extern const Color DarkOliveGreen;
extern const Color DarkOrange;
extern const Color DarkOrchid;
extern const Color DarkRed;
extern const Color DarkSalmon;
extern const Color DarkSeaGreen;
extern const Color DarkSlateBlue;
extern const Color DarkSlateGray;
extern const Color DarkSlateGrey;
extern const Color DarkTurquoise;
extern const Color DarkViolet;
extern const Color DeepPink;
extern const Color DeepSkyBlue;
extern const Color DimGray;
extern const Color DimGrey;
extern const Color DodgerBlue;
extern const Color FireBrick;
extern const Color FloralWhite;
extern const Color ForestGreen;
extern const Color Fuchsia;
extern const Color Gainsboro;
extern const Color GhostWhite;
extern const Color Gold;
extern const Color GoldenRod;
extern const Color Gray;
extern const Color Grey;
extern const Color Green;
extern const Color GreenYellow;
extern const Color HoneyDew;
extern const Color HotPink;
extern const Color IndianRed;
extern const Color Indigo;
extern const Color Ivory;
extern const Color Khaki;
extern const Color Lavender;
extern const Color LavenderBlush;
extern const Color LawnGreen;
extern const Color LemonChiffon;
extern const Color LightBlue;
extern const Color LightCoral;
extern const Color LightCyan;
extern const Color LightGoldenRodYellow;
extern const Color LightGray;
extern const Color LightGrey;
extern const Color LightGreen;
extern const Color LightPink;
extern const Color LightSalmon;
extern const Color LightSeaGreen;
extern const Color LightSkyBlue;
extern const Color LightSlateGray;
extern const Color LightSlateGrey;
extern const Color LightSteelBlue;
extern const Color LightYellow;
extern const Color Lime;
extern const Color LimeGreen;
extern const Color Linen;
extern const Color Magenta;
extern const Color Maroon;
extern const Color MediumAquaMarine;
extern const Color MediumBlue;
extern const Color MediumOrchid;
extern const Color MediumPurple;
extern const Color MediumSeaGreen;
extern const Color MediumSlateBlue;
extern const Color MediumSpringGreen;
extern const Color MediumTurquoise;
extern const Color MediumVioletRed;
extern const Color MidnightBlue;
extern const Color MintCream;
extern const Color MistyRose;
extern const Color Moccasin;
extern const Color NavajoWhite;
extern const Color Navy;
extern const Color OldLace;
extern const Color Olive;
extern const Color OliveDrab;
extern const Color Orange;
extern const Color OrangeRed;
extern const Color Orchid;
extern const Color PaleGoldenRod;
extern const Color PaleGreen;
extern const Color PaleTurquoise;
extern const Color PaleVioletRed;
extern const Color PapayaWhip;
extern const Color PeachPuff;
extern const Color Peru;
extern const Color Pink;
extern const Color Plum;
extern const Color PowderBlue;
extern const Color Purple;
extern const Color RebeccaPurple;
extern const Color Red;
extern const Color RosyBrown;
extern const Color SaddleBrown;
extern const Color Salmon;
extern const Color SandyBrown;
extern const Color SeaGreen;
extern const Color SeaShell;
extern const Color Sienna;
extern const Color Silver;
extern const Color SkyBlue;
extern const Color SlateBlue;
extern const Color SlateGray;
extern const Color SlateGrey;
extern const Color Snow;
extern const Color SpringGreen;
extern const Color SteelBlue;
extern const Color Tan;
extern const Color Teal;
extern const Color Thistle;
extern const Color Tomato;
extern const Color Turquoise;
extern const Color Violet;
extern const Color Wheat;
extern const Color White;
extern const Color WhiteSmoke;
extern const Color Yellow;
extern const Color YellowGreen;
}
}

View File

@@ -0,0 +1,65 @@
#pragma once
#include "Color.hpp"
#include "Rectangle.hpp"
#include <vector>
namespace Tesses::Framework::Graphics {
class Font;
constexpr int32_t CharHeight = 16;
constexpr int64_t CharWidth = 16;
constexpr int32_t GetCharWidth(const int32_t chars)
{
return chars * 18;
}
enum class TextAlign {
TopLeft,
TopMiddle,
TopRight,
CenterLeft,
CenterMiddle,
CenterRight,
BottomLeft,
BottomMiddle,
BottomRight
};
enum class ImageCopyEffect {
Overwrite,
Invert,
InvertIfNotTransparent
};
enum class ScaleAlgorithm {
None,
NearestNeighbor
};
class Image {
uint32_t w=0;
uint32_t h=0;
std::vector<Color> data={};
void PlotLineLow(const Color& col, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
void PlotLineHigh(const Color& col, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
public:
Image();
Image(uint32_t w, uint32_t h);
Image(uint32_t w,uint32_t h,std::vector<Color> data);
uint32_t Width();
uint32_t Height();
void SetSize(uint32_t w, uint32_t h);
void SetSize(uint32_t w, uint32_t h, Color c);
void SetPixel(uint32_t x, uint32_t y, Color c);
Color GetPixel(uint32_t x, uint32_t y);
std::vector<Color>& Data();
void DrawRectangle(const Rectangle& rect, const Color& col, int borderSize=1);
void FillRectangle(const Rectangle& rect, const Color& col);
void DrawLine(const Point& pt1, const Point& pt2, const Color& col, int borderSize=1);
//text is 16x16
void DrawChar(char c, const Point& location, const Color& col);
void DrawString(std::string text, const Point& location, const Color& col);
//void RenderText(std::string text, const Font& font, const Color& col, const Point& loc);
//void RenderTextAligned(std::string text, const Font& font, const Color& col, const Rectangle& rect, TextAlign align);
void DrawImage(Image* src, const Point& pt, ImageCopyEffect copyEffect=ImageCopyEffect::Overwrite);
void Resize(Image* dest, const Size& sz, ScaleAlgorithm algo=ScaleAlgorithm::NearestNeighbor);
};
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "ImageFormat.hpp"
namespace Tesses::Framework::Graphics::ImageFormats {
class BitmapFormat : public ImageFormat {
public:
BitmapFormat();
void Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image);
void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags="");
};
};

View File

@@ -0,0 +1,15 @@
#pragma once
#include "BitmapFormat.hpp"
#include "PngFormat.hpp"
#include "JpegFormat.hpp"
namespace Tesses::Framework::Graphics::ImageFormats {
class Formats {
public:
static BitmapFormat Bitmap;
static PngFormat Png;
static JpegFormat Jpeg;
//Don't free the ImageFormat (may return null)
static ImageFormat* FromExtension(std::string ext);
};
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include <TessesFramework/Streams/Stream.hpp>
#include "../Image.hpp"
namespace Tesses::Framework::Graphics::ImageFormats {
class ImageFormat {
public:
virtual void Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image)=0;
virtual void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags="")=0;
virtual ~ImageFormat();
};
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "ImageFormat.hpp"
namespace Tesses::Framework::Graphics::ImageFormats {
class JpegFormat : public ImageFormat {
public:
JpegFormat();
void Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image);
void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags="");
};
};

View File

@@ -0,0 +1,10 @@
#pragma once
#include "ImageFormat.hpp"
namespace Tesses::Framework::Graphics::ImageFormats {
class PngFormat : public ImageFormat {
public:
PngFormat();
void Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image);
void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags="");
};
};

View File

@@ -0,0 +1,23 @@
#pragma once
#include <cstdint>
#include <string>
namespace Tesses::Framework::Graphics {
class Point {
public:
Point()
{
}
Point(int32_t x, int32_t y)
{
this->X = x;
this->Y = y;
}
int32_t X=0;
int32_t Y=0;
std::string ToString()
{
return std::to_string(X) + ", " + std::to_string(Y);
}
};
};

View File

@@ -0,0 +1,42 @@
#pragma once
#include "Point.hpp"
#include "Size.hpp"
namespace Tesses::Framework::Graphics {
class Rectangle {
public:
Rectangle()
{
}
Rectangle(Point pt, int32_t square) : Rectangle(pt, Graphics::Size(square))
{
}
Rectangle(int32_t x, int32_t y, int32_t square) : Rectangle(Point(x,y),square)
{
}
Rectangle(int32_t x, int32_t y, int32_t width, int32_t height) : Rectangle(Point(x,y),Graphics::Size(width,height))
{
}
Rectangle(Point pt, Size sz)
{
this->Location = pt;
this->Size = sz;
}
Graphics::Point Location;
Graphics::Size Size;
std::string ToString()
{
return std::to_string(Location.X) + ", " + std::to_string(Location.Y) + ", " + std::to_string(Size.Width) + ", " + std::to_string(Size.Height);
}
bool Intersects(Point pt)
{
return pt.X >= Location.X && pt.Y >= Location.Y && pt.X < (Location.X + Size.Width) && pt.Y < (Location.Y + Size.Height);
}
};
};

View File

@@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include <string>
namespace Tesses::Framework::Graphics {
class Size {
public:
Size()
{
}
Size(int32_t square)
{
this->Width = square;
this->Height = square;
}
Size(int32_t width, int32_t height)
{
this->Width = width;
this->Height = height;
}
int32_t Width=0;
int32_t Height=0;
bool IsSquare()
{
return Width == Height;
}
std::string ToString()
{
return std::to_string(Width) + "x" + std::to_string(Height);
}
};
};

View File

@@ -0,0 +1,6 @@
#pragma once
#include "Color.hpp"
#include "Image.hpp"
#include "Rectangle.hpp"
#include "ImageFormats/Formats.hpp"
#include "Webcam.hpp"

View File

@@ -0,0 +1,35 @@
#pragma once
#include "Image.hpp"
namespace Tesses::Framework::Graphics
{
class DeviceInfo {
public:
uint8_t Device;
std::string Name;
std::vector<Size> Resolutions;
};
class Device {
private:
std::shared_ptr<HiddenFieldData> field;
public:
Device(uint8_t device, const Size& sz, uint8_t fps=10);
void Open();
std::shared_ptr<Image> ReadFrame();
void Close();
~Device();
static bool IsEnabled();
static std::vector<DeviceInfo> GetDevices();
static void GetDevices(std::vector<DeviceInfo>& devices);
};
}