AutoSkill C++ CImage Save Translated Components
Implement the CImage::save function to generate a new BMP file with translated and reordered components. The function must create a blank image initialized to the background color, iterate through components using specific offset loops, and copy pixels based on original and new coordinates.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/c-cimage-save-translated-components" ~/.claude/skills/ecnu-icalk-autoskill-c-cimage-save-translated-components && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/c-cimage-save-translated-components/SKILL.mdsource content
C++ CImage Save Translated Components
Implement the CImage::save function to generate a new BMP file with translated and reordered components. The function must create a blank image initialized to the background color, iterate through components using specific offset loops, and copy pixels based on original and new coordinates.
Prompt
Role & Objective
You are a C++ Developer implementing the
CImage::save method for an image processing library. Your goal is to create a new image array where components have been translated to new positions and reordered, then save this to a file.
Communication & Style Preferences
Use standard C++ syntax. Adhere strictly to the specific loop structure requested by the user.
Operational Rules & Constraints
- Initialization: Create a new image array
by callingout
. This initializes the image to the background color.newImage(bgColor_) - Iteration: Loop through all components using
.numComponents() - Component Data: For each component
, extractc
(new row/col),ulNew
(original row/col),ulOrig
, andheight
.width - Loop Structure: Use nested loops starting at
andj=0
to iterate through the component's height (k=0
) and width (h
).w - Coordinate Calculation:
- Calculate original pixel position:
andorigPosR = origr + j
.origPosC = origc + k - Calculate new pixel position:
andnewPosR = newr + j
.newPosC = newc + k
- Calculate original pixel position:
- Pixel Verification: Check if the pixel at the original position belongs to the current component using
.labels_[origPosR][origPosC] == c.label - Pixel Copying: If the pixel belongs to the component, copy the RGB channels from
toimg_[origPosR][origPosC]
.out[newPosR][newPosC] - Finalization: Save the image using
and deallocate the memory usingwriteRGBBMP(filename, out, h_, w_)
.deallocateImage(out)
Anti-Patterns
- Do not use
.std::rotate - Do not iterate over the entire image dimensions (
,h_
) for every component; iterate only over the component's bounding box.w_ - Do not use
to check the new position; check the original position.labels_
Triggers
- implement CImage save function
- save translated components to bmp
- create new image array with background color
- copy pixels using j=0 and k=0 loops