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

Remove drawFrame() code duplication in IndexedColorAnimation and subclasses #16

Closed
fweiss opened this issue Jul 17, 2024 · 4 comments
Closed

Comments

@fweiss
Copy link
Owner

fweiss commented Jul 17, 2024

So we reduced the index color initialization code. Static initialization of pixelIndexes[][] works best instead of std::vectorstd::vector>. Also using ColorIndex enum to ensure that array bounds are safe. But the enum is tricky. We tried to put the drawFrame(Frame&) in the base class, but had to repeat it in each subclass to handle the subclass's particular enum.

We tried several approaches: templates. helper classes, helper functions. We want to keep the enum as index type safety, but the drawFrame lookups can be the underlying uint. The main problem seems to be with the colorMap which is std::map<ColorIndex,uint32_t>, where ColorIndex is peculiar to the subclass. We also don't want to have too much boilerplate in the derived classes.

@fweiss
Copy link
Owner Author

fweiss commented Jul 17, 2024

This is related to #10. Maybe just hack to data reduction and then deal with the code duplication?

@fweiss
Copy link
Owner Author

fweiss commented Jul 17, 2024

An outline of the IndexedColor::drawFrame(Frame&) function:

  • get pixel indexes for current frame (tricky)
  • loop over pixel indexes in the frame
  • lookup the mapped color (tricky)
  • set the pixel via the frame interface

@fweiss
Copy link
Owner Author

fweiss commented Jul 17, 2024

Maybe we can do a function relay like this:

in subclass:

void drawFrame(Frame& frame) {
    drawFrame<ColorIndex>(frame);
}

and the IndexColorAnimation, create a function template:

template<ColorIndexEnum>
void drawFrame(Frame& frame) {
    // here we have access to the particular ColorIndex for the subclass
}

@fweiss
Copy link
Owner Author

fweiss commented Jul 18, 2024

The above mentioned function template approach works.

@fweiss fweiss closed this as completed Jul 18, 2024
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

No branches or pull requests

1 participant