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