summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-10 19:01:21 +0100
committerwm4 <wm4@nowhere>2020-02-10 19:01:21 +0100
commit8c2179becfbda3253c34d5d71f5f095257830ac0 (patch)
tree9d10efae992e4fcb182139f67c8ff3b8ec886aa8
parentd699893dbda3213198d75c6d19cf401c53af3f1e (diff)
downloadmpv-8c2179becfbda3253c34d5d71f5f095257830ac0.tar.bz2
mpv-8c2179becfbda3253c34d5d71f5f095257830ac0.tar.xz
zimg: add pal8 unpacker
Some pngs are paletted, so this is vaguely interesting.
-rw-r--r--video/zimg.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/video/zimg.c b/video/zimg.c
index 7b118426a7..f0048aa195 100644
--- a/video/zimg.c
+++ b/video/zimg.c
@@ -411,6 +411,30 @@ static int packed_repack(void *user, unsigned i, unsigned x0, unsigned x1)
return 0;
}
+static int unpack_pal(void *user, unsigned i, unsigned x0, unsigned x1)
+{
+ struct mp_zimg_repack *r = user;
+
+ uint8_t *src = (void *)(r->mpi->planes[0] + r->mpi->stride[0] * (ptrdiff_t)i);
+ uint32_t *pal = (void *)r->mpi->planes[1];
+
+ uint8_t *dst[4] = {0};
+ for (int p = 0; p < r->num_planes; p++) {
+ dst[p] = r->tmp->planes[p] +
+ r->tmp->stride[p] * (ptrdiff_t)(i & r->zmask[p]);
+ }
+
+ for (int x = x0; x < x1; x++) {
+ uint32_t c = pal[src[x]];
+ dst[0][x] = (c >> 8) & 0xFF; // G
+ dst[1][x] = (c >> 0) & 0xFF; // B
+ dst[2][x] = (c >> 16) & 0xFF; // R
+ dst[3][x] = (c >> 24) & 0xFF; // A
+ }
+
+ return 0;
+}
+
static int repack_nv(void *user, unsigned i, unsigned x0, unsigned x1)
{
struct mp_zimg_repack *r = user;
@@ -574,6 +598,21 @@ static void setup_misc_packer(struct mp_zimg_repack *r)
static int c_order[] = {3, 2, 1};
for (int n = 0; n < 3; n++)
r->components[n] = c_order[n] - 1;
+ } else if (r->zimgfmt == IMGFMT_PAL8 && !r->pack) {
+ struct mp_regular_imgfmt gbrap = {
+ .component_type = MP_COMPONENT_TYPE_UINT,
+ .forced_csp = MP_CSP_RGB,
+ .component_size = 1,
+ .num_planes = 4,
+ .planes = { {1, {2}}, {1, {3}}, {1, {1}}, {1, {4}}, },
+ .chroma_w = 1,
+ .chroma_h = 1,
+ };
+ int grap_fmt = mp_find_regular_imgfmt(&gbrap);
+ if (!grap_fmt)
+ return;
+ r->zimgfmt = grap_fmt;
+ r->repack = unpack_pal;
}
}