RFR: 8012229: [lcms] Improve performance of color conversion for images with alpha channel

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

RFR: 8012229: [lcms] Improve performance of color conversion for images with alpha channel

Sergey Bylokhov-2
The lcms 2.8 version added support for the cmsFLAGS_COPY_ALPHA flag:
https://sourceforge.net/p/lcms/mailman/lcms-user/thread/001c01d1c0f3%2484a7cb30%248df76190%24%40ProDigitalSoftware.com/#msg35143398

which supports alpha channel transportation

For our usage, it means we can use TYPE_4BYTE_ABGR and TYPE_INT_ARGB directly as a source and destination.

Some numbers; converting new BufferedImage(3000, 3000, TYPE_INT_ARGB) from CS_sRGB to CS_CIEXYZ via op.filter(src, dst):
//before the fix
//Benchmark                  Mode  Cnt    Score    Error  Units
//ColorAlphaConv.testFilter  avgt    5  603,392 ± 12,932  ms/op

//after the fix
//Benchmark                  Mode  Cnt    Score   Error  Units
//ColorAlphaConv.testFilter  avgt    5  121,624 ± 0,906  ms/op

But still slower than kcms
//kcms jdk8u60
//Benchmark                  Mode  Cnt   Score   Error  Units
//ColorAlphaConv.testFilter  avgt    5  13,256 ± 0,169  ms/op

-------------

Commit messages:
 - Initial fix

Changes: https://git.openjdk.java.net/jdk/pull/3239/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3239&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8012229
  Stats: 208 lines in 5 files changed: 195 ins; 2 del; 11 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3239.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3239/head:pull/3239

PR: https://git.openjdk.java.net/jdk/pull/3239
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8012229: [lcms] Improve performance of color conversion for images with alpha channel

Sergey Bylokhov-2
On Mon, 29 Mar 2021 07:36:35 GMT, Sergey Bylokhov <[hidden email]> wrote:

> The lcms 2.8 version added support for the cmsFLAGS_COPY_ALPHA flag:
> https://sourceforge.net/p/lcms/mailman/lcms-user/thread/001c01d1c0f3%2484a7cb30%248df76190%24%40ProDigitalSoftware.com/#msg35143398
>
> which supports alpha channel transportation
>
> For our usage, it means we can use TYPE_4BYTE_ABGR and TYPE_INT_ARGB directly as a source and destination.
>
> Some numbers; converting new BufferedImage(3000, 3000, TYPE_INT_ARGB) from CS_sRGB to CS_CIEXYZ via op.filter(src, dst):
> //before the fix
> //Benchmark                  Mode  Cnt    Score    Error  Units
> //ColorAlphaConv.testFilter  avgt    5  603,392 ± 12,932  ms/op
>
> //after the fix
> //Benchmark                  Mode  Cnt    Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  121,624 ± 0,906  ms/op
>
> But still slower than kcms
> //kcms jdk8u60
> //Benchmark                  Mode  Cnt   Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  13,256 ± 0,169  ms/op

src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSTransform.java line 167:

> 165:         return dst.getColorModel().hasAlpha() == src.getColorModel().hasAlpha();
> 166:     }
> 167:

Thoughts about the method above:
 - I have left the first check as-is, so for any opaque destinations we will pass data to the lcms directly, but I am not sure that this is correct for source/destination with premultiplied alpha.
 - Since I am not sure about premultiplied alpha I have excluded it for the current fix if the destination has an alpha channel.

src/java.desktop/share/native/liblcms/LCMS.c line 193:

> 191:
> 192:     sTrans = cmsCreateMultiprofileTransform(iccArray, j,
> 193:         inFormatter, outFormatter, renderType, cmsFLAGS_COPY_ALPHA);

Does not affect performance if the image does not have alpha.

test/jdk/sun/java2d/cmm/ColorConvertOp/ColCvtAlphaDifferentSrcDst.java line 73:

> 71:         //opaqueDst(TYPE_INT_ARGB_PRE, TYPE_4BYTE_ABGR_PRE);
> 72:         //opaqueDst(TYPE_4BYTE_ABGR_PRE, TYPE_INT_BGR);
> 73:     }

Actually, according to the spec, we should transform pre-alpha to alpha -> then apply ICC transform -> then transform pre-alpha-> alpha.
See class description of the:
https://docs.oracle.com/javase/7/docs/api/java/awt/image/ColorConvertOp.html

But it looks like implementation does something different.

-------------

PR: https://git.openjdk.java.net/jdk/pull/3239
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8012229: [lcms] Improve performance of color conversion for images with alpha channel

Alexander Zvegintsev-2
In reply to this post by Sergey Bylokhov-2
On Mon, 29 Mar 2021 07:36:35 GMT, Sergey Bylokhov <[hidden email]> wrote:

> The lcms 2.8 version added support for the cmsFLAGS_COPY_ALPHA flag:
> https://sourceforge.net/p/lcms/mailman/lcms-user/thread/001c01d1c0f3%2484a7cb30%248df76190%24%40ProDigitalSoftware.com/#msg35143398
>
> which supports alpha channel transportation
>
> For our usage, it means we can use TYPE_4BYTE_ABGR and TYPE_INT_ARGB directly as a source and destination.
>
> Some numbers:
> converting new BufferedImage(3000, 3000, TYPE_INT_ARGB) from CS_sRGB to CS_CIEXYZ via op.filter(src, dst).
> //before the fix
> //Benchmark                  Mode  Cnt    Score    Error  Units
> //ColorAlphaConv.testFilter  avgt    5  603,392 ± 12,932  ms/op
>
> //after the fix
> //Benchmark                  Mode  Cnt    Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  121,624 ± 0,906  ms/op
>
> But still slower than kcms
> //kcms jdk8u60
> //Benchmark                  Mode  Cnt   Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  13,256 ± 0,169  ms/op

Marked as reviewed by azvegint (Reviewer).

test/jdk/sun/java2d/cmm/ColorConvertOp/ColCvtAlphaDifferentSrcDst.java line 52:

> 50:
> 51:     private static int WIDTH = 256;
> 52:     private static int HEIGHT = 256;

Basing on naming, it looks that you wanted to make these variable final.

-------------

PR: https://git.openjdk.java.net/jdk/pull/3239
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8012229: [lcms] Improve performance of color conversion for images with alpha channel [v2]

Sergey Bylokhov-2
In reply to this post by Sergey Bylokhov-2
> The lcms 2.8 version added support for the cmsFLAGS_COPY_ALPHA flag:
> https://sourceforge.net/p/lcms/mailman/lcms-user/thread/001c01d1c0f3%2484a7cb30%248df76190%24%40ProDigitalSoftware.com/#msg35143398
>
> which supports alpha channel transportation
>
> For our usage, it means we can use TYPE_4BYTE_ABGR and TYPE_INT_ARGB directly as a source and destination.
>
> Some numbers:
> converting new BufferedImage(3000, 3000, TYPE_INT_ARGB) from CS_sRGB to CS_CIEXYZ via op.filter(src, dst).
> //before the fix
> //Benchmark                  Mode  Cnt    Score    Error  Units
> //ColorAlphaConv.testFilter  avgt    5  603,392 ± 12,932  ms/op
>
> //after the fix
> //Benchmark                  Mode  Cnt    Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  121,624 ± 0,906  ms/op
>
> But still slower than kcms
> //kcms jdk8u60
> //Benchmark                  Mode  Cnt   Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  13,256 ± 0,169  ms/op

Sergey Bylokhov has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'master' into JDK-8012229
 - Update ColCvtAlphaDifferentSrcDst.java
 - Initial fix

-------------

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/3239/files
  - new: https://git.openjdk.java.net/jdk/pull/3239/files/c89a4ca1..60a3dfca

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=3239&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=3239&range=00-01

  Stats: 4586 lines in 234 files changed: 3018 ins; 664 del; 904 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3239.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3239/head:pull/3239

PR: https://git.openjdk.java.net/jdk/pull/3239
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8012229: [lcms] Improve performance of color conversion for images with alpha channel [v2]

Alexander Zvegintsev-2
On Wed, 31 Mar 2021 21:31:43 GMT, Sergey Bylokhov <[hidden email]> wrote:

>> The lcms 2.8 version added support for the cmsFLAGS_COPY_ALPHA flag:
>> https://sourceforge.net/p/lcms/mailman/lcms-user/thread/001c01d1c0f3%2484a7cb30%248df76190%24%40ProDigitalSoftware.com/#msg35143398
>>
>> which supports alpha channel transportation
>>
>> For our usage, it means we can use TYPE_4BYTE_ABGR and TYPE_INT_ARGB directly as a source and destination.
>>
>> Some numbers:
>> converting new BufferedImage(3000, 3000, TYPE_INT_ARGB) from CS_sRGB to CS_CIEXYZ via op.filter(src, dst).
>> //before the fix
>> //Benchmark                  Mode  Cnt    Score    Error  Units
>> //ColorAlphaConv.testFilter  avgt    5  603,392 ± 12,932  ms/op
>>
>> //after the fix
>> //Benchmark                  Mode  Cnt    Score   Error  Units
>> //ColorAlphaConv.testFilter  avgt    5  121,624 ± 0,906  ms/op
>>
>> But still slower than kcms
>> //kcms jdk8u60
>> //Benchmark                  Mode  Cnt   Score   Error  Units
>> //ColorAlphaConv.testFilter  avgt    5  13,256 ± 0,169  ms/op
>
> Sergey Bylokhov has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
>
>  - Merge branch 'master' into JDK-8012229
>  - Update ColCvtAlphaDifferentSrcDst.java
>  - Initial fix

Marked as reviewed by azvegint (Reviewer).

-------------

PR: https://git.openjdk.java.net/jdk/pull/3239
Reply | Threaded
Open this post in threaded view
|

Integrated: 8012229: [lcms] Improve performance of color conversion for images with alpha channel

Sergey Bylokhov-2
In reply to this post by Sergey Bylokhov-2
On Mon, 29 Mar 2021 07:36:35 GMT, Sergey Bylokhov <[hidden email]> wrote:

> The lcms 2.8 version added support for the cmsFLAGS_COPY_ALPHA flag:
> https://sourceforge.net/p/lcms/mailman/lcms-user/thread/001c01d1c0f3%2484a7cb30%248df76190%24%40ProDigitalSoftware.com/#msg35143398
>
> which supports alpha channel transportation
>
> For our usage, it means we can use TYPE_4BYTE_ABGR and TYPE_INT_ARGB directly as a source and destination.
>
> Some numbers:
> converting new BufferedImage(3000, 3000, TYPE_INT_ARGB) from CS_sRGB to CS_CIEXYZ via op.filter(src, dst).
> //before the fix
> //Benchmark                  Mode  Cnt    Score    Error  Units
> //ColorAlphaConv.testFilter  avgt    5  603,392 ± 12,932  ms/op
>
> //after the fix
> //Benchmark                  Mode  Cnt    Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  121,624 ± 0,906  ms/op
>
> But still slower than kcms
> //kcms jdk8u60
> //Benchmark                  Mode  Cnt   Score   Error  Units
> //ColorAlphaConv.testFilter  avgt    5  13,256 ± 0,169  ms/op

This pull request has now been integrated.

Changeset: 16acfafb
Author:    Sergey Bylokhov <[hidden email]>
URL:       https://git.openjdk.java.net/jdk/commit/16acfafb
Stats:     208 lines in 5 files changed: 195 ins; 2 del; 11 mod

8012229: [lcms] Improve performance of color conversion for images with alpha channel

Reviewed-by: azvegint

-------------

PR: https://git.openjdk.java.net/jdk/pull/3239