-
Notifications
You must be signed in to change notification settings - Fork 51
fix: copy background image to avoid re-encoding #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The original implementation was re-encoding the JPEG image when saving to both background.jpg and background_in_theme.jpg files, which could cause quality degradation and performance issues. This fix adds a copyFile function to duplicate the file without re-encoding, preserving image quality and improving efficiency. Log: Fixed background image quality issue in GRUB theme Influence: 1. Test that background images are properly displayed in GRUB menu 2. Verify both background.jpg and background_in_theme.jpg files are created 3. Check that image quality is maintained without artifacts 4. Test with different image formats and sizes 5. Verify the copy operation works correctly with file permissions fix: 复制背景图片避免重复编码 原实现在保存到 background.jpg 和 background_in_theme.jpg 文件时都会重新 编码 JPEG 图像,这可能导致质量下降和性能问题。此修复添加了 copyFile 函数 来复制文件而不重新编码,保持图像质量并提高效率。 Log: 修复了 GRUB 主题中的背景图片质量问题 Influence: 1. 测试 GRUB 菜单中背景图片是否正确显示 2. 验证 background.jpg 和 background_in_theme.jpg 文件是否都创建成功 3. 检查图像质量是否保持,没有出现伪影 4. 使用不同格式和大小的图片进行测试 5. 验证复制操作是否正确处理文件权限 PMS: BUG-315809
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactor setBackground to preserve image quality and improve performance by copying the JPEG file instead of re-encoding it for the second output, with explicit error handling for each step. Sequence diagram for the updated background image saving processsequenceDiagram
participant setBackground
participant os
participant logger
participant copyFile
setBackground->os: Stat(fallbackDir)
os-->>setBackground: exists
setBackground->saveJpeg: saveJpeg(bgImg, background.jpg)
saveJpeg-->>setBackground: error or success
alt saveJpeg error
setBackground->logger: Fatal(err)
else saveJpeg success
setBackground->copyFile: copyFile(background.jpg, background_in_theme.jpg)
copyFile-->>setBackground: error or success
alt copyFile error
setBackground->logger: Fatal(err)
end
end
Class diagram for the new copyFile function integrationclassDiagram
class setBackground {
+setBackground(bgFile string)
}
class copyFile {
+copyFile(src string, dst string) (written int64, err error)
}
setBackground --> copyFile: uses
class logger {
+Fatal(err error)
}
setBackground --> logger: error handling
class saveJpeg {
+saveJpeg(img, filename string) error
}
setBackground --> saveJpeg: saves JPEG
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码的修改看起来是为了优化背景图片的处理方式,但存在一些可以改进的地方:
建议的改进代码: func setBackground(bgFile string) error {
// ... 其他代码保持不变 ...
fallbackDir := getFallbackDir()
_, err := os.Stat(fallbackDir)
if err == nil {
// 构建文件路径
backgroundFile := filepath.Join(fallbackDir, "background.jpg")
backgroundInThemeFile := filepath.Join(fallbackDir, "background_in_theme.jpg")
// 保存JPEG图片
if err := saveJpeg(bgImg, backgroundFile); err != nil {
return fmt.Errorf("failed to save background image: %v", err)
}
// 复制文件到主题目录
if err := copyFileWithBuffer(backgroundFile, backgroundInThemeFile); err != nil {
return fmt.Errorf("failed to copy background image: %v", err)
}
}
return nil
}
// 带缓冲区的文件复制函数
func copyFileWithBuffer(src, dst string) error {
sourceFile, err := os.Open(src)
if err != nil {
return err
}
defer sourceFile.Close()
destFile, err := os.Create(dst)
if err != nil {
return err
}
defer destFile.Close()
// 使用4KB的缓冲区
buf := make([]byte, 4096)
_, err = io.CopyBuffer(destFile, sourceFile, buf)
return err
}这样的改进提高了代码的健壮性、可维护性和性能,同时提供了更好的错误处理机制。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, robertkill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
The original implementation was re-encoding the JPEG image when saving to both background.jpg and background_in_theme.jpg files, which could cause quality degradation and performance issues. This fix adds a copyFile function to duplicate the file without re-encoding, preserving image quality and improving efficiency.
Log: Fixed background image quality issue in GRUB theme
Influence:
fix: 复制背景图片避免重复编码
原实现在保存到 background.jpg 和 background_in_theme.jpg 文件时都会重新 编码 JPEG 图像,这可能导致质量下降和性能问题。此修复添加了 copyFile 函数
来复制文件而不重新编码,保持图像质量并提高效率。
Log: 修复了 GRUB 主题中的背景图片质量问题
Influence:
PMS: BUG-315809
Summary by Sourcery
Use file copying instead of re-encoding for GRUB background images to preserve quality and improve efficiency.
Bug Fixes:
Enhancements: