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

Pixel remapping/Swizzling #1115

Open
onepiecefreak3 opened this issue Feb 16, 2020 · 7 comments
Open

Pixel remapping/Swizzling #1115

onepiecefreak3 opened this issue Feb 16, 2020 · 7 comments

Comments

@onepiecefreak3
Copy link

@onepiecefreak3 onepiecefreak3 commented Feb 16, 2020

This feature is implemented in many graphics hardwares at least of most gaming consoles. Adding this feature would enable ImageSharp to natively allow for these specifications of graphics hardware to be supported out of the box.

As per OpenCV naming and implementation this feature is most likely known as "Remapping" or "Point remapping". So as the naming goes, it should incorporate either one.

Point remappings are, as the name suggests, a process to rearrange the pixels from a source to a destination point, where each source point is modified as per following method:
dst(x,y) = src(fx(x,y), fy(x,y))

As for the implementation following this function, it should allow executing an action for both the x- and y-coordinate, and return its modified value respectively. Or an even simpler approach as seen in the Kanvas library of the Kuriimu2 project, where it just takes in a Point and returns a new one with the modified coordinates.

Sources:
OpenCV documentation on remapping: https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=remap
Kuriimu2's Kanvas Swizzle interface:https://github.com/FanTranslatorsInternational/Kuriimu2/blob/dev/src/Kontract/Kanvas/IImageSwizzle.cs

@antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Feb 20, 2020

As far as I remember our discussion, remapping should actually alter the image. This could be implemented easily in a single ImageProcessor that consumes an IImageSwizzle-like interface as a parameter.

@use191

This comment has been minimized.

@Sergio0694
Copy link
Collaborator

@Sergio0694 Sergio0694 commented Feb 23, 2020

This also seems a pretty good candidate to use the value delegate trick (for those unfamiliar, I mean using a struct type implementing an interface and making the method generic with the T : struct, ISomeInterface constraint, instead of taking an actual delegate like a Func<...>), since if I'm reading that linked OpenCV correctly, you'd basically have to invoke two custom functions to map the x, y coordinates of every single pixel in the original image 🤔
If there were two non-inlineable callvirt for each pixel, that'd be quite the performance hit.

@use191

This comment has been minimized.

@Mahiar7

This comment has been minimized.

@louis126

This comment has been minimized.

@onepiecefreak3
Copy link
Author

@onepiecefreak3 onepiecefreak3 commented Mar 7, 2020

@Sergio0694 Of course having 2 delegates calling for each coordinate x and y could hit performance in the situation you described. That's why I also included a sample from Kanvas, where a Point struct is just taken in, modified, and then returned. That might at least reduce the delegate count to one. But however you want to implement it, is of course the decision of this team here. I just gave my input on already existing examples for this kind of operation.

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

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.