From 236cd4ff6fce68036e46b55985d1f473e02f5a53 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 22 Dec 2020 12:21:56 +0100 Subject: [PATCH] [WIP] icon-palette --- app/src/icon.c | 42 ++++++++++++++++++++++++++++++++++++++---- data/icon.png | Bin 6540 -> 4156 bytes 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/src/icon.c b/app/src/icon.c index f5988c187e..b646b7bafd 100644 --- a/app/src/icon.c +++ b/app/src/icon.c @@ -182,6 +182,7 @@ to_sdl_pixel_format(enum AVPixelFormat fmt) { case AV_PIX_FMT_BGR555BE: return SDL_PIXELFORMAT_BGR555; case AV_PIX_FMT_RGB444BE: return SDL_PIXELFORMAT_RGB444; case AV_PIX_FMT_BGR444BE: return SDL_PIXELFORMAT_BGR444; + case AV_PIX_FMT_PAL8: return SDL_PIXELFORMAT_INDEX8; default: return SDL_PIXELFORMAT_UNKNOWN; } } @@ -203,10 +204,9 @@ scrcpy_icon_load() { goto error; } - bool is_packed_rgb = desc->flags & AV_PIX_FMT_FLAG_RGB - && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR); - if (!is_packed_rgb) { - LOGE("Could not load non-RGB icon"); + bool is_packed = !(desc->flags & AV_PIX_FMT_FLAG_PLANAR); + if (!is_packed) { + LOGE("Could not load non-packed icon"); goto error; } @@ -230,6 +230,40 @@ scrcpy_icon_load() { goto error; } + if (frame->format == AV_PIX_FMT_PAL8) { + // Initialize the SDL palette + uint8_t *data = frame->data[1]; + SDL_Color colors[256]; + for (int i = 0; i < 256; ++i) { + SDL_Color *color = &colors[i]; + + // The palette is transported in AVFrame.data[1], is 1024 bytes + // long (256 4-byte entries) and is formatted the same as in + // AV_PIX_FMT_RGB32 described above (i.e., it is also + // endian-specific). + // +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + color->a = data[i * 4]; + color->r = data[i * 4 + 1]; + color->g = data[i * 4 + 2]; + color->b = data[i * 4 + 3]; +#else + color->a = data[i * 4 + 3]; + color->r = data[i * 4 + 2]; + color->g = data[i * 4 + 1]; + color->b = data[i * 4]; +#endif + } + + SDL_Palette *palette = surface->format->palette; + assert(palette); + int ret = SDL_SetPaletteColors(palette, colors, 0, 256); + if (ret) { + LOGE("Could not set palette colors"); + goto error; + } + } + surface->userdata = frame; // frame owns the data return surface; diff --git a/data/icon.png b/data/icon.png index 06617be8a5496c8dc141dfaa898130275aa42918..9db8983a8c361bbf4018067679f62843d0b8d701 100644 GIT binary patch literal 4156 zcmcIn3p7>hx1VdRz3q*#QSG93i>jsU2HMS+e<$fG=sdI^~yVdWa(6udhka#xrito04{_QP!hckS_W z^xNfoDD;`%YKf7d!$xPTRGx-dES9|g){{8Xr!MiJ7~yE|1i--c2nVkaGAXODu8}XC z(G95sP>8j)Tf=czfZZ9dD{2Fb}`SJ2kogfl>LRE+<2Sh z!yU1(@9sIRee!bI_1LMb8RxmVMNVEkV^BZ8+}zBYNl7ESVr- z*fy|i+x9Wx8hHYU^EU;%_-zG9a)G}#cVI;e3!eE@5bSYXDup=nVe4!tg(CW=~#PBAN6+u5Rz<v~E1juqW5dkacgDKfo2!#gfQ z_WN^_W!tWn^p(}UdwSlu%qr>k;Dg`nHbRI6yHoCPZ-I4MV5YlxRQM|Hsx@5DsghPp zIU3$#o^<5W;ZO6Ql^RQvVJ9Ow4OM4n-5XdlFh&8H4;~w=BWJ|)_TuQ&6q8^F6#sCM zH}$oBXW}N+$)5b1b_njz9?y1pU(ux#x_YJHh>bM(zuo>wA>qZmr_+-%n!*|_xOO_; zI;84#XHRj`%6*Y4@Y?Y~Xt~wHsc7l`uXQUB(%B6yA8(x%}gMtQE-f3f`AhGYgla#6vSR zCk(DG0sHL~-Li9fi^0BAPOmJpQ;V9KIiuj_q7y(f;!I37VqjCG=o@gh_y8;mn=CAQ zrKb$(HPcsU2*mUc3Qg#M@B0=UFj%|+e9fg@MR+zO`;YU#8XR}|t;}SqY9j{Rp6NQv z1!l0OZj8B&Ng*7>!m)ih$gsbv*uN|u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