12 Replies Latest reply: Jun 20, 2014 7:01 AM by lrosenth RSS

    How to do multi-stage blending

    JPT78151361 Community Member

      I want to do the following blending operation in RGB space:

       

      Within the transparency group (I'm using a Form XObject), the resulting colour is the source colour (i.e. no blending).  The resulting alpha is the source alpha.

       

      Then I want to blend this form with the page using the standard transparency formula: C_r = (1-a_s)*C_b + a_s*C_s.

       

      For instance, If I draw a solid black circle with alpha 1 and then two thin lines over it (one horizontal and the other vertical), both with alpha 0, I should end up with 4 quadrants.  I can then place this group onto the page so that the 4 quadrants are drawn in black on the page and the space where the lines were drawn are transparent, so that the original page contents can be seen through it.

       

      Is this possible in PDF, or do I need to combine the objects into a complex polygon?  In my application, alpha is always 0 or 1. Section 7.2.6 of PDF version 1.5, fourth edition, seem to suggest that this is not possible (due to the Union function used to calculate the resulting alpha).

        • 1. Re: How to do multi-stage blending
          lrosenth Adobe Employee

          You are correct that because of the use of a Union, what you want to accomplish will require that you "segment" your object.  This is because you are thinking about transparency as a simple "bitmap" - but that's not the model used by modern graphic systems.

          • 2. Re: How to do multi-stage blending
            JPT78151361 Community Member

            Thank you for the confirmation.

             

            Does the model used by modern graphic systems support some other method of vectorised erase?

             

            Just out of pure curiosity: how does the reader / printer implement transparency groups without some sort of intermediary bitmapped buffer?

             

            On OpenGL I would antialiase in the fragment shader, use the depth buffer to avoid artifacts on the edges and use a frame buffer object to implement transparency groups.

            • 3. Re: How to do multi-stage blending
              Test Screen Name CommunityMVP

              An implementation is not mandated to use bitmap buffering at any point. It can implement other ways. There is no way to erase in the object model, a deliberate omission to allow flexibility of implementation.

               

              If thinking PDF must be passed through a bitmap buffer your view is (understandably) narrow. PDFs are not always rendered to a bitmap as their final result. For example they might be converted to another graphics format, where retaining as much vector information as possible is desirable.

              • 4. Re: How to do multi-stage blending
                JPT78151361 Community Member

                Ah - this makes sence.  Thank you.

                • 5. Re: How to do multi-stage blending
                  lrosenth Adobe Employee

                  What you can do to "erase" is clip.  (obviously it's not really erasing but hiding), but has the same visual.

                  • 6. Re: How to do multi-stage blending
                    JPT78151361 Community Member

                    I'll investigate...

                     

                    If I understand clipping correctly, you set up a clipping shape / object,

                    and then draw over it.  The object you're drawing will then be clipped by

                    the clipping mask.  Do I understand correctly?

                     

                    I'm writing a gerber to pdf converter.  They have an object called an

                    aperture, which can be drawn by a series of draw / erase cycles.  The order

                    matters, 'cause you can't erase what hasn't been drawn yet, and you can

                    draw over a previously erased portion.

                     

                    If you want a ring with a cross over it, you draw a big circle, erase a

                    smaller circle, and then draw the two lines.

                     

                    After creating this aperture you can draw the result onto the

                    artwork-in-progress either positive (draw as is) or negative (erase / make

                    a hole).  The latter I implement as drawing in white, but I cannot use that

                    trick for the apertures.

                    • 7. Re: How to do multi-stage blending
                      lrosenth Adobe Employee

                      You set up a clipping path and then whatever you draw after clipped to the shape of that path.  The clipping path can be defined by either other paths or text shapes.  This is a "hard" clip/mask operation, in that things are either IN or OUT (on/off).  If you want to get fancy, you can use a transparency mask (called a SoftMask) where things can be partially in/out.

                       

                      This aperture definitely appears to assume a raster-based output where you can erase.  (consider a printer where such a thing is impossible).  Since they assume a raster anyway, I would probably consider rasterizing it yourself and then putting the raster results into the PDF.  Obviously you lose resolution independence but not sure how important that is.   The alternative would be to do path based operations to compute the final path(s) to be rendered and then put that into the PDF.  You can use some of the well know "polygon clipping" solutions for such a task.

                       

                      Drawing in white is a bad idea since it assumes that the final output will be drawn on a white background - which isn't always the case.  PDF assumes a transparent (or really, nothing drawn) background so if you were to use white - you'd get white and not "nothing".

                      • 8. Re: How to do multi-stage blending
                        JPT78151361 Community Member

                        I want to avoid rasterising because I want to end up with a nice and neat

                        PDF that I can embed in a LaTeX document.  For any practical PCB (printed

                        circuit board), the Gerber is rasterised to at least 1200 dpi (often 2400

                        dpi) in order to obtain adequate resolution on small features.  For a PCB

                        that is A4 in size, that is quite a large picture, even after PNG

                        compression.

                         

                        I could of course rasterise only the apertures (which are generally small

                        compared to the PCB), but I prefer a more elegant solution.

                         

                        I like the clipping idea.  I can draw the aperture primitives front to

                        back: augment the clipping structure for "clear" primitives and draw the

                        "dark" primitives using this structure.  If I cannot augment clipping

                        structures on the fly, I can always generate multiple clipping structures

                        and use the correct one for each "dark" stage.

                         

                        For the moment, I can live with drawing in white because I'll generally

                        print the PDF onto a white background.  Even when printing to a

                        transparency, the printer assumes a white page and will only deposit black

                        ink where I want it.  It would be nice to render the different copper

                        layers as different coloured transparent layers on top of each other, in

                        which case I would need to generate proper holes, but this would be a

                        future feature of my converter...

                        • 9. Re: How to do multi-stage blending
                          JPT78151361 Community Member

                          Clipping paths work perfectly -- thank you.

                          • 10. Re: How to do multi-stage blending
                            lrosenth Adobe Employee

                            My pleasure - glad to hear it's working!

                            • 11. Re: How to do multi-stage blending
                              JPT78151361 Community Member

                              Just for interest sake: my output PDF can be found at https://drive.google.com/file/d/0Bzxt3kuNPaEccU8wSlkzQVpJWW8/edit?usp=sharing

                               

                              The aperture in question is object 11, line 170.  As well as objects 12 and 13, but they are simply modifications of the same aperture (I left the apertures uncompressed for easy debugging).

                               

                              The Gerber draws a large circle and then erases a smaller circle and two lines.

                              • 12. Re: How to do multi-stage blending
                                lrosenth Adobe Employee

                                Looks great!