This commit is contained in:
yukun 2019-12-18 13:46:36 +01:00
parent 680ed3a1ad
commit 4cb4fcd562
5 changed files with 1 additions and 261 deletions

View File

@ -26,7 +26,7 @@ include_directories(lib/toml)
set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library")
include_directories(${LIB_PATH}/include) include_directories(${LIB_PATH}/include)
add_executable(Terminal ${SOURCES} ${HEADERS} main/main.cpp src/Terminal.h src/Terminal.cpp src/Bitmap.cpp src/Bitmap.h src/Font.cpp src/Font.h) add_executable(Terminal ${SOURCES} ${HEADERS} main/main.cpp src/Terminal.h src/Terminal.cpp)
target_link_libraries(Terminal ${LIB_PATH}/lib/liblibrary.a) target_link_libraries(Terminal ${LIB_PATH}/lib/liblibrary.a)

View File

@ -1,63 +0,0 @@
#include "Bitmap.h"
#include <fstream>
#include <iostream>
Bitmap::Bitmap() {
offset = 0;
width = 0;
height = 0;
bpp = 0;
}
Bitmap::Bitmap(const std::string &file) {
offset = 0;
width = 0;
height = 0;
bpp = 0;
load(file);
}
void Bitmap::load(const std::string &file) {
std::ifstream stream;
stream.open(file);
if(stream.is_open()){
std::string str((std::istreambuf_iterator<char>(stream)),std::istreambuf_iterator<char>());
data.resize(str.size());
for(int i = 0; i < str.size();i++){
data[i] = str[i];
}
offset = (int)*(unsigned int*)(&data[10]);
width = (int)*(unsigned int*)(&data[18]);
height = (int)*(unsigned int*)(&data[22]);
bpp = (int)*(unsigned short*)(&data[28]);
}
}
int Bitmap::getWidth() {
return width;
}
int Bitmap::getHeight() {
return height;
}
char *Bitmap::getData() {
return &data[offset];
}
int Bitmap::getBitsPerPixel() {
return bpp;
}
unsigned int Bitmap::getPixel(int x, int y) {
unsigned int pixel = 0;
char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8);
for(int i = 0; i < getBitsPerPixel() / 8;i++){
*((char*)&pixel+i) = ptr[i];
}
if(pixel != 0){
return pixel;
}
return pixel;
}

View File

@ -1,67 +0,0 @@
#ifndef TERMINAL_BITMAP_H
#define TERMINAL_BITMAP_H
#include <string>
#include <vector>
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @brief: Used to load a Bitmap from a file.
*/
class Bitmap {
public:
Bitmap();
explicit Bitmap(const std::string &file);
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @brief: Used to load a Bitmap from a file.
*/
void load(const std::string &file);
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @return: the width of the image.
*/
int getWidth();
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @return: the height of the image
*/
int getHeight();
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @return: the pixel data as an byte array
*/
char *getData();
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @return: the number of bits uses per pixel
*/
int getBitsPerPixel();
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @return: the pixel value by coordinates, (0,0) is on the top left
*/
unsigned int getPixel(int x, int y);
private:
int width;
int height;
int offset;
int bpp;
std::vector<char> data;
};
#endif //TERMINAL_BITMAP_H

View File

@ -1,79 +0,0 @@
#include "Font.h"
#include <cpptoml.h>
Font::Font() {
xOffset = 0;
yOffset = 0;
xSize = 0;
ySize = 0;
xCount = 0;
yCount = 0;
xStart = 0;
yStart = 0;
fillValue = 0;
firstChar = ' ';
}
Font::Font(const std::string &file, const std::string &configFile) : Font() {
load(file, configFile);
}
void Font::load(const std::string &file, const std::string &configFile) {
bitmap.load(file);
auto config = cpptoml::parse_file(configFile);
xOffset = config->get_as<int>("xOffset").value_or(0);
yOffset = config->get_as<int>("yOffset").value_or(0);
xSize = config->get_as<int>("xSize").value_or(0);
ySize = config->get_as<int>("ySize").value_or(0);
xCount = config->get_as<int>("xCount").value_or(0);
yCount = config->get_as<int>("yOffset").value_or(0);
xStart = config->get_as<int>("xStart").value_or(0);
yStart = config->get_as<int>("yStart").value_or(0);
fillValue = config->get_as<unsigned int>("fillValue").value_or(0);
firstChar = (char)config->get_as<int>("firstChar").value_or(0);
pixelSize = config->get_as<int>("pixelSize").value_or(0);
gap = config->get_as<int>("gap").value_or(-1);
invertedColors = config->get_as<int>("invertedColors").value_or(0);
}
int Font::width() {
return xSize;
}
int Font::height() {
return ySize;
}
bool Font::getPixel(char character, int x, int y) {
//index of character(x and y)
int index = (character - firstChar);
if(gap != -1){
if (index >= gap){
index++;
}
}
int xIndex = index % xCount;
int yIndex = index / xCount;
if(index < 0){
yIndex--;
xIndex += xCount;
}
//character index to pixel index conversion
int xPos = xIndex * (xSize + xOffset) + xStart;
int yPos = yIndex * (ySize + yOffset) + yStart;
bool value = bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue;
if(invertedColors){
return !value;
}else{
return value;
}
}

View File

@ -1,51 +0,0 @@
//
// Created by yukun on 05.12.19.
//
#ifndef TERMINAL_FONT_H
#define TERMINAL_FONT_H
#include "Bitmap.h"
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @brief: this class provides pixel access based on characters
*/
class Font {
public:
Bitmap bitmap;
//space between characters
int xOffset;
int yOffset;
//size of a character
int xSize;
int ySize;
//count of characters per row
int xCount;
//count of rows
int yCount;
//pixel offset of first character
int xStart;
int yStart;
unsigned int fillValue;
char firstChar;
int pixelSize;
int gap;
bool invertedColors;
Font();
explicit Font(const std::string &file, const std::string &configFile);
void load(const std::string &file, const std::string &configFile);
int width();
int height();
bool getPixel(char character, int x, int y);
};
#endif //TERMINAL_FONT_H