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

Fixes crop module bug #1019

Merged
merged 3 commits into from
Apr 18, 2019
Merged

Fixes crop module bug #1019

merged 3 commits into from
Apr 18, 2019

Conversation

Divy123
Copy link
Member

@Divy123 Divy123 commented Apr 16, 2019

Fixes #987

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with npm test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/is-reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@codecov
Copy link

codecov bot commented Apr 16, 2019

Codecov Report

Merging #1019 into main will increase coverage by 2.89%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1019      +/-   ##
==========================================
+ Coverage   34.08%   36.98%   +2.89%     
==========================================
  Files          97       99       +2     
  Lines        1778     1836      +58     
  Branches      278      287       +9     
==========================================
+ Hits          606      679      +73     
+ Misses       1172     1157      -15
Impacted Files Coverage Δ
examples/lib/defaultHtmlStepUi.js 14.47% <0%> (ø) ⬆️
src/modules/Crop/Crop.js 100% <100%> (ø)
src/util/ParseInputCoordinates.js 73.33% <0%> (ø)
src/modules/Crop/Module.js 91.3% <0%> (+82.6%) ⬆️

@Divy123
Copy link
Member Author

Divy123 commented Apr 16, 2019

@jywarren please review.
I will be adding UI tests once its ok to you.

@Divy123
Copy link
Member Author

Divy123 commented Apr 16, 2019

ezgif-1-eefec2b8c744

@Divy123
Copy link
Member Author

Divy123 commented Apr 16, 2019

@Divy123 please have a look!!

@jywarren
Copy link
Member

jywarren commented Apr 16, 2019 via email

@Divy123
Copy link
Member Author

Divy123 commented Apr 16, 2019

If I am getting it correct, it means to have a UI test with these coordinates as input:
Screenshot from 2019-04-17 01-39-24

@jywarren

@jywarren
Copy link
Member

jywarren commented Apr 17, 2019 via email

@jywarren
Copy link
Member

OK, it was a cache issue related to #605 #953 -- now there's no error; however, it doesn't crop:

image

In any case this should be fixed by your code, no? Can you try these dimensions specifically? Thank you so much!!!

@jywarren
Copy link
Member

And, shall we try adding a module test to protect this feature in the future? We could do a simple looks-like comparison like this:

test('Contrast module works correctly', function(t) {
sequencer.run({mode:'test'}, function(out) {
var result = sequencer.steps[2].output.src
base64Img.imgSync(result, target, 'result')
base64Img.imgSync(benchmark, target, 'benchmark')
result = './test_outputs/result.png'
benchmark = './test_outputs/benchmark.png'
looksSame(result, benchmark, function(err, res) {
if (err) console.log(err)
t.equal(res.equal, true)
t.end()
})
})
})

@vibhorgupta-gh
Copy link

vibhorgupta-gh commented Apr 17, 2019

@jywarren

OK, it was a cache issue related to #605 #953

I'm not so sure. I was still able to reproduce this, on certain values of x and y. I'll recheck and post back here. I was looking into #213 and it's pretty confusing as to why the image is being altered. I'll try and see if it indeed is just a cache issue.

@harshkhandeparkar
Copy link
Member

Maybe it is because of the util functions which are included. I think this only occurs when the offset values are included

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

In any case this should be fixed by your code, no? Can you try these dimensions specifically? Thank you so much!!!

There are some issues related to crop module involving the way pixels are manipulated that's why these problems are arising.
Doing some changes here.

And, shall we try adding a module test to protect this feature in the future? We could do a simple looks-like comparison like this:

Sure @jywarren!!

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

@harshkhandeparkar which of the util functions are you talking about?
What I am able to see this error is happening when x coordinates are changed.

When we change y ones, there are no errors its perfectly working.

@harshkhandeparkar
Copy link
Member

Probably parseCornerCoordinates. I don't know why I feel like the util func is a prob but I do.

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

To this, actually the problem existed even before the utility was added. You can refer #213 is an year old issue. Also the func only generates the exact coordinates if user enters in %. The code you can see and is pretty simple. I don't think there might be a bug. @harshkhandeparkar if you think there is can you point out please towards the line where it can be.

@jywarren
Copy link
Member

Sorry, to clarify:

OK, it was a cache issue related to #605 #953

I meant that the js error was a cache issue, not the color problems in the crop module. Thanks!

@jywarren
Copy link
Member

And there are some good clues on what's causing the color issue... sometimes it's missing a blue channel, sometimes a red channel! So, it seems likely due to a 4-color-channel pixel manipulation error of some kind.

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

Screenshot from 2019-04-17 20-45-55
@harshkhandeparkar this is the o/p as seen after removing the utility function. I think there is something other to it.

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

@jywarren the problem is arising when we change the 'x' coordinates and not in case of y coordinates.
What d you think can be a probable reason for this?

@vibhorgupta-gh
Copy link

Yes, @Divy123 I noticed the same in the afternoon. Have been trying to figure it out. I tried looking for issues with the jquery plugin itself, couldn't find one pertaining to this.

@jywarren thoughts on using some other well-maintained library for rewriting the module?

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

I don't think this is related to imageareaselect. There is somewhat missing in pixel manipulation.
Figuring it out, will try to come up with a solution soon.

@harshkhandeparkar
Copy link
Member

@Divy123 no I don't have any doubts. Wait I'll look into the rest of the code in a min.

Sent from my OnePlus3 using FastHub

@harshkhandeparkar
Copy link
Member

Ah look at this file https://github.com/publiclab/image-sequencer/blob/main/src/modules/Crop/Crop.js
It creates a new unit8Array and saves the pixels itself. This is an old module. I think we should try using the extraManipulation func of PixelManipulation API.

@harshkhandeparkar
Copy link
Member

@Divy123 it doesn't even use PixelManipulation properly.

Sent from my OnePlus3 using FastHub

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

@harshkhandeparkar It does not matter if it uses old or new functionality, it should be correct.

Looking into it now.

Thanks!!

@harshkhandeparkar
Copy link
Member

Maybe the older functionality didn't include the 4th channel, alpha. Anyways, updating to the latest is to be done in any case.

@Divy123
Copy link
Member Author

Divy123 commented Apr 17, 2019

ezgif com-video-to-gif

@jywarren working as desired now!!
Please have a look!!
Will add the test if it's ok to you!!

@jywarren
Copy link
Member

jywarren commented Apr 17, 2019 via email

@harshkhandeparkar
Copy link
Member

What was the problem @Divy123.

@Divy123
Copy link
Member Author

Divy123 commented Apr 18, 2019

@harshkhandeparkar there were a ceratin number of problems:

  1. We were using incorrect parent of input
  2. Somehow the css for imageareaselect was missing
  3. Input was not triggered by change in imageareaselect
  4. The pixels were manipulated incorrectly. I mean the logic used was partially incorrect.

@vibhorgupta-gh
Copy link

@Divy123 great catch :D

@vibhorgupta-gh vibhorgupta-gh requested a review from jywarren April 18, 2019 10:49
@harshkhandeparkar
Copy link
Member

@Divy123 why don't you update this to use PixelManipulation API? That will also make it future proof.

@harshkhandeparkar
Copy link
Member

And a lot simpler to read and manage.

@Divy123
Copy link
Member Author

Divy123 commented Apr 18, 2019

I think restructuring can be made in another PR of all those modules that run on older modules.
Thanks !!

@Divy123
Copy link
Member Author

Divy123 commented Apr 18, 2019

The code-cov increases by 2.89% here after adding the test.
Hurraayy 🎉 🎉
@jywarren please have a look!!

@jywarren jywarren merged commit 2be7a3d into publiclab:main Apr 18, 2019
@jywarren
Copy link
Member

Awesome!!!

@jywarren
Copy link
Member

Great work!!!

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

Successfully merging this pull request may close these issues.

Drag to select crop UI is broken
4 participants