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

Petr Slaby commented on PDFBOX-2117:
------------------------------------

{quote}
How much slower?
{quote}
E.g. with the attached  000001_MTEXT_CS6.pdf which has an axial shading using 
PDDeviceCMYK, the time spent in AxialShading#getRaster() increases from ~0.5s 
to ~8.2s. I have other examples with axial shading using PDDeviceRGB, these are 
faster. ~7.2s drops to ~2.1s on three pdf pages rendered in them. But this is 
expected as PDDeviceRGB does nothing in getRGBImage() while it does a 
calculation through sRGB in getRGB(). If I skip the call of getRGB() in the 
case of PDDeviceRGB shading, the total time on this three files drops to 0.6s. 
For the moment, this seems to be the best solution to me.

{quote}
 In your patch you can just return rgbImage.getRaster() because getColorModel() 
always returns sRGB.
{quote}
Not always. The buffered image returned from PDColorSpace#toRGBImageAWT() uses 
DirectColorModel while the one returned from PDDeviceRGB uses 
ComponentColorModel.  Then value returned from 
AxialShadingContext#getColorModel() would need to be adjusted accordingly or 
the conversion needs to be done if the color model does not match. I was not 
sure about that. 

I think the usage of getRGBImage might be slower here because of the overhead 
of ColorConvertOp or the overhead of conversion via a buffered image in 
general. The method AxialShadingContext#getRaster() is called from AWT code 
when filling an area. It is called many times, usually to produce a one pixel 
high raster. I assume that, unless the fill area is a rectangle, AWT uses a 
scan line on the area being filled and requests a fill raster for each single 
line part it finds.



> AxialShadingContext is slow
> ---------------------------
>
>                 Key: PDFBOX-2117
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2117
>             Project: PDFBox
>          Issue Type: Improvement
>            Reporter: Petr Slaby
>         Attachments: 000001_MTEXT_CS6.pdf, AxialShading.patch, 
> AxialShading1.patch, AxialShadingContext.java.getrgbimage, 
> Shading2Function2text.pdf, asy-shade.pdf, color_gradient.pdf, 
> shading_pattern.pdf
>
>
> AxialShadingContext#getRaster() is on top of profiler hot spots in documents 
> that use an axial shading. Inside it, the slowest part is calling 
> PDColorSpaceRGB#toRGB() and PDFunctionType3#eval() (in this order).
>   



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

Reply via email to