Skip to content

windows上ccap工具保存jpg、png图片bug处理 - #53

Merged
wysaid merged 2 commits into
wysaid:mainfrom
joefei94:main
Apr 25, 2026
Merged

windows上ccap工具保存jpg、png图片bug处理#53
wysaid merged 2 commits into
wysaid:mainfrom
joefei94:main

Conversation

@joefei94

@joefei94 joefei94 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

目前ccap工具在windows上保存jpg、png图片是反的,可以看一下例图。修改了一下代码,并删除了无用的处理逻辑。
capture_20260423_212411_1280x720_292

Summary by CodeRabbit

  • Bug Fixes
    • Fixed image orientation handling when exporting PNG and JPG files
    • Improved JPG color conversion consistency and processing efficiency

@coderabbitai

coderabbitai Bot commented Apr 25, 2026

Copy link
Copy Markdown

Walkthrough

PNG/JPG scanline orientation logic is inverted to correct directional handling, while outdated orientation documentation is removed. The JPG color conversion path for BGR input is simplified by consolidating duplicate branches into a single consistent loop that converts to RGB before encoding.

Changes

Cohort / File(s) Summary
Scanline Orientation & JPG Conversion Logic
cli/ccap_cli_utils.cpp
Inverted isTopToBottom condition for scanline ordering, removed Media Foundation comments, and consolidated duplicate BGR-to-RGB conversion branches into a single loop for JPG encoding.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A flip of the top, a flip of the base,
Scanlines now dance in their proper place!
Duplicate branches trimmed, color flows clean,
The trickiest logic we've ever seen!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the bug fix addressing incorrect image orientation (upside-down) when saving JPG/PNG files on Windows in the ccap tool.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wysaid
wysaid requested a review from Copilot April 25, 2026 08:59
@wysaid

wysaid commented Apr 25, 2026

Copy link
Copy Markdown
Owner

@Auggie review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cli/ccap_cli_utils.cpp (1)

850-882: Optional: deduplicate the BGR→RGB conversion and skip alpha for JPG.

The JPG and PNG branches now contain near-identical BGR→RGB loops. They can be hoisted into a single helper, and for JPG the alpha copy is unnecessary because stbi_write_jpg ignores the 4th channel (it always encodes RGB regardless of comp). Not a correctness issue — purely cleanup.

♻️ Sketch of a deduplicated helper
auto convertBgrToRgb = [&](bool keepAlpha) {
    std::vector<uint8_t> rgbBuffer(static_cast<size_t>(width) * height * comp);
    const int total = width * height;
    for (int i = 0; i < total; ++i) {
        rgbBuffer[i * comp + 0] = imageData[i * comp + 2];
        rgbBuffer[i * comp + 1] = imageData[i * comp + 1];
        rgbBuffer[i * comp + 2] = imageData[i * comp + 0];
        if (keepAlpha && comp == 4) {
            rgbBuffer[i * comp + 3] = imageData[i * comp + 3];
        }
    }
    return rgbBuffer;
};

if (imageFormat == ImageFormat::JPG) {
    if (isBGR && comp >= 3) {
        auto rgb = convertBgrToRgb(/*keepAlpha=*/false);
        result = stbi_write_jpg(filePath.c_str(), width, height, comp, rgb.data(), jpegQuality);
    } else {
        result = stbi_write_jpg(filePath.c_str(), width, height, comp, imageData, jpegQuality);
    }
} else { // PNG
    if (isBGR && comp >= 3) {
        auto rgb = convertBgrToRgb(/*keepAlpha=*/true);
        result = stbi_write_png(filePath.c_str(), width, height, comp, rgb.data(), width * comp);
    } else {
        result = stbi_write_png(filePath.c_str(), width, height, comp, imageData, width * comp);
    }
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/ccap_cli_utils.cpp` around lines 850 - 882, The BGR→RGB conversion is
duplicated in the ImageFormat::JPG and PNG branches; extract it into a single
helper (e.g., convertBgrToRgb or a lambda) that takes a keepAlpha flag and
returns a std::vector<uint8_t> with channels swapped, ensure you only copy alpha
when keepAlpha is true and comp == 4, then call that helper when isBGR && comp
>= 3; for JPG call it with keepAlpha=false (since stbi_write_jpg ignores the 4th
channel) and for PNG call it with keepAlpha=true, and replace the duplicated
loops with calls to this helper before invoking stbi_write_jpg/stbi_write_png.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cli/ccap_cli_utils.cpp`:
- Around line 850-882: The BGR→RGB conversion is duplicated in the
ImageFormat::JPG and PNG branches; extract it into a single helper (e.g.,
convertBgrToRgb or a lambda) that takes a keepAlpha flag and returns a
std::vector<uint8_t> with channels swapped, ensure you only copy alpha when
keepAlpha is true and comp == 4, then call that helper when isBGR && comp >= 3;
for JPG call it with keepAlpha=false (since stbi_write_jpg ignores the 4th
channel) and for PNG call it with keepAlpha=true, and replace the duplicated
loops with calls to this helper before invoking stbi_write_jpg/stbi_write_png.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3ff3a2c1-de78-445c-9f65-d7695d3de0c3

📥 Commits

Reviewing files that changed from the base of the PR and between 28c4fa4 and eb90582.

📒 Files selected for processing (1)
  • cli/ccap_cli_utils.cpp

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 修复了 ccap CLI 在 Windows 上导出 JPG/PNG 图片上下颠倒的问题,使保存逻辑与 FrameOrientation(TopToBottom / BottomToTop)的语义保持一致,并顺带移除了一段重复/无效的颜色通道转换分支。

Changes:

  • 修正 PNG/JPG 保存时的垂直翻转条件:仅在 BottomToTop 时进行 flip,以满足 stb 对“首行在内存起始处”的要求
  • 删除 JPG 的 BGR→RGB 转换中重复的 tempBuffer.empty() 分支逻辑,简化实现

@wysaid
wysaid merged commit af18e57 into wysaid:main Apr 25, 2026
40 checks passed
@wysaid

wysaid commented Apr 25, 2026

Copy link
Copy Markdown
Owner

感谢修复。 不只是 Windows,其他平台的这条路径也会受影响。已合入改动。

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.

3 participants