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

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.vscode
build

134
.onedev-buildspec.yml Normal file
View File

@@ -0,0 +1,134 @@
version: 39
jobs:
- name: Build
steps:
- !CheckoutStep
name: Checkout
cloneCredential: !DefaultCredential {}
withLfs: true
withSubmodules: true
cloneDepth: 1
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Jammy amd64
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/jammy:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-jammy.sh amd64
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Jammy arm64
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/jammy:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-jammy.sh arm64
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Jammy riscv64
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/jammy:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-jammy.sh riscv64
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Jammy armhf
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/jammy:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-jammy.sh armhf
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Plucky amd64
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/plucky:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-plucky.sh amd64
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Plucky arm64
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/plucky:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-plucky.sh arm64
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Plucky riscv64
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/plucky:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-plucky.sh riscv64
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Plucky armhf
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/plucky:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-plucky.sh armhf
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
- !CommandStep
name: Build Plucky i386
runInContainer: true
image: onedev.site.tesses.net/dependencies/debbuilder/plucky:latest
interpreter: !DefaultInterpreter
commands: |
cd Packaging/Linux
bash build-ubuntu-plucky.sh i386
envVars:
- name: GITEA_AUTH
value: '@secret:GITEA_AUTH@'
useTTY: true
condition: ALL_PREVIOUS_STEPS_WERE_SUCCESSFUL
triggers:
- !BranchUpdateTrigger {}
retryCondition: never
maxRetries: 3
retryDelay: 30
timeout: 14400

163
CMakeLists.txt Normal file
View File

@@ -0,0 +1,163 @@
cmake_minimum_required(VERSION 3.16)
project(TessesFrameworkGFX)
option(TESSESFRAMEWORKGFX_ENABLE_STATIC "Enable static build" ON)
option(TESSESFRAMEWORKGFX_ENABLE_SHARED "Enable shared build" ON)
option(TESSESFRAMEWORKGFX_ENABLE_EXAMPLES "Enable examples" OFF)
option(TESSESFRAMEWORKGFX_FETCHCONTENT "Fetch content" ON)
option(TESSESFRAMEWORKGFX_ENABLE_WEBCAM "Enable webcam" ON)
set(TESSESFRAMEWORKGFX_SOURCES
src/Color.cpp
src/Image.cpp
src/Webcam.cpp
src/Font.cpp
src/ImageCopy.cpp
src/ImageFormats/BitmapFormat.cpp
src/ImageFormats/PngFormat.cpp
src/ImageFormats/JpegFormat.cpp
src/ImageFormats/Formats.cpp
src/ImageFormats/stb/stb_image_wrapper.cpp
)
include(FetchContent)
include(GNUInstallDirs)
if(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
FetchContent_Declare(
webcam
GIT_REPOSITORY https://github.com/rojarand/libwebcam
)
if(TESSESFRAMEWORKGFX_ENABLE_STATIC)
set(LIB_MODE "STATIC")
else()
set(LIB_MODE "SHARED")
endif()
FetchContent_MakeAvailable(webcam)
if(TESSESFRAMEWORKGFX_ENABLE_STATIC AND TESSESFRAMEWORK_ENABLE_SHARED)
set_property(TARGET webcam PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
list(APPEND TessesFrameworkGFXLibs webcam)
endif()
if(TESSESFRAMEWORKGFX_ENABLE_STATIC)
add_library(tessesframework_gfx STATIC ${TESSESFRAMEWORKGFX_SOURCES})
if(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
target_link_libraries(tessesframework_gfx PUBLIC webcam)
target_compile_definitions(tessesframework_gfx PUBLIC TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
endif()
list(APPEND TessesFrameworkGFXLibs tessesframework_gfx)
target_include_directories(tessesframework_gfx
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
endif()
if(TESSESFRAMEWORKGFX_ENABLE_SHARED)
add_library(tessesframework_gfx_shared SHARED ${TESSESFRAMEWORKGFX_SOURCES})
if(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
target_link_libraries(tessesframework_gfx_shared PUBLIC webcam)
target_compile_definitions(tessesframework_gfx_shared PUBLIC TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
endif()
list(APPEND TessesFrameworkGFXLibs tessesframework_gfx_shared)
target_include_directories(tessesframework_gfx_shared
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
endif()
if(TESSESFRAMEWORKGFX_FETCHCONTENT)
FetchContent_Declare(
TessesFramework
GIT_REPOSITORY https://onedev.site.tesses.net/tesses-framework.git
)
FetchContent_MakeAvailable(TessesFramework)
if(TESSESFRAMEWORKGFX_ENABLE_STATIC)
target_link_libraries(tessesframework_gfx PUBLIC tessesframework)
endif()
if(TESSESFRAMEWORKGFX_ENABLE_SHARED)
target_link_libraries(tessesframework_gfx_shared PUBLIC tessesframework_shared)
endif()
list(APPEND TessesFrameworkGFXLibs ${TessesFrameworkTargets})
else()
find_package(TessesFramework REQUIRED)
if(TESSESFRAMEWORKGFX_ENABLE_STATIC)
target_link_libraries(tessesframework_gfx PUBLIC TessesFramework::tessesframework)
if(TESSESFRAMEWORKGFX_ENABLE_PNG)
target_compile_definitions(tessesframework_gfx PUBLIC TESSESFRAMEWORKGFX_ENABLE_PNG)
endif()
endif()
if(TESSESFRAMEWORKGFX_ENABLE_SHARED)
target_link_libraries(tessesframework_gfx_shared PUBLIC TessesFramework::tessesframework_shared)
endif()
endif()
if(TESSESFRAMEWORKGFX_ENABLE_EXAMPLES)
add_executable(createbmp examples/createbmp.cpp)
target_link_libraries(createbmp PUBLIC tessesframework_gfx)
add_executable(png2bmp examples/png2bmp.cpp)
target_link_libraries(png2bmp PUBLIC tessesframework_gfx)
add_executable(fillrect examples/fillrect.cpp)
target_link_libraries(fillrect PUBLIC tessesframework_gfx)
add_executable(drawfont examples/drawfont.cpp)
target_link_libraries(drawfont PUBLIC tessesframework_gfx)
add_executable(drawtext examples/drawtext.cpp)
target_link_libraries(drawtext PUBLIC tessesframework_gfx)
add_executable(resize examples/resize.cpp)
target_link_libraries(resize PUBLIC tessesframework_gfx)
if(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
add_executable(getdevices examples/getdevices.cpp)
target_link_libraries(getdevices PUBLIC tessesframework_gfx)
add_executable(capture examples/capture.cpp)
target_link_libraries(capture PUBLIC tessesframework_gfx)
endif()
endif()
install(TARGETS ${TessesFrameworkGFXLibs}
EXPORT TessesFrameworkGFXTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/TessesFrameworkGFX DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT TessesFrameworkGFXTargets
FILE TessesFrameworkGFXTargets.cmake
NAMESPACE TessesFrameworkGFX::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFrameworkGFX
)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkGFXConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFrameworkGFX)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkGFXConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFrameworkGFX)

10
Config.cmake.in Normal file
View File

@@ -0,0 +1,10 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/TessesFrameworkGFXTargets.cmake")
check_required_components(TessesFrameworkGFX)
find_package(TessesFramework)
if(@TESSESFRAMEWORKGFX_ENABLE_WEBCAM@)
find_package(webcam)
endif()

21
LICENSE.md Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Mike Nolan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,38 @@
#!/bin/bash
apt update -y
if [[ "$1" == "amd64" ]]; then
source ./version.sh
mkdir -p build/jammy
cd build/jammy
mkdir build-amd64
apt install -y git pkg-config tessesframework
cmake -S ../../../../ -B build-amd64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORKGFX_FETCHCONTENT=OFF
cd build-amd64
make -j`nproc`
make install DESTDIR=../tessesframework-gfx_$DEB_VERSION\_amd64
mkdir -p ../tessesframework-gfx_$DEB_VERSION\_amd64/DEBIAN
bash ../../../make-control.sh ../tessesframework-gfx_$DEB_VERSION\_amd64/DEBIAN/control amd64
cd ../
dpkg-deb --build tessesframework-gfx_$DEB_VERSION\_amd64
else
source ./version.sh
mkdir -p build/jammy
cd build/jammy
mkdir build-$1
apt install -y git pkg-config tessesframework:$1
cmake -S ../../../../ -B build-$1 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORKGFX_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/$1.cmake
cd build-$1
make -j`nproc`
make install DESTDIR=../tessesframework-gfx_$DEB_VERSION\_$1
mkdir -p ../tessesframework-gfx_$DEB_VERSION\_$1/DEBIAN
bash ../../../make-control.sh ../tessesframework-gfx_$DEB_VERSION\_$1/DEBIAN/control $1
cd ../
dpkg-deb --build tessesframework-gfx_$DEB_VERSION\_$1
fi
curl --user tesses50:$GITEA_AUTH -X DELETE \
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/tessesframework-gfx/$DEB_VERSION/$1
curl --user tesses50:$GITEA_AUTH \
--upload-file tessesframework-gfx_$DEB_VERSION\_$1.deb \
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/upload

View File

@@ -0,0 +1,34 @@
#!/bin/bash
DEBIAN_FRONTEND=noninteractive apt update -y
source ./version.sh
mkdir -p build/plucky
cd build/plucky
if [[ "$1" == "amd64" ]]; then
mkdir build-amd64
DEBIAN_FRONTEND=noninteractive apt install -y git pkg-config tessesframework
cmake -S ../../../../ -B build-amd64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORKGFX_FETCHCONTENT=OFF
cd build-amd64
make -j`nproc`
make install DESTDIR=../tessesframework--gfx_$DEB_VERSION\_amd64
mkdir -p ../tessesframework--gfx_$DEB_VERSION\_amd64/DEBIAN
bash ../../../make-control.sh ../tessesframework--gfx_$DEB_VERSION\_amd64/DEBIAN/control amd64
cd ../
dpkg-deb --build tessesframework--gfx_$DEB_VERSION\_amd64
else
mkdir build-$1
DEBIAN_FRONTEND=noninteractive apt install -y git pkg-config tessesframework:$1
cmake -S ../../../../ -B build-$1 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORKGFX_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/$1.cmake
cd build-$1
make -j`nproc`
make install DESTDIR=../tessesframework--gfx_$DEB_VERSION\_$1
mkdir -p ../tessesframework--gfx_$DEB_VERSION\_$1/DEBIAN
bash ../../../make-control.sh ../tessesframework--gfx_$DEB_VERSION\_$1/DEBIAN/control $1
cd ../
dpkg-deb --build tessesframework--gfx_$DEB_VERSION\_$1
fi
curl --user tesses50:$GITEA_AUTH -X DELETE \
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/tessesframework--gfx/$DEB_VERSION/$1
curl --user tesses50:$GITEA_AUTH \
--upload-file tessesframework--gfx_$DEB_VERSION\_$1.deb \
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/upload

View File

@@ -0,0 +1,8 @@
echo "Package: tessesframework-gfx" > "$1"
echo "Version: $DEB_VERSION" >> "$1"
echo "Architecture: $2" >> "$1"
echo "Essential: no" >> "$1"
echo "Priority: optional" >> "$1"
echo "Depends: tessesframework" >> "$1"
echo "Maintainer: Mike Nolan" >> "$1"
echo "Description: Graphics Library For TessesFramework" >> "$1"

View File

@@ -0,0 +1 @@
export DEB_VERSION=1.0.0

161
README.md Normal file
View File

@@ -0,0 +1,161 @@
Tesses Framework GFX
====================
A simple graphics library for C++
![TGFX Font](font.png)
You can use the font freely (I made it)
### To Install (from source)
```bash
git clone https://onedev.site.tesses.net/tesses-framework/tessesframework-gfx.git
cd tessesframework-gfx
cmake -S .. -B .
make -j`nproc`
sudo make install
```
### To Install (from source, without fetchcontent)
Get Tesses Framework [https://onedev.site.tesses.net/tesses-framework](https://onedev.site.tesses.net/tesses-framework)
```bash
git clone https://onedev.site.tesses.net/tesses-framework/tessesframework-gfx.git
cd tessesframework-gfx
cmake -S .. -B . -DTESSESFRAMEWORKGFX_FETCHCONTENT=OFF
make -j`nproc`
sudo make install
```
### To install on ubuntu from package manager
Set up my repos [here](https://crosslang.tesseslanguage.com/downloads/linux/ubuntu/index.html)
```bash
sudo apt update
sudo apt install tessesframework-gfx
```
### To use in C++ include
```c++
#include <TessesFrameworkGFX/TessesFrameworkGFX.hpp>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
...
int main(int argc, char** argv)
{
TF_Init();
...
TF_Quit();
}
```
### To create an image
```c++
Image image(640,480); //or without arguments
```
### To draw a line
```c++
image.DrawLine(Point(40,50),Point(50,60), Colors::Blue, 2); //line thickness is 2
```
### To draw a rectangle
```c++
image.DrawRectangle(Rectangle(8,8,20,20), Colors::Green, 5); //border size is 5
image.FillRectangle(Rectangle(8,40,20,28), Colors::Yellow); //fill a rectangle
```
### To draw text in that font above (it is my font)
the font is 16x16 but this function treats it as 18 width (for padding so the text isn't squished), this also only supports uppercase letters and the ascii table (no lower case or non ascii chars, non ascii chars will appear as spaces and lower case will appear as uppercase)
```c++
image.DrawString("Hello, world", Point(0,1),Colors::Red);
```
### Image formats
- Formats::Bitmap (my own)
- Formats::Png, Formats::Jpeg (stb_image, from here: [https://github.com/nothings/stb](https://github.com/nothings/stb))
### Loading images (png and jpeg use stb, bmp is my own implementation)
```c++
auto strm = std::make_shared<FileStream>("file.png","rb");
Formats::Png::Load(strm, &image);
```
### Saving images (png and jpeg use stb, bmp is my own implementation)
```c++
auto strm = std::make_shared<FileStream>("file.png","wb");
Formats::Png::Save(strm, &image);
```
### Resizing images (uses nearest neighbor by default and is the only option right now)
```c++
Image newImage;
image.Resize(&newImage,Size(320,240));
```
### Drawing images onto other images
Overwrite just overwrites existing pixels in destination from source, Invert inverts the src pixels when copying from source to destination (does not touch source, just so we are clear), InvertIfNotTransparent inverts pixels in the destination image if the alpha channel in source image is >127
also point is for location in destination, it will use 0, 0 in source and w, h for source
```c++
Image srcImg;
image.DrawImage(&srcImg, Point(10,10), ImageCopyEffect::Overwrite);
```
### Resizing and drawing to another image
We need to combine the last two examples
- srcImg: the source picture
- tmpImg: the resized image
- image: the image we want to draw to
```c++
Image srcImg; //this would not be right here it would have data in it (even text you want to make bigger)
Image tmpImg;
srcImg.Resize(&tmpImg,Size(320,240));
image.DrawImage(&tmpImg, Point(10,10), ImageCopyEffect::Overwrite);
```
### Webcam
On windows and linux if TESSESFRAMEWORKGFX_ENABLE_WEBCAM is defined in cmake
You can use this to find webcams
It will not find any if TESSESFRAMEWORKGFX_ENABLE_WEBCAM is not defined and Device::IsEnabled() will return false
Uses [https://github.com/rojarand/libwebcam](https://github.com/rojarand/libwebcam) released under MIT (FetchContent, and is optional)
```c++
auto devs = Device::GetDevices();
for(auto dev : devs)
{
std::cout << dev.Name << std::endl;
for(auto res : dev.Resolutions)
{
std::cout << "\t" << res.ToString() << std::endl;
//if this camera and resolution are desired
Device dev2(dev.Device, res,10); //10 fps
dev2.Open();
do {
auto frame = auto frame = dev2.ReadFrame();
if(frame != nullptr)
{
//frame is a shared pointer to an image
Image* img = frame.get(); //if you need a pointer for saving or whatnot
}
} while(true);
dev2.Close();
}
std::cout << std::endl;
}
```

46
examples/capture.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
Tesses::Framework::TF_Init();
auto devs = Device::GetDevices();
for(auto dev : devs)
{
for(auto res : dev.Resolutions)
{
Device dev2(dev.Device, res,10);
dev2.Open();
usleep(5000000);
auto frame = dev2.ReadFrame();
if(frame != nullptr)
{
Image clock;
Image clock2;
auto strm = std::make_shared<FileStream>("capture.png","wb");
auto date = Tesses::Framework::Date::DateTime::Now();
auto dateStr = date.ToString("%Y/%m/%d %I:%M %p");
clock.SetSize(GetCharWidth(dateStr.size()),CharHeight+2, Color(0,0,0,0));
//frame->FillRectangle(Rectangle(0,0,w,CharHeight+2),Colors::Blue);
clock.DrawString(dateStr,Point(0,1),Colors::Black);
clock.Resize(&clock2,Size(clock.Width()*2,clock.Height()*2));
frame->DrawImage(&clock2,Point(0,0), ImageCopyEffect::InvertIfNotTransparent);
Formats::Png.Save(strm,frame.get());
}
dev2.Close();
break;
}
}
return 0;
}

72
examples/createbmp.cpp Normal file
View File

@@ -0,0 +1,72 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
#define WIDTH 19
#define HEIGHT 12
#define A 0x0A
#define B 0x0B
#define C 0x0C
char house[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //1
0,0,0,0,0,0,0,0,9,9,0,0,0,7,0,0,B,B,0, //2
0,0,0,8,8,0,0,0,9,9,0,0,7,6,7,0,A,0,B, //3
0,0,0,8,8,0,0,0,0,0,0,7,C,C,C,7,A,0,0, //4
0,8,8,8,8,8,8,0,0,0,7,C,C,C,C,C,7,0,0, //5
0,8,8,8,8,8,8,0,0,7,7,7,7,7,7,7,7,7,0, //6
0,0,0,8,8,0,0,0,0,1,5,5,5,5,5,5,5,1,0, //7
0,0,0,8,8,0,0,0,0,1,6,5,3,3,3,5,6,1,0, //8
4,4,4,8,8,4,4,4,4,1,6,5,3,2,3,5,6,1,4, //9
4,4,4,8,8,4,4,4,4,1,5,5,3,2,3,5,5,1,4, //10
4,4,4,4,4,4,4,4,4,1,1,1,1,1,1,1,1,1,4, //11
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 //12
};
int main(int argc, char** argv)
{
TF_InitWithConsole();
Color pallete[] = {
Colors::SkyBlue,
Colors::Grey,
Colors::Crimson,
Colors::Lime,
Colors::LawnGreen,
Colors::DarkOliveGreen,
Colors::DimGrey,
Colors::BurlyWood,
Colors::White,
Colors::Yellow,
Colors::FireBrick,
Colors::WhiteSmoke,
Colors::DarkGoldenRod
};
Image img(WIDTH*32,HEIGHT*32);
for(uint32_t y = 0; y < HEIGHT; y++)
{
for(uint32_t x = 0; x < WIDTH; x++)
{
char c = house[y * WIDTH + x];
for(uint32_t y0 = 0; y0 < 32; y0++)
{
uint32_t y1 = y * 32 + y0;
for(uint32_t x0 = 0; x0 < 32;x0++)
{
uint32_t x1 = x * 32 + x0;
img.SetPixel(x1,y1, pallete[c]);
}
}
}
}
auto strm = std::make_shared<FileStream>("house.bmp","wb");
Formats::Bitmap.Save(strm,&img);
}

38
examples/drawfont.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
TF_InitWithConsole();
Image img;
auto strm = std::make_shared<FileStream>(argv[1],"wb");
std::vector<std::string> chrs = {
"!\"#$%&\'(",
")*+,-./0",
"12345678",
"9:;<=>?@",
"ABCDEFGH",
"IJKLMNOP",
"QRSTUVWX",
"YZ[\\]^_`",
"{|}~TGFX"
};
img.SetSize(144,(uint32_t)(18*chrs.size()),Colors::White);
for(int y = 0; y < chrs.size(); y++)
{
for(int x = 0; x < 8; x++)
{
img.DrawChar(chrs[y][x],Point(1+(18*x),1+(18*y)),Colors::Black);
}
}
Formats::Png.Save(strm,&img);
}

22
examples/drawtext.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
TF_InitWithConsole();
Image img;
std::string text=argv[1];
auto strm = std::make_shared<FileStream>(argv[2],"wb");
img.SetSize((uint32_t)GetCharWidth(text.size()),CharHeight+2,Colors::White);
img.DrawString(text,Point(0,1),Colors::Black);
Formats::Png.Save(strm,&img);
}

23
examples/fillrect.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
TF_InitWithConsole();
Image img;
img.SetSize(128,128,Color::Parse(argv[2]));
auto strm = std::make_shared<FileStream>(argv[1],"wb");
img.FillRectangle(Rectangle(32,32,64,64),Color::Parse(argv[3]));
img.DrawLine(Point(8,8),Point(100,58),Colors::Yellow,10);
img.DrawLine(Point(100,58),Point(8,100),Colors::Yellow,10);
Formats::Png.Save(strm,&img);
}

23
examples/getdevices.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
auto devs = Device::GetDevices();
for(auto dev : devs)
{
std::cout << dev.Name << std::endl;
for(auto res : dev.Resolutions)
{
std::cout << "\t" << res.ToString() << std::endl;
}
std::cout << std::endl;
}
return 0;
}

19
examples/png2bmp.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
TF_InitWithConsole();
Image img;
auto srcStrm = std::make_shared<FileStream>(argv[1],"rb");
auto strm = std::make_shared<FileStream>(argv[2],"wb");
Formats::Png.Load(srcStrm,&img);
Formats::Bitmap.Save(strm,&img);
}

23
examples/resize.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "TessesFrameworkGFX/TessesFrameworkGFX.hpp"
#include <cstdlib>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Graphics;
using namespace Tesses::Framework::Graphics::ImageFormats;
using namespace Tesses::Framework::Streams;
int main(int argc, char** argv)
{
TF_Init();
auto srcStrm = std::make_shared<FileStream>(argv[2],"rb");
auto destStrm = std::make_shared<FileStream>(argv[3],"wb");
auto res = Http::HttpUtils::SplitString(argv[1],"x");
int w = std::stoi(res.at(0));
int h = std::stoi(res.at(1));
Image srcImg;
Image destImg;
Formats::Png.Load(srcStrm, &srcImg);
srcImg.Resize(&destImg,Size(w,h));
Formats::Png.Save(destStrm,&destImg);
}

BIN
font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

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);
};
}

432
src/Color.cpp Normal file
View File

@@ -0,0 +1,432 @@
#include "TessesFrameworkGFX/Color.hpp"
#include "TessesFramework/Http/HttpUtils.hpp"
using HttpUtils = Tesses::Framework::Http::HttpUtils;
namespace Tesses::Framework::Graphics {
namespace Colors {
const Color AliceBlue(240,248,255);
const Color AntiqueWhite(250,235,215);
const Color Aqua(0,255,255);
const Color Aquamarine(127,255,212);
const Color Azure(240,255,255);
const Color Beige(245,245,220);
const Color Bisque(255,228,196);
const Color Black(0,0,0);
const Color BlanchedAlmond(255,235,205);
const Color Blue(0,0,255);
const Color BlueViolet(138,43,226);
const Color Brown(165,42,42);
const Color BurlyWood(222,184,135);
const Color CadetBlue(95,158,160);
const Color Chartreuse(127,255,0);
const Color Chocolate(210,105,30);
const Color Coral(255,127,80);
const Color CornflowerBlue(100,149,237);
const Color Cornsilk(255,248,220);
const Color Crimson(220,20,60);
const Color Cyan(0,255,255);
const Color DarkBlue(0,0,139);
const Color DarkCyan(0,139,139);
const Color DarkGoldenRod(184,134,11);
const Color DarkGray(169,169,169);
const Color DarkGrey(169,169,169);
const Color DarkGreen(0,100,0);
const Color DarkKhaki(189,183,107);
const Color DarkMagenta(139,0,139);
const Color DarkOliveGreen(85,107,47);
const Color DarkOrange(255,140,0);
const Color DarkOrchid(153,50,204);
const Color DarkRed(139,0,0);
const Color DarkSalmon(233,150,122);
const Color DarkSeaGreen(143,188,143);
const Color DarkSlateBlue(72,61,139);
const Color DarkSlateGray(47,79,79);
const Color DarkSlateGrey(47,79,79);
const Color DarkTurquoise(0,206,209);
const Color DarkViolet(148,0,211);
const Color DeepPink(255,20,147);
const Color DeepSkyBlue(0,191,255);
const Color DimGray(105,105,105);
const Color DimGrey(105,105,105);
const Color DodgerBlue(30,144,255);
const Color FireBrick(178,34,34);
const Color FloralWhite(255,250,240);
const Color ForestGreen(34,139,34);
const Color Fuchsia(255,0,255);
const Color Gainsboro(220,220,220);
const Color GhostWhite(248,248,255);
const Color Gold(255,215,0);
const Color GoldenRod(218,165,32);
const Color Gray(128,128,128);
const Color Grey(128,128,128);
const Color Green(0,128,0);
const Color GreenYellow(173,255,47);
const Color HoneyDew(240,255,240);
const Color HotPink(255,105,180);
const Color IndianRed(205,92,92);
const Color Indigo(75,0,130);
const Color Ivory(255,255,240);
const Color Khaki(240,230,140);
const Color Lavender(230,230,250);
const Color LavenderBlush(255,240,245);
const Color LawnGreen(124,252,0);
const Color LemonChiffon(255,250,205);
const Color LightBlue(173,216,230);
const Color LightCoral(240,128,128);
const Color LightCyan(224,255,255);
const Color LightGoldenRodYellow(250,250,210);
const Color LightGray(211,211,211);
const Color LightGrey(211,211,211);
const Color LightGreen(144,238,144);
const Color LightPink(255,182,193);
const Color LightSalmon(255,160,122);
const Color LightSeaGreen(32,178,170);
const Color LightSkyBlue(135,206,250);
const Color LightSlateGray(119,136,153);
const Color LightSlateGrey(119,136,153);
const Color LightSteelBlue(176,196,222);
const Color LightYellow(255,255,224);
const Color Lime(0,255,0);
const Color LimeGreen(50,205,50);
const Color Linen(250,240,230);
const Color Magenta(255,0,255);
const Color Maroon(128,0,0);
const Color MediumAquaMarine(102,205,170);
const Color MediumBlue(0,0,205);
const Color MediumOrchid(186,85,211);
const Color MediumPurple(147,112,219);
const Color MediumSeaGreen(60,179,113);
const Color MediumSlateBlue(123,104,238);
const Color MediumSpringGreen(0,250,154);
const Color MediumTurquoise(72,209,204);
const Color MediumVioletRed(199,21,133);
const Color MidnightBlue(25,25,112);
const Color MintCream(245,255,250);
const Color MistyRose(255,228,225);
const Color Moccasin(255,228,181);
const Color NavajoWhite(255,222,173);
const Color Navy(0,0,128);
const Color OldLace(253,245,230);
const Color Olive(128,128,0);
const Color OliveDrab(107,142,35);
const Color Orange(255,165,0);
const Color OrangeRed(255,69,0);
const Color Orchid(218,112,214);
const Color PaleGoldenRod(238,232,170);
const Color PaleGreen(152,251,152);
const Color PaleTurquoise(175,238,238);
const Color PaleVioletRed(219,112,147);
const Color PapayaWhip(255,239,213);
const Color PeachPuff(255,218,185);
const Color Peru(205,133,63);
const Color Pink(255,192,203);
const Color Plum(221,160,221);
const Color PowderBlue(176,224,230);
const Color Purple(128,0,128);
const Color RebeccaPurple(102,51,153);
const Color Red(255,0,0);
const Color RosyBrown(188,143,143);
const Color SaddleBrown(139,69,19);
const Color Salmon(250,128,114);
const Color SandyBrown(244,164,96);
const Color SeaGreen(46,139,87);
const Color SeaShell(255,245,238);
const Color Sienna(160,82,45);
const Color Silver(192,192,192);
const Color SkyBlue(135,206,235);
const Color SlateBlue(106,90,205);
const Color SlateGray(112,128,144);
const Color SlateGrey(112,128,144);
const Color Snow(255,250,250);
const Color SpringGreen(0,255,127);
const Color SteelBlue(70,130,180);
const Color Tan(210,180,140);
const Color Teal(0,128,128);
const Color Thistle(216,191,216);
const Color Tomato(255,99,71);
const Color Turquoise(64,224,208);
const Color Violet(238,130,238);
const Color Wheat(245,222,179);
const Color White(255,255,255);
const Color WhiteSmoke(245,245,245);
const Color Yellow(255,255,0);
const Color YellowGreen(154,205,50);
}
Color::Color()
{
}
Color::Color(uint8_t r, uint8_t g, uint8_t b) : Color(r,g,b,255)
{
}
Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
this->Red = r;
this->Green = g;
this->Blue = b;
this->Alpha = a;
}
Color::Color(Color c, uint8_t a) : Color(c.Red,c.Green,c.Blue,a)
{
}
Color::Color(uint8_t* color_data) : Color(color_data[0],color_data[1],color_data[2],color_data[3])
{
}
std::string Color::ToString(bool alphaIf255)
{
std::string str={
'#',
HttpUtils::NibbleToHex((Red >> 4) & 0x0F),
HttpUtils::NibbleToHex(Red & 0x0F),
HttpUtils::NibbleToHex((Green >> 4) & 0x0F),
HttpUtils::NibbleToHex(Green & 0x0F),
HttpUtils::NibbleToHex((Blue >> 4) & 0x0F),
HttpUtils::NibbleToHex(Blue & 0x0F)
};
if(alphaIf255 || this->Alpha < 255)
{
str.push_back(HttpUtils::NibbleToHex((Blue >> 4) & 0x0F));
str.push_back(HttpUtils::NibbleToHex(Blue & 0x0F));
}
return str;
}
void Color::ToArray(uint8_t* color_data)
{
color_data[0] = Red;
color_data[1] = Green;
color_data[2] = Blue;
color_data[3] = Alpha;
}
bool Color::TryParse(std::string color, Color& col)
{
color = HttpUtils::ToLower(color);
if(color.size() < 1) return false;
else if(color[0] != '#') {
if(color == "aliceblue") {col = Colors::AliceBlue; return true;}
else if(color == "antiquewhite") {col = Colors::AntiqueWhite; return true;}
else if(color == "aqua") {col = Colors::Aqua; return true;}
else if(color == "aquamarine") {col = Colors::Aquamarine; return true;}
else if(color == "azure"){ col = Colors::Azure; return true; }
else if(color == "beige"){ col = Colors::Beige; return true; }
else if(color == "bisque"){ col = Colors::Bisque; return true; }
else if(color == "black"){ col = Colors::Black; return true; }
else if(color == "blanchedalmond"){ col = Colors::BlanchedAlmond; return true; }
else if(color == "blue"){ col = Colors::Blue; return true; }
else if(color == "blueviolet"){ col = Colors::BlueViolet; return true; }
else if(color == "brown"){ col = Colors::Brown; return true; }
else if(color == "burlywood"){ col = Colors::BurlyWood; return true; }
else if(color == "cadetblue"){ col = Colors::CadetBlue; return true; }
else if(color == "chartreuse"){ col = Colors::Chartreuse; return true; }
else if(color == "chocolate"){ col = Colors::Chocolate; return true; }
else if(color == "coral"){ col = Colors::Coral; return true; }
else if(color == "cornflowerblue"){ col = Colors::CornflowerBlue; return true; }
else if(color == "cornsilk"){ col = Colors::Cornsilk; return true; }
else if(color == "crimson"){ col = Colors::Crimson; return true; }
else if(color == "cyan"){ col = Colors::Cyan; return true; }
else if(color == "darkblue"){ col = Colors::DarkBlue; return true; }
else if(color == "darkcyan"){ col = Colors::DarkCyan; return true; }
else if(color == "darkgoldenrod"){ col = Colors::DarkGoldenRod; return true; }
else if(color == "darkgray"){ col = Colors::DarkGray; return true; }
else if(color == "darkgrey"){ col = Colors::DarkGrey; return true; }
else if(color == "darkgreen"){ col = Colors::DarkGreen; return true; }
else if(color == "darkkhaki"){ col = Colors::DarkKhaki; return true; }
else if(color == "darkmagenta"){ col = Colors::DarkMagenta; return true; }
else if(color == "darkolivegreen"){ col = Colors::DarkOliveGreen; return true; }
else if(color == "darkorange"){ col = Colors::DarkOrange; return true; }
else if(color == "darkorchid"){ col = Colors::DarkOrchid; return true; }
else if(color == "darkred"){ col = Colors::DarkRed; return true; }
else if(color == "darksalmon"){ col = Colors::DarkSalmon; return true; }
else if(color == "darkseagreen"){ col = Colors::DarkSeaGreen; return true; }
else if(color == "darkslateblue"){ col = Colors::DarkSlateBlue; return true; }
else if(color == "darkslategray"){ col = Colors::DarkSlateGray; return true; }
else if(color == "darkslategrey"){ col = Colors::DarkSlateGrey; return true; }
else if(color == "darkturquoise"){ col = Colors::DarkTurquoise; return true; }
else if(color == "darkviolet"){ col = Colors::DarkViolet; return true; }
else if(color == "deeppink"){ col = Colors::DeepPink; return true; }
else if(color == "deepskyblue"){ col = Colors::DeepSkyBlue; return true; }
else if(color == "dimgray"){ col = Colors::DimGray; return true; }
else if(color == "dimgrey"){ col = Colors::DimGrey; return true; }
else if(color == "dodgerblue"){ col = Colors::DodgerBlue; return true; }
else if(color == "firebrick"){ col = Colors::FireBrick; return true; }
else if(color == "floralwhite"){ col = Colors::FloralWhite; return true; }
else if(color == "forestgreen"){ col = Colors::ForestGreen; return true; }
else if(color == "fuchsia"){ col = Colors::Fuchsia; return true; }
else if(color == "gainsboro"){ col = Colors::Gainsboro; return true; }
else if(color == "ghostwhite"){ col = Colors::GhostWhite; return true; }
else if(color == "gold"){ col = Colors::Gold; return true; }
else if(color == "goldenrod"){ col = Colors::GoldenRod; return true; }
else if(color == "gray"){ col = Colors::Gray; return true; }
else if(color == "grey"){ col = Colors::Grey; return true; }
else if(color == "green"){ col = Colors::Green; return true; }
else if(color == "greenyellow"){ col = Colors::GreenYellow; return true; }
else if(color == "honeydew"){ col = Colors::HoneyDew; return true; }
else if(color == "hotpink"){ col = Colors::HotPink; return true; }
else if(color == "indianred"){ col = Colors::IndianRed; return true; }
else if(color == "indigo"){ col = Colors::Indigo; return true; }
else if(color == "ivory"){ col = Colors::Ivory; return true; }
else if(color == "khaki"){ col = Colors::Khaki; return true; }
else if(color == "lavender"){ col = Colors::Lavender; return true; }
else if(color == "lavenderblush"){ col = Colors::LavenderBlush; return true; }
else if(color == "lawngreen"){ col = Colors::LawnGreen; return true; }
else if(color == "lemonchiffon"){ col = Colors::LemonChiffon; return true; }
else if(color == "lightblue"){ col = Colors::LightBlue; return true; }
else if(color == "lightcoral"){ col = Colors::LightCoral; return true; }
else if(color == "lightcyan"){ col = Colors::LightCyan; return true; }
else if(color == "lightgoldenrodyellow"){ col = Colors::LightGoldenRodYellow; return true; }
else if(color == "lightgray"){ col = Colors::LightGray; return true; }
else if(color == "lightgrey"){ col = Colors::LightGrey; return true; }
else if(color == "lightgreen"){ col = Colors::LightGreen; return true; }
else if(color == "lightpink"){ col = Colors::LightPink; return true; }
else if(color == "lightsalmon"){ col = Colors::LightSalmon; return true; }
else if(color == "lightseagreen"){ col = Colors::LightSeaGreen; return true; }
else if(color == "lightskyblue"){ col = Colors::LightSkyBlue; return true; }
else if(color == "lightslategray"){ col = Colors::LightSlateGray; return true; }
else if(color == "lightslategrey"){ col = Colors::LightSlateGrey; return true; }
else if(color == "lightsteelblue"){ col = Colors::LightSteelBlue; return true; }
else if(color == "lightyellow"){ col = Colors::LightYellow; return true; }
else if(color == "lime"){ col = Colors::Lime; return true; }
else if(color == "limegreen"){ col = Colors::LimeGreen; return true; }
else if(color == "linen"){ col = Colors::Linen; return true; }
else if(color == "magenta"){ col = Colors::Magenta; return true; }
else if(color == "maroon"){ col = Colors::Maroon; return true; }
else if(color == "mediumaquamarine"){ col = Colors::MediumAquaMarine; return true; }
else if(color == "mediumblue"){ col = Colors::MediumBlue; return true; }
else if(color == "mediumorchid"){ col = Colors::MediumOrchid; return true; }
else if(color == "mediumpurple"){ col = Colors::MediumPurple; return true; }
else if(color == "mediumseagreen"){ col = Colors::MediumSeaGreen; return true; }
else if(color == "mediumslateblue"){ col = Colors::MediumSlateBlue; return true; }
else if(color == "mediumspringgreen"){ col = Colors::MediumSpringGreen; return true; }
else if(color == "mediumturquoise"){ col = Colors::MediumTurquoise; return true; }
else if(color == "mediumvioletred"){ col = Colors::MediumVioletRed; return true; }
else if(color == "midnightblue"){ col = Colors::MidnightBlue; return true; }
else if(color == "mintcream"){ col = Colors::MintCream; return true; }
else if(color == "mistyrose"){ col = Colors::MistyRose; return true; }
else if(color == "moccasin"){ col = Colors::Moccasin; return true; }
else if(color == "navajowhite"){ col = Colors::NavajoWhite; return true; }
else if(color == "navy"){ col = Colors::Navy; return true; }
else if(color == "oldlace"){ col = Colors::OldLace; return true; }
else if(color == "olive"){ col = Colors::Olive; return true; }
else if(color == "olivedrab"){ col = Colors::OliveDrab; return true; }
else if(color == "orange"){ col = Colors::Orange; return true; }
else if(color == "orangered"){ col = Colors::OrangeRed; return true; }
else if(color == "orchid"){ col = Colors::Orchid; return true; }
else if(color == "palegoldenrod"){ col = Colors::PaleGoldenRod; return true; }
else if(color == "palegreen"){ col = Colors::PaleGreen; return true; }
else if(color == "paleturquoise"){ col = Colors::PaleTurquoise; return true; }
else if(color == "palevioletred"){ col = Colors::PaleVioletRed; return true; }
else if(color == "papayawhip"){ col = Colors::PapayaWhip; return true; }
else if(color == "peachpuff"){ col = Colors::PeachPuff; return true; }
else if(color == "peru"){ col = Colors::Peru; return true; }
else if(color == "pink"){ col = Colors::Pink; return true; }
else if(color == "plum"){ col = Colors::Plum; return true; }
else if(color == "powderblue"){ col = Colors::PowderBlue; return true; }
else if(color == "purple"){ col = Colors::Purple; return true; }
else if(color == "rebeccapurple"){ col = Colors::RebeccaPurple; return true; }
else if(color == "red"){ col = Colors::Red; return true; }
else if(color == "rosybrown"){ col = Colors::RosyBrown; return true; }
else if(color == "saddlebrown"){ col = Colors::SaddleBrown; return true; }
else if(color == "salmon"){ col = Colors::Salmon; return true; }
else if(color == "sandybrown"){ col = Colors::SandyBrown; return true; }
else if(color == "seagreen"){ col = Colors::SeaGreen; return true; }
else if(color == "seashell"){ col = Colors::SeaShell; return true; }
else if(color == "sienna"){ col = Colors::Sienna; return true; }
else if(color == "silver"){ col = Colors::Silver; return true; }
else if(color == "skyblue"){ col = Colors::SkyBlue; return true; }
else if(color == "slateblue"){ col = Colors::SlateBlue; return true; }
else if(color == "slategray"){ col = Colors::SlateGray; return true; }
else if(color == "slategrey"){ col = Colors::SlateGrey; return true; }
else if(color == "snow"){ col = Colors::Snow; return true; }
else if(color == "springgreen"){ col = Colors::SpringGreen; return true; }
else if(color == "steelblue"){ col = Colors::SteelBlue; return true; }
else if(color == "tan"){ col = Colors::Tan; return true; }
else if(color == "teal"){ col = Colors::Teal; return true; }
else if(color == "thistle"){ col = Colors::Thistle; return true; }
else if(color == "tomato"){ col = Colors::Tomato; return true; }
else if(color == "turquoise"){ col = Colors::Turquoise; return true; }
else if(color == "violet"){ col = Colors::Violet; return true; }
else if(color == "wheat"){ col = Colors::Wheat; return true; }
else if(color == "white"){ col = Colors::White; return true; }
else if(color == "whitesmoke"){ col = Colors::WhiteSmoke; return true; }
else if(color == "yellow"){ col = Colors::Yellow; return true; }
else if(color == "yellowgreen"){ col = Colors::YellowGreen; return true; }
}
else if(color.size() == 4)
{
for(size_t i = 1; i < 4; i++)
if((color[i] < 'a' || color[i] > 'f') && (color[i] < '0' || color[i] > '9')) return false;
uint8_t r = HttpUtils::HexToNibble(color[1]);
uint8_t g = HttpUtils::HexToNibble(color[2]);
uint8_t b = HttpUtils::HexToNibble(color[3]);
col.Red = r | r << 4;
col.Green = g | g << 4;
col.Blue = b | b << 4;
col.Alpha = 255;
return true;
}
else if(color.size() == 5)
{
for(size_t i = 1; i < 5; i++)
if((color[i] < 'a' || color[i] > 'f') && (color[i] < '0' || color[i] > '9')) return false;
uint8_t r = HttpUtils::HexToNibble(color[1]);
uint8_t g = HttpUtils::HexToNibble(color[2]);
uint8_t b = HttpUtils::HexToNibble(color[3]);
uint8_t a = HttpUtils::HexToNibble(color[4]);
col.Red = r | r << 4;
col.Green = g | g << 4;
col.Blue = b | b << 4;
col.Alpha = a | a << 4;
return true;
}
else if(color.size() == 7)
{
for(size_t i = 1; i < 7; i++)
if((color[i] < 'a' || color[i] > 'f') && (color[i] < '0' || color[i] > '9')) return false;
uint8_t r = (HttpUtils::HexToNibble(color[1]) << 4) | HttpUtils::HexToNibble(color[2]);
uint8_t g = (HttpUtils::HexToNibble(color[3]) << 4) | HttpUtils::HexToNibble(color[4]);
uint8_t b = (HttpUtils::HexToNibble(color[5]) << 4) | HttpUtils::HexToNibble(color[6]);
col.Red = r;
col.Green = g;
col.Blue = b;
col.Alpha = 255;
return true;
}
else if(color.size() == 9)
{
for(size_t i = 1; i < 9; i++)
if((color[i] < 'a' || color[i] > 'f') && (color[i] < '0' || color[i] > '9')) return false;
uint8_t r = (HttpUtils::HexToNibble(color[1]) << 4) | HttpUtils::HexToNibble(color[2]);
uint8_t g = (HttpUtils::HexToNibble(color[3]) << 4) | HttpUtils::HexToNibble(color[4]);
uint8_t b = (HttpUtils::HexToNibble(color[5]) << 4) | HttpUtils::HexToNibble(color[6]);
uint8_t a = (HttpUtils::HexToNibble(color[7]) << 4) | HttpUtils::HexToNibble(color[8]);
col.Red = r;
col.Green = g;
col.Blue = b;
col.Alpha = a;
return true;
return true;
}
return false;
}
Color Color::Parse(std::string color)
{
Color c;
if(Color::TryParse(color,c)) return c;
throw std::runtime_error("Could not parse color");
}
bool Color::operator!=(Color other)
{
return !(*this == other);
}
bool Color::operator==(Color other)
{
return Red == other.Red && Green == other.Green && Blue == other.Blue && Alpha == other.Alpha;
}
}

771
src/Font.cpp Normal file
View File

@@ -0,0 +1,771 @@
#include "TessesFrameworkGFX/Image.hpp"
namespace Tesses::Framework::Graphics {
static void C_P(Image* img, const Point& location, const Color& col);
static void C_F(Image* img, const Point& location, const Color& col);
static void C_T(Image* img, const Point& location, const Color& col);
static void C_1(Image* img, const Point& location, const Color& col);
static void C_S(Image* img, const Point& location, const Color& col);
static void C_ForwardSlash(Image* img, const Point& location, const Color& col);
static void C_BackSlash(Image* img, const Point& location, const Color& col);
static void C_A(Image* img, const Point& location, const Color& col)
{
int topLeftX = 7;
int topRightX = 8;
int middle = 7;
img->DrawLine(Point(location.X,location.Y+15),Point(topLeftX+location.X,location.Y), col, 1);
img->DrawLine(Point(location.X+15,location.Y+15),Point(topRightX+location.X,location.Y),col,1);
img->DrawLine(Point(location.X+4,location.Y+middle),Point(location.X+10,location.Y+middle),col);
}
static void C_B(Image* img, const Point& location, const Color& col)
{
C_P(img,location,col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+9),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+15,location.Y+12),Point(location.X+15,location.Y+10),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+13,location.Y+15),col);
}
static void C_C(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+15,location.Y+15),col);
}
static void C_D(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+12,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+12,location.Y),col);
img->DrawLine(Point(location.X+15,location.Y+3),Point(location.X+15,location.Y+11),col);
img->DrawLine(Point(location.X+12,location.Y),Point(location.X+15,location.Y+3),col);
img->DrawLine(Point(location.X+12,location.Y+15),Point(location.X+15,location.Y+12),col);
}
static void C_E(Image* img, const Point& location, const Color& col)
{
C_F(img,location,col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+15,location.Y+15),col);
}
static void C_F(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+11,location.Y+7),col);
}
static void C_G(Image* img, const Point& location, const Color& col)
{
C_C(img,location,col);
img->DrawLine(Point(location.X+15,location.Y+15),Point(location.X+15,location.Y+7),col);
img->DrawLine(Point(location.X+5,location.Y+7),Point(location.X+15,location.Y+7),col);
}
static void C_H(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+15,location.Y+7),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+15),col);
}
static void C_I(Image* img, const Point& location, const Color& col)
{
C_T(img,location,col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+15,location.Y+15),col);
}
static void C_J(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X+7,location.Y),Point(location.X+7,location.Y+13),col);
img->DrawLine(Point(location.X+7,location.Y+13),Point(location.X+5,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+13),Point(location.X+2,location.Y+15),col);
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X+5,location.Y+15),col);
}
static void C_K(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X,location.Y+8),Point(location.X+15,location.Y+15),col);
}
static void C_L(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+15,location.Y+15),col);
}
static void C_M(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+7,location.Y+7),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+8,location.Y+7),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+15),col);
}
static void C_N(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y+15),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+15),col);
}
static void C_O(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y),Point(location.X,location.Y+2),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
img->DrawLine(Point(location.X,location.Y+3),Point(location.X,location.Y+12),col);
img->DrawLine(Point(location.X+15,location.Y+3),Point(location.X+15,location.Y+12),col);
img->DrawLine(Point(location.X+3,location.Y),Point(location.X+12,location.Y),col);
img->DrawLine(Point(location.X+3,location.Y+15),Point(location.X+12,location.Y+15),col);
}
static void C_P(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+13,location.Y),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
img->DrawLine(Point(location.X+15,location.Y+3),Point(location.X+15,location.Y+4),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+13,location.Y+7),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+5),col);
}
static void C_Q(Image* img, const Point& location, const Color& col)
{
C_O(img,location,col);
img->DrawLine(Point(location.X+10,location.Y+10),Point(location.X+15,location.Y+15),col);
}
static void C_R(Image* img, const Point& location, const Color& col)
{
C_P(img,location,col);
img->DrawLine(Point(location.X,location.Y+8),Point(location.X+15,location.Y+15),col);
}
static void C_S(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y),Point(location.X,location.Y+2),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
img->DrawLine(Point(location.X,location.Y+3),Point(location.X,location.Y+5),col);
img->DrawLine(Point(location.X+15,location.Y+9),Point(location.X+15,location.Y+12),col);
img->DrawLine(Point(location.X+3,location.Y),Point(location.X+12,location.Y),col);
img->DrawLine(Point(location.X+3,location.Y+15),Point(location.X+12,location.Y+15),col);
img->SetPixel((uint32_t)(location.X+1),(uint32_t)(location.Y+6),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X+13,location.Y+7),col);
img->SetPixel((uint32_t)(location.X+14),(uint32_t)(location.Y+8),col);
}
static void C_T(Image* img, const Point& location, const Color& col)
{
C_1(img,location,col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
}
static void C_U(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X+13,location.Y+15),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X,location.Y+13),col);
}
static void C_V(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X+7,location.Y+15),col);
img->DrawLine(Point(location.X+8,location.Y+15),Point(location.X+15,location.Y),col);
}
static void C_W(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+7,location.Y+3),col);
img->DrawLine(Point(location.X+15,location.Y+15),Point(location.X+8,location.Y+3),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+15),col);
}
static void C_X(Image* img, const Point& location, const Color& col)
{
C_BackSlash(img,location,col);
C_ForwardSlash(img,location,col);
}
static void C_Y(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X+7,location.Y+7),col);
img->DrawLine(Point(location.X+14,location.Y),Point(location.X+7,location.Y+7),col);
img->DrawLine(Point(location.X+7,location.Y+8),Point(location.X+7,location.Y+15),col);
}
static void C_Z(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+15,location.Y+15),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X,location.Y+15),col);
}
static void C_0(Image* img, const Point& location, const Color& col)
{
C_O(img,location,col);
img->DrawRectangle(Rectangle(location.X+7,location.Y+7,2,2),col);
}
static void C_1(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+7,location.Y),Point(location.X+7,location.Y+15),col);
}
static void C_2(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+4,location.Y),Point(location.X+13,location.Y),col);
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X+15,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+13),Point(location.X+2,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+9),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X+13,location.Y+7),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X,location.Y+9),col);
img->DrawLine(Point(location.X+15,location.Y+2),Point(location.X+15,location.Y+5),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+5),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
}
static void C_3(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+4,location.Y),Point(location.X+13,location.Y),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+13,location.Y+15),col);
img->DrawLine(Point(location.X+15,location.Y+13),Point(location.X+13,location.Y+15),col);
img->DrawLine(Point(location.X+15,location.Y+9),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X+13,location.Y+7),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+9),col);
img->DrawLine(Point(location.X+15,location.Y+2),Point(location.X+15,location.Y+5),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+5),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
}
static void C_4(Image* img, const Point& location, const Color& col)
{
C_1(img,location,col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+12,location.Y+7),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+7,location.Y),col);
}
static void C_5(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+7),col);
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+15,location.Y+9),Point(location.X+15,location.Y+12),col);
img->DrawLine(Point(location.X+3,location.Y+15),Point(location.X+12,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+13,location.Y+7),col);
img->SetPixel((uint32_t)(location.X+14),(uint32_t)(location.Y+8),col);
}
static void C_6(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y+2),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X,location.Y+13),Point(location.X+2,location.Y+15),col);
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X+13,location.Y+15),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+13,location.Y+7),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+9),col);
img->DrawLine(Point(location.X+15,location.Y+9),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X,location.Y+2),Point(location.X+2,location.Y),col);
img->DrawLine(Point(location.X+2,location.Y),Point(location.X+11,location.Y),col);
}
static void C_7(Image* img, const Point& location, const Color& col)
{
C_ForwardSlash(img,location,col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y),col);
}
static void C_8(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y),Point(location.X,location.Y+2),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+5),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X,location.Y+5),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+15,location.Y+9),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X,location.Y+9),col);
img->DrawLine(Point(location.X,location.Y+3),Point(location.X,location.Y+4),col);
img->DrawLine(Point(location.X+15,location.Y+3),Point(location.X+15,location.Y+4),col);
img->DrawLine(Point(location.X,location.Y+10),Point(location.X,location.Y+12),col);
img->DrawLine(Point(location.X+15,location.Y+10),Point(location.X+15,location.Y+12),col);
img->DrawLine(Point(location.X+3,location.Y+7),Point(location.X+12,location.Y+7),col);
img->DrawLine(Point(location.X+3,location.Y),Point(location.X+12,location.Y),col);
img->DrawLine(Point(location.X+3,location.Y+15),Point(location.X+12,location.Y+15),col);
}
static void C_9(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+2,location.Y+15),Point(location.X,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y),Point(location.X,location.Y+2),col);
img->DrawLine(Point(location.X+13,location.Y+15),Point(location.X+15,location.Y+13),col);
img->DrawLine(Point(location.X+13,location.Y),Point(location.X+15,location.Y+2),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X,location.Y+5),col);
img->DrawLine(Point(location.X,location.Y+3),Point(location.X,location.Y+4),col);
img->DrawLine(Point(location.X+3,location.Y+7),Point(location.X+15,location.Y+7),col);
img->DrawLine(Point(location.X+3,location.Y),Point(location.X+12,location.Y),col);
img->DrawLine(Point(location.X+3,location.Y+15),Point(location.X+12,location.Y+15),col);
img->DrawLine(Point(location.X+15,location.Y+2),Point(location.X+15,location.Y+13),col);
}
static void C_ForwardSlash(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+15,location.Y),Point(location.X,location.Y+15),col);
}
static void C_BackSlash(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X+15,location.Y+15),col);
}
static void C_Period(Image* img, const Point& location, const Color& col)
{
img->DrawRectangle(Rectangle(location.X+7,location.Y+11,2,2),col);
}
static void C_EscPoint(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+7,location.Y+2),Point(location.X+7,location.Y+8),col);
img->DrawLine(Point(location.X+8,location.Y+2),Point(location.X+8,location.Y+8),col);
C_Period(img,location,col);
}
static void C_Colon(Image* img, const Point& location, const Color& col)
{
img->DrawRectangle(Rectangle(location.X+7,location.Y+3,2,2),col);
C_Period(img,location,col);
}
static void C_Comma(Image* img, const Point& location, const Color& col)
{
C_Period(img,location,col);
img->DrawLine(Point(location.X+7,location.Y+11),Point(location.X+5,location.Y+13),col);
img->DrawLine(Point(location.X+8,location.Y+11),Point(location.X+6,location.Y+13),col);
}
static void C_Semicolon(Image* img, const Point& location, const Color& col)
{
img->DrawRectangle(Rectangle(location.X+7,location.Y+3,2,2),col);
C_Comma(img,location,col);
}
static void C_Minus(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+15,location.Y+7),col);
}
static void C_Plus(Image* img, const Point& location, const Color& col)
{
C_Minus(img,location,col);
C_1(img,location,col);
}
static void C_Star(Image* img, const Point& location, const Color& col)
{
C_Minus(img,location,col);
img->DrawLine(Point(location.X+7,location.Y),Point(location.X+7,location.Y+7),col);
img->DrawLine(Point(location.X+7,location.Y+7),Point(location.X,location.Y+14),col);
img->DrawLine(Point(location.X+8,location.Y+7),Point(location.X+15,location.Y+14),col);
}
static void C_LT(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y+7),Point(location.X+15,location.Y),col);
img->DrawLine(Point(location.X,location.Y+8),Point(location.X+15,location.Y+15),col);
}
static void C_GT(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+15,location.Y+7),Point(location.X,location.Y),col);
img->DrawLine(Point(location.X+15,location.Y+8),Point(location.X,location.Y+15),col);
}
static void C_EQ(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y+6),Point(location.X+15,location.Y+6),col);
img->DrawLine(Point(location.X,location.Y+9),Point(location.X+15,location.Y+9),col);
}
static void C_Dollar(Image* img, const Point& location, const Color& col)
{
C_1(img,location,col);
C_S(img,location,col);
}
static void C_BitwiseOr(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+7,location.Y),Point(location.X+7,location.Y+7),col);
img->DrawLine(Point(location.X+7,location.Y+9),Point(location.X+7,location.Y+15),col);
}
static void C_PoundPhone(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+4,location.Y),Point(location.X+4,location.Y+14),col);
img->DrawLine(Point(location.X+9,location.Y),Point(location.X+9,location.Y+14),col);
img->DrawLine(Point(location.X,location.Y+4),Point(location.X+14,location.Y+4),col);
img->DrawLine(Point(location.X,location.Y+9),Point(location.X+14,location.Y+9),col);
}
static void C_LBracket(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y),Point(location.X,location.Y+15),col);
img->DrawLine(Point(location.X,location.Y),Point(location.X+7,location.Y),col);
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+7,location.Y+15),col);
}
static void C_RBracket(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+15),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+8,location.Y),col);
img->DrawLine(Point(location.X+15,location.Y+15),Point(location.X+8,location.Y+15),col);
}
static void C_Underscore(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X,location.Y+15),Point(location.X+15,location.Y+15),col);
}
static void C_MrHat(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+3,location.Y+4),Point(location.X+7,location.Y),col);
img->DrawLine(Point(location.X+12,location.Y+4),Point(location.X+8,location.Y),col);
}
static void C_Quot(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+5,location.Y),Point(location.X+5,location.Y+5),col);
}
static void C_DQuot(Image* img, const Point& location, const Color& col)
{
C_Quot(img,location,col);
img->DrawLine(Point(location.X+9,location.Y),Point(location.X+9,location.Y+5),col);
}
static void C_Apos(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+5,location.Y),Point(location.X+8,location.Y+3),col);
}
static void C_LParen(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+5,location.Y+2),Point(location.X+7,location.Y),col);
img->DrawLine(Point(location.X+4,location.Y+3),Point(location.X+4,location.Y+12),col);
img->DrawLine(Point(location.X+5,location.Y+13),Point(location.X+7,location.Y+15),col);
}
static void C_RParen(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+10,location.Y+2),Point(location.X+8,location.Y),col);
img->DrawLine(Point(location.X+11,location.Y+3),Point(location.X+11,location.Y+12),col);
img->DrawLine(Point(location.X+10,location.Y+13),Point(location.X+8,location.Y+15),col);
}
static void C_LBrace(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+5,location.Y+2),Point(location.X+7,location.Y),col);
img->DrawLine(Point(location.X+5,location.Y+13),Point(location.X+7,location.Y+15),col);
img->DrawLine(Point(location.X+4,location.Y+3),Point(location.X+4,location.Y+5),col);
img->DrawLine(Point(location.X+4,location.Y+10),Point(location.X+4,location.Y+12),col);
img->DrawLine(Point(location.X+2,location.Y+7),Point(location.X+4,location.Y+5),col);
img->DrawLine(Point(location.X+2,location.Y+8),Point(location.X+4,location.Y+10),col);
}
static void C_RBrace(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+10,location.Y+2),Point(location.X+8,location.Y),col);
img->DrawLine(Point(location.X+10,location.Y+13),Point(location.X+8,location.Y+15),col);
img->DrawLine(Point(location.X+11,location.Y+3),Point(location.X+11,location.Y+5),col);
img->DrawLine(Point(location.X+11,location.Y+10),Point(location.X+11,location.Y+12),col);
img->DrawLine(Point(location.X+13,location.Y+7),Point(location.X+11,location.Y+5),col);
img->DrawLine(Point(location.X+13,location.Y+8),Point(location.X+11,location.Y+10),col);
}
static void C_Percent(Image* img, const Point& location, const Color& col)
{
C_ForwardSlash(img,location,col);
img->DrawRectangle(Rectangle(location.X,location.Y,4,4),col);
img->DrawRectangle(Rectangle(location.X+12,location.Y+12,4,4),col);
}
static void C_Question(Image* img, const Point& location, const Color& col)
{
C_Period(img,location,col);
img->DrawLine(Point(location.X+1,location.Y+1),Point(location.X+13,location.Y+1),col);
img->DrawLine(location,Point(location.X+15,location.Y),col);
img->DrawLine(location,Point(location.X,location.Y+5),col);
img->DrawLine(Point(location.X+1,location.Y+1),Point(location.X+1,location.Y+5),col);
img->DrawLine(Point(location.X+14,location.Y+1),Point(location.X+14,location.Y+5),col);
img->DrawLine(Point(location.X+15,location.Y),Point(location.X+15,location.Y+5),col);
img->DrawLine(Point(location.X+15,location.Y+5),Point(location.X+7,location.Y+5),col);
img->DrawLine(Point(location.X+15,location.Y+5),Point(location.X+7,location.Y+5),col);
img->DrawLine(Point(location.X+15,location.Y+6),Point(location.X+7,location.Y+6),col);
img->DrawLine(Point(location.X+15,location.Y+6),Point(location.X+7,location.Y+6),col);
img->DrawLine(Point(location.X+7,location.Y+6),Point(location.X+7,location.Y+8),col);
img->DrawLine(Point(location.X+8,location.Y+6),Point(location.X+8,location.Y+8),col);
}
static void C_Tilda(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+1,location.Y+5),Point(location.X+7,location.Y+5),col);
img->DrawLine(Point(location.X,location.Y+6),Point(location.X+8,location.Y+6),col);
img->DrawLine(Point(location.X,location.Y+7),Point(location.X,location.Y+10),col);
img->DrawLine(Point(location.X+1,location.Y+7),Point(location.X+1,location.Y+10),col);
img->DrawLine(Point(location.X+7,location.Y+9),Point(location.X+15,location.Y+9),col);
img->DrawLine(Point(location.X+8,location.Y+10),Point(location.X+14,location.Y+10),col);
img->DrawRectangle(Rectangle(location.X+7,location.Y+7,2,2),col);
img->DrawLine(Point(location.X+14,location.Y+5),Point(location.X+14,location.Y+8),col);
img->DrawLine(Point(location.X+15,location.Y+5),Point(location.X+15,location.Y+8),col);
}
static void C_Amp(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+5,location.Y+2),Point(location.X+9,location.Y+2),col);
img->DrawLine(Point(location.X+4,location.Y+3),Point(location.X+4,location.Y+5),col);
img->DrawLine(Point(location.X+5,location.Y+6),Point(location.X+8,location.Y+13),col);
img->DrawLine(Point(location.X+2,location.Y+13),Point(location.X+11,location.Y+4),col);
img->DrawLine(Point(location.X+9,location.Y+2),Point(location.X+11,location.Y+4),col);
img->DrawLine(Point(location.X+2,location.Y+13),Point(location.X+4,location.Y+15),col);
img->DrawLine(Point(location.X+4,location.Y+15),Point(location.X+7,location.Y+15),col);
img->DrawLine(Point(location.X+7,location.Y+15),Point(location.X+11,location.Y+11),col);
img->DrawLine(Point(location.X+8,location.Y+13),Point(location.X+10,location.Y+15),col);
}
static void C_At(Image* img, const Point& location, const Color& col)
{
img->DrawLine(Point(location.X+1,location.Y+15),Point(location.X+15,location.Y+15),col);
img->DrawLine(Point(location.X+1,location.Y+1),Point(location.X+1,location.Y+15),col);
img->DrawLine(Point(location.X+1,location.Y+1),Point(location.X+14,location.Y+1),col);
img->DrawLine(Point(location.X+14,location.Y+1),Point(location.X+14,location.Y+13),col);
img->DrawLine(Point(location.X+3,location.Y+13),Point(location.X+14,location.Y+13),col);
img->DrawLine(Point(location.X+3,location.Y+3),Point(location.X+3,location.Y+13),col);
img->DrawLine(Point(location.X+3,location.Y+3),Point(location.X+12,location.Y+3),col);
img->DrawLine(Point(location.X+12,location.Y+3),Point(location.X+12,location.Y+11),col);
img->DrawLine(Point(location.X+12,location.Y+11),Point(location.X+10,location.Y+11),col);
img->DrawLine(Point(location.X+10,location.Y+5),Point(location.X+10,location.Y+11),col);
img->DrawLine(Point(location.X+6,location.Y+5),Point(location.X+10,location.Y+5),col);
img->DrawLine(Point(location.X+6,location.Y+10),Point(location.X+10,location.Y+10),col);
img->DrawLine(Point(location.X+5,location.Y+6),Point(location.X+5,location.Y+9),col);
}
void Image::DrawChar(char c, const Point& location, const Color& col)
{
if(c >= 'a' && c <= 'z') c = (c - 'a')+'A';
switch(c)
{
case 'A':
C_A(this,location,col);
break;
case 'B':
C_B(this,location,col);
break;
case 'C':
C_C(this,location,col);
break;
case 'D':
C_D(this,location,col);
break;
case 'E':
C_E(this,location,col);
break;
case 'F':
C_F(this,location,col);
break;
case 'G':
C_G(this,location,col);
break;
case 'H':
C_H(this,location,col);
break;
case 'I':
C_I(this,location,col);
break;
case 'J':
C_J(this,location,col);
break;
case 'K':
C_K(this,location,col);
break;
case 'L':
C_L(this,location,col);
break;
case 'M':
C_M(this,location,col);
break;
case 'N':
C_N(this,location,col);
break;
case 'O':
C_O(this,location,col);
break;
case 'P':
C_P(this,location,col);
break;
case 'Q':
C_Q(this,location,col);
break;
case 'R':
C_R(this,location,col);
break;
case 'S':
C_S(this,location,col);
break;
case 'T':
C_T(this,location,col);
break;
case 'U':
C_U(this,location,col);
break;
case 'V':
C_V(this,location,col);
break;
case 'W':
C_W(this,location,col);
break;
case 'X':
C_X(this,location,col);
break;
case 'Y':
C_Y(this,location,col);
break;
case 'Z':
C_Z(this,location,col);
break;
case '0':
C_0(this,location,col);
break;
case '1':
C_1(this,location,col);
break;
case '2':
C_2(this,location,col);
break;
case '3':
C_3(this,location,col);
break;
case '4':
C_4(this,location,col);
break;
case '5':
C_5(this,location,col);
break;
case '6':
C_6(this,location,col);
break;
case '7':
C_7(this,location,col);
break;
case '8':
C_8(this,location,col);
break;
case '9':
C_9(this,location,col);
break;
case '/':
C_ForwardSlash(this,location,col);
break;
case '\\':
C_BackSlash(this,location,col);
break;
case ':':
C_Colon(this,location,col);
break;
case ';':
C_Semicolon(this,location,col);
break;
case '.':
C_Period(this,location,col);
break;
case ',':
C_Comma(this,location,col);
break;
case '-':
C_Minus(this,location,col);
break;
case '+':
C_Plus(this,location,col);
break;
case '*':
C_Star(this,location,col);
break;
case '<':
C_LT(this,location,col);
break;
case '>':
C_GT(this,location,col);
break;
case '=':
C_EQ(this,location,col);
break;
case '!':
C_EscPoint(this,location,col);
break;
case '$':
C_Dollar(this,location,col);
break;
case '|':
C_BitwiseOr(this, location,col);
break;
case '#':
C_PoundPhone(this, location, col);
break;
case '[':
C_LBracket(this,location,col);
break;
case ']':
C_RBracket(this,location,col);
break;
case '_':
C_Underscore(this,location,col);
break;
case '^':
C_MrHat(this,location,col);
break;
case '\'':
C_Quot(this,location,col);
break;
case '"':
C_DQuot(this,location,col);
break;
case '`':
C_Apos(this,location,col);
break;
case '(':
C_LParen(this,location,col);
break;
case ')':
C_RParen(this,location,col);
break;
case '{':
C_LBrace(this,location,col);
break;
case '}':
C_RBrace(this,location,col);
break;
case '%':
C_Percent(this,location,col);
break;
case '?':
C_Question(this,location,col);
break;
case '~':
C_Tilda(this,location,col);
break;
case '&':
C_Amp(this,location,col);
break;
case '@':
C_At(this,location,col);
break;
}
}
}

212
src/Image.cpp Normal file
View File

@@ -0,0 +1,212 @@
#include "TessesFrameworkGFX/Image.hpp"
namespace Tesses::Framework::Graphics {
Image::Image()
{
}
Image::Image(uint32_t w, uint32_t h)
{
this->w = w;
this->h = h;
SetSize(w,h);
}
Image::Image(uint32_t w,uint32_t h,std::vector<Color> data)
{
this->w = w;
this->h = h;
this->data = data;
if(this->data.size() != w * h) throw std::runtime_error("data size does not match the factor of width and height");
}
uint32_t Image::Width()
{
return this->w;
}
uint32_t Image::Height()
{
return this->h;
}
void Image::SetSize(uint32_t w, uint32_t h)
{
this->w = w;
this->h = h;
this->data.resize(w * h);
}
void Image::SetSize(uint32_t w, uint32_t h, Color c)
{
this->w = w;
this->h = h;
this->data.resize(w * h);
for(size_t i = 0; i < this->data.size(); i++) this->data[i] = c;
}
void Image::SetPixel(uint32_t x, uint32_t y, Color c)
{
this->data[y*w+x] = c;
}
Color Image::GetPixel(uint32_t x, uint32_t y)
{
return this->data[y*w+x];
}
std::vector<Color>& Image::Data()
{
return this->data;
}
void Image::DrawRectangle(const Rectangle& rect, const Color& col, int borderSize)
{
int x = rect.Location.X;
int y = rect.Location.Y;
int w = rect.Size.Width;
int h = rect.Size.Height;
auto& data = this->Data();
for(int b = 0; b < borderSize; b++)
{
this->DrawLine(Point(x,y),Point(x+w-1,y),col);
this->DrawLine(Point(x,y),Point(x,y+h-1),col);
this->DrawLine(Point(x,y+h-1),Point(x+w-1,y+h-1),col);
this->DrawLine(Point(x+w-1,y),Point(x+w-1,y+h-1),col);
x++;
y++;
w-=2;
h-=2;
}
}
void Image::FillRectangle(const Rectangle& rect, const Color& col)
{
auto imgW = this->Width();
auto imgH = this->Height();
int x = rect.Location.X;
int y = rect.Location.Y;
int w = rect.Size.Width;
int h = rect.Size.Height;
int left = x;
int top = y;
int right = x+w-1;
int bottom = y+h-1;
if(left > right)
{
left = left ^ right;
right = left ^ right;
left = left ^ right;
}
if(top > bottom)
{
top = top ^ bottom;
bottom = top ^ bottom;
top = top ^ bottom;
}
if(left < 0) left = 0;
if(left >= imgW) return;
if(right <= 0) return;
if(right >= imgW) right = imgW-1;
if(top < 0) top = 0;
if(top >= imgH) return;
if(bottom <= 0) return;
if(bottom >= imgH) bottom = imgH-1;
auto& data = this->Data();
for(int y=top ; y <= bottom; y++)
{
for(int x=left; x <= right; x++)
{
data[y*imgW+x] =col;
}
}
}
void Image::PlotLineLow(const Color& col,int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
int32_t dx = x2 - x1;
int32_t dy = y2 - y1;
int32_t yi = 1;
if(dy < 0){
yi = -1;
dy = -dy;
}
int32_t d = (2 * dy) - dx;
int32_t y = y1;
for(int32_t x = x1; x <= x2; x++)
{
this->SetPixel((uint32_t)x,(uint32_t)y, col);
if(d > 0)
{
y += yi;
d += (2* (dy - dx));
}
else
{
d = d + 2*dy;
}
}
}
void Image::PlotLineHigh(const Color& col, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
int32_t dx = x2 - x1;
int32_t dy = y2 - y1;
int32_t xi = 1;
if(dx < 0){
xi = -1;
dx = -dx;
}
int32_t d = (2 * dx) - dy;
int32_t x = x1;
for(int32_t y = y1; y <= y2; y++)
{
this->SetPixel((uint32_t)x,(uint32_t)y, col);
if(d > 0)
{
x += xi;
d += (2* (dx - dy));
}
else
{
d = d + 2*dx;
}
}
}
void Image::DrawLine(const Point& pt1, const Point& pt2, const Color& col, int borderSize)
{
for(int i = 0; i < borderSize; i++)
if(abs(pt2.Y - pt1.Y) < abs(pt2.X - pt1.X))
{
if(pt1.X > pt2.X)
PlotLineLow(col,pt2.X,pt2.Y+i,pt1.X,pt1.Y+i);
else
PlotLineLow(col,pt1.X,pt1.Y+i,pt2.X,pt2.Y+i);
}
else
{
if(pt1.Y > pt2.Y)
PlotLineHigh(col,pt2.X+i,pt2.Y,pt1.X+i,pt1.Y);
else
PlotLineHigh(col,pt1.X+i,pt1.Y,pt2.X+i,pt2.Y);
}
}
void Image::DrawString(std::string text, const Point& pt, const Color& color)
{
for(size_t i =0; i < text.size(); i++)
{
DrawChar(text[i], Point(pt.X+((int)i*18)+1,pt.Y),color);
}
}
}

96
src/ImageCopy.cpp Normal file
View File

@@ -0,0 +1,96 @@
#include "TessesFrameworkGFX/Image.hpp"
namespace Tesses::Framework::Graphics
{
void Image::DrawImage(Image* src, const Point& pt, ImageCopyEffect copyEffect)
{
switch(copyEffect)
{
case ImageCopyEffect::Overwrite:
{
uint32_t w = std::min<uint32_t>(src->w,std::min<uint32_t>(this->w,(uint32_t)(this->w-pt.X)));
uint32_t h = std::min<uint32_t>(src->h,std::min<uint32_t>(this->h,(uint32_t)(this->h-pt.Y)));
for(uint32_t y = 0; y < h; y++)
{
for(uint32_t x = 0; x < w; x++)
{
this->SetPixel(x+(uint32_t)pt.X,y+(uint32_t)pt.Y,src->GetPixel(x,y));
}
}
}
case ImageCopyEffect::Invert:
{
uint32_t w = std::min<uint32_t>(src->w,std::min<uint32_t>(this->w,(uint32_t)(this->w-pt.X)));
uint32_t h = std::min<uint32_t>(src->h,std::min<uint32_t>(this->h,(uint32_t)(this->h-pt.Y)));
for(uint32_t y = 0; y < h; y++)
{
for(uint32_t x = 0; x < w; x++)
{
auto destc = this->GetPixel(x+(uint32_t)pt.X,y+(uint32_t)pt.Y);
auto oldc = src->GetPixel(x,y);
destc.Red = 255 - oldc.Red;
destc.Green = 255 - oldc.Green;
destc.Blue = 255 - oldc.Blue;
destc.Alpha = oldc.Alpha;
this->SetPixel(x+(uint32_t)pt.X,y+(uint32_t)pt.Y,destc);
}
}
}
break;
case ImageCopyEffect::InvertIfNotTransparent:
{
uint32_t w = std::min<uint32_t>(src->w,std::min<uint32_t>(this->w,(uint32_t)(this->w-pt.X)));
uint32_t h = std::min<uint32_t>(src->h,std::min<uint32_t>(this->h,(uint32_t)(this->h-pt.Y)));
for(uint32_t y = 0; y < h; y++)
{
for(uint32_t x = 0; x < w; x++)
{
auto destc = this->GetPixel(x+(uint32_t)pt.X,y+(uint32_t)pt.Y);
auto oldc = src->GetPixel(x,y);
if(oldc.Alpha > 127)
{
destc.Red = 255 - destc.Red;
destc.Green = 255 - destc.Green;
destc.Blue = 255 - destc.Blue;
}
this->SetPixel(x+(uint32_t)pt.X,y+(uint32_t)pt.Y,destc);
}
}
}
break;
}
}
void Image::Resize(Image* dest, const Size& sz, ScaleAlgorithm algo)
{
dest->SetSize((uint64_t)sz.Width,(uint64_t)sz.Height);
switch(algo)
{
case ScaleAlgorithm::None:
{
uint32_t w = std::min<uint32_t>(dest->w,this->w);
uint32_t h = std::min<uint32_t>(dest->h,this->h);
for(uint32_t y = 0; y < h; y++)
{
for(uint32_t x = 0; x < w; x++)
{
dest->SetPixel(x,y,this->GetPixel(x,y));
}
}
}
break;
case ScaleAlgorithm::NearestNeighbor:
{
for(uint32_t y= 0; y < dest->h ; y++)
{
for(uint32_t x=0 ;x < dest->w ; x++)
{
dest->SetPixel(x,y,this->GetPixel((uint32_t)((float)x/(float)dest->w*(float)this->w),(uint32_t)((float)y/(float)dest->h*(float)this->h )));
}
}
}
break;
}
}
}

View File

@@ -0,0 +1,201 @@
#include "TessesFrameworkGFX/ImageFormats/BitmapFormat.hpp"
#include <TessesFramework/Streams/ByteWriter.hpp>
#include <TessesFramework/Streams/MemoryStream.hpp>
#include <iostream>
namespace Tesses::Framework::Graphics::ImageFormats {
BitmapFormat::BitmapFormat()
{
}
void BitmapFormat::Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image)
{
uint8_t header[14];
if(strm->ReadBlock(header,14) < 14) throw std::runtime_error("Invalid bmp file, header to small.");
if(header[0] != 0x42 || header[1] != 0x4D) throw std::runtime_error("Invalid bmp file, does not start with BM.");
uint8_t info_header[40];
if(strm->ReadBlock(info_header,40) < 40) throw std::runtime_error("Invalid bmp file, info header is too small.");
if(info_header[0] != 40 || info_header[1] != 0 || info_header[2] != 0 || info_header[3] != 0) throw std::runtime_error("Invald bmp file, info header size is corrupt.");
uint32_t width = 0;
width |= (uint32_t)info_header[4];
width |= (uint32_t)info_header[5] << 8;
width |= (uint32_t)info_header[6] << 16;
width |= (uint32_t)info_header[7] << 24;
uint32_t height = 0;
height |= (uint32_t)info_header[8];
height |= (uint32_t)info_header[9] << 8;
height |= (uint32_t)info_header[10] << 16;
height |= (uint32_t)info_header[11] << 24;
int32_t h0= *(int32_t*)&height;
bool isInverted=h0 < 0;
if(isInverted) height = (uint32_t)(-h0);
image->SetSize(width,height);
uint16_t planes = 0;
planes |= (uint16_t)info_header[12];
planes |= (uint16_t)info_header[13] << 8;
if(planes != 1) throw std::runtime_error("Planes is not 1");
uint16_t bpp = 0;
bpp |= (uint16_t)info_header[14];
bpp |= (uint16_t)info_header[15] << 8;
uint32_t compression = 0;
compression |= (uint32_t)info_header[16];
compression |= (uint32_t)info_header[17] << 8;
compression |= (uint32_t)info_header[18] << 16;
compression |= (uint32_t)info_header[19] << 24;
if(compression != 0) throw std::runtime_error("This bmp decoder does not support compression");
uint32_t imageSize = 0;
imageSize |= (uint32_t)info_header[20];
imageSize |= (uint32_t)info_header[21] << 8;
imageSize |= (uint32_t)info_header[22] << 16;
imageSize |= (uint32_t)info_header[23] << 24;
uint32_t colorsUsed = 0;
colorsUsed |= (uint32_t)info_header[32];
colorsUsed |= (uint32_t)info_header[33] << 8;
colorsUsed |= (uint32_t)info_header[34] << 16;
colorsUsed |= (uint32_t)info_header[35] << 24;
std::vector<Color> col={};
if(colorsUsed > 0)
{
col.resize(colorsUsed);
uint8_t* buff = new uint8_t[colorsUsed*4];
if(strm->ReadBlock(buff,colorsUsed*4) != colorsUsed*4) { delete buff; throw std::runtime_error("Could not read colors");}
for(size_t i = 0; i < colorsUsed; i++)
{
col[i].Red = buff[i * 4 + 2];
col[i].Green = buff[i * 4 + 1];
col[i].Blue = buff[i * 4];
col[i].Alpha = 255;
}
delete buff;
}
std::vector<Color>& pixel_out = image->Data();
if(bpp == 24)
{
uint32_t stride = 3 * width;
uint32_t m = stride % 4;
if(m != 0) stride += 4 - (m % 4);
uint8_t* buffer = new uint8_t[stride];
for(uint32_t y = 0; y < height; y++)
{
uint32_t yOut = isInverted ? y : ((height - y)-1);
if(strm->ReadBlock(buffer,stride) != stride)
{
delete buffer;
throw std::runtime_error("Bmp image data is truncated");
}
for(uint32_t x = 0; x < width; x++)
{
pixel_out[yOut * width + x].Red = buffer[x*3+2];
pixel_out[yOut * width + x].Green = buffer[x*3+1];
pixel_out[yOut * width + x].Blue = buffer[x*3];
pixel_out[yOut * width + x].Alpha=255;
}
}
delete buffer;
}
else if(bpp == 16)
{
uint32_t stride = 2 * width;
uint32_t m = stride % 4;
if(m != 0) stride += 4 - (m % 4);
uint8_t* buffer = new uint8_t[stride];
for(uint32_t y = 0; y < height; y++)
{
uint32_t yOut =isInverted ? y : ((height - y)-1);
if(strm->ReadBlock(buffer,stride) != stride)
{
delete buffer;
throw std::runtime_error("Bmp image data is truncated");
}
for(uint32_t x = 0; x < width; x++)
{
uint16_t px = (uint16_t)(buffer[x*2+1] << 8) | (uint16_t)buffer[x*2];
uint16_t red = (px & 0xF800) >> 11;
uint16_t green = (px & 0x07E0) >> 5;
uint16_t blue = (px & 0x001F);
red = (red * 255 + 15) / 31;
green = (green * 255 + 31) / 63;
blue = (blue * 255 + 15) / 31;
pixel_out[yOut * width + x].Red = red;
pixel_out[yOut * width + x].Green = green;
pixel_out[yOut * width + x].Blue = blue;
pixel_out[yOut * width + x].Alpha=255;
}
}
delete buffer;
}
else if(bpp == 8)
{
uint32_t stride = width;
uint8_t* buffer = new uint8_t[stride];
for(uint32_t y = 0; y < height; y++)
{
uint32_t yOut =isInverted ? y : ((height - y)-1);
if(strm->ReadBlock(buffer,stride) != stride)
{
delete buffer;
throw std::runtime_error("Bmp image data is truncated");
}
for(uint32_t x = 0; x < width; x++)
{
pixel_out[yOut * width + x] = col.at (buffer[x]);
}
}
delete buffer;
}
else throw std::runtime_error("Bitdepth " + std::to_string(bpp) + "bpp is not supported yet.");
}
void BitmapFormat::Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags)
{
auto memStrm=std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
Tesses::Framework::Streams::ByteWriter writer(memStrm);
uint32_t stride = image->Width() * 3;
uint32_t m = stride % 4;
if(m != 0) stride += 4 - (m % 4);
uint32_t sz = (stride * image->Height())+14+40;
memStrm->WriteBlock((const uint8_t*)"BM",2);
writer.WriteU32LE(sz);
writer.WriteU32LE(0);
writer.WriteU32LE(14+40);
writer.WriteU32LE(40);
writer.WriteU32LE(image->Width());
writer.WriteU32LE(image->Height());
writer.WriteU16LE(1);
writer.WriteU16LE(24);
writer.WriteU32LE(0);
writer.WriteU32LE(0);
writer.WriteU32LE(0);
writer.WriteU32LE(0);
writer.WriteU32LE(0);
writer.WriteU32LE(0);
memStrm->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
memStrm->CopyTo(strm);
uint8_t* buffer = new uint8_t[stride];
memset(buffer,0,stride);
auto width = image->Width();
auto height = image->Height();
for(uint32_t y = 0; y < height; y++)
{
uint32_t yOut = (height - y)-1;
for(uint32_t x = 0; x < width; x++)
{
auto c = image->GetPixel(x,yOut);
buffer[x*3+2] = c.Red;
buffer[x*3+1] = c.Green;
buffer[x*3] = c.Blue;
}
strm->WriteBlock(buffer,stride);
}
}
}

View File

@@ -0,0 +1,20 @@
#include "TessesFrameworkGFX/ImageFormats/Formats.hpp"
namespace Tesses::Framework::Graphics::ImageFormats {
PngFormat Formats::Png;
BitmapFormat Formats::Bitmap;
JpegFormat Formats::Jpeg;
ImageFormat* Formats::FromExtension(std::string ext)
{
if(ext == ".jpg" || ext == ".jpeg") return &Jpeg;
if(ext==".png") return &Png;
if(ext==".bmp") return &Bitmap;
return nullptr;
}
ImageFormat::~ImageFormat()
{
}
}

View File

@@ -0,0 +1,24 @@
#include "stb/stb_image_wrapper.hpp"
namespace Tesses::Framework::Graphics::ImageFormats
{
JpegFormat::JpegFormat()
{
}
static void _write(void* ctx, void* buffer, int len)
{
static_cast<Tesses::Framework::Streams::Stream*>(ctx)->WriteBlock((const uint8_t*)buffer,(size_t)len);
}
void JpegFormat::Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image)
{
LoadStb(strm,image);
}
void JpegFormat::Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags)
{
auto ptr=ToStbPointer(image,false);
stbi_write_jpg_to_func(_write,static_cast<void*>(strm.get()),(int)image->Width(),(int)image->Height(),3,ptr, 100);
delete[] ptr;
}
}

View File

@@ -0,0 +1,24 @@
#include "stb/stb_image_wrapper.hpp"
namespace Tesses::Framework::Graphics::ImageFormats
{
PngFormat::PngFormat()
{
}
static void _write(void* ctx, void* buffer, int len)
{
static_cast<Tesses::Framework::Streams::Stream*>(ctx)->WriteBlock((const uint8_t*)buffer,(size_t)len);
}
void PngFormat::Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image)
{
LoadStb(strm,image);
}
void PngFormat::Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image,std::string flags)
{
auto ptr=ToStbPointer(image,true);
stbi_write_png_to_func(_write,static_cast<void*>(strm.get()),(int)image->Width(),(int)image->Height(),4,ptr,4*(int)image->Width());
delete[] ptr;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,122 @@
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_wrapper.hpp"
namespace Tesses::Framework::Graphics::ImageFormats
{
static int _eof(void* user)
{
auto strm = static_cast<Tesses::Framework::Streams::Stream*>(user);
return strm->EndOfStream() ? 1 : 0;
}
static int _read(void* user, char* data, int sz)
{
auto strm = static_cast<Tesses::Framework::Streams::Stream*>(user);
return (int)strm->ReadBlock((uint8_t*)data, (size_t)sz);
}
static void _skip(void* user, int n)
{
auto strm = static_cast<Tesses::Framework::Streams::Stream*>(user);
strm->Seek((int64_t)n,Tesses::Framework::Streams::SeekOrigin::Current);
}
void LoadStb(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image)
{
stbi_io_callbacks cb={.read=_read,.skip=_skip,.eof=_eof};
int w;
int h;
int channels;
auto bytes = stbi_load_from_callbacks(&cb,static_cast<void*>(strm.get()),&w,&h,&channels,0);
if(bytes == nullptr) throw std::runtime_error("Could not open image");
image->SetSize((uint32_t)w,(uint32_t)h);
auto& data = image->Data();
switch(channels)
{
case 1:
for(int y = 0; y < h; y++)
{
for(int x = 0; x < w; x++)
{
uint32_t pxOff = (y*w+x);
data[pxOff].Red = bytes[pxOff];
data[pxOff].Green = bytes[pxOff];
data[pxOff].Blue = bytes[pxOff];
data[pxOff].Alpha = 255;
}
}
break;
case 3:
for(int y = 0; y < h; y++)
{
for(int x = 0; x < w; x++)
{
uint32_t pxOff = (y*w+x);
data[pxOff].Red = bytes[pxOff*3];
data[pxOff].Green = bytes[pxOff*3+1];
data[pxOff].Blue = bytes[pxOff*3+2];
data[pxOff].Alpha = 255;
}
}
break;
case 4:
for(int y = 0; y < h; y++)
{
for(int x = 0; x < w; x++)
{
uint32_t pxOff = (y*w+x);
data[pxOff].Red = bytes[pxOff*4];
data[pxOff].Green = bytes[pxOff*4+1];
data[pxOff].Blue = bytes[pxOff*4+2];
data[pxOff].Alpha = bytes[pxOff*4+3];
}
}
break;
}
free(bytes);
}
uint8_t* ToStbPointer(Image* image, bool perserveAlpha)
{
if(perserveAlpha)
{
uint8_t* mem = new uint8_t[image->Width() * image->Height()*4];
uint32_t w = image->Width();
uint32_t h = image->Height();
auto& oldBuff = image->Data();
for(uint32_t y = 0; y < h; y++)
{
for(uint32_t x = 0; x < w; x++)
{
auto off = y*w+x;
mem[off*4] = oldBuff[off].Red;
mem[off*4+1] = oldBuff[off].Green;
mem[off*4+2] = oldBuff[off].Blue;
mem[off*4+3] = oldBuff[off].Alpha;
}
}
return mem;
}
else
{
uint8_t* mem = new uint8_t[image->Width() * image->Height()*4];
uint32_t w = image->Width();
uint32_t h = image->Height();
auto& oldBuff = image->Data();
for(uint32_t y = 0; y < h; y++)
{
for(uint32_t x = 0; x < w; x++)
{
auto off = y*w+x;
mem[off*3] = oldBuff[off].Red;
mem[off*3+1] = oldBuff[off].Green;
mem[off*3+2] = oldBuff[off].Blue;
}
}
return mem;
}
}
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "stb_image.h"
#include "stb_image_write.h"
#include "TessesFrameworkGFX/ImageFormats/Formats.hpp"
namespace Tesses::Framework::Graphics::ImageFormats
{
void LoadStb(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, Image* image);
//free with delete[]
uint8_t* ToStbPointer(Image* image, bool perserveAlpha);
}

File diff suppressed because it is too large Load Diff

125
src/Webcam.cpp Normal file
View File

@@ -0,0 +1,125 @@
#include "TessesFrameworkGFX/Webcam.hpp"
#include "TessesFrameworkGFX/ImageFormats/Formats.hpp"
#include <webcam.h>
namespace Tesses::Framework::Graphics {
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
class WebcamDevice : public HiddenFieldData
{
public:
webcam::device dev;
WebcamDevice(uint8_t num, webcam::video_settings& settings) : dev(num,settings)
{
}
};
#endif
Device::Device(uint8_t device, const Size& sz, uint8_t fps)
{
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
webcam::video_settings set2;
set2.set_fps(fps);
set2.set_format(webcam::format_MJPEG());
set2.set_quality(100);
set2.set_resolution(webcam::resolution((short)sz.Width,(short)sz.Height));
this->field = std::make_shared<WebcamDevice>(device, set2);
#endif
}
void Device::Open()
{
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
auto dev = std::dynamic_pointer_cast<WebcamDevice>(this->field);
if(dev != nullptr) dev->dev.open();
#endif
}
std::shared_ptr<Image> Device::ReadFrame()
{
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
auto dev = std::dynamic_pointer_cast<WebcamDevice>(this->field);
if(dev != nullptr)
{
std::shared_ptr<Image> image=nullptr;
auto frame = dev->dev.read();
if(frame != nullptr)
{
image = std::make_shared<Image>();
auto strm = std::make_shared<Tesses::Framework::Streams::MemoryStream>(true);
strm->WriteBlock((const uint8_t*)frame->get_data(),(size_t)frame->get_data_lenght());
strm->Seek(0,Tesses::Framework::Streams::SeekOrigin::Begin);
ImageFormats::Formats::Jpeg.Load(strm,image.get());
}
delete frame;
return image;
}
#endif
return nullptr;
}
void Device::Close()
{
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
auto dev = std::dynamic_pointer_cast<WebcamDevice>(this->field);
if(dev != nullptr) dev->dev.close();
#endif
}
Device::~Device()
{
}
bool Device::IsEnabled()
{
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
return true;
#endif
return false;
}
std::vector<DeviceInfo> Device::GetDevices()
{
std::vector<DeviceInfo> info;
GetDevices(info);
return info;
}
void Device::GetDevices(std::vector<DeviceInfo>& devices)
{
#if defined(TESSESFRAMEWORKGFX_ENABLE_WEBCAM)
const webcam::device_info_enumeration & enumeration = webcam::enumerator::enumerate();
const size_t count = enumeration.count();
for (size_t device_index = 0; device_index < count; device_index++)
{
const webcam::device_info & device_info = enumeration.get(device_index);
const webcam::model_info & model_info = device_info.get_model_info();
DeviceInfo info;
info.Device = (uint8_t)(device_index+1);
info.Name = model_info.get_name();
//print image details
const webcam::video_info_enumeration & video_info_enumeration = device_info.get_video_info_enumeration();
size_t video_count = video_info_enumeration.count();
for (size_t video_index = 0; video_index < video_count; video_index++){
const webcam::video_info & video_info = video_info_enumeration.get(video_index);
auto& fmt = video_info.get_format();
if(fmt == webcam::format_MJPEG() || fmt == webcam::format_JPEG())
{
auto& sz = video_info.get_resolution();
info.Resolutions.push_back(Size(sz.get_width(),sz.get_height()));
}
}
devices.push_back(info);
}
#endif
}
}