Skip to content
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

fix: support multi frame image load #148

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rb-union
Copy link
Contributor

As title.

Log: Support multi frame image load.
Influence: quickprint

@rb-union rb-union changed the base branch from release/nofreeimage to master November 8, 2024 09:14
As title.

Log: Support multi frame image load.
Influence: quickprint
@rb-union rb-union force-pushed the release/nofreeimage branch from ed671d7 to d0c05bb Compare November 8, 2024 09:15
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rb-union

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 15, 2024

TAG Bot

New tag: 1.0.47
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #153

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码逻辑优化

    • QImageReader创建后立即检查imagePtr->frame是否等于s_SingleFrame,如果相等则不调用jumpToImage,这可能是为了处理单帧图像的情况。但是,如果s_SingleFrame等于0或某个特定值,可能会导致jumpToImage被调用,这可能是逻辑错误。建议确认s_SingleFrame的值是否正确,并确保逻辑符合预期。
  2. 异常处理

    • catch块中捕获了std::exception,但没有对异常进行进一步处理或记录。建议在捕获异常后,记录更多的上下文信息,以便于调试和问题追踪。
  3. 资源管理

    • QImageReader对象在异常处理和正常流程中都没有被显式释放。虽然QImageReader在析构时会自动释放资源,但在异常情况下,显式释放资源是一个好的实践,可以避免潜在的内存泄漏。
  4. 错误处理

    • qWarningqCritical中打印的错误信息应该更加详细,包括文件路径和帧号,以便于快速定位问题。
  5. 代码风格

    • 代码中存在一些多余的空行,建议清理代码,保持代码的整洁和可读性。
  6. 注释

    • 注释应该更加详细,解释为什么需要跳转到特定帧,以及为什么在读取失败时需要设置ContentError状态。

综合以上意见,建议对代码进行如下修改:

QImageReader reader(imagePtr->filePath);
if (s_SingleFrame != imagePtr->frame) {
    if (!reader.jumpToImage(imagePtr->frame)) {
        qWarning() << QString("Load multi frame image failed(jump to image): %1, file: %2, frame: %3")
                   .arg(reader.errorString()).arg(imagePtr->filePath).arg(imagePtr->frame);
        imagePtr->state = ContentError;
        return false;
    }
}

if (!reader.canRead()) {
    qWarning() << QString("Load multi frame image failed: %1, file: %2, frame: %3")
               .arg(reader.errorString()).arg(imagePtr->filePath).arg(imagePtr->frame);
    imagePtr->state = ContentError;
    return false;
}

imagePtr->data = reader.read();
if (imagePtr->data.isNull()) {
    qWarning() << QString("Load multi frame image failed: %1, file: %2, frame: %3")
               .arg(reader.errorString()).arg(imagePtr->filePath).arg(imagePtr->frame);
    imagePtr->state = ContentError;
    return false;
}

try {
    // 其他可能抛出异常的代码
} catch (const std::exception &e) {
    qCritical() << qPrintable("Exception: load image failed!") << qPrintable(e.what())
                << "File: " << imagePtr->filePath << "Frame: " << imagePtr->frame;
    // 处理异常
}

以上修改旨在提高代码的可读性、健壮性和可维护性。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants