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

Implement shading with Coons and tensor-product patch meshes

    XMLWordPrintableJSON

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: