just test gamma correction algorithm
This commit is contained in:
@@ -56,7 +56,7 @@ VERILATOR_FLAGS += --threads 14
|
||||
TOP_MODULE = isp
|
||||
VERILATOR_FLAGS += -top $(TOP_MODULE)
|
||||
# Input files for Verilator
|
||||
VERILATOR_INPUT = ../isp.v *.cpp ../Demosaic/Demosaic2.v ../Crop/*.v ../ColorBlender/*.v ../RAM/*.v
|
||||
VERILATOR_INPUT = ../isp.v *.cpp ../Demosaic/Demosaic2.v ../Crop/*.v ../Color/*.v ../RAM/*.v
|
||||
|
||||
# Check if SC exists via a verilator call (empty if not)
|
||||
SYSTEMC_EXISTS := $(shell $(VERILATOR) --get-supported SYSTEMC)
|
||||
|
||||
@@ -28,15 +28,15 @@ static const uint16_t OUT_WIDTH = 1920;
|
||||
static const uint16_t OUT_HEIGHT = 1080;
|
||||
#define OUT_SIZE (OUT_WIDTH * OUT_HEIGHT)
|
||||
|
||||
struct color_gain
|
||||
{
|
||||
// color gain for correcting color
|
||||
struct color_gain {
|
||||
double red;
|
||||
double green;
|
||||
double blue;
|
||||
}color_gain {1.0, 0.5, 1.1};
|
||||
} color_gain{1.3, 0.8, 1.3};
|
||||
|
||||
static const double gamma_value = 2.2;
|
||||
|
||||
using namespace std;
|
||||
using namespace sc_core;
|
||||
using namespace sc_dt;
|
||||
|
||||
@@ -56,8 +56,8 @@ SC_MODULE(TB_ISP) {
|
||||
sc_in<uint32_t> im_data;
|
||||
|
||||
sc_out<bool> is_done;
|
||||
unique_ptr<uint16_t[]> image = make_unique<uint16_t[]>(IN_SIZE);
|
||||
unique_ptr<uint32_t[]> out = make_unique<uint32_t[]>(OUT_SIZE);
|
||||
std::unique_ptr<uint16_t[]> image = std::make_unique<uint16_t[]>(IN_SIZE);
|
||||
std::unique_ptr<uint32_t[]> out = std::make_unique<uint32_t[]>(OUT_SIZE);
|
||||
|
||||
SC_CTOR(TB_ISP) {
|
||||
SC_CTHREAD(send_Data, clk.pos());
|
||||
@@ -137,25 +137,25 @@ SC_MODULE(TB_ISP) {
|
||||
};
|
||||
|
||||
int sc_main(int argc, char* argv[]) {
|
||||
cout << "Get into sc_main" << endl;
|
||||
std::cout << "Get into sc_main" << std::endl;
|
||||
// Open image
|
||||
ifstream in_image;
|
||||
ofstream out_image;
|
||||
in_image.open("./transform/test.bin", ios::in | ios::binary);
|
||||
out_image.open("./transform/out.bin", ios::out | ios::binary);
|
||||
std::ifstream in_image;
|
||||
std::ofstream out_image;
|
||||
in_image.open("./transform/test.bin", std::ios::in | std::ios::binary);
|
||||
out_image.open("./transform/out.bin", std::ios::out | std::ios::binary);
|
||||
if (!in_image.is_open()) {
|
||||
cout << "Open image fail" << endl;
|
||||
std::cout << "Open image fail" << std::endl;
|
||||
exit(0);
|
||||
} else {
|
||||
cout << "Ready to sim" << endl;
|
||||
std::cout << "Ready to sim" << std::endl;
|
||||
}
|
||||
|
||||
// Read image
|
||||
auto buf = make_unique<uint8_t[]>(2 * IN_SIZE);
|
||||
auto buf = std::make_unique<uint8_t[]>(2 * IN_SIZE);
|
||||
in_image.read((char*)buf.get(), IN_SIZE * 2);
|
||||
in_image.close();
|
||||
// Reshape data
|
||||
auto image = make_unique<uint16_t[]>(IN_SIZE);
|
||||
auto image = std::make_unique<uint16_t[]>(IN_SIZE);
|
||||
uint32_t i = 0;
|
||||
for (int y = 0; y < IN_HEIGHT; y++) {
|
||||
for (int x = 0; x < IN_WIDTH; x++) {
|
||||
@@ -164,7 +164,7 @@ int sc_main(int argc, char* argv[]) {
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
cout << "Finish Reading data" << endl;
|
||||
std::cout << "Finish Reading data" << std::endl;
|
||||
|
||||
// This is a more complicated example, please also see the simpler
|
||||
// examples/make_hello_c.
|
||||
@@ -306,7 +306,7 @@ int sc_main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Save output image
|
||||
cout << "Ready to save raw RGB image" << endl;
|
||||
std::cout << "Ready to save raw RGB image" << std::endl;
|
||||
// for (int y = 0; y < OUT_HEIGHT; y++)
|
||||
// for(int x = 0; x < OUT_WIDTH; x++)
|
||||
// out_image.write((const char *)&tb_isp.out[y * OUT_WIDTH + x],
|
||||
@@ -324,6 +324,10 @@ int sc_main(int argc, char* argv[]) {
|
||||
uint8_t green = (tb_isp.out[y * OUT_WIDTH + x] & 0x0000ff00) >> 8;
|
||||
uint8_t blue = (tb_isp.out[y * OUT_WIDTH + x] & 0x000000ff);
|
||||
|
||||
// red = 255 * std::pow(red / 255.0, 1 / gamma_value);
|
||||
// green = 255 * std::pow(green / 255.0, 1 / gamma_value);
|
||||
// blue = 255 * std::pow(blue / 255.0, 1 / gamma_value);
|
||||
|
||||
out_image.write((const char*)&red, sizeof(red));
|
||||
out_image.write((const char*)&green, sizeof(green));
|
||||
out_image.write((const char*)&blue, sizeof(blue));
|
||||
@@ -337,12 +341,6 @@ int sc_main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i = 0; i < OUT_WIDTH * OUT_HEIGHT * 3; i += 3) {
|
||||
// data[i + 0] = std::min(255, static_cast<int>(data[i + 0] *
|
||||
// red_gain)); data[i + 1] = std::min(255, static_cast<int>(data[i + 1]
|
||||
// * green_gain)); data[i + 2] = std::min(255, static_cast<int>(data[i +
|
||||
// 2] * blue_gain));
|
||||
// }
|
||||
write_bmp("test.bmp", data, OUT_WIDTH, OUT_HEIGHT);
|
||||
delete[] data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user