This commit is contained in:
yukun 2019-11-28 17:14:27 +01:00
parent 8ef788ab64
commit 95b45bdce2
6 changed files with 31 additions and 18 deletions

View File

@ -64,7 +64,7 @@
#include "../src/Imagedisplay.hpp" #include "../src/Imagedisplay.hpp"
#include <unistd.h> #include <unistd.h>
void outPutPixel(int windowHeight, int windowWidth);
int main(){ int main(){
@ -76,23 +76,23 @@ int main(){
std::cout <<"picture" << std::endl; std::cout <<"picture" << std::endl;
vkvm::Color backgroundColor = vkvm::getBackgroundColor(); vkvm::Color backgroundColor = vkvm::getBackgroundColor();
for(int i = 0; i<1000; i++) { for(int i = 0; i<1000; i++) {
Imagedisplay imagedisplay("src/P1.bmp"); Imagedisplay imagedisplay("../src/P6.bmp");
imagedisplay.load("src/P1.bmp"); for (int w = 0; w < vkvm::getWidth(); w++) {
for (int w; w < vkvm::getWidth(); w++) { for (int h = 0; h < vkvm::getHeight(); h++) {
for (int h; h < vkvm::getHeight(); h++) {
unsigned int a ; unsigned int a ;
a = imagedisplay.getPixel(w, h); a = imagedisplay.getPixel(w, h);
vkvm::setPixel(w,h,vkvm::Color(a)); vkvm::setPixel(w,h,vkvm::Color(a));
} }
} }
outPutPixel(vkvm::getHeight() ,vkvm::getWidth());
sleep(5); sleep(5);
vkvm::setDefaultValues(); vkvm::setDefaultValues();
Imagedisplay imagedisplay2("src/P2.bmp"); Imagedisplay imagedisplay2("../src/P7.bmp");
imagedisplay2.load("src/P2.bmp");
for (int w; w < vkvm::getWidth(); w++) { for (int w = 0; w < vkvm::getWidth(); w++) {
for (int h; h < vkvm::getHeight(); h++) { for (int h = 0; h < vkvm::getHeight(); h++) {
unsigned int a ; unsigned int a ;
a = imagedisplay2.getPixel(w, h); a = imagedisplay2.getPixel(w, h);
vkvm::setPixel(w,h,vkvm::Color(a)); vkvm::setPixel(w,h,vkvm::Color(a));
@ -101,10 +101,9 @@ int main(){
sleep(5); sleep(5);
vkvm::setDefaultValues(); vkvm::setDefaultValues();
Imagedisplay imagedisplay3("src/P3.bmp"); Imagedisplay imagedisplay3("../src/P6.bmp");
imagedisplay3.load("src/P3.bmp"); for (int w = 0; w < vkvm::getWidth(); w++) {
for (int w; w < vkvm::getWidth(); w++) { for (int h = 0; h < vkvm::getHeight(); h++){
for (int h; h < vkvm::getHeight(); h++){
unsigned int a ; unsigned int a ;
a = imagedisplay3.getPixel(w, h); a = imagedisplay3.getPixel(w, h);
vkvm::setPixel(w,h,vkvm::Color(a)); vkvm::setPixel(w,h,vkvm::Color(a));
@ -114,10 +113,9 @@ int main(){
sleep(5); sleep(5);
vkvm::setDefaultValues(); vkvm::setDefaultValues();
Imagedisplay imagedisplay4("src/P4.bmp"); Imagedisplay imagedisplay4("../src/P7.bmp");
imagedisplay4.load("src/P4.bmp"); for (int w = 0; w < vkvm::getWidth(); w++) {
for (int w; w < vkvm::getWidth(); w++) { for (int h = 0; h < vkvm::getHeight(); h++){
for (int h; h < vkvm::getHeight(); h++){
unsigned int a ; unsigned int a ;
a = imagedisplay4.getPixel(w, h); a = imagedisplay4.getPixel(w, h);
vkvm::setPixel(w,h,vkvm::Color(a)); vkvm::setPixel(w,h,vkvm::Color(a));
@ -130,4 +128,18 @@ int main(){
}); });
vkvm::callEvent(vkvm::Timer); vkvm::callEvent(vkvm::Timer);
}
void outPutPixel(int windowHeight, int windowWidth) {
for(int y = 0; y < windowHeight; y++) {
for(int x = 0; x < windowWidth; x++) {
if(vkvm::getPixel(x, y).getRed() !=0) {
std::cout << "*";
} else {
std::cout << " ";
}
}
std::cout << "\n";
}
} }

View File

@ -29,7 +29,6 @@ void Imagedisplay::load(const std::string &file) {
for(int i = 0; i < str.size();i++){ for(int i = 0; i < str.size();i++){
data[i] = str[i]; data[i] = str[i];
} }
offset = (int)*(unsigned int*)(&data[10]); offset = (int)*(unsigned int*)(&data[10]);
width = (int)*(unsigned int*)(&data[18]); width = (int)*(unsigned int*)(&data[18]);
height = (int)*(unsigned int*)(&data[22]); height = (int)*(unsigned int*)(&data[22]);
@ -58,9 +57,11 @@ unsigned int Imagedisplay::getPixel(int x, int y) {
char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8); char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8);
for(int i = 0; i < getBitsPerPixel() / 8;i++){ for(int i = 0; i < getBitsPerPixel() / 8;i++){
*((char*)&pixel+i) = ptr[i]; *((char*)&pixel+i) = ptr[i];
std::cout<< "hi: im" << (unsigned int) ptr[i]<< std::endl;
} }
if(pixel != 0){ if(pixel != 0){
return pixel; return pixel;
} }
return pixel; return pixel;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB