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

dynamic canvas scaling? #108

Merged
merged 10 commits into from
Dec 18, 2022
Merged

dynamic canvas scaling? #108

merged 10 commits into from
Dec 18, 2022

Conversation

seijihariki
Copy link
Collaborator

We finally have some working (?) dynamic canvas scaling. For now, uses buttons to scale the canvas manually. It has some of the black magic everyone loves, and messing with prototypes (which is okay, I think. This is an end-user application and not a lib, and changes only affect canvases with the .origin property set on its context.).

But the good thing of using this approach is that "most" code didn't change much, and if you just develop your tools using world coordinates as normal, everything should work fine. Hard-coded coordinates have no more meaning practically, not even (0, 0) for the layer canvases, so for these particular uses you will have to use the Root functions, like drawImageRoot, or use utility layer functions such as layer.clear().

So, basically:

  • The black magic makes coding decently easy (no dealing with coordinate transforms)
  • The black magic makes history function properly after canvas scale, not requiring any changes to the history entries themselves
  • The black magic is kind of seamless, automatically drawing correctly from canvases to canvases in a way that supports canvas with various origins.
  • The black magic makes things stay in the same place they were before (things on 0, 0 continue in 0, 0; things on 35, 7 continue on 35, 7)
  • The black magic makes negative coordinates valid on the canvas.

Initially, I was trying to use translate() transform and other transformation matrices. But some things (drawImage did not take translate into account when sourcing; same as getImageData and putImageData) were making this a painful transition.

So, this is the black magic commit. If you find any problems during testing (I would be surprised if there aren't any), please open an issue, so I can give this a look.

@zero01101 I don't know what you were expecting, but I guess it may be this.

Signed-off-by: Victor Seiji Hariki victorseijih@gmail.com

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
@seijihariki seijihariki changed the title canvas scaling? dynamic canvas scaling? Dec 17, 2022
@seijihariki
Copy link
Collaborator Author

And, if you want to ask, this system probably supports infinite canvasing (autoscale and whatnot). Just need to tweak the black magic a bit, detecting external draw requests and sending an expand() call when a draw is attempted outside the allocated area.

It could be an exercise for the viewer :P

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
@zero01101
Copy link
Owner

aaaaaaaaaaaaaaaaaaaaaaahahahahahahahahahahaha it IS exactly what i was thinking it was lmao

literally my first response to expanding the canvas: this is so so so so so good, like i swear to god i tried to do exactly this and ... yeah

@zero01101
Copy link
Owner

zero01101 commented Dec 17, 2022

very very obviously i haven't put any real time into playing with it yet but my god it's perfect

i <3 black magic

[edit]

huh ok well i swear there was an instance in which outpainting wasn't working at all but now i can't reproduce it

[more edit]

🤦 well seems that was because i had runway's non inpainting 1.5 model loaded

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
@seijihariki
Copy link
Collaborator Author

Will be pushing some fixes for tools as I find issues.

A quick demo:

Peek.2022-12-17.01-03.mp4

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
@zero01101
Copy link
Owner

zero01101 commented Dec 17, 2022

alright so after i realized i was using a NOT inpainting model, things started working much better thank you and this is genuinely black magic as you said but i think it may have a bit too much eye of newt regarding saving images ;)

test big wide image via expand left by 2560px:
image

what save canvas gave me:
2022-12-17 04 31 17 openOutpaint image

yes i use the step-by-step params as a "test suite" lol :P

@seijihariki
Copy link
Collaborator Author

Is this after the last commits done to the branch? I can give it a look.

@zero01101
Copy link
Owner

zero01101 commented Dec 17, 2022

[edit] yep, happening on fc7302f

ohh, interesting, i hadn't given it much of a thorough poke around or anything; just tried it again though and made THREE whole images on it and oh hey guess what

image

but export gives me

image

[more edit]

lol please don't think this is some kind of OMG EMERGENCY BUGFIX thing, i'm about to go to bed but seriously this really is black magic and i love it

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
@seijihariki
Copy link
Collaborator Author

Fixed

@zero01101
Copy link
Owner

zero01101 commented Dec 17, 2022

lmao what

image

confirmed fixed and i'm sorry you had to see this lol

image

@seijihariki
Copy link
Collaborator Author

seijihariki commented Dec 17, 2022

I'm going to bed as well, actually. Good night!

@seijihariki
Copy link
Collaborator Author

lmao what

image

Haha, I mean, I've fixed so many of these tiny fixed-coordinate related bugs while implementing this that it became second nature to me to fix these.

Also, that is a great example of the 0,0 coordinate not meaning anything anymore. It previously represented the top-leftmost point in the canvas. Now it's just a random point inside it. (-context.origin.x, -context.origin.y) is now the top-leftmost point. Could use layer.origin or collection.origin instead (imageCollection for the main image collection).

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
@seijihariki seijihariki marked this pull request as ready for review December 18, 2022 22:26
Copy link
Owner

@zero01101 zero01101 left a comment

Choose a reason for hiding this comment

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

oh very absolutely yes, 100% all about the black magic

Comment on lines +13 to +16
/**
* Represents a size
*/
class Size {
Copy link
Owner

Choose a reason for hiding this comment

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

love it

Comment on lines +318 to +321
let minx = Infinity;
let maxx = -Infinity;
let miny = Infinity;
let maxy = -Infinity;
Copy link
Owner

Choose a reason for hiding this comment

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

yeah negative infinity is one of those things i have trouble even conceptualizing lmao

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.

None yet

2 participants