Fix 8bit to float to 8bit conversion
This commit is contained in:
parent
5b20c5df29
commit
e40b7c1a29
1 changed files with 26 additions and 16 deletions
|
@ -49,6 +49,10 @@ namespace {
|
|||
|
||||
[[gnu::pure]]
|
||||
float to_srgb (float l) {
|
||||
if (l <= 0.00313066844250063f)
|
||||
return l * 12.92f;
|
||||
else
|
||||
return 1.055f * std::pow(l, 1.0f / 2.4f) - 0.055f;
|
||||
}
|
||||
|
||||
void srgb_to_linear (std::vector<float>& data, int, int) {
|
||||
|
@ -56,17 +60,16 @@ namespace {
|
|||
}
|
||||
|
||||
void linear_to_srgb (std::vector<float>& data, int w, int h) {
|
||||
assert(false);
|
||||
std::transform(data.begin(), data.end(), data.begin(), &to_srgb);
|
||||
}
|
||||
|
||||
std::vector<float> bilinear_resize (int in_w, int in_h, const std::vector<float>& data, int out_w, int out_h) {
|
||||
assert(false);
|
||||
return std::vector<float>();
|
||||
return data;
|
||||
}
|
||||
|
||||
std::vector<float> rgb4_to_float (const std::vector<char>& data, const std::vector<uint8_t>& palette, int w, int h) {
|
||||
assert(w * h);
|
||||
std::vector<float> retval(w * h);
|
||||
std::vector<float> retval(w * h * 3);
|
||||
const int scanl_sz = scanline_size(w, 4);
|
||||
|
||||
std::vector<float> float_palette;
|
||||
|
@ -82,10 +85,10 @@ namespace {
|
|||
const int row = y * scanl_sz;
|
||||
for (int x = 0; x < w / 2; ++x) {
|
||||
const uint8_t curr = data[row + x];
|
||||
const int dst_index_a = y * scanl_sz + x * 2 * 3;
|
||||
const int dst_index_a = y * (w * 3) + x * 2 * 3;
|
||||
const int dst_index_b = dst_index_a + 3;
|
||||
const int src_index_a = (curr bitand 0x0f) * 4;
|
||||
const int src_index_b = ((curr bitand 0xf0) >> 4) * 4;
|
||||
const int src_index_b = (curr bitand 0x0f) * 4;
|
||||
const int src_index_a = ((curr bitand 0xf0) >> 4) * 4;
|
||||
|
||||
retval[dst_index_a + 0] = float_palette[src_index_a + 0];
|
||||
retval[dst_index_a + 1] = float_palette[src_index_a + 1];
|
||||
|
@ -98,11 +101,17 @@ namespace {
|
|||
return retval;
|
||||
}
|
||||
|
||||
std::vector<char> float_to_rgb24 (const std::vector<float>& data) {
|
||||
std::vector<char> retval;
|
||||
retval.reserve(data.size());
|
||||
for (auto f : data) {
|
||||
retval.push_back(static_cast<char>(static_cast<uint8_t>(f * 255.0f)));
|
||||
std::vector<char> float_to_rgb24 (const std::vector<float>& data, int w, int h) {
|
||||
const int scanl_sz = scanline_size(w, 24);
|
||||
std::vector<char> retval(scanl_sz * h);
|
||||
assert(retval.size() >= data.size());
|
||||
|
||||
for (int y = 0; y < h; ++y) {
|
||||
for (int x = 0; x < w; ++x) {
|
||||
for (int c = 0; c < 3; ++c) {
|
||||
retval[y * scanl_sz + x * 3 + c] = static_cast<char>(static_cast<uint8_t>(data[y * scanl_sz + x * 3 + c] * 255.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -163,10 +172,11 @@ std::vector<std::vector<char>> icon_fetch (const ConstBlock& block, int width, i
|
|||
std::vector<char> resized_rgb;
|
||||
if (scale) {
|
||||
std::vector<float> float_data = rgb4_to_float(orig_rgb, palette, in_width, in_height);
|
||||
srgb_to_linear(float_data, in_width, in_height);
|
||||
auto float_resized_rgb = bilinear_resize(in_width, in_height, float_data, width, height);
|
||||
linear_to_srgb(float_resized_rgb, width, height);
|
||||
resized_rgb = float_to_rgb24(float_resized_rgb);
|
||||
//srgb_to_linear(float_data, in_width, in_height);
|
||||
//auto float_resized_rgb = bilinear_resize(in_width, in_height, float_data, width, height);
|
||||
//linear_to_srgb(float_resized_rgb, width, height);
|
||||
//resized_rgb = float_to_rgb24(float_resized_rgb, width, height);
|
||||
resized_rgb = float_to_rgb24(float_data, width, height);
|
||||
}
|
||||
else {
|
||||
std::swap(resized_rgb, orig_rgb);
|
||||
|
|
Loading…
Add table
Reference in a new issue