-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Control of trns chunk #1629
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
Open
mastrodaro
wants to merge
2
commits into
Automattic:master
Choose a base branch
from
mastrodaro:control-of-trns-chunk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Control of trns chunk #1629
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding an export settings, what do you think of reusing the existing
alpha
setting from the canvas context attributes, e.g.:We currently automatically switch to RGB24 if
alpha
isfalse
:node-canvas/src/CanvasRenderingContext2d.cc
Lines 711 to 714 in bf5126b
but we don't have to do that since RGB16_565 and RGB30 also have no alpha channel (i.e.
{pixelFormat: "RGB30", alpha: false}
is valid).What do you think of that API? If you're okay with it, then the lines I quoted above just need to change to this:
and one or two places in this PR need to be updated to (1) store the
alpha
property value and (2) use it during encoding.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my primary idea but after I saw this format selection algorithm I though it was too risky to modify the relation of RGB24 and alpha. I will try to reuse alpha from context creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I dont know how to read value that is set in backend (Imagebackend) [at Context2d CanvasRenderingContext2d.cc] to use used in PNG.h
there is somehow generated cairo_image_surface_get_format and I would like to achieve something like cairo_image_surface_get_alpha after I set alpha in backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to add a new member to the Context2d or Canvas class that stores whether or not alpha is in use (add to CanvasRenderingContext2d.h or Canvas.h). If you don't do that, then I don't think there's a way for us to know if, say, an A8 image palette has transparency or not.
To use that value when encoding, you could add a property to the
PngClosure
struct (in closure.h) likebool alpha
, and set it on the closure when setting up the PNG encoding task (everywhere you seeparsePNGArgs
used in Canvas.cc). That closure is passed in to the PNG encoder.(Sorry for the slow reply, will try to respond faster so we can land this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will try this hopefully tomorrow - last time I had problems to retrieve back data I set on backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My changes so far:
same as with format I added
alpha
Not sure if needed but also added (similar to format) in header file:
Not sure what should be default for
alpha
in construct - probably true to do not introduce breaking changes.ImageBackend.h:
So further I added (similar to format) in ImageBackend:
and also getter.
In result I was not able to fetch alpha in PNG.h similar as its done with format
cairo_format_t format = cairo_image_surface_get_format(surface);
And I assume I should fetch it from
surface
somehow.p.s. what exactly is closure, isnt it the params I pass to the
canvas.createPNGStream
? Then I am trying to move alpha I introduced in this object to the construct of attributes in callcanvas.getContext
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can omit these. They're used for adding getters that are accessible from JS. Adding them would mean adding non-standard features, which we try to avoid.
This shouldn't matter as long as you're setting
alpha
in all code paths (i.e. for allpixelFormat
s) inGetContext
.I would:
bool alpha
toPngClosure
in closure.hparsePNGArgs
in use currently, likeclosure.alpha = canvas->backend()->alpha
.closure->closure->alpha
.(Untested, but roughly that...)
It's not a great name, especially since we have
closure->closure
in some places (and they're two different structs/classes!). It's just a struct of data that we define (in closure.h) that libpng passes around through all of its APIs for us, allowing us to have access to whatever data we need.