Imagey Working
parent
1aa3897528
commit
bdce7b1ff8
Binary file not shown.
|
@ -2,3 +2,60 @@
|
|||
0 641 1665866052497865386 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
0 664 1665866052521866039 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
0 746 1665866052601868219 CMakeFiles/Step_2.dir/src/util/parser.cpp.o dc1044c577ff67b5
|
||||
1 764 1665866108151377057 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
764 812 1665866108195378250 Step_2 19d1b439b571d21d
|
||||
0 737 1665866134140080705 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
737 784 1665866134188082003 Step_2 19d1b439b571d21d
|
||||
1 699 1665866154740637513 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
1 736 1665866154776638483 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
1 772 1665866154812639458 CMakeFiles/Step_2.dir/src/util/parser.cpp.o dc1044c577ff67b5
|
||||
772 819 1665866154856640645 Step_2 19d1b439b571d21d
|
||||
0 711 1665866173157134599 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
711 758 1665866173205135893 Step_2 19d1b439b571d21d
|
||||
1 745 1665866188345544081 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
745 793 1665866188393545377 Step_2 19d1b439b571d21d
|
||||
0 682 1665866198577819716 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
682 730 1665866198625821006 Step_2 19d1b439b571d21d
|
||||
1 658 1665866206622036278 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
658 703 1665866206666037462 Step_2 19d1b439b571d21d
|
||||
1 679 1665866259755463980 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
1 745 1665866259819465697 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
745 792 1665866259867466984 Step_2 19d1b439b571d21d
|
||||
1 694 1665866273771839855 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
694 740 1665866273819841139 Step_2 19d1b439b571d21d
|
||||
0 699 1665866283004087270 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
699 746 1665866283052088554 Step_2 19d1b439b571d21d
|
||||
1 695 1665866364454264811 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
1 762 1665866364522266625 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
762 812 1665866364570267904 Step_2 19d1b439b571d21d
|
||||
1 734 1665866415991638213 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
734 780 1665866416039639491 Step_2 19d1b439b571d21d
|
||||
1 767 1665866489461590889 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
767 817 1665866489513592269 Step_2 19d1b439b571d21d
|
||||
0 721 1665866534886795466 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
721 767 1665866534930796631 Step_2 19d1b439b571d21d
|
||||
1 737 1665866585904146106 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
737 785 1665866585952147377 Step_2 19d1b439b571d21d
|
||||
0 739 1665866609260763726 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
739 788 1665866609308764995 Step_2 19d1b439b571d21d
|
||||
1 751 1665866635861466605 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
751 797 1665866635905467768 Step_2 19d1b439b571d21d
|
||||
0 742 1665866645113710957 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
742 788 1665866645157712118 Step_2 19d1b439b571d21d
|
||||
1 698 1665866654509959046 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
698 750 1665866654561960418 Step_2 19d1b439b571d21d
|
||||
0 741 1665866688902866589 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
741 787 1665866688946867750 Step_2 19d1b439b571d21d
|
||||
0 666 1665866701887209005 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
666 714 1665866701931210166 Step_2 19d1b439b571d21d
|
||||
1 684 1665866709055397988 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
685 731 1665866709103399256 Step_2 19d1b439b571d21d
|
||||
0 703 1665866723327774171 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
0 778 1665866723399776069 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
778 825 1665866723447777334 Step_2 19d1b439b571d21d
|
||||
1 743 1665866747336406702 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
743 790 1665866747380407861 Step_2 19d1b439b571d21d
|
||||
0 718 1665866811722101345 CMakeFiles/Step_2.dir/src/image/image.cpp.o 13adbb05fcabbeec
|
||||
718 768 1665866811770102606 Step_2 19d1b439b571d21d
|
||||
1 675 1665866822498384757 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||
675 721 1665866822542385912 Step_2 19d1b439b571d21d
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
Start testing: Oct 15 16:34 EDT
|
||||
Start testing: Oct 15 16:47 EDT
|
||||
----------------------------------------------------------
|
||||
End testing: Oct 15 16:34 EDT
|
||||
End testing: Oct 15 16:47 EDT
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 768 KiB |
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.1 KiB |
Binary file not shown.
|
@ -41,14 +41,14 @@ namespace Raytracing {
|
|||
static inline std::string toLowerCase(const std::string& s){
|
||||
std::stringstream str;
|
||||
std::for_each(s.begin(), s.end(), [&str](unsigned char ch) {
|
||||
str << std::tolower(ch);
|
||||
str << (char) std::tolower(ch);
|
||||
});
|
||||
return str.str();
|
||||
}
|
||||
static inline std::string toUpperCase(const std::string& s){
|
||||
std::stringstream str;
|
||||
std::for_each(s.begin(), s.end(), [&str](unsigned char ch) {
|
||||
str << std::toupper(ch);
|
||||
str << (char) std::toupper(ch);
|
||||
});
|
||||
return str.str();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "image/image.h"
|
||||
#include <ios>
|
||||
#include <fstream>
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <image/stb_image_write.h>
|
||||
|
||||
namespace Raytracing {
|
||||
|
@ -17,7 +18,7 @@ namespace Raytracing {
|
|||
pixelData = new vec4[image.width * image.height];
|
||||
for (int i = 0; i < image.width; i++) {
|
||||
for (int j = 0; j < image.height; j++) {
|
||||
this->setPixelColor(i, j, image.pixelData[i * image.width + j]);
|
||||
this->setPixelColor(i, j, image.pixelData[i * image.height + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,19 +26,19 @@ namespace Raytracing {
|
|||
int Image::getPixelR(int x, int y) const {
|
||||
// values are stored as a floating point number [0, 1)
|
||||
// but most formats want an int [0, 255]
|
||||
return (int) (255.999 * getPixelColor(x, y).r());
|
||||
return int(255.0 * getPixelColor(x, y).r());
|
||||
}
|
||||
|
||||
int Image::getPixelG(int x, int y) const {
|
||||
return (int) (255.999 * getPixelColor(x, y).g());
|
||||
return int(255.0 * getPixelColor(x, y).g());
|
||||
}
|
||||
|
||||
int Image::getPixelB(int x, int y) const {
|
||||
return (int) (255.999 * getPixelColor(x, y).b());
|
||||
return int(255.0 * getPixelColor(x, y).b());
|
||||
}
|
||||
|
||||
int Image::getPixelA(int x, int y) const {
|
||||
return (int) (255.999 * getPixelColor(x, y).a());
|
||||
return int(255.0 * getPixelColor(x, y).a());
|
||||
}
|
||||
|
||||
Image::~Image() {
|
||||
|
@ -46,17 +47,17 @@ namespace Raytracing {
|
|||
|
||||
void ImageOutput::write(const std::string& file, const std::string& formatExtension) {
|
||||
auto lowerExtension = Raytracing::String::toLowerCase(formatExtension);
|
||||
auto fullFile = file + lowerExtension;
|
||||
auto fullFile = file + "." + lowerExtension;
|
||||
|
||||
if (!lowerExtension.ends_with("hdr")) {
|
||||
// unfortunately we do have to put the data into a format that STB can read
|
||||
int data[image.getWidth() * image.getHeight() * 3];
|
||||
unsigned char data[image.getWidth() * image.getHeight() * 3];
|
||||
int pixelIndex = 0;
|
||||
for (int i = 0; i < image.getWidth(); i++) {
|
||||
for (int j = 0; j < image.getHeight(); j++) {
|
||||
data[pixelIndex++] = image.getPixelR(i, j);
|
||||
data[pixelIndex++] = image.getPixelR(i, j);
|
||||
for (int j = image.getHeight()-1; j >= 0; j--) {
|
||||
for (int i = 0; i < image.getWidth(); i++) {
|
||||
data[pixelIndex++] = image.getPixelR(i, j);
|
||||
data[pixelIndex++] = image.getPixelG(i, j);
|
||||
data[pixelIndex++] = image.getPixelB(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,9 @@ namespace Raytracing {
|
|||
if (lowerExtension.ends_with("bmp")) {
|
||||
stbi_write_bmp(fullFile.c_str(), image.getWidth(), image.getHeight(), 3, data);
|
||||
} else if (lowerExtension.ends_with("png")) {
|
||||
stbi_write_png(fullFile.c_str(), image.getWidth(), image.getHeight(), 3, data, 3 * sizeof(int));
|
||||
// stride here isn't clearly defined in the docs for some reason,
|
||||
// but it's just the image's width times the number of channels
|
||||
stbi_write_png(fullFile.c_str(), image.getWidth(), image.getHeight(), 3, data, image.getWidth() * 3);
|
||||
} else if (lowerExtension.ends_with("jpg")) {
|
||||
stbi_write_jpg(fullFile.c_str(), image.getWidth(), image.getHeight(), 3, data, 90);
|
||||
} else
|
||||
|
|
|
@ -49,15 +49,11 @@ int main(int argc, char** args) {
|
|||
|
||||
Raytracing::Image image(512, 512);
|
||||
|
||||
for (int i = 0; i < image.getWidth(); i++){
|
||||
for (int j = 0; j < image.getHeight(); j++){
|
||||
image.setPixelColor(i, j, Raytracing::vec4(double(i) / double(image.getWidth()-1), double(j) / double(image.getHeight()-1), 0.25, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Raytracing::ImageOutput imageOutput(image);
|
||||
|
||||
imageOutput.write("hello", "png");
|
||||
imageOutput.write("test", "hdr");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue