Title: Add support for pre-multiplied alpha · Issue #3391 · processing/processing · GitHub
Open Graph Title: Add support for pre-multiplied alpha · Issue #3391 · processing/processing
X Title: Add support for pre-multiplied alpha · Issue #3391 · processing/processing
Description: At the bottom of this pull request (#2601) @benfry mentioned opening an issue about implementing pre-multiplied alpha, which I don't think was ever done? I certainly dropped the ball on following up. It would be great if an official imag...
Open Graph Description: At the bottom of this pull request (#2601) @benfry mentioned opening an issue about implementing pre-multiplied alpha, which I don't think was ever done? I certainly dropped the ball on following u...
X Description: At the bottom of this pull request (#2601) @benfry mentioned opening an issue about implementing pre-multiplied alpha, which I don't think was ever done? I certainly dropped the ball on followi...
Opengraph URL: https://github.com/processing/processing/issues/3391
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add support for pre-multiplied alpha","articleBody":"At the bottom of this pull request (https://github.com/processing/processing/pull/2601) @benfry mentioned opening an issue about implementing pre-multiplied alpha, which I don't think was ever done? I certainly dropped the ball on following up. It would be great if an official image mode for this was added (I'm currently sub-classing the GL renderer to achieve this). Otherwise multiple layering (as well as convolution, etc) don't work correctly.\n\nFor reference, a long and admittedly opinionated extract of an email sent to @JakubValtar last year with a suggestion for handling this internally in the OpenGL renderer - feel free to TL;DR, although the NVIDIA link is worth a read.\n\n---\n\nOK, you asked me how Processing might use pre-multiplied alpha without\nbreaking the API. So to start, a possibly controversial statement -\nblending in Processing is completely broken. It was one of the\nreasons I stopped using Processing the first time around (~2006) - I\nlike the API but in my opinion there are some issues with the\nimplementation. Praxis LIVE v1 deliberately made use of aspects of\nthe Processing API, but re-implemented on top of a custom software and\nOpenGL renderer. Fast forward to a year ago, and I decided to stop\ntrying to re-implement the API - the new Processing OpenGL is too good\nto miss! So Praxis LIVE v2 now embeds Processing as a library -\nhowever, there's no way I'm breaking blending in the process - luckily\nit isn't that difficult to work around.\n\nThere are many sources around about pre-multipled alpha. I found this\npage recently looking into GL blend modes\n(http://www.slideshare.net/Mark_Kilgard/blend-modes-for-opengl) - it's\nabout the new NVIDIA blend mode extensions - note that slide 16 talks\nabout the fact that blend modes assume pre-multiplied alpha. It\nmentions one of the key issues (one that affects me) - drawing into\nsurfaces with alpha channels - sometimes you can get away with it if\nthe destination is opaque. He also mentions the Porter-Duff model and\nhow it relies on pre-multiplied alpha - interesting that the default\nblending in the Java2D renderer works fine - because the JRE\nAlphaComposite pre-multiplies, blends and un-premultiplies.\n\nIncidentally, that slide also touches on another issue -\npre-multiplied alpha is necessary for performing various filtering\neffects (eg. blur) on surfaces with alpha. I haven't looked at the\nPImage filters but I imagine there might be an issue there (note the\nConvolveOp in the JRE multiplies, filters and unmultiplies).\n\nNow, all that multiplying and unmultiplying is a bit pointless! ;-)\nNot to mention it's not easily achievable with OpenGL. So, how to use\npre-multiplied alpha without changing the API?\n\nThe important thing in my opinion is separating the external format of\nimages to the format they're stored internally. Take managed images\nin the Java2D backend - cached textures are not stored in the format\nof the BufferedImage, but the optimum format for rendering. Just\nbecause the format to the user is un-premultiplied ARGB doesn't mean\nthat the underlying storage has to be. Processing could easily switch\nto storing the underlying pixel data, in all modes, as pre-multiplied.\nOr, simpler, though not fixing issues elsewhere, it could just store\npre-multiplied data in the OpenGL textures.\n\nThe key things to handle are times when the user is setting colours,\ntimes when the user is retrieving colours, and access to the pixel\narray.\n\nProcessing already does colour calculations to match a colour format\nset by the user and convert into internal data. What I've done in\nPraxis LIVE's PGraphics sub-class is override the various colorCalc()\nmethods to multiply in the alpha. That's pretty much all that I'm\nusing right now, but then I don't have 100% API coverage! It would be\npossible to handle multiply and unpremultiply fairly easily in set()\nand get(), which leaves the pixel array - I'd suggest running a\nun-premultiply \u003c\u003e premultiply during loadPixels() and updatePixels(),\nwith an extra hint to leave it premultiplied and save any hit (of\ncourse RGB images wouldn't have any anyway).\n\nI'm not quite sure if there would be any implications to PShape that\nwould need looking at - I guess I'll find out when I come to\nintegrating support for them! ;-)\n\nThe one aspect of the API that would change would be GLSL - mind you\nI'd assert that's fixing it rather than breaking it - however, it's\nthe one place that might affect the behaviour of user code.\n\nIncidentally, if it's of interest - some alternate software blend\nmodes that I and another person on the Java Gaming forum worked on a\nfew years back - all using pre-multiplied alpha, obviously -\nhttp://www.java-gaming.org/topics/some-new-blendmodes-add-multiply-overlay-etc/24529/view.html\n","author":{"url":"https://github.com/neilcsmith-net","@type":"Person","name":"neilcsmith-net"},"datePublished":"2015-06-16T16:45:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/3391/processing/issues/3391"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d12684f6-5908-4692-9639-c66384356e76 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8446:3EC154:3AAB732:4E70425:696F1F8C |
| html-safe-nonce | 567bfeb9502543e5d1a3ba05fb0c28380214eee8dbecb9a8215a6d49b4463b82 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDQ2OjNFQzE1NDozQUFCNzMyOjRFNzA0MjU6Njk2RjFGOEMiLCJ2aXNpdG9yX2lkIjoiNTg1NjAyMjc4MTI1NzI2MDk0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | daf3e94f9b69500e6f54288459f5044090ac65cb2108da4b25eba3a6e65beedb |
| hovercard-subject-tag | issue:88780027 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/processing/processing/3391/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0fe16a35c3c33f20fec5f8677d8003bf7fb5d3e284e9773d10b79f3bbfb960ce/processing/processing/issues/3391 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0fe16a35c3c33f20fec5f8677d8003bf7fb5d3e284e9773d10b79f3bbfb960ce/processing/processing/issues/3391 |
| og:image:alt | At the bottom of this pull request (#2601) @benfry mentioned opening an issue about implementing pre-multiplied alpha, which I don't think was ever done? I certainly dropped the ball on following u... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | neilcsmith-net |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/processing/processing git https://github.com/processing/processing.git |
| octolytics-dimension-user_id | 1617169 |
| octolytics-dimension-user_login | processing |
| octolytics-dimension-repository_id | 7807399 |
| octolytics-dimension-repository_nwo | processing/processing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7807399 |
| octolytics-dimension-repository_network_root_nwo | processing/processing |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width