[ 
https://issues.apache.org/jira/browse/PDFBOX-1915?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14011877#comment-14011877
 ] 

Shaola Ren commented on PDFBOX-1915:
------------------------------------

those are old stuffs, hopefully there are useful for someone

got correct contour of shading type 6 image

the code are available at https://bitbucket.org/xinshu/pdfbox.git

for webview https://bitbucket.org/xinshu/pdfbox

related files are in file shading6ContourTest.rar

This is stuff edited from the emails from me and Tilman, I am sorry that I 
didn't post my questions on Jira 

earlier, hopefully these emails don't have any thing that is not suitable to be 
published publicly, if there are 

such issues, Tilman Please, Feel free to delete or edit them. I am sorry for 
this unconvenience.

>From Shaola to Tilman

Hi Tilman,

Now, I can get correct shape of an image of shading type 6, this is the item 1 
of my last email. The result of the 

two test files are attached, you will see each patch has a solid color, that's 
because I still didn't work on color 

calculation, I just gave each point inside a patch the same color. Generally, 
to accomplish this task(the shape), I 

need to consider 3 cases which I drew in patchCase.jpg labeled with 1, 2, 3. 
For case 1 and 2, each of them can 

have another 3 subcases which I labeled them with "1,2 could be" at the bottom 
of patchCase.jpg. The two test files 

only involve cases 1 and 2, the 3rd case is more complex, I need to split one 
patch into 2 quasi-triangle patch. 

Now the code does not work for case 3.

The color of a patch is not calculated yet, which is the item 2 of my last 
email.

The progress is a little bit slower than I thought, there are many unexpected 
issues. I think I need to follow plan 

B in my proposal.


>From Tilman to Shaola

Hi Shaola,

Don't panic. IMHO you're doing pretty good. Don't forget that you just started 
a week ago.


>From Tilman to Shaola

Hello Shaola,

Look what I found:
https://www.google.ca/patents/US6552725

HOWEVER the bad news is that most likely you can't use that solution because it 
is patented. Apache is a US based 

corporation and software patents are valid there.

I uploaded more examples in JIRA. Only one of them deals with coons patches.

Tilman

>From Shaola to Tilman

Hello Tilman,

Thanks, the attachment is the contour results of several test files, for 
coons26.pdf, the result is weird.

The two new test cases have true hasFunction parameter, they helped me to 
adjust my reading method to deal with 

this case. I noticed that in the GouraudShadingContext.java, this issue in the 
method readVertex is not taken into 

account, although in the getRaster(), this case is considered, but I think it 
will generate a null pointer 

exception when it reads an image of shading type 4 or 5 with a true hasFunction 
parameter, I didn't test this yet.

For other issues, with time I think they should be worked out in a way.

>From Tilman to Shaola
Hi Shaola,

I believe this is a misunderstanding because the arrangement of the values is 
different for type 6 than type 4/5. 

See this part of the spec for type 5 on page 324:

    If this entry is present, the color data for each vertex must be specified 
by a single parametric variable 

rather than by n separate color components.
    ...
    The data stream provides a sequence of Bézier control points and color 
values that define the shape and colors 

of each patch. All of a patch’s control points are given first, followed by the 
color values for its corners. Note 

that this differs from a triangle mesh (shading types 4 and 5), in which the 
coordinates and color of each vertex 

are given together.


So function = true means that there will be one value. You can handle this as 
if you had a grayscale image, which 

also means that there is 1 color value.

Re sequence: you first interpolate to get the value of a point, then you feed 
that value to the function, which 

will return a Color array. That one you then convert to RGB as in the existing 
code. In other words, you don't have 

to bother much about the function thing.

Attached: two examples of coons patches without a function. One RGB and one 
gray.

Hi Shaola,

No, the amount of color values goes like this, if I've understood it correctly:

hasFunction = true  ==> 1 value

hasFunction = false: depends of colorspace

gray => 1 value
rgb => 3 values
cmyk => 4 values
other color spaces... who knows.

Attached you see a coons patch with two color values ("duotone", this is a 
weird mix of red and black that I took 

from a ps file of Prof. Bill Casselman) and one with 4 (cmyk).

However I suspect that you did indeed find a bug in my software, i.e. 
numberofcolorcomponents should be 1 if 

function. Oops. I will research this now that I'm getting better in postscript 
and create a Gouraud shading with 

function.

Tilman

>From Shaola to Tilman,

Hello Tilman,

I know, the description for has function in shading type 5 and 6 is similar, 
see file PDF3200_2008.pdf page 198, 

the top paragraph. I just suspected that part, now I see the difference, the 
null pointer exception happened in my 

code is because for type 6 I need to read at least 2 color values, but there is 
only 1 color value when hasFunction 

is true, for type 5, there is only 1 color value after each vertex no matter 
hasFunction is true or false. Thanks.

With the new test files you attached, I think I can put the 
evalFunction(values) away without worry it at least 

now.

I just checked your update in jira PDFBOX-1915, I downloaded the new files. 
Thanks for reminding me, I received the 

update emails in dev list mail, there are some others, so I didn't pay 
attention to this specific one.

Best,
Shaola

Hello Tilman,

I am sorry that I bothered you too much today, now I can get the right data 
sequence with hasFunction = true. The 

folded image's contour can be got right, as this is just the contour, the 
folded line is not showed up which is as 

expected not an error. I attached the result. This test file has a non-zero 
edgeflag, at least now it can prove 

that the read of data stream and management of non-zero edgeflag case are 
correct.

I updated my web repository, there is too much redundant code as this is still 
in process.

Best,
Shaola

Yes, there is some trick, however for the shading type 6, it seems I just got 
it right with you hint, but not 

exactly as you said. Sometimes, even a not that right answer is helpful, thanks.

> Implement shading with Coons and tensor-product patch meshes
> ------------------------------------------------------------
>
>                 Key: PDFBOX-1915
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-1915
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: Rendering
>    Affects Versions: 2.0.0
>            Reporter: Tilman Hausherr
>              Labels: graphical, gsoc2014, java, math, shading
>         Attachments: CONICAL.pdf, GWG060_Shading_x1a.pdf, HSBWHEEL.pdf, 
> McAfee-ShadingType7.pdf, TENSOR.pdf, XYZsweep.pdf, 
> asy-coons-but-really-tensor.pdf, asy-tensor-rainbow.pdf, asy-tensor.pdf, 
> coons-function.pdf, coons-function.ps, coons-nofunction-CMYK.pdf, 
> coons-nofunction-CMYK.ps, coons-nofunction-Duotone.pdf, 
> coons-nofunction-Duotone.ps, coons-nofunction-Gray.pdf, 
> coons-nofunction-Gray.ps, coons-nofunction-RGB.pdf, coons-nofunction-RGB.ps, 
> coons2-function.pdf, coons2-function.ps, 
> eci_altona-test-suite-v2_technical_H.pdf, lamp_cairo.pdf
>
>
> 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)



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to