修复壁纸数据错误 bug
This commit is contained in:
@@ -33,9 +33,8 @@ uint32_t *generate_wallpaper(const wallpaper_config_t *wallpaper_config,
|
|||||||
uint32_t monitor_index = 0;
|
uint32_t monitor_index = 0;
|
||||||
while (monitor) {
|
while (monitor) {
|
||||||
uint32_t img_index = (index + monitor_index) % wallpaper_config->count;
|
uint32_t img_index = (index + monitor_index) % wallpaper_config->count;
|
||||||
|
const char *path = wallpaper_config->path_list[img_index];
|
||||||
Imlib_Image wallpaper_img =
|
Imlib_Image wallpaper_img = imlib_load_image(path);
|
||||||
imlib_load_image(wallpaper_config->path_list[img_index]);
|
|
||||||
if (!wallpaper_img) {
|
if (!wallpaper_img) {
|
||||||
monitor = monitor->next;
|
monitor = monitor->next;
|
||||||
monitor_index++;
|
monitor_index++;
|
||||||
@@ -55,14 +54,11 @@ uint32_t *generate_wallpaper(const wallpaper_config_t *wallpaper_config,
|
|||||||
float height_ratio = (float)dst_height / img_height;
|
float height_ratio = (float)dst_height / img_height;
|
||||||
float scale = MAX(width_ratio, height_ratio);
|
float scale = MAX(width_ratio, height_ratio);
|
||||||
|
|
||||||
uint32_t scaled_width = img_width * scale;
|
|
||||||
uint32_t scaled_height = img_height * scale;
|
|
||||||
|
|
||||||
/* 图片居中显示,计算原图绘制区域 */
|
/* 图片居中显示,计算原图绘制区域 */
|
||||||
int src_x = (scaled_width - dst_width) / (2 * scale);
|
|
||||||
int src_y = (scaled_height - dst_height) / (2 * scale);
|
|
||||||
int src_width = dst_width / scale;
|
int src_width = dst_width / scale;
|
||||||
int src_height = dst_height / scale;
|
int src_height = dst_height / scale;
|
||||||
|
int src_x = (img_width - src_width) / 2;
|
||||||
|
int src_y = (img_height - src_height) / 2;
|
||||||
|
|
||||||
/* 绘制图片到最终图像上 */
|
/* 绘制图片到最终图像上 */
|
||||||
imlib_context_set_image(final_image);
|
imlib_context_set_image(final_image);
|
||||||
@@ -84,7 +80,7 @@ uint32_t *generate_wallpaper(const wallpaper_config_t *wallpaper_config,
|
|||||||
|
|
||||||
/* 复制数据到自己分配的内存中(原数据会在图像释放后无效) */
|
/* 复制数据到自己分配的内存中(原数据会在图像释放后无效) */
|
||||||
size_t data_size = screen_width * screen_height * sizeof(uint32_t);
|
size_t data_size = screen_width * screen_height * sizeof(uint32_t);
|
||||||
uint32_t *result = malloc(data_size);
|
uint32_t *result = ecalloc(1, data_size);
|
||||||
if (result) memcpy(result, data, data_size);
|
if (result) memcpy(result, data, data_size);
|
||||||
|
|
||||||
/* 释放图像 */
|
/* 释放图像 */
|
||||||
|
|||||||
Reference in New Issue
Block a user