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