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

attempting webgl-distort #1022

Merged
merged 12 commits into from
Apr 19, 2019
Merged

attempting webgl-distort #1022

merged 12 commits into from
Apr 19, 2019

Conversation

tech4GT
Copy link
Member

@tech4GT tech4GT commented Apr 18, 2019

@jywarren As of now the image sort of falls out of the canvas, after the module runs, can you try this and see how the inputs need to be changed for a sizeable demo.

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@codecov
Copy link

codecov bot commented Apr 18, 2019

Codecov Report

Merging #1022 into main will decrease coverage by 1.54%.
The diff coverage is 3.37%.

Impacted file tree graph

@@            Coverage Diff            @@
##             main   #1022      +/-   ##
=========================================
- Coverage   37.04%   35.5%   -1.55%     
=========================================
  Files         100     102       +2     
  Lines        1857    1946      +89     
  Branches      291     298       +7     
=========================================
+ Hits          688     691       +3     
- Misses       1169    1255      +86
Impacted Files Coverage Δ
src/Modules.js 100% <ø> (ø) ⬆️
src/modules/WebglDistort/index.js 100% <100%> (ø)
src/modules/WebglDistort/Module.js 2.27% <2.27%> (ø)

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
@tech4GT
Copy link
Member Author

tech4GT commented Apr 18, 2019

Oh silly me!! I put the code to run it in onload which was running it again and again! I fixed it!

@tech4GT
Copy link
Member Author

tech4GT commented Apr 18, 2019

Input:
image_0

Output:
image_1

@tech4GT
Copy link
Member Author

tech4GT commented Apr 18, 2019

cc @VibhorCodecianGupta

@vibhorgupta-gh
Copy link

Does this run in node environment as well? In theory, i mean. Is it supported?
Also, i want to test it out locally, I had written some code of my own similar to this deriving from @jywarren 's repo. How can i pull your branch?

@tech4GT
Copy link
Member Author

tech4GT commented Apr 18, 2019

Yes this is running just fine in node. :D
You should be able to run git pull https://github.com/tech4gt/image-sequencer webglDistort

@vibhorgupta-gh
Copy link

vibhorgupta-gh commented Apr 18, 2019

@tech4GT sweet, this works perfectly. The next steps could be:

  • take custom inputs for corner coordinates
  • take angle argument for distort (since this looks like a rotation function from face value)

Do you have any other improvements in mind?

@tech4GT
Copy link
Member Author

tech4GT commented Apr 18, 2019

Okay Vibhor, that sounds great, would you like to implement the custom options part?
Also @jywarren I tried using the node distribution of glfx but it did not work for me, I think for now the best way is to leave this stuff in the source code itself.

@tech4GT
Copy link
Member Author

tech4GT commented Apr 18, 2019

@VibhorCodecianGupta Once you are done make a pull request at my branch! Thanks!

@vibhorgupta-gh
Copy link

Will do.
This utilises a matrix of x,y coordinates for the new positions of the corner points, which is a tad bit too mathematical for the users to understand in one go, so they'll end up using trial and error to get the desired effect. The angle approach can be one fix to this. Any other ideas? I'll implement the custom coordinates anyway, just brainstorming here
cc @jywarren

@jywarren
Copy link
Member

So, for initial implementation, i think we should have x,y for all four corners, because one main use case is MapKnitter.org exporting. But i agree, we may think of other UIs that will be better -- and eventually, we could even have a "dragging" UI similar to https://github.com/publiclab/Leaflet.DistortableImage/ -- although that's a big project!!!

@vibhorgupta-gh
Copy link

Awesome. Working on x,y coordinates and the angle approach now.

@jywarren
Copy link
Member

Does it still generate images cut off if it goes outside the original canvas?

This is so rad!!!!!!!!!

@jywarren
Copy link
Member

I do think we should protect this with a test, esp. for how complex it is. Vibhor, did you want to try that too?

Once we have a test, we should feel comfortable swapping the webgl-distort library to source via NPM (although we can attempt it in a follow-up PR!) What do you think?

@vibhorgupta-gh
Copy link

Sounds good. I'll write the tests along as well. So this PR will be the custom inputs and test cases.

@vibhorgupta-gh
Copy link

Screen Shot 2019-04-19 at 10 30 00 AM

This is what custom inputs look like.
cc @jywarren @tech4GT

Also, @tech4GT I'm unable to push the changes, it says failed to push refs. I used git push https://github.com/tech4gt/image-sequencer webglDistort
Am I doing something wrong here?

@tech4GT
Copy link
Member Author

tech4GT commented Apr 19, 2019

Good work Vibhor!! Yeah you won't be able to push directly! Push to your fork and make a pull request from there to my branch.

@vibhorgupta-gh
Copy link

@tech4GT actually, I just did. My rebase commits and custom input code are all in your branch now. I apparently had to name my local branch the same as yours. Is that a problem, should I just make a PR instead?

@tech4GT
Copy link
Member Author

tech4GT commented Apr 19, 2019

Oh, if you are able to push then that's fine!

@vibhorgupta-gh vibhorgupta-gh requested a review from jywarren April 19, 2019 05:13
@@ -0,0 +1,230 @@
/*
* Resolves Fisheye Effect
Copy link
Member

Choose a reason for hiding this comment

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

I think this isn't the correct description.

/*
* Resolves Fisheye Effect
*/
module.exports = function DoNothing(options, UI) {
Copy link
Member

Choose a reason for hiding this comment

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

function DoNothing? 😂

try {
var canvas = fx.canvas(1500, 1500);
} catch (e) {
alert(e);
Copy link
Member

Choose a reason for hiding this comment

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

How about an alet that says "Not Supported" instead of just throwing the error. It will mostly be gibberish (i guess).

var defaults = require('./../../util/getDefaults.js')(require('./info.json'));

var output;
var fx = require('./glfx')
Copy link
Member

Choose a reason for hiding this comment

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

Why is it added to npm if it is included from the module folder?

Choose a reason for hiding this comment

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

@tech4GT pointed out how the npm distribution wasn't working for him, so he put the script in. For now, the script is utilised but let's not remove the npm dist either

Copy link
Member

Choose a reason for hiding this comment

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

Ok

@harshkhandeparkar
Copy link
Member

@VibhorCodecianGupta what do the negative coordinates indicate? Is the center of the image (0, 0)?

@harshkhandeparkar
Copy link
Member

Look at the img. It has anti-aliasing problems. Is it because of the library(webgl-distort)? Can it be fixed?

@harshkhandeparkar
Copy link
Member

Oh wait. The library is added to npm but never used?

@harshkhandeparkar
Copy link
Member

Are they relative to the original coords?

@vibhorgupta-gh
Copy link

No, they are absolute. 0,0 is the top left corner of the image.
here: https://github.com/publiclab/image-sequencer/pull/1022/files#diff-ed92d292abbd954e2a350862971fc8f7R203

@harshkhandeparkar
Copy link
Member

If (0,0) is the top left, will a negative coordinate lie outside the image/canvas?

@vibhorgupta-gh
Copy link

@harshkhandeparkar pull the branch and try it out locally once, you'll understand how it'll work. If you find some odd behaviour, let us know here

@harshkhandeparkar
Copy link
Member

Can you or someone publish it to your github pages? I don't have my pc right now. I will only be able to use it tmrw or the day after

@harshkhandeparkar
Copy link
Member

By the way, can't the image be anti alliased during the rasterisation stage?

@vibhorgupta-gh
Copy link

Also, from what I have tried out, it works in a relative fashion. The image will not overflow out of the canvas, the coordinates adjust themselves so that the maximum value of a point will be inside the canvas and every other point will be placed relatively. I'll check the anti-aliasing

@harshkhandeparkar
Copy link
Member

Ok

@vibhorgupta-gh
Copy link

Added test cases, good to go.
cc @tech4GT @jywarren

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Cool, just a few things noted here! Great work!!!

};
var target = 'test_outputs';
var red = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg==";
var benchmark = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAH0lEQVQ4T2NkoBAwUqifYdQAhtEwYBgNA1A+Gvi8AAAmmAARf9qcXAAAAABJRU5ErkJggg==";
Copy link
Member

Choose a reason for hiding this comment

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

Hi! Hmm, not sure; is this supposed to show anything? I tried opening it in a browser but don't see an image.

Copy link
Member

Choose a reason for hiding this comment

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

I do see a small grey-ish 16x16 pixel img.

Choose a reason for hiding this comment

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

I'll check it out!

// Test 2 to check options are correct
test('Check Options', function(t) {
t.equal(sequencer.steps[1].options.nw, '0 100', 'Options are correct');
t.equal(sequencer.steps[1].options.ne, '1023 50', 'Options are correct');
Copy link
Member

Choose a reason for hiding this comment

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

Here, that's a really big distortion; it's a very tiny image; could we just say something under 100?

Also, would it be possible to pass comma-separated values rather than space-separated? I think it'll render better in a URL, don't you think?

Choose a reason for hiding this comment

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

Agreed, comma separated it is, then

Copy link
Member

Choose a reason for hiding this comment

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

Comma separated values can have spaces as well. We have to replace those as well using regex. A better approach would be to do both. We can first separate it at spaces, then remove all commas, if there are no spaces, separate at commas.

@jywarren
Copy link
Member

Let's bump the version number to 3.2.0, too! I'm about to publish 3.1.0.

@vibhorgupta-gh
Copy link

I'll rectify these, then the following bump will support gl-context, fix the crop module bug and support various input methods. Sweet! It'll be of great help here

@jywarren
Copy link
Member

Just noting that i had already released v3.1.0, so i had to make the last one v3.2.0, so this will need to be v3.3.0. Sorry for the confusion!

ne: '1023 50',
se: '1223 867',
sw: '100 767'
nw: '0 0',
Copy link
Member

Choose a reason for hiding this comment

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

These coords aren't space separted. Shouldn't they be?

Copy link
Member

Choose a reason for hiding this comment

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

You are too fast.

module.exports = function parseDistortCoordinates(options) {

let coord = []
coord.push(options.nw.split(','))
Copy link
Member

Choose a reason for hiding this comment

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

I think we can also replace any spaces using regex.

@vibhorgupta-gh
Copy link

This is the new input format now, comma separated:

Screen Shot 2019-04-19 at 10 12 40 PM

Also, fixed tests, the new image distorted benchmark image is visible:

webgl-distort

@jywarren
Copy link
Member

Awesome, perfect! I can publish to NPM if you bump the version too.

@vibhorgupta-gh
Copy link

v3.3.0, right?

@jywarren
Copy link
Member

Yep!

@vibhorgupta-gh
Copy link

@jywarren version bumped, distort working. IS is maturing!

@jywarren jywarren merged commit c36922d into publiclab:main Apr 19, 2019
@jywarren
Copy link
Member

Amazing!!!

@jywarren
Copy link
Member

Publishing to NPM too!

@jywarren jywarren mentioned this pull request Apr 30, 2019
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.

4 participants