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

When the 3-Pencils enhancement were done, here another suggestion #32

Open
ghost opened this issue Jun 29, 2013 · 4 comments
Open

When the 3-Pencils enhancement were done, here another suggestion #32

ghost opened this issue Jun 29, 2013 · 4 comments

Comments

@ghost
Copy link

ghost commented Jun 29, 2013

After working with this 3 colour lines into separated layers, it would be a new implementation to this state to have functions which allow these same colour lines to be changed into one of the others,

for example a frame with rough drawings done with the Blue-Pencil could have its lines be turned into Black lines if they are susceptible to be used as finish lines.

I think it has something to do with an Alpha channel/layer that is pasted in front of that frame when we desire to change that lines

@davidlamhauge
Copy link
Contributor

Is this not taken care of by #1246?

@Jose-Moreno
Copy link
Member

@davidlamhauge In a way it does, but this has an extra requirement, and that is to specifically change the mentioned colors.

With the current implementation you've linked every pixel in the canvas will be tinted in the new color, but with this issue the key is that you should be able to tint only the intended color.

This usually requires a color sampling step to determine the hue of the color you want to replace before applying it. A sort of color filter if you will. Some apps do it with an HSVA or RGBA threshold, and ideally we should be able to replace the color with an alpha value as well.

In that sense the current implementation would be missing that previous step in order for this issue to be fulfilled entirely.

@davidlamhauge
Copy link
Contributor

davidlamhauge commented Jul 1, 2020

@Jose-Moreno Okay. I didn't read it properly.
I guess this should be possible on current keyframe or all keyframes, like the current feature that changes line color, but it could be hard to know the difference between the two, and what should the menu text be? In the present feature you select the color you want to end up with, but in the new feature you select the color you want replaced, and then you should select the new color afterwards. Hmm...
Well, the reason I stumbled upon this issue, is that I would like a feature, where you could colorize an existing line, with the color you have in your pencil/pen/brush. And that's quite another story.

@Jose-Moreno
Copy link
Member

@davidlamhauge Actually I don't think the basic functionality has to change. It can still be thought to change the keyframe or layer contents, but the key difference is using a color threshold to filter which pixels are meant to be changed.

So for example if I had 3 strokes, 1 red, 1 green and 1 blue, and picked the blue color using the eyedropper, that would make it so only the currently selected color as seen in the color box would be affected by the replacement color action.

Technically I'm not sure how this is done or how to make it a "proper" algorithm that's optimized but what i'd do as a naive approach is to:

  1. Pick the color I want to filter out. If we made a panel for this, i'd have a toggle that said "use currently selected color" if it's ON, it uses the color as threshold filter, if it's OFF it does what it's doing right now.
    If the mentioned checkbox is ON:
  2. When pressing the replace color menu option -> Store the color picked value as an RGBA vector or whatever object type is being used in Pencil2D right now
  3. Then i'd map (key-value pairs) all the pixel RGBA values in the canvas or selected area inside a multidimensional std::vector matrix or std::map . Of course if there's already a structure that handles these kind of things, i'd use that.
  4. With the map or container then i'd compare each value of the vector with the previously picked color. If using a threshold slider it means the pixel values comparison would have to occur within a certain range of color (to filter by hue) and alpha (to filter by transparency value; fully transparent)
  5. Then if the pixel grid has any pixel with colors that match the previously stored color within threshold, then apply the existing replace color function only to those pixels, taking care of preserving their current transparency / alpha value (so only hue would be changed)

I mean it seems the replace color function already does the pixel search by transparency using the mBounds object and methods to check, so it should be possible to add a restriction to look for the picked color before applying the actual color.

I also see that there are some utility methods used for the flood fill tool that could help with the specific color filtering like the scanline method and the compareColor method in bitmap.cpp

void BitmapImage::scanLine(int x, int y, QRgb color)

bool BitmapImage::compareColor(QRgb newColor, QRgb oldColor, int tolerance, QHash<QRgb, bool> *cache)

In essence the previous step we're looking for should be very similar to what the bucket tool is already doing, but we trade the user input for a canvas grid search, adjusting filtered pixels by hue & alpha threshold.

The floodfill algorithm is not perfect of course, but these concepts should make it possible to achieve the overall goal. At least that's my impression of it, but I could be wrong of course.

@J5lx J5lx moved this to Low priority in Enhancement Priority Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Low priority
Development

No branches or pull requests

2 participants