Compare commits

..

6 Commits

Author SHA1 Message Date
Romain Vimont
f7e11cb8aa Add scrcpy icon to README 2021-10-23 09:41:59 +02:00
Romain Vimont
2ef537997e Remove legacy scrcpy icon
Remove the old icon in XPM format and the code to load it.
2021-10-23 09:41:59 +02:00
Romain Vimont
778e60ce77 Add icon source in SVG format
Scrcpy only uses the PNG format (because SDL only supports bitmap
icons), but keep the SVG source in the repo.
2021-10-23 09:41:59 +02:00
Romain Vimont
45d099e3de Use a new scrcpy icon
Use the new icon designed by @varlesh:
<https://github.com/Genymobile/scrcpy/pull/1987#issuecomment-949684080>

Load it from a PNG file (SDL only supports bitmap icons).
2021-10-23 09:41:59 +02:00
Romain Vimont
934bb8efb7 Add support for palette icon formats
To support more icon formats.
2021-10-23 09:41:59 +02:00
Romain Vimont
fcadb44d45 Add icon loader
Add helper to load icons from image files via FFmpeg.
2021-10-23 09:41:58 +02:00
6 changed files with 32 additions and 42 deletions

View File

@@ -1,5 +1,7 @@
# scrcpy (v1.19) # scrcpy (v1.19)
![icon](data/icon.png)
[Read in another language](#translations) [Read in another language](#translations)
This application provides display and control of Android devices connected on This application provides display and control of Android devices connected on

View File

@@ -150,10 +150,7 @@ executable('scrcpy', src,
c_args: []) c_args: [])
install_man('scrcpy.1') install_man('scrcpy.1')
install_data('../data/icon.svg', install_data('../data/icon.png',
rename: 'scrcpy.svg',
install_dir: 'share/icons/hicolor/scalable/apps')
install_data('../data/icon_256x256.png',
rename: 'scrcpy.png', rename: 'scrcpy.png',
install_dir: 'share/icons/hicolor/256x256/apps') install_dir: 'share/icons/hicolor/256x256/apps')

View File

@@ -12,15 +12,9 @@
#include "util/process.h" #include "util/process.h"
#include "util/str_util.h" #include "util/str_util.h"
static const char *const scrcpy_icons[] = { #define SCRCPY_PORTABLE_ICON_FILENAME "icon.png"
#ifdef PORTABLE #define SCRCPY_DEFAULT_ICON_PATH \
"icon.svg",
"icon.png",
#else
PREFIX "/share/icons/hicolor/scalable/apps/scrcpy.svg"
PREFIX "/share/icons/hicolor/256x256/apps/scrcpy.png" PREFIX "/share/icons/hicolor/256x256/apps/scrcpy.png"
#endif
};
static char * static char *
get_envvar_icon_path(void) { get_envvar_icon_path(void) {
@@ -49,10 +43,6 @@ get_envvar_icon_path(void) {
static AVFrame * static AVFrame *
decode_image(const char *path) { decode_image(const char *path) {
// The non-allocation errors are logged in debug mode, because several
// paths might be tested sequentially. If the first fails but the second
// succeeds, then we don't want error messages in the console.
AVFrame *result = NULL; AVFrame *result = NULL;
AVFormatContext *ctx = avformat_alloc_context(); AVFormatContext *ctx = avformat_alloc_context();
@@ -62,18 +52,18 @@ decode_image(const char *path) {
} }
if (avformat_open_input(&ctx, path, NULL, NULL) < 0) { if (avformat_open_input(&ctx, path, NULL, NULL) < 0) {
LOGD("Could not open image codec: %s", path); LOGE("Could not open image codec: %s", path);
goto free_ctx; goto free_ctx;
} }
if (avformat_find_stream_info(ctx, NULL) < 0) { if (avformat_find_stream_info(ctx, NULL) < 0) {
LOGD("Could not find image stream info"); LOGE("Could not find image stream info");
goto close_input; goto close_input;
} }
int stream = av_find_best_stream(ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0); int stream = av_find_best_stream(ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
if (stream < 0 ) { if (stream < 0 ) {
LOGD("Could not find best image stream"); LOGE("Could not find best image stream");
goto close_input; goto close_input;
} }
@@ -81,18 +71,23 @@ decode_image(const char *path) {
AVCodec *codec = avcodec_find_decoder(params->codec_id); AVCodec *codec = avcodec_find_decoder(params->codec_id);
if (!codec) { if (!codec) {
LOGD("Could not find image decoder"); LOGE("Could not find image decoder");
goto close_input; goto close_input;
} }
AVCodecContext *codec_ctx = avcodec_alloc_context3(codec); AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);
if (!codec_ctx) {
LOGE("Could not allocate codec context");
goto close_input;
}
if (avcodec_parameters_to_context(codec_ctx, params) < 0) { if (avcodec_parameters_to_context(codec_ctx, params) < 0) {
LOGD("Could not fill codec context"); LOGE("Could not fill codec context");
goto free_codec_ctx; goto free_codec_ctx;
} }
if (avcodec_open2(codec_ctx, codec, NULL) < 0) { if (avcodec_open2(codec_ctx, codec, NULL) < 0) {
LOGD("Could not open image codec"); LOGE("Could not open image codec");
goto free_codec_ctx; goto free_codec_ctx;
} }
@@ -110,7 +105,7 @@ decode_image(const char *path) {
} }
if (av_read_frame(ctx, packet) < 0) { if (av_read_frame(ctx, packet) < 0) {
LOGD("Could not read frame"); LOGE("Could not read frame");
av_packet_free(&packet); av_packet_free(&packet);
av_frame_free(&frame); av_frame_free(&frame);
goto close_codec; goto close_codec;
@@ -118,14 +113,14 @@ decode_image(const char *path) {
int ret; int ret;
if ((ret = avcodec_send_packet(codec_ctx, packet)) < 0) { if ((ret = avcodec_send_packet(codec_ctx, packet)) < 0) {
LOGD("Could not send icon packet: %d", ret); LOGE("Could not send icon packet: %d", ret);
av_packet_free(&packet); av_packet_free(&packet);
av_frame_free(&frame); av_frame_free(&frame);
goto close_codec; goto close_codec;
} }
if ((ret = avcodec_receive_frame(codec_ctx, frame)) != 0) { if ((ret = avcodec_receive_frame(codec_ctx, frame)) != 0) {
LOGD("Could not receive icon frame: %d", ret); LOGE("Could not receive icon frame: %d", ret);
av_packet_free(&packet); av_packet_free(&packet);
av_frame_free(&frame); av_frame_free(&frame);
goto close_codec; goto close_codec;
@@ -236,6 +231,7 @@ load_from_path(const char *path) {
int ret = SDL_SetPaletteColors(palette, colors, 0, 256); int ret = SDL_SetPaletteColors(palette, colors, 0, 256);
if (ret) { if (ret) {
LOGE("Could not set palette colors"); LOGE("Could not set palette colors");
SDL_FreeSurface(surface);
goto error; goto error;
} }
} }
@@ -263,21 +259,18 @@ scrcpy_icon_load() {
return icon; return icon;
} }
for (size_t i = 0; i < ARRAY_LEN(scrcpy_icons); ++i) {
#ifndef PORTABLE #ifndef PORTABLE
icon = load_from_path(scrcpy_icons[i]); LOGD("Using icon: " SCRCPY_DEFAULT_ICON_PATH);
if (icon) { icon = load_from_path(SCRCPY_DEFAULT_ICON_PATH);
LOGD("Using icon: %s", scrcpy_icons[i]);
}
#else #else
icon_path = get_local_file_path(scrcpy_icons[i]); icon_path = get_local_file_path(SCRCPY_PORTABLE_ICON_FILENAME);
icon = load_from_path(icon_path); if (!icon_path) {
if (icon) { LOGE("Could not get icon path");
LOGD("Using icon (portable): %s", icon_path);
} }
LOGD("Using icon (portable): %s", icon_path);
icon = load_from_path(icon_path);
free(icon_path); free(icon_path);
#endif #endif
}
return icon; return icon;
} }

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@@ -94,8 +94,7 @@ dist-win32: build-server build-win32
cp "$(WIN32_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/" cp "$(WIN32_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN32_TARGET_DIR)/"
cp data/scrcpy-console.bat "$(DIST)/$(WIN32_TARGET_DIR)" cp data/scrcpy-console.bat "$(DIST)/$(WIN32_TARGET_DIR)"
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)" cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN32_TARGET_DIR)"
cp data/icon_256x256.png "$(DIST)/$(WIN32_TARGET_DIR)/icon.png" cp data/icon.png "$(DIST)/$(WIN32_TARGET_DIR)"
cp data/icon.svg "$(DIST)/$(WIN32_TARGET_DIR)"
cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avutil-56.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avcodec-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/" cp prebuilt-deps/ffmpeg-4.3.1-win32-shared/bin/avformat-58.dll "$(DIST)/$(WIN32_TARGET_DIR)/"
@@ -112,8 +111,7 @@ dist-win64: build-server build-win64
cp "$(WIN64_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/" cp "$(WIN64_BUILD_DIR)"/app/scrcpy.exe "$(DIST)/$(WIN64_TARGET_DIR)/"
cp data/scrcpy-console.bat "$(DIST)/$(WIN64_TARGET_DIR)" cp data/scrcpy-console.bat "$(DIST)/$(WIN64_TARGET_DIR)"
cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)" cp data/scrcpy-noconsole.vbs "$(DIST)/$(WIN64_TARGET_DIR)"
cp data/icon_256x256.png "$(DIST)/$(WIN64_TARGET_DIR)/icon.png" cp data/icon.png "$(DIST)/$(WIN64_TARGET_DIR)"
cp data/icon.svg "$(DIST)/$(WIN64_TARGET_DIR)"
cp prebuilt-deps/ffmpeg-4.3.1-win64-shared/bin/avutil-56.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp prebuilt-deps/ffmpeg-4.3.1-win64-shared/bin/avutil-56.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
cp prebuilt-deps/ffmpeg-4.3.1-win64-shared/bin/avcodec-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp prebuilt-deps/ffmpeg-4.3.1-win64-shared/bin/avcodec-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/"
cp prebuilt-deps/ffmpeg-4.3.1-win64-shared/bin/avformat-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/" cp prebuilt-deps/ffmpeg-4.3.1-win64-shared/bin/avformat-58.dll "$(DIST)/$(WIN64_TARGET_DIR)/"

2
run
View File

@@ -20,6 +20,6 @@ then
exit 1 exit 1
fi fi
SCRCPY_ICON_PATH="data/icon.svg" \ SCRCPY_ICON_PATH="data/icon.png" \
SCRCPY_SERVER_PATH="$BUILDDIR/server/scrcpy-server" \ SCRCPY_SERVER_PATH="$BUILDDIR/server/scrcpy-server" \
"$BUILDDIR/app/scrcpy" "$@" "$BUILDDIR/app/scrcpy" "$@"