Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-1915

Implement shading with Coons and tensor-product patch meshes

    Details

      Description

      Of the seven shading methods described in the PDF specification, type 6 (Coons patch meshes) and type 7 (Tensor-product patch meshes) haven't been implemented. I have done type 1, 4 and 5, but I don't know the math for type 6 and 7. My math days are decades away.

      Knowledge prerequisites:

      • java, although you don't have to be a java ace, just feel confortable
      • math: you should know what "cubic Bézier curves", "Degenerate Bézier curves", "bilinear interpolation", "tensor-product", "affine transform matrix" and "Bernstein polynomials" are, or be able to learn it
      • maven (basic)
      • svn (basic)
      • an IDE like Netbeans or Eclipse or IntelliJ (basic)
      • ideally, you are either a math student who likes to program, or a computer science student who is specializing in graphics.

      A first look at PDFBOX: try the command utility here:
      https://pdfbox.apache.org/commandline/#pdfToImage
      and use your favorite PDF, or the PDFs mentioned in PDFBOX-615, these have the shading types that are already implemented.

      Some simple source code to convert to images:

      String filename = "blah.pdf";
      PDDocument document = PDDocument.loadNonSeq(new File(filename), null);
      List<PDPage> pdPages = document.getDocumentCatalog().getAllPages();
      int page = 0;
      for (PDPage pdPage : pdPages)
      {
      ++page;
      BufferedImage bim = RenderUtil.convertToImage(pdPage, BufferedImage.TYPE_BYTE_BINARY, 300);
      ImageIO.write(bim, "png", new File(filename+page+".png"));
      }
      document.close();

      You are not starting from scratch. The implementation of type 4 and 5 shows you how to read parameters from the PDF and set the graphics. You don't have to learn the complete PDF spec, only 15 pages related to the two shading types, and 6 pages about shading in general. The PDF specification is here:
      http://www.adobe.com/devnet/pdf/pdf_reference.html

      The tricky parts are:

      • decide whether a point(x,y) is inside or outside a patch
      • decide the color of a point within the patch

      To get an idea about the code, look at the classes GouraudTriangle, GouraudShadingContext, Type4ShadingContext and Vertex here
      https://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/
      or download the whole project from the repository.
      https://pdfbox.apache.org/downloads.html#scm
      If you want to see the existing code in the debugger with a Gouraud shading, try this file:
      http://asymptote.sourceforge.net/gallery/Gouraud.pdf

      Testing:
      I have attached several example PDFs. To see which one has which shading, open them with an editor like NOTEPAD++, and search for "/ShadingType" (without the quotes). If your images are rendering like the example PDFs, then you were successful.

      Optional:
      Review and optimize the complete shading package for speed; implement cubic spline interpolation for type 0 (sampled) functions (that one is really low-low priority, see details by looking up "cubic spline interpolation" in the PDF spec, which tells that it is disregarded in printing, and I don't have a test PDF).

      Mentor: Tilman Hausherr (European timezone, languages: german, english, french)

        Attachments

        1. asy-tensor.pdf
          15 kB
          Tilman Hausherr
        2. asy-coons-but-really-tensor.pdf
          12 kB
          Tilman Hausherr
        3. lamp_cairo.pdf
          37 kB
          Tilman Hausherr
        4. XYZsweep.pdf
          5 kB
          Tilman Hausherr
        5. TENSOR.pdf
          5 kB
          Tilman Hausherr
        6. HSBWHEEL.pdf
          3 kB
          Tilman Hausherr
        7. CONICAL.pdf
          3 kB
          Tilman Hausherr
        8. McAfee-ShadingType7.pdf
          621 kB
          Tilman Hausherr
        9. asy-tensor-rainbow.pdf
          12 kB
          Tilman Hausherr
        10. eci_altona-test-suite-v2_technical_H.pdf
          3.62 MB
          Tilman Hausherr
        11. GWG060_Shading_x1a.pdf
          1.27 MB
          Tilman Hausherr
        12. coons2-function.pdf
          3 kB
          Tilman Hausherr
        13. coons2-function.ps
          0.7 kB
          Tilman Hausherr
        14. coons-function.pdf
          3 kB
          Tilman Hausherr
        15. coons-function.ps
          0.6 kB
          Tilman Hausherr
        16. coons-nofunction-CMYK.pdf
          3 kB
          Tilman Hausherr
        17. coons-nofunction-CMYK.ps
          0.5 kB
          Tilman Hausherr
        18. coons-nofunction-Duotone.pdf
          3 kB
          Tilman Hausherr
        19. coons-nofunction-Duotone.ps
          1 kB
          Tilman Hausherr
        20. coons-nofunction-Gray.pdf
          3 kB
          Tilman Hausherr
        21. coons-nofunction-Gray.ps
          0.4 kB
          Tilman Hausherr
        22. coons-nofunction-RGB.pdf
          3 kB
          Tilman Hausherr
        23. coons-nofunction-RGB.ps
          0.4 kB
          Tilman Hausherr
        24. Shadingtype6week1.pdf
          530 kB
          Shaola Ren
        25. shading6ContourTest.rar
          30 kB
          Shaola Ren
        26. patchCases.jpg
          43 kB
          Shaola Ren
        27. patchMap.jpg
          44 kB
          Shaola Ren
        28. updateshading6ContourTest.rar
          5 kB
          Shaola Ren
        29. shading6Done.rar
          847 kB
          Shaola Ren
        30. pass4FlagTest.rar
          36 kB
          Shaola Ren
        31. coons4-function.ps
          1 kB
          Tilman Hausherr
        32. tensor-nofunction-RGB.pdf
          3 kB
          Tilman Hausherr
        33. tensor-nofunction-RGB.ps
          0.5 kB
          Tilman Hausherr
        34. shading7.rar
          1.37 MB
          Shaola Ren
        35. tensor-nofunction-RGB_1.png
          79 kB
          Shaola Ren
        36. tensor4-nofunction.pdf
          3 kB
          Tilman Hausherr
        37. tensor4-nofunction.ps
          1 kB
          Tilman Hausherr
        38. _gwg060_shading_x1a.pdf-1.png
          133 kB
          Tilman Hausherr
        39. _mcafee-shadingtype7.pdf-1.png
          198 kB
          Tilman Hausherr
        40. lamp_cairo7_0.png
          36 kB
          Shaola Ren
        41. lamp_cairo7_1.png
          42 kB
          Shaola Ren
        42. lamp_cairo7_1.png
          42 kB
          Shaola Ren
        43. tensor4-nofunction_1.png
          68 kB
          Shaola Ren
        44. GWG060_Shading_x1a_1.png
          15 kB
          Shaola Ren
        45. failedTest.rar
          333 kB
          Shaola Ren
        46. mcafeeU5.pdf
          131 kB
          Tilman Hausherr
        47. mcafeeu5.pdf-1.png
          61 kB
          Tilman Hausherr
        48. lineRasterization.jpg
          45 kB
          Shaola Ren
        49. mcafeeU5_1.png
          6 kB
          Shaola Ren
        50. crestron-p9.pdf
          1.67 MB
          Tilman Hausherr
        51. CIB-coonsmesh.pdf
          7 kB
          Tilman Hausherr
        52. CIB-coons-vs-tensormesh.pdf
          8 kB
          Tilman Hausherr
        53. example_030.pdf
          28 kB
          Petr Slaby
        54. ch14.pdf
          774 kB
          Tilman Hausherr
        55. pattern-shading-2-4-idMatrix.pdf
          6 kB
          Tilman Hausherr
        56. DECAHED.pdf
          3 kB
          Tilman Hausherr
        57. TRITYP4.pdf
          3 kB
          Tilman Hausherr
        58. type45.pdf
          86 kB
          Shaola Ren
        59. LATTICE1.pdf
          3 kB
          Tilman Hausherr
        60. LATTICE2.pdf
          3 kB
          Tilman Hausherr
        61. axsh02.pdf
          3 kB
          Shaola Ren
        62. axsh02_1_withBBox.png
          13 kB
          Shaola Ren
        63. axsh02_1_withoutBBox.png
          13 kB
          Shaola Ren
        64. Kommunikationsbedingungen-Einlagen_FIDOR-Bank.pdf
          109 kB
          Tilman Hausherr
        65. Shading2Function2LargeDomain.pdf
          3 kB
          Tilman Hausherr
        66. Shading2Function2LargeDomain.pdf-1-bad.png
          10 kB
          Tilman Hausherr
        67. Shading2Function2LargeDomain.pdf-1-good.png
          8 kB
          Tilman Hausherr
        68. Shading2Function2LargeDomain.ps
          0.2 kB
          Tilman Hausherr
        69. eci_1-old.png
          68 kB
          Shaola Ren
        70. eci_1.png
          68 kB
          Shaola Ren

          Activity

            People

            • Assignee:
              xinshu Shaola Ren
              Reporter:
              tilman Tilman Hausherr
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: