diff --git a/CMakeLists.txt b/CMakeLists.txt index 9409d74..37777cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ file(GLOB_RECURSE TESTS test/*.cpp) set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") include_directories(${LIB_PATH}/include) -add_executable(Demo ${SOURCES} ${HEADERS} main/main.cpp) +add_executable(Demo ${SOURCES} ${HEADERS} main/main.cpp src/Imagedisplay.hpp src/Imagedisplay.cpp) target_link_libraries(Demo ${LIB_PATH}/lib/liblibrary.a) diff --git a/main/main.cpp b/main/main.cpp index 36c19fb..97206fe 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,58 +1,133 @@ +//#include +//#include "internal.hpp" +//#include "vkvm.hpp" +// +//int main() { +// vkvm::initialize(0); +// +// vkvm::registerEvent(vkvm::EventType::Redraw, [](){ +// vkvm::log(vkvm::INFO, "redraw event callback"); +// }); +// vkvm::registerEvent(vkvm::EventType::Timer, [](){ +// vkvm::log(vkvm::INFO, "timer event callback"); +// }); +// +// vkvm::buttonPressed(vkvm::KeyCode::A); +// vkvm::buttonPressed(vkvm::KeyCode::D); +// vkvm::buttonPressed(vkvm::KeyCode::Z); +// vkvm::buttonPressed(vkvm::KeyCode::Backspcce); +// +// vkvm::KeyCode code = vkvm::getLastPressedKey(); +// while(code != 0){ +// vkvm::log(vkvm::INFO, "keyCode: ", code); +// code = vkvm::getLastPressedKey(); +// } +// +// vkvm::setMode(vkvm::GraphicMode::RGB); +// +// vkvm::setPixel(0,0, vkvm::getBackgroundColor()); +// vkvm::setPixel(5,8, vkvm::getForegroundColor()); +// +// vkvm::Color color = vkvm::getPixel(0,0); +// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); +// color = vkvm::getPixel(5,8); +// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); +// +// vkvm::setMode(vkvm::GraphicMode::TwoColors); +// +// color = vkvm::getPixel(0,0); +// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); +// color = vkvm::getPixel(5,8); +// vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); +// +// +// std::string input; +// while(input != "exit"){ +// std::cout << "type r for redraw and t for timer (exit to exit)" << std::endl; +// std::cout << "> "; +// std::getline(std::cin, input); +// +// if(input == "r"){ +// vkvm::callEvent(vkvm::Redraw); +// } +// if(input == "t"){ +// vkvm::callEvent(vkvm::Timer); +// } +// } +// return 0; +//} + #include +#include "../src/demo.h" #include "internal.hpp" #include "vkvm.hpp" +#include "../src/Imagedisplay.hpp" +#include + + + +int main(){ -int main() { vkvm::initialize(0); - vkvm::registerEvent(vkvm::EventType::Redraw, [](){ - vkvm::log(vkvm::INFO, "redraw event callback"); - }); - vkvm::registerEvent(vkvm::EventType::Timer, [](){ - vkvm::log(vkvm::INFO, "timer event callback"); - }); + vkvm::setDefaultValues(); - vkvm::buttonPressed(vkvm::KeyCode::A); - vkvm::buttonPressed(vkvm::KeyCode::D); - vkvm::buttonPressed(vkvm::KeyCode::Z); - vkvm::buttonPressed(vkvm::KeyCode::Backspcce); + vkvm::registerEvent(vkvm::Timer, [](){ + std::cout <<"picture" << std::endl; + vkvm::Color backgroundColor = vkvm::getBackgroundColor(); + for(int i = 0; i<1000; i++) { + Imagedisplay imagedisplay("src/P1.bmp"); + imagedisplay.load("src/P1.bmp"); + for (int w; w < vkvm::getWidth(); w++) { + for (int h; h < vkvm::getHeight(); h++) { + unsigned int a ; + a = imagedisplay.getPixel(w, h); + vkvm::setPixel(w,h,vkvm::Color(a)); - vkvm::KeyCode code = vkvm::getLastPressedKey(); - while(code != 0){ - vkvm::log(vkvm::INFO, "keyCode: ", code); - code = vkvm::getLastPressedKey(); - } + } + } + sleep(5); + vkvm::setDefaultValues(); - vkvm::setMode(vkvm::GraphicMode::RGB); + Imagedisplay imagedisplay2("src/P2.bmp"); + imagedisplay2.load("src/P2.bmp"); + for (int w; w < vkvm::getWidth(); w++) { + for (int h; h < vkvm::getHeight(); h++) { + unsigned int a ; + a = imagedisplay2.getPixel(w, h); + vkvm::setPixel(w,h,vkvm::Color(a)); + } + } + sleep(5); + vkvm::setDefaultValues(); - vkvm::setPixel(0,0, vkvm::getBackgroundColor()); - vkvm::setPixel(5,8, vkvm::getForegroundColor()); + Imagedisplay imagedisplay3("src/P3.bmp"); + imagedisplay3.load("src/P3.bmp"); + for (int w; w < vkvm::getWidth(); w++) { + for (int h; h < vkvm::getHeight(); h++){ + unsigned int a ; + a = imagedisplay3.getPixel(w, h); + vkvm::setPixel(w,h,vkvm::Color(a)); + } - vkvm::Color color = vkvm::getPixel(0,0); - vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); - color = vkvm::getPixel(5,8); - vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); + } + sleep(5); + vkvm::setDefaultValues(); - vkvm::setMode(vkvm::GraphicMode::TwoColors); + Imagedisplay imagedisplay4("src/P4.bmp"); + imagedisplay4.load("src/P4.bmp"); + for (int w; w < vkvm::getWidth(); w++) { + for (int h; h < vkvm::getHeight(); h++){ + unsigned int a ; + a = imagedisplay4.getPixel(w, h); + vkvm::setPixel(w,h,vkvm::Color(a)); + } - color = vkvm::getPixel(0,0); - vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); - color = vkvm::getPixel(5,8); - vkvm::log(vkvm::INFO,"color = (", (int)color.getRed(), ", ", (int)color.getGreen(), ", ", (int)color.getBlue(), ")"); - - - std::string input; - while(input != "exit"){ - std::cout << "type r for redraw and t for timer (exit to exit)" << std::endl; - std::cout << "> "; - std::getline(std::cin, input); - - if(input == "r"){ - vkvm::callEvent(vkvm::Redraw); + } + sleep(5); } - if(input == "t"){ - vkvm::callEvent(vkvm::Timer); - } - } - return 0; -} + + }); + vkvm::callEvent(vkvm::Timer); + +} \ No newline at end of file diff --git a/src/Imagedisplay.cpp b/src/Imagedisplay.cpp new file mode 100644 index 0000000..3f2aad3 --- /dev/null +++ b/src/Imagedisplay.cpp @@ -0,0 +1,66 @@ +// +// Created by yukun on 27.11.19. +// +#include "Imagedisplay.hpp" +#include +#include + +Imagedisplay::Imagedisplay() { + offset = 0; + width = 0; + height = 0; + bpp = 0; +} + +Imagedisplay::Imagedisplay(const std::string &file) { + offset = 0; + width = 0; + height = 0; + bpp = 0; + load(file); +} + +void Imagedisplay::load(const std::string &file) { + std::ifstream stream; + stream.open(file); + if(stream.is_open()){ + std::string str((std::istreambuf_iterator(stream)),std::istreambuf_iterator()); + 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 Imagedisplay::getWidth() { + return width; +} + +int Imagedisplay::getHeight() { + return height; +} + +char *Imagedisplay::getData() { + return &data[offset]; +} + +int Imagedisplay::getBitsPerPixel() { + return bpp; +} + +unsigned int Imagedisplay::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; +} diff --git a/src/Imagedisplay.hpp b/src/Imagedisplay.hpp new file mode 100644 index 0000000..8a7664e --- /dev/null +++ b/src/Imagedisplay.hpp @@ -0,0 +1,28 @@ +// +// Created by yukun on 27.11.19. +// + +#ifndef DEMO_IMAGEDISPLAY_HPP +#define DEMO_IMAGEDISPLAY_HPP + +#include +#include + +class Imagedisplay { +public: + Imagedisplay(); + explicit Imagedisplay(const std::string &file); + void load(const std::string &file); + int getWidth(); + int getHeight(); + char *getData(); + int getBitsPerPixel(); + unsigned int getPixel(int x, int y); +private: + int width; + int height; + int offset; + int bpp; + std::vector data; +}; +#endif //DEMO_IMAGEDISPLAY_HPP diff --git a/src/P1.bmp b/src/P1.bmp new file mode 100644 index 0000000..9091f54 Binary files /dev/null and b/src/P1.bmp differ diff --git a/src/P2.bmp b/src/P2.bmp new file mode 100644 index 0000000..94f6779 Binary files /dev/null and b/src/P2.bmp differ diff --git a/src/P3.bmp b/src/P3.bmp new file mode 100644 index 0000000..24751c3 Binary files /dev/null and b/src/P3.bmp differ diff --git a/src/P4.bmp b/src/P4.bmp new file mode 100644 index 0000000..3735ab9 Binary files /dev/null and b/src/P4.bmp differ diff --git a/src/demo.h b/src/demo.h index 9b77cb9..041912a 100644 --- a/src/demo.h +++ b/src/demo.h @@ -1,8 +1,17 @@ -#ifndef SHARED_MEMORY_DEMO_H -#define SHARED_MEMORY_DEMO_H +#ifndef DEMO_H +#define DEMO_H +#include +#include +#include +#include +#include "Font.h" +#include "vector" -int test(); +class demo { +public: + +}; #endif //SHARED_MEMORY_DEMO_H