summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/png.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-08-15 18:19:18 +1000
committer Vas Crabb <vas@vastheman.com>2017-08-15 18:19:18 +1000
commit1c4c96a0cf8f0499d264bc9ddbe7b05743276cd6 (patch)
tree1850570267d4cda951bed85b4d9841af55780ee8 /src/lib/util/png.cpp
parentb978ce8af35f662cc43275a06b5ff07ef79b7472 (diff)
add a not BIOS machine filter (useful in composite filters), support RGB PNG with transparent pen because why not
Diffstat (limited to 'src/lib/util/png.cpp')
-rw-r--r--src/lib/util/png.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/lib/util/png.cpp b/src/lib/util/png.cpp
index 409d8806f3d..54f943e3955 100644
--- a/src/lib/util/png.cpp
+++ b/src/lib/util/png.cpp
@@ -543,15 +543,16 @@ public:
// handle grayscale non-alpha case
uint32_t const bpp(pnginfo.bit_depth >> 3);
std::uint16_t const transpen(pnginfo.trans ? fetch_16bit(pnginfo.trans.get()) : 0U);
+ unsigned const samp_shift((8 < pnginfo.bit_depth) ? 8 : 0);
for (std::uint32_t y = 0; dimensions.second > y; ++y)
{
for (std::uint32_t x = 0; dimensions.first > x; ++x, src += bpp)
{
- std::uint16_t i((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src));
- std::uint8_t const a((pnginfo.trans && (transpen == i)) ? 0x00 : 0xff);
- i >>= (8 < pnginfo.bit_depth) ? 8 : 0;
- accumalpha &= a;
- bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = rgb_t(a, i, i, i);
+ std::uint16_t i_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src));
+ std::uint8_t const a_val((pnginfo.trans && (transpen == i_val)) ? 0x00 : 0xff);
+ i_val >>= samp_shift;
+ accumalpha &= a_val;
+ bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = rgb_t(a_val, i_val, i_val, i_val);
}
}
}
@@ -576,12 +577,23 @@ public:
uint32_t const r(0 * bps);
uint32_t const g(1 * bps);
uint32_t const b(2 * bps);
+ std::uint16_t const transpen_r(pnginfo.trans ? fetch_16bit(&pnginfo.trans[0]) : 0U);
+ std::uint16_t const transpen_g(pnginfo.trans ? fetch_16bit(&pnginfo.trans[2]) : 0U);
+ std::uint16_t const transpen_b(pnginfo.trans ? fetch_16bit(&pnginfo.trans[4]) : 0U);
+ unsigned const samp_shift((8 < pnginfo.bit_depth) ? 8 : 0);
for (std::uint32_t y = 0; dimensions.second > y; ++y)
{
for (std::uint32_t x = 0; dimensions.first > x; ++x, src += bpp)
{
- rgb_t const pix(0xff, src[r], src[g], src[b]);
- bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = pix;
+ uint16_t r_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src + r));
+ uint16_t g_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src + g));
+ uint16_t b_val((8 < pnginfo.bit_depth) ? fetch_16bit(src) : fetch_8bit(src + b));
+ std::uint8_t const a_val((pnginfo.trans && (transpen_r == r_val) && (transpen_g == g_val) && (transpen_b == b_val)) ? 0x00 : 0xff);
+ r_val >>= samp_shift;
+ g_val >>= samp_shift;
+ b_val >>= samp_shift;
+ accumalpha &= a_val;
+ bitmap.pix32((y << y_shift) + y_offs, (x << x_shift) + x_offs) = rgb_t(a_val, r_val, g_val, b_val);
}
}
}