create a different width of input and outpud SyncFIFO

This commit is contained in:
SikongJueluo
2024-07-01 21:51:00 +08:00
parent e4fffd21bb
commit 407dedd229
3 changed files with 180 additions and 23 deletions

View File

@@ -33,10 +33,11 @@ struct color_gain {
double red;
double green;
double blue;
} color_gain{1.1, 0.7, 1.3};
} color_gain{1.1, 0.7, 1.3}, white_gain;
static const double gamma_value = 2.2;
static const double saturation_inc = 0.5;
static const double white_radio = 0.1;
using namespace sc_core;
using namespace sc_dt;
@@ -143,7 +144,7 @@ int sc_main(int argc, char* argv[]) {
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);
// out_image.open("./transform/out.bin", std::ios::out | std::ios::binary);
if (!in_image.is_open()) {
std::cout << "Open image fail" << std::endl;
exit(0);
@@ -336,6 +337,8 @@ int sc_main(int argc, char* argv[]) {
new uint8_t[OUT_WIDTH * OUT_HEIGHT * 3]; // RGB24格式像素数据
// software algorthms analyze
uint32_t red_total = 0, green_total = 0, blue_total = 0;
uint8_t red_max = 0, green_max = 0, blue_max = 0;
for (int32_t y = 0; y < OUT_HEIGHT; ++y) {
for (int32_t x = 0; x < OUT_WIDTH; ++x) {
int32_t index = (y * OUT_WIDTH + x) * 3;
@@ -349,7 +352,13 @@ int sc_main(int argc, char* argv[]) {
// green = 255 * std::pow(green / 255.0, 1 / gamma_value);
// blue = 255 * std::pow(blue / 255.0, 1 / gamma_value);
// Adjust white balance
// Calculate white balance data
red_max = std::max(red_max, red);
green_max = std::max(green_max, green);
blue_max = std::max(blue_max, blue);
red_total += red;
green_total += green;
blue_total += blue;
// Adjust vibrance
// uint8_t max = std::max({red, green, blue});
@@ -379,7 +388,7 @@ int sc_main(int argc, char* argv[]) {
// green = static_cast<uchar>(L * 255 +
// (green - L * 255) * (1 +
// alpha));
// blue = static_cast<uchar>(L * 255 +
// blue = static_cast<uchar>(L * 255 +
// (blue - L * 255) * (1 +
// alpha));
// }
@@ -391,32 +400,47 @@ int sc_main(int argc, char* argv[]) {
}
}
// Save output image
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],
// sizeof(tb_isp.out[0]));
// out_image.close();
// save to image
// Adjust White Balance : Grey World Color Correction
double K = static_cast<double>(red_total + green_total + blue_total) / (3 * OUT_SIZE);
white_gain.red = static_cast<double>(K * OUT_SIZE) / red_total;
white_gain.green = static_cast<double>(K * OUT_SIZE) / green_total;
white_gain.blue = static_cast<double>(K * OUT_SIZE) / blue_total;
printf("Gain: red = %f, green = %f, blue = %f", white_gain.red,
white_gain.green, white_gain.blue);
for (int32_t y = 0; y < OUT_HEIGHT; ++y) {
for (int32_t x = 0; x < OUT_WIDTH; ++x) {
int32_t index = (y * OUT_WIDTH + x) * 3;
uint8_t red = data[index + 0];
uint8_t green = data[index + 1];
uint8_t blue = data[index + 2];
out_image.write((const char*)&red, sizeof(red));
out_image.write((const char*)&green, sizeof(green));
out_image.write((const char*)&blue, sizeof(blue));
printf("x=%4d, y=%4d, red=0x%02x, green=0x%02x, blue=0x%02x\n", x,
y, red, green, blue);
data[index + 0] =
static_cast<uint8_t>(white_gain.red * data[index + 0]);
data[index + 1] =
static_cast<uint8_t>(white_gain.green * data[index + 1]);
data[index + 2] =
static_cast<uint8_t>(white_gain.blue * data[index + 2]);
}
}
// save to bin
std::cout << "Ready to save raw RGB image" << std::endl;
// for (int32_t y = 0; y < OUT_HEIGHT; ++y) {
// for (int32_t x = 0; x < OUT_WIDTH; ++x) {
// int32_t index = (y * OUT_WIDTH + x) * 3;
// uint8_t red = data[index + 0];
// uint8_t green = data[index + 1];
// uint8_t blue = data[index + 2];
// out_image.write((const char*)&red, sizeof(red));
// out_image.write((const char*)&green, sizeof(green));
// out_image.write((const char*)&blue, sizeof(blue));
// printf("x=%4d, y=%4d, red=0x%02x, green=0x%02x, blue=0x%02x\n",
// x,
// y, red, green, blue);
// }
// }
// save to bmp
write_bmp("test.bmp", data, OUT_WIDTH, OUT_HEIGHT);
delete[] data;